From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24222 invoked by alias); 14 Feb 2012 11:44:49 -0000 Received: (qmail 24214 invoked by uid 22791); 14 Feb 2012 11:44:49 -0000 X-SWARE-Spam-Status: No, hits=-2.0 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,TW_GC,TW_LG X-Spam-Check-By: sourceware.org Received: from mail-yx0-f175.google.com (HELO mail-yx0-f175.google.com) (209.85.213.175) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 14 Feb 2012 11:44:32 +0000 Received: by yenr5 with SMTP id r5so2967888yen.20 for ; Tue, 14 Feb 2012 03:44:32 -0800 (PST) MIME-Version: 1.0 Received: by 10.50.196.228 with SMTP id ip4mr33296405igc.28.1329219871928; Tue, 14 Feb 2012 03:44:31 -0800 (PST) Received: by 10.50.114.38 with HTTP; Tue, 14 Feb 2012 03:44:31 -0800 (PST) In-Reply-To: <4F3A44DB.4070605@gmail.com> References: <4F387D25.40406@gmail.com> <1586090240029193189@unknownmsgid> <4F389217.7040506@gmail.com> <4F395754.3070407@gmail.com> <4F3A2DC7.3000502@redhat.com> <4F3A44DB.4070605@gmail.com> Date: Tue, 14 Feb 2012 11:44:00 -0000 Message-ID: Subject: Re: Interface gcj-compiled library with Java programs in a runtime (other than gij)? From: Bryce McKinlay To: Yi Lin Cc: java@gcc.gnu.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable 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/msg00015.txt.bz2 On Tue, Feb 14, 2012 at 11:26 AM, Yi Lin wrote: > > Thank you all for the answers. I think I have some clue about CNI/JNI on = the interface. > > But I still have doubt about how a shared library compiled from Java can = be used by a) c/c++, b) Java code running on other JVM (not libgcj interpre= ter). I think b) is straightforwad if a) is possible. > > So for a), is calling a shared library of compiled java code any differen= t than calling a shared library from normal c/c++ code? I have been spendin= g two days exploring this and trying different approaches. My expectation i= s to load the compiled Java lib and use its method via dlopen, dlsym, etc. = I guess another possibility is to use JvCreateVM(), and do everything in Ja= va fashion. I don't have any success in either yet. Any hint would be very = helpful so I could stop wasting time on a wrong track. a) is certainly possible, using either JNI or CNI. Whichever one you use, you need to call a couple of functions to initialize the Java VM before you start calling your Java classes.=A0You just need to make sure libgcj gets loaded somehow, either using -lgcj or dlopen. See here for a CNI example: http://gcc.gnu.org/onlinedocs/gcj/Invocation.html#Invocation b) "Should" work, but maybe you'd get conflicts with things like signal handlers since you effectively have 2 Java runtimes running in the same process.