This is the mail archive of the java@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Class file generated by "gcj -C" throws ClassFormatError


I can reproduce this on x86 and on PowerPC.  On x86 I get:

Exception in thread "main" java.lang.ClassFormatError: bar (Bad index into constant pool)
	at java.lang.ClassLoader.defineClass0(Native Method)
	at java.lang.ClassLoader.defineClass(ClassLoader.java:486)
	at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:111)
	at java.net.URLClassLoader.defineClass(URLClassLoader.java:248)
	at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:297)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:286)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:253)
	at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:313)

On PowerPC, I get:

Error loading class bar: Bad index into constant pool


Here are the GCC specs:
Reading specs from ../gcc/orig/install/bin/../lib/gcc-lib/i686-pc-linux-gnu/3.0/specs
Reading specs from ../gcc/orig/install/bin/../lib/gcc-lib/i686-pc-linux-gnu/3.0/../../../libgcj.spec
rename spec lib to liborig
rename spec startfile to startfileorig
Configured with: ../gcc-3.0/configure --enable-threads --enable-java-gc=boehm --prefix=/home/minyard/gcc/orig/install
Thread model: posix
gcc version 3.0

Reading specs from ../gcc/install/bin/../lib/gcc-lib/powerpc-unknown-linux-gnu/3.0/specs
Reading specs from ../gcc/install/bin/../lib/gcc-lib/powerpc-unknown-linux-gnu/3.0/../../../libgcj.spec
rename spec lib to liborig
rename spec startfile to startfileorig
Configured with: ../gcc-3.0/configure --enable-threads=libc-lock --enable-java-gc=egc --prefix=/home/minyard/gcc/install
Thread model: libc-lock
gcc version 3.0

If I change the "0" to a "0L" and diff the class file output from
jcf-dump (bar.class.1 has the "0L", bar.class.2 has the "0"), I get:

1c1
< Reading .class from bar.class.1.
---
> Reading .class from bar.class.2.
4c4
< Constant pool (count: 19):
---
> Constant pool (count: 18):
12,21c12,21
< #8: Long 0=0x0
< #10: Utf8: "main"
< #11: Utf8: "([Ljava/lang/String;)V"
< #12: Utf8: "Code"
< #13: Utf8: "<init>"
< #14: Utf8: "()V"
< #15: NameAndType name: 13=<init>, signature: 14=()void
< #16: Methodref class: 4=java.lang.Object name_and_type: 15=<<init> ()void>
< #17: Utf8: "SourceFile"
< #18: Utf8: "bar.java"
---
> #8: Integer 0=0x0
> #9: Utf8: "main"
> #10: Utf8: "([Ljava/lang/String;)V"
> #11: Utf8: "Code"
> #12: Utf8: "<init>"
> #13: Utf8: "()V"
> #14: NameAndType name: 12=<init>, signature: 13=()void
> #15: Methodref class: 4=java.lang.Object name_and_type: 14=<<init> ()void>
> #16: Utf8: "SourceFile"
> #17: Utf8: "bar.java"
29c29
< Attribute "ConstantValue", length:2, value: #8=<Long 0>
---
> Attribute "ConstantValue", length:2, value: #8=<Integer 0>
33c33
< Method name:"main" public static Signature: 11=(java.lang.String[])void
---
> Method name:"main" public static Signature: 10=(java.lang.String[])void
37c37
< Method name:"<init>" Signature: 14=()void
---
> Method name:"<init>" Signature: 13=()void
40c40
<   1: invokespecial #16=<Method java.lang.Object.<init> ()void>
---
>   1: invokespecial #15=<Method java.lang.Object.<init> ()void>
44c44
< Attribute "SourceFile", length:2, #18="bar.java"
---
> Attribute "SourceFile", length:2, #17="bar.java"


-Corey

Weiqi Gao <weiqigao@yahoo.com> writes:

> I wrote:
> > 
> > On Sparc/Solaris 2.6, 'gcj -C foo.java' generates a
> > foo.class file that throws ClassFormatError when run
> > with 'java foo':
> > 
> > // foo.java
> > class foo {
> >   static long x;
> >   public static void main(String[] args) {
> >     new foo();
> >   }
> > }
> 
> I was confused yesterday and copied the wrong file. 
> The Java source that has the problem is
> 
> class bar {
>   static long x = 0;
>   public static void main(String[] args) {
>   }
> }
> 
> The error is thrown if x is initialized with '0'.  The
> error is not thrown if x is initialized with '0L' or
> not at all.
> 
> 
> =====
> Weiqi Gao
> weiqigao@yahoo.com
> 
> 
> 
> __________________________________________________
> Do You Yahoo!?
> Get personalized email addresses from Yahoo! Mail
> http://personal.mail.yahoo.com/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]