On Tue, 30 Jun 2026 16:58:47 GMT, Alan Bateman <[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 3380:

> 3378:       <description>
> 3379:         This function can be used to return from a method with a return 
> type
> 3380:         of <code>void</code>, a constructor or a class initializer.

I thought class initializers were implicitly disallowed because the caller you 
are returning to must be a Java frame?

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?

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

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

Reply via email to