dynamic_cast problem in JNI code - any suggestions welcome.
Jan Hardenbergh
hardenbergh@rtviz.com
Mon Nov 11 21:03:00 GMT 2002
> From: Andrew Haley [mailto:aph@redhat.com]
>> Jan Hardenbergh writes:
> >
> > We are running a Java app on Redhat 7.2 using gcc3 and we have some JNI
> > code. We have added some dynamic_cast operator to improve the error
> > checking, however, when running on Linux they crash.
> >
> >
> > Any advice?
>> Before we go any further, try compiling with gcc 3.2.
>> If it's still broken in that release we can investigate further.
Still no good. I downloaded gcc-3.2 and tried again. It still happens.
Since the workaround is so easy, I am not going to pursue this. However, I
am reporting what I found. Here is the offending line of code:
VLIImageBufferInternal *pColor = dynamic_cast<VLIImageBufferInternal
*>(m_tIB);
m_tIB is a superclass that the user creates: VLIImageBuffer
NOTE! this code runs FINE when used in another application. The exact same
shared object dies when run from Java thru JNI. Another thing I have noticed
is that there are unresolved references in our library that do not seem to
get called, however, when the library is opened in the JNI environment, it
wants all symbols resolved.
This seems to support the theory that some library involved in dynamic
linking is not compiled with the same compiler. This was the theory in a
Debian bug report about dynamic_cast causing a SEGV. That bug was closed
when both libraries were recompiled with the same compiler and it worked.
This crash does not happen if static_cast is used in place of dynamic_cast.
That's our solution for now.
Here is more info: ======== :
bash-2.05$ gcc --version
gcc (GCC) 3.2
Copyright (C) 2002 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
bash-2.05$ uname -a
Linux DHCP87 2.4.7-10 #1 Thu Sep 6 17:27:27 EDT 2001 i686 unknown
[jch: this is a fairly vanilla Redhat 7.2]
bash-2.05$ ./config.guess
i686-pc-linux-gnu
bash-2.05$ java -version
java version "1.3.1_06"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1_06-b01)
Java HotSpot(TM) Client VM (build 1.3.1_06-b01, mixed mode)
bash-2.05$ java -classpath vli3.jar:trav2.jar travaj/vlitravaj
An unexpected exception has been detected in native code outside the VM.
Unexpected Signal : 11 occurred at PC=0x8103c98
Function name=(N/A)
Library=(N/A)
NOTE: We are unable to locate the function name symbol for the error
just occurred. Please refer to release documentation for possible
reason and solutions.
Current Java thread:
at com.terarecon.vli.VLIVolume.render(Native Method)
at travaj.vlitravaj.render(vlitravaj.java:85)
at travaj.vlitravaj.main(vlitravaj.java:101)
Dynamic libraries:
08048000-0804c000 r-xp 00000000 16:03 195702
/usr/java/jdk1.3.1_06/bin/i386/native_threads/java
0804c000-0804d000 rw-p 00003000 16:03 195702
/usr/java/jdk1.3.1_06/bin/i386/native_threads/java
40000000-40016000 r-xp 00000000 16:01 551618 /lib/ld-2.2.4.so
40016000-40017000 rw-p 00015000 16:01 551618 /lib/ld-2.2.4.so
40017000-40028000 r-xp 00000000 16:03 860791
/usr/java/jdk1.3.1_06/jre/lib/i386/libverify.so
40028000-4002a000 rw-p 00010000 16:03 860791
/usr/java/jdk1.3.1_06/jre/lib/i386/libverify.so
4002a000-4002b000 r--p 00000000 16:03 648967
/usr/lib/locale/en_US/LC_IDENTIFICATION
4002b000-4002c000 r--p 00000000 16:03 989698
/usr/lib/locale/en_US/LC_MEASUREMENT
4002d000-4003a000 r-xp 00000000 16:01 924774 /lib/i686/libpthread-0.9.so
4003a000-40042000 rw-p 0000c000 16:01 924774 /lib/i686/libpthread-0.9.so
40042000-4004b000 r-xp 00000000 16:03 325335
/usr/java/jdk1.3.1_06/jre/lib/i386/native_threads/libhpi.so
4004b000-4004c000 rw-p 00008000 16:03 325335
/usr/java/jdk1.3.1_06/jre/lib/i386/native_threads/libhpi.so
4004c000-40252000 r-xp 00000000 16:03 406667
/usr/java/jdk1.3.1_06/jre/lib/i386/client/libjvm.so
40252000-4035b000 rw-p 00205000 16:03 406667
/usr/java/jdk1.3.1_06/jre/lib/i386/client/libjvm.so
40372000-40375000 r-xp 00000000 16:01 551631 /lib/libdl-2.2.4.so
40375000-40376000 rw-p 00002000 16:01 551631 /lib/libdl-2.2.4.so
40376000-404a8000 r-xp 00000000 16:01 924770 /lib/i686/libc-2.2.4.so
404a8000-404ad000 rw-p 00131000 16:01 924770 /lib/i686/libc-2.2.4.so
404b1000-404c4000 r-xp 00000000 16:01 551636 /lib/libnsl-2.2.4.so
404c4000-404c5000 rw-p 00012000 16:01 551636 /lib/libnsl-2.2.4.so
404c8000-404ea000 r-xp 00000000 16:01 924772 /lib/i686/libm-2.2.4.so
404ea000-404eb000 rw-p 00021000 16:01 924772 /lib/i686/libm-2.2.4.so
404eb000-4051f000 r-xp 00000000 16:03 65912
/usr/lib/libstdc++-2-libc6.1-1-2.9.0.so
4051f000-4052b000 rw-p 00033000 16:03 65912
/usr/lib/libstdc++-2-libc6.1-1-2.9.0.so
4052d000-4054e000 r-xp 00000000 16:03 860782
/usr/java/jdk1.3.1_06/jre/lib/i386/libjava.so
4054e000-40550000 rw-p 00020000 16:03 860782
/usr/java/jdk1.3.1_06/jre/lib/i386/libjava.so
40551000-40565000 r-xp 00000000 16:03 860792
/usr/java/jdk1.3.1_06/jre/lib/i386/libzip.so
40565000-40568000 rw-p 00013000 16:03 860792
/usr/java/jdk1.3.1_06/jre/lib/i386/libzip.so
40568000-4129f000 r--s 00000000 16:03 812160
/usr/java/jdk1.3.1_06/jre/lib/rt.jar
412cc000-415c3000 r--s 00000000 16:03 812153
/usr/java/jdk1.3.1_06/jre/lib/i18n.jar
415c3000-415d9000 r--s 00000000 16:03 812161
/usr/java/jdk1.3.1_06/jre/lib/sunrsasign.jar
43681000-43682000 r--p 00000000 16:03 892356
/usr/lib/locale/en_US/LC_TELEPHONE
43682000-43683000 r--p 00000000 16:03 892358
/usr/lib/locale/en_US/LC_ADDRESS
43683000-43684000 r--p 00000000 16:03 892357
/usr/lib/locale/en_US/LC_NAME
43684000-43685000 r--p 00000000 16:03 551641
/usr/lib/locale/en_US/LC_PAPER
43685000-43686000 r--p 00000000 16:03 941049
/usr/lib/locale/en_US/LC_MESSAGES/SYS_LC_MESSAGES
43686000-43687000 r--p 00000000 16:03 989697
/usr/lib/locale/en_US/LC_MONETARY
43687000-4368d000 r--p 00000000 16:03 649025
/usr/lib/locale/en_US/LC_COLLATE
4368d000-4368e000 r--p 00000000 16:03 648968
/usr/lib/locale/en_US/LC_TIME
4368e000-4368f000 r--p 00000000 16:03 730111
/usr/lib/locale/en_US/LC_NUMERIC
4368f000-43690000 r--s 00000000 16:02 1514813
/space/7nov/sw/vlidemo/silver/java/trav2.jar
49cef000-49d1a000 r--p 00000000 16:03 730116
/usr/lib/locale/en_US/LC_CTYPE
49d1a000-49d21000 r--s 00000000 16:02 1514809
/space/7nov/sw/vlidemo/silver/java/vli3.jar
49d21000-49d27000 r-xp 00000000 16:01 551715
/lib/libgcc_s-3.0.2-20010905.so.1
49d27000-49d29000 rw-p 00005000 16:01 551715
/lib/libgcc_s-3.0.2-20010905.so.1
49d2f000-49d39000 r-xp 00000000 16:01 551652 /lib/libnss_files-2.2.4.so
49d39000-49d3a000 rw-p 00009000 16:01 551652 /lib/libnss_files-2.2.4.so
49d3a000-49d44000 r-xp 00000000 16:01 551657 /lib/libnss_nis-2.2.4.so
49d44000-49d45000 rw-p 00009000 16:01 551657 /lib/libnss_nis-2.2.4.so
4a5b1000-4a5f5000 r-xp 00000000 16:02 1580016
/space/7nov/sw/vlidemo/silver/java/libvli3jni.so.3.1
4a5f5000-4a5ff000 rw-p 00043000 16:02 1580016
/space/7nov/sw/vlidemo/silver/java/libvli3jni.so.3.1
4a614000-4a6ac000 r-xp 00000000 16:03 66584 /usr/lib/libstdc++.so.5.0.0
4a6ac000-4a6c6000 rw-p 00097000 16:03 66584 /usr/lib/libstdc++.so.5.0.0
4a6cb000-4a7a2000 r-xp 00000000 16:02 81571
/space/7nov/sw/vlidemo/silver/java/libvli3.so.3.1
4a7a2000-4a7b8000 rw-p 000d6000 16:02 81571
/space/7nov/sw/vlidemo/silver/java/libvli3.so.3.1
Local Time = Mon Nov 11 14:55:09 2002
Elapsed Time = 0
#
# The exception above was detected in native code outside the VM
#
# Java VM: Java HotSpot(TM) Client VM (1.3.1_06-b01 mixed mode)
#
# An error report file has been saved as hs_err_pid26245.log.
# Please refer to the file for further information.
#
Aborted
: ======== :
I cannot send source to libvli3 or libvli3jni.
YON - Jan C. Hardenbergh - hardenbergh@terarecon.com
More information about the Java
mailing list