< prev index next >

src/java.base/share/classes/java/lang/invoke/MethodHandleStatics.java

Print this page
rev 14210 : 8154231: Simplify access to System properties from JDK code
Reviewed-by: rriggs


   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
  23  * questions.
  24  */
  25 
  26 package java.lang.invoke;
  27 
  28 import java.security.AccessController;
  29 import java.security.PrivilegedAction;
  30 import jdk.internal.misc.Unsafe;

  31 
  32 /**
  33  * This class consists exclusively of static names internal to the
  34  * method handle implementation.
  35  * Usage:  {@code import static java.lang.invoke.MethodHandleStatics.*}
  36  * @author John Rose, JSR 292 EG
  37  */
  38 /*non-public*/ class MethodHandleStatics {
  39 
  40     private MethodHandleStatics() { }  // do not instantiate
  41 
  42     static final Unsafe UNSAFE = Unsafe.getUnsafe();
  43 
  44     static final boolean DEBUG_METHOD_HANDLE_NAMES;
  45     static final boolean DUMP_CLASS_FILES;
  46     static final boolean TRACE_INTERPRETER;
  47     static final boolean TRACE_METHOD_LINKAGE;
  48     static final int COMPILE_THRESHOLD;
  49     static final int DONT_INLINE_THRESHOLD;
  50     static final int PROFILE_LEVEL;
  51     static final boolean PROFILE_GWT;
  52     static final int CUSTOMIZE_THRESHOLD;
  53     static final boolean VAR_HANDLE_GUARDS;
  54 
  55     static {
  56         final Object[] values = new Object[10];
  57         AccessController.doPrivileged(new PrivilegedAction<>() {
  58                 public Void run() {
  59                     values[0] = Boolean.getBoolean("java.lang.invoke.MethodHandle.DEBUG_NAMES");
  60                     values[1] = Boolean.getBoolean("java.lang.invoke.MethodHandle.DUMP_CLASS_FILES");
  61                     values[2] = Boolean.getBoolean("java.lang.invoke.MethodHandle.TRACE_INTERPRETER");
  62                     values[3] = Boolean.getBoolean("java.lang.invoke.MethodHandle.TRACE_METHOD_LINKAGE");
  63                     values[4] = Integer.getInteger("java.lang.invoke.MethodHandle.COMPILE_THRESHOLD", 0);
  64                     values[5] = Integer.getInteger("java.lang.invoke.MethodHandle.DONT_INLINE_THRESHOLD", 30);
  65                     values[6] = Integer.getInteger("java.lang.invoke.MethodHandle.PROFILE_LEVEL", 0);
  66                     values[7] = Boolean.parseBoolean(System.getProperty("java.lang.invoke.MethodHandle.PROFILE_GWT", "true"));
  67                     values[8] = Integer.getInteger("java.lang.invoke.MethodHandle.CUSTOMIZE_THRESHOLD", 127);
  68                     values[9] = Boolean.parseBoolean(System.getProperty("java.lang.invoke.VarHandle.VAR_HANDLE_GUARDS", "true"));
  69                     return null;
  70                 }
  71             });
  72         DEBUG_METHOD_HANDLE_NAMES = (Boolean) values[0];
  73         DUMP_CLASS_FILES          = (Boolean) values[1];
  74         TRACE_INTERPRETER         = (Boolean) values[2];
  75         TRACE_METHOD_LINKAGE      = (Boolean) values[3];
  76         COMPILE_THRESHOLD         = (Integer) values[4];
  77         DONT_INLINE_THRESHOLD     = (Integer) values[5];
  78         PROFILE_LEVEL             = (Integer) values[6];
  79         PROFILE_GWT               = (Boolean) values[7];
  80         CUSTOMIZE_THRESHOLD       = (Integer) values[8];
  81         VAR_HANDLE_GUARDS         = (Boolean) values[9];
  82 
  83         if (CUSTOMIZE_THRESHOLD < -1 || CUSTOMIZE_THRESHOLD > 127) {
  84             throw newInternalError("CUSTOMIZE_THRESHOLD should be in [-1...127] range");
  85         }
  86     }
  87 
  88     /** Tell if any of the debugging switches are turned on.
  89      *  If this is the case, it is reasonable to perform extra checks or save extra information.
  90      */
  91     /*non-public*/ static boolean debugEnabled() {
  92         return (DEBUG_METHOD_HANDLE_NAMES |
  93                 DUMP_CLASS_FILES |
  94                 TRACE_INTERPRETER |
  95                 TRACE_METHOD_LINKAGE);
  96     }
  97 
  98     // handy shared exception makers (they simplify the common case code)
  99     /*non-public*/ static InternalError newInternalError(String message) {
 100         return new InternalError(message);
 101     }




   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
  23  * questions.
  24  */
  25 
  26 package java.lang.invoke;
  27 
  28 import java.util.Properties;

  29 import jdk.internal.misc.Unsafe;
  30 import sun.security.action.GetPropertyAction;
  31 
  32 /**
  33  * This class consists exclusively of static names internal to the
  34  * method handle implementation.
  35  * Usage:  {@code import static java.lang.invoke.MethodHandleStatics.*}
  36  * @author John Rose, JSR 292 EG
  37  */
  38 /*non-public*/ class MethodHandleStatics {
  39 
  40     private MethodHandleStatics() { }  // do not instantiate
  41 
  42     static final Unsafe UNSAFE = Unsafe.getUnsafe();
  43 
  44     static final boolean DEBUG_METHOD_HANDLE_NAMES;
  45     static final boolean DUMP_CLASS_FILES;
  46     static final boolean TRACE_INTERPRETER;
  47     static final boolean TRACE_METHOD_LINKAGE;
  48     static final int COMPILE_THRESHOLD;
  49     static final int DONT_INLINE_THRESHOLD;
  50     static final int PROFILE_LEVEL;
  51     static final boolean PROFILE_GWT;
  52     static final int CUSTOMIZE_THRESHOLD;
  53     static final boolean VAR_HANDLE_GUARDS;
  54 
  55     static {
  56         Properties props = GetPropertyAction.getProperties();
  57         DEBUG_METHOD_HANDLE_NAMES = Boolean.parseBoolean(
  58                 props.getProperty("java.lang.invoke.MethodHandle.DEBUG_NAMES"));
  59         DUMP_CLASS_FILES = Boolean.parseBoolean(
  60                 props.getProperty("java.lang.invoke.MethodHandle.DUMP_CLASS_FILES"));
  61         TRACE_INTERPRETER = Boolean.parseBoolean(
  62                 props.getProperty("java.lang.invoke.MethodHandle.TRACE_INTERPRETER"));
  63         TRACE_METHOD_LINKAGE = Boolean.parseBoolean(
  64                 props.getProperty("java.lang.invoke.MethodHandle.TRACE_METHOD_LINKAGE"));
  65         COMPILE_THRESHOLD = Integer.parseInt(
  66                 props.getProperty("java.lang.invoke.MethodHandle.COMPILE_THRESHOLD", "0"));
  67         DONT_INLINE_THRESHOLD = Integer.parseInt(
  68                 props.getProperty("java.lang.invoke.MethodHandle.DONT_INLINE_THRESHOLD", "30"));
  69         PROFILE_LEVEL = Integer.parseInt(
  70                 props.getProperty("java.lang.invoke.MethodHandle.PROFILE_LEVEL", "0"));
  71         PROFILE_GWT = Boolean.parseBoolean(
  72                 props.getProperty("java.lang.invoke.MethodHandle.PROFILE_GWT", "true"));
  73         CUSTOMIZE_THRESHOLD = Integer.parseInt(
  74                 props.getProperty("java.lang.invoke.MethodHandle.CUSTOMIZE_THRESHOLD", "127"));
  75         VAR_HANDLE_GUARDS = Boolean.parseBoolean(
  76                 props.getProperty("java.lang.invoke.VarHandle.VAR_HANDLE_GUARDS", "true"));





  77 
  78         if (CUSTOMIZE_THRESHOLD < -1 || CUSTOMIZE_THRESHOLD > 127) {
  79             throw newInternalError("CUSTOMIZE_THRESHOLD should be in [-1...127] range");
  80         }
  81     }
  82 
  83     /** Tell if any of the debugging switches are turned on.
  84      *  If this is the case, it is reasonable to perform extra checks or save extra information.
  85      */
  86     /*non-public*/ static boolean debugEnabled() {
  87         return (DEBUG_METHOD_HANDLE_NAMES |
  88                 DUMP_CLASS_FILES |
  89                 TRACE_INTERPRETER |
  90                 TRACE_METHOD_LINKAGE);
  91     }
  92 
  93     // handy shared exception makers (they simplify the common case code)
  94     /*non-public*/ static InternalError newInternalError(String message) {
  95         return new InternalError(message);
  96     }


< prev index next >