@@ -139,7 +139,7 @@ private MethodHandle makeVarHandleMethodInvoker(VarHandle.AccessMode ak, boolean
139
139
MethodType mtype = targetType ;
140
140
MethodType invokerType = mtype .insertParameterTypes (0 , VarHandle .class );
141
141
142
- LambdaForm lform = varHandleMethodInvokerHandleForm (ak , mtype , isExact );
142
+ LambdaForm lform = varHandleMethodInvokerHandleForm (mtype , isExact );
143
143
VarHandle .AccessDescriptor ad = new VarHandle .AccessDescriptor (mtype , ak .at .ordinal (), ak .ordinal ());
144
144
MethodHandle invoker = BoundMethodHandle .bindSingle (invokerType , lform , ad );
145
145
@@ -346,20 +346,22 @@ static LambdaForm invokeHandleForm(MethodType mtype, boolean customized, int whi
346
346
}
347
347
348
348
349
- static MemberName varHandleInvokeLinkerMethod (VarHandle .AccessMode ak , MethodType mtype ) {
350
- LambdaForm lform ;
351
- if (mtype .parameterSlotCount () <= MethodType .MAX_MH_ARITY - MH_LINKER_ARG_APPENDED ) {
352
- lform = varHandleMethodGenericLinkerHandleForm (ak , mtype );
353
- } else {
354
- // TODO
349
+ static MemberName varHandleInvokeLinkerMethod (MethodType mtype ) {
350
+ if (mtype .parameterSlotCount () > MethodType .MAX_MH_ARITY - MH_LINKER_ARG_APPENDED ) {
355
351
throw newInternalError ("Unsupported parameter slot count " + mtype .parameterSlotCount ());
356
352
}
353
+ LambdaForm lform = varHandleMethodGenericLinkerHandleForm (mtype );
357
354
return lform .vmentry ;
358
355
}
359
356
360
- private static LambdaForm varHandleMethodGenericLinkerHandleForm (VarHandle .AccessMode ak ,
361
- MethodType mtype ) {
362
- // TODO Cache form?
357
+ private static LambdaForm varHandleMethodGenericLinkerHandleForm (MethodType mtype ) {
358
+ mtype = mtype .basicType (); // normalize Z to I, String to Object, etc.
359
+
360
+ int which = MethodTypeForm .LF_VH_GEN_LINKER ;
361
+ LambdaForm lform = mtype .form ().cachedLambdaForm (which );
362
+ if (lform != null ) {
363
+ return lform ;
364
+ }
363
365
364
366
final int THIS_VH = 0 ;
365
367
final int ARG_BASE = THIS_VH + 1 ;
@@ -396,19 +398,26 @@ private static LambdaForm varHandleMethodGenericLinkerHandleForm(VarHandle.Acces
396
398
MethodType outCallType = mtype .insertParameterTypes (0 , VarHandle .class )
397
399
.basicType ();
398
400
names [LINKER_CALL ] = new Name (outCallType , outArgs );
399
- LambdaForm lform = new LambdaForm (ARG_LIMIT + 1 , names , VARHANDLE_LINKER );
401
+ lform = new LambdaForm (ARG_LIMIT + 1 , names , VARHANDLE_LINKER );
400
402
if (LambdaForm .debugNames ()) {
401
- String name = ak .methodName () + ":VarHandle_invoke_MT_" +
402
- shortenSignature (basicTypeSignature (mtype ));
403
+ String name = "VarHandle_invoke_MT_" + shortenSignature (basicTypeSignature (mtype ));
403
404
LambdaForm .associateWithDebugName (lform , name );
404
405
}
405
406
lform .compileToBytecode ();
407
+
408
+ lform = mtype .form ().setCachedLambdaForm (which , lform );
409
+
406
410
return lform ;
407
411
}
408
412
409
- private static LambdaForm varHandleMethodInvokerHandleForm (VarHandle .AccessMode ak ,
410
- MethodType mtype , boolean isExact ) {
411
- // TODO Cache form?
413
+ private static LambdaForm varHandleMethodInvokerHandleForm (MethodType mtype , boolean isExact ) {
414
+ mtype = mtype .basicType (); // normalize Z to I, String to Object, etc.
415
+
416
+ int which = (isExact ? MethodTypeForm .LF_VH_EX_INVOKER : MethodTypeForm .LF_VH_GEN_INVOKER );
417
+ LambdaForm lform = mtype .form ().cachedLambdaForm (which );
418
+ if (lform != null ) {
419
+ return lform ;
420
+ }
412
421
413
422
final int THIS_MH = 0 ;
414
423
final int CALL_VH = THIS_MH + 1 ;
@@ -448,17 +457,18 @@ private static LambdaForm varHandleMethodInvokerHandleForm(VarHandle.AccessMode
448
457
}
449
458
450
459
MethodType outCallType = mtype .insertParameterTypes (0 , VarHandle .class )
451
- .basicType ();
460
+ .basicType ();
452
461
names [LINKER_CALL ] = new Name (outCallType , outArgs );
453
462
Kind kind = isExact ? VARHANDLE_EXACT_INVOKER : VARHANDLE_INVOKER ;
454
- LambdaForm lform = new LambdaForm (ARG_LIMIT , names , kind );
463
+ lform = new LambdaForm (ARG_LIMIT , names , kind );
455
464
if (LambdaForm .debugNames ()) {
456
- String name = ak .methodName () +
457
- (isExact ? ":VarHandle_exactInvoker_" : ":VarHandle_invoker_" ) +
458
- shortenSignature (basicTypeSignature (mtype ));
465
+ String name = (isExact ? "VarHandle_exactInvoker_" : "VarHandle_invoker_" ) + shortenSignature (basicTypeSignature (mtype ));
459
466
LambdaForm .associateWithDebugName (lform , name );
460
467
}
461
468
lform .prepare ();
469
+
470
+ lform = mtype .form ().setCachedLambdaForm (which , lform );
471
+
462
472
return lform ;
463
473
}
464
474
@@ -473,12 +483,10 @@ static MethodHandle checkVarHandleGenericType(VarHandle handle, VarHandle.Access
473
483
// Test for exact match on invoker types
474
484
// TODO match with erased types and add cast of return value to lambda form
475
485
MethodHandle mh = handle .getMethodHandle (ad .mode );
476
- if (mh .type () == ad .symbolicMethodTypeInvoker ) {
477
- return mh ;
478
- }
479
- else {
486
+ if (mh .type () != ad .symbolicMethodTypeInvoker ) {
480
487
return mh .asType (ad .symbolicMethodTypeInvoker );
481
488
}
489
+ return mh ;
482
490
}
483
491
484
492
@ ForceInline
0 commit comments