Access:

» NoodleGlue - Simplifying JNI Code Generation

Related categories: Java | C/C++

Tree
Viewed: 13417 | Article date: 2005-12-13 15:21:08

NoodleGlue is a set of tools, which generates JNI code from a simple script and the C/C++ header files, and includes a library to manage the code at runtime. It was written in various stages with the aim to not only simplify the problems related to large JNI code projects, but also to manage the somewhat incompatible memory-management models of unmanaged C/C++ code and Java’s garbage collection mechanism. It is not perfect, but right now NoodleGlue can handle most features of C and C++ and, when using NoodleGlue-generated libraries, programmers should find it as easy to use their library in Java as they do in C or C++. Even better, NoodleGlue has now been open-sourced for everyone to use for free!
About the Autor

Tree is lead programmer at Noodleheaven and works on several disparate projects from Noodle, an interactive music player to server software to drive giant display technology.

To contact the author: tree@noodleheaven.net

JNI is the natural way to support native C or C++ library code in Java. However, writing the JNI interface for each function or class method can be extremely tedious and prone to error. When the underlying library is changing this can be even worse, as the need to edit the JNI code can turn into a full time job on a large project!

NoodleGlue is a set of tools, which generates JNI code from a simple script and the C/C++ header files, and includes a library to manage the code at runtime. It was written in various stages with the aim to not only simplify the problems related to large JNI code projects, but also to manage the somewhat incompatible memory-management models of unmanaged C/C++ code and Java's garbage collection mechanism. It is not perfect, but right now NoodleGlue can handle most features of C and C++ and, when using NoodleGlue-generated libraries, programmers should find it as easy to use their library in Java as they do in C or C++. Even better, NoodleGlue has now been open-sourced for everyone to use for free!

A reference-counting strategy can help

NoodleGlue works at runtime by having native and Java peer class objects. They are bound together by one of the key design features for Noodleglue: a simple reference management system. It is certainly not rocket science, but configuring NoodleGlue to require as little developer involvement as possible has not been easy. Java, with its lovely memory manager and C/C++, with their manual new/delete pattern, do not fit together too well. Some native libraries (our own internal ones included) use a memory management strategy using smart pointers. They use reference-counting to ensure objects are deleted without leaving pointers to non-existent objects when used properly. NoodleGlue runtime uses reference-counting to manage - as much as possible - the object management between C++ and Java peer objects. What all this means is that when a native object's reference count drops to 0, it will not be deleted straight away, but waits until the Java peer is garbage-collected. This works in reverse too: a Java object will not be garbage-collected until the native object no longer needs it to exist.

This does not mean that your library has to support smart pointers; however, you will miss out on a couple of really cool features like sub-classing native classes directly in Java, where overloaded methods are called from C++.

Page: 1 2 3 4
Buy article Buy subscription
Buy now add to cart
add to cart
Standard price: 2€/$3 Standard price: 25€/$30
Buy article for as little as (2€/$3) each allow access to individual articles. Buy a full access to our Software Developers's Journal archive portal. You will be able to read the articles from all archive issues from year 2005 and 2006. For just 25€/$30 you get unrestricted access to the entire website for the whole year.
SDJhakin9

.SDJ Users:


.:Login
.:Password

[Register]
[Forgotten your password?]

...Shopping Cart

sum: 0 €
Choose currency:

...Topics

...Advertisement

www.acunetix.com www.verifysoft.com

...Conferences




...Print Edition Archive

...Affiliate Program



 

 

Subscribe | Contact Us | Newsletter | Privacy policy | Regulations | See all issues | About SDJ
Copyright C 2006 by Software Developer's Journal. All rights reserved.