<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body style="overflow-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;">BTW, defineHiddenClass is not a good replacement for us, ‘cause if we used it, then JavaScript code compiled to Java bytecode will no longer show up in stack traces (as the generated classes are hidden.) With defineAnonymousClass we could still have proper stack traces when an exception is thrown from compiled JavaScript code.<div><br><div>I had discussions with folks at Oracle about this, but it’s not a high priority for them to fix this, sadly.<div><br></div><div>There’s not much drawback to this, BTW. Nashorn will just load the compiled code as ordinary classes; defineAnonymousClass was a bit of a performance optimization; such classes were marginally lighter and also could skip the bytecode verifier (for better or worse.)</div><div><br></div><div>Attila.<br><div><br><blockquote type="cite"><div>On 2024. Jan 24., at 14:22, Remi Forax <forax@univ-mlv.fr> wrote:</div><br class="Apple-interchange-newline"><div><meta charset="UTF-8"><div style="caret-color: rgb(0, 0, 0); font-family: arial, helvetica, sans-serif; font-size: 16px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><br class="Apple-interchange-newline"><br></div><hr id="zwchr" data-marker="__DIVIDER__" style="caret-color: rgb(0, 0, 0); font-family: arial, helvetica, sans-serif; font-size: 16px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><div data-marker="__HEADERS__" style="caret-color: rgb(0, 0, 0); font-family: arial, helvetica, sans-serif; font-size: 16px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><blockquote style="border-left-width: 2px; border-left-style: solid; border-left-color: rgb(16, 16, 255); margin-left: 5px; padding-left: 5px; font-weight: normal; font-style: normal; text-decoration: none; font-family: Helvetica, Arial, sans-serif; font-size: 12pt;"><b>From:<span class="Apple-converted-space"> </span></b>"Luc Chapon" <sxilderik@gmail.com><br><b>To:<span class="Apple-converted-space"> </span></b>"nashorn-dev" <nashorn-dev@openjdk.org><br><b>Sent:<span class="Apple-converted-space"> </span></b>Wednesday, January 24, 2024 1:02:48 PM<br><b>Subject:<span class="Apple-converted-space"> </span></b>Unsafe.defineAnonymousClass no longer exists in Java17!<br></blockquote></div><div data-marker="__QUOTED_TEXT__" style="caret-color: rgb(0, 0, 0); font-family: arial, helvetica, sans-serif; font-size: 16px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><blockquote style="border-left-width: 2px; border-left-style: solid; border-left-color: rgb(16, 16, 255); margin-left: 5px; padding-left: 5px; font-weight: normal; font-style: normal; text-decoration: none; font-family: Helvetica, Arial, sans-serif; font-size: 12pt;"><div dir="ltr"><div class="gmail_default" style="font-family: georgia, serif; color: rgb(32, 18, 77);">Hello all</div><div class="gmail_default" style="font-family: georgia, serif; color: rgb(32, 18, 77);"><br></div><div class="gmail_default" style="font-family: georgia, serif; color: rgb(32, 18, 77);">First message here</div><div class="gmail_default" style="font-family: georgia, serif; color: rgb(32, 18, 77);"><br></div><div class="gmail_default" style="font-family: georgia, serif; color: rgb(32, 18, 77);">We are facing a problem re Nashorn (latest) and java17</div><div class="gmail_default" style="font-family: georgia, serif; color: rgb(32, 18, 77);"><br></div><div class="gmail_default" style="font-family: georgia, serif; color: rgb(32, 18, 77);">In Context.java, line 330, you try to get a handle to a no longer existent method, Unsafe.defineAnonymousClass</div><div class="gmail_default" style="font-family: georgia, serif; color: rgb(32, 18, 77);"><br></div><div class="gmail_default" style="font-family: georgia, serif; color: rgb(32, 18, 77);">And fail of course.</div><div class="gmail_default" style="font-family: georgia, serif; color: rgb(32, 18, 77);"><br></div><div class="gmail_default" style="font-family: georgia, serif; color: rgb(32, 18, 77);">I’m trying to rewrite this part for our own temporary urgent need according to this.<br><br><a href="https://www.oracle.com/java/technologies/javase/17-relnote-issues.html" target="_blank">https://www.oracle.com/java/technologies/javase/17-relnote-issues.html</a><br></div><blockquote style="margin: 0px 0px 0px 40px; border: medium; padding: 0px;"><div class="gmail_default" style="font-family: georgia, serif; color: rgb(32, 18, 77);"><div style="box-sizing: border-box; margin: 0px; padding: 0px; list-style: none; background-repeat: no-repeat; font-family: OracleSansVF, OracleSansVFCyGr, OracleSansFB, -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", sans-serif; font-size: 14.63px; background-color: rgb(251, 249, 248);">core-libs</div></div><div class="gmail_default" style="font-family: georgia, serif; color: rgb(32, 18, 77);"><b style="box-sizing: border-box; margin: 0px; padding: 0px; list-style: none; background-repeat: no-repeat; font-family: OracleSansVF, OracleSansVFCyGr, OracleSansFB, -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", sans-serif; font-size: 14.63px; background-color: rgb(251, 249, 248);"><a href="https://www.oracle.com/java/technologies/javase/17-relnote-issues.html#JDK-8243287" target="_blank" style="box-sizing: border-box; margin: 0px; padding: 0px; list-style: none; background-repeat: no-repeat; color: rgb(0, 107, 143); text-decoration: none;"><span class="gmail-arrow" style="box-sizing: border-box; margin: 0px; padding: 0px; list-style: none; background-repeat: no-repeat;">➜</span></a> Removal of sun.misc.Unsafe::defineAnonymousClass</b></div><div class="gmail_default" style="font-family: georgia, serif; color: rgb(32, 18, 77);"><p style="box-sizing: border-box; margin: 0px 0px 1.1em; padding: 0px; list-style: none; background-repeat: no-repeat; line-height: 1.55; font-family: OracleSansVF, OracleSansVFCyGr, OracleSansFB, -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", sans-serif; font-size: 14.63px; background-color: rgb(251, 249, 248);"><code style="box-sizing: border-box; margin: 0px; padding: 0px; list-style: none; background-repeat: no-repeat;">sun.misc.Unsafe::defineAnonymousClass</code> API has been removed in JDK 17. The API replacement is <code style="box-sizing: border-box; margin: 0px; padding: 0px; list-style: none; background-repeat: no-repeat;">java.lang.invoke.MethodHandles.Lookup::defineHiddenClass</code> and <code style="box-sizing: border-box; margin: 0px; padding: 0px; list-style: none; background-repeat: no-repeat;">java.lang.invoke.MethodHandles.Lookup::defineHiddenClassWithClassData</code>.</p></div></blockquote><div class="gmail_default" style="font-family: georgia, serif; color: rgb(32, 18, 77);"><br></div><div class="gmail_default" style="font-family: georgia, serif; color: rgb(32, 18, 77);">Are you aware of the problem? Is there a fix already available?</div></div></blockquote><div><br></div><div>Hello,<br data-mce-bogus="1"></div><div>defineAnonymousClass have been replaced by Lookup.defineHiddenClass(...) [1] which is a public API.</div><br><blockquote style="border-left-width: 2px; border-left-style: solid; border-left-color: rgb(16, 16, 255); margin-left: 5px; padding-left: 5px; font-weight: normal; font-style: normal; text-decoration: none; font-family: Helvetica, Arial, sans-serif; font-size: 12pt;"><div dir="ltr"><div class="gmail_default" style="font-family: georgia, serif; color: rgb(32, 18, 77);"><br></div><div class="gmail_default" style="font-family: georgia, serif; color: rgb(32, 18, 77);">Thank you!</div></div></blockquote><div><br></div><div>regards,<br data-mce-bogus="1"></div><div>Rémi<br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div><blockquote style="border-left-width: 2px; border-left-style: solid; border-left-color: rgb(16, 16, 255); margin-left: 5px; padding-left: 5px; font-weight: normal; font-style: normal; text-decoration: none; font-family: Helvetica, Arial, sans-serif; font-size: 12pt;"><div dir="ltr"><div class="gmail_default" style="font-family: georgia, serif; color: rgb(32, 18, 77);"><br></div><div class="gmail_default" style="font-family: georgia, serif; color: rgb(32, 18, 77);">Luc Chapon</div><div class="gmail_default" style="font-family: georgia, serif; color: rgb(32, 18, 77);">ChapsVision</div><div class="gmail_default" style="font-family: georgia, serif; color: rgb(32, 18, 77);">Suresnes, France</div></div></blockquote><div><br></div><div>[1]<span class="Apple-converted-space"> </span><a href="https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/lang/invoke/MethodHandles.Lookup.html#defineHiddenClass(byte[],boolean,java.lang.invoke.MethodHandles.Lookup.ClassOption...)">https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/lang/invoke/MethodHandles.Lookup.html#defineHiddenClass(byte[],boolean,java.lang.invoke.MethodHandles.Lookup.ClassOption...)</a></div></div></div></blockquote></div><br></div></div></div></body></html>