Re: Question on how JNI spec & you (+others?) conform to it.
[email protected] Mon, 17 Oct 2005 11:30:07 GMT
| Newsgroups | gmane.comp.java.vm.sablevm.devel |
|---|---|
| Message-ID | <[email protected]> |
> We implemented the JNI interface based on Liang's book
Turns out this may have been a mistake: from
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4458083
> The VM needs to implement its functionality according to specifications,
> and the publication "The Java Native Interface" by S. Liang is not the
> JNI specification. The JNI specification is the defining guide, and the
> other reference books should not be used to interpret that specification.
So the "Programmer's Guide and Specification", *isn't* the Specification (and
that's official!), despite being billed as "the definitive resource", contains
critical errors (despite being written by the person who wrote the *real* spec)
and has no errata. Furthermore, Sun (used to) charge for this, while giving the
real information away free. How helpful.
The differences are mostly that the book is more lax for the JNI user, so
tougher on the JNI implementor, so by working to the book you've *almost*
worked to both of them, effectively playing it safe; howver, there is (at least)
one significant exception:
p1 = env->GetPrimitiveArrayCritical(array1);
if (!p1) { return SOME_ERROR_CODE; /* exception is pending */ }
p2 = env->GetPrimitiveArrayCritical(array2);
if (!p2) {
/* Now what!?
According to the the book it's not safe to call Exception<Stuff>
(because we are in JNI critical section)
According to spec it's not safe to call Release<Stuff>Critical
(because exception is pending)
While we dither with indecision here, the GC, or possibly the entire
Java runtime, may have been suspended */
}
The only way for the implementor to play it safe (and this is why I bring it to
your attention) is to ensure that all these functions are safe to call at this
point, thus going beyond both specs.
However, for vendor-agnostic JNI users to play it safe (not knowing which spec
the implementors have worked to), there is *nothing* they can do in this
situation that might not lead to Undefined Behaviour. Phooey.
John