RFR [lworld] 8239929: Object.newIdentity() replacement for new Object()

Mandy Chung mandy.chung at oracle.com
Thu Feb 27 22:40:04 UTC 2020


I think we should add @Deprecated in the Object constructor.

Otherwise, looks fine.

Mandy

On 2/25/20 11:20 AM, Roger Riggs wrote:
> Please review the static factory of an IdentityObject to replace "new 
> Object()"
> as mentioned in [1].
>
> No replacements proposed yet.  There are 504 instances of "new 
> Object()" in JDK modules.
> @@ -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() {}
> +    }
> +
>
>
> As a Webrev:
> http://cr.openjdk.java.net/~rriggs/webrev-object-newinstance-8239929/
>
> Thanks, Roger
>
> [1] 
> http://cr.openjdk.java.net/~briangoetz/valhalla/sov/02-object-model.html



More information about the valhalla-dev mailing list