Bug 183682 - [1.6][compiler] Invalid stackmap generated for "anewarray" bytecode
Summary: [1.6][compiler] Invalid stackmap generated for "anewarray" bytecode
Status: VERIFIED DUPLICATE of bug 169596
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.3   Edit
Hardware: PC Solaris
: P3 normal (vote)
Target Milestone: 3.3 M7   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-04-23 19:18 EDT by David Liu CLA
Modified: 2007-04-27 10:42 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description David Liu CLA 2007-04-23 19:18:26 EDT
When the following class is compiled using Eclipse's compiler, an invalid stackmap is generated.

public class TestClass {
    public TestClass(int i) {
        TestClass [] array = new TestClass[] { i == 0 ? null : null };
    }
}

Eclipse's Java compiler generates the following stackmap (displayed from javap):

  StackMapTable: number_of_entries = 2
   frame_type = 255 /* full_frame */
     offset_delta = 18
     locals = [ class TestClass, int ]
     stack = [ class TestClass, class TestClass, int ]
   frame_type = 255 /* full_frame */
     offset_delta = 0
     locals = [ class TestClass, int ]
     stack = [ class TestClass, class TestClass, int, null ]

Whereas Sun's Java compiler produces the following:

  StackMapTable: number_of_entries = 2
   frame_type = 255 /* full_frame */
     offset_delta = 18
     locals = [ class TestClass, int ]
     stack = [ class "[LTestClass;", class "[LTestClass;", int ]
   frame_type = 255 /* full_frame */
     offset_delta = 0
     locals = [ class TestClass, int ]
     stack = [ class "[LTestClass;", class "[LTestClass;", int, null ]

Specifically, Eclipse's Java compiler specifies that the Java stack contains two references to TestClass (pushed by the "anewarray" bytecode), whereas the correct Java stack actually contains two references to arrays of TestClass. However, since the verifier defaults to type inference when type checking fails, no error messages are displayed by default for the incorrect stack maps. 

[maxwell]dl156546:Test> java -classpath bin TestClass
Exception in thread "main" java.lang.NoSuchMethodError: main

When type interference is disabled, the class fails to verify:

[maxwell]dl156546:Test> java -XX:-FailOverToOldVerifier -classpath bin TestClass
Exception in thread "main" java.lang.VerifyError: Inconsistent stackmap frames at branch target 18 in method TestClass.<init>(I)V at offset 11
Comment 1 David Liu CLA 2007-04-23 20:17:17 EDT
Typo... I'm actually running 3.3M4
Comment 2 Olivier Thomann CLA 2007-04-23 20:44:44 EDT
This has been fixed for 3.3M5.
Added regression test org.eclipse.jdt.core.tests.compiler.regression.StackMapAttributeTest.test032()

*** This bug has been marked as a duplicate of bug 169596 ***
Comment 3 Olivier Thomann CLA 2007-04-23 20:45:21 EDT
Reopen to assign first.
Comment 4 Olivier Thomann CLA 2007-04-23 20:45:59 EDT

*** This bug has been marked as a duplicate of bug 169596 ***
Comment 5 David Liu CLA 2007-04-23 21:30:22 EDT
My mistake, I didn't find the existing bug report earlier. Thanks.
Comment 6 Olivier Thomann CLA 2007-04-23 21:34:08 EDT
No problem. Always worth reporting it just in case it was not reported before.
Thanks for the report.
Comment 7 David Audel CLA 2007-04-27 10:42:55 EDT
Verified for 3.3 M7 using build I20070427-0010