Subject: | Error detected by enabling additional checks for JNI functions in the JVM |
Date: | Fri, 11 Jan 2013 22:40:46 -0500 |
To: | bug-Inline-Java [...] rt.cpan.org |
From: | Max Vohlken <mvohlken [...] us.ibm.com> |
In trying to debug a crash when using the JNI JVM on Solaris sparc with
Inline-Java-0.53 I enabled this feature in the JVM
-Xcheck:jni perform additional checks for JNI functions
by setting this environment variable:
PERL_INLINE_JAVA_EXTRA_JAVA_ARGS=-Xcheck:jni
When running the first test t/01_init.t the JVM complains:
FATAL ERROR in native method: JNI string operation received a non-string
Abort (core dumped)
The core dump has this stack trace:
=>[1] __lwp_kill(0x0, 0x6, 0x0, 0xfefbc000, 0x2, 0x1), at 0xfef9fc54
[2] raise(0x6, 0x0, 0xffbfe418, 0xfea9f838, 0x11838, 0x11800), at
0xfef50c48
[3] abort(0x1f5fc8, 0xfeab6d74, 0x1000, 0xfea8e000, 0x30ac4, 0x30800), at
0xfef36d50
[4] os::abort(0x1, 0xfea8ec6c, 0x1, 0xfea8e000, 0xc6c, 0xc00), at
0xfe8c9cd4
[5] checked_jni_ReleaseStringUTFChars(0x64dd28, 0x6698ac, 0x7d857c,
0x64dc00, 0xfeaa4d4c, 0xfea8e000), at 0xfe7a4708
[6] XS_Inline__Java__JNI_process_command(0x24404, 0xfeaa4d50, 0x413618,
0xfeaa4d50, 0x40c90, 0x6698ac), at 0xfeb730c4
[7] Perl_pp_entersub(0x40c90, 0x60e94, 0x4bda54, 0x664910, 0xff355218,
0x0), at 0xff267774
[8] Perl_runops_standard(0x40c90, 0xffffffff, 0x19d700, 0xff266a30,
0xff25df50, 0x710c0), at 0xff25dea8
[9] Perl_call_sv(0x40c90, 0x41, 0xff355218, 0xffbfe6f4, 0x40c90,
0x48c7c), at 0xff1cab4c
[10] Perl_call_list(0x0, 0x40c90, 0x48c7c, 0x40c90, 0x5, 0xff355218), at
0xff1cf9d4
[11] S_run_body(0x40c90, 0x1, 0xff1c9750, 0x0, 0x410e0, 0x0), at
0xff1c9c98
[12] perl_run(0x40c90, 0x40e80, 0xff355218, 0x1, 0x3d, 0x40c90), at
0xff1c997c
[13] main(0x20, 0xffbfeabc, 0x213c0, 0x0, 0x0, 0x210c8), at 0x10dbc
I traced this issue to the following lines in the function process_command
() in JNI.xs
(*(env))->DeleteLocalRef(env, resp) ;
(*(env))->ReleaseStringUTFChars(env, resp, RETVAL) ;
These lines need to be swapped as follows:
(*(env))->ReleaseStringUTFChars(env, resp, RETVAL) ;
(*(env))->DeleteLocalRef(env, resp) ;
I think this makes sense. The string should be released before we say we
are done with it.
Max Vohlken
IBM
Rational Software Division
Advisory Software Engineer
550 King St.
Littleton, MA 01460
Email: mvohlken@us.ibm.com
Phone: 978-899-4720