Community
Participate
Working Groups
Using HEAD, interface I { int CONST = A.foo(); } class A { static int foo() { System.out.println("SUCCESS"); return 0; } } class B implements I { B() { int i = CONST; } } public class X { public static void main(String[] args) { new B(); } } Compiling this code with optimizing out unused locals ends up with no call for the CONST field inside the constructor of B. -preserveAllLocals should not change the behavior of the code. The code seems to be in SingleNameReference. I'll attach a patch.
Created attachment 51035 [details] Proposed fix
Created attachment 51055 [details] Regression tests updated Updated the BooleanTest. We optimized out completely the generation of the static field.
Not all SingleNameReferences need to be deoptimized as in previous patch. interface I { int CONST = A.foo(); } class A { static int foo() { System.out.println("SUCCESS"); return 0; } } class B implements I { static int LOCAL_STATIC; B(int param) { int i = CONST; // keep for possible <clinit> int j = param; // may optimize out int k = LOCAL_STATIC; // may optimize out } } public class X { public static void main(String[] args) { new B(12); } }
Testcase for QualifiedNameReference: "[I.CONST]" should be printed (amongst others) interface I { Value CONST = A.foo("[I.CONST]"); } class Value { static String NAME = ""; String v; Value(String v) { this.v = v; } } class A { static Value foo(String str) { System.out.print(str); return new Value("str"); } } class B implements I { static Value LOCAL_STATIC = A.foo("[B.LOCAL_STATIC]"); Value local_field = A.foo("[B.local_field]"); B(Value param) { String i = CONST.NAME; // keep for possible <clinit> String j = param.NAME; // may optimize out String k = LOCAL_STATIC.NAME; // may optimize out String l = local_field.NAME; // may optimize out } } public class X { public static void main(String[] args) { new B(new Value("[PARAM]")); } }
Same issue with FieldReference: "[I.CONST]" should be printed (amongst others) interface I { Value CONST = A.foo("[I.CONST]"); } class Value { static String NAME = ""; String v; Value(String v) { this.v = v; } } class A { static Value foo(String str) { System.out.print(str); return new Value("str"); } } class B implements I { static Value LOCAL_STATIC = A.foo("[B.LOCAL_STATIC]"); Value local_field = A.foo("[B.local_field]"); B(Value param) { String i = this.CONST.NAME; // keep for possible <clinit> String k = this.LOCAL_STATIC.NAME; // may optimize out String l = this.local_field.NAME; // may optimize out } } public class X { public static void main(String[] args) { new B(new Value("[PARAM]")); } }
Added InitializationTest#test189-191; GenericTypeTest#test1039-1041.
Created attachment 51079 [details] Better patch Solves issues for single/qualified and field references
Released for 3.3M3. Fixed
Considering for 3.2.2.
Released for 3.2.2
Verified for 3.3 M3 using build I20061030-0010
verified for 3.2.2 using build M20070112-1200