src/java.base/share/classes/sun/reflect/ReflectionFactory.java

Print this page
rev 12972 : 8140606: Update library code to use internal Unsafe
Reviewed-by: duke


  27 
  28 import java.lang.reflect.Field;
  29 import java.lang.reflect.Executable;
  30 import java.lang.reflect.Method;
  31 import java.lang.reflect.Constructor;
  32 import java.lang.reflect.Modifier;
  33 import java.security.AccessController;
  34 import java.security.Permission;
  35 import java.security.PrivilegedAction;
  36 import sun.reflect.misc.ReflectUtil;
  37 
  38 /** <P> The master factory for all reflective objects, both those in
  39     java.lang.reflect (Fields, Methods, Constructors) as well as their
  40     delegates (FieldAccessors, MethodAccessors, ConstructorAccessors).
  41     </P>
  42 
  43     <P> The methods in this class are extremely unsafe and can cause
  44     subversion of both the language and the verifier. For this reason,
  45     they are all instance methods, and access to the constructor of
  46     this factory is guarded by a security check, in similar style to
  47     {@link sun.misc.Unsafe}. </P>
  48 */
  49 
  50 public class ReflectionFactory {
  51 
  52     private static boolean initted = false;
  53     private static final Permission reflectionFactoryAccessPerm
  54         = new RuntimePermission("reflectionFactoryAccess");
  55     private static final ReflectionFactory soleInstance = new ReflectionFactory();
  56     // Provides access to package-private mechanisms in java.lang.reflect
  57     private static volatile LangReflectAccess langReflectAccess;
  58 
  59     //
  60     // "Inflation" mechanism. Loading bytecodes to implement
  61     // Method.invoke() and Constructor.newInstance() currently costs
  62     // 3-4x more than an invocation via native code for the first
  63     // invocation (though subsequent invocations have been benchmarked
  64     // to be over 20x faster). Unfortunately this cost increases
  65     // startup time for certain applications that use reflection
  66     // intensively (but only once per class) to bootstrap themselves.
  67     // To avoid this penalty we reuse the existing JVM entry points




  27 
  28 import java.lang.reflect.Field;
  29 import java.lang.reflect.Executable;
  30 import java.lang.reflect.Method;
  31 import java.lang.reflect.Constructor;
  32 import java.lang.reflect.Modifier;
  33 import java.security.AccessController;
  34 import java.security.Permission;
  35 import java.security.PrivilegedAction;
  36 import sun.reflect.misc.ReflectUtil;
  37 
  38 /** <P> The master factory for all reflective objects, both those in
  39     java.lang.reflect (Fields, Methods, Constructors) as well as their
  40     delegates (FieldAccessors, MethodAccessors, ConstructorAccessors).
  41     </P>
  42 
  43     <P> The methods in this class are extremely unsafe and can cause
  44     subversion of both the language and the verifier. For this reason,
  45     they are all instance methods, and access to the constructor of
  46     this factory is guarded by a security check, in similar style to
  47     {@link jdk.internal.misc.Unsafe}. </P>
  48 */
  49 
  50 public class ReflectionFactory {
  51 
  52     private static boolean initted = false;
  53     private static final Permission reflectionFactoryAccessPerm
  54         = new RuntimePermission("reflectionFactoryAccess");
  55     private static final ReflectionFactory soleInstance = new ReflectionFactory();
  56     // Provides access to package-private mechanisms in java.lang.reflect
  57     private static volatile LangReflectAccess langReflectAccess;
  58 
  59     //
  60     // "Inflation" mechanism. Loading bytecodes to implement
  61     // Method.invoke() and Constructor.newInstance() currently costs
  62     // 3-4x more than an invocation via native code for the first
  63     // invocation (though subsequent invocations have been benchmarked
  64     // to be over 20x faster). Unfortunately this cost increases
  65     // startup time for certain applications that use reflection
  66     // intensively (but only once per class) to bootstrap themselves.
  67     // To avoid this penalty we reuse the existing JVM entry points