Skip to content

Commit 11e99cc

Browse files
committed
Add check for throwDefaultConflict J9Method
Checks that the J9Method being invoked is not the special J9Method vm->initialMethods.throwDefaultConflict. This fixes a segfault that was happening when trying to load a bytecodes field containing 0x0 Signed-off-by: Matthew Hall <matthew.hall3@outlook.com>
1 parent eac2531 commit 11e99cc

File tree

1 file changed

+32
-60
lines changed

1 file changed

+32
-60
lines changed

runtime/vm/BytecodeInterpreter.hpp

Lines changed: 32 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,8 @@ class INTERPRETER_CLASS
614614
#endif /* defined(J9VM_OPT_METHOD_HANDLE) */
615615
}
616616

617+
#define isMethodDefaultConflictJ9Method(method) (method == _currentThread->javaVM->initialMethods.throwDefaultConflict)
618+
617619
VMINLINE VM_BytecodeAction
618620
j2iTransition(
619621
REGISTER_ARGS_LIST
@@ -623,9 +625,9 @@ class INTERPRETER_CLASS
623625
) {
624626
VM_JITInterface::disableRuntimeInstrumentation(_currentThread);
625627
VM_BytecodeAction rc = GOTO_RUN_METHOD;
626-
void* const jitReturnAddress = VM_JITInterface::fetchJITReturnAddress(_currentThread, _sp);
627-
J9ROMMethod* const romMethod = J9_ROM_METHOD_FROM_RAM_METHOD(_sendMethod);
628-
void* const exitPoint = j2iReturnPoint(J9ROMMETHOD_SIGNATURE(romMethod));
628+
void *const jitReturnAddress = VM_JITInterface::fetchJITReturnAddress(_currentThread, _sp);
629+
J9ROMMethod *const romMethod = J9_ROM_METHOD_FROM_RAM_METHOD(_sendMethod);
630+
void *const exitPoint = j2iReturnPoint(J9ROMMETHOD_SIGNATURE(romMethod));
629631
if (J9_ARE_ANY_BITS_SET(romMethod->modifiers, J9AccNative | J9AccAbstract)) {
630632
_literals = (J9Method*)jitReturnAddress;
631633
_pc = nativeReturnBytecodePC(REGISTER_ARGS, romMethod);
@@ -9465,6 +9467,20 @@ class INTERPRETER_CLASS
94659467
}
94669468

94679469
#if defined(J9VM_OPT_OPENJDK_METHODHANDLE)
9470+
9471+
VMINLINE VM_BytecodeAction
9472+
nullCheckJ9Obj(j9object_t j9Obj, bool fromJIT, REGISTER_ARGS_LIST, UDATA decSP)
9473+
{
9474+
if (J9_UNEXPECTED(NULL == j9Obj)) {
9475+
if (fromJIT) {
9476+
_sp -= decSP;
9477+
buildJITResolveFrame(REGISTER_ARGS);
9478+
}
9479+
return THROW_NPE;
9480+
}
9481+
return GOTO_RUN_METHOD;
9482+
}
9483+
94689484
/* This INL only covers invokeBasic dispatched directly from bytecode, invokeBasic calls
94699485
* dispatched from linkToVirtual is inlined to avoid need of flags and tempValues to
94709486
* pass the correct argCount during VM transition since the ramCP index still points
@@ -9491,12 +9507,7 @@ class INTERPRETER_CLASS
94919507
}
94929508

94939509
j9object_t mhReceiver = ((j9object_t *)_sp)[mhReceiverIndex];
9494-
if (J9_UNEXPECTED(NULL == mhReceiver)) {
9495-
if (fromJIT) {
9496-
buildJITResolveFrame(REGISTER_ARGS);
9497-
}
9498-
return THROW_NPE;
9499-
}
9510+
if (nullCheckJ9Obj(mhReceiver, fromJIT, REGISTER_ARGS, 0) == THROW_NPE) return THROW_NPE;
95009511

95019512
j9object_t lambdaForm = J9VMJAVALANGINVOKEMETHODHANDLE_FORM(_currentThread, mhReceiver);
95029513
j9object_t memberName = J9VMJAVALANGINVOKELAMBDAFORM_VMENTRY(_currentThread, lambdaForm);
@@ -9520,9 +9531,7 @@ class INTERPRETER_CLASS
95209531

95219532
/* Pop memberNameObject from the stack. */
95229533
j9object_t memberNameObject = *(j9object_t *)_sp++;
9523-
if (J9_UNEXPECTED(NULL == memberNameObject)) {
9524-
goto throw_npe;
9525-
}
9534+
if (nullCheckJ9Obj(memberNameObject, fromJIT, REGISTER_ARGS, true) == THROW_NPE) return THROW_NPE;
95269535

95279536
_sendMethod = (J9Method *)(UDATA)J9OBJECT_U64_LOAD(_currentThread, memberNameObject, _vm->vmtargetOffset);
95289537

@@ -9532,10 +9541,10 @@ class INTERPRETER_CLASS
95329541

95339542
if (J9_ARE_NO_BITS_SET(romMethod->modifiers, J9AccStatic)) {
95349543
j9object_t mhReceiver = ((j9object_t *)_sp)[methodArgCount - 1];
9535-
if (J9_UNEXPECTED(NULL == mhReceiver)) {
9536-
goto throw_npe;
9537-
}
9544+
if (nullCheckJ9Obj(mhReceiver, false, REGISTER_ARGS, false) == THROW_NPE) return THROW_NPE;
95389545
}
9546+
} else {
9547+
goto throwDefaultConflict;
95399548
}
95409549

