Re: Question on how JNI spec & you (+others?) conform to it.
Etienne Gagnon <[email protected]> Sat, 15 Oct 2005 22:16:30 -0400
| Newsgroups | gmane.comp.java.vm.sablevm.devel |
|---|---|
| Message-ID | <[email protected]> |
Hi John, We implemented the JNI interface based on Liang's book (at least, I did), but only using the "specification" section of this book. I have not really thought deeply about the matter of pending exception for each of the 11.8.2 list, though. The rule of thumb is that there won't be any problem calling on of these functions, *unless* some Java code is executed as part of this function. Thus, MonitorExit worries me, as if the monitor is in inconsistent state, a new exception must be raised, which means that some Java code will be executed (the constructor, etc.). So, there might be a problem. You could actually test SableVM's behavior to see whether it meets the spec. This is pretty easy, as when SableVM is compiled with debugging features, it aborts with an assestion error if a pending exception is present in a place where it is not allowed. So, you could write some JNI code like this: ... SomeJNICall() // call some JNI function rasing an exception MonitorExit() // try to release a monitor that you have NOT entered ;-) ... Then, run this code on a SableVM version configure as follows: $ ./configure --enable-debugging-features ... Please let me know what you find. I am pretty sure that the above will fail. The thing is that, if it fails, I see no easy way to implement Liang's book specified behavior, in which case, the online specification would actually make more sense. It's not easy to find out what is the real specification of Java... More often than not, it would seem that Sun considers that their "reference" implementation is the specification, and the role of the books and online documents is simply to serve a guide to that "specification". Yet, there are bugs in the reference implementation, so it cannot really be the specification, right? I am not sure... All I know is that I cannot access the reference implementation source code without getting "tainted", as it is not free software (http://www.gnu.org/philosophy/free-sw.html). So, we have to resolve specification ambiguities / inconsistencies by using logic as best as we can. Have fun! Etienne [email protected] wrote: > (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. -- Etienne M. Gagnon, Ph.D. http://www.info2.uqam.ca/~egagnon/ SableVM: http://www.sablevm.org/ SableCC: http://www.sablecc.org/ _______________________________________________ SableVM-devel mailing list [email protected] http://sablevm.org/lists/control/listinfo/sablevm-devel
signature.asc
(application/pgp-signature, 256 B)
-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.1 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFDUbf+jyrJi4rH84gRAomXAJ99pL/aQMLa3ezxLEvAjxmlqOpPHACeInnw vr0+Pn79ggW9vvGlQzFep+w= =EwfH -----END PGP SIGNATURE-----