Bug 195317 - [compiler] java.lang.ClassFormatError: Invalid pc in LineNumberTable
Summary: [compiler] java.lang.ClassFormatError: Invalid pc in LineNumberTable
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.3   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 3.3.1   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 196183 202165 205046 (view as bug list)
Depends on:
Blocks:
 
Reported: 2007-07-03 18:31 EDT by Ian Rogers# CLA
Modified: 2008-09-16 09:46 EDT (History)
5 users (show)

See Also:


Attachments
Javap disassembly for the class with the incorrect line number table. (11.07 KB, application/octet-stream)
2007-07-03 18:32 EDT, Ian Rogers# CLA
no flags Details
Proposed fix (2.50 KB, patch)
2007-07-05 13:44 EDT, Olivier Thomann CLA
no flags Details | Diff
Proposed fix + regression test (5.39 KB, patch)
2007-07-05 13:52 EDT, Olivier Thomann CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ian Rogers# CLA 2007-07-03 18:31:36 EDT
When using GNU Classpath 0.95 built with ECJ 3.3 the error "java.lang.ClassFormatError: Invalid pc in LineNumberTable in class file java/util/zip/InflaterDynHeader" is reported by the HotSpot client JVM. The line number table for the static initializer of the class looks like:

  LineNumberTable: 
   line 49: 0
   line 50: 19
   line 65: 38
   line 64: 140
   line 40: 143

but the static initializer has no bytecode index 50:

static {};
  Code:
   0:	iconst_3
...
   43:	iconst_0
   44:	bipush	16
   46:	iastore
   47:	dup
   48:	iconst_1
   49:	bipush	17
   51:	iastore
   52:	dup
   53:	iconst_2
   54:	bipush	18
   56:	iastore
...

It is incorrect for the HotSpot JVM to fail due to an incorrect line number table entry:

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6361363

it is also incorrect of ECJ to generate an incorrect line number table. The bug causes builds of the Jikes RVM to fail when using ECJ 3.3 and the Hot Spot client JVM to build/boot strap it.
Comment 1 Ian Rogers# CLA 2007-07-03 18:32:51 EDT
Created attachment 72990 [details]
Javap disassembly for the class with the incorrect line number table.
Comment 2 Philipe Mulet CLA 2007-07-04 06:16:07 EDT
Is this a regression over 3.2 ? 
Tagging for 3.3.1.
Comment 3 Olivier Thomann CLA 2007-07-04 15:37:31 EDT
I am investigating.
Comment 4 Ian Rogers# CLA 2007-07-05 09:23:33 EDT
Classpath 0.95 compiles fine with ECJ 3.2, so the Jikes RVM has reverted to using ECJ 3.2 currently. There's a Jikes RVM issue tracker here:
http://jira.codehaus.org/browse/RVM-112
Comment 5 Olivier Thomann CLA 2007-07-05 12:09:38 EDT
The problem doesn't come from the static initializer. The clinit is fine.
It comes from the method   public boolean decode(java.util.zip.StreamManipulator input) throws java.util.zip.DataFormatException;
which has a line number entry beyond the code length.
I am working on it.
Comment 6 Olivier Thomann CLA 2007-07-05 12:11:52 EDT
A simpler test case is:
public class X {
	public static void main(String[] args) {
		int mode = 1;
		loop: for (;;) {
			switch (mode) {
				case 2 :
					return;
				case 1:
					mode = 2;
					continue loop;
			}
		}
	}
}

  // Method descriptor #15 ([Ljava/lang/String;)V
  // Stack: 1, Locals: 2
  public static void main(String[] args);
     0  iconst_1
     1  istore_1 [mode]
     2  iload_1 [mode]
     3  tableswitch default: 27
          case 1: 25
          case 2: 24
    24  return
    25  iconst_2
    26  istore_1 [mode]
    27  goto 2
      Line numbers:
        [pc: 0, line: 3]
        [pc: 2, line: 5]
        [pc: 24, line: 7]
        [pc: 25, line: 9]
        [pc: 27, line: 10]
        [pc: 30, line: 11]
        [pc: 27, line: 4]
      Local variable table:
        [pc: 0, pc: 30] local: args index: 0 type: String[]
        [pc: 2, pc: 30] local: mode index: 1 type: int

as you can see, the line number entry for pc 30 is invalid.
Removing the continue loop; statement fixes it.
Comment 7 Olivier Thomann CLA 2007-07-05 13:44:12 EDT
Created attachment 73144 [details]
Proposed fix

When optimizing a jump to next bytecode, we need to remove entries in the pcToSourceMap table that exceeds the current code stream position.
Comment 8 Olivier Thomann CLA 2007-07-05 13:52:28 EDT
Created attachment 73145 [details]
Proposed fix + regression test

Same fix + a regression test
Comment 9 Olivier Thomann CLA 2007-07-05 15:01:48 EDT
Released for 3.4M1.
Added regression test in org.eclipse.jdt.core.tests.compiler.regression.ForStatementTest#test005

Keep it open for release in 3.3.1.
Comment 10 Olivier Thomann CLA 2007-07-05 22:12:37 EDT
Released for 3.3.1.
Added regression test in
org.eclipse.jdt.core.tests.compiler.regression.ForStatementTest#test005
Comment 11 Olivier Thomann CLA 2007-07-06 10:11:09 EDT
Ian, it would be nice if you could confirm that this is fixed using the next 3.3 maintenance build (next Wednesday).
Thanks.
Comment 12 Ian Rogers# CLA 2007-07-06 10:15:57 EDT
Will do, thanks for all your efforts!
Ian
Comment 13 Olivier Thomann CLA 2007-07-11 12:18:07 EDT
*** Bug 196183 has been marked as a duplicate of this bug. ***
Comment 14 Ian Rogers# CLA 2007-07-11 19:42:38 EDT
Downloaded:
http://fullmoon.torolab.ibm.com/downloads/drops/M20070711-0800/ecj.jar
and previous regressions have now disappeared. Thanks!
Comment 15 Frederic Fusier CLA 2007-08-07 06:33:12 EDT
Verified for 3.4M1 using build I20070806-1800.
Comment 16 Eric Jodet CLA 2007-09-03 09:51:25 EDT
Verified for 3.3.1 using build M20070831-2000
Comment 17 Jerome Lanneluc CLA 2007-09-04 04:48:48 EDT
*** Bug 196183 has been marked as a duplicate of this bug. ***
Comment 18 Olivier Thomann CLA 2007-09-04 15:45:07 EDT
*** Bug 202165 has been marked as a duplicate of this bug. ***
Comment 19 Jerome Lanneluc CLA 2007-10-04 12:10:15 EDT
*** Bug 205046 has been marked as a duplicate of this bug. ***