Tim Ellison wrote:
On 15/Sep/2009 09:51, Regis wrote:
Tim Ellison wrote:
On 15/Sep/2009 04:26, Regis wrote:
Tim Ellison wrote:
(2) Not sure if any JNI implementations will care, but AIUI you only
should call ReleaseByteArrayElements if you got a copy of the array
(i.e. as indicated by the GetByteArrayElements).
I had the puzzle too, and did some searches, I found HARMONY-1634, not
sure it's just suitable for drlvm, but "The Get.. Release pair can be
used to prevent GC during the operation" seems reasonable, so I followed
it.
My point was that, AIUI, the Release should only be called if the Get
returned a copy, and you are not checking whether the Get returned a
copy or not. In practice, it probably doesn't matter anyway.
AIUI, If Get pinned java heap, the pinned array will be locked to
prevent GC collect or move it, Release will unlock it. So I think
Release should be called anyway, like we did in HARMONY-1634.
The Get* function will tell you if it has been pinned or copied via the
isCopy argument. However, as I read the spec [1] I think you are right
that Release* should/could be called every time (which is likely a
trivial operation for pinned arrays anyway).
I was looking at the Essential JNI book [2] reference page that says,
"This value [isCopy] should be tested to determine if a call to
Release<pType>ArrayElements needs to be called." (p.378)
I normally wrap the Release* function call in an if(isCopy == JNI_TRUE)
conditional, but maybe more by habit than necessity.
I agree it is different for GetPrimitiveArrayCritical (which was the
subject of HARMONY-1634).
[1]
http://java.sun.com/j2se/1.5.0/docs/guide/jni/spec/functions.html#wp17382
[2] http://www.amazon.com/Essential-Jni-Java-Native-Interface/dp/0136798950
Regards,
Tim
I applied the improvements at r816508 and closed the JIRA.
--
Best Regards,
Regis.