Skip to content
Permalink
Browse files
Added IdentityObject.newIdentity()
  • Loading branch information
Roger Riggs committed Mar 24, 2020
1 parent 092f642 commit 0bca2918eeed1df8bc1bc779d8af3f5813a61def
Showing 2 changed files with 21 additions and 2 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1994, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1994, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -27,6 +27,8 @@

import jdk.internal.HotSpotIntrinsicCandidate;

import java.util.Objects;

/**
* Class {@code Object} is the root of the class hierarchy.
* Every class has {@code Object} as a superclass. All objects,
@@ -40,6 +42,9 @@ public class Object {

/**
* Constructs a new object.
*
* @apiNote {@link Objects#newIdentity java.util.Objects.newIdentity()}
* should be used instead of {@code new Object()}.
*/
@HotSpotIntrinsicCandidate
public Object() {}
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2009, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2009, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -436,4 +436,18 @@ int checkFromIndexSize(int fromIndex, int size, int length) {
public static long getObjectSize(Object o) {
return Unsafe.getUnsafe().getObjectSize(o);
}

/**
* Returns a new Object implementing the {@code IdentityObject} interface.
* The object is a unique {@link IdentityObject} suitable for all purposes
* 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 a new instance of an anonymous inner class.
return new IdentityObject() { };
}
}

0 comments on commit 0bca291

Please sign in to comment.