public inbox for
 help / color / mirror / Atom feed
From: Andrew Cagney <>
To: frysk <>
Subject: jnixx - making jni smell more like cni
Date: Mon, 09 Jun 2008 15:00:00 -0000	[thread overview]
Message-ID: <> (raw)


As part of translating frysk's CNI bindings to JNI, I mocked up a JNI 
bindings generator to simplify the process.  Among its features are:

-- generation of name spaces and a class inheritance structure that 
reflects the java code:
For instance, the lib.dwfl.ElfException class is generated as:
    class lib::dwfl::ElfException : public java::lang::RuntimeException

-- lets you directly invoke methods (wrappers take care of the JNI)
For instance, a static method in LocalMemory can be invoked with:
    java::lang::String s = frysk::testbed::LocalMemory::getModuleName(env)
(yes you still need to pass an env variable round)

-- provides get/set methods for class fields
For instance, given the class variable:
    jint intVar;
a method can read/modify/write it using:
    SetIntVar(env, GetIntVar(env) + 1);

-- lets you use a more natural throw/catch style for handling exceptions
For instance, a try/finally can be implemented using:
    try {
    catch (java::lang::Throwable e) {
        do cleanup stuff;
        throw e;
(rather than the traditional JNI style of trying to remember to check 
return values for failure)

-- provides wrappers to manage references to array and string elements
For instance, to get at and print a java string as a unix string:
    jstringUTFChars string = jstringUTFChars(env, javaString);
    fprintf(stderr, "string = %s\n", string.elements());

While there are still a few warts and I'd not consider the interfaces 
100% pinned down, the basic framework is working very well.  The curious 
are more than welcome to have a play.  Ideas, suggestions, questions, 
and code are all most welcome.


                 reply	other threads:[~2008-06-06 21:18 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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:

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

  git send-email \ \ \ \

* 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).