JNI-performance - Is it really that fast?

Clemens Eisserer linuxhippy at gmail.com
Wed Mar 26 20:16:37 UTC 2008

Hi Dave,

Thanks for mentioning the blog, I already knew it but to be honest not
everything was 100% clear for me ;)

>  Unbiasing a lock, or more properly revoking its bias, can be
>  exceptionally expensive.   In the extreme case it might require a full
>  stop-the-world thread rendezvous to ensure there are no races between
>  the revoking thread and the bias holding thread.  (Ken's oopsla paper
>  describes some ways to mitigate that cost).
Well, ok, a stop-the-world thing "just" to revoke the bias would be
really expensive ... not sure if it would be a win even under optimal
conditions for this use.

>  If you suspect that biased locking would be a win then
>  for the most part you'd be better off with synchronized instead of yet
>  another special construct.   (I worry too that things like BiasedLock
>  don't necessarily age well. Biased locking is purely a response to
>  processor-local CAS/cmpxchg latency.  As processor vendors have turned
>  their attention to the issue the latency has shown relative
>  improvement so today's good idea might be tomorrow's legacy baggage
>  that needs to be towed around in perpetuity).
Well thats an argument I not really thought of and you're right of course.
Most likely the situations where this could be a win are seldom, and a
lot of work would be needed to implement and maintain it.
But don't you think the situation will only get worse the more cores
the current "design" is stretched to?
Lets just hope the situation will improve :)

Thanks a lot for listening and explaining everything that detailed, lg Clemens

I did some micro-benchmarking again on my machine again for a JNI-call:
180ms - jni per call, no locking
240ms - command-buffer(32k), locked JNI call every 1600 calls,
native-side buffer interpreter (a switch statement)
629ms - jni per call, locked
locking was done with a ReentrantLock.

So the command-buffering and interpreting semms to pay off, although
on my machine its still slower than a un-locked JNI call.

More information about the discuss mailing list