New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add the check of BCV_SPECIAL in generating stackmaps #9419
Add the check of BCV_SPECIAL in generating stackmaps #9419
Conversation
Verified the failing cases at #9385 and #5676, which works good as expected:
|
Reviewer: @DanHeidinga |
@DanHeidinga, please hold off reviewing the code as I detected the VerifyError was still detected by Hotspot after manually changing the class version to 42 in the class file. |
d65321b
to
657b969
Compare
@DanHeidinga , the fix is ready for review as all personal builds & Grinder tests passed without any issue specific to verifier. |
runtime/bcverify/bcverify.c
Outdated
if ((*targetStackPtr != (UDATA) (BCV_BASE_TYPE_TOP)) | ||
&& !(*targetStackPtr & BCV_SPECIAL) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't the local targetItem
already initialized to be *targetStackPtr
? Can the local be used here?
Also, please use explicit boolean conditions
if ((*targetStackPtr != (UDATA) (BCV_BASE_TYPE_TOP)) | |
&& !(*targetStackPtr & BCV_SPECIAL) | |
if ((targetItem != (UDATA) (BCV_BASE_TYPE_TOP)) | |
&& ((targetItem & BCV_SPECIAL) == 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this really checking for (targetItem & BCV_SPECIAL_INIT) != 0
to avoid changing to BCV_BASE_TYPE_TOP
in that case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't the local
targetItem
already initialized to be*targetStackPtr
? Can the local be used here? Also, please use explicit boolean conditions
Yes, we should use targetItem
instead of *targetStackPtr
in this case. Updated as suggested.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this really checking for
(targetItem & BCV_SPECIAL_INIT) != 0
to avoid changing toBCV_BASE_TYPE_TOP
in that case?
Yes, it was based on the thorough debugging with the class files in question. It is obvious that the intention of the original implementation was to reserve the BCV_SPECIAL
bits so as to set up uninitializedThis
in setInitializedThisStatus
but somehow the bits were wipe out here accidentally to deal with other situations. The BCV_SPECIAL
bits can't be restored back or reset up later in simulateStack
once they are removed here. That's why we need to handle the case on both mergeStack()
and matchStack()
to ensure the BCV_SPECIAL
bits from the generated stackmaps are correctly addressed.
runtime/bcverify/j9bcverify.tdf
Outdated
@@ -114,7 +114,7 @@ TraceExit=Trc_RTV_findAndMatchStack_Exit Overhead=1 Level=3 Template="findAndMat | |||
TraceEntry=Trc_RTV_matchStack_Entry Overhead=1 Level=3 Template="matchStack - inlineMatch is %i" | |||
TraceException=Trc_RTV_matchStack_DepthMismatchException Overhead=1 Level=1 Template="matchStack - %.*s %.*s%.*s mismatched stack depths, live = %i, target = %i" | |||
TraceException=Trc_RTV_matchStack_IncompatibleClassException Overhead=1 Level=1 Template="matchStack - %.*s %.*s%.*s incompatible objects at offset %i, live = 0x%X, target = 0x%X" | |||
TraceException=Trc_RTV_matchStack_PrimitiveMismatchException Overhead=1 Level=1 Template="matchStack - %.*s %.*s%.*s incompatible primitives at offset %i, live = 0x%X, target = 0x%X" | |||
TraceException=Trc_RTV_matchStack_PrimitiveOrSpecialMismatchException Overhead=1 Level=1 Template="matchStack - %.*s %.*s%.*s incompatible primitives or special at offset %i, live = 0x%X, target = 0x%X" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tracepoints aren't changed. If necessary, the current one is obsoleted and a new one is introduced at the end of the file so the index & format never change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree and moved the new tracepoint to the end of the file.
runtime/bcverify/rtverify.c
Outdated
/* Only skip the check on the target slot with BCV_SPECIAL for the generated stackmaps | ||
* as this slot is set up based on the bytecode itself rather than decompressed stackmaps. | ||
*/ | ||
} else if ((*targetPtr != BCV_BASE_TYPE_TOP) && !((*targetPtr & BCV_SPECIAL) && verifyData->createdStackMap)) { | ||
Trc_RTV_matchStack_PrimitiveOrSpecialMismatchException(verifyData->vmStruct, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/* Only skip the check on the target slot with BCV_SPECIAL for the generated stackmaps | |
* as this slot is set up based on the bytecode itself rather than decompressed stackmaps. | |
*/ | |
} else if ((*targetPtr != BCV_BASE_TYPE_TOP) && !((*targetPtr & BCV_SPECIAL) && verifyData->createdStackMap)) { | |
Trc_RTV_matchStack_PrimitiveOrSpecialMismatchException(verifyData->vmStruct, | |
} else if (*targetPtr != BCV_BASE_TYPE_TOP) { | |
if (((*targetPtr & BCV_SPECIAL) != 0) && verifyData->createdStackMap) { | |
/* Generated stackmaps can skip the check on the target slot with BCV_SPECIAL | |
* as this slot is set up based on the bytecode itself rather than decompressed stackmaps. | |
*/ | |
} else { | |
Trc_RTV_matchStack_PrimitiveOrSpecialMismatchException(verifyData->vmStruct, | |
..... | |
rc = BCV_FAIL; /* fail - primitive or special mismatch */ | |
goto _incompatibleType; | |
} | |
} |
Reorganizing this may be clearer about when the check is being skipped vs not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree and updated against the suggestion above.
657b969
to
f2335ae
Compare
runtime/bcverify/j9bcverify.tdf
Outdated
@@ -114,7 +114,6 @@ TraceExit=Trc_RTV_findAndMatchStack_Exit Overhead=1 Level=3 Template="findAndMat | |||
TraceEntry=Trc_RTV_matchStack_Entry Overhead=1 Level=3 Template="matchStack - inlineMatch is %i" | |||
TraceException=Trc_RTV_matchStack_DepthMismatchException Overhead=1 Level=1 Template="matchStack - %.*s %.*s%.*s mismatched stack depths, live = %i, target = %i" | |||
TraceException=Trc_RTV_matchStack_IncompatibleClassException Overhead=1 Level=1 Template="matchStack - %.*s %.*s%.*s incompatible objects at offset %i, live = 0x%X, target = 0x%X" | |||
TraceException=Trc_RTV_matchStack_PrimitiveMismatchException Overhead=1 Level=1 Template="matchStack - %.*s %.*s%.*s incompatible primitives at offset %i, live = 0x%X, target = 0x%X" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The old tracepoint has to stay here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
The change is to add the check of BCV_SPECIAL when merging & matching stacks to ensure the uninitializedThis flag is correctly set up during the generation of stackmaps so as to match the RI's behavior at runtime verification.[ci skip] Fixes: eclipse-openj9#9385 Signed-off-by: Cheng Jin <jincheng@ca.ibm.com>
f2335ae
to
a811a1a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Jenkins test sanity plinux,zlinux jdk8 |
Jenkins test sanity win,osx jdk11 |
Jenkins test sanity xlinux jdk14 |
Ported to 0.21 release branch in #9951 |
The change is to add the check of BCV_SPECIAL when
merging & matching stacks to ensure the uninitializedThis
flag is correctly set up during the generation of stackmaps
so as to match the RI's behavior at runtime verification.
Fixes: #9385
Signed-off-by: Cheng Jin jincheng@ca.ibm.com