Skip to content

8357381: C2: assert(false) failed: should not be here - #31037

Closed
sarannat wants to merge 8 commits into
openjdk:masterfrom
sarannat:JDK-8357381
Closed

8357381: C2: assert(false) failed: should not be here#31037
sarannat wants to merge 8 commits into
openjdk:masterfrom
sarannat:JDK-8357381

Conversation

@sarannat

@sarannat sarannat commented May 5, 2026

Copy link
Copy Markdown
Contributor

Issue
The assertion assert(false, "should not be here") in ConnectionGraph::move_inst_mem fires because a StoreB node has StrEquals as a memory user.

Analysis
The main issues starts after the first iteration of iterative escape analysis. As mentioned in JDK-8357381, EA#0 does lock removal. During IGVN after EA#0, the string intrinsic node StrEqual undergoes an ideal transformation (StrIntrinsicNode::Ideal()) which peels its MergeMem input node. At this point StoreB becomes a direct input of StrEquals.

Now EA#1 runs on the transformed graph. Phase 2 of split_unique_types explicitly allows StrEquals as a user of StoreB. In Phase 4, split_unique_types then calls move_inst_mem which is responsible for moving memory users to their memory slices. However, move_inst_mem only handles MergeMem, MemBar, Mem, and Phi as memory user. Since, StrEquals is not handled in move_inst_mem even though it is allowed in Phase 2 of split_unique_types it fires the assertion assert(false, "should not be here").

Solution
In the proposed fix, I have extended move_inst_mem to move string intrinsic nodes that are explicitly allowed in Phase 2 of split_unique_type to their appropriate memory slices.

Testing
Tier1-3 and Github actions

Question to reviewers
Please let me know if this fix looks reasonable.

Thank you @danielogh for the initial analysis.



Progress

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

Issue

  • JDK-8357381: C2: assert(false) failed: should not be here (Bug - P3)(⚠️ The fixVersion in this issue is [28] but the fixVersion in .jcheck/conf is 27, a new backport will be created when this pr is integrated.)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 31037

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

Using diff file

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

Using Webrev

Link to Webrev Comment

@bridgekeeper

bridgekeeper Bot commented May 5, 2026

Copy link
Copy Markdown

👋 Welcome back snatarajan! 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

openjdk Bot commented May 5, 2026

Copy link
Copy Markdown

❗ This change is not yet ready to be integrated.
See the Progress checklist in the description for automated requirements.

@openjdk openjdk Bot added the hotspot-compiler hotspot-compiler-dev@openjdk.org label May 5, 2026
@openjdk

openjdk Bot commented May 5, 2026

Copy link
Copy Markdown

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

  • hotspot-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 commented May 5, 2026

Copy link
Copy Markdown

The total number of required reviews for this PR has been set to 2 based on the presence of this label: hotspot-compiler. This can be overridden with the /reviewers command.

@sarannat
sarannat marked this pull request as ready for review May 5, 2026 17:54
@openjdk openjdk Bot added the rfr Pull request is ready for review label May 5, 2026
@mlbridge

mlbridge Bot commented May 5, 2026

Copy link
Copy Markdown

Comment thread src/hotspot/share/opto/escape.cpp Outdated
Comment on lines +4152 to +4153
} else if (use->Opcode() == Op_AryEq || use->Opcode() == Op_StrComp || use->Opcode() == Op_CountPositives ||
use->Opcode() == Op_StrEquals || use->Opcode() == Op_StrIndexOf || use->Opcode() == Op_StrIndexOfChar) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you add a new method to combine these check into one place and use it here and other places where which check these intrinsics?

Comment thread src/hotspot/share/opto/escape.cpp Outdated
Comment on lines +4154 to +4155
if (alias_idx == general_idx)
continue;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could you add braces here?

Comment thread src/hotspot/share/opto/escape.cpp Outdated
Comment on lines +4157 to +4164
uint orig_uniq = C->unique();
Node* m = find_inst_mem(n, general_idx, orig_phis);
assert(orig_uniq == C->unique(), "no new nodes");
igvn->hash_delete(use);
imax -= use->replace_edge(n, m, igvn);
igvn->hash_insert(use);
record_for_optimizer(use);
--i;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Also this pattern (or part of it) seems quite repeated across this if...else. Maybe it would it be worth extracting it?

@anton-seoane

Copy link
Copy Markdown
Contributor

And... I think adding a regression test for this would be easy 😉, and probably worth it

Comment thread src/hotspot/share/opto/escape.cpp Outdated
return result;
}

