Skip to content

8326616: tools/javac/patterns/Exhaustiveness.java intermittently Timeout signalled after 480 seconds #20836

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

Closed
wants to merge 4 commits into from

Conversation

lahodaj
Copy link
Contributor

@lahodaj lahodaj commented Sep 3, 2024

This patch revisits the fix for JDK-8325215 (PR: #17949). The problem in that bug was along the following lines.

Consider this code:

    sealed interface B permits S1, S2 {}
    final class S1 implements B {}
    final class S2 implements B {}
    record R(B b, B s) {}
    private void test(R r) {
        switch (r) {
            case R(B _, S1 _) -> {}
            case R(S1 _, B _) -> {}
            case R(S2 _, S2 _) -> {}
        }
    }

The switch is exhaustive, but before the fix for JDK-8325215, javac considered it not exhaustive. If case R(S1 _, B _) is preplaced with case R(S1 _, S2 _), javac will consider the switch to be exhaustive.

This problem is because to prove that the switch is exhaustive, it is necessary to merge R(S1 _, B _) and R(S2 _, S2 _) into R(B _, S2 _), which then can be merged with R(B _, S1 _) to form R(B _, B_), and then just R _, which means the switch is exhaustive.

But, before JDK-8325215, javac could merge R(S1 _, B _) and R(S2 _, S2 _) into R(B _, S2 _), because it was looking at the two patterns, set the mismatching component to 0, and was looking at the patterns in all other components, if they are precisely the same - but they are not, so javac failed to merge the patterns. Note that it is permitted to replace a type pattern with a more specific type pattern (i.e. replace B _ with S2 _).

The solution in JDK-8325215 was to expand all type patterns in all the patterns in the set into their possible permitted subtypes. I.e. in the above case R(S1 _, B _) was expanded to R(S1 _, B _), R(S1 _, S1 _) and R(S1 _, S2 _). As a consequence, the merging could proceed, and javac would consider the switch to be exhaustive.

The problem with this solution is that it sometimes leads to a very big pattern set, which the javac then processes very slowly/too slowly.

The proposal alternate fix for the original problem proposed herein is to avoid the creation of the very big pattern set, and rather permit javac to merge R(S1 _, B _) and R(S2 _, S2 _), because B is a supertype of (more general pattern than) S2. This is a bit tricky, as the code that searches for merge candidates is using hashes for the patterns, and the hashes speed up the search very significantly (and the use of the hashes is not compatible with the use of the subtyping relation). So, the proposal is to use hashing when possible, and use the subtyping relation when no more patterns can be merged.

I ran the Exhaustiveness test many times with this change, without a timeout so far.


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8326616: tools/javac/patterns/Exhaustiveness.java intermittently Timeout signalled after 480 seconds (Bug - P4)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/20836/head:pull/20836
$ git checkout pull/20836

Update a local copy of the PR:
$ git checkout pull/20836
$ git pull https://git.openjdk.org/jdk.git pull/20836/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 20836

View PR using the GUI difftool:
$ git pr show -t 20836

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/20836.diff

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Sep 3, 2024

👋 Welcome back jlahoda! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Sep 3, 2024

@lahodaj 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:

8326616: tools/javac/patterns/Exhaustiveness.java intermittently Timeout signalled after 480 seconds

Reviewed-by: abimpoudis

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 140 new commits pushed to the master branch:

  • a35fd38: 8339368: Switch targets are not inflated in CodeModel if no StackMap
  • 7db4d46: 8330159: [C2] Remove or clarify Compile::init_start
  • 9e0ccb8: 8339548: GHA: RISC-V: Use Debian snapshot archive for bootstrap
  • 8fb8cd8: 8339347: keytool -importpass insists prompting the user even if there is no terminal
  • 9e1af8c: 8339285: Test fails with assert(depth < max_critical_stack_depth) failed: can't have more than 10 critical frames
  • 48d7943: 8339342: FieldAllocationCount is mostly unused
  • e203df4: 8338100: C2: assert(!n_loop->is_member(get_loop(lca))) failed: control must not be back in the loop
  • 98020e4: 8338133: Cleanup direct use of new HtmlTree
  • b895d7c: 8332423: [PPC64] Remove C1_MacroAssembler::call_c_with_frame_resize
  • 59c4649: 8329959: Update DigestMD5Client.java - fix typo in javadoc string
  • ... and 130 more: https://git.openjdk.org/jdk/compare/e63418ee017def80689c88671e5d124b2d453fda...master

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.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk bot added the rfr Pull request is ready for review label Sep 3, 2024
@openjdk
Copy link

openjdk bot commented Sep 3, 2024

@lahodaj The following label will be automatically applied to this pull request:

  • compiler

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.

@openjdk openjdk bot added the compiler compiler-dev@openjdk.org label Sep 3, 2024
@mlbridge
Copy link

mlbridge bot commented Sep 3, 2024

Webrevs

!(rpOne.nested[i] instanceof BindingPattern bpOne) ||
!(rpOther.nested[i] instanceof BindingPattern bpOther) ||
!types.isSubtype(types.erasure(bpOne.type), types.erasure(bpOther.type))) {
continue NEXT_PATTERN;
Copy link
Member

@biboudis biboudis Sep 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No tests in the patterns folder executes this block (continue NEXT_PATTERN;). I am sure it works, can you include a small test that leads to this line?

Copy link
Member

@biboudis biboudis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -1054,7 +1064,7 @@ private Set<PatternDescription> reduceNestedPatterns(Set<PatternDescription> pat
.stream()
//error recovery, ignore patterns with incorrect number of nested patterns:
.filter(pd -> pd.nested.length == nestedPatternsCount)
.collect(groupingBy(pd -> pd.hashCode(mismatchingCandidateFin)));
.collect(groupingBy(pd -> useHashes ? pd.hashCode(mismatchingCandidateFin) : 0));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

groupByHashes can be renamed into groupByOnlyMismatchingCandidateDifference or something else. The ByHashes is not applicable any more in the general case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've used groupEquivalenceCandidates - please let me know if that makes sense.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect!

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Sep 4, 2024
@openjdk openjdk bot removed the ready Pull request is ready to be integrated label Sep 6, 2024
Copy link
Member

@biboudis biboudis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Jan. Nice work!

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Sep 6, 2024
@lahodaj
Copy link
Contributor Author

lahodaj commented Sep 9, 2024

/integrate

@openjdk
Copy link

openjdk bot commented Sep 9, 2024

Going to push as commit a18d9d8.
Since your change was applied there have been 153 commits pushed to the master branch:

  • 79d7613: 8338153: java/awt/Checkbox/CheckboxCheckerScalingTest.java test failed on linux machine
  • f0e84b7: 8339703: Problem list serviceability/sa/TestJhsdbJstackUpcall.java for generational ZGC
  • deeb09a: 8339307: jhsdb jstack could not trace FFM upcall frame
  • fbe2629: 8339635: StringConcatFactory optimization for CompactStrings off
  • 8e580ec: 8338123: Linker crash when building a downcall handle with many arguments in x64
  • 5b72bbf: 8339519: Remove size field from instructions
  • 0df10bb: 8339466: Enumerate shared stubs and define static fields and names via declarations
  • 9ebc2ec: 8339317: Optimize ClassFile writeBuffer
  • d2b36f0: 8339642: Reduce overheads in InvokerBytecodeGenerator
  • cb00333: 8339640: Reduce construction overheads in StringConcatFactory$InlineHiddenClassStrategy
  • ... and 143 more: https://git.openjdk.org/jdk/compare/e63418ee017def80689c88671e5d124b2d453fda...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Sep 9, 2024
@openjdk openjdk bot closed this Sep 9, 2024
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Sep 9, 2024
@openjdk
Copy link

openjdk bot commented Sep 9, 2024

@lahodaj Pushed as commit a18d9d8.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler compiler-dev@openjdk.org integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

2 participants