<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: "Calibri Light", "Helvetica Light", sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
Hi David, a dynamic constant does have the advantage of bypassing some circular initialization issues. However, such a constant still must be initialized by the time the class finishes initialization. The benefits of a dynamic constant are not helpful unless
we adjust the JLS. In addition, a synthetic field can be accessed by other classes and interfaces in the same nest; not so for dynamic constants without an accessor method.</div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> compiler-dev <compiler-dev-retn@openjdk.org> on behalf of David Lloyd <david.lloyd@redhat.com><br>
<b>Sent:</b> Wednesday, January 28, 2026 3:43 PM<br>
<b>To:</b> Eirik Bjørsnøs <eirbjo@gmail.com><br>
<b>Cc:</b> compiler-dev@openjdk.org <compiler-dev@openjdk.org><br>
<b>Subject:</b> Re: Q: Why are $assertionsDisabled nested classes loaded eagerly by interface static initializers?</font>
<div> </div>
</div>
<div>
<div dir="ltr">
<div class="x_gmail_default" style="font-family:arial,helvetica,sans-serif">On the same token, maybe it's worth considering going farther, and making assertion status determination use a dynamic constant instead of a synthetic field?</div>
</div>
<br>
<div class="x_gmail_quote">
<div dir="ltr" class="x_gmail_attr">On Wed, Jan 28, 2026 at 3:36 PM Eirik Bjørsnøs <<a href="mailto:eirbjo@gmail.com" target="_blank">eirbjo@gmail.com</a>> wrote:<br>
</div>
<blockquote class="x_gmail_quote" style="margin:0px 0px 0px 0.8ex; border-left:1px solid rgb(204,204,204); padding-left:1ex">
<div dir="ltr"><br>
<div>Hi,</div>
<div><br>
</div>
<div>Since interfaces cannot have private fields, javac needs to generate a synthetic inner class to hold the $assertionsDisabled field.</div>
<div><br>
</div>
<div>A static initializer is also added to the interface, eagerly initializing the nested class, see the java.util.zip.Checksum for an example:</div>
<div><br>
</div>
<div><font face="monospace"> static {};<br>
Code:<br>
0: getstatic #16 // Field java/util/zip/Checksum$1.$assertionsDisabled:Z<br>
3: ifeq 6<br>
6: return</font></div>
<div><font face="monospace"><br>
</font></div>
<div>What is the purpose of this eager initialization in Lower::assertFlagTest? I would presume a lazy initialization of the nested class on the first run of an assert would be sufficient?</div>
<div><br>
</div>
<div>In fact when I remove this eager initialization, assertions seem to load the nested class just fine with -esa enabled, but avoid loading the nested class with assertions disabled. </div>
<div><br>
</div>
<div>Asking because this would save class loading common scenarios where the default method is always overridden and thus the default method with the assert is never executed.</div>
<div><br>
</div>
<div>Can we load these nested synthetic classes lazily?</div>
<div><br>
</div>
<div>Cheers,</div>
<div>Eirik.</div>
</div>
</blockquote>
</div>
<div><br clear="all">
</div>
<div><br>
</div>
<span class="x_gmail_signature_prefix">-- </span><br>
<div dir="ltr" class="x_gmail_signature">
<div dir="ltr">- DML • he/him<br>
</div>
</div>
</div>
</body>
</html>