1
1
/*
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.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
30
30
import org .junit .Assert ;
31
31
import org .junit .Test ;
32
32
33
+ import jdk .graal .compiler .nodes .EndNode ;
33
34
import jdk .graal .compiler .nodes .extended .BoxNode ;
34
35
import jdk .graal .compiler .nodes .extended .UnboxNode ;
35
36
import jdk .graal .compiler .nodes .java .StoreFieldNode ;
38
39
39
40
public class PartialEscapeAnalysisIterationTest extends EATestBase {
40
41
41
- // remember boxing nodes from before PEA
42
- private List <BoxNode > boxNodes ;
43
-
44
42
@ Override
45
43
protected void canonicalizeGraph () {
46
44
super .canonicalizeGraph ();
47
- boxNodes = graph .getNodes ().filter (BoxNode .class ).snapshot ();
48
45
}
49
46
50
47
private static final class AllocatedObject {
@@ -59,13 +56,16 @@ private static final class AllocatedObject {
59
56
}
60
57
}
61
58
59
+ public static int cnt ;
62
60
public static volatile Object obj1 ;
63
61
public static volatile Double object1 = (double ) 123 ;
64
62
public static volatile AllocatedObject object2 = new AllocatedObject (123 );
65
63
66
64
public static String moveIntoBranchBox (int id ) {
67
65
Double box = object1 + 1 ;
68
66
if (id == 0 ) {
67
+ // Prevent if simplification
68
+ cnt ++;
69
69
obj1 = new AtomicReference <>(box );
70
70
}
71
71
return "value" ;
@@ -82,7 +82,7 @@ public static String moveIntoBranch(int id) {
82
82
@ Test
83
83
public void testJMHBlackholePattern () {
84
84
/*
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
86
86
* effects still need to be applied since they move the allocation between blocks.
87
87
*/
88
88
@@ -91,7 +91,7 @@ public void testJMHBlackholePattern() {
91
91
Assert .assertEquals (1 , graph .getNodes ().filter (UnboxNode .class ).count ());
92
92
Assert .assertEquals (1 , graph .getNodes ().filter (BoxNode .class ).count ());
93
93
// 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 );
95
95
96
96
// test with a normal object
97
97
prepareGraph ("moveIntoBranch" , false );
@@ -133,23 +133,24 @@ public static String noLoopIterationEmpty(int id) {
133
133
@ Test
134
134
public void testNoLoopIteration () {
135
135
/*
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.
138
137
*/
139
138
140
139
// test with a boxing object
141
140
prepareGraph ("noLoopIterationBox" , true );
141
+ List <BoxNode > boxNodes = graph .getNodes ().filter (BoxNode .class ).snapshot ();
142
142
Assert .assertEquals (1 , boxNodes .size ());
143
- Assert .assertTrue (boxNodes .get ( 0 ). isAlive () );
143
+ Assert .assertTrue (boxNodes .getFirst (). next () instanceof EndNode );
144
144
145
145
// test with a normal object (needs one iteration to replace NewInstance with
146
146
// CommitAllocation)
147
147
for (String name : new String []{"noLoopIterationEmpty" , "noLoopIteration" }) {
148
148
prepareGraph (name , false );
149
149
List <CommitAllocationNode > allocations = graph .getNodes ().filter (CommitAllocationNode .class ).snapshot ();
150
150
new PartialEscapePhase (true , false , createCanonicalizerPhase (), null , graph .getOptions ()).apply (graph , context );
151
- Assert .assertEquals (1 , allocations .size ());
151
+ Assert .assertEquals (2 , allocations .size ());
152
152
Assert .assertTrue (allocations .get (0 ).isAlive ());
153
+ Assert .assertTrue (allocations .get (1 ).isAlive ());
153
154
}
154
155
}
155
156
0 commit comments