public inbox for java@gcc.gnu.org
 help / color / mirror / Atom feed
From: David Daney <ddaney.cavm@gmail.com>
To: Yi Lin <qinsoon@gmail.com>
Cc: Brian Jones <cbjones1@gmail.com>, java@gcc.gnu.org
Subject: Re: Interface gcj-compiled library with Java programs in a runtime (other than gij)?
Date: Mon, 13 Feb 2012 18:33:00 -0000	[thread overview]
Message-ID: <4F395754.3070407@gmail.com> (raw)
In-Reply-To: <4F389217.7040506@gmail.com>

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<qinsoon@gmail.com> 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
>
>

  reply	other threads:[~2012-02-13 18:33 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-13  3:01 Yi Lin
2012-02-13  4:01 ` Brian Jones
2012-02-13  4:30   ` Yi Lin
2012-02-13 18:33     ` David Daney [this message]
2012-02-14  9:48       ` Andrew Haley
2012-02-14 10:31         ` Bryce McKinlay
2012-02-14 11:26           ` Yi Lin
2012-02-14 11:44             ` Bryce McKinlay

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4F395754.3070407@gmail.com \
    --to=ddaney.cavm@gmail.com \
    --cc=cbjones1@gmail.com \
    --cc=java@gcc.gnu.org \
    --cc=qinsoon@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).