8219774: Reexamine the initialization of LangReflectAccess shared secret at AccessibleObject::<clinit>

Reviewed-by: alanb
This commit is contained in:
Mandy Chung 2019-07-23 20:03:03 -07:00
parent 94c38c4cc1
commit 203db2596f
10 changed files with 65 additions and 205 deletions

View file

@ -30,6 +30,7 @@ import java.lang.invoke.MethodHandle;
import java.lang.ref.WeakReference;
import java.security.AccessController;
import jdk.internal.access.SharedSecrets;
import jdk.internal.misc.VM;
import jdk.internal.module.IllegalAccessLogger;
import jdk.internal.reflect.CallerSensitive;
@ -77,6 +78,10 @@ import sun.security.util.SecurityConstants;
* @spec JPMS
*/
public class AccessibleObject implements AnnotatedElement {
static {
// AccessibleObject is initialized early in initPhase1
SharedSecrets.setJavaLangReflectAccess(new ReflectAccess());
}
static void checkPermission() {
SecurityManager sm = System.getSecurityManager();

View file

@ -111,7 +111,7 @@ public final class Constructor<T> extends Executable {
/**
* Package-private constructor used by ReflectAccess to enable
* instantiation of these objects in Java code from the java.lang
* package via sun.reflect.LangReflectAccess.
* package via jdk.internal.access.JavaLangReflectAccess.
*/
Constructor(Class<T> declaringClass,
Class<?>[] parameterTypes,

View file

@ -113,9 +113,7 @@ class Field extends AccessibleObject implements Member {
/**
* Package-private constructor used by ReflectAccess to enable
* instantiation of these objects in Java code from the java.lang
* package via sun.reflect.LangReflectAccess.
* Package-private constructor
*/
Field(Class<?> declaringClass,
String name,

View file

@ -113,9 +113,7 @@ public final class Method extends Executable {
}
/**
* Package-private constructor used by ReflectAccess to enable
* instantiation of these objects in Java code from the java.lang
* package via sun.reflect.LangReflectAccess.
* Package-private constructor
*/
Method(Class<?> declaringClass,
String name,

View file

@ -25,10 +25,7 @@
package java.lang.reflect;
import java.security.AccessController;
import java.util.StringJoiner;
import jdk.internal.reflect.LangReflectAccess;
import jdk.internal.reflect.ReflectionFactory;
/**
* The Modifier class provides {@code static} methods and
@ -47,16 +44,6 @@ import jdk.internal.reflect.ReflectionFactory;
*/
public class Modifier {
/*
* Bootstrapping protocol between java.lang and java.lang.reflect
* packages
*/
static {
ReflectionFactory factory = AccessController.doPrivileged(
new ReflectionFactory.GetReflectionFactoryAction());
factory.setLangReflectAccess(new java.lang.reflect.ReflectAccess());
}
/**
* Return {@code true} if the integer argument includes the
* {@code public} modifier, {@code false} otherwise.

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -29,52 +29,10 @@ import jdk.internal.reflect.MethodAccessor;
import jdk.internal.reflect.ConstructorAccessor;
/** Package-private class implementing the
sun.reflect.LangReflectAccess interface, allowing the java.lang
jdk.internal.access.JavaLangReflectAccess interface, allowing the java.lang
package to instantiate objects in this package. */
class ReflectAccess implements jdk.internal.reflect.LangReflectAccess {
public Field newField(Class<?> declaringClass,
String name,
Class<?> type,
int modifiers,
int slot,
String signature,
byte[] annotations)
{
return new Field(declaringClass,
name,
type,
modifiers,
slot,
signature,
annotations);
}
public Method newMethod(Class<?> declaringClass,
String name,
Class<?>[] parameterTypes,
Class<?> returnType,
Class<?>[] checkedExceptions,
int modifiers,
int slot,
String signature,
byte[] annotations,
byte[] parameterAnnotations,
byte[] annotationDefault)
{
return new Method(declaringClass,
name,
parameterTypes,
returnType,
checkedExceptions,
modifiers,
slot,
signature,
annotations,
parameterAnnotations,
annotationDefault);
}
class ReflectAccess implements jdk.internal.access.JavaLangReflectAccess {
public <T> Constructor<T> newConstructor(Class<T> declaringClass,
Class<?>[] parameterTypes,
Class<?>[] checkedExceptions,