Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 29 Mar 2008 06:36:11 +0000
From:      Rod <funkyrod@gmail.com>
To:        freebsd-java@freebsd.org.
Subject:   Is JNI (Java Native Interface) Known to Work in Both Directions on FreeBSD (to invoke the JVM from native software)?
Message-ID:  <dbe5b4eb0803282336p5143c5a3ub15113eaef799668@mail.gmail.com>

next in thread | raw e-mail | index | archive | help
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 () :


# R -d gdb
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/local/lib/R/bin/exec/R

R version 2.6.0 (2007-10-03)
Copyright (C) 2007 The R Foundation for Statistical Computing
ISBN 3-900051-07-0

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(rJava)
[New LWP 100145]
[New Thread 0x28909300 (LWP 100145)]
> .jinit() ######(calls code to invoke the JVM)
[New Thread 0x28909200 (LWP 100169)]
[New Thread 0x28909500 (LWP 100170)]
[New Thread 0x28909600 (LWP 100171)]

Program received signal SIGSYS, Bad system call.
[Switching to Thread 0x28909300 (LWP 100145)]
0x2830a86b in ksem_init () from /lib/libc.so.7
(gdb) bt
#0  0x2830a86b in ksem_init () from /lib/libc.so.7
#1  0x28300229 in sem_init () from /lib/libc.so.7
#2  0x29ab0e59 in os::signal_init_pd ()
   from /usr/local/jdk1.6.0/jre/lib/i386/client/libjvm.so
#3  0x29aaeb62 in os::signal_init ()
   from /usr/local/jdk1.6.0/jre/lib/i386/client/libjvm.so
#4  0x29b39342 in Threads::create_vm ()
   from /usr/local/jdk1.6.0/jre/lib/i386/client/libjvm.so
#5  0x299aa736 in JNI_CreateJavaVM ()
   from /usr/local/jdk1.6.0/jre/lib/i386/client/libjvm.so
#6  0xbfbfd66b in ?? ()
#7  0x00000000 in ?? ()
#8  0x00000000 in ?? ()
#9  0xbfbfd584 in ?? ()
#10 0x00000009 in ?? ()
#11 0xffffffff in ?? ()
#12 0x299a91cf in JNI_GetDefaultJavaVMInitArgs ()
   from /usr/local/jdk1.6.0/jre/lib/i386/client/libjvm.so
Previous frame inner to this frame (corrupt stack?)
(gdb)

I'm running this under a clean install of 7-Release I386:

# uname -a
FreeBSD  7.0-RELEASE FreeBSD 7.0-RELEASE #0: Sun Feb 24 19:59:52 UTC
2008     root@logan.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC  i386

I was getting the same result on my existing installation, so in case it was
some mix-up with libraries I tried new installations of 7-Release and also
PCBSD-1.5 (based on 6.3), both with the same result.

I've tried Java 1.6 built from ports (usr/ports/java/jdk16)

# java -version
java version "1.6.0_03-p3"
Java(TM) SE Runtime Environment (build
1.6.0_03-p3-root_16_feb_2008_09_59-b00)
Java HotSpot(TM) Client VM (build 1.6.0_03-p3-root_16_feb_2008_09_59-b00,
mixed mode)


I've also tried Diablo-Java1.5 as follows, with exactly the same result as
above.

# java -version
java version "1.5.0"
Java(TM) 2 Runtime Environment, Standard Edition (build diablo-1.5.0-b01)
Java HotSpot(TM) Client VM (build diablo-1.5.0_07-b01, mixed mode)

Both jdk1.5 and jdk1.6 gave exactly the same result.

I'm going to check with the rJava developers to see if they can assist, but
I thought I'd check on this list if there are any known special issues to
get JNI working fully under FreeBSD (specifically to create a JVM and use
Java objects from native software), or if it is known not to work?

Thanks for any help

Rod.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?dbe5b4eb0803282336p5143c5a3ub15113eaef799668>