[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: C++ exception in JNI code aborts
From: |
bouree |
Subject: |
Re: C++ exception in JNI code aborts |
Date: |
Wed, 15 Nov 2000 19:42:55 GMT |
Definitely sounds like a bug in the C++ compiler. Haven't worked on the
said platform to confirm this.
The only thing I would suggest is to remove the JRE completely and call
the NativeMethod from a pure C++ program. That would isolate the problem
to the C++ compiler.
good luck
In article <address@hidden>,
address@hidden wrote:
>
> We have a JNI layer which interfaces some legacy code to some java
code.
> When the legacy code throws a (C++) exception which is caught in the
> JNI layer, the jre aborts. This only seems to happen on RedHat 7.0. On
> Solaris, and earlier versions of Linux, this behavior is not seen. We
> have whittled it down to the smallest possible example, which does not
> involve any of our legacy code, and in which the exception is thrown
and
> caught in the JNI code itself.
>
> We are using the 1.3.0 (mixed mode) Standard Edition of the JRE. Here
is
> the output from a run on RedHat 7.0:
>
> > Linux tunafish 2.2.16-22 #1 Tue Aug 22
> > 16:49:06 EDT 2000 i686 unknown
> > gcc 2.96
> > java version "1.3.0"
> > Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0)
> > Java HotSpot(TM) Client VM (build 1.3.0, mixed mode)
> >
> > Hello world from java main.
> > hello world from native [3]
> > ./it: line 5: 13342 Aborted java -showversion
> > -Djava.library.path=. -classpath . MainClass
>
> And here is the output on RedHat 6:
>
> > Linux clam 2.2.16 #1 Thu Jun 15 12:09:18 PDT 2000 i686 unknown
> > gcc 2.95.2
> > java version "1.3.0" <<libmylib.cpp>> <<MainClass.java>>
<<it>>
> > Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0)
> > Java HotSpot(TM) Client VM (build 1.3.0, mixed mode)
> >
> > Hello world from java main.
> > hello world from native [3]
> > cought the error
> > after try/catch block
> > Goodbye from java main.
>
> Below is the JNI (shared object code) which is built like so:
>
> g++ -shared -o libmylib.so libmylib.cpp
>
> And also below is the Java driver used to load the JNI code and fire
it
> up. Finally, note that
> even if we build the libmylib.so statically linked to all runtime
> components (glibc, etc), the problem
> still occurs. We did upgrade the RedHat 7.0 box to the latest glibc we
> could find.
>
> If anyone has any ideas why this is happening and how we might avoid
it,
> I
> would really appreciate hearing from you.
>
> Thanks in advance.
> Ron Forrester
>
> =-=-=-=-=-=- libmylib.cpp =-=-=-=-=-=-
>
> #include "jni.h"
> #include <stdio.h>
>
> extern "C" JNIEXPORT void JNICALL Java_MainClass_aNativeCall
> (JNIEnv *env, jobject jObj, jint i)
> {
> try {
> printf("hello world from native [%d]\n", i);
> throw "wow";
> printf("no throw\n");
> }
> catch (...) {
> printf("cought the error\n");
> }
> printf("after try/catch block\n");
> }
>
> =-=-=-=-=-=- MainClass.java =-=-=-=-=-=-
>
> public class MainClass {
>
> static {
> try {
> System.loadLibrary("mylib");
> } catch (Error e) {
> System.out.println("failed to load the
> library");
> System.exit(1);
> }
> }// static for load library.
>
> /*
> */
> public static void main(String[] args) {
>
> System.out.println("Hello world from java main.");
> MainClass m = new MainClass();
> m.aNativeCall(3);
> System.out.println("Goodbye from java main.");
> }
>
> public native void aNativeCall(int i);
> }
>
>
--
http://members.aol.com/bourie
Sent via Deja.com http://www.deja.com/
Before you buy.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Re: C++ exception in JNI code aborts,
bouree <=