jaroslav@1646
|
1 |
/*
|
jaroslav@1646
|
2 |
* Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
|
jaroslav@1646
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
jaroslav@1646
|
4 |
*
|
jaroslav@1646
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
jaroslav@1646
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
jaroslav@1646
|
7 |
* published by the Free Software Foundation. Oracle designates this
|
jaroslav@1646
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
jaroslav@1646
|
9 |
* by Oracle in the LICENSE file that accompanied this code.
|
jaroslav@1646
|
10 |
*
|
jaroslav@1646
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
jaroslav@1646
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
jaroslav@1646
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
jaroslav@1646
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that
|
jaroslav@1646
|
15 |
* accompanied this code).
|
jaroslav@1646
|
16 |
*
|
jaroslav@1646
|
17 |
* You should have received a copy of the GNU General Public License version
|
jaroslav@1646
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
jaroslav@1646
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
jaroslav@1646
|
20 |
*
|
jaroslav@1646
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
jaroslav@1646
|
22 |
* or visit www.oracle.com if you need additional information or have any
|
jaroslav@1646
|
23 |
* questions.
|
jaroslav@1646
|
24 |
*/
|
jaroslav@1646
|
25 |
|
jaroslav@1646
|
26 |
package java.lang.invoke;
|
jaroslav@1646
|
27 |
|
jaroslav@1646
|
28 |
import java.security.AccessController;
|
jaroslav@1646
|
29 |
import java.security.PrivilegedAction;
|
jaroslav@1651
|
30 |
//import sun.misc.Unsafe;
|
jaroslav@1646
|
31 |
|
jaroslav@1646
|
32 |
/**
|
jaroslav@1646
|
33 |
* This class consists exclusively of static names internal to the
|
jaroslav@1646
|
34 |
* method handle implementation.
|
jaroslav@1646
|
35 |
* Usage: {@code import static java.lang.invoke.MethodHandleStatics.*}
|
jaroslav@1646
|
36 |
* @author John Rose, JSR 292 EG
|
jaroslav@1646
|
37 |
*/
|
jaroslav@1646
|
38 |
/*non-public*/ class MethodHandleStatics {
|
jaroslav@1646
|
39 |
|
jaroslav@1646
|
40 |
private MethodHandleStatics() { } // do not instantiate
|
jaroslav@1646
|
41 |
|
jaroslav@1651
|
42 |
// static final Unsafe UNSAFE = Unsafe.getUnsafe();
|
jaroslav@1646
|
43 |
|
jaroslav@1646
|
44 |
static final boolean DEBUG_METHOD_HANDLE_NAMES;
|
jaroslav@1646
|
45 |
static final boolean DUMP_CLASS_FILES;
|
jaroslav@1646
|
46 |
static final boolean TRACE_INTERPRETER;
|
jaroslav@1646
|
47 |
static final boolean TRACE_METHOD_LINKAGE;
|
jaroslav@1646
|
48 |
static final Integer COMPILE_THRESHOLD;
|
jaroslav@1646
|
49 |
static {
|
jaroslav@1646
|
50 |
final Object[] values = { false, false, false, false, null };
|
jaroslav@1646
|
51 |
AccessController.doPrivileged(new PrivilegedAction<Void>() {
|
jaroslav@1646
|
52 |
public Void run() {
|
jaroslav@1646
|
53 |
values[0] = Boolean.getBoolean("java.lang.invoke.MethodHandle.DEBUG_NAMES");
|
jaroslav@1646
|
54 |
values[1] = Boolean.getBoolean("java.lang.invoke.MethodHandle.DUMP_CLASS_FILES");
|
jaroslav@1646
|
55 |
values[2] = Boolean.getBoolean("java.lang.invoke.MethodHandle.TRACE_INTERPRETER");
|
jaroslav@1646
|
56 |
values[3] = Boolean.getBoolean("java.lang.invoke.MethodHandle.TRACE_METHOD_LINKAGE");
|
jaroslav@1646
|
57 |
values[4] = Integer.getInteger("java.lang.invoke.MethodHandle.COMPILE_THRESHOLD");
|
jaroslav@1646
|
58 |
return null;
|
jaroslav@1646
|
59 |
}
|
jaroslav@1646
|
60 |
});
|
jaroslav@1646
|
61 |
DEBUG_METHOD_HANDLE_NAMES = (Boolean) values[0];
|
jaroslav@1646
|
62 |
DUMP_CLASS_FILES = (Boolean) values[1];
|
jaroslav@1646
|
63 |
TRACE_INTERPRETER = (Boolean) values[2];
|
jaroslav@1646
|
64 |
TRACE_METHOD_LINKAGE = (Boolean) values[3];
|
jaroslav@1646
|
65 |
COMPILE_THRESHOLD = (Integer) values[4];
|
jaroslav@1646
|
66 |
}
|
jaroslav@1646
|
67 |
|
jaroslav@1646
|
68 |
/*non-public*/ static String getNameString(MethodHandle target, MethodType type) {
|
jaroslav@1646
|
69 |
if (type == null)
|
jaroslav@1646
|
70 |
type = target.type();
|
jaroslav@1646
|
71 |
MemberName name = null;
|
jaroslav@1646
|
72 |
if (target != null)
|
jaroslav@1646
|
73 |
name = target.internalMemberName();
|
jaroslav@1646
|
74 |
if (name == null)
|
jaroslav@1646
|
75 |
return "invoke" + type;
|
jaroslav@1646
|
76 |
return name.getName() + type;
|
jaroslav@1646
|
77 |
}
|
jaroslav@1646
|
78 |
|
jaroslav@1646
|
79 |
/*non-public*/ static String getNameString(MethodHandle target, MethodHandle typeHolder) {
|
jaroslav@1646
|
80 |
return getNameString(target, typeHolder == null ? (MethodType) null : typeHolder.type());
|
jaroslav@1646
|
81 |
}
|
jaroslav@1646
|
82 |
|
jaroslav@1646
|
83 |
/*non-public*/ static String getNameString(MethodHandle target) {
|
jaroslav@1646
|
84 |
return getNameString(target, (MethodType) null);
|
jaroslav@1646
|
85 |
}
|
jaroslav@1646
|
86 |
|
jaroslav@1646
|
87 |
/*non-public*/ static String addTypeString(Object obj, MethodHandle target) {
|
jaroslav@1646
|
88 |
String str = String.valueOf(obj);
|
jaroslav@1646
|
89 |
if (target == null) return str;
|
jaroslav@1646
|
90 |
int paren = str.indexOf('(');
|
jaroslav@1646
|
91 |
if (paren >= 0) str = str.substring(0, paren);
|
jaroslav@1646
|
92 |
return str + target.type();
|
jaroslav@1646
|
93 |
}
|
jaroslav@1646
|
94 |
|
jaroslav@1646
|
95 |
// handy shared exception makers (they simplify the common case code)
|
jaroslav@1646
|
96 |
/*non-public*/ static InternalError newInternalError(String message, Throwable cause) {
|
jaroslav@1646
|
97 |
return new InternalError(message, cause);
|
jaroslav@1646
|
98 |
}
|
jaroslav@1646
|
99 |
/*non-public*/ static InternalError newInternalError(Throwable cause) {
|
jaroslav@1646
|
100 |
return new InternalError(cause);
|
jaroslav@1646
|
101 |
}
|
jaroslav@1646
|
102 |
/*non-public*/ static RuntimeException newIllegalStateException(String message) {
|
jaroslav@1646
|
103 |
return new IllegalStateException(message);
|
jaroslav@1646
|
104 |
}
|
jaroslav@1646
|
105 |
/*non-public*/ static RuntimeException newIllegalStateException(String message, Object obj) {
|
jaroslav@1646
|
106 |
return new IllegalStateException(message(message, obj));
|
jaroslav@1646
|
107 |
}
|
jaroslav@1646
|
108 |
/*non-public*/ static RuntimeException newIllegalArgumentException(String message) {
|
jaroslav@1646
|
109 |
return new IllegalArgumentException(message);
|
jaroslav@1646
|
110 |
}
|
jaroslav@1646
|
111 |
/*non-public*/ static RuntimeException newIllegalArgumentException(String message, Object obj) {
|
jaroslav@1646
|
112 |
return new IllegalArgumentException(message(message, obj));
|
jaroslav@1646
|
113 |
}
|
jaroslav@1646
|
114 |
/*non-public*/ static RuntimeException newIllegalArgumentException(String message, Object obj, Object obj2) {
|
jaroslav@1646
|
115 |
return new IllegalArgumentException(message(message, obj, obj2));
|
jaroslav@1646
|
116 |
}
|
jaroslav@1646
|
117 |
/*non-public*/ static Error uncaughtException(Throwable ex) {
|
jaroslav@1646
|
118 |
throw newInternalError("uncaught exception", ex);
|
jaroslav@1646
|
119 |
}
|
jaroslav@1646
|
120 |
static Error NYI() {
|
jaroslav@1646
|
121 |
throw new AssertionError("NYI");
|
jaroslav@1646
|
122 |
}
|
jaroslav@1646
|
123 |
private static String message(String message, Object obj) {
|
jaroslav@1646
|
124 |
if (obj != null) message = message + ": " + obj;
|
jaroslav@1646
|
125 |
return message;
|
jaroslav@1646
|
126 |
}
|
jaroslav@1646
|
127 |
private static String message(String message, Object obj, Object obj2) {
|
jaroslav@1646
|
128 |
if (obj != null || obj2 != null) message = message + ": " + obj + ", " + obj2;
|
jaroslav@1646
|
129 |
return message;
|
jaroslav@1646
|
130 |
}
|
jaroslav@1646
|
131 |
}
|