java/7066: gcj generates invalid bytecode for inner classes
Bruno Haible
bruno@clisp.org
Tue Jun 18 07:51:00 GMT 2002
>Number: 7066
>Category: java
>Synopsis: gcj generates invalid bytecode for an inner class
>Confidential: no
>Severity: critical
>Priority: medium
>Responsible: unassigned
>State: open
>Class: wrong-code
>Submitter-Id: net
>Arrival-Date: Tue Jun 18 06:16:02 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator: Bruno Haible
>Release: 3.1
>Organization:
GNU hackers
>Environment:
System: Linux linuix 2.4.18-4GB #1 Wed Mar 27 13:57:05 UTC 2002 i686 un=
known
Architecture: i686
=20
host: i686-pc-linux-gnu
build: i686-pc-linux-gnu
target: i686-pc-linux-gnu
configured with: /packages2/gcc-3.1/configure --prefix=3D/packages/gnu-=
snapshot --enable-shared --enable-version-specific-runtime-libs --enabl=
e-nls
>Description:
gcj 3.1 generates invalid bytecode for the following program.
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D GetURL.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
import java.io.*;
import java.net.*;
public class GetURL {
private static long timeout =3D 30*1000;
private boolean done;
private Thread timeoutThread;
public void fetch (String s) {
URL url;
try {
url =3D new URL(s);
} catch (MalformedURLException e) {
System.exit(1);
return;
}
System.err.print("Retrieving "+s+"...");
System.err.flush();
done =3D false;
timeoutThread =3D
new Thread() {
public void run () {
try {
sleep(timeout);
if (!done) {
System.err.println(" timed out.");
System.exit(1);
}
} catch (InterruptedException e) {
}
}
};
timeoutThread.start();
try {
InputStream istream =3D new BufferedInputStream(url.openStream())=
;
OutputStream ostream =3D new BufferedOutputStream(System.out);
for (;;) {
int b =3D istream.read();
if (b < 0) break;
ostream.write(b);
}
ostream.close();
System.out.flush();
istream.close();
} catch (IOException e) {
System.err.println(" failed.");
System.exit(1);
}
done =3D true;
System.err.println(" done.");
}
public static void main (String[] args) {
if (args.length !=3D 1)
System.exit(1);
(new GetURL()).fetch(args[0]);
System.exit(0);
}
}
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
>How-To-Repeat:
Save the above snippet as GetURL.java. Then
$ gcj --version
gcj (GCC) 3.1
Copyright =A9 2002 Free Software Foundation, Inc.
Ce logiciel est libre; voir les sources pour les conditions de copie. =
Il n'y a PAS
GARANTIE; ni implicite pour le MARCHANDAGE ou pour un BUT PARTICULIER.
$ gcj -C -d . GetURL.java=20
$ someurl=3D"http://localhost/" # or some other accessible URL
$ gij --version
gij (GNU libgcj) version 3.1
Copyright (C) 2002 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is=
NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURP=
OSE.
$ CLASSPATH=3D. gij GetURL $someurl
Retrieving http://localhost/...Exception in thread "main" java.lang.Int=
ernalError: Thread.start called but threads not available
at 0x4025f270: java.lang.Throwable.Throwable(java.lang.String) (/pac=
kages/gnu-snapshot/lib/libgcj.so.3)
at 0x4024dcf6: java.lang.Error.Error(java.lang.String) (/packages/gn=
u-snapshot/lib/libgcj.so.3)
at 0x4025f606: java.lang.VirtualMachineError.VirtualMachineError(jav=
a.lang.String) (/packages/gnu-snapshot/lib/libgcj.so.3)
at 0x4024ff06: java.lang.InternalError.InternalError(java.lang.Strin=
g) (/packages/gnu-snapshot/lib/libgcj.so.3)
at 0x403cc038: _Jv_ThreadStart(java.lang.Thread, int, void ()(java.l=
ang.Thread)) (/packages/gnu-snapshot/lib/libgcj.so.3)
at 0x40240aa1: java.lang.Thread.start() (/packages/gnu-snapshot/lib/=
libgcj.so.3)
at 0x403db0f7: ffi_call_SYSV (/packages/gnu-snapshot/lib/libgcj.so.3=
)
at 0x403db0a7: ffi_raw_call (/packages/gnu-snapshot/lib/libgcj.so.3)=
at 0x40231048: _Jv_InterpMethod.continue1(_Jv_InterpMethodInvocation=
) (/packages/gnu-snapshot/lib/libgcj.so.3)
at 0x403e60a4: _Jv_InterpMethod.run(ffi_cif, void, ffi_raw, _Jv_Inte=
rpMethodInvocation) (/packages/gnu-snapshot/lib/libgcj.so.3)
at 0x4022ee14: _Jv_InterpMethod.run_normal(ffi_cif, void, ffi_raw, v=
oid) (/packages/gnu-snapshot/lib/libgcj.so.3)
at 0x403daf5c: ?? (??:0)
at 0x403db0f7: ffi_call_SYSV (/packages/gnu-snapshot/lib/libgcj.so.3=
)
at 0x403db0a7: ffi_raw_call (/packages/gnu-snapshot/lib/libgcj.so.3)=
at 0x40231048: _Jv_InterpMethod.continue1(_Jv_InterpMethodInvocation=
) (/packages/gnu-snapshot/lib/libgcj.so.3)
at 0x403e60a4: _Jv_InterpMethod.run(ffi_cif, void, ffi_raw, _Jv_Inte=
rpMethodInvocation) (/packages/gnu-snapshot/lib/libgcj.so.3)
at 0x4022ee14: _Jv_InterpMethod.run_normal(ffi_cif, void, ffi_raw, v=
oid) (/packages/gnu-snapshot/lib/libgcj.so.3)
at 0x403daf5c: ?? (??:0)
at 0x40235258: gnu.gcj.runtime.FirstThread.call_main() (/packages/gn=
u-snapshot/lib/libgcj.so.3)
at 0x402bde78: gnu.gcj.runtime.FirstThread.run() (/packages/gnu-snap=
shot/lib/libgcj.so.3)
at 0x40240a0c: _Jv_ThreadRun(java.lang.Thread) (/packages/gnu-snapsh=
ot/lib/libgcj.so.3)
at 0x4021d094: _Jv_RunMain(java.lang.Class, byte const, int, byte co=
nst, boolean) (/packages/gnu-snapshot/lib/libgcj.so.3)
at 0x08048a40: main (/packages2/gcc-3.1/libjava/gij.cc:140)
at 0x405e3668: __libc_start_main (/lib/libc.so.6)
at 0x080487a1: _start (??:0)
$ java -version
java version "1.3.1_02"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1_02-b02)
Java HotSpot(TM) Client VM (build 1.3.1_02-b02, mixed mode)
$ CLASSPATH=3D. java GetURL $someurl
Retrieving http://localhost/...Exception in thread "main" java.lang.Ver=
ifyError: (class: GetURL$1, method: <init> signature: (LGetURL;)V) Expe=
cting to find object/array on stack
at GetURL.fetch(GetURL.java:31)
at GetURL.main(GetURL.java:54)
$ javap -c 'GetURL$1'
Compiled from GetURL.java
final class GetURL$1 extends java.lang.Thread {
GetURL$1(GetURL);
public void run();
}
Method GetURL$1(GetURL)
0 aload_0
1 aload_1
2 putfield #12 <Field GetURL this$0>
5 aload_0
6 invokespecial #15 <Method java.lang.Thread()>
9 return
...
>Fix:
Fix the code generated for the constructor of the anonymous inner class=
'GetURL$1'.
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the Gcc-bugs
mailing list