<!DOCTYPE html><html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body><div style="font-family: sans-serif;"><div class="markdown" style="white-space: normal;">
<p dir="auto">Overall, as we look at Preload, it is looking more and more like a no-op, as far as the JLS and JVMS is concerned.  Perhaps that is a signal that it should be placed somewhere outside of the JVMS, such as in a Leyden-specific mechanism (a preload list) produced in a way decoupled from any transactions between the JLS and JVMS.</p>
<p dir="auto">On 1 Jun 2023, at 11:24, Dan Smith wrote:</p>
</div><div class="plaintext" style="white-space: normal;"><blockquote style="margin: 0 0 5px; padding-left: 5px; border-left: 2px solid #777777; color: #777777;"><blockquote style="margin: 0 0 5px; padding-left: 5px; border-left: 2px solid #777777; border-left-color: #999999; color: #999999;"><p dir="auto">On Jun 1, 2023, at 10:53 AM, Dan Heidinga <heidinga@redhat.com> wrote:</p>
<p dir="auto">A couple of questions about the spec for the Preload attribute[0].  The current spec says it indicates "certain classes contain information that may be of interest during linkage."</p>
<p dir="auto">The Preload attribute removes one need for Q modifiers while allowing calling convention optimizations and layout decisions to be made early.</p>
<p dir="auto">The current spec is quite vague on what classes should be included in the attribute and on when / what the VM will do with those classes (or even if it does anything).</p>
</blockquote><p dir="auto">FWIW, the JEP has more detail about when javac is expected to include classes in Preload.</p>
<blockquote style="margin: 0 0 5px; padding-left: 5px; border-left: 2px solid #777777; border-left-color: #999999; color: #999999;"><p dir="auto">I think it's time to tighten up the spec for Preload attribute and specify:
<br>
* what the VM will do with classes listed in the attribute</p>
</blockquote><p dir="auto">It is intentional that the VM may choose to do nothing. So anything it does is purely an optimization.</p>
</blockquote></div>
<div class="markdown" style="white-space: normal;">
<p dir="auto">Looks like a nop…</p>
<p dir="auto">(In particular, it should not <em>reject</em> any inputs, because that would destabilize separate compilability in unpredictable ways.)</p>
</div><div class="plaintext" style="white-space: normal;"><blockquote style="margin: 0 0 5px; padding-left: 5px; border-left: 2px solid #777777; color: #777777;"><blockquote style="margin: 0 0 5px; padding-left: 5px; border-left: 2px solid #777777; border-left-color: #999999; color: #999999;"><p dir="auto">* when those classes will be loaded (ie: somewhere in JVMS 5.3)</p>
</blockquote><p dir="auto">If the VM chooses to load Preload classes, then our thinking was that JVMS 5.4 already describes the details of timing:</p>
<p dir="auto"><a href="https://docs.oracle.com/javase/specs/jvms/se20/html/jvms-5.html#jvms-5.4" style="color: #777777;">https://docs.oracle.com/javase/specs/jvms/se20/html/jvms-5.html#jvms-5.4</a></p>
<p dir="auto">So, for example, "Alternatively, an implementation may choose an "eager" linkage strategy, where all symbolic references are resolved at once when the class or interface is being verified." That is, the Preload classes could all be loaded during verification, or at some other stage of linking.</p>
<p dir="auto">My expectation is that the natural point for processing Preload is during preparation as vtables are set up, but sometimes I get these things wrong. :-)</p>
</blockquote></div>
<div class="markdown" style="white-space: normal;">
<p dir="auto">Sometimes you want them early (for instance layout) and sometimes you need to wait (vtable layout or even just before <clinit>).</p>
</div><div class="plaintext" style="white-space: normal;"><blockquote style="margin: 0 0 5px; padding-left: 5px; border-left: 2px solid #777777; color: #777777;"><blockquote style="margin: 0 0 5px; padding-left: 5px; border-left: 2px solid #777777; border-left-color: #999999; color: #999999;"><p dir="auto">* how invalid cases are handled, including circularities (Class A's Preload mentions B <: A)</p>
</blockquote></blockquote></div>
<div class="markdown" style="white-space: normal;">
<p dir="auto">Silent supression of errors, if any.  Again, like a nop…</p>
</div><div class="plaintext" style="white-space: normal;"><blockquote style="margin: 0 0 5px; padding-left: 5px; border-left: 2px solid #777777; color: #777777;"><p dir="auto">"Errors detected during linkage are thrown at a point in the program where some action is taken by the program that might, directly or indirectly, require linkage to the class or interface involved in the error."</p>
<p dir="auto">I've always found this rule super vague, but I think "require" is the key word, and implies that errors caused by Preload resolution should just be ignored. (Because Preload isn't "required" to be processed at all.)</p>
<blockquote style="margin: 0 0 5px; padding-left: 5px; border-left: 2px solid #777777; border-left-color: #999999; color: #999999;"><p dir="auto">* what types of classes can be listed (any? only values?)</p>
</blockquote><p dir="auto">Definitely intend to support any classes of interest. Say a future optimization wants to know about a sealed superinterface, for example—it would be fine to tweak javac to add that interface to Preload, and then use the information to facilitate the optimization.</p>
<p dir="auto">There's a lot of nondeterminism here—can a compliant system trigger changes to class loading timing, but just on my birthday?—but I think it's within the scope of JVMS 5.4, which provides a lot of latitude for loading classes whenever it's convenient.</p>
<blockquote style="margin: 0 0 5px; padding-left: 5px; border-left: 2px solid #777777; border-left-color: #999999; color: #999999;"><p dir="auto">It probably makes sense to start from the current Hotspot handling of the attribute and fine tune that into the spec?</p>
</blockquote><p dir="auto">So I've outlined our hands-off stake in the ground above. The spec would definitely benefit, at least, from a non-normative cross-reference to 5.4 and short explanation. Beyond that, I think we'd be open to specifying more if we can agree something more is needed...</p>
</blockquote></div>
<div class="markdown" style="white-space: normal;">
<p dir="auto">I think we could get the benefits in Fred’s prototype (as he describes) with a list that is decoupled from any particular class file, and Leyden could deliver this list.</p>
<p dir="auto">As you see, I’m kind of sour on a Preload attribute these days.</p>

</div></div></body>

</html>