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
Ignore checkcast in Java 21 type switch #2813
Conversation
// Since we're on a checkcast look for a switch with a target on the previous PC | ||
SwitchDetails switchDetails = findSwitchDetailsByPc(pc - 1); | ||
|
||
if (switchDetails != null) { |
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.
This is essentially "if not...else" which is a double negative. Perhaps refactor to "if null then return false".
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.
Yes, I have made the change
|
||
private SwitchDetails findSwitchDetailsByPc(int pc) { | ||
for (SwitchDetails switchDetails : switchOffsetStack) { | ||
for (int i = 0; i < switchDetails.swOffsets.length; i++) { |
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.
Couldn't this be a second foreach loop?
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.
I have made the change
- Compile samples with JDK 21 - Added comments and fixed minor issues
Since the first instruction in a switch might be an aload and take an additional operand we also need to check for PC-2 when checking if we're at a case of the switch. Added a test for nested switches
Am I missing where jdk 21 only is required? I don't see any new imports and tests seem to all indicate only run with jdk 21 so I think jdk 17 is still allowed? Also this is still in Draft so I presume you will remove it from draft once its ready to be merged. |
I've highligted the part where a JDK 21 is required: we're building bug samples using Java 21 language features. |
I have reverted the change to continue building on JDK 17 and 21, the bug samples using java 21 langage features are not built when running on JDK 17 (and the correspoding tests are skipped) |
.github/workflows/release.yml
Outdated
uses: actions/setup-java@v4 | ||
with: | ||
java-version: '21' | ||
java-version: '17' |
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.
If Java 21 is needed for all the test to run, I think it's better if we stuck to this version for the release.
Repurposed
SwitchHandler
to keep track of theInvokeDynamic
corresponding to a Java 21 type switch.We detect that the switch uses the object type by looking for a
typeSwitch
invocation.Then we ignore the
checkcast
for each of the switch's target PC + 1I have removed the sample provided by @robinjhector in #2782 so we don't have to compile Java 21 code because it doesn't seem to work for now. Instead I'm using the compiled .class files directly.Update: this PR effectively upgrades the build to JDK 21 (from 17 AND 21) since we now use Java 21 language features in bug samplesThis PR enables the compilation of bug samples using Java 21 language features when running on JDK 21 or above