Is JNI (Java Native Interface) Known to Work in Both Directions on FreeBSD (to invoke the JVM from native software)?

Rod funkyrod at gmail.com
Sun Mar 30 00:58:27 PDT 2008


Further to the below, here's some more output:

#
# An unexpected error has been detected by Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x28233838, pid=22317, tid=0x28b01100
#
# Java VM: Java HotSpot(TM) Client VM (
1.6.0_03-p3-root_16_feb_2008_09_59-b00 mixed mode)
# Problematic frame:
# V  [libjvm.so+0x1b6838]
#
# An error report file with more information is saved as hs_err_pid22317.log
#
# Please submit bug reports to freebsd-java at FreeBSD.org
#

Here's the log file:

#
# An unexpected error has been detected by Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x28233838, pid=22317, tid=0x28b01100
#
# Java VM: Java HotSpot(TM) Client VM (
1.6.0_03-p3-root_16_feb_2008_09_59-b00 mixed mode)
# Problematic frame:
# V  [libjvm.so+0x1b6838]
#
# Please submit bug reports to freebsd-java at FreeBSD.org
#

---------------  T H R E A D  ---------------

Current thread (0x28b22000):  JavaThread "main" [_thread_in_vm,
id=682627328]

siginfo:si_signo=11, si_errno=0, si_code=1, si_addr=0x00000000

Registers:
EAX=0x00000000, EBX=0x284492f8, ECX=0x28b1400c, EDX=0x28b22000
ESP=0xbfbfe7e0, EBP=0xbfbfe838, ESI=0xbfbfe7f4, EDI=0x28b22000
EIP=0x28233838, EFLAGS=0x00010282

Top of Stack: (sp=0xbfbfe7e0)
0xbfbfe7e0:   28b22000 28b22000 28b22000 2833605e
0xbfbfe7f0:   28b1400c 00000001 28b22000 284492f8
0xbfbfe800:   28b22000 28b220ec bfbfe848 2822a3dd
0xbfbfe810:   28b22000 28b14008 000004a4 28416fe8
0xbfbfe820:   0000000e 28b22000 00000000 00000001
0xbfbfe830:   bfbfe904 00000000 bfbfe868 08048a54
0xbfbfe840:   28b220ec 00000000 00000000 bfbfe87c
0xbfbfe850:   28b220ec 00000000 08048b19 08048b14

Instructions: (pc=0x28233838)
0x28233828:   02 00 00 8b 45 10 c7 45 e8 0e 00 00 00 8d 75 bc
0x28233838:   8b 10 8b 42 08 8b 52 0c 83 c2 1c 66 8b 40 26 51

Stack: [0xbfa00000,0xbfc00000),  sp=0xbfbfe7e0,  free space=2041k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native
code)
V  [libjvm.so+0x1b6838]
C  [test3+0xa54]
C  [test3+0x961]
C  [test3+0x689]


---------------  P R O C E S S  ---------------

Java Threads: ( => current thread )
  0x28beb800 JavaThread "Low Memory Detector" daemon [_thread_blocked,
id=682629632]
  0x28b28000 JavaThread "CompilerThread0" daemon [_thread_blocked,
id=682629376]
  0x28b27000 JavaThread "Signal Dispatcher" daemon [_thread_blocked,
id=682628608]
  0x28b25800 JavaThread "Finalizer" daemon [_thread_blocked, id=682629120]
  0x28b24800 JavaThread "Reference Handler" daemon [_thread_blocked,
id=682628864]
=>0x28b22000 JavaThread "main" [_thread_in_vm, id=682627328]

Other Threads:
  0x28b23800 VMThread [id=682628352]
  0x28bec800 WatcherThread [id=682629888]

VM state:not at safepoint (normal execution)

VM Mutex/Monitor currently owned by a thread: None

Heap
 def new generation   total 960K, used 158K [0x2ac80000, 0x2ad80000,
0x2b160000)
  eden space 896K,  17% used [0x2ac80000, 0x2aca7830, 0x2ad60000)
  from space 64K,   0% used [0x2ad60000, 0x2ad60000, 0x2ad70000)
  to   space 64K,   0% used [0x2ad70000, 0x2ad70000, 0x2ad80000)
 tenured generation   total 4096K, used 0K [0x2b160000, 0x2b560000,
0x2ec80000)
   the space 4096K,   0% used [0x2b160000, 0x2b160000, 0x2b160200,
0x2b560000)
 compacting perm gen  total 12288K, used 1459K [0x2ec80000, 0x2f880000,
0x32c80000)
   the space 12288K,  11% used [0x2ec80000, 0x2edecf10, 0x2eded000,
0x2f880000)
No shared spaces configured.

