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 ;
@@ -59,13 +60,16 @@ private static final class AllocatedObject {
59
60
}
60
61
}
61
62
63
+ public static int cnt ;
62
64
public static volatile Object obj1 ;
63
65
public static volatile Double object1 = (double ) 123 ;
64
66
public static volatile AllocatedObject object2 = new AllocatedObject (123 );
65
67
66
68
public static String moveIntoBranchBox (int id ) {
67
69
Double box = object1 + 1 ;
68
70
if (id == 0 ) {
71
+ // Prevent if simplification
72
+ cnt ++;
69
73
obj1 = new AtomicReference <>(box );
70
74
}
71
75
return "value" ;
@@ -82,7 +86,7 @@ public static String moveIntoBranch(int id) {
82
86
@ Test
83
87
public void testJMHBlackholePattern () {
84
88
/*
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
86
90
* effects still need to be applied since they move the allocation between blocks.
87
91
*/
88
92
@@ -91,7 +95,7 @@ public void testJMHBlackholePattern() {
91
95
Assert .assertEquals (1 , graph .getNodes ().filter (UnboxNode .class ).count ());
92
96
Assert .assertEquals (1 , graph .getNodes ().filter (BoxNode .class ).count ());
93
97
// 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 );
95
99
96
100
// test with a normal object
97
101
prepareGraph ("moveIntoBranch" , false );
@@ -133,23 +137,24 @@ public static String noLoopIterationEmpty(int id) {
133
137
@ Test
134
138
public void testNoLoopIteration () {
135
139
/*
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.
138
141
*/
139
142
140
143
// test with a boxing object
141
144
prepareGraph ("noLoopIterationBox" , true );
145
+ List <BoxNode > boxNodes = graph .getNodes ().filter (BoxNode .class ).snapshot ();
142
146
Assert .assertEquals (1 , boxNodes .size ());
143
- Assert .assertTrue (boxNodes .get ( 0 ). isAlive () );
147
+ Assert .assertTrue (boxNodes .getFirst (). next () instanceof EndNode );
144
148
145
149
// test with a normal object (needs one iteration to replace NewInstance with
146
150
// CommitAllocation)
147
151
for (String name : new String []{"noLoopIterationEmpty" , "noLoopIteration" }) {
148
152
prepareGraph (name , false );
149
153
List <CommitAllocationNode > allocations = graph .getNodes ().filter (CommitAllocationNode .class ).snapshot ();
150
154
new PartialEscapePhase (true , false , createCanonicalizerPhase (), null , graph .getOptions ()).apply (graph , context );
151
- Assert .assertEquals (1 , allocations .size ());
155
+ Assert .assertEquals (2 , allocations .size ());
152
156
Assert .assertTrue (allocations .get (0 ).isAlive ());
157
+ Assert .assertTrue (allocations .get (1 ).isAlive ());
153
158
}
154
159
}
155
160
0 commit comments