You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Daniel Kowalik <da...@reuters.pl> on 2003/09/19 09:43:23 UTC

Tomcat and native libs.

Hi, i've got a simple application with a couple of servlets using one
shared object. The problem is that this shared object uses native libs
and there is no way to avoid it. And whenever servlet gets the instance
of this shared object, Tomcat crashes and also crashes the whole JVM.
When i use this obejct outside tomcat, in a standalone application,
everything is ok. I've gave it a try  on solaris and windows and in both
cases i've got the same results. Of course native libs are for sol and
win respectively.  And here is the question: shall i somehow inform
Tomcat about native libs? (Theese are already on LD_LIBRARY_PATH
variable). 


Bests
daniel


Re: Tomcat and native libs.

Posted by Christopher Williams <cc...@ntlworld.com>.
I'm no Unix expert, but I believe that signal 11 is a segmentation fault
(i.e. you're accessing either an invalid memory address or one which you are
not allowed to use).  The most likely cause is a NULL pointer access.  What
you could try doing is handling signal 11 in your code.  In the remainder of
your native code you could set a global variable to the name of the current
function being executed and your signal handler could print this to STDOUT.
Then at least you can start to isolate where the problem is occurring.

Do something like the following:

#include <signal.h>
#include <siginfo.h>

char *g_currFn = "";

if (SIG_ERR == sigset(11, handler)) {
    // Bummer...
}
...

void handler(int sig) {
    // Print signal and offending function to STDERR
    psignal(sig, (const char *) g_currFn);
}

int myfunc(int) {
    g_currFn = "myfunc";
    ...
}


Something that is eminently possible is that your native code is relying on
a Java class that is, say, in $JAVA_HOME/jre/lib/ext and is being loaded by
the standard Java classloader but is not being loaded by the Tomcat loader.
In this case the call:
jclass clz = env->FindClass("example/somewhere/something/ClassIWant");
jmethodID mid = env->GetMethodID(clz, "<init>", "()V");

will access an invalid pointer and crash the virtual machine.  I know; I've
done it.

Hope this helps.

Chris.



---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: Tomcat and native libs.

Posted by Christopher Williams <cc...@ntlworld.com>.
I'm no Unix expert, but I believe that signal 11 is a segmentation fault
(i.e. you're accessing either an invalid memory address or one which you are
not allowed to use).  The most likely cause is a NULL pointer access.  What
you could try doing is handling signal 11 in your code.  In the remainder of
your native code you could set a global variable to the name of the current
function being executed and your signal handler could print this to STDOUT.
Then at least you can start to isolate where the problem is occurring.

Do something like the following:

#include <signal.h>
#include <siginfo.h>

char *g_currFn = "";

if (SIG_ERR == sigset(11, handler)) {
    // Bummer...
}
...

void handler(int sig) {
    // Print signal and offending function to STDERR
    psignal(sig, (const char *) g_currFn);
}

int myfunc(int) {
    g_currFn = "myfunc";
    ...
}


Something that is eminently possible is that your native code is relying on
a Java class that is, say, in $JAVA_HOME/jre/lib/ext and is being loaded by
the standard Java classloader but is not being loaded by the Tomcat loader.
In this case the call:
jclass clz = env->FindClass("example/somewhere/something/ClassIWant");
jmethodID mid = env->GetMethodID(clz, "<init>", "()V");

will access an invalid pointer and crash the virtual machine.  I know; I've
done it.

Hope this helps.

Chris.



RE: Re[2]: Tomcat and native libs.

Posted by Daniel Kowalik <da...@reuters.pl>.
Hi Anton, sorry i haven't replied earlier. The native code is ok. It
works perfectly without Tomcat. It's related to reloading web
application. I've actually worked it out. But by taking a bit differen
way.

Bests
daniel

-----Original Message-----
From: Anton Tagunov [mailto:atagunov@mail.cnt.ru] 
Sent: 20 września 2003 18:58
To: Tomcat Users List
Subject: Re[2]: Tomcat and native libs.


Hello Daniel!

Can it be that the native code is plainly crashing?
Or may it be related to reloading a web application?

DK> Unexpected Signal : 11 occurred at PC=0xFE0EAFE8 Function=[Unknown. 
DK> Nearest: JVM_FindPrimitiveClass+0x1BB8] 
DK> Library=/usr/j2sdk1.4.1_04/jre/lib/sparc/client/libjvm.so
DK> Current Java thread:

Anton


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re[2]: Tomcat and native libs.

Posted by Anton Tagunov <at...@mail.cnt.ru>.
Hello Daniel!

Can it be that the native code is plainly crashing?
Or may it be related to reloading a web application?

