This is the mail archive of the
frysk@sourceware.org
mailing list for the frysk project.
jnixx - making jni smell more like cni
- From: Andrew Cagney <cagney at redhat dot com>
- To: frysk <frysk at sources dot redhat dot com>
- Date: Fri, 06 Jun 2008 17:17:46 -0400
- Subject: jnixx - making jni smell more like cni
Hi,
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 {
callJavaMethodFoo();
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.
Andrew