On Wed, 1 Jul 2026 07:51:43 GMT, David Holmes <[email protected]> wrote:

>> JVMTI ForceEarlyReturnVoid can be used to return early from a constructor or 
>> class initializer. Early return from a constructor with strictly-initialized 
>> instance fields is problematic, as is early return from a class initializer 
>> when there are strictly-initialized static fields. The proposal for the 
>> initial integration is to keep it simple and just disallow 
>> ForceEarlyReturnVoid to return early from a value class constructor.
>> 
>> ---------
>> - [x] I confirm that I make this contribution in accordance with the 
>> [OpenJDK Interim AI Policy](https://openjdk.org/legal/ai).
>
> src/hotspot/share/prims/jvmti.xml line 3387:
> 
>> 3385:         <p/>
>> 3386:         This function can not be used to return early from the 
>> constructor
>> 3387:         of a value class.
> 
> FWIW I don't think you can define sensible semantics for early return from a 
> constructor with non-value types. What does it mean for final fields for 
> example, if you can re-execute a constructor?

ForceEarlyReturnVoid can be used to return early from a constructor. A crazy 
thing to do as it leaves things uninitialized or in an inconsistent state. It 
means that some final fields may have their default value.

All we're doing here is taming it for value class constructors as the instance 
fields are strictly-initialized and it would be ever more crazy and problematic 
to allow early return before the fields have been initialized. It would be 
possible to make this more finer grain, meaning don't allow return before super 
but that could be more long term if needed.

-------------

PR Review Comment: 
https://git.openjdk.org/valhalla/pull/2604#discussion_r3504273025

Reply via email to