RFR [lworld] 8239929: Object.newIdentity() replacement for new Object()
Roger Riggs
Roger.Riggs at oracle.com
Tue Feb 25 19:20:25 UTC 2020
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