libgcj/1243: gij freezes when running program with System.loadLibrary
Oskar Liljeblad
osk@hem.passagen.se
Wed Dec 20 12:22:00 GMT 2000
>Number: 1243
>Category: libgcj
>Synopsis: gij freezes when running program with System.loadLibrary
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: green
>State: open
>Class: sw-bug
>Submitter-Id: unknown
>Arrival-Date: Wed Dec 20 12:18:12 PST 2000
>Closed-Date:
>Last-Modified: Tue Apr 25 15:16:00 PDT 2000
>Originator:
>Release:
>Organization:
>Environment:
>Description:
--82I3+IH0IqGh5yIs
Content-Type: text/plain; charset=us-ascii
Category: gcj
Release: libgcj 20000418 snapshot
Environment: libc6 2.1.3, egcs 2.96 20000417 snapshot
When I run gij on the following program, gij executes it,
but stops responding before anything is printed.
However, compiling the program to native code and
running that instead, works fine.
The program is simple, and has been attached. The
Makefile contains 'run' and 'run-gij' to test the
various executing methods.
Oskar Liljeblad (osk@hem.passagen.se)
--82I3+IH0IqGh5yIs
Content-Type: text/x-java
Content-Disposition: attachment; filename="HelloWorld.java"
class HelloWorld {
public native void hello();
static {
System.loadLibrary("helloworld");
}
}
class Demo {
public static void main(String[] args) {
new HelloWorld().hello();
}
}
--82I3+IH0IqGh5yIs
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename=Makefile
LIBJAVA_PREFIX = /home/usel/Base
LD_LIBRARY_PATH := $(LD_LIBRARY_PATH):.
CLASSPATH := $(CLASSPATH):.
.PHONY: all clean run run-gij
all: Demo
clean:
-rm -f *.o *.class Demo HelloWorld.h libhelloworld.so
run: all
Demo
run-gij: all
gij Demo
Demo.class HelloWorld.class: HelloWorld.java
gcj -C $<
%.o: %.class
gcj -c $<
HelloWorld.h: HelloWorld.java
gcjh HelloWorld
natHelloWorld.o: natHelloWorld.cc HelloWorld.h
g++ -g -I. -I$(LIBJAVA_PREFIX)/include -fno-rtti -c $<
libhelloworld.so: natHelloWorld.o
gcc -shared -o $@ $^
Demo: HelloWorld.o Demo.o libhelloworld.so
gcj --main=Demo -o $@ HelloWorld.o Demo.o -L. -lhelloworld
--82I3+IH0IqGh5yIs
Content-Type: text/x-c++src
Content-Disposition: attachment; filename="natHelloWorld.cc"
#include <stdio.h>
#include <gcj/cni.h>
#include <HelloWorld.h>
void
HelloWorld::hello()
{
printf("Hello, GCJ world!\n");
}
--82I3+IH0IqGh5yIs--
>How-To-Repeat:
>Fix:
>Release-Note:
>Audit-Trail:
Formerly PR libgcj/215
From: Bryce McKinlay <bryce@albatross.co.nz>
To: java-gnats@sourceware.cygnus.com, osk@hem.passagen.se, green@cygnus.com
Cc:
Subject: Re: libgcj/215
Date: Mon, 24 Apr 2000 01:24:21 +1200
Hi Oskar,
When I run this, I don't get a freeze. I get:
$ gij Demo
java.lang.ExceptionInInitializerError
at 0x400edf0b: java::lang::Throwable::Throwable(void)
(/usr/local/gcc/lib/libgcj.so.1)
at 0x400e3002: java::lang::Error::Error(void)
(/usr/local/gcc/lib/libgcj.so.1)
at 0x400e5282: java::lang::LinkageError::LinkageError(void)
(/usr/local/gcc/lib/libgcj.so.1)
at 0x400e319e:
java::lang::ExceptionInInitializerError::ExceptionInInitializerError(java::lang::Throwable
*) (/usr/local/gcc/lib/libgcj.so.1)
at 0x40134700: java::lang::Class::initializeClass(void)
(/usr/local/gcc/lib/libgcj.so.1)
at 0x400bab3e: _Jv_InterpMethod::continue1(_Jv_InterpMethodInvocation
*) (/usr/local/gcc/lib/libgcj.so.1)
[...]
Looking closer, a NullPointerException is thrown from inside the
"HelloWorld" initializer, in _Jv_ResolvePoolEntry.
Basically, loading native code from interpreted code doesn't yet work.
(In this case loading a native method implementation, but loading
compiled java code using forName() from interpreted code doesn't work
yet, either).
regards
[ bryce ]
http://sourceware.cygnus.com/cgi-bin/gnatsweb.pl?cmd=view&pr=215&database=java
From: Tom Tromey <tromey@cygnus.com>
To: Bryce McKinlay <bryce@albatross.co.nz>
Cc: green@cygnus.com, java-gnats@sourceware.cygnus.com
Subject: Re: libgcj/215
Date: Tue, 25 Apr 2000 15:13:16 -0700 (PDT)
Bryce> Basically, loading native code from interpreted code doesn't
Bryce> yet work. (In this case loading a native method
Bryce> implementation, but loading compiled java code using forName()
Bryce> from interpreted code doesn't work yet, either).
I've solved this problem when the native method is implemented using
JNI (patch pending). But we haven't even considered it for CNI code.
I guess there's no reason to prohibit this case, though it does seem
unusual. One idea would be to add a CNI function that could be used
to register these functions (from JNI_OnLoad). Another idea would be
to hack jni.cc to generate the mangling for such methods and look for
them before looking for a CNI method. Ouch.
Tom
>Unformatted:
More information about the Gcc-prs
mailing list