jdk/src/java.base/share/classes/jdk/internal/reflect/ReflectionFactory.java
changeset 37593 824750ada3d6
parent 37363 329dba26ffd2
child 37781 71ed5645f17c
equal deleted inserted replaced
37592:c80f098887f4 37593:824750ada3d6
    28 import java.lang.reflect.Field;
    28 import java.lang.reflect.Field;
    29 import java.lang.reflect.Executable;
    29 import java.lang.reflect.Executable;
    30 import java.lang.reflect.Method;
    30 import java.lang.reflect.Method;
    31 import java.lang.reflect.Constructor;
    31 import java.lang.reflect.Constructor;
    32 import java.lang.reflect.Modifier;
    32 import java.lang.reflect.Modifier;
    33 import java.security.AccessController;
       
    34 import java.security.Permission;
    33 import java.security.Permission;
    35 import java.security.PrivilegedAction;
    34 import java.security.PrivilegedAction;
       
    35 import java.util.Properties;
    36 import sun.reflect.misc.ReflectUtil;
    36 import sun.reflect.misc.ReflectUtil;
       
    37 import sun.security.action.GetPropertyAction;
    37 
    38 
    38 /** <P> The master factory for all reflective objects, both those in
    39 /** <P> The master factory for all reflective objects, both those in
    39     java.lang.reflect (Fields, Methods, Constructors) as well as their
    40     java.lang.reflect (Fields, Methods, Constructors) as well as their
    40     delegates (FieldAccessors, MethodAccessors, ConstructorAccessors).
    41     delegates (FieldAccessors, MethodAccessors, ConstructorAccessors).
    41     </P>
    42     </P>
   380         static initializer (more properly, that for
   381         static initializer (more properly, that for
   381         java.lang.reflect.AccessibleObject) causes this class's to be
   382         java.lang.reflect.AccessibleObject) causes this class's to be
   382         run, before the system properties are set up. */
   383         run, before the system properties are set up. */
   383     private static void checkInitted() {
   384     private static void checkInitted() {
   384         if (initted) return;
   385         if (initted) return;
   385         AccessController.doPrivileged(
   386 
   386             new PrivilegedAction<>() {
   387         // Tests to ensure the system properties table is fully
   387                 public Void run() {
   388         // initialized. This is needed because reflection code is
   388                     // Tests to ensure the system properties table is fully
   389         // called very early in the initialization process (before
   389                     // initialized. This is needed because reflection code is
   390         // command-line arguments have been parsed and therefore
   390                     // called very early in the initialization process (before
   391         // these user-settable properties installed.) We assume that
   391                     // command-line arguments have been parsed and therefore
   392         // if System.out is non-null then the System class has been
   392                     // these user-settable properties installed.) We assume that
   393         // fully initialized and that the bulk of the startup code
   393                     // if System.out is non-null then the System class has been
   394         // has been run.
   394                     // fully initialized and that the bulk of the startup code
   395 
   395                     // has been run.
   396         if (System.out == null) {
   396 
   397             // java.lang.System not yet fully initialized
   397                     if (System.out == null) {
   398             return;
   398                         // java.lang.System not yet fully initialized
   399         }
   399                         return null;
   400 
   400                     }
   401         Properties props = GetPropertyAction.getProperties();
   401 
   402         String val = props.getProperty("sun.reflect.noInflation");
   402                     String val = System.getProperty("sun.reflect.noInflation");
   403         if (val != null && val.equals("true")) {
   403                     if (val != null && val.equals("true")) {
   404             noInflation = true;
   404                         noInflation = true;
   405         }
   405                     }
   406 
   406 
   407         val = props.getProperty("sun.reflect.inflationThreshold");
   407                     val = System.getProperty("sun.reflect.inflationThreshold");
   408         if (val != null) {
   408                     if (val != null) {
   409             try {
   409                         try {
   410                 inflationThreshold = Integer.parseInt(val);
   410                             inflationThreshold = Integer.parseInt(val);
   411             } catch (NumberFormatException e) {
   411                         } catch (NumberFormatException e) {
   412                 throw new RuntimeException("Unable to parse property sun.reflect.inflationThreshold", e);
   412                             throw new RuntimeException("Unable to parse property sun.reflect.inflationThreshold", e);
   413             }
   413                         }
   414         }
   414                     }
   415 
   415 
   416         initted = true;
   416                     initted = true;
       
   417                     return null;
       
   418                 }
       
   419             });
       
   420     }
   417     }
   421 
   418 
   422     private static LangReflectAccess langReflectAccess() {
   419     private static LangReflectAccess langReflectAccess() {
   423         if (langReflectAccess == null) {
   420         if (langReflectAccess == null) {
   424             // Call a static method to get class java.lang.reflect.Modifier
   421             // Call a static method to get class java.lang.reflect.Modifier