Skip to content

Commit 58a22ad

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 78878f2 commit 58a22ad

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
@@ -624,6 +624,8 @@ class INTERPRETER_CLASS
624624
#endif /* defined(J9VM_OPT_METHOD_HANDLE) */
625625
}
626626

627+
#define isMethodDefaultConflictJ9Method(method) (method == _currentThread->javaVM->initialMethods.throwDefaultConflict)
628+
627629
VMINLINE VM_BytecodeAction
628630
j2iTransition(
629631
REGISTER_ARGS_LIST
@@ -633,9 +635,9 @@ class INTERPRETER_CLASS
633635
) {
634636
VM_JITInterface::disableRuntimeInstrumentation(_currentThread);
635637
VM_BytecodeAction rc = GOTO_RUN_METHOD;
636-
void* const jitReturnAddress = VM_JITInterface::fetchJITReturnAddress(_currentThread, _sp);
637-
J9ROMMethod* const romMethod = J9_ROM_METHOD_FROM_RAM_METHOD(_sendMethod);
638-
void* const exitPoint = j2iReturnPoint(J9ROMMETHOD_SIGNATURE(romMethod));
638+
void *const jitReturnAddress = VM_JITInterface::fetchJITReturnAddress(_currentThread, _sp);
639+
J9ROMMethod *const romMethod = J9_ROM_METHOD_FROM_RAM_METHOD(_sendMethod);
640+
void *const exitPoint = j2iReturnPoint(J9ROMMETHOD_SIGNATURE(romMethod));
639641
if (J9_ARE_ANY_BITS_SET(romMethod->modifiers, J9AccNative | J9AccAbstract)) {
640642
_literals = (J9Method*)jitReturnAddress;
641643
_pc = nativeReturnBytecodePC(REGISTER_ARGS, romMethod);
@@ -9499,6 +9501,20 @@ class INTERPRETER_CLASS
94999501
}
95009502

95019503
#if defined(J9VM_OPT_OPENJDK_METHODHANDLE)
9504+
9505+
VMINLINE VM_BytecodeAction
9506+
nullCheckJ9Obj(j9object_t j9Obj, bool fromJIT, REGISTER_ARGS_LIST, UDATA decSP)
9507+
{
9508+
if (J9_UNEXPECTED(NULL == j9Obj)) {
9509+
if (fromJIT) {
9510+
_sp -= decSP;
9511+
buildJITResolveFrame(REGISTER_ARGS);
9512+
}
9513+
return THROW_NPE;
9514+
}
9515+
return GOTO_RUN_METHOD;
9516+
}
9517+
95029518
/* This INL only covers invokeBasic dispatched directly from bytecode, invokeBasic calls
95039519
* dispatched from linkToVirtual is inlined to avoid need of flags and tempValues to
95049520
* pass the correct argCount during VM transition since the ramCP index still points
@@ -9525,12 +9541,7 @@ class INTERPRETER_CLASS
95259541
}
95269542

95279543
j9object_t mhReceiver = ((j9object_t *)_sp)[mhReceiverIndex];
9528-
if (J9_UNEXPECTED(NULL == mhReceiver)) {
9529-
if (fromJIT) {
9530-
buildJITResolveFrame(REGISTER_ARGS);
9531-
}
9532-
return THROW_NPE;
9533-
}
9544+
if (nullCheckJ9Obj(mhReceiver, fromJIT, REGISTER_ARGS, 0) == THROW_NPE) return THROW_NPE;
95349545

95359546
j9object_t lambdaForm = J9VMJAVALANGINVOKEMETHODHANDLE_FORM(_currentThread, mhReceiver);
95369547
j9object_t memberName = J9VMJAVALANGINVOKELAMBDAFORM_VMENTRY(_currentThread, lambdaForm);
@@ -9554,9 +9565,7 @@ class INTERPRETER_CLASS
95549565

95559566
/* Pop memberNameObject from the stack. */
95569567
j9object_t memberNameObject = *(j9object_t *)_sp++;
9557-
if (J9_UNEXPECTED(NULL == memberNameObject)) {
9558-
goto throw_npe;
9559-
}
9568+
if (nullCheckJ9Obj(memberNameObject, fromJIT, REGISTER_ARGS, true) == THROW_NPE) return THROW_NPE;
95609569

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

@@ -9566,10 +9575,10 @@ class INTERPRETER_CLASS
95669575

95679576
if (J9_ARE_NO_BITS_SET(romMethod->modifiers, J9AccStatic)) {
95689577
j9object_t mhReceiver = ((j9object_t *)_sp)[methodArgCount - 1];
9569-
if (J9_UNEXPECTED(NULL == mhReceiver)) {
9570-
goto throw_npe;
9571-
}
9578+
if (nullCheckJ9Obj(mhReceiver, false, REGISTER_ARGS, false) == THROW_NPE) return THROW_NPE;
95729579
}
9580+
} else {
9581+
goto throwDefaultConflict;
95739582
}
95749583

