@@ -55,7 +55,8 @@ public static void main(String[] args) {
5555
5656 @ Run (test = {"testLoad" , "testStore" , "testLoadDependent1" , "testLoadDependent2" , "testLoadArray" ,
5757 "testLoadArrayOverlap" , "testLoadIndependentAliasClasses" , "testLoadMismatched" ,
58- "testLoadArrayCopy" , "testLoadArrayCopyUnknownLength" })
58+ "testLoadArrayCopy" , "testLoadArrayCopyUnknownLength" ,
59+ "testAllocationIndependence1" , "testAllocationIndependence2" })
5960 public void run () {
6061 C1 c1 = new C1 ();
6162 C2 c2 = new C2 ();
@@ -81,6 +82,9 @@ public void run() {
8182 Asserts .assertEQ (1 , testLoadArrayCopyUnknownLength (a1 , a2 , 100 , 1 ));
8283 a1 [2 ] = 0 ;
8384 Asserts .assertEQ (0 , testLoadArrayCopyUnknownLength (a1 , a2 , 2 , 1 ));
85+
86+ Asserts .assertEQ (3 , testAllocationIndependence1 (c1 , 1 , 2 ).v );
87+ Asserts .assertEQ (3 , testAllocationIndependence2 (c1 , 1 , 2 ).v );
8488 }
8589
8690 @ Test
@@ -170,4 +174,25 @@ static int testLoadArrayCopyUnknownLength(int[] a1, int[] a2, int len, int v) {
170174 System .arraycopy (a2 , 0 , a1 , 0 , len );
171175 return a1 [2 ];
172176 }
177+
178+ @ Test
179+ @ IR (failOn = IRNode .LOAD , phase = CompilePhase .BEFORE_MACRO_EXPANSION )
180+ static C1 testAllocationIndependence1 (C1 o1 , int v1 , int v2 ) {
181+ // o1 and o2 are independent
182+ o1 .v = v1 ;
183+ C1 o2 = new C1 ();
184+ o2 .v = o1 .v + v2 ;
185+ return o2 ;
186+ }
187+
188+ @ Test
189+ @ IR (failOn = IRNode .LOAD , phase = CompilePhase .BEFORE_MACRO_EXPANSION )
190+ static C1 testAllocationIndependence2 (C1 o1 , int v1 , int v2 ) {
191+ // o1 and o2 are independent, but we also want CastPP(o1) and o2 being independent
192+ C1 o2 = new C1 ();
193+ o1 .v = v1 ;
194+ o2 .v = v2 ;
195+ o2 .v = o1 .v + o2 .v ;
196+ return o2 ;
197+ }
173198}
0 commit comments