libgcj/1109: libgcj crashes on string operation

gback@cs.utah.edu gback@cs.utah.edu
Wed Dec 20 12:06:00 GMT 2000


>Number:         1109
>Category:       libgcj
>Synopsis:       libgcj crashes on string operation
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    tromey
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Dec 20 12:06:04 PST 2000
>Closed-Date:    Wed Nov 17 03:33:09 PST 1999
>Last-Modified:  Wed Nov 17 03:40:01 PST 1999
>Originator:     gback@cs.utah.edu
>Release:        CVS ca. Oct 15
>Organization:
>Environment:
RH 5.2, glibc 2.0.7, Linux 2.2.12
>Description:
libgcj crashes on the following program.
Note that gcj won't compile the .java code, use
Sun's JDK or jikes to create bytecode first:


(gdb) run
Starting program: /x/gback/transvirtual/tmp/gcjpure/./a.out
1
2
3

Program received signal SIGSEGV, Segmentation fault.
0x40100a28 in java::lang::String::hashCode (this=0x0)
    at ../../../libgcj/libjava/java/lang/natString.cc:90
90        return hashChars(JvGetStringChars(this), length());
Current language:  auto; currently c++
(gdb) c
Continuing.

Program received signal SIGSEGV, Segmentation fault.
java::lang::String::charAt (this=0x400a92a0, i=0)
    at ../../../libgcj/libjava/java/lang/natString.cc:444
444       return JvGetStringChars(this)[i];
(gdb) bt
#0  java::lang::String::charAt (this=0x400a92a0, i=0)
    at ../../../libgcj/libjava/java/lang/natString.cc:444
#1  0x4008fa7a in gnu.gcj.convert.Output_8859_1.write (this=0x8067f60,
    str=0x400a92a0, inpos=1, inlength=512, work=0x808af00)
    at ../../../libgcj/libjava/gnu/gcj/convert/Output_8859_1.java:48
#2  0x400a8c2f in java.io.PrintStream.writeChars (this=0x8063d40,
    str=0x400a92a0, offset=0, count=961102)
    at ../../../libgcj/libjava/java/io/PrintStream.java:130
#3  0x400a86f4 in java.io.PrintStream.print (this=0x8063d40, str=0x400a92a0,
    println=true) at ../../../libgcj/libjava/java/io/PrintStream.java:63
#4  0x400a92d7 in java.io.PrintStream.println (this=0x8063d40, str=0x400a92a0)
    at ../../../libgcj/libjava/java/io/PrintStream.java:220
#5  0x80492b5 in C.main () at C.java:14
#6  0x400ff815 in java::lang::FirstThread::run (this=0x8064f90)
    at ../../../libgcj/libjava/java/lang/natFirstThread.cc:52
#7  0x400bcb8a in java.lang.Thread.run_ (this=0x8064f90)
    at ../../../libgcj/libjava/java/lang/Thread.java:119
#8  0x40103fee in java::lang::Thread::run__ (obj=0x8064f90)
    at ../../../libgcj/libjava/java/lang/natThread.cc:288
#9  0x4011317a in _Jv_ThreadStart (thread=0x8064f90,
    meth=0x40103fd0 <java::lang::Thread::run__(java::lang::Object *)>)
    at ../../../libgcj/libjava/no-threads.cc:25
#10 0x4010406b in java::lang::Thread::start (this=0x8064f90)
    at ../../../libgcj/libjava/java/lang/natThread.cc:301
#11 0x4008d2ce in JvRunMain (klass=0x804c1a0, argc=1, argv=0xbffffad4)
    at ../../../libgcj/libjava/prims.cc:790
#12 0x804938b in main (argc=1, argv=0xbffffad4) at /tmp/ccVTmO9rmain.i:9

>How-To-Repeat:
Compile and run this program:

import java.io.*;

public class C {
        public static void main(String av[]) {
                String x = null, y = null, z = null;
                LineNumberReader r = new LineNumberReader(
                                        new InputStreamReader(System.in));
                try {
                        x = r.readLine();
                        y = r.readLine();
                        z = r.readLine();
                        ((String)null).hashCode();
                } catch (Exception e) {
                        System.out.println(x);
                        System.out.println(y);
                        System.out.println(z);
                }
        }
}

Note that if you compile C.java with jikes, gcj will
fail even if the exception is not caused by a
NullPointerException, but even by a simple "throw new
Exception".

Secondly, if you only print x and y, it works.
Third, if you only print x, it prints nothing, but
doesn't crash.


>Fix:
None
>Release-Note:

>Audit-Trail:

Formerly PR libgcj/103


