<!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">On 1 Jun 2023, at 12:34, Brian Goetz wrote:</p>
</div><blockquote class="embedded" style="margin: 0 0 5px; padding-left: 5px; border-left: 2px solid #777777; color: #777777;"><div id="91B88780-877B-4825-95AE-44ED5EDDD65F">
<br>
<br>
<div class="moz-cite-prefix">On 6/1/2023 2:32 PM, Dan Heidinga wrote:<br></div>
<blockquote type="cite" cite="mid:CAJq4Gi5FCxxnuSAEbdLC2n3zETL3ozXwCwu+omMGZ4UxA=YrVQ@mail.gmail.com">
<div dir="ltr">
<div dir="ltr"><br></div>
<br>
<div class="gmail_quote">
<div dir="ltr" class="gmail_attr">On Thu, Jun 1, 2023 at 1:59 PM Brian Goetz <<a href="mailto:brian.goetz@oracle.com" moz-do-not-send="true" class="moz-txt-link-freetext">brian.goetz@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><font size="4"><font face="monospace">I think that there should be an explicit (and not synthetic) method_info for the implicit constructor, with the obvious Code attribute (`defaultvalue` / `areturn`.) </font></font></div>
</blockquote>
<div><br></div>
<div>I'm slightly concerned about having a Code attribute for the implicit constructor as it allows agents (ClassFile load hook & redefinition) to modify the bytecodes to be inconsistent with the VM's behaviour given the VM won't actually call the implicit constructor.</div>
<div><br></div>
<div>Telling users it's "as if" the VM called the implicit ctor and then having the reflective behaviour be different after retransformation is slightly uncomfortable.</div>
</div>
</div>
</blockquote>
<br>
I'm fine if the expansion of the constructor body happens at runtime rather than compile time; my suggestion was mostly "this is super-easy in the static compiler, why make more work for the JVM." But, if you're signing up for that work, I won't stop you....<br>
<br>
<br></div></blockquote>
<div class="markdown" style="white-space: normal;"><p dir="auto"><br>
I haven’t signed up the JVM for that work! It seems like busy-work to me. JVM code which implements some busy-work requirement costs money for no benefit, and its (inevitable) bug tail risks increased attack surfaces.</p>
<p dir="auto">I’m assuming (a) the <code style="margin: 0; padding: 0 0.4em; border-radius: 3px; background-color: #F7F7F7;">aconst_default</code> bytecode is not API (it’s private) and therefore that (b) any materialization of a default value will go through either the class’s API (real <code style="margin: 0; padding: 0 0.4em; border-radius: 3px; background-color: #F7F7F7;">new C()</code>) or else via some reflective API point (<code style="margin: 0; padding: 0 0.4em; border-radius: 3px; background-color: #F7F7F7;">C.class.defaultValue()</code>). Maybe something very simple like:</p>
<pre style="margin-left: 15px; margin-right: 15px; padding: 5px; background-color: #F7F7F7; border-radius: 5px 5px 5px 5px; overflow-x: auto; max-width: 90vw;"><code style="margin: 0; border-radius: 3px; background-color: #F7F7F7; padding: 0px;">C defaultValue() {
// if the next line throws an exception, it goes to the client
var a1 = Array.newInstance(asNonNullable(), 1);
// at this point we know C has a default value
return (C ) Array.get(a1, 0);
//OR?? return this.newInstance();
}
</code></pre>
<p dir="auto">Regarding the problem of agents, I’d say either we don’t care what a buggy agent does, or else we can might add an implementation restriction that refuses to allow a buggy agent to load an implicit constructor with a bad body.</p>
<p dir="auto">Agents can modify all sorts of JDK internals. (Also non-javac-spun classfiles explore all sorts of odd states.) We can’t play whack-a-mole trying to prevent all kinds of agent misbehavior. That would just end up creating an endless parade of costs and bugs.</p>
<p dir="auto">And I don’t want to add a verification rule; the costs of tweaking the verifier far outweigh the benefits. Let’s give some basic trust our classfile generators and agents.</p>
</div></div></body>
</html>