Skip to content

Commit 0781756

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 0781756

File tree

1 file changed

+40
-62
lines changed

1 file changed

+40
-62
lines changed

runtime/vm/BytecodeInterpreter.hpp

Lines changed: 40 additions & 62 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 isMethodDefaultConflictForMethodHandle(method) (method == _currentThread->javaVM->initialMethods.throwDefaultConflict)
628+
627629
VMINLINE VM_BytecodeAction
628630
j2iTransition(
629631
REGISTER_ARGS_LIST
@@ -633,12 +635,17 @@ 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));
639-
if (J9_ARE_ANY_BITS_SET(romMethod->modifiers, J9AccNative | J9AccAbstract)) {
638+
void *const jitReturnAddress = VM_JITInterface::fetchJITReturnAddress(_currentThread, _sp);
639+
J9ROMMethod *const romMethod = isMethodDefaultConflictForMethodHandle(_sendMethod) ? NULL : J9_ROM_METHOD_FROM_RAM_METHOD(_sendMethod);
640+
641+
if (isMethodDefaultConflictForMethodHandle(_sendMethod) || J9_ARE_ANY_BITS_SET(romMethod->modifiers, J9AccNative | J9AccAbstract)) {
640642
_literals = (J9Method*)jitReturnAddress;
641-
_pc = nativeReturnBytecodePC(REGISTER_ARGS, romMethod);
643+
if (isMethodDefaultConflictForMethodHandle(_sendMethod)) {
644+
buildJITResolveFrame(REGISTER_ARGS);
645+
} else {
646+
_pc = nativeReturnBytecodePC(REGISTER_ARGS, romMethod);
647+
}
648+
642649
#if defined(J9SW_NEEDS_JIT_2_INTERP_CALLEE_ARG_POP)
643650
/* Variable frame */
644651
_arg0EA = NULL;
@@ -658,6 +665,7 @@ class INTERPRETER_CLASS
658665
rc = GOTO_THROW_CURRENT_EXCEPTION;
659666
}
660667
} else {
668+
void* const exitPoint = j2iReturnPoint(J9ROMMETHOD_SIGNATURE(romMethod));
661669
bool decompileOccurred = false;
662670
_pc = (U_8*)jitReturnAddress;
663671
UDATA preCount = 0;
@@ -9499,6 +9507,20 @@ class INTERPRETER_CLASS
94999507
}
95009508

95019509
#if defined(J9VM_OPT_OPENJDK_METHODHANDLE)
9510+
9511+
VMINLINE VM_BytecodeAction
9512+
nullCheckJ9Obj(j9object_t j9Obj, bool fromJIT, REGISTER_ARGS_LIST, UDATA decSP)
9513+
{
9514+
if (J9_UNEXPECTED(NULL == j9Obj)) {
9515+
if (fromJIT) {
9516+
_sp -= decSP;
9517+
buildJITResolveFrame(REGISTER_ARGS);
9518+
}
9519+
return THROW_NPE;
9520+
}
9521+
return GOTO_RUN_METHOD;
9522+
}
9523+
95029524
/* This INL only covers invokeBasic dispatched directly from bytecode, invokeBasic calls
95039525
* dispatched from linkToVirtual is inlined to avoid need of flags and tempValues to
95049526
* pass the correct argCount during VM transition since the ramCP index still points
@@ -9525,12 +9547,7 @@ class INTERPRETER_CLASS
95259547
}
95269548

95279549
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-
}
9550+
if (nullCheckJ9Obj(mhReceiver, fromJIT, REGISTER_ARGS, 0) == THROW_NPE) return THROW_NPE;
95349551

95359552
j9object_t lambdaForm = J9VMJAVALANGINVOKEMETHODHANDLE_FORM(_currentThread, mhReceiver);
95369553
j9object_t memberName = J9VMJAVALANGINVOKELAMBDAFORM_VMENTRY(_currentThread, lambdaForm);
@@ -9554,9 +9571,7 @@ class INTERPRETER_CLASS
95549571

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

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

@@ -9566,10 +9581,10 @@ class INTERPRETER_CLASS
95669581

95679582
if (J9_ARE_NO_BITS_SET(romMethod->modifiers, J9AccStatic)) {
95689583
j9object_t mhReceiver = ((j9object_t *)_sp)[methodArgCount - 1];
9569-
if (J9_UNEXPECTED(NULL == mhReceiver)) {
9570-
goto throw_npe;
9571-
}
9584+
if (nullCheckJ9Obj(mhReceiver, false, REGISTER_ARGS, false) == THROW_NPE) return THROW_NPE;
95729585
}
9586+
} else {
9587+
goto throwDefaultConflict;
95739588
}
95749589

95759590
if (fromJIT) {
@@ -9611,13 +9626,13 @@ class INTERPRETER_CLASS
96119626

96129627
return rc;
96139628

9614-
throw_npe:
9629+
throwDefaultConflict:
96159630
if (fromJIT) {
9616-
/* Restore SP to before popping memberNameObject. */
96179631
_sp -= 1;
96189632
buildJITResolveFrame(REGISTER_ARGS);
96199633
}
9620-
return THROW_NPE;
9634+
// run() will run throwDefaultConflictForMemberName()
9635+
return GOTO_RUN_METHOD;
96219636
}
96229637

