2011-03-18 00:03:24 -07:00
|
|
|
/*
|
2015-09-23 08:43:51 +02:00
|
|
|
* Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
|
2011-03-18 00:03:24 -07:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
|
|
*
|
|
|
|
* This code is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License version 2 only, as
|
|
|
|
* published by the Free Software Foundation. Oracle designates this
|
|
|
|
* particular file as subject to the "Classpath" exception as provided
|
|
|
|
* by Oracle in the LICENSE file that accompanied this code.
|
|
|
|
*
|
|
|
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* version 2 for more details (a copy is included in the LICENSE file that
|
|
|
|
* accompanied this code).
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License version
|
|
|
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*
|
|
|
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
|
|
* or visit www.oracle.com if you need additional information or have any
|
|
|
|
* questions.
|
|
|
|
*/
|
|
|
|
|
2011-03-23 23:02:31 -07:00
|
|
|
package java.lang.invoke;
|
2011-03-18 00:03:24 -07:00
|
|
|
|
2011-06-01 23:56:47 -07:00
|
|
|
import java.security.AccessController;
|
|
|
|
import java.security.PrivilegedAction;
|
2015-11-11 09:19:12 +00:00
|
|
|
import jdk.internal.misc.Unsafe;
|
2011-06-01 23:56:47 -07:00
|
|
|
|
2011-03-18 00:03:24 -07:00
|
|
|
/**
|
|
|
|
* This class consists exclusively of static names internal to the
|
|
|
|
* method handle implementation.
|
2011-03-23 23:02:31 -07:00
|
|
|
* Usage: {@code import static java.lang.invoke.MethodHandleStatics.*}
|
2011-03-18 00:03:24 -07:00
|
|
|
* @author John Rose, JSR 292 EG
|
|
|
|
*/
|
|
|
|
/*non-public*/ class MethodHandleStatics {
|
|
|
|
|
|
|
|
private MethodHandleStatics() { } // do not instantiate
|
|
|
|
|
2012-07-24 10:47:44 -07:00
|
|
|
static final Unsafe UNSAFE = Unsafe.getUnsafe();
|
|
|
|
|
2011-06-01 23:56:47 -07:00
|
|
|
static final boolean DEBUG_METHOD_HANDLE_NAMES;
|
2012-07-24 10:47:44 -07:00
|
|
|
static final boolean DUMP_CLASS_FILES;
|
|
|
|
static final boolean TRACE_INTERPRETER;
|
|
|
|
static final boolean TRACE_METHOD_LINKAGE;
|
2014-09-10 19:19:47 +04:00
|
|
|
static final int COMPILE_THRESHOLD;
|
2014-10-29 09:31:37 -07:00
|
|
|
static final int DONT_INLINE_THRESHOLD;
|
2014-09-10 19:19:46 +04:00
|
|
|
static final int PROFILE_LEVEL;
|
2015-01-29 10:27:30 -08:00
|
|
|
static final boolean PROFILE_GWT;
|
2015-01-29 10:27:30 -08:00
|
|
|
static final int CUSTOMIZE_THRESHOLD;
|
2014-09-10 19:19:46 +04:00
|
|
|
|
2011-06-01 23:56:47 -07:00
|
|
|
static {
|
2015-10-27 09:09:37 +01:00
|
|
|
final Object[] values = new Object[9];
|
2015-04-23 09:32:35 -07:00
|
|
|
AccessController.doPrivileged(new PrivilegedAction<>() {
|
2011-06-01 23:56:47 -07:00
|
|
|
public Void run() {
|
|
|
|
values[0] = Boolean.getBoolean("java.lang.invoke.MethodHandle.DEBUG_NAMES");
|
2012-07-24 10:47:44 -07:00
|
|
|
values[1] = Boolean.getBoolean("java.lang.invoke.MethodHandle.DUMP_CLASS_FILES");
|
|
|
|
values[2] = Boolean.getBoolean("java.lang.invoke.MethodHandle.TRACE_INTERPRETER");
|
|
|
|
values[3] = Boolean.getBoolean("java.lang.invoke.MethodHandle.TRACE_METHOD_LINKAGE");
|
2014-11-24 07:19:36 -08:00
|
|
|
values[4] = Integer.getInteger("java.lang.invoke.MethodHandle.COMPILE_THRESHOLD", 0);
|
2014-11-24 07:16:38 -08:00
|
|
|
values[5] = Integer.getInteger("java.lang.invoke.MethodHandle.DONT_INLINE_THRESHOLD", 30);
|
|
|
|
values[6] = Integer.getInteger("java.lang.invoke.MethodHandle.PROFILE_LEVEL", 0);
|
2015-01-29 10:27:30 -08:00
|
|
|
values[7] = Boolean.parseBoolean(System.getProperty("java.lang.invoke.MethodHandle.PROFILE_GWT", "true"));
|
2015-01-29 10:27:30 -08:00
|
|
|
values[8] = Integer.getInteger("java.lang.invoke.MethodHandle.CUSTOMIZE_THRESHOLD", 127);
|
2011-06-01 23:56:47 -07:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
DEBUG_METHOD_HANDLE_NAMES = (Boolean) values[0];
|
2012-07-24 10:47:44 -07:00
|
|
|
DUMP_CLASS_FILES = (Boolean) values[1];
|
|
|
|
TRACE_INTERPRETER = (Boolean) values[2];
|
|
|
|
TRACE_METHOD_LINKAGE = (Boolean) values[3];
|
2014-11-24 07:16:38 -08:00
|
|
|
COMPILE_THRESHOLD = (Integer) values[4];
|
|
|
|
DONT_INLINE_THRESHOLD = (Integer) values[5];
|
|
|
|
PROFILE_LEVEL = (Integer) values[6];
|
2015-01-29 10:27:30 -08:00
|
|
|
PROFILE_GWT = (Boolean) values[7];
|
2015-01-29 10:27:30 -08:00
|
|
|
CUSTOMIZE_THRESHOLD = (Integer) values[8];
|
|
|
|
|
|
|
|
if (CUSTOMIZE_THRESHOLD < -1 || CUSTOMIZE_THRESHOLD > 127) {
|
|
|
|
throw newInternalError("CUSTOMIZE_THRESHOLD should be in [-1...127] range");
|
|
|
|
}
|
2011-06-01 23:56:47 -07:00
|
|
|
}
|
2011-05-17 19:48:19 -07:00
|
|
|
|
2014-02-24 18:11:55 +04:00
|
|
|
/** Tell if any of the debugging switches are turned on.
|
|
|
|
* If this is the case, it is reasonable to perform extra checks or save extra information.
|
|
|
|
*/
|
|
|
|
/*non-public*/ static boolean debugEnabled() {
|
|
|
|
return (DEBUG_METHOD_HANDLE_NAMES |
|
|
|
|
DUMP_CLASS_FILES |
|
|
|
|
TRACE_INTERPRETER |
|
|
|
|
TRACE_METHOD_LINKAGE);
|
|
|
|
}
|
|
|
|
|
2011-03-18 00:03:24 -07:00
|
|
|
// handy shared exception makers (they simplify the common case code)
|
2014-02-24 18:11:55 +04:00
|
|
|
/*non-public*/ static InternalError newInternalError(String message) {
|
|
|
|
return new InternalError(message);
|
|
|
|
}
|
2012-10-19 17:04:35 -07:00
|
|
|
/*non-public*/ static InternalError newInternalError(String message, Throwable cause) {
|
|
|
|
return new InternalError(message, cause);
|
|
|
|
}
|
|
|
|
/*non-public*/ static InternalError newInternalError(Throwable cause) {
|
|
|
|
return new InternalError(cause);
|
|
|
|
}
|
2011-03-18 00:03:24 -07:00
|
|
|
/*non-public*/ static RuntimeException newIllegalStateException(String message) {
|
|
|
|
return new IllegalStateException(message);
|
|
|
|
}
|
|
|
|
/*non-public*/ static RuntimeException newIllegalStateException(String message, Object obj) {
|
|
|
|
return new IllegalStateException(message(message, obj));
|
|
|
|
}
|
|
|
|
/*non-public*/ static RuntimeException newIllegalArgumentException(String message) {
|
|
|
|
return new IllegalArgumentException(message);
|
|
|
|
}
|
|
|
|
/*non-public*/ static RuntimeException newIllegalArgumentException(String message, Object obj) {
|
|
|
|
return new IllegalArgumentException(message(message, obj));
|
|
|
|
}
|
2011-05-12 19:27:49 -07:00
|
|
|
/*non-public*/ static RuntimeException newIllegalArgumentException(String message, Object obj, Object obj2) {
|
|
|
|
return new IllegalArgumentException(message(message, obj, obj2));
|
|
|
|
}
|
2014-09-10 19:19:47 +04:00
|
|
|
/** Propagate unchecked exceptions and errors, but wrap anything checked and throw that instead. */
|
2012-09-20 14:02:55 -07:00
|
|
|
/*non-public*/ static Error uncaughtException(Throwable ex) {
|
2014-09-10 19:19:47 +04:00
|
|
|
if (ex instanceof Error) throw (Error) ex;
|
|
|
|
if (ex instanceof RuntimeException) throw (RuntimeException) ex;
|
2012-10-19 17:04:35 -07:00
|
|
|
throw newInternalError("uncaught exception", ex);
|
2011-03-18 00:03:24 -07:00
|
|
|
}
|
|
|
|
private static String message(String message, Object obj) {
|
|
|
|
if (obj != null) message = message + ": " + obj;
|
|
|
|
return message;
|
|
|
|
}
|
2011-05-12 19:27:49 -07:00
|
|
|
private static String message(String message, Object obj, Object obj2) {
|
|
|
|
if (obj != null || obj2 != null) message = message + ": " + obj + ", " + obj2;
|
|
|
|
return message;
|
|
|
|
}
|
2011-03-18 00:03:24 -07:00
|
|
|
}
|