Skip to content

Commit e697712

Browse files
mur47x111zapster
authored andcommitted
AtomicReference will participate in PEA while WeakReference won't
1 parent a6a3079 commit e697712

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

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

Lines changed: 12 additions & 11 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;
@@ -38,13 +39,9 @@
3839

3940
public class PartialEscapeAnalysisIterationTest extends EATestBase {
4041

41-
// remember boxing nodes from before PEA
42-
private List<BoxNode> boxNodes;
43-
4442
@Override
4543
protected void canonicalizeGraph() {
4644
super.canonicalizeGraph();
47-
boxNodes = graph.getNodes().filter(BoxNode.class).snapshot();
4845
}
4946

5047
private static final class AllocatedObject {
@@ -59,13 +56,16 @@ private static final class AllocatedObject {
5956
}
6057
}
6158

59+
public static int cnt;
6260
public static volatile Object obj1;
6361
public static volatile Double object1 = (double) 123;
6462
public static volatile AllocatedObject object2 = new AllocatedObject(123);
6563

6664
public static String moveIntoBranchBox(int id) {
6765
Double box = object1 + 1;
6866
if (id == 0) {
67+
// Prevent if simplification
68+
cnt++;
6969
obj1 = new AtomicReference<>(box);
7070
}
7171
return "value";
@@ -82,7 +82,7 @@ public static String moveIntoBranch(int id) {
8282
@Test
8383
public void testJMHBlackholePattern() {
8484
/*
85-
* The overall number of allocations in this methods does not change during PEA, but the
85+
* The overall number of allocations in these methods does not change during PEA, but the
8686
* effects still need to be applied since they move the allocation between blocks.
8787
*/
8888

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

9696
// test with a normal object
9797
prepareGraph("moveIntoBranch", false);
@@ -133,23 +133,24 @@ public static String noLoopIterationEmpty(int id) {
133133
@Test
134134
public void testNoLoopIteration() {
135135
/*
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).
136+
* After PEA, the BoxNode stays outside the loop.
138137
*/
139138

140139
// test with a boxing object
141140
prepareGraph("noLoopIterationBox", true);
141+
List<BoxNode> boxNodes = graph.getNodes().filter(BoxNode.class).snapshot();
142142
Assert.assertEquals(1, boxNodes.size());
143-
Assert.assertTrue(boxNodes.get(0).isAlive());
143+
Assert.assertTrue(boxNodes.getFirst().next() instanceof EndNode);
144144

145145
// test with a normal object (needs one iteration to replace NewInstance with
146146
// CommitAllocation)
147147
for (String name : new String[]{"noLoopIterationEmpty", "noLoopIteration"}) {
148148
prepareGraph(name, false);
149149
List<CommitAllocationNode> allocations = graph.getNodes().filter(CommitAllocationNode.class).snapshot();
150150
new PartialEscapePhase(true, false, createCanonicalizerPhase(), null, graph.getOptions()).apply(graph, context);
151-
Assert.assertEquals(1, allocations.size());
151+
Assert.assertEquals(2, allocations.size());
152152
Assert.assertTrue(allocations.get(0).isAlive());
153+
Assert.assertTrue(allocations.get(1).isAlive());
153154
}
154155
}
155156

0 commit comments

Comments
 (0)