From owner-freebsd-java@FreeBSD.ORG Sun Mar 30 07:13:10 2008 Return-Path: Delivered-To: freebsd-java@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id BC8541065675 for ; Sun, 30 Mar 2008 07:13:10 +0000 (UTC) (envelope-from funkyrod@gmail.com) Received: from wa-out-1112.google.com (wa-out-1112.google.com [209.85.146.180]) by mx1.freebsd.org (Postfix) with ESMTP id 9421C8FC17 for ; Sun, 30 Mar 2008 07:13:10 +0000 (UTC) (envelope-from funkyrod@gmail.com) Received: by wa-out-1112.google.com with SMTP id k17so1256950waf.3 for ; Sun, 30 Mar 2008 00:13:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:to:subject:date:user-agent:references:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:message-id:from; bh=2T6nBRdvZ5wkYiiBikF0MGdwFuaszeO6Y3ERYcndiek=; b=klvHJ1v1qDqOkShAUH9i/QqthK1rF9QU2hKo+zsO/4INQmt6LvFLLmx5rETfiHCwzpzkGLCmCfBWwzxjuYQyMPU4D4grrtEQbNotNn8HoLZ4DVsrbGzejcyvU3MjgjpwiYEesROnLh7FbuL/gRNsJGd4fOoyA7M7xJJdU0ltgc4= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=to:subject:date:user-agent:references:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:message-id:from; b=drKFcIqQ0HLPQFuyCX7DYbuczByjlKF9MCsYsTT4Oy5IdFyoA6Sqb+R0T0y+Ng8l46VZ7bOq3MsyVdQjoCfGrUaNahoZQWtIJaFWX/S+Cva7qEpjPRrJ5qkHNMrPtVp2Wkr/FL0eYb+nhkAm7xBX4xEA4Ym5m0KT4iEoXZiIYZc= Received: by 10.114.200.2 with SMTP id x2mr7315131waf.143.1206859540596; Sat, 29 Mar 2008 23:45:40 -0700 (PDT) Received: from ?192.168.2.23? ( [121.218.97.236]) by mx.google.com with ESMTPS id m6sm1984614wag.11.2008.03.29.23.45.37 (version=SSLv3 cipher=OTHER); Sat, 29 Mar 2008 23:45:39 -0700 (PDT) To: freebsd-java@freebsd.org Date: Sun, 30 Mar 2008 17:45:32 +1100 User-Agent: KMail/1.9.7 References: <20080329075205.A2617@turing> In-Reply-To: <20080329075205.A2617@turing> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200803301745.32739.rodneyh@bigpond.net.au> From: Rodney Hoskinson Subject: Re: Is JNI (Java Native Interface) Known to Work in Both Directions on FreeBSD (to invoke the JVM from native software)? X-BeenThere: freebsd-java@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Porting Java to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 30 Mar 2008 07:13:10 -0000 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 #endif using namespace std; #include #include #include /* 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 () :