Question on how JNI spec & you (+others?) conform to it.

[email protected] Sat, 15 Oct 2005 14:45:15 GMT
Newsgroups gmane.comp.java.vm.sablevm.devel
Message-ID <[email protected]>
(Apologies if this is not the most relevant place to be asking this. If that is
the case, please point me somewhere more appropriate. I've asked on the Java
newsgroups, Sun Forums, and even directly to the Sun JNI team itself, with no
joy.)

The JNI spec appears in two documents. One is the book "Java Native Interface,
Programmers' Guide and Specification" by Cheng Liang, and the other in the
online doc "JNI Specification" off java.sun.com (which currently stands at
v1.5). Which did you work to when implementing JNI in sableVM? This is
important, as the two documents contradict one another as to what constitues
Undefined Behvaiour in the face of a pending Exception (i.e. ExceptionCheck()
returning non-zero).

The Programmers' Guide says (11.8.2) that resource-releasing JNI functions like
DeleteLocalRef, Release<Type>ArrayElems etc can be called when there is a
pending Exception, but the online spec (which is more recent in its current
version) says (right at the end of Chapter 2) that only ExceptionOccurred,
ExceptionDescribe and ExceptionClear. (Oddly, ExceptionCheck is not on the list
but this is presumably an oversight.)

I am interested in whether, in your experience as implementors of the JNI, you
think it reasonable that a quality JVM may exist that only conforms to the
online spec (thus necessitating more careful exception checking in the face of
resource cleanup), rather than Liang's book (which specifically says such checks
are unnecessary). The reason is, that I have written my JNI client code based on
the former, having only come across the latter quite recently. The error
checking I do is extensive (and may have performance considerations), but
according to Liang I can strip it out with impunity.

Obviously *Sun's* JVM will conform to both documents, but I am trying to
ascertain whether if I do work to Liang's book, some quality JNI implementation
out there might, by design, lead to Undefined Behaviour. I was hoping that you
might have some valuable insight into this issue, having been through the
process yourselves.

Thanks

John.