----- Original Message -----
> From: "Attila Szegedi" <szege...@gmail.com>
> To: "nashorn-dev" <nashorn-dev@openjdk.java.net>
> Cc: "Greg Watts" <gwa...@us.ibm.com>
> Sent: Lundi 28 Juin 2021 19:07:38
> Subject: Re: Does Nashorn (org.openjdk.nashorn) have any support for Java 17?

> Hi Greg,
> 
> that’s a consequence of Java 17 removing the Unsafe.defineAnonymousClass 
> method.
> Unfortunately, we don’t have an ideal replacement for it yet.
> MethodHandles.Lookup.defineHiddenClass is supposed to be a publicly supported
> replacement, but it hides the generated classes from stack traces, and that
> makes Nashorn incorrectly report exception stack traces, since we use this
> method to emit code compiled from scripts.
> 
> There’s been some discussion about this[0] and the JDK team at Oracle is aware
> that we’d need a better replacement API but there’s not one available yet :-(
> 
> We use Unsafe.defineAnonymousClass for Nashorn’s lazy compilation feature, 
> where
> it compiles every function independently just before it is executed for the
> first time. This is in contrast to eager compilation, where the whole script 
> is
> compiled when it is loaded. Lazy compilation is the default.
> 
> One thing you can do right now is try to somehow pass “false” as the value of
> the “lazy.compilation” system property to turn off lazy compilation.
> 
> I’ve been working on a branch that’ll handle the problem gracefully and 
> default
> to eager compilation if Unsafe.defineAnonymousClass is not present in the Java
> runtime. I’ll probably make a release soon with this fix.

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

> 
> Hope this helps,
>  Attila.

Rémi

> 
> [0] https://mail.openjdk.java.net/pipermail/core-libs-dev/2021-May/077347.html
> 
> 
>> On 2021. Jun 28., at 18:24, Greg Watts <gwa...@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
>> email: gwa...@us.ibm.com
>> 
>> "Take risks:  if you win, you will be happy; if you lose, you will be wise"
> > - Unknown

Reply via email to