Skip to content

Commit 74bc60b

Browse files
author
Vladimir Kozlov
committed
8347997: assert(false) failed: EA: missing memory path
Backport-of: 6b581d22e13599b16b38aff1ca5a795c6a910d30
1 parent d2262fe commit 74bc60b

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
@@ -3778,6 +3778,20 @@ bool LibraryCallKit::inline_native_Continuation_pinning(bool unpin) {
37783778
Node* test_pin_count_over_underflow = _gvn.transform(new BoolNode(pin_count_cmp, BoolTest::eq));
37793779
IfNode* iff_pin_count_over_underflow = create_and_map_if(control(), test_pin_count_over_underflow, PROB_MIN, COUNT_UNKNOWN);
37803780

3781+
// True branch, pin count over/underflow.
3782+
Node* pin_count_over_underflow = _gvn.transform(new IfTrueNode(iff_pin_count_over_underflow));
3783+
{
3784+
// Trap (but not deoptimize (Action_none)) and continue in the interpreter
3785+
// which will throw IllegalStateException for pin count over/underflow.
3786+
// No memory changed so far - we can use memory create by reset_memory()
3787+
// at the beginning of this intrinsic. No need to call reset_memory() again.
3788+
PreserveJVMState pjvms(this);
3789+
set_control(pin_count_over_underflow);
3790+
uncommon_trap(Deoptimization::Reason_intrinsic,
3791+
Deoptimization::Action_none);
3792+
assert(stopped(), "invariant");
3793+
}
3794+
37813795
// False branch, no pin count over/underflow. Increment or decrement pin count and store back.
37823796
Node* valid_pin_count = _gvn.transform(new IfFalseNode(iff_pin_count_over_underflow));
37833797
set_control(valid_pin_count);
@@ -3789,20 +3803,7 @@ bool LibraryCallKit::inline_native_Continuation_pinning(bool unpin) {
37893803
next_pin_count = _gvn.transform(new AddINode(pin_count, _gvn.intcon(1)));
37903804
}
37913805

3792-
Node* updated_pin_count_memory = store_to_memory(control(), pin_count_offset, next_pin_count, T_INT, MemNode::unordered);
3793-
3794-
// True branch, pin count over/underflow.
3795-
Node* pin_count_over_underflow = _gvn.transform(new IfTrueNode(iff_pin_count_over_underflow));
3796-
{
3797-
// Trap (but not deoptimize (Action_none)) and continue in the interpreter
3798-
// which will throw IllegalStateException for pin count over/underflow.
3799-
PreserveJVMState pjvms(this);
3800-
set_control(pin_count_over_underflow);
3801-
set_all_memory(input_memory_state);
3802-
uncommon_trap_exact(Deoptimization::Reason_intrinsic,
3803-
Deoptimization::Action_none);
3804-
assert(stopped(), "invariant");
3805-
}
3806+
store_to_memory(control(), pin_count_offset, next_pin_count, T_INT, MemNode::unordered);
38063807

38073808
// Result of top level CFG and Memory.
38083809
RegionNode* result_rgn = new RegionNode(PATH_LIMIT);
@@ -3812,7 +3813,7 @@ bool LibraryCallKit::inline_native_Continuation_pinning(bool unpin) {
38123813

38133814
result_rgn->init_req(_true_path, _gvn.transform(valid_pin_count));
38143815
result_rgn->init_req(_false_path, _gvn.transform(continuation_is_null));
3815-
result_mem->init_req(_true_path, _gvn.transform(updated_pin_count_memory));
3816+
result_mem->init_req(_true_path, _gvn.transform(reset_memory()));
38163817
result_mem->init_req(_false_path, _gvn.transform(input_memory_state));
38173818

38183819
// 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)