61 * which=0 retrieves MethodHandlePushLimit
62 * which=1 retrieves stack slot push size (in address units)
63 */
64 static native int getConstant(int which);
65
66 static final boolean COUNT_GWT;
67
68 /// CallSite support
69
70 /** Tell the JVM that we need to change the target of a CallSite. */
71 static native void setCallSiteTargetNormal(CallSite site, MethodHandle target);
72 static native void setCallSiteTargetVolatile(CallSite site, MethodHandle target);
73
74 private static native void registerNatives();
75 static {
76 registerNatives();
77 COUNT_GWT = getConstant(Constants.GC_COUNT_GWT) != 0;
78
79 // The JVM calls MethodHandleNatives.<clinit>. Cascade the <clinit> calls as needed:
80 MethodHandleImpl.initStatics();
81 }
82
83 // All compile-time constants go here.
84 // There is an opportunity to check them against the JVM's idea of them.
85 static class Constants {
86 Constants() { } // static only
87 // MethodHandleImpl
88 static final int // for getConstant
89 GC_COUNT_GWT = 4,
90 GC_LAMBDA_SUPPORT = 5;
91
92 // MemberName
93 // The JVM uses values of -2 and above for vtable indexes.
94 // Field values are simple positive offsets.
95 // Ref: src/share/vm/oops/methodOop.hpp
96 // This value is negative enough to avoid such numbers,
97 // but not too negative.
98 static final int
99 MN_IS_METHOD = 0x00010000, // method (not constructor)
100 MN_IS_CONSTRUCTOR = 0x00020000, // constructor
101 MN_IS_FIELD = 0x00040000, // field
276 }
277 static {
278 assert(verifyConstants());
279 }
280
281 // Up-calls from the JVM.
282 // These must NOT be public.
283
284 /**
285 * The JVM is linking an invokedynamic instruction. Create a reified call site for it.
286 */
287 static MemberName linkCallSite(Object callerObj,
288 Object bootstrapMethodObj,
289 Object nameObj, Object typeObj,
290 Object staticArguments,
291 Object[] appendixResult) {
292 MethodHandle bootstrapMethod = (MethodHandle)bootstrapMethodObj;
293 Class<?> caller = (Class<?>)callerObj;
294 String name = nameObj.toString().intern();
295 MethodType type = (MethodType)typeObj;
296 CallSite callSite = CallSite.makeSite(bootstrapMethod,
297 name,
298 type,
299 staticArguments,
300 caller);
301 if (callSite instanceof ConstantCallSite) {
302 appendixResult[0] = callSite.dynamicInvoker();
303 return Invokers.linkToTargetMethod(type);
304 } else {
305 appendixResult[0] = callSite;
306 return Invokers.linkToCallSiteMethod(type);
307 }
308 }
309
310 /**
311 * The JVM wants a pointer to a MethodType. Oblige it by finding or creating one.
312 */
313 static MethodType findMethodHandleType(Class<?> rtype, Class<?>[] ptypes) {
314 return MethodType.makeImpl(rtype, ptypes, true);
315 }
316
317 /**
318 * The JVM wants to link a call site that requires a dynamic type check.
319 * Name is a type-checking invoker, invokeExact or invoke.
320 * Return a JVM method (MemberName) to handle the invoking.
321 * The method assumes the following arguments on the stack:
322 * 0: the method handle being invoked
323 * 1-N: the arguments to the method handle invocation
324 * N+1: an optional, implicitly added argument (typically the given MethodType)
325 * <p>
326 * The nominal method at such a call site is an instance of
327 * a signature-polymorphic method (see @PolymorphicSignature).
328 * Such method instances are user-visible entities which are
|
61 * which=0 retrieves MethodHandlePushLimit
62 * which=1 retrieves stack slot push size (in address units)
63 */
64 static native int getConstant(int which);
65
66 static final boolean COUNT_GWT;
67
68 /// CallSite support
69
70 /** Tell the JVM that we need to change the target of a CallSite. */
71 static native void setCallSiteTargetNormal(CallSite site, MethodHandle target);
72 static native void setCallSiteTargetVolatile(CallSite site, MethodHandle target);
73
74 private static native void registerNatives();
75 static {
76 registerNatives();
77 COUNT_GWT = getConstant(Constants.GC_COUNT_GWT) != 0;
78
79 // The JVM calls MethodHandleNatives.<clinit>. Cascade the <clinit> calls as needed:
80 MethodHandleImpl.initStatics();
81 }
82
83 // All compile-time constants go here.
84 // There is an opportunity to check them against the JVM's idea of them.
85 static class Constants {
86 Constants() { } // static only
87 // MethodHandleImpl
88 static final int // for getConstant
89 GC_COUNT_GWT = 4,
90 GC_LAMBDA_SUPPORT = 5;
91
92 // MemberName
93 // The JVM uses values of -2 and above for vtable indexes.
94 // Field values are simple positive offsets.
95 // Ref: src/share/vm/oops/methodOop.hpp
96 // This value is negative enough to avoid such numbers,
97 // but not too negative.
98 static final int
99 MN_IS_METHOD = 0x00010000, // method (not constructor)
100 MN_IS_CONSTRUCTOR = 0x00020000, // constructor
101 MN_IS_FIELD = 0x00040000, // field
276 }
277 static {
278 assert(verifyConstants());
279 }
280
281 // Up-calls from the JVM.
282 // These must NOT be public.
283
284 /**
285 * The JVM is linking an invokedynamic instruction. Create a reified call site for it.
286 */
287 static MemberName linkCallSite(Object callerObj,
288 Object bootstrapMethodObj,
289 Object nameObj, Object typeObj,
290 Object staticArguments,
291 Object[] appendixResult) {
292 MethodHandle bootstrapMethod = (MethodHandle)bootstrapMethodObj;
293 Class<?> caller = (Class<?>)callerObj;
294 String name = nameObj.toString().intern();
295 MethodType type = (MethodType)typeObj;
296 if (!TRACE_METHOD_LINKAGE)
297 return linkCallSiteImpl(caller, bootstrapMethod, name, type,
298 staticArguments, appendixResult);
299 return linkCallSiteTracing(caller, bootstrapMethod, name, type,
300 staticArguments, appendixResult);
301 }
302 static MemberName linkCallSiteImpl(Class<?> caller,
303 MethodHandle bootstrapMethod,
304 String name, MethodType type,
305 Object staticArguments,
306 Object[] appendixResult) {
307 CallSite callSite = CallSite.makeSite(bootstrapMethod,
308 name,
309 type,
310 staticArguments,
311 caller);
312 if (callSite instanceof ConstantCallSite) {
313 appendixResult[0] = callSite.dynamicInvoker();
314 return Invokers.linkToTargetMethod(type);
315 } else {
316 appendixResult[0] = callSite;
317 return Invokers.linkToCallSiteMethod(type);
318 }
319 }
320 // Tracing logic:
321 static MemberName linkCallSiteTracing(Class<?> caller,
322 MethodHandle bootstrapMethod,
323 String name, MethodType type,
324 Object staticArguments,
325 Object[] appendixResult) {
326 Object bsmReference = bootstrapMethod.internalMemberName();
327 if (bsmReference == null) bsmReference = bootstrapMethod;
328 Object staticArglist = (staticArguments instanceof Object[] ?
329 java.util.Arrays.asList((Object[]) staticArguments) :
330 staticArguments);
331 System.out.println("linkCallSite "+caller.getName()+" "+
332 bsmReference+" "+
333 name+type+"/"+staticArglist);
334 try {
335 MemberName res = linkCallSiteImpl(caller, bootstrapMethod, name, type,
336 staticArguments, appendixResult);
337 System.out.println("linkCallSite => "+res+" + "+appendixResult[0]);
338 return res;
339 } catch (Throwable ex) {
340 System.out.println("linkCallSite => throw "+ex);
341 throw ex;
342 }
343 }
344
345 /**
346 * The JVM wants a pointer to a MethodType. Oblige it by finding or creating one.
347 */
348 static MethodType findMethodHandleType(Class<?> rtype, Class<?>[] ptypes) {
349 return MethodType.makeImpl(rtype, ptypes, true);
350 }
351
352 /**
353 * The JVM wants to link a call site that requires a dynamic type check.
354 * Name is a type-checking invoker, invokeExact or invoke.
355 * Return a JVM method (MemberName) to handle the invoking.
356 * The method assumes the following arguments on the stack:
357 * 0: the method handle being invoked
358 * 1-N: the arguments to the method handle invocation
359 * N+1: an optional, implicitly added argument (typically the given MethodType)
360 * <p>
361 * The nominal method at such a call site is an instance of
362 * a signature-polymorphic method (see @PolymorphicSignature).
363 * Such method instances are user-visible entities which are
|