Skip to content

Commit 33f2e34

Browse files
committed
AtomicReference will participate in PEA while WeakReference won't
1 parent a6a3079 commit 33f2e34

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/core/test/ea/PartialEscapeAnalysisIterationTest.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -30,6 +30,7 @@
3030
import org.junit.Assert;
3131
import org.junit.Test;
3232

33+
import jdk.graal.compiler.nodes.EndNode;
3334
import jdk.graal.compiler.nodes.extended.BoxNode;
3435
import jdk.graal.compiler.nodes.extended.UnboxNode;
3536
import jdk.graal.compiler.nodes.java.StoreFieldNode;
@@ -59,13 +60,16 @@ private static final class AllocatedObject {
5960
}
6061
}
6162

63+
public static int cnt;
6264
public static volatile Object obj1;
6365
public static volatile Double object1 = (double) 123;
6466
public static volatile AllocatedObject object2 = new AllocatedObject(123);
6567

6668
public static String moveIntoBranchBox(int id) {
6769
Double box = object1 + 1;
6870
if (id == 0) {
71+
// Prevent if simplification
72+
cnt++;
6973
obj1 = new AtomicReference<>(box);
7074
}
7175
return "value";
@@ -82,7 +86,7 @@ public static String moveIntoBranch(int id) {
8286
@Test
8387
public void testJMHBlackholePattern() {
8488
/*
85-
* The overall number of allocations in this methods does not change during PEA, but the
89+
* The overall number of allocations in these methods does not change during PEA, but the
8690
* effects still need to be applied since they move the allocation between blocks.
8791
*/
8892

@@ -91,7 +95,7 @@ public void testJMHBlackholePattern() {
9195
Assert.assertEquals(1, graph.getNodes().filter(UnboxNode.class).count());
9296
Assert.assertEquals(1, graph.getNodes().filter(BoxNode.class).count());
9397
// the boxing needs to be moved into the branch
94-
Assert.assertTrue(graph.getNodes().filter(BoxNode.class).first().next() instanceof StoreFieldNode);
98+
Assert.assertTrue(graph.getNodes().filter(BoxNode.class).first().next() instanceof CommitAllocationNode);
9599

96100
// test with a normal object
97101
prepareGraph("moveIntoBranch", false);
@@ -133,23 +137,24 @@ public static String noLoopIterationEmpty(int id) {
133137
@Test
134138
public void testNoLoopIteration() {
135139
/*
136-
* PEA should not apply any effects on this method, since it cannot move the allocation into
137-
* the branch anyway (it needs to stay outside the loop).
140+
* After PEA, the BoxNode stays outside the loop.
138141
*/
139142

140143
// test with a boxing object
141144
prepareGraph("noLoopIterationBox", true);
145+
List<BoxNode> boxNodes = graph.getNodes().filter(BoxNode.class).snapshot();
142146
Assert.assertEquals(1, boxNodes.size());
143-
Assert.assertTrue(boxNodes.get(0).isAlive());
147+
Assert.assertTrue(boxNodes.getFirst().next() instanceof EndNode);
144148

145149
// test with a normal object (needs one iteration to replace NewInstance with
146150
// CommitAllocation)
147151
for (String name : new String[]{"noLoopIterationEmpty", "noLoopIteration"}) {
148152
prepareGraph(name, false);
149153
List<CommitAllocationNode> allocations = graph.getNodes().filter(CommitAllocationNode.class).snapshot();
150154
new PartialEscapePhase(true, false, createCanonicalizerPhase(), null, graph.getOptions()).apply(graph, context);
151-
Assert.assertEquals(1, allocations.size());
155+
Assert.assertEquals(2, allocations.size());
152156
Assert.assertTrue(allocations.get(0).isAlive());
157+
Assert.assertTrue(allocations.get(1).isAlive());
153158
}
154159
}
155160

0 commit comments

Comments
 (0)