Dynamic libraries:
0x08048000     /mnt2/usr/home/rodney/cprog/test3/./src/test3
0x2807d000     /usr/local/jdk1.6.0/jre/lib/i386/client/libjvm.so
0x28862000     /lib/libthr.so.3
0x28875000     /usr/lib/libstdc++.so.6
0x2896a000     /lib/libm.so.5
0x2897f000     /lib/libgcc_s.so.1
0x2898a000     /lib/libc.so.7
0x28a90000     /usr/local/jdk1.6.0/jre/lib/i386/native_threads/libhpi.so
0x28aa2000     /usr/local/jdk1.6.0/jre/lib/i386/libverify.so
0x28aaf000     /usr/local/jdk1.6.0/jre/lib/i386/libjava.so
0x28ad6000     /usr/local/jdk1.6.0/jre/lib/i386/libzip.so
0x28adf000     /lib/libz.so.4
0x28049000     /libexec/ld-elf.so.1

VM Arguments:
java_command: <unknown>
Launcher Type: generic

Environment Variables:
PATH=/usr/local/gnu-autotools/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/local/sbin:/usr/local/bin:/root/bin
LD_LIBRARY_PATH=/usr/local/lib/R/lib:/usr/local/jdk1.6.0/lib:/usr/local/jdk1.6.0/jre/lib/i386:/usr/local/jdk1.6.0/jre/lib/i386/client:/usr/local/lib/R/library/rJava/libs:/usr/local/jdk1.6.0/jre/lib/i386/server
SHELL=/bin/csh
DISPLAY=:0
HOSTTYPE=FreeBSD
OSTYPE=FreeBSD
MACHTYPE=i386

Signal Handlers:
SIGSEGV: [libjvm.so+0x35e9c0], sa_mask[0]=0xfffefeff, sa_flags=0x00000042
SIGBUS: [libjvm.so+0x35e9c0], sa_mask[0]=0xfffefeff, sa_flags=0x00000042
SIGFPE: [libjvm.so+0x2a4bd0], sa_mask[0]=0xfffefeff, sa_flags=0x00000042
SIGPIPE: [libjvm.so+0x2a4bd0], sa_mask[0]=0xfffefeff, sa_flags=0x00000042
SIGILL: [libjvm.so+0x2a4bd0], sa_mask[0]=0xfffefeff, sa_flags=0x00000042
SIGUSR1: SIG_DFL, sa_mask[0]=0x00000000, sa_flags=0x00000000
SIGUSR2: [libjvm.so+0x2a6c10], sa_mask[0]=0x00000000, sa_flags=0x00000042
SIGHUP: [libjvm.so+0x2a5c70], sa_mask[0]=0xfffefeff, sa_flags=0x00000042
SIGINT: [libjvm.so+0x2a5c70], sa_mask[0]=0xfffefeff, sa_flags=0x00000042
SIGQUIT: [libjvm.so+0x2a5c70], sa_mask[0]=0xfffefeff, sa_flags=0x00000042
SIGTERM: [libjvm.so+0x2a5c70], sa_mask[0]=0xfffefeff, sa_flags=0x00000042
SIGUSR2: [libjvm.so+0x2a6c10], sa_mask[0]=0x00000000, sa_flags=0x00000042


---------------  S Y S T E M  ---------------

OS:Bsd
uname:FreeBSD 7.0-RELEASE FreeBSD 7.0-RELEASE #0: Sun Feb 24 19:59:52 UTC
2008     root at logan.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC i386
rlimit: STACK 65536k, CORE infinity, NPROC 5547, NOFILE 11095
CPU:total 1 (1 cores per cpu, 1 threads per core) family 6 model 13 stepping
6, cmov, cx8, fxsr, mmx, sse, sse2

Memory: 4k page, physical 764700k(191175k free)

vm_info: Java HotSpot(TM) Client VM (1.6.0_03-p3-root_16_feb_2008_09_59-b00)
for bsd-x86, built on Feb 16 2008 11:10:46 by "root" with gcc
4.2.120070719  [FreeBSD]


I'm going to try rebuilding jdk16 again.

On Sun, Mar 30, 2008 at 6:45 AM, Rodney Hoskinson <funkyrod at gmail.com>
wrote:

