< prev index next >

src/java.base/share/classes/jdk/internal/reflect/ReflectionFactory.java

Print this page


   1 /*
   2  * Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  27 
  28 import java.io.Externalizable;
  29 import java.io.ObjectInputStream;
  30 import java.io.ObjectOutputStream;
  31 import java.io.ObjectStreamClass;
  32 import java.io.OptionalDataException;
  33 import java.io.Serializable;
  34 import java.lang.invoke.MethodHandle;
  35 import java.lang.invoke.MethodHandles;
  36 import java.lang.reflect.Field;
  37 import java.lang.reflect.Executable;
  38 import java.lang.reflect.InvocationTargetException;
  39 import java.lang.reflect.Method;
  40 import java.lang.reflect.Constructor;
  41 import java.lang.reflect.Modifier;
  42 import java.security.Permission;
  43 import java.security.PrivilegedAction;
  44 import java.util.Objects;
  45 import java.util.Properties;
  46 

  47 import sun.reflect.misc.ReflectUtil;
  48 import sun.security.action.GetPropertyAction;
  49 
  50 /** <P> The master factory for all reflective objects, both those in
  51     java.lang.reflect (Fields, Methods, Constructors) as well as their
  52     delegates (FieldAccessors, MethodAccessors, ConstructorAccessors).
  53     </P>
  54 
  55     <P> The methods in this class are extremely unsafe and can cause
  56     subversion of both the language and the verifier. For this reason,
  57     they are all instance methods, and access to the constructor of
  58     this factory is guarded by a security check, in similar style to
  59     {@link jdk.internal.misc.Unsafe}. </P>
  60 */
  61 
  62 public class ReflectionFactory {
  63 
  64     private static boolean initted = false;
  65     private static final Permission reflectionFactoryAccessPerm
  66         = new RuntimePermission("reflectionFactoryAccess");


 568         }
 569     }
 570 
 571     //--------------------------------------------------------------------------
 572     //
 573     // Internals only below this point
 574     //
 575 
 576     static int inflationThreshold() {
 577         return inflationThreshold;
 578     }
 579 
 580     /** We have to defer full initialization of this class until after
 581         the static initializer is run since java.lang.reflect.Method's
 582         static initializer (more properly, that for
 583         java.lang.reflect.AccessibleObject) causes this class's to be
 584         run, before the system properties are set up. */
 585     private static void checkInitted() {
 586         if (initted) return;
 587 
 588         // Tests to ensure the system properties table is fully
 589         // initialized. This is needed because reflection code is
 590         // called very early in the initialization process (before
 591         // command-line arguments have been parsed and therefore
 592         // these user-settable properties installed.) We assume that
 593         // if System.out is non-null then the System class has been
 594         // fully initialized and that the bulk of the startup code
 595         // has been run.
 596 
 597         if (System.out == null) {
 598             // java.lang.System not yet fully initialized
 599             return;
 600         }
 601 
 602         Properties props = GetPropertyAction.privilegedGetProperties();
 603         String val = props.getProperty("sun.reflect.noInflation");
 604         if (val != null && val.equals("true")) {
 605             noInflation = true;
 606         }
 607 
 608         val = props.getProperty("sun.reflect.inflationThreshold");
 609         if (val != null) {
 610             try {
 611                 inflationThreshold = Integer.parseInt(val);
 612             } catch (NumberFormatException e) {
 613                 throw new RuntimeException("Unable to parse property sun.reflect.inflationThreshold", e);
 614             }
 615         }
 616 
 617         initted = true;
 618     }


   1 /*
   2  * Copyright (c) 2001, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  27 
  28 import java.io.Externalizable;
  29 import java.io.ObjectInputStream;
  30 import java.io.ObjectOutputStream;
  31 import java.io.ObjectStreamClass;
  32 import java.io.OptionalDataException;
  33 import java.io.Serializable;
  34 import java.lang.invoke.MethodHandle;
  35 import java.lang.invoke.MethodHandles;
  36 import java.lang.reflect.Field;
  37 import java.lang.reflect.Executable;
  38 import java.lang.reflect.InvocationTargetException;
  39 import java.lang.reflect.Method;
  40 import java.lang.reflect.Constructor;
  41 import java.lang.reflect.Modifier;
  42 import java.security.Permission;
  43 import java.security.PrivilegedAction;
  44 import java.util.Objects;
  45 import java.util.Properties;
  46 
  47 import jdk.internal.misc.VM;
  48 import sun.reflect.misc.ReflectUtil;
  49 import sun.security.action.GetPropertyAction;
  50 
  51 /** <P> The master factory for all reflective objects, both those in
  52     java.lang.reflect (Fields, Methods, Constructors) as well as their
  53     delegates (FieldAccessors, MethodAccessors, ConstructorAccessors).
  54     </P>
  55 
  56     <P> The methods in this class are extremely unsafe and can cause
  57     subversion of both the language and the verifier. For this reason,
  58     they are all instance methods, and access to the constructor of
  59     this factory is guarded by a security check, in similar style to
  60     {@link jdk.internal.misc.Unsafe}. </P>
  61 */
  62 
  63 public class ReflectionFactory {
  64 
  65     private static boolean initted = false;
  66     private static final Permission reflectionFactoryAccessPerm
  67         = new RuntimePermission("reflectionFactoryAccess");


 569         }
 570     }
 571 
 572     //--------------------------------------------------------------------------
 573     //
 574     // Internals only below this point
 575     //
 576 
 577     static int inflationThreshold() {
 578         return inflationThreshold;
 579     }
 580 
 581     /** We have to defer full initialization of this class until after
 582         the static initializer is run since java.lang.reflect.Method's
 583         static initializer (more properly, that for
 584         java.lang.reflect.AccessibleObject) causes this class's to be
 585         run, before the system properties are set up. */
 586     private static void checkInitted() {
 587         if (initted) return;
 588 
 589         // Defer initialization until module system is initialized so as
 590         // to avoid inflation and spinning bytecode in unnamed modules
 591         // during early startup.
 592         if (!VM.isModuleSystemInited()) {







 593             return;
 594         }
 595 
 596         Properties props = GetPropertyAction.privilegedGetProperties();
 597         String val = props.getProperty("sun.reflect.noInflation");
 598         if (val != null && val.equals("true")) {
 599             noInflation = true;
 600         }
 601 
 602         val = props.getProperty("sun.reflect.inflationThreshold");
 603         if (val != null) {
 604             try {
 605                 inflationThreshold = Integer.parseInt(val);
 606             } catch (NumberFormatException e) {
 607                 throw new RuntimeException("Unable to parse property sun.reflect.inflationThreshold", e);
 608             }
 609         }
 610 
 611         initted = true;
 612     }


< prev index next >