Standalone Nashorn is coming for Java 15+

Attila Szegedi szegedia at gmail.com
Mon Oct 12 17:05:09 UTC 2020



> On 2020. Oct 12., at 18:41, Gustavo Lopes <gustavo at sqreen.com> wrote:
> 
> I had to change to the Unsafe in sun.misc rather than the internal one

Yeah, forgot to address this one… So that is used for “anonymous code loading” which is an optional feature and I think for the first cut, I might just disable it. It is somewhat (not much) faster as I believe those classes bypass the verifier and the class might probably use marginally less memory. I’m thinking of replacing it with MethodHandles.Lookup.defineHiddenClass[1] and thus completely avoid reliance on any internal APIs. I’m sure this public API doesn’t bypass the verifier, but is otherwise a fine choice as it also allows granular unloading of no longer used code and is in general lighter than ordinary class definition. 

Of course, it’ll make this Nashorn usable on Java15+ only as Lookup.defineHiddenClass debuts in Java 15, but I reckon that’s probably fine (we can discuss this issue separately.)

Attila.

[1] https://docs.oracle.com/en/java/javase/15/docs/api/java.base/java/lang/invoke/MethodHandles.Lookup.html#defineHiddenClass(byte%5B%5D,boolean,java.lang.invoke.MethodHandles.Lookup.ClassOption...)



More information about the nashorn-dev mailing list