From: Bryce McKinlay <bryce@albatross.co.nz>
To: gback@cs.utah.edu
Cc: java-gnats@sourceware.cygnus.com
Subject: Re: libgcj/103: libgcj crashes on string operation
Date: Wed, 17 Nov 1999 14:29:12 +1300

 I can not reproduce this problem using gcc 2.95.2 + java patches and current
 libgcj from cvs. I strongly suspect that this the exception handling problem in
 current gcc snapshots that has been discussed on the mailing list, and not a
 string handling bug.
 
 I will try this out on a gcc 2.96 build tonight. If it crashes there, its a good
 thing, because up until now I havn't been able to come up with a self-contained
 test case for this problem.
 
 For now, if you use gcc 2.95.2 plus the java patch from
 http://waitaki.otago.ac.nz/~bryce/gcj/ , you shouldn't have this problem.
 
 regards
 
   [ bryce ]
 
 

From: Godmar Back <gback@cs.utah.edu>
To: bryce@albatross.co.nz (Bryce McKinlay)
Cc: gback@cs.utah.edu, java-gnats@sourceware.cygnus.com
Subject: Re: libgcj/103: libgcj crashes on string operation
Date: Tue, 16 Nov 1999 18:53:06 -0700 (MST)

  Cool.
 I agree that it doesn't look like a string handling bug.
 
 Discussed on the mailing list...
 in http://sourceware.cygnus.com/ml/java-discuss/1999-q4/msg00269.html
 I saw a reference to that, but it wasn't discussed on java-discuss.
 Was it on the general gcc list or on gcj-patches or gcc-bugs?
 Is this fixed in the current cvs tree?
 
 	- Godmar
 
 > 
 > I can not reproduce this problem using gcc 2.95.2 + java patches and current
 > libgcj from cvs. I strongly suspect that this the exception handling problem in
 > current gcc snapshots that has been discussed on the mailing list, and not a
 > string handling bug.
 > 
 > I will try this out on a gcc 2.96 build tonight. If it crashes there, its a good
 > thing, because up until now I havn't been able to come up with a self-contained
 > test case for this problem.
 > 
 > For now, if you use gcc 2.95.2 plus the java patch from
 > http://waitaki.otago.ac.nz/~bryce/gcj/ , you shouldn't have this problem.
 > 
 > regards
 > 
 >   [ bryce ]
 > 
 > 
 

From: Bryce McKinlay <bryce@albatross.co.nz>
To: Godmar Back <gback@cs.utah.edu>
Cc: java-gnats@sourceware.cygnus.com
Subject: Re: libgcj/103: libgcj crashes on string operation
Date: Wed, 17 Nov 1999 15:19:11 +1300

 Godmar Back wrote:
 
 > Discussed on the mailing list...
 > in http://sourceware.cygnus.com/ml/java-discuss/1999-q4/msg00269.html
 > I saw a reference to that, but it wasn't discussed on java-discuss.
 
 Oh, well I guess that pretty much was the discussion.
 
 > Is this fixed in the current cvs tree?
 
 I havn't checked for a week or so. If its still broken on current cvs I will file a
 gcj PR tonight, and maybe post something to the gcc-bugs list.
 
 regards
 
   [ bryce ]
 
 
 

From: Godmar Back <gback@cs.utah.edu>
To: bryce@albatross.co.nz (Bryce McKinlay)
Cc: gback@cs.utah.edu, java-gnats@sourceware.cygnus.com
Subject: Re: libgcj/103: libgcj crashes on string operation
Date: Tue, 16 Nov 1999 19:26:15 -0700 (MST)

  Btw, the build with --enable-interpreter bombed on me too.
 I didn't complain about it cause I hadn't updated, but the problem
 was that "redirect" wasn't defined in libjava/java/lang/natClassLoader.cc
 
 I just turned --enable-interpreter off.
 
 	- Godmar
 
 
 > 
 > Godmar Back wrote:
 > 
 > > Discussed on the mailing list...
 > > in http://sourceware.cygnus.com/ml/java-discuss/1999-q4/msg00269.html
 > > I saw a reference to that, but it wasn't discussed on java-discuss.
 > 
 > Oh, well I guess that pretty much was the discussion.
 > 
 > > Is this fixed in the current cvs tree?
 > 
 > I havn't checked for a week or so. If its still broken on current cvs I will file a
 > gcj PR tonight, and maybe post something to the gcc-bugs list.
 > 
 > regards
 > 
 >   [ bryce ]
 > 
 > 
 > 
 

From: Bryce McKinlay <bryce@albatross.co.nz>
To: Godmar Back <gback@cs.utah.edu>
Cc: java-gnats@sourceware.cygnus.com
Subject: Re: libgcj/103: libgcj crashes on string operation
Date: Wed, 17 Nov 1999 15:29:04 +1300

 Godmar Back wrote:
 
 >  Btw, the build with --enable-interpreter bombed on me too.
 > I didn't complain about it cause I hadn't updated, but the problem
 > was that "redirect" wasn't defined in libjava/java/lang/natClassLoader.cc
 >
 > I just turned --enable-interpreter off.
 
 --enable-interpreter should be working ok. I'd reccomend you do a 'make clean' or even
 'rm -rf build' between builds if you change any of the configure settings, though.
 
 regards
 
   [ bryce ]
 
 

