[cfe-dev] clang via JNI + libclang-c

Renato Golin renato.golin at linaro.org
Fri Oct 11 01:24:57 PDT 2013


On 11 October 2013 08:02, Anton Smirnov <dev at antonsmirnov.name> wrote:

> Are there any obvious limitations or anybody with such experience?
>

Yes, JNI.

JNI is a poor implementation of C code, trying to deal with the poor
definitions of Java code, at the same time as trying to be 100%
cross-platform. It fails on all three levels.

Stack corruption in JNI is surprisingly common, especially on Windows (but
also on Linux), and a few tricks must be used if you pass more than just a
char pointer. On the top of my head I remember I had to define a large
array on the stack, so that the stack pointer wouldn't segfault.

JNI is also surprisingly poor in propagating errors from the C layer to the
Java layer (if at all), so catching errors and debugging the interface is
downright nightmare.

You would hope that, after all these years, someone would come up with a
fix, or a better infrastructure for inter-operating C code with Java...

This is a long shot, but have you tried using the VMKit and sharing C and
Java code via LLVM's Execution Engine? I heard of a project that managed to
do that with Python+C, including exception handling, so it should be
possible to do that with Java.

cheers,
--renato
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20131011/82dfd6d0/attachment.html>


More information about the cfe-dev mailing list