Does Nashorn (org.openjdk.nashorn) have any support for Java 17?

forax at univ-mlv.fr forax at univ-mlv.fr
Tue Jun 29 20:34:28 UTC 2021


> From: "Attila Szegedi" <szegedia at gmail.com>
> To: "Remi Forax" <forax at univ-mlv.fr>
> Cc: "nashorn-dev" <nashorn-dev at openjdk.java.net>
> Sent: Mardi 29 Juin 2021 00:37:56
> Subject: Re: Does Nashorn (org.openjdk.nashorn) have any support for Java 17?

>> On 2021. Jun 28., at 19:30, Remi Forax < [ mailto:forax at univ-mlv.fr |
>> forax at univ-mlv.fr ] > wrote:

>> In the meantime, I think you can use Lookup.defineClass() or do you rely on the
>> weird security model of the anonymous classes ?

> Thankfully, no. Nashorn regenerates code for the same function sometimes so it
> was convenient having old versions get garbage collectible when they were
> individual anonymous classes; not being registered with class loader didn’t
> make their reachability dependent on one another. I could simulate it with one
> class loader per generated class; but it’ll cause a bit of a proliferation of
> class loader objects. Anon classes were just convenient in this regard.

Yes, convenient but internally, you have one metaspace per anon class exactly like when you have one classloader per class. 

For lambdas, the jdk has moved from the weak semantics (le the proxy class is not linked to a classloader) to the strong semantics, the proxy class is linked to the class loader of the nestmate host class. 
https://github.com/openjdk/jdk/blob/master/src/java.base/share/classes/java/lang/invoke/InnerClassLambdaMetafactory.java#L405 

> IIUC Lookup.defineClass() doesn’t help me with that. Does it have some benefits
> over defining a class through a class loader ?

It does not help if you want the weak semantics, it helps if you want to use the strong semantics because lookup.defineClass() load the class with the same classloader as the lookup class. 

> Attila.

Rémi 

>>> Hope this helps,
>>> Attila.

>> Rémi

