Bug 20215 - gcj does not accept classes with same name fields
Summary: gcj does not accept classes with same name fields
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: java (show other bugs)
Version: 4.0.0
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: rejects-valid
: 49185 (view as bug list)
Depends on:
Blocks:
 
Reported: 2005-02-25 19:48 UTC by Daniel Bonniot
Modified: 2011-06-01 16:12 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2005-05-27 00:17:46


Attachments
Testcase (327 bytes, application/x-java-vm)
2005-02-25 19:50 UTC, Daniel Bonniot
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel Bonniot 2005-02-25 19:48:56 UTC
According to the JVM spec, class files can have several fields with the same
name. As long as they have different types, they will be distinguished since all
field operations specify both the name and the field of the field. Sun's JVM
accepts such classes, and correctly distinguishes the fields, as you can see in
the attached testcase. Here is the disassembly of this class:

Access flags: 0x20 super
This class: 2=DuplicateField, super: 4=java.lang.Object
Interfaces (count: 0):

Fields (count: 2):
Field name:"foo" static Signature: 6=java.lang.String
Field name:"foo" static Signature: 7=int

Methods (count: 3):

Method name:"<init>" Signature: 9=()void
Attribute "Code", length:17, max_stack:1, max_locals:1, code_length:5
  0: aload_0
  1: invokespecial #11=<Method java.lang.Object.<init> ()void>
  4: return

Method name:"main" public static Signature: 14=(java.lang.String[])void
Attribute "Code", length:31, max_stack:2, max_locals:1, code_length:19
  0: getstatic #20=<Field java.lang.System.out java.io.PrintStream>
  3: getstatic #22=<Field DuplicateField.foo java.lang.String>
  6: invokevirtual #28=<Method java.io.PrintStream.println (java.lang.String)void>
  9: getstatic #20=<Field java.lang.System.out java.io.PrintStream>
 12: getstatic #30=<Field DuplicateField.foo int>
 15: invokevirtual #33=<Method java.io.PrintStream.println (int)void>
 18: return

Method name:"<clinit>" static Signature: 9=()void
Attribute "Code", length:24, max_stack:1, max_locals:0, code_length:12
  0: ldc #36=<String "WOW">
  2: putstatic #22=<Field DuplicateField.foo java.lang.String>
  5: sipush 42
  8: putstatic #30=<Field DuplicateField.foo int>
 11: return


Sun's JVM correctly executes that program:

$ java DuplicateField
WOW
42

gcj fails during compilation with:

$ gcj DuplicateField.class
DuplicateField.java: In class 'DuplicateField':
DuplicateField.java: In method 'DuplicateField.main(java.lang.String[])':
DuplicateField.java:0: error: mismatching signature for field 'foo' in
'DuplicateField'
DuplicateField.java: In method 'DuplicateField.<clinit>()':
DuplicateField.java:0: error: mismatching signature for field 'foo' in
'DuplicateField'

Surprisingly, gij also fails with:

Exception in thread "main" java.lang.NullPointerException
   at java.io.PrintStream.println(java.lang.String) (/tmp/gcc/lib/libgcj.so.6.0.0)
   at DuplicateField.main(java.lang.String[]) (Unknown Source)
   at gnu.java.lang.MainThread.call_main() (/tmp/gcc/lib/libgcj.so.6.0.0)
   at gnu.java.lang.MainThread.run() (/tmp/gcc/lib/libgcj.so.6.0.0)

gcj (GCC) 4.0.0 20050223
Comment 1 Daniel Bonniot 2005-02-25 19:50:04 UTC
Created attachment 8285 [details]
Testcase
Comment 2 CVS Commits 2005-03-07 17:11:33 UTC
Subject: Bug 20215

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-4_0-branch
Changes by:	tromey@gcc.gnu.org	2005-03-07 17:11:29

Modified files:
	libjava        : ChangeLog link.cc 
	libjava/include: jvm.h 

Log message:
	PR java/20215:
	* include/jvm.h (_Jv_Linker::find_field_helper): Updated.
	* link.cc (find_field_helper): Added 'type' argument.
	(find_field): Updated.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libjava/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.3391.2.3&r2=1.3391.2.4
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libjava/link.cc.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.10&r2=1.10.2.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libjava/include/jvm.h.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.77&r2=1.77.2.1

Comment 3 CVS Commits 2005-03-07 17:18:40 UTC
Subject: Bug 20215

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	tromey@gcc.gnu.org	2005-03-07 17:18:33

Modified files:
	libjava        : ChangeLog link.cc 
	libjava/include: jvm.h 

Log message:
	PR java/20215:
	* include/jvm.h (_Jv_Linker::find_field_helper): Updated.
	* link.cc (find_field_helper): Added 'type' argument.
	(find_field): Updated.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libjava/ChangeLog.diff?cvsroot=gcc&r1=1.3399&r2=1.3400
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libjava/link.cc.diff?cvsroot=gcc&r1=1.10&r2=1.11
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libjava/include/jvm.h.diff?cvsroot=gcc&r1=1.77&r2=1.78

