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

8332106: VerifyError when using switch pattern in this(...) or super(...) #19217

Closed
wants to merge 3 commits into from

Conversation

lahodaj
Copy link
Contributor

@lahodaj lahodaj commented May 13, 2024

Considering code like:

public class Test {

    public Test(int i) {
    }

    public Test(Object o) {
        this(o instanceof R(String s) ? s.length() : -1);
    }

    public static void main(String... args) {}

    record R(String s) {}
}

Running this crashes:

$ java .../Test.java
Exception in thread "main" java.lang.VerifyError: Stack map does not match the one at exception handler 36
Exception Details:
  Location:
    Test.<init>(Ljava/lang/Object;)V @36: astore_2
  Reason:
    Type uninitializedThis (current frame, locals[0]) is not assignable to 'Test' (stack map, locals[0])
  Current Frame:
    bci: @14
    flags: { flagThisUninit }
    locals: { uninitializedThis, 'java/lang/Object', top, 'Test$R' }
    stack: { 'java/lang/Throwable' }
  Stackmap Frame:
    bci: @36
    flags: { }
    locals: { 'Test', 'java/lang/Object' }
    stack: { 'java/lang/Throwable' }
  Bytecode:
    0000000: 2a2b c100 0799 0018 2bc0 0007 4e2d b600
    0000010: 093a 0419 044d 2cb6 000d a700 0402 b700
    0000020: 13a7 0011 4dbb 001a 592c b600 1c2c b700
    0000030: 1fbf b1                                
  Exception Handler Table:
    bci [14, 17] => handler: 36
  Stackmap Table:
    same_locals_1_stack_item_frame(@29,UninitializedThis)
    full_frame(@30,{UninitializedThis,Object[#2]},{UninitializedThis,Integer})
    full_frame(@36,{Object[#20],Object[#2]},{Object[#24]})
    same_frame(@50)

        at java.base/java.lang.Class.forName0(Native Method)
        at java.base/java.lang.Class.forName(Class.java:534)
        at java.base/java.lang.Class.forName(Class.java:513)
        at jdk.compiler/com.sun.tools.javac.launcher.Main.execute(Main.java:432)
        at jdk.compiler/com.sun.tools.javac.launcher.Main.run(Main.java:208)
        at jdk.compiler/com.sun.tools.javac.launcher.Main.main(Main.java:135)

The reason is that there is a synthetic catch generated wrapping the record accessors inside the pattern matching. The range where the exception this catch is catching is before the real this(...) invokespecial, and hence the this is still an "uninitialized this". But the code for the catch is generated at the end of the constructor, when this is already initialized, and javac generates the stack maps as if this was initialized.

In general, the pattern matching code can be both before and after the this has been initialized. But, I don't think a stack map frame can be generated for the handler originating in places with both "uninitialized this " and (initialized) this.

The proposal here is to generate one set of the catch handlers for the state with "uninitialized this", and another for (initialized) this, if needed.


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-8332106: VerifyError when using switch pattern in this(...) or super(...) (Bug - P2)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 19217

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

Using diff file

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

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented May 13, 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 May 13, 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:

8332106: VerifyError when using switch pattern in this(...) or super(...)

Reviewed-by: abimpoudis, vromero

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

  • c2180d1: 8315767: InetAddress: constructing objects from BSD literal addresses
  • 2a11e0d: 8332743: Update comment related to JDK-8320522
  • 6829d9a: 8332122: [nmt] Totals for malloc should show total peak
  • 9d332e6: 8307193: Several Swing jtreg tests use class.forName on L&F classes
  • 98f6a80: 8332490: JMH org.openjdk.bench.java.util.zip.InflaterInputStreams.inflaterInputStreamRead OOM
  • 3d4185a: 8332739: Problemlist compiler/codecache/CheckLargePages until JDK-8332654 is fixed
  • c4557a7: 8332463: Byte conditional pattern case element dominates short constant case element
  • d59c12f: 8329718: Incorrect @since tags in elements in jdk.compiler and java.compiler
  • b4d1454: 8332740: [BACKOUT] JDK-8331081 'internal proprietary API' diagnostics if --system is configured to an earlier JDK version
  • 37c4778: 8332096: hotspot-ide-project fails with this-escape
  • ... and 104 more: https://git.openjdk.org/jdk/compare/1484153c1a092cefc20270b35aa1e508280843a4...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 13, 2024
@openjdk
Copy link

openjdk bot commented May 13, 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 May 13, 2024
@mlbridge
Copy link

mlbridge bot commented May 13, 2024

Webrevs

import java.util.Objects;
import java.util.function.Supplier;

public class UninitializedThisException {
Copy link
Member

Choose a reason for hiding this comment

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

nit: It would be nice to have a test for super(...) as well even though I am confident that it works. Feel free to ignore if there is no need for an extra test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Tests enahanced: 9dacde8

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

@lahodaj lahodaj changed the title 8332106: VerifyError when using switch pattern in this(...) or super(…) 8332106: VerifyError when using switch pattern in this(...) or super(...) May 16, 2024
Set<JCMethodInvocation> invocationsWithPatternMatchingCatch = Set.of();
ListBuffer<int[]> patternMatchingInvocationRanges;
PatternMatchingCatchConfigration patternMatchingCatchConfiguration =
new PatternMatchingCatchConfigration(Set.of(), null, null, null);
Copy link
Contributor

Choose a reason for hiding this comment

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

typo: Configuration

Copy link
Contributor

@vicente-romero-oracle vicente-romero-oracle left a comment

Choose a reason for hiding this comment

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

looks sensible

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

lahodaj commented May 24, 2024

/integrate

@openjdk
Copy link

openjdk bot commented May 24, 2024

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

  • da3001d: 8331975: Enable case-insensitive check in ccache and keytab entry lookup
  • 424eb60: 8331683: Clean up GetCarrierThread
  • 9b1d6d6: 8316328: Test jdk/jfr/event/oldobject/TestSanityDefault.java times out for some heap sizes
  • f8a3e4e: 8328998: Encoding support for Intel APX extended general-purpose registers
  • ddd73b4: 8332082: Shenandoah: Use consistent tests to determine when pre-write barrier is active
  • 0a9d1f8: 8332749: Broken link in MemorySegment.Scope.html
  • c9a7b97: 8332829: [BACKOUT] C2: crash in compiled code because of dependency on removed range check CastIIs
  • 7fd9d6c: 8332340: Add JavacBench as a test case for CDS
  • 417d174: 8331348: Some incremental builds deposit files in the make directory
  • 303ac9f: 8332671: Logging for pretouching thread stacks shows wrong memory range
  • ... and 123 more: https://git.openjdk.org/jdk/compare/1484153c1a092cefc20270b35aa1e508280843a4...master

Your commit was automatically rebased without conflicts.

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

openjdk bot commented May 24, 2024

@lahodaj Pushed as commit af056c1.

💡 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.

3 participants