DK> Unexpected Signal : 11 occurred at PC=0xFE0EAFE8
DK> Function=[Unknown. Nearest: JVM_FindPrimitiveClass+0x1BB8]
DK> Library=/usr/j2sdk1.4.1_04/jre/lib/sparc/client/libjvm.so
DK> Current Java thread:

Anton


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re[2]: Tomcat and native libs.

Posted by Anton Tagunov <at...@mail.cnt.ru>.
Hello Daniel!

Can it be that the native code is plainly crashing?
Or may it be related to reloading a web application?

DK> Unexpected Signal : 11 occurred at PC=0xFE0EAFE8
DK> Function=[Unknown. Nearest: JVM_FindPrimitiveClass+0x1BB8]
DK> Library=/usr/j2sdk1.4.1_04/jre/lib/sparc/client/libjvm.so
DK> Current Java thread:

Anton


RE: Tomcat and native libs.

Posted by Daniel Kowalik <da...@reuters.pl>.
Hi,
>Have you tried synchronizing access to the native methods?  Yes.

>Does Tomcat and the JVM crash when you only have one servlet using the
native code? 
Yes, everything crashes when the first servlet gets the instance of
shared object. Lets say the shared object is called Data. The servlet
gets the Data instance by "Data data = Data.getInstance();" and in Data
object it looks like this: "private static Data instance = new Data();"
and then the getter method. Data in it's constructor tries to get access
to Tibco Rendezvous and create a session. And exactly at this moment
everything crashes.

>Alternatively, can you have two instances of the object so that it is
not shared? 
No, i need to have it like this. This shared object gets the data, which
is then shared among other servlets. 

>What are the messages printed by the JVM when it crashes?
Unexpected Signal : 11 occurred at PC=0xFE0EAFE8
Function=[Unknown. Nearest: JVM_FindPrimitiveClass+0x1BB8]
Library=/usr/j2sdk1.4.1_04/jre/lib/sparc/client/libjvm.so
Current Java thread:
Dynamic libraries:
0x10000 	/usr/j2sdk1.4.1_04/bin/java
0xff360000 	/usr/lib/libthread.so.1
0xff3a0000 	/usr/lib/libdl.so.1
0xff280000 	/usr/lib/libc.so.1
0xff350000 	/usr/platform/SUNW,Sun-Blade-1000/lib/libc_psr.so.1
0xfe000000 	/usr/j2sdk1.4.1_04/jre/lib/sparc/client/libjvm.so
0xff210000 	/usr/lib/libCrun.so.1
0xff1f0000 	/usr/lib/libsocket.so.1
0xff100000 	/usr/lib/libnsl.so.1
0xff1c0000 	/usr/lib/libm.so.1
0xff240000 	/usr/lib/libw.so.1
0xff0c0000 	/usr/lib/libmp.so.2
0xff090000
/usr/j2sdk1.4.1_04/jre/lib/sparc/native_threads/libhpi.so
0xff060000 	/usr/j2sdk1.4.1_04/jre/lib/sparc/libverify.so
0xff020000 	/usr/j2sdk1.4.1_04/jre/lib/sparc/libjava.so
0xfe7d0000 	/usr/j2sdk1.4.1_04/jre/lib/sparc/libzip.so
0xfe5a0000 	/usr/lib/locale/pl_PL.ISO8859-2/pl_PL.ISO8859-2.so.2
0xfa0c0000 	/usr/j2sdk1.4.1_04/jre/lib/sparc/libnet.so
0xefe80000 	/work/jni/solaris/libsass3jni.so  - This one is
suspected.
0xf11e0000 	/usr/lib/libposix4.so.1
0xf0f10000 	/usr/lib/libaio.so.1
Local Time = Fri Sep 19 11:28:06 2003
Elapsed Time = 9
#
# HotSpot Virtual Machine Error : 11
# Error ID : 4F530E43505002E6 01
# Please report this error at
# http://java.sun.com/cgi-bin/bugreport.cgi
#
# Java VM: Java HotSpot(TM) Client VM (1.4.1_04-b01 mixed mode)
#
# An error report file has been saved as hs_err_pid871.log.
# Please refer to the file for further information.
#


>Are you sure that your native library is even beng found and loaded? 
It looks like. JVM says it's loaded. See the crash message. I've marked
the suspected library.

BTW, i've patched the system as it was suggested by sun. The funny thing
is that it runs without any problems if used without Tomcat. 

Bests
Daniel


-----Original Message-----
From: Christopher Williams [mailto:ccwilliams3@ntlworld.com] 
Sent: 19 września 2003 11:21
To: Tomcat Users List
Subject: Re: Tomcat and native libs.


  What are the messages printed by the JVM when it crashes?  Are you
