Skip to content

Commit 6b581d2

Browse files
author
Vladimir Kozlov
committed
8347997: assert(false) failed: EA: missing memory path
Reviewed-by: thartmann, chagedorn
1 parent 4662363 commit 6b581d2

File tree

2 files changed

+93
-15
lines changed

2 files changed

+93
-15
lines changed

src/hotspot/share/opto/library_call.cpp

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3761,6 +3761,20 @@ bool LibraryCallKit::inline_native_Continuation_pinning(bool unpin) {
37613761
Node* test_pin_count_over_underflow = _gvn.transform(new BoolNode(pin_count_cmp, BoolTest::eq));
37623762
IfNode* iff_pin_count_over_underflow = create_and_map_if(control(), test_pin_count_over_underflow, PROB_MIN, COUNT_UNKNOWN);
37633763

3764+
// True branch, pin count over/underflow.
3765+
Node* pin_count_over_underflow = _gvn.transform(new IfTrueNode(iff_pin_count_over_underflow));
3766+
{
3767+
// Trap (but not deoptimize (Action_none)) and continue in the interpreter
3768+
// which will throw IllegalStateException for pin count over/underflow.
3769+
// No memory changed so far - we can use memory create by reset_memory()
3770+
// at the beginning of this intrinsic. No need to call reset_memory() again.
3771+
PreserveJVMState pjvms(this);
3772+
set_control(pin_count_over_underflow);
3773+
uncommon_trap(Deoptimization::Reason_intrinsic,
3774+
Deoptimization::Action_none);
3775+
assert(stopped(), "invariant");
3776+
}
3777+
37643778
// False branch, no pin count over/underflow. Increment or decrement pin count and store back.
37653779
Node* valid_pin_count = _gvn.transform(new IfFalseNode(iff_pin_count_over_underflow));
37663780
set_control(valid_pin_count);
@@ -3772,20 +3786,7 @@ bool LibraryCallKit::inline_native_Continuation_pinning(bool unpin) {
37723786
next_pin_count = _gvn.transform(new AddINode(pin_count, _gvn.intcon(1)));
37733787
}
37743788

3775-
Node* updated_pin_count_memory = store_to_memory(control(), pin_count_offset, next_pin_count, T_INT, MemNode::unordered);
3776-
3777-
// True branch, pin count over/underflow.
3778-
Node* pin_count_over_underflow = _gvn.transform(new IfTrueNode(iff_pin_count_over_underflow));
3779-
{
3780-
// Trap (but not deoptimize (Action_none)) and continue in the interpreter
3781-
// which will throw IllegalStateException for pin count over/underflow.
3782-
PreserveJVMState pjvms(this);
3783-
set_control(pin_count_over_underflow);
3784-
set_all_memory(input_memory_state);
3785-
uncommon_trap_exact(Deoptimization::Reason_intrinsic,
3786-
Deoptimization::Action_none);
3787-
assert(stopped(), "invariant");
3788-
}
3789+
store_to_memory(control(), pin_count_offset, next_pin_count, T_INT, MemNode::unordered);
37893790

37903791
// Result of top level CFG and Memory.
37913792
RegionNode* result_rgn = new RegionNode(PATH_LIMIT);
@@ -3795,7 +3796,7 @@ bool LibraryCallKit::inline_native_Continuation_pinning(bool unpin) {
37953796

37963797
result_rgn->init_req(_true_path, _gvn.transform(valid_pin_count));
37973798
result_rgn->init_req(_false_path, _gvn.transform(continuation_is_null));
3798-
result_mem->init_req(_true_path, _gvn.transform(updated_pin_count_memory));
3799+
result_mem->init_req(_true_path, _gvn.transform(reset_memory()));
37993800
result_mem->init_req(_false_path, _gvn.transform(input_memory_state));
38003801

38013802
// Set output state.
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
* Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
/**
25+
* @test
26+
* @bug 8347997
27+
* @summary Test that Continuation.pin() and unpin() intrinsics work with EA.
28+
* @modules java.base/jdk.internal.vm
29+
* @run main TestContinuationPinningAndEA
30+
*/
31+
32+
import jdk.internal.vm.Continuation;
33+
34+
public class TestContinuationPinningAndEA {
35+
36+
static class FailsEA {
37+
final Object o;
38+
39+
public FailsEA() throws Throwable {
40+
o = new Object();
41+
Continuation.pin();
42+
Continuation.unpin();
43+
}
44+
}
45+
46+
static class Crashes {
47+
final Object o;
48+
49+
public Crashes() throws Throwable {
50+
Continuation.pin();
51+
Continuation.unpin();
52+
o = new Object();
53+
}
54+
}
55+
56+
static void test_FailsEA() throws Throwable {
57+
for (int i = 0; i < 10_000; ++i) {
58+
new FailsEA();
59+
}
60+
}
61+
62+
static void test_Crashes() throws Throwable {
63+
for (int i = 0; i < 10_000; ++i) {
64+
new Crashes();
65+
}
66+
}
67+
68+
public static void main(String[] args) throws Throwable {
69+
int iterations = 100;
70+
for (int i = 0; i < iterations; ++i) {
71+
test_FailsEA();
72+
}
73+
for (int i = 0; i < iterations; ++i) {
74+
test_Crashes();
75+
}
76+
}
77+
}

0 commit comments

Comments
 (0)