<div dir="ltr">On 11 October 2013 08:02, Anton Smirnov <span dir="ltr"><<a href="mailto:dev@antonsmirnov.name" target="_blank">dev@antonsmirnov.name</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>Are there any obvious limitations or anybody with such experience?</div></div></blockquote><div></div>
</div><br></div><div class="gmail_extra">Yes, JNI.</div><div class="gmail_extra"><br></div><div class="gmail_extra">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.</div>
<div class="gmail_extra"><br></div><div class="gmail_extra">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. </div>
<div class="gmail_extra"><br></div><div class="gmail_extra">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.</div>
<div class="gmail_extra"><br></div><div class="gmail_extra">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...</div><div class="gmail_extra">
<br></div><div class="gmail_extra">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.</div>
<div class="gmail_extra"><br></div><div class="gmail_extra">cheers,</div><div class="gmail_extra">--renato</div></div>