1 class MergeLoop { 2 static void blackhole(Object obj) {} 3 static void test(int val) { 4 Object obj1 = new Object(); 5 Object obj2 = new Object(); 6 7 for (int i = 0; i < val; ++i) { 8 // to prevent phi from being elided, we need to ensure obj is not loop invariant! 9 // the following shuffle just confuses ciTypeFlow 10 11 // swap 12 Object t = obj1; 13 obj1 = obj2; 14 obj2 = t; 15 // swap again 16 t = obj1; 17 obj1 = obj2; 18 obj2 = t; 19 20 blackhole(obj1); // escape here. 21 } 22 } 23 24 public static void main(String[] args) { 25 for (int i = 0; i < 200_000; ++i) { 26 test(24); 27 } 28 } 29 }