sure that your native library is even beng found and loaded?



---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


RE: Tomcat and native libs.

Posted by Daniel Kowalik <da...@reuters.pl>.
Hi,
>Have you tried synchronizing access to the native methods?  Yes.

>Does Tomcat and the JVM crash when you only have one servlet using the
native code? 
Yes, everything crashes when the first servlet gets the instance of
shared object. Lets say the shared object is called Data. The servlet
gets the Data instance by "Data data = Data.getInstance();" and in Data
object it looks like this: "private static Data instance = new Data();"
and then the getter method. Data in it's constructor tries to get access
to Tibco Rendezvous and create a session. And exactly at this moment
everything crashes.

>Alternatively, can you have two instances of the object so that it is
not shared? 
No, i need to have it like this. This shared object gets the data, which
is then shared among other servlets. 

>What are the messages printed by the JVM when it crashes?
Unexpected Signal : 11 occurred at PC=0xFE0EAFE8
Function=[Unknown. Nearest: JVM_FindPrimitiveClass+0x1BB8]
Library=/usr/j2sdk1.4.1_04/jre/lib/sparc/client/libjvm.so
Current Java thread:
Dynamic libraries:
0x10000 	/usr/j2sdk1.4.1_04/bin/java
0xff360000 	/usr/lib/libthread.so.1
0xff3a0000 	/usr/lib/libdl.so.1
0xff280000 	/usr/lib/libc.so.1
0xff350000 	/usr/platform/SUNW,Sun-Blade-1000/lib/libc_psr.so.1
0xfe000000 	/usr/j2sdk1.4.1_04/jre/lib/sparc/client/libjvm.so
0xff210000 	/usr/lib/libCrun.so.1
0xff1f0000 	/usr/lib/libsocket.so.1
0xff100000 	/usr/lib/libnsl.so.1
0xff1c0000 	/usr/lib/libm.so.1
0xff240000 	/usr/lib/libw.so.1
0xff0c0000 	/usr/lib/libmp.so.2
0xff090000
/usr/j2sdk1.4.1_04/jre/lib/sparc/native_threads/libhpi.so
0xff060000 	/usr/j2sdk1.4.1_04/jre/lib/sparc/libverify.so
0xff020000 	/usr/j2sdk1.4.1_04/jre/lib/sparc/libjava.so
0xfe7d0000 	/usr/j2sdk1.4.1_04/jre/lib/sparc/libzip.so
0xfe5a0000 	/usr/lib/locale/pl_PL.ISO8859-2/pl_PL.ISO8859-2.so.2
0xfa0c0000 	/usr/j2sdk1.4.1_04/jre/lib/sparc/libnet.so
0xefe80000 	/work/jni/solaris/libsass3jni.so  - This one is
suspected.
0xf11e0000 	/usr/lib/libposix4.so.1
0xf0f10000 	/usr/lib/libaio.so.1
Local Time = Fri Sep 19 11:28:06 2003
Elapsed Time = 9
#
# HotSpot Virtual Machine Error : 11
# Error ID : 4F530E43505002E6 01
# Please report this error at
# http://java.sun.com/cgi-bin/bugreport.cgi
#
# Java VM: Java HotSpot(TM) Client VM (1.4.1_04-b01 mixed mode)
#
# An error report file has been saved as hs_err_pid871.log.
# Please refer to the file for further information.
#


>Are you sure that your native library is even beng found and loaded? 
It looks like. JVM says it's loaded. See the crash message. I've marked
the suspected library.

BTW, i've patched the system as it was suggested by sun. The funny thing
is that it runs without any problems if used without Tomcat. 

Bests
Daniel


-----Original Message-----
From: Christopher Williams [mailto:ccwilliams3@ntlworld.com] 
Sent: 19 września 2003 11:21
To: Tomcat Users List
Subject: Re: Tomcat and native libs.


  What are the messages printed by the JVM when it crashes?  Are you
sure that your native library is even beng found and loaded?



---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: Tomcat and native libs.

Posted by Christopher Williams <cc...@ntlworld.com>.
Have you tried synchronizing access to the native methods?  Does Tomcat and
the JVM crash when you only have one servlet using the native code?
Alternatively, can you have two instances of the object so that it is not
shared?  What are the messages printed by the JVM when it crashes?  Are you
sure that your native library is even beng found and loaded?



Re: Tomcat and native libs.

Posted by Christopher Williams <cc...@ntlworld.com>.
Have you tried synchronizing access to the native methods?  Does Tomcat and
the JVM crash when you only have one servlet using the native code?
Alternatively, can you have two instances of the object so that it is not
shared?  What are the messages printed by the JVM when it crashes?  Are you
sure that your native library is even beng found and loaded?



---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org