Q: Why are $assertionsDisabled nested classes loaded eagerly by interface static initializers?
Eirik Bjørsnøs
eirbjo at gmail.com
Wed Jan 28 21:35:19 UTC 2026
Hi,
Since interfaces cannot have private fields, javac needs to generate a
synthetic inner class to hold the $assertionsDisabled field.
A static initializer is also added to the interface, eagerly initializing
the nested class, see the java.util.zip.Checksum for an example:
static {};
Code:
0: getstatic #16 // Field
java/util/zip/Checksum$1.$assertionsDisabled:Z
3: ifeq 6
6: return
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?
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.
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.
Can we load these nested synthetic classes lazily?
Cheers,
Eirik.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/compiler-dev/attachments/20260128/6ffbb2a4/attachment.htm>
More information about the compiler-dev
mailing list