From: Godmar Back <gback@cs.utah.edu>
To: bryce@albatross.co.nz (Bryce McKinlay)
Cc: gback@cs.utah.edu, java-gnats@sourceware.cygnus.com
Subject: Re: libgcj/103: libgcj crashes on string operation
Date: Tue, 16 Nov 1999 19:32:34 -0700 (MST)

 > 
 > Godmar Back wrote:
 > 
 > >  Btw, the build with --enable-interpreter bombed on me too.
 > > I didn't complain about it cause I hadn't updated, but the problem
 > > was that "redirect" wasn't defined in libjava/java/lang/natClassLoader.cc
 > >
 > > I just turned --enable-interpreter off.
 > 
 > --enable-interpreter should be working ok. I'd reccomend you do a 'make clean' or even
 > 'rm -rf build' between builds if you change any of the configure settings, though.
 > 
 
 I'm *always* do /bin/rm -rf * before building anything that has to do
 with gnu because I don't trust autoconf/automake a bit. ;-)
 
 That wasn't it... I'll cvs udpate libgcj and I'll let you know if it
 happens again.
 
 	- Godmar
 

From: Godmar Back <gback@cs.utah.edu>
To: bryce@albatross.co.nz (Bryce McKinlay)
Cc: gback@cs.utah.edu, java-gnats@sourceware.cygnus.com
Subject: Re: libgcj/103: libgcj crashes on string operation
Date: Tue, 16 Nov 1999 20:28:32 -0700 (MST)

  It doesn't happen anymore.
 
 I think this was the problem:
 
 1999-10-22  Tom Tromey  <tromey@cygnus.com>
 
         * Makefile.in: Rebuilt.
         * Makefile.am (java/lang/ClassLoader.h): New target.
         * java/lang/natClassLoader.cc (_Jv_FindClass): Removed reference
         to `redirect'.
 
 > 
 > Godmar Back wrote:
 > 
 > >  Btw, the build with --enable-interpreter bombed on me too.
 > > I didn't complain about it cause I hadn't updated, but the problem
 > > was that "redirect" wasn't defined in libjava/java/lang/natClassLoader.cc
 > >
 > > I just turned --enable-interpreter off.
 > 
 > --enable-interpreter should be working ok. I'd reccomend you do a 'make clean' or even
 > 'rm -rf build' between builds if you change any of the configure settings, though.
 > 
 > regards
 > 
 >   [ bryce ]
 > 
 > 
 
State-Changed-From-To: open->closed
State-Changed-By: bryce
State-Changed-When: Wed Nov 17 03:33:09 1999
State-Changed-Why:
    I believe this bug was specific to Godmar's specific gcc build. 
    I cannot reproduce it with 19991116.

From: Bryce McKinlay <bryce@albatross.co.nz>
To: gback@cs.utah.edu
Cc: java-gnats@sourceware.cygnus.com
Subject: Re: libgcj/103: libgcj crashes on string operation
Date: Thu, 18 Nov 1999 00:31:32 +1300

 Your test code works fine for me on the current (19991116) gcc snapshot, so I'm
 going to close the PR. I guess this wasn't the same as my (and Jeff Sturm's) EH
 bug though, as that one is still there.
 
 FYI, the simplest way to reproduce my bug is:
 
 import java.text.DecimalFormat;
 
 public class Format1
 {
   public static void main(String args[])
   {
     DecimalFormat df = new DecimalFormat();
   }
 }
 
 This causes libgcj to thrown an exception somewhere and subsequently abort during
 the 'throw'. It works fine on gcc 2.95.2. So far it only seems to occur on
 exceptions thrown and caught within libgcj - I havn't been able to reproduce it
 in self-contained code - and this makes it difficult to come up with a reasonable
 PR/gcc complaint ;-)
 
 regards
 
   [ bryce ]
 
 
 gback@cs.utah.edu wrote:
 
 > import java.io.*;
 >
 > public class C {
 >         public static void main(String av[]) {
 >                 String x = null, y = null, z = null;
 >                 LineNumberReader r = new LineNumberReader(
 >                                         new InputStreamReader(System.in));
 >                 try {
 >                         x = r.readLine();
 >                         y = r.readLine();
 >                         z = r.readLine();
 >                         ((String)null).hashCode();
 >                 } catch (Exception e) {
 >                         System.out.println(x);
 >                         System.out.println(y);
 >                         System.out.println(z);
 >                 }
 >         }
 > }
 

From: bryce@albatross.co.nz
To: gback@cs.utah.edu, java-gnats@sourceware.cygnus.com, tromey@cygnus.com
Cc:  
Subject: Re: libgcj/103
Date: 17 Nov 1999 11:33:09 -0000

 Synopsis: libgcj crashes on string operation
 
 State-Changed-From-To: open->closed
 State-Changed-By: bryce
 State-Changed-When: Wed Nov 17 03:33:09 1999
 State-Changed-Why:
     I believe this bug was specific to Godmar's specific gcc build. 
     I cannot reproduce it with 19991116.
 
 http://sourceware.cygnus.com/cgi-bin/gnatsweb.pl?cmd=view&database=java&pr=103
>Unformatted:




More information about the Gcc-prs mailing list