1 // inspired by this code snippet: 2 // https://github.com/openjdk/jdk/blob/42758cb889a5cf1d7f4c4b468a383b218baa1b27/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Symbol.java#L1318 3 class GetFieldIsAlias { 4 static class Type { 5 private int value; 6 public GetFieldIsAlias parent; 7 8 public Type(int value, GetFieldIsAlias parent) { 9 this.value = value; 10 this.parent = parent; 11 } 12 } 13 14 public Type type; 15 public GetFieldIsAlias() { 16 this.type = new Type(42, null); 17 // 'this.type' is supposed to be the fix pattern: AddP-LoadN-DecodeN-CastPP. 18 // We need to ensure this.type is alias with the object just created, or PEA assumes that this.type is 'a global variable' 19 // and we have to materialize 'this'. 20 this.type.parent = this; 21 } 22 23 public static void main(String[] args) { 24 for (int i = 0; i< 200_000; ++i) { 25 var obj = new GetFieldIsAlias(); 26 if (obj.type.parent != obj) { 27 throw new RuntimeException("wrong answer"); 28 } 29 } 30 } 31 }