diff a/src/java.base/share/classes/java/lang/Object.java b/src/java.base/share/classes/java/lang/Object.java --- a/src/java.base/share/classes/java/lang/Object.java +++ b/src/java.base/share/classes/java/lang/Object.java @@ -38,15 +38,36 @@ */ public class Object { /** * Constructs a new object. + * @apiNote {@link Object#newIdentity} should be used instead of {@code new Object()}. */ @HotSpotIntrinsicCandidate public Object() {} /** + * Constructs a new Object implementing the IdentityObject interface. + * The object is a unique IdentityObject suitable for all purposes + * that previously for which {@code new Object{}} was used including synchronization, + * mutexes and unique placeholders. + * + * @return a new Object implementing the IdentityObject interface + * @since Valhalla + */ + public static IdentityObject newIdentity() { + return new IdentityInstance(); + } + + /** + * IdentityInstance replaces plain {@code new Object()}. + */ + private final static class IdentityInstance implements IdentityObject { + private IdentityInstance() {} + } + + /** * Returns the runtime class of this {@code Object}. The returned * {@code Class} object is the object that is locked by {@code * static synchronized} methods of the represented class. * *

The actual result type is {@code Class}