7176515: ExceptionInInitializerError for an enum with multiple switch statements#10797
7176515: ExceptionInInitializerError for an enum with multiple switch statements#10797archiecobbs wants to merge 11 commits intoopenjdk:masterfrom
Conversation
|
👋 Welcome back archiecobbs! A progress list of the required criteria for merging this PR into |
|
@archiecobbs The following label will be automatically applied to this pull request:
When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command. |
Webrevs
|
|
@archiecobbs This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration! |
|
keepalive |
|
@archiecobbs This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be: You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 34 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@vicente-romero-oracle) but any other Committer may sponsor as well. ➡️ To flag this PR as ready for integration with the above commit message, type |
|
I think that a follow-up JIRA issue should be filed to track the situation in which the bug can still occur |
Agreed (though it's not something I have permission to do). |
true, I have created: https://bugs.openjdk.org/browse/JDK-8299760 |
|
/integrate |
|
@archiecobbs |
…d-on enums. - No mapping table needed for any Enum class within the same top level class. - Put mapping tables for different enum types into separate synthetic classes.
|
I've made a couple of improvements to this patch. As a result the follow-up bug 8299760, and also 8219412 - Eager enum class initialization with enum switch are now fixed. Improvement 1 The previous patch avoided generating a mapping table when the Improvement 2 All of the mapping tables for any /solves 8299760 |
|
@archiecobbs |
|
@archiecobbs |
…..."). This should go into a separate branch.
|
On second thought, the 2nd improvement belongs in a separate PR, as there probably is more discussion required. Reverting that part of the change from this PR. /issue remove 8219412 |
|
@archiecobbs |
|
@archiecobbs This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration! |
|
@archiecobbs This pull request has been inactive for more than 8 weeks and will now be automatically closed. If you would like to continue working on this pull request in the future, feel free to reopen it! This can be done using the |
|
/open |
|
@archiecobbs This pull request is now open |
|
I think that's an unrelated test failure:
But also I believe this problem was fixed a while ago, so I'll merge in the latest Thanks. |
|
I'm still seeing test: test/hotspot/jtreg/runtime/cds/appcds/jvmti/ClassFileLoadHookTest.java failing with this patch |
Strange... on github everything is passing now: https://github.com/archiecobbs/jdk/actions/runs/4473109724 But when I run that specific test on my laptop, it fails for me too. So I guess this test is not included in the standard test suite? In any case should be fixed in e6ef2ac. |
|
Hello Archie,
GitHub actions job for the jdk repo is configured to run only |
Thanks very much for that clarification. |
|
/integrate |
|
@archiecobbs |
|
/sponsor |
|
Going to push as commit ac6af6a.
Your commit was automatically rebased without conflicts. |
|
@vicente-romero-oracle @archiecobbs Pushed as commit ac6af6a. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
This patch is both a minor optimization and a fix for JDK-7176515.
JDK-7176515 relates to how javac handles
switchstatements onEnumvalues, which are effectively "syntactic sugar".The simple approach would be to just get the enum's
ordinal()value and then revert to a normal integer value switch on that. However, this snapshots the ordinal values at compile-time, and thus can fail if theEnumclass is recompiled later.Presumably to avoid that possibility (are there any other reasons?) the compiler instead uses a lookup table. This table is dynamically constructed at runtime by a static initializer in a synthetic class. This avoids the "stale ordinal" problem of the simple approach, but it also creates a potential class initialization loop if there happens to an
Enumswitch inside anEnumclass constructor, as demonstrated by the bug.This patch makes the following change: If we are handling an
Enumswitch, and theEnumclass we are switching on is also the class we are compiling, then just go with the simple approach, because the "stale ordinal" problem can't happen in this case so there's no need to build a runtime lookup table.This results in two improvements:
Although the reproducing test case provided in JDK-7176515 gets fixed by this patch, the underlying issue is still there and can still be triggered with a slightly more complicated test case (included, but commented out).
So JDK-7176515 could be left open (or a new bug created) and a separate discussion had about how to "really" fix it.
Part of this discussion should be defining what that means, i.e., the boundaries of the bug. There are some scenarios that are basically impossible to fix, for example, two
Enumclasses whose constructors take as a parameter instances of the otherEnumclass and then switch on it. That cycle has nothing to do with how switches are handled.Progress
Issues
Reviewers
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/10797/head:pull/10797$ git checkout pull/10797Update a local copy of the PR:
$ git checkout pull/10797$ git pull https://git.openjdk.org/jdk.git pull/10797/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 10797View PR using the GUI difftool:
$ git pr show -t 10797Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/10797.diff