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

Rodney Hoskinson funkyrod at gmail.com
Sun Mar 30 00:13:10 PDT 2008


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.0 also - 
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