> Nick
>
> Thanks,
>
> I'm still having trouble trying to invoke the JVM from FreeBSD.
> I compiled and ran the simple C++ JNI invocation program below, linked
> against
> jdk1.6.0 on FreeBSD7.0-Release. (Tried linking against diablo-jdk1.5.0also -
> same result).
>
> I got the same result as trying to run rJava: Program received signal
> SIGSYS
> (Bad system call).
>
>
>
> or in gdb:
>
> # gdb ./a.out
> GNU gdb 6.1.1 [FreeBSD]
> Copyright 2004 Free Software Foundation, Inc.
> GDB is free software, covered by the GNU General Public License, and you
> are
> welcome to change it and/or distribute copies of it under certain
> conditions.
> Type "show copying" to see the conditions.
> There is absolutely no warranty for GDB.  Type "show warranty" for
> details.
> This GDB was configured as "i386-marcel-freebsd"...(no debugging symbols
> found)...
> (gdb) run
> Starting program: /usr/home/test3/src/a.out
> (no debugging symbols found)...(no debugging symbols found)...(no
> debugging
> symbols found)...(no debugging symbols found)...(no debugging symbols
> found)...(no debugging symbols found)...[New LWP 100131]
> (no debugging symbols found)...[New Thread 0x28b01100 (LWP 100131)]
> (no debugging symbols found)...(no debugging symbols found)...(no
> debugging
> symbols found)...(no debugging symbols found)...(no debugging symbols
> found)...[New Thread 0x28b01300 (LWP 100192)]
> [New Thread 0x28b01500 (LWP 100193)]
> [New Thread 0x28b01600 (LWP 100203)]
>
> Program received signal SIGSYS, Bad system call.
> [Switching to Thread 0x28b01100 (LWP 100131)]
> 0x289bb86b in ksem_init () from /lib/libc.so.7
> (gdb) bt
> #0  0x289bb86b in ksem_init () from /lib/libc.so.7
> #1  0x289b1229 in sem_init () from /lib/libc.so.7
> #2  0x28321e59 in os::signal_init_pd ()
> from /usr/local/jdk1.6.0/jre/lib/i386/client/libjvm.so
> #3  0x2831fb62 in os::signal_init ()
> from /usr/local/jdk1.6.0/jre/lib/i386/client/libjvm.so
> #4  0x283aa342 in Threads::create_vm ()
> from /usr/local/jdk1.6.0/jre/lib/i386/client/libjvm.so
> #5  0x2821b736 in JNI_CreateJavaVM ()
> from /usr/local/jdk1.6.0/jre/lib/i386/client/libjvm.so
> #6  0xbfbfe80b in ?? ()
> #7  0x00000000 in ?? ()
> #8  0x00000000 in ?? ()
> #9  0x00000000 in ?? ()
> #10 0xbfbfe868 in ?? ()
> #11 0xffffffff in ?? ()
> #12 0x28077000 in ?? ()
> #13 0x00000018 in ?? ()
> #14 0x28b0c000 in ?? ()
> #15 0x01bfe850 in ?? ()
> #16 0x00000001 in ?? ()
> #17 0xbfbfe8b0 in ?? ()
> #18 0x00000000 in ?? ()
> #19 0xbfbfe868 in ?? ()
> #20 0x080488ea in main ()
> (gdb)
>
>
> Invocation program,  built with compiler flags:
>
> -I/usr/local/jdk1.6.0/include -I/usr/local/jdk1.6.0/include/freebsd
> -L/usr/local/jdk1.6.0/jre/lib/i386/server -ljvm
>
> #ifdef HAVE_CONFIG_H
> #include <config.h>
> #endif
>
>
>
> using namespace std;
>
> #include <iostream>
> #include <cstdlib>
> #include <jni.h>    /* where everything is defined */
>
>
>
> int main(int argc, char *argv[])
> {
>
>    JavaVM *jvm;       /* denotes a Java VM */
>    JNIEnv *env;       /* pointer to native method interface */
>    JavaVMInitArgs vm_args; /* JDK/JRE 6 VM initialization arguments */
>    JavaVMOption* options = new JavaVMOption[1];
>    options[0].optionString = "-Djava.class.path=/usr/local/jdk1.6.0/java";
>    vm_args.version = JNI_VERSION_1_6;
>    vm_args.nOptions = 1;
>    vm_args.options = options;
>    vm_args.ignoreUnrecognized = false;
>    /* load and initialize a Java VM, return a JNI interface
>     * pointer in env */
>    JNI_CreateJavaVM(&jvm,(void **)&env, &vm_args);
>    delete options;
>    /* invoke the Main.test method using the JNI */
>    jclass cls = env->FindClass("Main");
>    jmethodID mid = env->GetStaticMethodID(cls, "test", "(I)V");
>    env->CallStaticVoidMethod(cls, mid, 100);
>    /* We are done. */
>    jvm->DestroyJavaVM();
>
>  return EXIT_SUCCESS;
> }
>
> I'm stumped as to why JNI invocation appears not to work for me on
> FreeBSD.
>
> On Sunday 30 March 2008 01:53:52 Nick Johnson wrote:
> > Yeah, it works.  Take a look at jsvc that ships with Tomcat 6.  It binds
> > to a port, drops root permission and creates a JVM and does back and
> forth
> > communication with Tomcat.
> >
> >    Nick
> >
> > On Sat, 29 Mar 2008, Rod wrote:
> > > I'm having trouble using JNI software on FreeBSD.
> > > In summary:
> > > - I'm able to call native routines from a Java VM via JNI
> > > - However in the other direction JNI seems not to work. I can't create
> a
> > > JVM via JNI from native software.
> > > Admittedly, I'm using one specific software (R with rJava) and haven't
> > > tried running my own JNI software.
> > >
> > > What I'm noticing is that a call to JNI_CreateJavaVM () in
> > > /usr/local/jdk1.6.0/jre/lib/i386/client/libjvm.so results in SIGSYS,
> Bad
> > > Sytem Call.
> > >
> > > Here's my output from running R with rJava under gdb with a stack
> > > backtrace. It all seems to go pear-shaped at JNI_CreateJavaVM () :
>
>
>


More information about the freebsd-java mailing list