JNIWrapper Now on Mac OS X 64-bit

  • submit to reddit

JNIWrapper - Use Native Code from Java without JNI. Now on Mac, too.

JNIWrapper provides simplified access to native code from Java applications without using Java Native Interface (JNI). You write your code in the Java language only, and JNIWrapper does the rest.

The list of hardware platforms supported is growing constantly. This time we've added the support for Mac OS X 64-bit on Intel platform.

This new version also resolves issues reported to our support center. Please see the list of changes on the What's New page.

As always, you can download fully-functional version of JNIWrapper for Mac OS X and try it before buying. Your feedback and ideas about improvement of product are very much appreciated.

0
Average: 5 (1 vote)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Comments

Mike P(Okidoky) replied on Wed, 2008/10/29 - 10:39am

Question: can you pass Java memory to a native library without the memory copied to and from the native code, and instead use the "pinning" feature? That way it could make sense to write high performance large volume array calculations in native code. With JNI you can do that. The memory is "pinned" for the duration of the call. I've looked at JNA quite a while ago, and found that pinning wasn't an option. Does JNIWrapper let you do this?

Jose Maria Arranz replied on Thu, 2008/10/30 - 6:17am

Mike, an alternative is using a native array and access this native array with a memory buffer in Java, of course this array is not a normal Java array but it works for your problem.

Do you really need a normal Java array?

 

Mike P(Okidoky) replied on Thu, 2008/10/30 - 3:12pm in response to: jmarranz

Hi Jose, how about native image processing on BufferedImages. Some of them part of an off screen cache. The kind of magic I can pull off using beautiful raw machine code, I can't in Java. Allocating native memory for these things might create a massive memory management problem. I found pinning worked perfectly in pure JNI, without any noticable performance penalty. Copying memory for every call, would make the machine code writing efforts much less attractive.

Jose Maria Arranz replied on Fri, 2008/10/31 - 3:26am in response to: okidoky

I think your suggest is interesting, JNIWrapper and my own JNIEasy could add this feature with no much problem, isn't it Igor? :)

Contact with me if you want.

 

Igor Shvydkoy replied on Fri, 2008/10/31 - 12:33pm

Currently JNIWrapper doesn't have “Pinning” feature. The main reason why it is not supported now is that such feature has quite restricted usage. 'Pinning' feature is useful when you need to pass a large amount of memory from Java to native side without copying it. And actually "pinning" is just a new word for passing the data to a function call via pointer.

The main drawback there is that it is useful only if memory structures on Java and native sides are equal. For example, it is useful when you are passing an array of bytes, shorts, ints or longs. Unlike .NET, Java does not allow combining primitive types into the complex structures, because Java does not have an analogue of .NET's 'structure' keyword. So, if your Java arrays contains structures instead of primitive types then you will have to copy data from Java to native memory anyway.

On the other side, for now we do not have any requests for increasing the performance of JNIWrapper in terms of passing large amount of memory into a native side and back. Moreover, the performance of working with native API is very fast. For example, our JxCapture API performes creating of screenshots as fast as a C application, which is even faster than Robot API. And all that is made using just regular function calls.

If your application has a performance bottleneck in this action, we of course can look at how we can help you from our side, and possibly add pinning feature into JNIWrapper.

Edwin Babadaglian replied on Sat, 2008/11/01 - 1:42am

Does this posting relate to Mike's inquiry?

http://support.teamdev.com/message/4380#4380

 

Jose Maria Arranz replied on Sat, 2008/11/01 - 6:38am

No.

Mike wants to work with the same piece of "real" memory in Java and in native, the critical section feature of JNI allows to access the native memory *behind* the Java memory (in this case a primitive array), this way there is no copy between Java memory and native memory. If you work ever with native memory there is no problem, this memory can be accesed from Java using a buffer (a Java-native wrapper), one single piece of memory is used. Mike's problem is Mike wants one single piece of memory managed as a normal Java data byte array. Isn't it Mike?

 

Edwin Babadaglian replied on Sun, 2008/11/02 - 4:04pm in response to: jmarranz

This is what I understood as well.

A suggestion that appears near the bottom of the posting is for an API call such as "MemoryBuffer.wrap(java.nio.ByteBuffer)" where the ByteBuffer instance is of direct type. On the surface, this appears to enable sharing memory between Java and native code boundaries without the need for making a copy. If making a transition to using byte buffers instead of arrays is possible, would this work?

Thanks for your reply.

 

Mike P(Okidoky) replied on Sun, 2008/11/02 - 5:36pm in response to: eb37409

But then you have to allocate memory in Java in a special way, with nio buffers.

Ordinary BufferedImages are allocated the normal way, and the native code needs to have access to that to play with pixels...

 

Edwin Babadaglian replied on Mon, 2008/11/03 - 10:08pm in response to: okidoky

Sadly true, BufferedImage and ByteBuffer don't cross paths so this won't work. I develop file-management applications and utilize JNIWrapper to invoke Win32 functions to perform file access and transfer operations. I too have to perform byte-array copies between Java and Win32 functions when transferring file content.

So for cases where avoiding byte-arrays is possible, can JNIWrapper expand to interface with direct byte-buffers to eliminate copying between Java and native boundary?

 

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.