implicit constructor translation?
Dan Smith
daniel.smith at oracle.com
Thu Jun 1 18:49:19 UTC 2023
> On Jun 1, 2023, at 11:32 AM, Dan Heidinga <heidinga at redhat.com> wrote:
>
> On Thu, Jun 1, 2023 at 1:59 PM Brian Goetz <brian.goetz at oracle.com> wrote:
>> I think that there should be an explicit (and not synthetic) method_info for the implicit constructor, with the obvious Code attribute (`defaultvalue` / `areturn`.)
>>
> 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.
>
> 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.
The problem here is we have a language/VM model mismatch.
In the VM model: <vnew> is a factory method that can do whatever it wants, and be included or not included. All that matters for default values is ImplicitCreation.
In the language model: the implicit constructor allows both 'Foo.default' and 'new Foo()', both of which produce the same value.
Yes, it's possible to generate bytecode that doesn't conform to the language model, that's always the risk of designing a language/VM mismatch. But this feels to me like more of the same in the constructor space—e.g., we've already got VM-level abstract classes that can have <init> methods that won't run for value class instance creation, but will run for identity class instance creation.
More information about the valhalla-spec-observers
mailing list