author | attila |
Mon, 02 Mar 2015 14:33:55 +0100 | |
changeset 29282 | a8523237b66c |
parent 27210 | a04ede4787ba |
child 31279 | fef6f6ba3b02 |
permissions | -rw-r--r-- |
16147 | 1 |
/* |
16151 | 2 |
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. |
16147 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
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. |
|
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 |
||
16277 | 26 |
package jdk.nashorn.internal.lookup; |
16147 | 27 |
|
29282 | 28 |
import static jdk.nashorn.internal.runtime.JSType.isString; |
29 |
||
16155
a8ab83cbaa49
8005788: Loggers and their corresponding system properties not working correctly
lagergren
parents:
16151
diff
changeset
|
30 |
import java.io.ByteArrayOutputStream; |
16147 | 31 |
import java.io.PrintStream; |
32 |
import java.lang.invoke.MethodHandle; |
|
33 |
import java.lang.invoke.MethodHandles; |
|
34 |
import java.lang.invoke.MethodType; |
|
35 |
import java.lang.invoke.SwitchPoint; |
|
36 |
import java.lang.reflect.Method; |
|
37 |
import java.util.ArrayList; |
|
38 |
import java.util.Arrays; |
|
39 |
import java.util.List; |
|
40 |
import java.util.logging.Level; |
|
24745
3a6e1477362b
8041434: Add synchronization to the common global constants structure
lagergren
parents:
24744
diff
changeset
|
41 |
import jdk.nashorn.internal.runtime.Context; |
16173 | 42 |
import jdk.nashorn.internal.runtime.Debug; |
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
24745
diff
changeset
|
43 |
import jdk.nashorn.internal.runtime.ScriptObject; |
24744
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
44 |
import jdk.nashorn.internal.runtime.logging.DebugLogger; |
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
45 |
import jdk.nashorn.internal.runtime.logging.Loggable; |
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
46 |
import jdk.nashorn.internal.runtime.logging.Logger; |
16173 | 47 |
import jdk.nashorn.internal.runtime.options.Options; |
16147 | 48 |
|
49 |
/** |
|
50 |
* This class is abstraction for all method handle, switchpoint and method type |
|
51 |
* operations. This enables the functionality interface to be subclassed and |
|
27210
a04ede4787ba
8059813: Type Info Cache flag must must be documented
hannesw
parents:
26768
diff
changeset
|
52 |
* instrumented, as it has been proven vital to keep the number of method |
16147 | 53 |
* handles in the system down. |
16155
a8ab83cbaa49
8005788: Loggers and their corresponding system properties not working correctly
lagergren
parents:
16151
diff
changeset
|
54 |
* |
16147 | 55 |
* All operations of the above type should go through this class, and not |
56 |
* directly into java.lang.invoke |
|
16155
a8ab83cbaa49
8005788: Loggers and their corresponding system properties not working correctly
lagergren
parents:
16151
diff
changeset
|
57 |
* |
16147 | 58 |
*/ |
59 |
public final class MethodHandleFactory { |
|
60 |
||
61 |
private static final MethodHandles.Lookup PUBLIC_LOOKUP = MethodHandles.publicLookup(); |
|
62 |
private static final MethodHandles.Lookup LOOKUP = MethodHandles.lookup(); |
|
63 |
||
16155
a8ab83cbaa49
8005788: Loggers and their corresponding system properties not working correctly
lagergren
parents:
16151
diff
changeset
|
64 |
private static final Level TRACE_LEVEL = Level.INFO; |
16147 | 65 |
|
66 |
private MethodHandleFactory() { |
|
67 |
} |
|
68 |
||
69 |
/** |
|
70 |
* Runtime exception that collects every reason that a method handle lookup operation can go wrong |
|
71 |
*/ |
|
72 |
@SuppressWarnings("serial") |
|
73 |
public static class LookupException extends RuntimeException { |
|
74 |
/** |
|
75 |
* Constructor |
|
76 |
* @param e causing exception |
|
77 |
*/ |
|
78 |
public LookupException(final Exception e) { |
|
79 |
super(e); |
|
80 |
} |
|
81 |
} |
|
82 |
||
83 |
/** |
|
84 |
* Helper function that takes a class or an object with a toString override |
|
85 |
* and shortens it to notation after last dot. This is used to facilitiate |
|
86 |
* pretty printouts in various debug loggers - internal only |
|
87 |
* |
|
88 |
* @param obj class or object |
|
89 |
* |
|
90 |
* @return pretty version of object as string |
|
91 |
*/ |
|
92 |
public static String stripName(final Object obj) { |
|
93 |
if (obj == null) { |
|
94 |
return "null"; |
|
95 |
} |
|
96 |
||
97 |
if (obj instanceof Class) { |
|
98 |
return ((Class<?>)obj).getSimpleName(); |
|
99 |
} |
|
100 |
return obj.toString(); |
|
101 |
} |
|
102 |
||
24744
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
103 |
private static final MethodHandleFunctionality FUNC = new StandardMethodHandleFunctionality(); |
16147 | 104 |
private static final boolean PRINT_STACKTRACE = Options.getBooleanProperty("nashorn.methodhandles.debug.stacktrace"); |
105 |
||
106 |
/** |
|
107 |
* Return the method handle functionality used for all method handle operations |
|
108 |
* @return a method handle functionality implementation |
|
109 |
*/ |
|
24745
3a6e1477362b
8041434: Add synchronization to the common global constants structure
lagergren
parents:
24744
diff
changeset
|
110 |
public static MethodHandleFunctionality getFunctionality() { |
16147 | 111 |
return FUNC; |
112 |
} |
|
113 |
||
24744
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
114 |
private static final MethodHandle TRACE = FUNC.findStatic(LOOKUP, MethodHandleFactory.class, "traceArgs", MethodType.methodType(void.class, DebugLogger.class, String.class, int.class, Object[].class)); |
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
115 |
private static final MethodHandle TRACE_RETURN = FUNC.findStatic(LOOKUP, MethodHandleFactory.class, "traceReturn", MethodType.methodType(Object.class, DebugLogger.class, Object.class)); |
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
116 |
private static final MethodHandle TRACE_RETURN_VOID = FUNC.findStatic(LOOKUP, MethodHandleFactory.class, "traceReturnVoid", MethodType.methodType(void.class, DebugLogger.class)); |
24719 | 117 |
|
118 |
private static final String VOID_TAG = "[VOID]"; |
|
16147 | 119 |
|
26768
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
120 |
private static void err(final String str) { |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
121 |
Context.getContext().getErr().println(str); |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
122 |
} |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
123 |
|
16147 | 124 |
/** |
125 |
* Tracer that is applied before a value is returned from the traced function. It will output the return |
|
126 |
* value and its class |
|
127 |
* |
|
128 |
* @param value return value for filter |
|
129 |
* @return return value unmodified |
|
130 |
*/ |
|
131 |
static Object traceReturn(final DebugLogger logger, final Object value) { |
|
26768
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
132 |
final String str = " return" + |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
133 |
(VOID_TAG.equals(value) ? |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
134 |
";" : |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
135 |
" " + stripName(value) + "; // [type=" + (value == null ? "null]" : stripName(value.getClass()) + ']')); |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
136 |
if (logger == null) { |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
137 |
err(str); |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
138 |
} else if (logger.isEnabled()) { |
25821
fbb51e67d2a7
8048869: Reduce compile time by about 5% by removing the Class.casts from the AST nodes
lagergren
parents:
24778
diff
changeset
|
139 |
logger.log(TRACE_LEVEL, str); |
fbb51e67d2a7
8048869: Reduce compile time by about 5% by removing the Class.casts from the AST nodes
lagergren
parents:
24778
diff
changeset
|
140 |
} |
26768
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
141 |
|
16147 | 142 |
return value; |
143 |
} |
|
144 |
||
24719 | 145 |
static void traceReturnVoid(final DebugLogger logger) { |
146 |
traceReturn(logger, VOID_TAG); |
|
147 |
} |
|
148 |
||
16147 | 149 |
/** |
150 |
* Tracer that is applied before a function is called, printing the arguments |
|
151 |
* |
|
152 |
* @param tag tag to start the debug printout string |
|
153 |
* @param paramStart param index to start outputting from |
|
154 |
* @param args arguments to the function |
|
155 |
*/ |
|
156 |
static void traceArgs(final DebugLogger logger, final String tag, final int paramStart, final Object... args) { |
|
157 |
final StringBuilder sb = new StringBuilder(); |
|
158 |
||
159 |
sb.append(tag); |
|
160 |
||
161 |
for (int i = paramStart; i < args.length; i++) { |
|
162 |
if (i == paramStart) { |
|
163 |
sb.append(" => args: "); |
|
164 |
} |
|
165 |
||
166 |
sb.append('\''). |
|
167 |
append(stripName(argString(args[i]))). |
|
168 |
append('\''). |
|
169 |
append(' '). |
|
170 |
append('['). |
|
171 |
append("type="). |
|
172 |
append(args[i] == null ? "null" : stripName(args[i].getClass())). |
|
173 |
append(']'); |
|
174 |
||
175 |
if (i + 1 < args.length) { |
|
176 |
sb.append(", "); |
|
177 |
} |
|
178 |
} |
|
179 |
||
26768
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
180 |
if (logger == null) { |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
181 |
err(sb.toString()); |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
182 |
} else { |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
183 |
logger.log(TRACE_LEVEL, sb); |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
184 |
} |
16155
a8ab83cbaa49
8005788: Loggers and their corresponding system properties not working correctly
lagergren
parents:
16151
diff
changeset
|
185 |
stacktrace(logger); |
a8ab83cbaa49
8005788: Loggers and their corresponding system properties not working correctly
lagergren
parents:
16151
diff
changeset
|
186 |
} |
a8ab83cbaa49
8005788: Loggers and their corresponding system properties not working correctly
lagergren
parents:
16151
diff
changeset
|
187 |
|
a8ab83cbaa49
8005788: Loggers and their corresponding system properties not working correctly
lagergren
parents:
16151
diff
changeset
|
188 |
private static void stacktrace(final DebugLogger logger) { |
a8ab83cbaa49
8005788: Loggers and their corresponding system properties not working correctly
lagergren
parents:
16151
diff
changeset
|
189 |
if (!PRINT_STACKTRACE) { |
a8ab83cbaa49
8005788: Loggers and their corresponding system properties not working correctly
lagergren
parents:
16151
diff
changeset
|
190 |
return; |
16147 | 191 |
} |
16155
a8ab83cbaa49
8005788: Loggers and their corresponding system properties not working correctly
lagergren
parents:
16151
diff
changeset
|
192 |
final ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
a8ab83cbaa49
8005788: Loggers and their corresponding system properties not working correctly
lagergren
parents:
16151
diff
changeset
|
193 |
final PrintStream ps = new PrintStream(baos); |
a8ab83cbaa49
8005788: Loggers and their corresponding system properties not working correctly
lagergren
parents:
16151
diff
changeset
|
194 |
new Throwable().printStackTrace(ps); |
26768
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
195 |
final String st = baos.toString(); |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
196 |
if (logger == null) { |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
197 |
err(st); |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
198 |
} else { |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
199 |
logger.log(TRACE_LEVEL, st); |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
200 |
} |
16147 | 201 |
} |
202 |
||
203 |
private static String argString(final Object arg) { |
|
204 |
if (arg == null) { |
|
205 |
return "null"; |
|
206 |
} |
|
207 |
||
208 |
if (arg.getClass().isArray()) { |
|
209 |
final List<Object> list = new ArrayList<>(); |
|
210 |
for (final Object elem : (Object[])arg) { |
|
211 |
list.add('\'' + argString(elem) + '\''); |
|
212 |
} |
|
213 |
||
214 |
return list.toString(); |
|
215 |
} |
|
216 |
||
217 |
if (arg instanceof ScriptObject) { |
|
218 |
return arg.toString() + |
|
24720 | 219 |
" (map=" + Debug.id(((ScriptObject)arg).getMap()) + |
26768
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
220 |
')'; |
16147 | 221 |
} |
222 |
||
223 |
return arg.toString(); |
|
224 |
} |
|
225 |
||
226 |
/** |
|
227 |
* Add a debug printout to a method handle, tracing parameters and return values |
|
26768
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
228 |
* Output will be unconditional to stderr |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
229 |
* |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
230 |
* @param mh method handle to trace |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
231 |
* @param tag start of trace message |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
232 |
* @return traced method handle |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
233 |
*/ |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
234 |
public static MethodHandle addDebugPrintout(final MethodHandle mh, final Object tag) { |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
235 |
return addDebugPrintout(null, Level.OFF, mh, 0, true, tag); |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
236 |
} |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
237 |
|
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
238 |
/** |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
239 |
* Add a debug printout to a method handle, tracing parameters and return values |
16147 | 240 |
* |
241 |
* @param logger a specific logger to which to write the output |
|
24733
1e825be55fd1
8027043: Turn global accesses into MethodHandle.constant, with one chance of reassignment, e.g. x = value occuring once in the global scope is ok, twice is not.
lagergren
parents:
24720
diff
changeset
|
242 |
* @param level level over which to print |
16147 | 243 |
* @param mh method handle to trace |
244 |
* @param tag start of trace message |
|
245 |
* @return traced method handle |
|
246 |
*/ |
|
24733
1e825be55fd1
8027043: Turn global accesses into MethodHandle.constant, with one chance of reassignment, e.g. x = value occuring once in the global scope is ok, twice is not.
lagergren
parents:
24720
diff
changeset
|
247 |
public static MethodHandle addDebugPrintout(final DebugLogger logger, final Level level, final MethodHandle mh, final Object tag) { |
1e825be55fd1
8027043: Turn global accesses into MethodHandle.constant, with one chance of reassignment, e.g. x = value occuring once in the global scope is ok, twice is not.
lagergren
parents:
24720
diff
changeset
|
248 |
return addDebugPrintout(logger, level, mh, 0, true, tag); |
16147 | 249 |
} |
250 |
||
251 |
/** |
|
252 |
* Add a debug printout to a method handle, tracing parameters and return values |
|
26768
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
253 |
* Output will be unconditional to stderr |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
254 |
* |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
255 |
* @param mh method handle to trace |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
256 |
* @param paramStart first param to print/trace |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
257 |
* @param printReturnValue should we print/trace return value if available? |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
258 |
* @param tag start of trace message |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
259 |
* @return traced method handle |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
260 |
*/ |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
261 |
public static MethodHandle addDebugPrintout(final MethodHandle mh, final int paramStart, final boolean printReturnValue, final Object tag) { |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
262 |
return addDebugPrintout(null, Level.OFF, mh, paramStart, printReturnValue, tag); |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
263 |
} |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
264 |
|
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
265 |
/** |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
266 |
* Add a debug printout to a method handle, tracing parameters and return values |
16147 | 267 |
* |
268 |
* @param logger a specific logger to which to write the output |
|
24733
1e825be55fd1
8027043: Turn global accesses into MethodHandle.constant, with one chance of reassignment, e.g. x = value occuring once in the global scope is ok, twice is not.
lagergren
parents:
24720
diff
changeset
|
269 |
* @param level level over which to print |
16147 | 270 |
* @param mh method handle to trace |
271 |
* @param paramStart first param to print/trace |
|
272 |
* @param printReturnValue should we print/trace return value if available? |
|
273 |
* @param tag start of trace message |
|
274 |
* @return traced method handle |
|
275 |
*/ |
|
24733
1e825be55fd1
8027043: Turn global accesses into MethodHandle.constant, with one chance of reassignment, e.g. x = value occuring once in the global scope is ok, twice is not.
lagergren
parents:
24720
diff
changeset
|
276 |
public static MethodHandle addDebugPrintout(final DebugLogger logger, final Level level, final MethodHandle mh, final int paramStart, final boolean printReturnValue, final Object tag) { |
16147 | 277 |
final MethodType type = mh.type(); |
278 |
||
24719 | 279 |
//if there is no logger, or if it's set to log only coarser events |
280 |
//than the trace level, skip and return |
|
24733
1e825be55fd1
8027043: Turn global accesses into MethodHandle.constant, with one chance of reassignment, e.g. x = value occuring once in the global scope is ok, twice is not.
lagergren
parents:
24720
diff
changeset
|
281 |
if (logger != null && logger.levelCoarserThan(level)) { |
16147 | 282 |
return mh; |
283 |
} |
|
284 |
||
285 |
assert TRACE != null; |
|
286 |
||
287 |
MethodHandle trace = MethodHandles.insertArguments(TRACE, 0, logger, tag, paramStart); |
|
288 |
||
289 |
trace = MethodHandles.foldArguments( |
|
290 |
mh, |
|
291 |
trace.asCollector( |
|
292 |
Object[].class, |
|
293 |
type.parameterCount()). |
|
294 |
asType(type.changeReturnType(void.class))); |
|
295 |
||
296 |
final Class<?> retType = type.returnType(); |
|
24719 | 297 |
if (printReturnValue) { |
298 |
if (retType != void.class) { |
|
299 |
final MethodHandle traceReturn = MethodHandles.insertArguments(TRACE_RETURN, 0, logger); |
|
300 |
trace = MethodHandles.filterReturnValue(trace, |
|
301 |
traceReturn.asType( |
|
302 |
traceReturn.type().changeParameterType(0, retType).changeReturnType(retType))); |
|
303 |
} else { |
|
304 |
trace = MethodHandles.filterReturnValue(trace, MethodHandles.insertArguments(TRACE_RETURN_VOID, 0, logger)); |
|
305 |
} |
|
16147 | 306 |
} |
307 |
||
308 |
return trace; |
|
309 |
} |
|
310 |
||
311 |
/** |
|
24744
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
312 |
* Class that marshalls all method handle operations to the java.lang.invoke |
16147 | 313 |
* package. This exists only so that it can be subclassed and method handles created from |
314 |
* Nashorn made possible to instrument. |
|
315 |
* |
|
316 |
* All Nashorn classes should use the MethodHandleFactory for their method handle operations |
|
317 |
*/ |
|
24744
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
318 |
@Logger(name="methodhandles") |
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
319 |
private static class StandardMethodHandleFunctionality implements MethodHandleFunctionality, Loggable { |
16147 | 320 |
|
24744
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
321 |
// for bootstrapping reasons, because a lot of static fields use MH for lookups, we |
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
322 |
// need to set the logger when the Global object is finished. This means that we don't |
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
323 |
// get instrumentation for public static final MethodHandle SOMETHING = MH... in the builtin |
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
324 |
// classes, but that doesn't matter, because this is usually not where we want it |
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
325 |
private DebugLogger log = DebugLogger.DISABLED_LOGGER; |
16147 | 326 |
|
24744
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
327 |
public StandardMethodHandleFunctionality() { |
16147 | 328 |
} |
329 |
||
330 |
@Override |
|
24745
3a6e1477362b
8041434: Add synchronization to the common global constants structure
lagergren
parents:
24744
diff
changeset
|
331 |
public DebugLogger initLogger(final Context context) { |
3a6e1477362b
8041434: Add synchronization to the common global constants structure
lagergren
parents:
24744
diff
changeset
|
332 |
return this.log = context.getLogger(this.getClass()); |
16147 | 333 |
} |
334 |
||
335 |
@Override |
|
24744
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
336 |
public DebugLogger getLogger() { |
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
337 |
return log; |
24720 | 338 |
} |
339 |
||
16147 | 340 |
protected static String describe(final Object... data) { |
341 |
final StringBuilder sb = new StringBuilder(); |
|
342 |
||
343 |
for (int i = 0; i < data.length; i++) { |
|
344 |
final Object d = data[i]; |
|
345 |
if (d == null) { |
|
346 |
sb.append("<null> "); |
|
29282 | 347 |
} else if (isString(d)) { |
16147 | 348 |
sb.append(d.toString()); |
349 |
sb.append(' '); |
|
350 |
} else if (d.getClass().isArray()) { |
|
351 |
sb.append("[ "); |
|
352 |
for (final Object da : (Object[])d) { |
|
353 |
sb.append(describe(new Object[]{ da })).append(' '); |
|
354 |
} |
|
355 |
sb.append("] "); |
|
356 |
} else { |
|
357 |
sb.append(d) |
|
358 |
.append('{') |
|
359 |
.append(Integer.toHexString(System.identityHashCode(d))) |
|
360 |
.append('}'); |
|
361 |
} |
|
362 |
||
363 |
if (i + 1 < data.length) { |
|
364 |
sb.append(", "); |
|
365 |
} |
|
366 |
} |
|
367 |
||
368 |
return sb.toString(); |
|
369 |
} |
|
370 |
||
371 |
public MethodHandle debug(final MethodHandle master, final String str, final Object... args) { |
|
24744
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
372 |
if (log.isEnabled()) { |
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
373 |
if (PRINT_STACKTRACE) { |
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
374 |
stacktrace(log); |
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
375 |
} |
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
376 |
return addDebugPrintout(log, Level.INFO, master, Integer.MAX_VALUE, false, str + ' ' + describe(args)); |
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
377 |
} |
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
378 |
return master; |
16147 | 379 |
} |
380 |
||
381 |
@Override |
|
382 |
public MethodHandle filterArguments(final MethodHandle target, final int pos, final MethodHandle... filters) { |
|
24744
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
383 |
final MethodHandle mh = MethodHandles.filterArguments(target, pos, filters); |
16147 | 384 |
return debug(mh, "filterArguments", target, pos, filters); |
385 |
} |
|
386 |
||
387 |
@Override |
|
388 |
public MethodHandle filterReturnValue(final MethodHandle target, final MethodHandle filter) { |
|
24744
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
389 |
final MethodHandle mh = MethodHandles.filterReturnValue(target, filter); |
16147 | 390 |
return debug(mh, "filterReturnValue", target, filter); |
391 |
} |
|
392 |
||
393 |
@Override |
|
394 |
public MethodHandle guardWithTest(final MethodHandle test, final MethodHandle target, final MethodHandle fallback) { |
|
24744
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
395 |
final MethodHandle mh = MethodHandles.guardWithTest(test, target, fallback); |
16147 | 396 |
return debug(mh, "guardWithTest", test, target, fallback); |
397 |
} |
|
398 |
||
399 |
@Override |
|
400 |
public MethodHandle insertArguments(final MethodHandle target, final int pos, final Object... values) { |
|
24744
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
401 |
final MethodHandle mh = MethodHandles.insertArguments(target, pos, values); |
16147 | 402 |
return debug(mh, "insertArguments", target, pos, values); |
403 |
} |
|
404 |
||
405 |
@Override |
|
406 |
public MethodHandle dropArguments(final MethodHandle target, final int pos, final Class<?>... values) { |
|
24744
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
407 |
final MethodHandle mh = MethodHandles.dropArguments(target, pos, values); |
16147 | 408 |
return debug(mh, "dropArguments", target, pos, values); |
409 |
} |
|
410 |
||
411 |
@Override |
|
16173 | 412 |
public MethodHandle dropArguments(final MethodHandle target, final int pos, final List<Class<?>> values) { |
24744
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
413 |
final MethodHandle mh = MethodHandles.dropArguments(target, pos, values); |
16173 | 414 |
return debug(mh, "dropArguments", target, pos, values); |
415 |
} |
|
416 |
||
417 |
@Override |
|
16147 | 418 |
public MethodHandle asType(final MethodHandle handle, final MethodType type) { |
24744
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
419 |
final MethodHandle mh = handle.asType(type); |
16147 | 420 |
return debug(mh, "asType", handle, type); |
421 |
} |
|
422 |
||
423 |
@Override |
|
424 |
public MethodHandle bindTo(final MethodHandle handle, final Object x) { |
|
24744
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
425 |
final MethodHandle mh = handle.bindTo(x); |
16147 | 426 |
return debug(mh, "bindTo", handle, x); |
427 |
} |
|
428 |
||
429 |
@Override |
|
430 |
public MethodHandle foldArguments(final MethodHandle target, final MethodHandle combiner) { |
|
24744
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
431 |
final MethodHandle mh = MethodHandles.foldArguments(target, combiner); |
16147 | 432 |
return debug(mh, "foldArguments", target, combiner); |
433 |
} |
|
434 |
||
435 |
@Override |
|
436 |
public MethodHandle explicitCastArguments(final MethodHandle target, final MethodType type) { |
|
24744
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
437 |
final MethodHandle mh = MethodHandles.explicitCastArguments(target, type); |
16147 | 438 |
return debug(mh, "explicitCastArguments", target, type); |
439 |
} |
|
440 |
||
441 |
@Override |
|
442 |
public MethodHandle arrayElementGetter(final Class<?> type) { |
|
24744
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
443 |
final MethodHandle mh = MethodHandles.arrayElementGetter(type); |
16147 | 444 |
return debug(mh, "arrayElementGetter", type); |
445 |
} |
|
446 |
||
447 |
@Override |
|
448 |
public MethodHandle arrayElementSetter(final Class<?> type) { |
|
24744
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
449 |
final MethodHandle mh = MethodHandles.arrayElementSetter(type); |
16147 | 450 |
return debug(mh, "arrayElementSetter", type); |
451 |
} |
|
452 |
||
453 |
@Override |
|
454 |
public MethodHandle throwException(final Class<?> returnType, final Class<? extends Throwable> exType) { |
|
24744
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
455 |
final MethodHandle mh = MethodHandles.throwException(returnType, exType); |
16147 | 456 |
return debug(mh, "throwException", returnType, exType); |
457 |
} |
|
458 |
||
459 |
@Override |
|
24719 | 460 |
public MethodHandle catchException(final MethodHandle target, final Class<? extends Throwable> exType, final MethodHandle handler) { |
24744
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
461 |
final MethodHandle mh = MethodHandles.catchException(target, exType, handler); |
24719 | 462 |
return debug(mh, "catchException", exType); |
463 |
} |
|
464 |
||
465 |
@Override |
|
16147 | 466 |
public MethodHandle constant(final Class<?> type, final Object value) { |
24744
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
467 |
final MethodHandle mh = MethodHandles.constant(type, value); |
16147 | 468 |
return debug(mh, "constant", type, value); |
469 |
} |
|
470 |
||
471 |
@Override |
|
26768
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
472 |
public MethodHandle identity(final Class<?> type) { |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
473 |
final MethodHandle mh = MethodHandles.identity(type); |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
474 |
return debug(mh, "identity", type); |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
475 |
} |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
476 |
|
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
477 |
@Override |
16147 | 478 |
public MethodHandle asCollector(final MethodHandle handle, final Class<?> arrayType, final int arrayLength) { |
24744
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
479 |
final MethodHandle mh = handle.asCollector(arrayType, arrayLength); |
16147 | 480 |
return debug(mh, "asCollector", handle, arrayType, arrayLength); |
481 |
} |
|
482 |
||
483 |
@Override |
|
484 |
public MethodHandle asSpreader(final MethodHandle handle, final Class<?> arrayType, final int arrayLength) { |
|
24744
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
485 |
final MethodHandle mh = handle.asSpreader(arrayType, arrayLength); |
16147 | 486 |
return debug(mh, "asSpreader", handle, arrayType, arrayLength); |
487 |
} |
|
488 |
||
489 |
@Override |
|
490 |
public MethodHandle getter(final MethodHandles.Lookup explicitLookup, final Class<?> clazz, final String name, final Class<?> type) { |
|
24744
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
491 |
try { |
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
492 |
final MethodHandle mh = explicitLookup.findGetter(clazz, name, type); |
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
493 |
return debug(mh, "getter", explicitLookup, clazz, name, type); |
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
494 |
} catch (final NoSuchFieldException | IllegalAccessException e) { |
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
495 |
throw new LookupException(e); |
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
496 |
} |
16147 | 497 |
} |
498 |
||
499 |
@Override |
|
500 |
public MethodHandle staticGetter(final MethodHandles.Lookup explicitLookup, final Class<?> clazz, final String name, final Class<?> type) { |
|
24744
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
501 |
try { |
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
502 |
final MethodHandle mh = explicitLookup.findStaticGetter(clazz, name, type); |
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
503 |
return debug(mh, "static getter", explicitLookup, clazz, name, type); |
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
504 |
} catch (final NoSuchFieldException | IllegalAccessException e) { |
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
505 |
throw new LookupException(e); |
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
506 |
} |
16147 | 507 |
} |
508 |
||
509 |
@Override |
|
510 |
public MethodHandle setter(final MethodHandles.Lookup explicitLookup, final Class<?> clazz, final String name, final Class<?> type) { |
|
24744
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
511 |
try { |
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
512 |
final MethodHandle mh = explicitLookup.findSetter(clazz, name, type); |
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
513 |
return debug(mh, "setter", explicitLookup, clazz, name, type); |
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
514 |
} catch (final NoSuchFieldException | IllegalAccessException e) { |
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
515 |
throw new LookupException(e); |
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
516 |
} |
16147 | 517 |
} |
518 |
||
519 |
@Override |
|
520 |
public MethodHandle staticSetter(final MethodHandles.Lookup explicitLookup, final Class<?> clazz, final String name, final Class<?> type) { |
|
24744
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
521 |
try { |
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
522 |
final MethodHandle mh = explicitLookup.findStaticSetter(clazz, name, type); |
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
523 |
return debug(mh, "static setter", explicitLookup, clazz, name, type); |
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
524 |
} catch (final NoSuchFieldException | IllegalAccessException e) { |
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
525 |
throw new LookupException(e); |
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
526 |
} |
16147 | 527 |
} |
528 |
||
529 |
@Override |
|
530 |
public MethodHandle find(final Method method) { |
|
24744
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
531 |
try { |
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
532 |
final MethodHandle mh = PUBLIC_LOOKUP.unreflect(method); |
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
533 |
return debug(mh, "find", method); |
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
534 |
} catch (final IllegalAccessException e) { |
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
535 |
throw new LookupException(e); |
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
536 |
} |
16147 | 537 |
} |
538 |
||
539 |
@Override |
|
540 |
public MethodHandle findStatic(final MethodHandles.Lookup explicitLookup, final Class<?> clazz, final String name, final MethodType type) { |
|
24744
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
541 |
try { |
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
542 |
final MethodHandle mh = explicitLookup.findStatic(clazz, name, type); |
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
543 |
return debug(mh, "findStatic", explicitLookup, clazz, name, type); |
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
544 |
} catch (final NoSuchMethodException | IllegalAccessException e) { |
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
545 |
throw new LookupException(e); |
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
546 |
} |
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
547 |
} |
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
548 |
|
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
549 |
@Override |
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
550 |
public MethodHandle findSpecial(final MethodHandles.Lookup explicitLookup, final Class<?> clazz, final String name, final MethodType type, final Class<?> thisClass) { |
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
551 |
try { |
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
552 |
final MethodHandle mh = explicitLookup.findSpecial(clazz, name, type, thisClass); |
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
553 |
return debug(mh, "findSpecial", explicitLookup, clazz, name, type); |
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
554 |
} catch (final NoSuchMethodException | IllegalAccessException e) { |
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
555 |
throw new LookupException(e); |
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
556 |
} |
16147 | 557 |
} |
558 |
||
559 |
@Override |
|
560 |
public MethodHandle findVirtual(final MethodHandles.Lookup explicitLookup, final Class<?> clazz, final String name, final MethodType type) { |
|
24744
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
561 |
try { |
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
562 |
final MethodHandle mh = explicitLookup.findVirtual(clazz, name, type); |
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
563 |
return debug(mh, "findVirtual", explicitLookup, clazz, name, type); |
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
564 |
} catch (final NoSuchMethodException | IllegalAccessException e) { |
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
565 |
throw new LookupException(e); |
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
566 |
} |
16147 | 567 |
} |
568 |
||
569 |
@Override |
|
570 |
public SwitchPoint createSwitchPoint() { |
|
24744
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
571 |
final SwitchPoint sp = new SwitchPoint(); |
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
572 |
log.log(TRACE_LEVEL, "createSwitchPoint ", sp); |
16147 | 573 |
return sp; |
574 |
} |
|
575 |
||
576 |
@Override |
|
577 |
public MethodHandle guardWithTest(final SwitchPoint sp, final MethodHandle before, final MethodHandle after) { |
|
24744
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
578 |
final MethodHandle mh = sp.guardWithTest(before, after); |
16147 | 579 |
return debug(mh, "guardWithTest", sp, before, after); |
580 |
} |
|
581 |
||
582 |
@Override |
|
583 |
public MethodType type(final Class<?> returnType, final Class<?>... paramTypes) { |
|
24744
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
584 |
final MethodType mt = MethodType.methodType(returnType, paramTypes); |
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24743
diff
changeset
|
585 |
log.log(TRACE_LEVEL, "methodType ", returnType, " ", Arrays.toString(paramTypes), " ", mt); |
16147 | 586 |
return mt; |
587 |
} |
|
588 |
} |
|
589 |
} |