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 Permission reflectionFactoryAccessPerm 54 = new RuntimePermission("reflectionFactoryAccess"); 55 private static 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 68 // for the first few invocations of Methods and Constructors and 69 // then switch to the bytecode-based implementations. 70 // 71 // Package-private to be accessible to NativeMethodAccessorImpl 72 // and NativeConstructorAccessorImpl 73 private static boolean noInflation = false; 74 private static int inflationThreshold = 15; 75 | 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 68 // for the first few invocations of Methods and Constructors and 69 // then switch to the bytecode-based implementations. 70 // 71 // Package-private to be accessible to NativeMethodAccessorImpl 72 // and NativeConstructorAccessorImpl 73 private static boolean noInflation = false; 74 private static int inflationThreshold = 15; 75 |