95419550
if (fromJIT) {
@@ -9577,13 +9586,13 @@ class INTERPRETER_CLASS
95779586

95789587
return rc;
95799588

9580-
throw_npe:
9589+
throwDefaultConflict:
95819590
if (fromJIT) {
9582-
/* Restore SP to before popping memberNameObject. */
95839591
_sp -= 1;
95849592
buildJITResolveFrame(REGISTER_ARGS);
95859593
}
9586-
return THROW_NPE;
9594+
// run() will run throwDefaultConflictForMemberName()
9595+
return GOTO_RUN_METHOD;
95879596
}
95889597

95899598
VMINLINE VM_BytecodeAction
@@ -9594,14 +9603,7 @@ class INTERPRETER_CLASS
95949603

95959604
/* Pop memberNameObject from the stack. */
95969605
j9object_t memberNameObject = *(j9object_t *)_sp++;
9597-
if (J9_UNEXPECTED(NULL == memberNameObject)) {
9598-
if (fromJIT) {
9599-
/* Restore SP to before popping memberNameObject. */
9600-
_sp -= 1;
9601-
buildJITResolveFrame(REGISTER_ARGS);
9602-
}
9603-
return THROW_NPE;
9604-
}
9606+
if (nullCheckJ9Obj(memberNameObject, fromJIT, REGISTER_ARGS, true) == THROW_NPE) return THROW_NPE;
96059607

96069608
J9Method *method = (J9Method *)(UDATA)J9OBJECT_U64_LOAD(_currentThread, memberNameObject, _vm->vmtargetOffset);
96079609
J9ROMMethod *romMethod = J9_ROM_METHOD_FROM_RAM_METHOD(method);
@@ -9621,14 +9623,7 @@ class INTERPRETER_CLASS
96219623
}
96229624

96239625
j9object_t receiverObject = ((j9object_t *)_sp)[methodArgCount - 1];
9624-
if (J9_UNEXPECTED(NULL == receiverObject)) {
9625-
if (fromJIT) {
9626-
/* Restore SP to before popping memberNameObject. */
9627-
_sp -= 1;
9628-
buildJITResolveFrame(REGISTER_ARGS);
9629-
}
9630-
return THROW_NPE;
9631-
}
9626+
if (nullCheckJ9Obj(receiverObject, fromJIT, REGISTER_ARGS, true) == THROW_NPE) return THROW_NPE;
96329627

96339628
/* The vTable offset has been stored in memberNameObject.vmindex.
96349629
*
@@ -9687,30 +9682,14 @@ class INTERPRETER_CLASS
96879682

96889683
/* Pop memberNameObject from the stack. */
96899684
j9object_t memberNameObject = *(j9object_t *)_sp++;
9690-
if (J9_UNEXPECTED(NULL == memberNameObject)) {
9691-
if (fromJIT) {
9692-
/* Restore SP to before popping memberNameObject. */
9693-
_sp -= 1;
9694-
buildJITResolveFrame(REGISTER_ARGS);
9695-
}
9696-
rc = THROW_NPE;
9697-
goto done;
9698-
}
9685+
if (nullCheckJ9Obj(memberNameObject, fromJIT, REGISTER_ARGS, true) == THROW_NPE) return THROW_NPE;
96999686

97009687
method = (J9Method *)(UDATA)J9OBJECT_U64_LOAD(_currentThread, memberNameObject, _vm->vmtargetOffset);
97019688
romMethod = J9_ROM_METHOD_FROM_RAM_METHOD(method);
97029689
methodArgCount = romMethod->argCount;
97039690

97049691
receiverObject = ((j9object_t *)_sp)[methodArgCount - 1];
9705-
if (J9_UNEXPECTED(NULL == receiverObject)) {
9706-
if (fromJIT) {
9707-
/* Restore SP to before popping memberNameObject. */
9708-
_sp -= 1;
9709-
buildJITResolveFrame(REGISTER_ARGS);
9710-
}
9711-
rc = THROW_NPE;
9712-
goto done;
9713-
}
9692+
if (nullCheckJ9Obj(receiverObject, fromJIT, REGISTER_ARGS, true) == THROW_NPE) return THROW_NPE;
97149693

97159694
receiverClass = J9OBJECT_CLAZZ(_currentThread, receiverObject);
97169695

@@ -9795,14 +9774,7 @@ class INTERPRETER_CLASS
97959774
}
97969775

97979776
j9object_t nativeMH = *(j9object_t *)_sp;
9798-
if (J9_UNEXPECTED(NULL == nativeMH)) {
9799-
if (fromJIT) {
9800-
/* Restore SP to before popping the dummy argument. */
9801-
_sp -= 1;
9802-
buildJITResolveFrame(REGISTER_ARGS);
9803-
}
9804-
return THROW_NPE;
9805-
}
9777+
if (nullCheckJ9Obj(nativeMH, fromJIT, REGISTER_ARGS, true) == THROW_NPE) return THROW_NPE;
98069778

98079779
j9object_t nepObject = J9VMJAVALANGINVOKENATIVEMETHODHANDLE_NEP(_currentThread, nativeMH);
98089780
j9object_t methodType = J9VMJAVALANGINVOKEMETHODHANDLE_TYPE(_currentThread, nepObject);

0 commit comments

Comments
 (0)