Skip to content
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

8324809: compiler can crash with SOE while proving if two recursive types are disjoint #19194

Closed

Conversation

vicente-romero-oracle
Copy link
Contributor

@vicente-romero-oracle vicente-romero-oracle commented May 11, 2024

javac is crashing with SOE while compiling code like:

class Criteria<B extends Builder<? extends Criteria>> {
    public <D extends Builder<E>, E extends Criteria<D>> D builder() {
        return (D) new Builder<>();
    }

}

class Builder<C extends Criteria<? extends Builder<C>>> {}

here while attributing: return (D)new Builder<>(); the compiler is trying to prove that: Builder<C> is castable to D, then as the upper bound of D is Builder<E>, we need to check if Builder<C> is castable to Builder<E>. Then the next step is to try to check if type variables C and E are disjoint. During this process is when the compiler gets out of resources given that

E <: Criteria
D <: Builder here we have E again and we start over in an infinite loop,

Here the proposal is to detect cycles in the type arguments graph and accept these type of casts if we find a cycle and thus can't prove if two types are disjoint,

TIA


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

Warning

 ⚠️ Found leading lowercase letter in issue title for 8324809: compiler can crash with SOE while proving if two recursive types are disjoint

Issue

  • JDK-8324809: compiler can crash with SOE while proving if two recursive types are disjoint (Bug - P3)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 19194

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

Using diff file

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

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented May 11, 2024

👋 Welcome back vromero! 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 May 11, 2024

@vicente-romero-oracle 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:

8324809: compiler can crash with SOE while proving if two recursive types are disjoint

Reviewed-by: mcimadamore

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

  • da9c23a: 8325384: sun/security/ssl/SSLSessionImpl/ResumptionUpdateBoundValues.java failing intermittently when main thread is a virtual thread
  • dc184f1: 8324649: Shenandoah: replace implementation of free set
  • 2599151: 8331202: Support for Duration until another Instant
  • 6f7ddbe: 8260633: [macos] java/awt/dnd/MouseEventAfterStartDragTest/MouseEventAfterStartDragTest.html test failed
  • fa3e94d: 8332393: Problemlist compiler/rangechecks/TestArrayAccessAboveRCAfterRCCastIIEliminated.java
  • a33cb90: 8332098: Add missing @ since tags to jdk.jdi
  • 910d77b: 8331953: ubsan: metaspaceShared.cpp:1305:57: runtime error: applying non-zero offset 12849152 to null pointer
  • f9f8d0b: 8332101: Add an @since to StandardOperation:REMOVE in jdk.dynalink
  • f398cd2: 8331575: C2: crash when ConvL2I is split thru phi at LongCountedLoop
  • 96c5c3f: 8329998: Remove double initialization for parts of small TypeArrays in ZObjArrayAllocator
  • ... and 392 more: https://git.openjdk.org/jdk/compare/76cbe4883b5f53843e5140eee2145011fec67e4c...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 May 11, 2024
@openjdk
Copy link

openjdk bot commented May 11, 2024

@vicente-romero-oracle 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 May 11, 2024
@mlbridge
Copy link

mlbridge bot commented May 11, 2024

Webrevs

erasure(t.getUpperBound()) :
visit(t.getUpperBound());
return rewriteAsWildcardType(bound, t, EXTENDS);
if (seen.add(t)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

IIRC, this code is called by Types.isCastable, in an attempt to do some fancy logic (outside the spec) which allow to determine whether two types are disjoint or not. To do this, the code attempts to rewrite occurrences of type-variables using wildcards. So, in some cases the logic fails with SOE - so that result should lead to the consequence that we don't know whether the types are disjoint or not, but, since we're outside the scope of the spec, we need to treat them as not disjoint (e.g. the cast should be possible and we gave up proving that it should NOT be possible).

So, I'm afraid that return t here is going to make this method stricter than intended, which will lead javac to think that the types are in fact disjoint, and that will result in a compiler error. I wonder if we should we return a ? instead?

@@ -4734,6 +4734,10 @@ class Rewriter extends UnaryVisitor<Type> {

boolean high;
boolean rewriteTypeVars;
// map to avoid visiting same type argument twice, like in Foo<T>.Bar<T>
Map<Type, Type> argMap = new HashMap<>();
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to use both a map and a set, or can we just use the map?

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 think yes and in any case the code is more readable, me thinks, with both than using only one

Copy link
Contributor

@mcimadamore mcimadamore left a comment

Choose a reason for hiding this comment

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

Looks good

@openjdk openjdk bot added the ready Pull request is ready to be integrated label May 16, 2024
@vicente-romero-oracle
Copy link
Contributor Author

/integrate

@openjdk
Copy link

openjdk bot commented May 17, 2024

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

  • b7ae0ae: 8328572: JFR: Use Class.forPrimitiveName(String)
  • e611151: 8331281: RISC-V: C2: Support vector-scalar and vector-immediate bitwise logic instructions
  • 44bdf99: 8332239: Improve CSS for block tags
  • 9bb6169: 8317621: --add-script should support JavaScript modules
  • 4eb1eaf: 8329617: Update stylesheet for specs and tool documentation
  • d4c2edf: 8331855: Convert jdk.jdeps jdeprscan and jdeps to use the Classfile API
  • beeffd4: 8332109: Convert remaining tests using com.sun.tools.classfile to ClassFile API
  • e0d1c4b: 8321428: Deprecate for removal the package java.beans.beancontext
  • 0b0445b: 8331724: Refactor j.l.constant implementation to internal package
  • d84a8fd: 8332327: Return _methods_jmethod_ids field back in VMStructs
  • ... and 409 more: https://git.openjdk.org/jdk/compare/76cbe4883b5f53843e5140eee2145011fec67e4c...master

Your commit was automatically rebased without conflicts.

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

openjdk bot commented May 17, 2024

@vicente-romero-oracle Pushed as commit 39a55e9.

💡 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