<div dir="ltr">Thanks for the explanation, Chen.<br><br>I was confused by the javadoc on <font face="monospace">defineClass</font>, as it states that references would also be redirected during verification. I now see that class loads during verification are irrelevant here. I was also unaware that the receiver of field and method references were directly referring to <font face="monospace">thisClass</font><font face="arial, sans-serif"> (mostly due to never manually reading the constant pool and just relying on disassemblers to combine the entries) which made me believe they were replaced differently.</font><div><font face="arial, sans-serif"><br></font></div><div><font face="arial, sans-serif">I'll probably move my setup over to using custom classloaders, as I will need to be able to use lambdas. I don't think I can do any bytecode patching here as I can't get the runtime name before the jvm has already loaded the class (and I'm already generating it with ASM so I have full control over the bytecode). </font><span style="font-family:arial,sans-serif">Being able to do more with indy in hidden classes would be nice, but I will for the foreseeable future be stuck on java 21, so any new progress won't be affecting me anyway.</span></div><div><span style="font-family:arial,sans-serif"><br></span></div><div><span style="font-family:arial,sans-serif">I now see that there was no bug or oversight and that I simply misunderstood documentation and behaviour. </span></div><div><span style="font-family:arial,sans-serif"><br></span></div><div><span style="font-family:arial,sans-serif">Thanks for your time, Matias</span></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Sep 10, 2024 at 4:47 PM Chen Liang <<a href="mailto:chen.l.liang@oracle.com">chen.l.liang@oracle.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class="msg5012538537166416067">
<div dir="ltr">
<div style="font-family:Aptos,Aptos_EmbeddedFont,Aptos_MSFontService,Calibri,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
Hi Matias,</div>
<div style="font-family:Aptos,Aptos_EmbeddedFont,Aptos_MSFontService,Calibri,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
Since MethodHandles is a library API, I think we can discuss about this on core-libs list.</div>
<div style="font-family:Aptos,Aptos_EmbeddedFont,Aptos_MSFontService,Calibri,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Aptos,Aptos_EmbeddedFont,Aptos_MSFontService,Calibri,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
About the self-reference replacement: as the spec says, it only happens to the thisClass Class entry in the hidden class. That means if the class is referenced in a method (such as a method's parameter in your class) or field (such as a field's type in your
class) descriptor, all of which do not go through Class entries, the reference is kept as-is. So the lack of substitution for NameAndType is working as intended.</div>
<div style="font-family:Aptos,Aptos_EmbeddedFont,Aptos_MSFontService,Calibri,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Aptos,Aptos_EmbeddedFont,Aptos_MSFontService,Calibri,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
Currently, LambdaMetafactory only has limited support for static methods in hidden classes, which was actually not available in release 22 and only added in release 23 development as there's a need from project Babylon. This is not part of LMF's specification
and we might adjust this behavior at any time.</div>
<div style="font-family:Aptos,Aptos_EmbeddedFont,Aptos_MSFontService,Calibri,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Aptos,Aptos_EmbeddedFont,Aptos_MSFontService,Calibri,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
For your purpose, you might have to bytecode process the class and patch references manually, or look into using non-hidden classes in custom class loaders instead.</div>
<div style="font-family:Aptos,Aptos_EmbeddedFont,Aptos_MSFontService,Calibri,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Aptos,Aptos_EmbeddedFont,Aptos_MSFontService,Calibri,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
Regards,</div>
<div style="font-family:Aptos,Aptos_EmbeddedFont,Aptos_MSFontService,Calibri,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
Chen</div>
<div id="m_5012538537166416067appendonsend"></div>
<hr style="display:inline-block;width:98%">
<div id="m_5012538537166416067divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> discuss <<a href="mailto:discuss-retn@openjdk.org" target="_blank">discuss-retn@openjdk.org</a>> on behalf of Matias Koivikko <<a href="mailto:matias.koivikko@gmail.com" target="_blank">matias.koivikko@gmail.com</a>><br>
<b>Sent:</b> Tuesday, September 10, 2024 7:35 AM<br>
<b>To:</b> <a href="mailto:discuss@openjdk.org" target="_blank">discuss@openjdk.org</a> <<a href="mailto:discuss@openjdk.org" target="_blank">discuss@openjdk.org</a>><br>
<b>Subject:</b> Where to ask about a potential bug/oversight with hidden classes</font>
<div> </div>
</div>
<div>
<div dir="ltr">Hi everyone,
<div><br>
</div>
<div>I've been working on a project where I compile custom code to class files and load them using
<font face="monospace">MethodHandles.Lookup#defineHiddenClass</font><font face="arial, sans-serif"> into the jvm. This seems like the correct method to me as my classes don't need to be referenced from the outside beyond reflectively calling a single method
and they should ideally unload soon after unless they stored references somewhere.</font></div>
<div><font face="arial, sans-serif"><br>
</font></div>
<div><font face="arial, sans-serif">As for the bug, it involves lambdas that capture
</font><font face="monospace">this</font><font face="arial, sans-serif"> and a </font><font face="monospace">ClassNotFoundException</font><font face="arial, sans-serif"> being thrown for the hidden class. As far as I understand it, the </font><span style="font-family:arial,sans-serif">hidden</span> <font face="arial, sans-serif">class
gets a randomized name at runtime and all references to itself within the class file should be replaced. It seems like this process doesn't work properly for the main
</font><font face="monospace">NameAndType</font><font face="arial, sans-serif"> of an
</font><font face="monospace">invokedynamic</font><font face="arial, sans-serif"> instruction. This would then cause a runtime crash whenever capturing lambdas among other uses of indy are used.</font></div>
<div><font face="arial, sans-serif"><br>
</font></div>
<div><font face="arial, sans-serif">Does anyone have any ideas on what I could have done wrong or where I should take this question further? I assume there's some more appropriate mailing list to discuss this issue in.</font></div>
<div><font face="arial, sans-serif"><br>
</font></div>
<div><font face="arial, sans-serif">Regards, Matias</font></div>
<div><font face="arial, sans-serif"><br>
</font></div>
<div><font face="arial, sans-serif"><br>
</font></div>
</div>
</div>
</div>
</div></blockquote></div>