@@ -9532,7 +9532,21 @@ class INTERPRETER_CLASS
9532
9532
#endif /* defined(J9VM_OPT_METHOD_HANDLE) */
9533
9533
}
9534
9534
9535
- #if defined(J9VM_OPT_OPENJDK_METHODHANDLE)
9535
+ #if defined(J9VM_OPT_OPENJDK_METHODHANDLE)
9536
+
9537
+ VMINLINE bool
9538
+ j9ObjIsNull (j9object_t j9Obj, bool fromJIT, REGISTER_ARGS_LIST, UDATA decSP)
9539
+ {
9540
+ if (J9_UNEXPECTED (NULL == j9Obj)) {
9541
+ if (fromJIT) {
9542
+ _sp -= decSP;
9543
+ buildJITResolveFrame (REGISTER_ARGS);
9544
+ }
9545
+ return true ;
9546
+ }
9547
+ return false ;
9548
+ }
9549
+
9536
9550
/* This INL only covers invokeBasic dispatched directly from bytecode, invokeBasic calls
9537
9551
* dispatched from linkToVirtual is inlined to avoid need of flags and tempValues to
9538
9552
* pass the correct argCount during VM transition since the ramCP index still points
@@ -9558,23 +9572,23 @@ class INTERPRETER_CLASS
9558
9572
mhReceiverIndex = (methodIndexAndArgCount & 0xFF );
9559
9573
}
9560
9574
9575
+ j9object_t lambdaForm = NULL ;
9576
+ j9object_t memberName = NULL ;
9561
9577
j9object_t mhReceiver = ((j9object_t *)_sp)[mhReceiverIndex];
9562
- if (J9_UNEXPECTED (NULL == mhReceiver)) {
9563
- if (fromJIT) {
9564
- buildJITResolveFrame (REGISTER_ARGS);
9565
- }
9566
- return THROW_NPE;
9578
+ if (j9ObjIsNull (mhReceiver, fromJIT, REGISTER_ARGS, 0 )) {
9579
+ rc = THROW_NPE;
9580
+ goto done;
9567
9581
}
9568
9582
9569
- j9object_t lambdaForm = J9VMJAVALANGINVOKEMETHODHANDLE_FORM (_currentThread, mhReceiver);
9570
- j9object_t memberName = J9VMJAVALANGINVOKELAMBDAFORM_VMENTRY (_currentThread, lambdaForm);
9583
+ lambdaForm = J9VMJAVALANGINVOKEMETHODHANDLE_FORM (_currentThread, mhReceiver);
9584
+ memberName = J9VMJAVALANGINVOKELAMBDAFORM_VMENTRY (_currentThread, lambdaForm);
9571
9585
_sendMethod = (J9Method *)(UDATA)J9OBJECT_U64_LOAD (_currentThread, memberName, _vm->vmtargetOffset );
9572
9586
9573
9587
if (fromJIT) {
9574
9588
VM_JITInterface::restoreJITReturnAddress (_currentThread, _sp, (void *)_literals);
9575
9589
rc = j2iTransition (REGISTER_ARGS, true );
9576
9590
}
9577
-
9591
+ done:
9578
9592
return rc;
9579
9593
}
9580
9594
@@ -9588,8 +9602,9 @@ class INTERPRETER_CLASS
9588
9602
9589
9603
/* Pop memberNameObject from the stack. */
9590
9604
j9object_t memberNameObject = *(j9object_t *)_sp++;
9591
- if (J9_UNEXPECTED (NULL == memberNameObject)) {
9592
- goto throw_npe;
9605
+ if (j9ObjIsNull (memberNameObject, fromJIT, REGISTER_ARGS, true )) {
9606
+ rc = THROW_NPE;
9607
+ goto done;
9593
9608
}
9594
9609
9595
9610
_sendMethod = (J9Method *)(UDATA)J9OBJECT_U64_LOAD (_currentThread, memberNameObject, _vm->vmtargetOffset );
@@ -9600,8 +9615,9 @@ class INTERPRETER_CLASS
9600
9615
9601
9616
if (J9_ARE_NO_BITS_SET (romMethod->modifiers , J9AccStatic)) {
9602
9617
j9object_t mhReceiver = ((j9object_t *)_sp)[methodArgCount - 1 ];
9603
- if (J9_UNEXPECTED (NULL == mhReceiver)) {
9604
- goto throw_npe;
9618
+ if (j9ObjIsNull (mhReceiver, false , REGISTER_ARGS, false )) {
9619
+ rc = THROW_NPE;
9620
+ goto done;
9605
9621
}
9606
9622
}
9607
9623
}
@@ -9642,38 +9658,33 @@ class INTERPRETER_CLASS
9642
9658
VM_JITInterface::restoreJITReturnAddress (_currentThread, _sp, (void *)_literals);
9643
9659
rc = j2iTransition (REGISTER_ARGS, true );
9644
9660
}
9645
-
9661
+ done:
9646
9662
return rc;
9647
-
9648
- throw_npe:
9649
- if (fromJIT) {
9650
- /* Restore SP to before popping memberNameObject. */
9651
- _sp -= 1 ;
9652
- buildJITResolveFrame (REGISTER_ARGS);
9653
- }
9654
- return THROW_NPE;
9655
9663
}
9656
9664
9657
9665
VMINLINE VM_BytecodeAction
9658
9666
linkToVirtual (REGISTER_ARGS_LIST)
9659
9667
{
9660
9668
VM_BytecodeAction rc = GOTO_RUN_METHOD;
9669
+ J9Method *method = NULL ;
9670
+ J9ROMMethod *romMethod = NULL ;
9671
+ UDATA methodArgCount = 0 ;
9672
+ bool isInvokeBasic = false ;
9673
+ j9object_t receiverObject = NULL ;
9674
+ UDATA vTableOffset = 0 ;
9675
+ J9Class *receiverClass = NULL ;
9661
9676
bool fromJIT = J9_ARE_ANY_BITS_SET (jitStackFrameFlags (REGISTER_ARGS, 0 ), J9_SSF_JIT_NATIVE_TRANSITION_FRAME);
9662
9677
9663
9678
/* Pop memberNameObject from the stack. */
9664
9679
j9object_t memberNameObject = *(j9object_t *)_sp++;
9665
- if (J9_UNEXPECTED (NULL == memberNameObject)) {
9666
- if (fromJIT) {
9667
- /* Restore SP to before popping memberNameObject. */
9668
- _sp -= 1 ;
9669
- buildJITResolveFrame (REGISTER_ARGS);
9670
- }
9671
- return THROW_NPE;
9680
+ if (j9ObjIsNull (memberNameObject, fromJIT, REGISTER_ARGS, true )) {
9681
+ rc = THROW_NPE;
9682
+ goto done;
9672
9683
}
9673
9684
9674
- J9Method * method = (J9Method *)(UDATA)J9OBJECT_U64_LOAD (_currentThread, memberNameObject, _vm->vmtargetOffset );
9675
- J9ROMMethod * romMethod = J9_ROM_METHOD_FROM_RAM_METHOD (method);
9676
- UDATA methodArgCount = 0 ;
9685
+ method = (J9Method *)(UDATA)J9OBJECT_U64_LOAD (_currentThread, memberNameObject, _vm->vmtargetOffset );
9686
+ romMethod = J9_ROM_METHOD_FROM_RAM_METHOD (method);
9687
+ methodArgCount = 0 ;
9677
9688
bool isInvokeBasic = (J9_BCLOOP_SEND_TARGET_METHODHANDLE_INVOKEBASIC == J9_BCLOOP_DECODE_SEND_TARGET (method->methodRunAddress ));
9678
9689
9679
9690
/* In MethodHandle.loop API it may generate a invokeBasic NamedFunction (see LambdaForm$NamedFunction(MethodType basicInvokerType))
@@ -9688,14 +9699,10 @@ class INTERPRETER_CLASS
9688
9699
methodArgCount = romMethod->argCount ;
9689
9700
}
9690
9701
9691
- j9object_t receiverObject = ((j9object_t *)_sp)[methodArgCount - 1 ];
9692
- if (J9_UNEXPECTED (NULL == receiverObject)) {
9693
- if (fromJIT) {
9694
- /* Restore SP to before popping memberNameObject. */
9695
- _sp -= 1 ;
9696
- buildJITResolveFrame (REGISTER_ARGS);
9697
- }
9698
- return THROW_NPE;
9702
+ receiverObject = ((j9object_t *)_sp)[methodArgCount - 1 ];
9703
+ if (j9ObjIsNull (receiverObject, fromJIT, REGISTER_ARGS, true )) {
9704
+ rc = THROW_NPE;
9705
+ goto done;
9699
9706
}
9700
9707
9701
9708
/* The vTable offset has been stored in memberNameObject.vmindex.
@@ -9706,8 +9713,8 @@ class INTERPRETER_CLASS
9706
9713
* In that case, MemberName resolution has already done the iTable walk to get the corresponding vTable offset in
9707
9714
* C and stored it in vmindex. The receiver is always an instance of C (or a subclass).
9708
9715
*/
9709
- UDATA vTableOffset = (UDATA)J9OBJECT_U64_LOAD (_currentThread, memberNameObject, _vm->vmindexOffset );
9710
- J9Class * receiverClass = J9OBJECT_CLAZZ (_currentThread, receiverObject);
9716
+ vTableOffset = (UDATA)J9OBJECT_U64_LOAD (_currentThread, memberNameObject, _vm->vmindexOffset );
9717
+ receiverClass = J9OBJECT_CLAZZ (_currentThread, receiverObject);
9711
9718
_sendMethod = *(J9Method **)(((UDATA)receiverClass) + vTableOffset);
9712
9719
9713
9720
/* The invokeBasic INL uses the methodArgCount from ramCP to locate the receiver object,
@@ -9734,7 +9741,7 @@ class INTERPRETER_CLASS
9734
9741
VM_JITInterface::restoreJITReturnAddress (_currentThread, _sp, (void *)_literals);
9735
9742
rc = j2iTransition (REGISTER_ARGS, true );
9736
9743
}
9737
-
9744
+ done:
9738
9745
return rc;
9739
9746
}
9740
9747
@@ -9755,12 +9762,7 @@ class INTERPRETER_CLASS
9755
9762
9756
9763
/* Pop memberNameObject from the stack. */
9757
9764
j9object_t memberNameObject = *(j9object_t *)_sp++;
9758
- if (J9_UNEXPECTED (NULL == memberNameObject)) {
9759
- if (fromJIT) {
9760
- /* Restore SP to before popping memberNameObject. */
9761
- _sp -= 1 ;
9762
- buildJITResolveFrame (REGISTER_ARGS);
9763
- }
9765
+ if (j9ObjIsNull (memberNameObject, fromJIT, REGISTER_ARGS, true )) {
9764
9766
rc = THROW_NPE;
9765
9767
goto done;
9766
9768
}
@@ -9770,12 +9772,7 @@ class INTERPRETER_CLASS
9770
9772
methodArgCount = romMethod->argCount ;
9771
9773
9772
9774
receiverObject = ((j9object_t *)_sp)[methodArgCount - 1 ];
9773
- if (J9_UNEXPECTED (NULL == receiverObject)) {
9774
- if (fromJIT) {
9775
- /* Restore SP to before popping memberNameObject. */
9776
- _sp -= 1 ;
9777
- buildJITResolveFrame (REGISTER_ARGS);
9778
- }
9775
+ if (j9ObjIsNull (receiverObject, fromJIT, REGISTER_ARGS, true )) {
9779
9776
rc = THROW_NPE;
9780
9777
goto done;
9781
9778
}
@@ -9853,6 +9850,11 @@ class INTERPRETER_CLASS
9853
9850
linkToNative (REGISTER_ARGS_LIST)
9854
9851
{
9855
9852
VM_BytecodeAction rc = GOTO_RUN_METHOD;
9853
+ j9object_t nepObject = NULL ;
9854
+ j9object_t methodType = NULL ;
9855
+ j9object_t invokeCacheArray = NULL ;
9856
+ j9object_t memberName = NULL ;
9857
+ j9object_t appendix = NULL ;
9856
9858
bool fromJIT = J9_ARE_ANY_BITS_SET (jitStackFrameFlags (REGISTER_ARGS, 0 ), J9_SSF_JIT_NATIVE_TRANSITION_FRAME);
9857
9859
9858
9860
/* Pop up the dummy argument (the placeholder for the method type of the bound MH)
@@ -9863,24 +9865,20 @@ class INTERPRETER_CLASS
9863
9865
}
9864
9866
9865
9867
j9object_t nativeMH = *(j9object_t *)_sp;
9866
- if (J9_UNEXPECTED (NULL == nativeMH)) {
9867
- if (fromJIT) {
9868
- /* Restore SP to before popping the dummy argument. */
9869
- _sp -= 1 ;
9870
- buildJITResolveFrame (REGISTER_ARGS);
9871
- }
9872
- return THROW_NPE;
9868
+ if (j9ObjIsNull (nativeMH, fromJIT, REGISTER_ARGS, true )) {
9869
+ rc = THROW_NPE;
9870
+ goto done;
9873
9871
}
9874
9872
9875
- j9object_t nepObject = J9VMJAVALANGINVOKENATIVEMETHODHANDLE_NEP (_currentThread, nativeMH);
9876
- j9object_t methodType = J9VMJAVALANGINVOKEMETHODHANDLE_TYPE (_currentThread, nepObject);
9873
+ nepObject = J9VMJAVALANGINVOKENATIVEMETHODHANDLE_NEP (_currentThread, nativeMH);
9874
+ methodType = J9VMJAVALANGINVOKEMETHODHANDLE_TYPE (_currentThread, nepObject);
9877
9875
UDATA methodArgCount = VM_VMHelpers::methodTypeParameterSlotCount (_currentThread, methodType);
9878
9876
9879
9877
/* The cache array stores the data (memberName & appendix) for the bound MH which
9880
9878
* has been resolved when generating the downcall handler.
9881
9879
*/
9882
- j9object_t invokeCacheArray = J9VMJAVALANGINVOKENATIVEMETHODHANDLE_INVOKECACHE (_currentThread, nativeMH);
9883
- j9object_t memberName = (j9object_t )J9JAVAARRAYOFOBJECT_LOAD (_currentThread, invokeCacheArray, 0 );
9880
+ invokeCacheArray = J9VMJAVALANGINVOKENATIVEMETHODHANDLE_INVOKECACHE (_currentThread, nativeMH);
9881
+ memberName = (j9object_t )J9JAVAARRAYOFOBJECT_LOAD (_currentThread, invokeCacheArray, 0 );
9884
9882
_sendMethod = (J9Method *)(UDATA)J9OBJECT_U64_LOAD (_currentThread, memberName, _vm->vmtargetOffset );
9885
9883
9886
9884
/* Shift arguments by 1 and place the NEP object as the placeholder before the first argument
@@ -9889,7 +9887,7 @@ class INTERPRETER_CLASS
9889
9887
memmove (_sp, _sp + 1 , methodArgCount * sizeof (UDATA));
9890
9888
_sp[methodArgCount] = (UDATA)nepObject;
9891
9889
9892
- j9object_t appendix = (j9object_t )J9JAVAARRAYOFOBJECT_LOAD (_currentThread, invokeCacheArray, 1 );
9890
+ appendix = (j9object_t )J9JAVAARRAYOFOBJECT_LOAD (_currentThread, invokeCacheArray, 1 );
9893
9891
/* The slot the dummy argument is replaced with the method type to ensure it works with
9894
9892
* and without JIT in terms of the argument count.
9895
9893
*/
@@ -9899,7 +9897,7 @@ class INTERPRETER_CLASS
9899
9897
VM_JITInterface::restoreJITReturnAddress (_currentThread, _sp, (void *)_literals);
9900
9898
rc = j2iTransition (REGISTER_ARGS, true );
9901
9899
}
9902
-
9900
+ done:
9903
9901
return rc;
9904
9902
}
9905
9903
#endif /* JAVA_SPEC_VERSION >= 22 */
0 commit comments