Almost compiled java.lang.invoke, except the parts that deal with Asm bytecode generator
2 * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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.
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
26 package java.lang.invoke;
28 import java.security.AccessController;
29 import java.security.PrivilegedAction;
30 //import sun.misc.Unsafe;
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
38 /*non-public*/ class MethodHandleStatics {
40 private MethodHandleStatics() { } // do not instantiate
42 // static final Unsafe UNSAFE = Unsafe.getUnsafe();
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 Integer COMPILE_THRESHOLD;
50 final Object[] values = { false, false, false, false, null };
51 AccessController.doPrivileged(new PrivilegedAction<Void>() {
53 values[0] = Boolean.getBoolean("java.lang.invoke.MethodHandle.DEBUG_NAMES");
54 values[1] = Boolean.getBoolean("java.lang.invoke.MethodHandle.DUMP_CLASS_FILES");
55 values[2] = Boolean.getBoolean("java.lang.invoke.MethodHandle.TRACE_INTERPRETER");
56 values[3] = Boolean.getBoolean("java.lang.invoke.MethodHandle.TRACE_METHOD_LINKAGE");
57 values[4] = Integer.getInteger("java.lang.invoke.MethodHandle.COMPILE_THRESHOLD");
61 DEBUG_METHOD_HANDLE_NAMES = (Boolean) values[0];
62 DUMP_CLASS_FILES = (Boolean) values[1];
63 TRACE_INTERPRETER = (Boolean) values[2];
64 TRACE_METHOD_LINKAGE = (Boolean) values[3];
65 COMPILE_THRESHOLD = (Integer) values[4];
68 /*non-public*/ static String getNameString(MethodHandle target, MethodType type) {
71 MemberName name = null;
73 name = target.internalMemberName();
75 return "invoke" + type;
76 return name.getName() + type;
79 /*non-public*/ static String getNameString(MethodHandle target, MethodHandle typeHolder) {
80 return getNameString(target, typeHolder == null ? (MethodType) null : typeHolder.type());
83 /*non-public*/ static String getNameString(MethodHandle target) {
84 return getNameString(target, (MethodType) null);
87 /*non-public*/ static String addTypeString(Object obj, MethodHandle target) {
88 String str = String.valueOf(obj);
89 if (target == null) return str;
90 int paren = str.indexOf('(');
91 if (paren >= 0) str = str.substring(0, paren);
92 return str + target.type();
95 // handy shared exception makers (they simplify the common case code)
96 /*non-public*/ static InternalError newInternalError(String message, Throwable cause) {
97 return new InternalError(message, cause);
99 /*non-public*/ static InternalError newInternalError(Throwable cause) {
100 return new InternalError(cause);
102 /*non-public*/ static RuntimeException newIllegalStateException(String message) {
103 return new IllegalStateException(message);
105 /*non-public*/ static RuntimeException newIllegalStateException(String message, Object obj) {
106 return new IllegalStateException(message(message, obj));
108 /*non-public*/ static RuntimeException newIllegalArgumentException(String message) {
109 return new IllegalArgumentException(message);
111 /*non-public*/ static RuntimeException newIllegalArgumentException(String message, Object obj) {
112 return new IllegalArgumentException(message(message, obj));
114 /*non-public*/ static RuntimeException newIllegalArgumentException(String message, Object obj, Object obj2) {
115 return new IllegalArgumentException(message(message, obj, obj2));
117 /*non-public*/ static Error uncaughtException(Throwable ex) {
118 throw newInternalError("uncaught exception", ex);
121 throw new AssertionError("NYI");
123 private static String message(String message, Object obj) {
124 if (obj != null) message = message + ": " + obj;
127 private static String message(String message, Object obj, Object obj2) {
128 if (obj != null || obj2 != null) message = message + ": " + obj + ", " + obj2;