Skip to content

Commit 8608b16

Browse files
marc-chevalierTobiHartmann
authored andcommitted
8348887: Create IR framework test for JDK-8347997
Reviewed-by: thartmann, chagedorn
1 parent 23eb648 commit 8608b16

File tree

1 file changed

+124
-0
lines changed

1 file changed

+124
-0
lines changed
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
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+
* @requires vm.continuations
27+
* @bug 8347997
28+
* @library /test/lib /
29+
* @summary Test that Continuation.pin() and unpin() intrinsics work with EA.
30+
* @modules java.base/jdk.internal.vm
31+
* @run driver compiler.c2.irTests.TestContinuationPinningAndEA
32+
*/
33+
34+
package compiler.c2.irTests;
35+
36+
import compiler.lib.ir_framework.*;
37+
import jdk.internal.vm.Continuation;
38+
39+
public class TestContinuationPinningAndEA {
40+
public static void main(String[] args) {
41+
TestFramework.runWithFlags("--add-modules", "java.base", "--add-exports", "java.base/jdk.internal.vm=ALL-UNNAMED");
42+
}
43+
44+
@Run(test = {
45+
"test_AllocPinUnpin", "test_PinUnpinAlloc",
46+
"test_AllocPinUnpinNoInline", "test_PinUnpinAllocNoInline",
47+
})
48+
public void runMethod() {
49+
test_AllocPinUnpin();
50+
test_PinUnpinAlloc();
51+
test_AllocPinUnpinNoInline();
52+
test_PinUnpinAllocNoInline();
53+
}
54+
55+
// ===Cases where allocations are removed===
56+
static class AllocPinUnpin {
57+
final Object o;
58+
59+
@ForceInline
60+
public AllocPinUnpin() {
61+
o = new Object();
62+
Continuation.pin();
63+
Continuation.unpin();
64+
}
65+
}
66+
67+
static class PinUnpinAlloc {
68+
final Object o;
69+
70+
@ForceInline
71+
public PinUnpinAlloc() {
72+
Continuation.pin();
73+
Continuation.unpin();
74+
o = new Object();
75+
}
76+
}
77+
78+
@Test
79+
@IR(failOn = {IRNode.ALLOC})
80+
void test_AllocPinUnpin() {
81+
new AllocPinUnpin();
82+
}
83+
84+
@Test
85+
@IR(failOn = {IRNode.ALLOC})
86+
void test_PinUnpinAlloc() {
87+
new PinUnpinAlloc();
88+
}
89+
90+
// ===Sanity check that allocations would happen===
91+
static class AllocPinUnpinNoInline {
92+
final Object o;
93+
94+
@DontInline
95+
public AllocPinUnpinNoInline() {
96+
o = new Object();
97+
Continuation.pin();
98+
Continuation.unpin();
99+
}
100+
}
101+
102+
static class PinUnpinAllocNoInline {
103+
final Object o;
104+
105+
@DontInline
106+
public PinUnpinAllocNoInline() {
107+
Continuation.pin();
108+
Continuation.unpin();
109+
o = new Object();
110+
}
111+
}
112+
113+
@Test
114+
@IR(counts = {IRNode.ALLOC, ">0"})
115+
void test_AllocPinUnpinNoInline() {
116+
new AllocPinUnpinNoInline();
117+
}
118+
119+
@Test
120+
@IR(counts = {IRNode.ALLOC, ">0"})
121+
void test_PinUnpinAllocNoInline() {
122+
new PinUnpinAllocNoInline();
123+
}
124+
}

0 commit comments

Comments
 (0)