<< Dan Troesser: JSF and ASP.NET Side By Side | Home | XML Has Totally Failed ... On The Web >>

JNI, Systen.unloadLibrary(), @Native(dll=foo, function=bar), ...

Dear Java people,

I understand that everybody is busy right now with new and exciting Java language features like closures and continuations and module systems and that Sun people are also busy with Open Sourcing pieces of (but not the whole) Java SE and ME before year's end and I'm really happy about all these developments.

But before you go off to the deep end and spend years debating, reviewing, testing, and releasing all these wonderful features, which I'm sure will draw more developers to the Java platform, could somebody please take a few minutes and take a look at my modest Java feature requests:

It has to do with JNI, the most elaborate and comprehensive native code interface I've ever seen in popular programming languages. It gets the job done (if you have the resources) but it's a pain to program with. And it is sometimes considered a performance bottleneck, what with all the locking and copying when a variable crosses the JNI boundary.

The first thing that I would like to have is a System.unloadLibrary() call to balance out the System.loadLibrary() call that has been present in the Java language from the beginning. This would make writing unloadable plug-ins that uses native code easier.

The second thing I would like to have is a @Native annotation that would direct the runtime system to generate JNI wrappers automatically. Come to think about it, had annotations been available in the Java language from the beginning, there probably wouldn't be a native keyword at all. The more I think about it, the more I think something like the following would make sense:

@Native(dll=foo,function=bar)
public void bar();

The C/C++ stuff that people write after doing javah are boring, repetitive, tricky, and hard to get right. If the Java runtime can automatically generate the stuff from the annotation, that would bring about a productivity boost to the entire Java scene. Not only don't Java people have to write tedious code just to use native library functionality, they also don't have reinvent the wheel in Java because using a wheel written in C/C++ is so hard.

Talking about using natively available features, what's up with the HTML widget in the JDK. The last time I checked, it's HTML 3.2 and could not render even Yahoo.com right. Can we remove it from the JDK and bring in a native widget that uses the latest natively available HTML widget on the platform?

Tags :


Re: JNI, Systen.unloadLibrary(), @Native(dll=foo, function=bar), ...

MS did just this and some more in its VM some ten years ago. That was the main reason why Sun revoked the Java licence from MS bacuse it would make a java program non-portable across different os platforms. :| I know. Even without this feature it's not very portable at all. Just check out what J2ME developers think of portability.

Re: JNI, Systen.unloadLibrary(), @Native(dll=foo, function=bar), ...

J/Invoke - http://www.jinvoke.com - is a product that also lets you do exactly what you wanted, perhaps even simpler! It makes calling functions from a native DLL as easy as P/Invoke does for .NET. Java developers can simply annotate a native method with the DLL and function name and J/Invoke manages the task of loading the specified DLL, automatically converting Java arguments to C arguments and invoking the target function in the DLL.

Add a comment Send a TrackBack