I am working on a project to write/read hdf5 files with LZO compression. I
have figured out the writing part. It is done by dynamically registering
the LZO filter callbacks. The writing is all in C.
I do not have much experience with Jave Native Interface, but it may be
feasible to write a JAVA Native Interface wrapper class around a C reader
class.
The problem with wrapping this function in Java is that the argument is a
structure with references to function pointers. It is these function pointers
that cannot be easily matched within Java. The void* argument itself can
easily be specified for Java to C conversion.
Suggestions are welcomed.
Allen
···
On Wednesday, December 24, 2014 06:27:11 PM Ching-Chia Wang wrote:
Hello,
I am working on a project to write/read hdf5 files with LZO compression. I
have figured out the writing part. It is done by dynamically registering
the LZO filter callbacks. The writing is all in C.
I do not have much experience with Jave Native Interface, but it may be
feasible to write a JAVA Native Interface wrapper class around a C reader
class.
I've dealt with similar problems when using callbacks from the National Instruments API. I resolved it with a little C code and some special handling for threads. The National Instruments library spawns its own threads which have to be registered with the JVM post-hoc.
It would be possible to create a native method transform of a static function "on the fly" using one of the byte code engineering libraries (Javassist, BCEL, ASM4) + a little stack management magic. If I have time to come up with a functional example, I'll post it. No guarantees. It is not hard to do this for a few specific functions if you are willing to add some C wrappers. Tricky for the general case, but not impossible either.
So, this can be done in the existing JVM. But there is also a lot of talk around new tools and standard libraries for Java Foreign Function Interface. We'll see if anything significantly new comes of that. You can get some hints regarding ongoing development through github in the jnr-ffi project. I realize this project is focused on Java calling foreign functions, but the data structures work the same in both directions.
The problem with wrapping this function in Java is that the argument is a structure with references
to function pointers. It is these function pointers that cannot be easily matched within Java. The void*
argument itself can easily be specified for Java to C conversion.
Suggestions are welcomed.
Allen
On Wednesday, December 24, 2014 06:27:11 PM Ching-Chia Wang wrote:
Hello,
I am working on a project to write/read hdf5 files with LZO
compression. I have figured out the writing part. It is done by
dynamically registering the LZO filter callbacks. The writing is all in C.
I do not have much experience with Jave Native Interface, but it may
be feasible to write a JAVA Native Interface wrapper class around a C
reader class.