Summary: | [compiler] Could optimize "return null" in presence of subroutine | ||
---|---|---|---|
Product: | [Eclipse Project] JDT | Reporter: | Philipe Mulet <philippe_mulet> |
Component: | Core | Assignee: | Philipe Mulet <philippe_mulet> |
Status: | VERIFIED FIXED | QA Contact: | |
Severity: | normal | ||
Priority: | P3 | ||
Version: | 3.2 | ||
Target Milestone: | 3.2 M6 | ||
Hardware: | PC | ||
OS: | Windows XP | ||
Whiteboard: |
Description
Philipe Mulet
2006-02-24 04:21:39 EST
Currently generates: // Method descriptor #19 ()Ljava/lang/Object; // Stack: 2, Locals: 2 static Object foo(); 0 aconst_null 1 astore_1 2 getstatic System.out : PrintStream [22] 5 ldc <String "SUCCESS"> [28] 7 invokevirtual PrintStream.println(String) : void [30] 10 aload_1 11 areturn 12 astore_0 13 getstatic System.out : PrintStream [22] 16 ldc <String "SUCCESS"> [28] 18 invokevirtual PrintStream.println(String) : void [30] 21 aload_0 22 athrow Exception Table: [pc: 0, pc: 2] -> 12 when : any Added GenericTypeTest#test044 Now consider constant expressions and null literal in optimized scenario of return statements. To verify this bug is fixed, the generated bytecode pattern should be shorter: In 1.5 target mode, instead of: // Method descriptor #19 ()Ljava/lang/Object; // Stack: 2, Locals: 2 static Object foo(); 0 aconst_null 1 astore_1 2 getstatic System.out : PrintStream [22] 5 ldc <String "SUCCESS"> [28] 7 invokevirtual PrintStream.println(String) : void [30] 10 aload_1 11 areturn ... it should be: // Method descriptor #19 ()Ljava/lang/Object; // Stack: 2, Locals: 1 static Object foo(); 0 getstatic System.out : PrintStream [22] 3 ldc <String "SUCCESS"> [28] 5 invokevirtual PrintStream.println(String) : void [30] 8 aconst_null 9 areturn ... Observe no temp 1 got allocated (one local less), and aconst_null directly precedes the return instruction. Verified for 3.2 M6 using build I20060327-0010 |