From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5299 invoked by alias); 6 Jun 2008 21:18:54 -0000 Received: (qmail 5286 invoked by uid 22791); 6 Jun 2008 21:18:53 -0000 X-Spam-Status: No, hits=-2.2 required=5.0 tests=AWL,BAYES_00,J_CHICKENPOX_93,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (66.187.233.31) by sourceware.org (qpsmtpd/0.31) with ESMTP; Fri, 06 Jun 2008 21:18:36 +0000 Received: from int-mx1.corp.redhat.com (int-mx1.corp.redhat.com [172.16.52.254]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id m56LIXt7026001 for ; Fri, 6 Jun 2008 17:18:34 -0400 Received: from pobox.corp.redhat.com (pobox.corp.redhat.com [10.11.255.20]) by int-mx1.corp.redhat.com (8.13.1/8.13.1) with ESMTP id m56LIXrw000720 for ; Fri, 6 Jun 2008 17:18:33 -0400 Received: from [127.0.0.1] (sebastian-int.corp.redhat.com [172.16.52.221]) by pobox.corp.redhat.com (8.13.1/8.13.1) with ESMTP id m56LIVEC025083 for ; Fri, 6 Jun 2008 17:18:33 -0400 Message-ID: <4849A97A.1050301@redhat.com> Date: Mon, 09 Jun 2008 15:00:00 -0000 From: Andrew Cagney User-Agent: Thunderbird 2.0.0.14 (X11/20080501) MIME-Version: 1.0 To: frysk Subject: jnixx - making jni smell more like cni Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.58 on 172.16.52.254 X-IsSubscribed: yes Mailing-List: contact frysk-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: frysk-owner@sourceware.org X-SW-Source: 2008-q2/txt/msg00086.txt.bz2 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