[foreign] RFR: native libraries should have a global scope

John Rose john.r.rose at oracle.com
Mon Jul 9 17:58:12 UTC 2018


On Jul 9, 2018, at 10:33 AM, Henry Jen <henry.jen at oracle.com> wrote:
> 
> I was hoping the get it right at first time, but this works. :)
> 
> Not an expert, hope JVM is smart enough to optimize it.

The JVM is very good at *some* boundary checks, and should
extend its competency over time to the ones we care about.

The JDK has some API points like Objects.checkFromToIndex
which are intended to provide clear signals to the JVM that
something is supposed to be well-optimized.

It's also the case that some arbitrary expression of <= < &&
should optimize well, even if the user didn't call a special API
point.  There's always a risk with arbitrary user-generated
expressions, since the JIT's optimizer cannot systematically
predict all variations of such expressions:  Users are very
clever at making hand-"optimized" versions of such logic
which run a fraction faster in the interpreter and then confuse
the JIT.  That's why the canned library routines are safer
even if they aren't always as slick-looking as bespoke code.

That said, we should have 'long' versions as well as 'int'
versions of those checker methods in the JDK.

— John


More information about the panama-dev mailing list