This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


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

java/3062: java eh crash in gcc3 branch



>Number:         3062
>Category:       java
>Synopsis:       optimized eh code crashes
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    unassigned
>State:          open
>Class:          wrong-code
>Submitter-Id:   net
>Arrival-Date:   Tue Jun 05 22:26:00 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator:     Per Bothner
>Release:        3.0 20010604 (prerelease)
>Organization:
>Environment:
System: Linux kelso.bothner.com 2.4.3 #1 Mon Apr 2 15:58:06 PDT 2001 i686 unknown
Architecture: i686 Redhat 7
host: i686-pc-linux-gnu
build: i686-pc-linux-gnu
target: i686-pc-linux-gnu
configured with: /home/bothner/GNU/gcc3/configure --enable-threads --prefix=/home/bothner/GNU/install-gcc3 --enable-languages=c++,java
>Description:
Compiling a Java test program with -O using the cvs gcc-3.0 branch
produces incorrect code, causing the test program to crash.

The test program is derived from Kawa.
>How-To-Repeat:

Copy this file to Test.java:

public class Test extends RuntimeException
{
  public static String apply (String proc)
  {
    Test cont = new Test();
    try
      {
	return cont.doThrow (proc);
      }
    catch (Test ex)
      {
	if (ex.continuation != cont)
	  throw ex;
	return ex.value;
      }
    finally
      {
	counter++;
      }
  }

  public static void main (String[] proc)
  {
    System.err.println("Hello "+apply("there!"));
  }

  public static int counter;
  public String value = "world!";
  public Object continuation = this;

  String doThrow(String str)
  {
    if (str != null)
      throw this;
    return str;
  }

  public  String apply1 (Object arg1)
  {
    String proc;
    try
      {
	proc = (String) arg1;
      }
    catch (ClassCastException ex)
      {
	throw new RuntimeException ("argument to call/cc is not procedure");
      }
    return apply (proc);
  }
}

Compile and run it:

$ gcj -O -g -o Test Test.java --main=Test
$ ./Test
Exception in thread "main" java.lang.NullPointerException
   at 0x4014c7ba: _Jv_ThrowSignal (/home/bothner/GNU/install-gcc3/lib/libgcj.so.2)
   at 0x4014c811: _Jv_ThrowSignal (/home/bothner/GNU/install-gcc3/lib/libgcj.so.2)
   at 0xbf7ff984: ?? (??:0)
   at 0x4016a740: gnu.gcj.runtime.FirstThread.run() (/home/bothner/GNU/install-gcc3/lib/libgcj.so.2)
   at 0x40178477: java.lang.Thread.run_(java.lang.Object) (/home/bothner/GNU/install-gcc3/lib/libgcj.so.2)
   at 0x4028a47f: _Jv_ThreadSetPriority(_Jv_Thread_t, int) (/home/bothner/GNU/install-gcc3/lib/libgcj.so.2)
   at 0x404cb079: GC_start_routine (/home/bothner/GNU/install-gcc3/lib/libgcjgc.so.1)
   at 0x404e7848: pthread_detach (/lib/libpthread.so.0)
   at 0x405ec92a: __clone (/lib/libc.so.6)

I also get a core dump using (a slightly older version of) the trunk.

Using JDK1.3 I get the correct output:

kelso<1769>javac Test.java
kelso<1770>java Test 
Hello world!

>Fix:

The problem seems to be related to confusion over the EXC_PTR_EXPR
tree node and/or the result of get_exception_pointer () .  The
assembly output includes:

.LBE10:
        .p2align 4,,7
.L51:
        movl    %eax, %esi
        cmpl    $1, %edx
        jne     .L45
.LBB12:
        .stabn 68,0,10,.LM11-_ZN4Test6apply1EPN4java4lang6ObjectE
.LM11:
        movl    -20(%ebp), %edx
.LEHB3:
        movl    -4(%edx), %eax
.LBB13:
        .stabn 68,0,12,.LM12-_ZN4Test6apply1EPN4java4lang6ObjectE
.LM12:
        cmpl    %ebx, 20(%eax)
        je      .L42
        subl    $12, %esp

The exception object in $eax is copied to $esi at .L51.  However,
at .LM11 we instead use -20(%ebp), which contains garbage.
>Release-Note:
>Audit-Trail:
>Unformatted:


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