JEP draft: Identity Warnings for Inline Class Candidates

OwnerDan Smith
Created2020/07/08 21:39
Updated2020/07/13 06:11


Provide warnings at compile time and runtime for behaviors that will change when certain classes of the Java SE APIs become inline classes.


The Valhalla Project is pursuing a significant enhancement to the Java programming model in the form of inline classes. Such classes declare their instances to be identity-free and capable of "inline" or "flattened" representations, where instances can be copied freely between memory locations and encoded using solely the values of the instances' fields.

Because inline class instances lack a unique identity, they are unsuitable for certain operations. Specifically:

There may also be constraints on inline class declarations preventing overriding of the Object methods clone and finalize and preventing the declaration of synchronized methods.

A number of classes in the Java SE API are candidates to become inline classes. In order to prepare users for the errors that will occur when those classes become inline, the javac compiler and Hotspot runtime should generate warnings now about anticipated errors in a future release.


We specifically anticipate that the following are likely to become inline classes:

It may be useful to define an annotation to identify these classes, interfaces, and factory methods.

The following changes alert clients of these APIs about operations that may fail in a future release:

In a future release, when the inline class migration occurs, the runtime warnings will be superseded by a standard error. At compile time, synchronization on an inline class type may also trigger a standard error, but it's also quite possible that there will still be a need for warnings where they involve interface types.


We could abandon efforts to migrate these classes to be inline classes. However, there are significant benefits that clients will enjoy when we complete the migration, and the relative impact on clients who depend on problematic behavior is quite small. (In fact, in most cases they have been warned by the API documentation not to perform synchronization.)

Risks and Assumptions

There is a risk that these classes never become inline classes. Even so, the synchronization warnings will be helpful, given the limited guarantees made about the identity of instances of these classes. It will also be useful progress to fully remove the wrapper class constructors.