29 import java.security.PrivilegedAction;
30 import sun.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 Integer COMPILE_THRESHOLD;
49 static {
50 final Object[] values = { false, false, false, false, null };
51 AccessController.doPrivileged(new PrivilegedAction<Void>() {
52 public Void run() {
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");
58 return null;
59 }
60 });
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];
66 }
67
68 /** Tell if any of the debugging switches are turned on.
69 * If this is the case, it is reasonable to perform extra checks or save extra information.
70 */
71 /*non-public*/ static boolean debugEnabled() {
72 return (DEBUG_METHOD_HANDLE_NAMES |
73 DUMP_CLASS_FILES |
74 TRACE_INTERPRETER |
75 TRACE_METHOD_LINKAGE);
76 }
77
78 /*non-public*/ static String getNameString(MethodHandle target, MethodType type) {
79 if (type == null)
80 type = target.type();
81 MemberName name = null;
82 if (target != null)
83 name = target.internalMemberName();
84 if (name == null)
85 return "invoke" + type;
|
29 import java.security.PrivilegedAction;
30 import sun.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 Integer COMPILE_THRESHOLD;
49 static final int PROFILE_LEVEL;
50
51 static {
52 final Object[] values = { false, false, false, false, null, null };
53 AccessController.doPrivileged(new PrivilegedAction<Void>() {
54 public Void run() {
55 values[0] = Boolean.getBoolean("java.lang.invoke.MethodHandle.DEBUG_NAMES");
56 values[1] = Boolean.getBoolean("java.lang.invoke.MethodHandle.DUMP_CLASS_FILES");
57 values[2] = Boolean.getBoolean("java.lang.invoke.MethodHandle.TRACE_INTERPRETER");
58 values[3] = Boolean.getBoolean("java.lang.invoke.MethodHandle.TRACE_METHOD_LINKAGE");
59 values[4] = Integer.getInteger("java.lang.invoke.MethodHandle.COMPILE_THRESHOLD");
60 values[5] = Integer.getInteger("java.lang.invoke.MethodHandle.PROFILE_LEVEL", 0);
61
62 return null;
63 }
64 });
65 DEBUG_METHOD_HANDLE_NAMES = (Boolean) values[0];
66 DUMP_CLASS_FILES = (Boolean) values[1];
67 TRACE_INTERPRETER = (Boolean) values[2];
68 TRACE_METHOD_LINKAGE = (Boolean) values[3];
69 COMPILE_THRESHOLD = (Integer) values[4];
70 PROFILE_LEVEL = (Integer) values[5];
71 }
72
73 /** Tell if any of the debugging switches are turned on.
74 * If this is the case, it is reasonable to perform extra checks or save extra information.
75 */
76 /*non-public*/ static boolean debugEnabled() {
77 return (DEBUG_METHOD_HANDLE_NAMES |
78 DUMP_CLASS_FILES |
79 TRACE_INTERPRETER |
80 TRACE_METHOD_LINKAGE);
81 }
82
83 /*non-public*/ static String getNameString(MethodHandle target, MethodType type) {
84 if (type == null)
85 type = target.type();
86 MemberName name = null;
87 if (target != null)
88 name = target.internalMemberName();
89 if (name == null)
90 return "invoke" + type;
|