Hi. I've just been converting an app to use C++-style casts instead of C-style casts and I've come across a nasty problem.
If you use a C++ dynamic_cast complied with g++-3.3 within a native Java method, the blackdown JVM (1.4.1) crashes. I've attached three very short sample files that illustrate this problem (Test.java, Test.cc and a Makefile). Changing the dynamic_cast to a static_cast in Test.cc stops the crash. Compiling the C++ library with g++-2.95 instead of g++-3.3 stops the crash (though compiling with g++-3.2 does not). Using gij or kaffe instead of the blackdown JVM to actually run the Java app stops the crash. I don't know whether the problem lies with g++-3.x or with the blackdown JVM. I cant see any libstdc++ clash happening; none of the blackdown packages depend on any libstdc++, nor do any of the libraries shipped with the blackdown JVM appear to link against any libstdc++. The hs_err file created by the JVM when it crashed is also attached, which includes a list of all shared libraries that are loaded. Only one version of libstdc++ appears. The problem can be replicated using the files below by running "make" and then "make runjava", assuming that /usr/bin/java and /usr/bin/javac point to the blackdown java and javac respectively. Any ideas on how this can be resolved are most welcome, short of (i) converting all dynamic_casts to static_casts, (ii) reverting to g++-2.95 or (iii) implementing the remainder of javax.swing in gij. Ben. :)
all: Test.class Test.h libTest.so Test.class: Test.java javac Test.java Test.h: Test.class gcjh -jni Test libTest.so: Test.h Test.cc g++-3.3 -shared \ -I/usr/lib/j2se/1.4/include -I/usr/lib/j2se/1.4/include/linux \ -o libTest.so Test.cc runjava: java -Djava.library.path=. Test rungij: gij-wrapper -Djava.library.path=. Test runkaffe: kaffe -Djava.library.path=.:/usr/lib/kaffe/jre/lib/i386 Test clean: rm -f libTest.so Test.h Test.class rm -f hs*.log
#include "Test.h" class A { public: virtual int getVal() { return 1; } A* wibble(); }; class B : public A { public: virtual int getVal() { return 2; } }; A* A::wibble() { return new B(); } JNIEXPORT jint JNICALL Java_Test_nativeTest (JNIEnv *env, jclass) { A* first = new A(); B* second = dynamic_cast<B*>(first->wibble()); return second->getVal(); }
class Test { public static void main(String[] args) { System.loadLibrary("Test"); System.out.println(nativeTest()); } private native static int nativeTest(); }
An unexpected exception has been detected in native code outside the VM. Unexpected Signal : 11 occurred at PC=0x81483AB Function=[Unknown.] 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 Test.nativeTest(Native Method) at Test.main(Test.java:5) Dynamic libraries: 08048000-0804d000 r-xp 00000000 03:03 298618 /usr/lib/j2se/1.4/bin/java 0804d000-0804e000 rw-p 00004000 03:03 298618 /usr/lib/j2se/1.4/bin/java 40000000-40011000 r-xp 00000000 03:03 163517 /lib/ld-2.3.1.so 40011000-40012000 rw-p 00011000 03:03 163517 /lib/ld-2.3.1.so 40012000-4001b000 r-xp 00000000 03:03 963226 /usr/lib/j2se/1.4/jre/lib/i386/native_threads/libhpi.so 4001b000-4001c000 ---p 00009000 03:03 963226 /usr/lib/j2se/1.4/jre/lib/i386/native_threads/libhpi.so 4001c000-4001d000 rw-p 00009000 03:03 963226 /usr/lib/j2se/1.4/jre/lib/i386/native_threads/libhpi.so 4001d000-40026000 r-xp 00000000 03:03 164279 /lib/libnss_compat-2.3.1.so 40026000-40027000 rw-p 00009000 03:03 164279 /lib/libnss_compat-2.3.1.so 40027000-4002a000 r--s 00000000 03:03 1029026 /usr/lib/j2se/1.4/jre/lib/ext/dnsns.jar 4002b000-40037000 r-xp 00000000 03:03 164377 /lib/libpthread-0.10.so 40037000-4003a000 rw-p 0000c000 03:03 164377 /lib/libpthread-0.10.so 4007a000-4007c000 r-xp 00000000 03:03 164163 /lib/libdl-2.3.1.so 4007c000-4007d000 rw-p 00001000 03:03 164163 /lib/libdl-2.3.1.so 4007d000-40185000 r-xp 00000000 03:03 164161 /lib/libc-2.3.1.so 40185000-4018b000 rw-p 00107000 03:03 164161 /lib/libc-2.3.1.so 4018d000-405f1000 r-xp 00000000 03:03 281638 /usr/lib/j2se/1.4/jre/lib/i386/client/libjvm.so 405f1000-4060e000 rw-p 00463000 03:03 281638 /usr/lib/j2se/1.4/jre/lib/i386/client/libjvm.so 4061e000-4062e000 r-xp 00000000 03:03 164165 /lib/libnsl-2.3.1.so 4062e000-4062f000 rw-p 00010000 03:03 164165 /lib/libnsl-2.3.1.so 40631000-40651000 r-xp 00000000 03:03 164164 /lib/libm-2.3.1.so 40651000-40652000 rw-p 0001f000 03:03 164164 /lib/libm-2.3.1.so 40652000-40661000 r-xp 00000000 03:03 963232 /usr/lib/j2se/1.4/jre/lib/i386/libverify.so 40661000-40663000 rw-p 0000e000 03:03 963232 /usr/lib/j2se/1.4/jre/lib/i386/libverify.so 40663000-40682000 r-xp 00000000 03:03 963233 /usr/lib/j2se/1.4/jre/lib/i386/libjava.so 40682000-40684000 rw-p 0001e000 03:03 963233 /usr/lib/j2se/1.4/jre/lib/i386/libjava.so 40684000-40699000 r-xp 00000000 03:03 963238 /usr/lib/j2se/1.4/jre/lib/i386/libzip.so 40699000-4069c000 rw-p 00014000 03:03 963238 /usr/lib/j2se/1.4/jre/lib/i386/libzip.so 4069c000-41d69000 r--s 00000000 03:03 968066 /usr/lib/j2se/1.4/jre/lib/rt.jar 41dac000-41dc3000 r--s 00000000 03:03 968059 /usr/lib/j2se/1.4/jre/lib/sunrsasign.jar 41dc3000-41e34000 r--s 00000000 03:03 968061 /usr/lib/j2se/1.4/jre/lib/jsse.jar 41e34000-41e47000 r--s 00000000 03:03 968060 /usr/lib/j2se/1.4/jre/lib/jce.jar 41e47000-42103000 r--s 00000000 03:03 968064 /usr/lib/j2se/1.4/jre/lib/charsets.jar 441ab000-441ac000 r-xp 00000000 03:03 1274482 /home/bab/source/debian/bugs/dynamic_cast/libTest.so 441ac000-441ad000 rw-p 00000000 03:03 1274482 /home/bab/source/debian/bugs/dynamic_cast/libTest.so 4c230000-4c24d000 r--s 00000000 03:03 1029025 /usr/lib/j2se/1.4/jre/lib/ext/sunjce_provider.jar 4c24d000-4c2ec000 r--s 00000000 03:03 1029027 /usr/lib/j2se/1.4/jre/lib/ext/localedata.jar 4c2ec000-4c2fa000 r--s 00000000 03:03 1029028 /usr/lib/j2se/1.4/jre/lib/ext/ldapsec.jar 4c312000-4c3a2000 r-xp 00000000 03:03 114822 /usr/lib/libstdc++.so.5.0.4 4c3a2000-4c3b9000 rw-p 0008f000 03:03 114822 /usr/lib/libstdc++.so.5.0.4 4c3be000-4c3c4000 r-xp 00000000 03:03 163284 /lib/libgcc_s.so.1 4c3c4000-4c3c5000 rw-p 00006000 03:03 163284 /lib/libgcc_s.so.1 Local Time = Wed Jun 11 19:31:51 2003 Elapsed Time = 0 # # The exception above was detected in native code outside the VM # # Java VM: Java HotSpot(TM) Client VM (Blackdown-1.4.1-beta mixed mode) #