>>> [0] [ https://mail.openjdk.java.net/pipermail/core-libs-dev/2021-May/077347.html
>>> | https://mail.openjdk.java.net/pipermail/core-libs-dev/2021-May/077347.html ]

>>>> On 2021. Jun 28., at 18:24, Greg Watts < [ mailto:gwatts at us.ibm.com |
>>>> gwatts at us.ibm.com ] > wrote:

>>>> Dear Nashorn development team,

>>>> I am trying to run an ANT build of our product using
>>>> nashorn-core:15.1.1.jar with Java 17 (pre-release - build 27) and I get:

>>>> BUILD FAILED
>>>> java.lang.ExceptionInInitializerError
>>>> at
>>>> org.openjdk.nashorn.internal.runtime.Context.compile(Context.java:1509)
>>>> at
>>>> org.openjdk.nashorn.internal.runtime.Context.compileScript(Context.java:1449)
>>>> at
>>>> org.openjdk.nashorn.internal.runtime.Context.compileScript(Context.java:759)
>>>> at
>>>> org.openjdk.nashorn.api.scripting.NashornScriptEngine.compileImpl(NashornScriptEngine.java:528)
>>>> at
>>>> org.openjdk.nashorn.api.scripting.NashornScriptEngine.compileImpl(NashornScriptEngine.java:517)
>>>> at
>>>> org.openjdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:395)
>>>> at
>>>> org.openjdk.nashorn.api.scripting.NashornScriptEngine.eval(NashornScriptEngine.java:151)
>>>> at
>>>> java.scripting/javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:262)
>>>> at
>>>> java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native
>>>> Method)
>>>> at
>>>> java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
>>>> at
>>>> java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>>>> at java.base/java.lang.reflect.Method.invoke(Method.java:568)
>>>> at org.apache.tools.ant.util.ReflectUtil.invoke(ReflectUtil.java:108)
>>>> at
>>>> org.apache.tools.ant.util.ReflectWrapper.invoke(ReflectWrapper.java:81)
>>>> at
>>>> org.apache.tools.ant.util.optional.JavaxScriptRunner.evaluateScript(JavaxScriptRunner.java:103)
>>>> at
>>>> org.apache.tools.ant.util.optional.JavaxScriptRunner.executeScript(JavaxScriptRunner.java:67)
>>>> at
>>>> org.apache.tools.ant.taskdefs.optional.Script.execute(Script.java:52)
>>>> at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
>>>> at jdk.internal.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
>>>> at
>>>> java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>>>> at java.base/java.lang.reflect.Method.invoke(Method.java:568)
>>>> at
>>>> org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
>>>> at org.apache.tools.ant.Task.perform(Task.java:348)
>>>> at org.apache.tools.ant.Target.execute(Target.java:392)
>>>> at org.apache.tools.ant.Target.performTasks(Target.java:413)
>>>> at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
>>>> at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
>>>> at
>>>> org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
>>>> at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
>>>> at org.apache.tools.ant.Main.runBuild(Main.java:811)
>>>> at org.apache.tools.ant.Main.startAnt(Main.java:217)
>>>> at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
>>>> at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)
>>>> Caused by: java.lang.RuntimeException: java.lang.NoSuchMethodException: no
>>>> such method:
>>>> sun.misc.Unsafe.defineAnonymousClass(Class,byte[],Object[])Class/invokeVirtual
>>>> at org.openjdk.nashorn.internal.runtime.Context
>>>> $AnonymousContextCodeInstaller.lambda$getDefineAnonymousClass
>>>> $0(Context.java:335)
>>>> at
>>>> java.base/java.security.AccessController.doPrivileged(AccessController.java:318)
>>>> at org.openjdk.nashorn.internal.runtime.Context
>>>> $AnonymousContextCodeInstaller.getDefineAnonymousClass(Context.java:327)
>>>> at org.openjdk.nashorn.internal.runtime.Context
>>>> $AnonymousContextCodeInstaller.<clinit>(Context.java:317)
>>>> ... 33 more
>>>> Caused by: java.lang.NoSuchMethodException: no such method:
>>>> sun.misc.Unsafe.defineAnonymousClass(Class,byte[],Object[])Class/invokeVirtual
>>>> at
>>>> java.base/java.lang.invoke.MemberName.makeAccessException(MemberName.java:976)
>>>> at java.base/java.lang.invoke.MemberName
>>>> $Factory.resolveOrFail(MemberName.java:1117)
>>>> at java.base/java.lang.invoke.MethodHandles
>>>> $Lookup.resolveOrFail(MethodHandles.java:3643)
>>>> at java.base/java.lang.invoke.MethodHandles
>>>> $Lookup.findVirtual(MethodHandles.java:2680)
>>>> at org.openjdk.nashorn.internal.runtime.Context
>>>> $AnonymousContextCodeInstaller.lambda$getDefineAnonymousClass
>>>> $0(Context.java:329)
>>>> ... 36 more
>>>> Caused by: java.lang.NoSuchMethodError: 'java.lang.Class
>>>> sun.misc.Unsafe.defineAnonymousClass(java.lang.Class, byte[],
>>>> java.lang.Object[])'
>>>> at java.base/java.lang.invoke.MethodHandleNatives.resolve(Native
>>>> Method)
>>>> at java.base/java.lang.invoke.MemberName
>>>> $Factory.resolve(MemberName.java:1085)
>>>> at java.base/java.lang.invoke.MemberName
>>>> $Factory.resolveOrFail(MemberName.java:1114)
>>>> ... 39 more

>>>> So I was curious to know please if Nashorn will be supported in Java 17,
>>>> and if so, when you might anticipate that to be released (ballpark
>>>> estimate)?

>>>> Greg Watts
>>>> WebSphere Zombie Apocalypse Team
>>>> External: 507-253-8901
>>>> [ mailto:gwatts at us.ibm.com | email: gwatts at us.ibm.com ]

>>>> "Take risks: if you win, you will be happy; if you lose, you will be wise"
>>>> - Unknown


More information about the nashorn-dev mailing list