Node* ConnectionGraph::find_inst_mem_assert_no_new_node(Node *orig_mem, int alias_idx, GrowableArray<PhiNode *> &orig_phis) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
Node* ConnectionGraph::find_inst_mem_assert_no_new_node(Node *orig_mem, int alias_idx, GrowableArray<PhiNode *> &orig_phis) {
Node* ConnectionGraph::find_inst_mem_assert_no_new_node(Node* orig_mem, int alias_idx, GrowableArray<PhiNode*>& orig_phis) {

Comment thread src/hotspot/share/opto/escape.hpp Outdated

void move_inst_mem(Node* n, GrowableArray<PhiNode *> &orig_phis);
Node* find_inst_mem(Node* mem, int alias_idx,GrowableArray<PhiNode *> &orig_phi_worklist, uint rec_depth = 0);
Node* find_inst_mem_assert_no_new_node(Node* mem, int alias_idx,GrowableArray<PhiNode *> &orig_phi_worklist);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
Node* find_inst_mem_assert_no_new_node(Node* mem, int alias_idx,GrowableArray<PhiNode *> &orig_phi_worklist);
Node* find_inst_mem_assert_no_new_node(Node* mem, int alias_idx,GrowableArray<PhiNode*>& orig_phi_worklist);

@sarannat

Copy link
Copy Markdown
Contributor Author

Added the test from JDK-8384257 (which is a duplicate) to the regression test as suggested by @chhagedorn.

* @test
* @bug 8357381
* @summary C2 compilation fails with C2: assert(false) failed: should not be here
* @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:-TieredCompilation -Xbatch -XX:CompileCommand=compileonly,compiler.escapeAnalysis.TestReadOnlyStringIntrinsicDuringEA::main

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why you need -XX:+UnlockDiagnosticVMOptions ?

You also need @requires vm.compiler2.enabled I think.

Compile only main will produce only OSR compilation. Is 10K iterations is enough for that?
Consider using -XX:CompileThreshold=n to reduce number of iterations to trigger C2 compilation early.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thank you for the review. I removed -XX:+UnlockDiagnosticVMOptions and made modifications to address your comments.

@vnkozlov

Copy link
Copy Markdown
Contributor

@sarannat please see GHA failures:

/home/runner/work/jdk/jdk/test/hotspot/jtreg/compiler/escapeAnalysis/TestReadOnlyStringIntrinsicDuringEA.java:37: error: package c159 does not exist
 public class TestReadOnlyStringIntrinsicDuringEA extends c159.HelperBase {
                                                              ^
1 error

}

public static void main(String[] strArr) {
for (int t = 0; t < 100_000; t++) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we also need 100000 iterations now that CompileThreshold is in place?

@anton-seoane anton-seoane left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this looks good now

op == Op_AryEq || op == Op_StrComp || op == Op_CountPositives ||
op == Op_StrCompressedCopy || op == Op_StrInflatedCopy || op == Op_VectorizedHashCode ||
op == Op_StrEquals || op == Op_StrIndexOf || op == Op_StrIndexOfChar)) {
is_mem_read_only_string_intrinsic(use) || op == Op_VectorizedHashCode ||

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What about EncodeISOArray? Should it receive similar treatment?

return result;
}

bool ConnectionGraph::is_mem_read_only_string_intrinsic(Node* n) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This name is a little misleading, AryEq is not a string intrinsic, for example, and why is VectorizedHashCode not here?

@openjdk

openjdk Bot commented Jun 4, 2026

Copy link
Copy Markdown

@sarannat this pull request can not be integrated into master due to one or more merge conflicts. To resolve these merge conflicts and update this pull request you can run the following commands in the local repository for your personal fork:

git checkout JDK-8357381
git fetch https://git.openjdk.org/jdk.git master
git merge FETCH_HEAD
# resolve conflicts and follow the instructions given by git merge
git commit -m "Merge master"
git push

@openjdk openjdk Bot added the merge-conflict Pull request has merge conflict with target branch label Jun 4, 2026
@eme64

eme64 commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

@sarannat Are you planning to keep working on this? I'd assume not?

@merykitty @vnkozlov It would be a shame if this patch was dropped. We should see that someone picks it up and brings it over the finish line, with proper attribution.

@sarannat

sarannat commented Jun 8, 2026

Copy link
Copy Markdown
Contributor Author

@eme64 : Thank you for the reminder. I do plan to see this PR to completion. I will start addressing the comments and merge-conflicts this week.

@bridgekeeper

bridgekeeper Bot commented Jul 7, 2026

Copy link
Copy Markdown

@sarannat 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 issue a /touch or /keepalive command to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration!

@bridgekeeper

bridgekeeper Bot commented Aug 4, 2026

Copy link
Copy Markdown

@sarannat 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 pull request command.

@bridgekeeper bridgekeeper Bot closed this Aug 4, 2026
@eme64

eme64 commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

@sarannat Are you still interested in working on this?

@TobiHartmann

Copy link
Copy Markdown
Member

Reopened with #32467.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

hotspot-compiler hotspot-compiler-dev@openjdk.org merge-conflict Pull request has merge conflict with target branch rfr Pull request is ready for review

Development

Successfully merging this pull request may close these issues.

6 participants