95759584
if (fromJIT) {
@@ -9611,13 +9620,13 @@ class INTERPRETER_CLASS
96119620

96129621
return rc;
96139622

9614-
throw_npe:
9623+
throwDefaultConflict:
96159624
if (fromJIT) {
9616-
/* Restore SP to before popping memberNameObject. */
96179625
_sp -= 1;
96189626
buildJITResolveFrame(REGISTER_ARGS);
96199627
}
9620-
return THROW_NPE;
9628+
// run() will run throwDefaultConflictForMemberName()
9629+
return GOTO_RUN_METHOD;
96219630
}
96229631

96239632
VMINLINE VM_BytecodeAction
@@ -9628,14 +9637,7 @@ class INTERPRETER_CLASS
96289637

96299638
/* Pop memberNameObject from the stack. */
96309639
j9object_t memberNameObject = *(j9object_t *)_sp++;
9631-
if (J9_UNEXPECTED(NULL == memberNameObject)) {
9632-
if (fromJIT) {
9633-
/* Restore SP to before popping memberNameObject. */
9634-
_sp -= 1;
9635-
buildJITResolveFrame(REGISTER_ARGS);
9636-
}
9637-
return THROW_NPE;
9638-
}
9640+
if (nullCheckJ9Obj(memberNameObject, fromJIT, REGISTER_ARGS, true) == THROW_NPE) return THROW_NPE;
96399641

96409642
J9Method *method = (J9Method *)(UDATA)J9OBJECT_U64_LOAD(_currentThread, memberNameObject, _vm->vmtargetOffset);
96419643
J9ROMMethod *romMethod = J9_ROM_METHOD_FROM_RAM_METHOD(method);
@@ -9655,14 +9657,7 @@ class INTERPRETER_CLASS
96559657
}
96569658

96579659
j9object_t receiverObject = ((j9object_t *)_sp)[methodArgCount - 1];
9658-
if (J9_UNEXPECTED(NULL == receiverObject)) {
9659-
if (fromJIT) {
9660-
/* Restore SP to before popping memberNameObject. */
9661-
_sp -= 1;
9662-
buildJITResolveFrame(REGISTER_ARGS);
9663-
}
9664-
return THROW_NPE;
9665-
}
9660+
if (nullCheckJ9Obj(receiverObject, fromJIT, REGISTER_ARGS, true) == THROW_NPE) return THROW_NPE;
96669661

96679662
/* The vTable offset has been stored in memberNameObject.vmindex.
96689663
*
@@ -9721,30 +9716,14 @@ class INTERPRETER_CLASS
97219716

97229717
/* Pop memberNameObject from the stack. */
97239718
j9object_t memberNameObject = *(j9object_t *)_sp++;
9724-
if (J9_UNEXPECTED(NULL == memberNameObject)) {
9725-
if (fromJIT) {
9726-
/* Restore SP to before popping memberNameObject. */
9727-
_sp -= 1;
9728-
buildJITResolveFrame(REGISTER_ARGS);
9729-
}
9730-
rc = THROW_NPE;
9731-
goto done;
9732-
}
9719+
if (nullCheckJ9Obj(memberNameObject, fromJIT, REGISTER_ARGS, true) == THROW_NPE) return THROW_NPE;
97339720

97349721
method = (J9Method *)(UDATA)J9OBJECT_U64_LOAD(_currentThread, memberNameObject, _vm->vmtargetOffset);
97359722
romMethod = J9_ROM_METHOD_FROM_RAM_METHOD(method);
97369723
methodArgCount = romMethod->argCount;
97379724

97389725
receiverObject = ((j9object_t *)_sp)[methodArgCount - 1];
9739-
if (J9_UNEXPECTED(NULL == receiverObject)) {
9740-
if (fromJIT) {
9741-
/* Restore SP to before popping memberNameObject. */
9742-
_sp -= 1;
9743-
buildJITResolveFrame(REGISTER_ARGS);
9744-
}
9745-
rc = THROW_NPE;
9746-
goto done;
9747-
}
9726+
if (nullCheckJ9Obj(receiverObject, fromJIT, REGISTER_ARGS, true) == THROW_NPE) return THROW_NPE;
97489727

97499728
receiverClass = J9OBJECT_CLAZZ(_currentThread, receiverObject);
97509729

@@ -9829,14 +9808,7 @@ class INTERPRETER_CLASS
98299808
}
98309809

98319810
j9object_t nativeMH = *(j9object_t *)_sp;
9832-
if (J9_UNEXPECTED(NULL == nativeMH)) {
9833-
if (fromJIT) {
9834-
/* Restore SP to before popping the dummy argument. */
9835-
_sp -= 1;
9836-
buildJITResolveFrame(REGISTER_ARGS);
9837-
}
9838-
return THROW_NPE;
9839-
}
9811+
if (nullCheckJ9Obj(nativeMH, fromJIT, REGISTER_ARGS, true) == THROW_NPE) return THROW_NPE;
98409812

98419813
j9object_t nepObject = J9VMJAVALANGINVOKENATIVEMETHODHANDLE_NEP(_currentThread, nativeMH);
98429814
j9object_t methodType = J9VMJAVALANGINVOKEMETHODHANDLE_TYPE(_currentThread, nepObject);

0 commit comments

Comments
 (0)