96239638
VMINLINE VM_BytecodeAction
@@ -9628,14 +9643,7 @@ class INTERPRETER_CLASS
96289643

96299644
/* Pop memberNameObject from the stack. */
96309645
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-
}
9646+
if (nullCheckJ9Obj(memberNameObject, fromJIT, REGISTER_ARGS, true) == THROW_NPE) return THROW_NPE;
96399647

96409648
J9Method *method = (J9Method *)(UDATA)J9OBJECT_U64_LOAD(_currentThread, memberNameObject, _vm->vmtargetOffset);
96419649
J9ROMMethod *romMethod = J9_ROM_METHOD_FROM_RAM_METHOD(method);
@@ -9655,14 +9663,7 @@ class INTERPRETER_CLASS
96559663
}
96569664

96579665
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-
}
9666+
if (nullCheckJ9Obj(receiverObject, fromJIT, REGISTER_ARGS, true) == THROW_NPE) return THROW_NPE;
96669667

96679668
/* The vTable offset has been stored in memberNameObject.vmindex.
96689669
*
@@ -9721,30 +9722,14 @@ class INTERPRETER_CLASS
97219722

97229723
/* Pop memberNameObject from the stack. */
97239724
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-
}
9725+
if (nullCheckJ9Obj(memberNameObject, fromJIT, REGISTER_ARGS, true) == THROW_NPE) return THROW_NPE;
97339726

97349727
method = (J9Method *)(UDATA)J9OBJECT_U64_LOAD(_currentThread, memberNameObject, _vm->vmtargetOffset);
97359728
romMethod = J9_ROM_METHOD_FROM_RAM_METHOD(method);
97369729
methodArgCount = romMethod->argCount;
97379730

97389731
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-
}
9732+
if (nullCheckJ9Obj(receiverObject, fromJIT, REGISTER_ARGS, true) == THROW_NPE) return THROW_NPE;
97489733

97499734
receiverClass = J9OBJECT_CLAZZ(_currentThread, receiverObject);
97509735

@@ -9829,14 +9814,7 @@ class INTERPRETER_CLASS
98299814
}
98309815

98319816
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-
}
9817+
if (nullCheckJ9Obj(nativeMH, fromJIT, REGISTER_ARGS, true) == THROW_NPE) return THROW_NPE;
98409818

98419819
j9object_t nepObject = J9VMJAVALANGINVOKENATIVEMETHODHANDLE_NEP(_currentThread, nativeMH);
98429820
j9object_t methodType = J9VMJAVALANGINVOKEMETHODHANDLE_TYPE(_currentThread, nepObject);

0 commit comments

Comments
 (0)