Comment 4 Andrew Pinski 2005-05-27 00:17:45 UTC
Confirmed, the gij problem has been fixed by the patches above, this only leaves the java front-end 
problem.
Comment 5 licheng.1212@gmail.com 2011-05-26 12:10:07 UTC
(In reply to comment #4)
> Confirmed, the gij problem has been fixed by the patches above, this only
> leaves the java front-end 
> problem.

[lee@localhost gcj_test]$ gcj -v
Using built-in specs.
Reading specs from /usr/lib/gcc/i686-redhat-linux/4.5.1/libgcj.spec
rename spec startfile to startfileorig
rename spec lib to liborig
COLLECT_GCC=gcj
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/i686-redhat-linux/4.5.1/lto-wrapper
Target: i686-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,lto --enable-plugin --enable-java-awt=gtk --disable-dssi --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre --enable-libgcj-multifile --enable-java-maintainer-mode --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libjava-multilib --with-ppl --with-cloog --with-tune=generic --with-arch=i686 --build=i686-redhat-linux
Thread model: posix
gcc version 4.5.1 20100924 (Red Hat 4.5.1-4) (GCC) 

a.java: In class 'a':
a.java: In method 'a.b(int)':
In file included from <built-in>:0:0:
a.java:0:0: error: mismatching signature for field 'aP' in 'a'
a.java:0:0: error: mismatching signature for field 'aP' in 'a'
a.java:0:0: error: mismatching signature for field 'ae' in 'a'
Comment 6 licheng.1212@gmail.com 2011-05-26 12:44:09 UTC
the Testcase attachments can't donwload
Comment 7 licheng.1212@gmail.com 2011-05-26 15:06:37 UTC
(In reply to comment #6)
> the Testcase attachments can't donwload

I have got the Testcase,but it still hava problem

[lee@localhost Downloads]$ gcj -v DuplicateField.class 
Using built-in specs.
Reading specs from /usr/lib/gcc/i686-redhat-linux/4.5.1/libgcj.spec
rename spec startfile to startfileorig
rename spec lib to liborig
COLLECT_GCC=gcj
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/i686-redhat-linux/4.5.1/lto-wrapper
Target: i686-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,lto --enable-plugin --enable-java-awt=gtk --disable-dssi --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre --enable-libgcj-multifile --enable-java-maintainer-mode --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libjava-multilib --with-ppl --with-cloog --with-tune=generic --with-arch=i686 --build=i686-redhat-linux
Thread model: posix
gcc version 4.5.1 20100924 (Red Hat 4.5.1-4) (GCC) 
COLLECT_GCC_OPTIONS='-v' '-fbootclasspath=./:/usr/share/java/libgcj-4.5.1.jar' '-g1' '-shared-libgcc' '-mtune=generic' '-march=i686'
COLLECT_GCC_OPTIONS='-v' '-fbootclasspath=./:/usr/share/java/libgcj-4.5.1.jar' '-g1' '-shared-libgcc' '-mtune=generic' '-march=i686'
 /usr/libexec/gcc/i686-redhat-linux/4.5.1/jc1 DuplicateField.class -fhash-synchronization -fno-use-divide-subroutine -fuse-boehm-gc -fnon-call-exceptions -fkeep-inline-functions -quiet -dumpbase DuplicateField.class -mtune=generic -march=i686 -auxbase DuplicateField -g1 -version -fbootclasspath=./:/usr/share/java/libgcj-4.5.1.jar -faux-classpath /tmp/ccUMiMyu.zip -o /tmp/ccGWZOga.s
GNU Java (GCC) version 4.5.1 20100924 (Red Hat 4.5.1-4) (i686-redhat-linux)
	compiled by GNU C version 4.5.1 20100924 (Red Hat 4.5.1-4), GMP version 4.3.1, MPFR version 2.4.2, MPC version 0.8.1
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
GNU Java (GCC) version 4.5.1 20100924 (Red Hat 4.5.1-4) (i686-redhat-linux)
	compiled by GNU C version 4.5.1 20100924 (Red Hat 4.5.1-4), GMP version 4.3.1, MPFR version 2.4.2, MPC version 0.8.1
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Class path starts here:
    /tmp/ccUMiMyu.zip/ (zip)
    ./ (system)
    /usr/share/java/libgcj-4.5.1.jar/ (system) (zip)
DuplicateField.java: In class 'DuplicateField':
DuplicateField.java: In method 'DuplicateField.main(java.lang.String[])':
In file included from <built-in>:0:0:
DuplicateField.java:0:0: error: mismatching signature for field 'foo' in 'DuplicateField'
DuplicateField.java: In method 'DuplicateField.<clinit>()':
DuplicateField.java:0:0: error: mismatching signature for field 'foo' in 'DuplicateField'
Comment 8 licheng.1212@gmail.com 2011-05-27 04:37:22 UTC
gij is OK
Comment 9 Andrew Pinski 2011-05-27 05:09:59 UTC
*** Bug 49185 has been marked as a duplicate of this bug. ***
Comment 10 licheng.1212@gmail.com 2011-05-28 07:45:31 UTC
(In reply to comment #4)
> Confirmed, the gij problem has been fixed by the patches above, this only
> leaves the java front-end 
> problem.


Why ony gij can fixed?
how about gcj??
Comment 11 licheng.1212@gmail.com 2011-06-01 16:12:04 UTC
is anybody here???