Skip to content

Commit

Permalink
Merge pull request #15550 from JasonFengJ9/npefree
Browse files Browse the repository at this point in the history
NPE extended message generation missed j9mem_free_memory calls
  • Loading branch information
pshipton committed Jul 19, 2022
2 parents ed0c6ec + c2a9aac commit e0f9da3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
5 changes: 5 additions & 0 deletions runtime/j9vm/javanextvmi.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,11 @@ JVM_GetExtendedNPEMessage(JNIEnv *env, jthrowable throwableObj)
}
j9mem_free_memory(npeMsg);
}
j9mem_free_memory(npeMsgData.liveStack);
j9mem_free_memory(npeMsgData.bytecodeOffset);
j9mem_free_memory(npeMsgData.bytecodeMap);
j9mem_free_memory(npeMsgData.stackMaps);
j9mem_free_memory(npeMsgData.unwalkedQueue);
} else {
Trc_SC_GetExtendedNPEMessage_Null_NPE_MSG(vmThread, userData.romClass, userData.romMethod, userData.bytecodeOffset);
}
Expand Down
27 changes: 17 additions & 10 deletions runtime/vm/extendedMessageNPE.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2020, 2021 IBM Corp. and others
* Copyright (c) 2020, 2022 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -798,6 +798,10 @@ computeNPEMsgAtPC(J9VMThread *vmThread, J9ROMMethod *romMethod, J9ROMClass *romC
PORT_ACCESS_FROM_VMC(vmThread);

Trc_VM_ComputeNPEMsgAtPC_Entry(vmThread, romClass, romMethod, temps, bytecodeOffset, bcCurrent, npePC, npeFinalFlag, *isMethodFlag, *npeMsg);
if (NULL != *npeMsg) {
j9mem_free_memory(*npeMsg);
*npeMsg = NULL;
}
if ((bcCurrent >= JBiconstm1) && (bcCurrent <= JBdconst1)) {
/*
* JBiconstm1, JBiconst0, JBiconst1, JBiconst2, JBiconst3, JBiconst4, JBiconst5
Expand Down Expand Up @@ -903,7 +907,7 @@ computeNPEMsgAtPC(J9VMThread *vmThread, J9ROMMethod *romMethod, J9ROMClass *romC
UDATA objectrefPos = bytecodeOffset[npePC].first;

if (BYTECODE_BRANCH_TARGET == objectrefPos) {
*npeMsg = NULL;
/* *npeMsg is NULL */
} else {
computeNPEMsgAtPC(vmThread, romMethod, romClass, objectrefPos, false, npeMsg, isMethodFlag, temps, bytecodeOffset);
}
Expand Down Expand Up @@ -1024,7 +1028,7 @@ computeNPEMsgAtPC(J9VMThread *vmThread, J9ROMMethod *romMethod, J9ROMClass *romC
if ((BYTECODE_BRANCH_TARGET == bcCausePos)
|| (BYTECODE_BRANCH_TARGET == bcCausePos2)
) {
*npeMsg = NULL;
/* *npeMsg is NULL */
} else {
computeNPEMsgAtPC(vmThread, romMethod, romClass, bcCausePos, false, npeMsg, isMethodFlag, temps, bytecodeOffset);
}
Expand All @@ -1041,30 +1045,32 @@ computeNPEMsgAtPC(J9VMThread *vmThread, J9ROMMethod *romMethod, J9ROMClass *romC
case JBaaload: {
UDATA bcCausePos = bytecodeOffset[npePC].first;

const char* npeMsgObjref = NULL;
char *npeMsgObjref = NULL;
UDATA aaloadIndexPos = 0;
if (BYTECODE_BRANCH_TARGET == bcCausePos) {
if (!npeFinalFlag) {
npeMsgObjref = "<array>";
npeMsgObjref = getMsgWithAllocation(vmThread, "<array>");
}
} else {
computeNPEMsgAtPC(vmThread, romMethod, romClass, bcCausePos, false, (char **)&npeMsgObjref, isMethodFlag, temps, bytecodeOffset);
computeNPEMsgAtPC(vmThread, romMethod, romClass, bcCausePos, false, &npeMsgObjref, isMethodFlag, temps, bytecodeOffset);
}
aaloadIndexPos = bytecodeOffset[npePC].second;
if (npeFinalFlag || (NULL == npeMsgObjref)) {
*npeMsg = (char *)npeMsgObjref;
*npeMsg = npeMsgObjref;
} else {
const char* npeMsgIndex = NULL;
char *npeMsgIndex = NULL;
if (BYTECODE_BRANCH_TARGET == aaloadIndexPos) {
npeMsgIndex = "...";
npeMsgIndex = getMsgWithAllocation(vmThread, "...");
} else {
computeNPEMsgAtPC(vmThread, romMethod, romClass, aaloadIndexPos, false, (char **)&npeMsgIndex, isMethodFlag, temps, bytecodeOffset);
computeNPEMsgAtPC(vmThread, romMethod, romClass, aaloadIndexPos, false, &npeMsgIndex, isMethodFlag, temps, bytecodeOffset);
}

if (NULL != npeMsgIndex) {
*npeMsg = getMsgWithAllocation(vmThread, "%s[%s]", npeMsgObjref, npeMsgIndex);
*isMethodFlag = false;
j9mem_free_memory(npeMsgIndex);
}
j9mem_free_memory(npeMsgObjref);
}
break;
}
Expand Down Expand Up @@ -1101,6 +1107,7 @@ computeNPEMsgAtPC(J9VMThread *vmThread, J9ROMMethod *romMethod, J9ROMClass *romC
*npeMsg = getMsgWithAllocation(vmThread, "%.*s", J9UTF8_LENGTH(fieldName), J9UTF8_DATA(fieldName));
} else {
*npeMsg = getMsgWithAllocation(vmThread, "%s.%.*s", npeMsgObjref, J9UTF8_LENGTH(fieldName), J9UTF8_DATA(fieldName));
j9mem_free_memory(npeMsgObjref);
}
*isMethodFlag = false;
}
Expand Down

0 comments on commit e0f9da3

Please sign in to comment.