From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26908 invoked by alias); 13 Feb 2012 18:33:10 -0000 Received: (qmail 26898 invoked by uid 22791); 13 Feb 2012 18:33:08 -0000 X-SWARE-Spam-Status: No, hits=-2.1 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,TW_GC X-Spam-Check-By: sourceware.org Received: from mail-gx0-f175.google.com (HELO mail-gx0-f175.google.com) (209.85.161.175) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 13 Feb 2012 18:32:55 +0000 Received: by ggeq1 with SMTP id q1so2634314gge.20 for ; Mon, 13 Feb 2012 10:32:54 -0800 (PST) Received: by 10.101.143.14 with SMTP id v14mr6904856ann.1.1329157974830; Mon, 13 Feb 2012 10:32:54 -0800 (PST) Received: from dd1.caveonetworks.com (64.2.3.195.ptr.us.xo.net. [64.2.3.195]) by mx.google.com with ESMTPS id y12sm38050965ang.21.2012.02.13.10.32.53 (version=SSLv3 cipher=OTHER); Mon, 13 Feb 2012 10:32:53 -0800 (PST) Message-ID: <4F395754.3070407@gmail.com> Date: Mon, 13 Feb 2012 18:33:00 -0000 From: David Daney User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.15) Gecko/20101027 Fedora/3.0.10-1.fc12 Thunderbird/3.0.10 MIME-Version: 1.0 To: Yi Lin CC: Brian Jones , java@gcc.gnu.org Subject: Re: Interface gcj-compiled library with Java programs in a runtime (other than gij)? References: <4F387D25.40406@gmail.com> <1586090240029193189@unknownmsgid> <4F389217.7040506@gmail.com> In-Reply-To: <4F389217.7040506@gmail.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Mailing-List: contact java-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: java-owner@gcc.gnu.org X-SW-Source: 2012-02/txt/msg00011.txt.bz2 On 02/12/2012 08:31 PM, Yi Lin wrote: > Thank you. I think I may have missed a keyword here: CNI. I avoid using > JNI for performance degradation. > > The detailed scenario is like: > There are two parts of code. > > -SomeJavaCode.java: containing a method call to NativeJavaLib.a(). > This part of code remains in bytecode So really what you are talking about is SomeJavaCode.class running the the libgcj interpreter. I am just going from memory here, but I think that the interpreter can only call native code via JNI. For compiled code, CNI may be faster. So... > > -NativeJavaLib.java: declaring 'native void a()' ... rename this bit like this: private native void _a(); /* 'Trampoline' to native code. */ void a() { _a(); } > -NativeJavaLib.cpp: implementing a() via CNI In here rename a() to _a(). > This part is compiled to libJavaLib.so > Now you have not changed SomeJavaCode.java in any way, but it is instead calling a normal java method in the NativeJavaLib.java, which takes care of doing the proper CNI calling. > Now SomeJavaCode can be executed correctly with 'gij' interpreter; I > think there is no JNI involved. But it cannot run on HotSpot or other > VM. If I have to use JNI to do this, then the approach is much less > attractive. > > Thanks, > Yi > > On 13/02/12 15:00 , Brian Jones wrote: >> I suggest you try jni to get to whatever native code you are >> interested in. >> >> Brian >> >> On Feb 12, 2012, at 10:01 PM, Yi Lin wrote: >> >>> Hi, >>> >>> I am wondering if we can use methods from a gcj-compiled library in >>> uncompiled Java program(bytecode) executed on a VM. >>> >>> According to gcj FAQ 1.7, there is no problem to do this with 'gij' >>> interpreter/runtime. You can compile some Java code into library >>> (native code), and run bytecode with 'gij' to invoke library methods. >>> But this seems only capable for 'gij', and other runtimes like >>> HotSpot cannot load and link the library properly. >>> >>> I want to know if there is a general solution to allow you interface >>> uncompiled Java program with gcj-compiled library. Any information or >>> reference about this will be appreciated. >>> >>> Many Thanks, >>> Yi > >