Re: [jdk17] RFR: 8269096: Add java.util.Objects.newIdentity method [v5]
- Original Message - > From: "Roger Riggs" > To: "core-libs-dev" > Sent: Mardi 29 Juin 2021 18:44:04 > Subject: Re: [jdk17] RFR: 8269096: Add java.util.Objects.newIdentity method > [v5] > On Tue, 29 Jun 2021 05:47:03 GMT, Tagir F. Valeev wrote: > >>> Roger Riggs has updated the pull request incrementally with one additional >>> commit since the last revision: >>> >>> Add test synchronizing on return value of Objecst.newIdentity() >> >> Probably it would be better to have an inner class named like `Identity` >> instead >> of anonymous class? When debugging or analyzing memory dumps, it would be >> more >> user-friendly to see `Objects$Identity` than `Objects$1`. >> >> Probably, not the part of this feature request, but it would be nice to add >> another method with string parameter, like `Objects.newIdentity("MY >> SENTINEL")`. The string should be stored in the field and returned from >> toString(). Again, this would make it easier to find where the object comes >> from during debugging or memory dump analysis. For the record, here's what we >> have in IntelliJ IDEA sources (Apache 2.0 licensed): >> >> >> public final class ObjectUtils { >> private ObjectUtils() { } >> >> ... >> >> /** >>* Creates a new object which could be used as sentinel value (special >> value to >>distinguish from any other object). It does not equal >>* to any other object. Usually should be assigned to the static final >> field. >>* >>* @param name an object name, returned from {@link #toString()} to >> simplify the >>debugging or heap dump analysis >>* (guaranteed to be stored as sentinel object field). If >> sentinel is >>assigned to the static final field, >>* it's recommended to supply that field name (possibly >> qualified >>with the class name). >>* @return a new sentinel object >>*/ >> public static @NotNull Object sentinel(@NotNull @NonNls String name) { >> return new Sentinel(name); >> } >> >> private static final class Sentinel { >> private final String myName; >> >> Sentinel(@NotNull String name) { >> myName = name; >> } >> >> @Override >> public String toString() { >> return myName; >> } >> } > > @amaembo Good suggestion for the Valhalla API and implementation. Today, only > the hashCode() identifies an Object. > For JDK17, it will continue to be a raw Object() instance. We should try to have a very limited API surface for now. We want to let the door open to having Object being both an identity class (when used with "new") and an abstract class (when inherited) by using two different generic specialization of the same class or whatever other scheme we come before Valhalla is complete. > > - > > PR: https://git.openjdk.java.net/jdk17/pull/112 RĂ©mi
Re: [jdk17] RFR: 8269096: Add java.util.Objects.newIdentity method [v5]
On Tue, 29 Jun 2021 05:47:03 GMT, Tagir F. Valeev wrote: >> Roger Riggs has updated the pull request incrementally with one additional >> commit since the last revision: >> >> Add test synchronizing on return value of Objecst.newIdentity() > > Probably it would be better to have an inner class named like `Identity` > instead of anonymous class? When debugging or analyzing memory dumps, it > would be more user-friendly to see `Objects$Identity` than `Objects$1`. > > Probably, not the part of this feature request, but it would be nice to add > another method with string parameter, like `Objects.newIdentity("MY > SENTINEL")`. The string should be stored in the field and returned from > toString(). Again, this would make it easier to find where the object comes > from during debugging or memory dump analysis. For the record, here's what we > have in IntelliJ IDEA sources (Apache 2.0 licensed): > > > public final class ObjectUtils { > private ObjectUtils() { } > > ... > > /** >* Creates a new object which could be used as sentinel value (special > value to distinguish from any other object). It does not equal >* to any other object. Usually should be assigned to the static final > field. >* >* @param name an object name, returned from {@link #toString()} to > simplify the debugging or heap dump analysis >* (guaranteed to be stored as sentinel object field). If > sentinel is assigned to the static final field, >* it's recommended to supply that field name (possibly > qualified with the class name). >* @return a new sentinel object >*/ > public static @NotNull Object sentinel(@NotNull @NonNls String name) { > return new Sentinel(name); > } > > private static final class Sentinel { > private final String myName; > > Sentinel(@NotNull String name) { > myName = name; > } > > @Override > public String toString() { > return myName; > } > } @amaembo Good suggestion for the Valhalla API and implementation. Today, only the hashCode() identifies an Object. For JDK17, it will continue to be a raw Object() instance. - PR: https://git.openjdk.java.net/jdk17/pull/112
Re: [jdk17] RFR: 8269096: Add java.util.Objects.newIdentity method [v5]
On Mon, 28 Jun 2021 19:45:34 GMT, Roger Riggs wrote: >> Add java.util.Objects.newIdentity to supply a unique object with identity. >> This is a replacement code can be used today for the traditional new >> Object() idiom, which will be deprecated under Project Valhalla. >> Refer to [JEP 401: Primitive Objects >> (Preview)](https://openjdk.java.net/jeps/401) for background. > > Roger Riggs has updated the pull request incrementally with one additional > commit since the last revision: > > Add test synchronizing on return value of Objecst.newIdentity() Probably it would be better to have an inner class named like `Identity` instead of anonymous class? When debugging or analyzing memory dumps, it would be more user-friendly to see `Objects$Identity` than `Objects$1`. Probably, not the part of this feature request, but it would be nice to add another method with string parameter, like `Objects.newIdentity("MY SENTINEL")`. The string should be stored in the field and returned from toString(). Again, this would make it easier to find where the object comes from during debugging or memory dump analysis. For the record, here's what we have in IntelliJ IDEA sources (Apache 2.0 licensed): public final class ObjectUtils { private ObjectUtils() { } ... /** * Creates a new object which could be used as sentinel value (special value to distinguish from any other object). It does not equal * to any other object. Usually should be assigned to the static final field. * * @param name an object name, returned from {@link #toString()} to simplify the debugging or heap dump analysis * (guaranteed to be stored as sentinel object field). If sentinel is assigned to the static final field, * it's recommended to supply that field name (possibly qualified with the class name). * @return a new sentinel object */ public static @NotNull Object sentinel(@NotNull @NonNls String name) { return new Sentinel(name); } private static final class Sentinel { private final String myName; Sentinel(@NotNull String name) { myName = name; } @Override public String toString() { return myName; } } - PR: https://git.openjdk.java.net/jdk17/pull/112
Re: [jdk17] RFR: 8269096: Add java.util.Objects.newIdentity method [v5]
> Add java.util.Objects.newIdentity to supply a unique object with identity. > This is a replacement code can be used today for the traditional new Object() > idiom, which will be deprecated under Project Valhalla. > Refer to [JEP 401: Primitive Objects > (Preview)](https://openjdk.java.net/jeps/401) for background. Roger Riggs has updated the pull request incrementally with one additional commit since the last revision: Add test synchronizing on return value of Objecst.newIdentity() - Changes: - all: https://git.openjdk.java.net/jdk17/pull/112/files - new: https://git.openjdk.java.net/jdk17/pull/112/files/eef1029c..f99d0846 Webrevs: - full: https://webrevs.openjdk.java.net/?repo=jdk17=112=04 - incr: https://webrevs.openjdk.java.net/?repo=jdk17=112=03-04 Stats: 12 lines in 1 file changed: 12 ins; 0 del; 0 mod Patch: https://git.openjdk.java.net/jdk17/pull/112.diff Fetch: git fetch https://git.openjdk.java.net/jdk17 pull/112/head:pull/112 PR: https://git.openjdk.java.net/jdk17/pull/112
Re: [jdk17] RFR: 8269096: Add java.util.Objects.newIdentity method [v5]
On Mon, 28 Jun 2021 19:45:34 GMT, Roger Riggs wrote: >> Add java.util.Objects.newIdentity to supply a unique object with identity. >> This is a replacement code can be used today for the traditional new >> Object() idiom, which will be deprecated under Project Valhalla. >> Refer to [JEP 401: Primitive Objects >> (Preview)](https://openjdk.java.net/jeps/401) for background. > > Roger Riggs has updated the pull request incrementally with one additional > commit since the last revision: > > Add test synchronizing on return value of Objecst.newIdentity() Marked as reviewed by jvernee (Reviewer). - PR: https://git.openjdk.java.net/jdk17/pull/112
Re: [jdk17] RFR: 8269096: Add java.util.Objects.newIdentity method [v4]
On Wed, 23 Jun 2021 19:21:02 GMT, Roger Riggs wrote: >> Add java.util.Objects.newIdentity to supply a unique object with identity. >> This is a replacement code can be used today for the traditional new >> Object() idiom, which will be deprecated under Project Valhalla. >> Refer to [JEP 401: Primitive Objects >> (Preview)](https://openjdk.java.net/jeps/401) for background. > > Roger Riggs has updated the pull request incrementally with one additional > commit since the last revision: > > Updated spec of Objects.newIdentity with: > "The class does not override any of the methods of {@code > java.lang.Object}." test/jdk/java/util/Objects/BasicObjectsTest.java line 48: > 46: errors += testNonNull(); > 47: errors += testNonNullOf(); > 48: errors += testNewIdentity(); The javadoc of `Objects::newIdentity` claims `[the returned object] can be used for synchronization`. Would it be useful to add a test that tries to synchronize on the result of `Objects.newIdentity` for that as well? - PR: https://git.openjdk.java.net/jdk17/pull/112
Re: [jdk17] RFR: 8269096: Add java.util.Objects.newIdentity method [v4]
> Add java.util.Objects.newIdentity to supply a unique object with identity. > This is a replacement code can be used today for the traditional new Object() > idiom, which will be deprecated under Project Valhalla. > Refer to [JEP 401: Primitive Objects > (Preview)](https://openjdk.java.net/jeps/401) for background. Roger Riggs has updated the pull request incrementally with one additional commit since the last revision: Updated spec of Objects.newIdentity with: "The class does not override any of the methods of {@code java.lang.Object}." - Changes: - all: https://git.openjdk.java.net/jdk17/pull/112/files - new: https://git.openjdk.java.net/jdk17/pull/112/files/bc73f6dd..eef1029c Webrevs: - full: https://webrevs.openjdk.java.net/?repo=jdk17=112=03 - incr: https://webrevs.openjdk.java.net/?repo=jdk17=112=02-03 Stats: 1 line in 1 file changed: 1 ins; 0 del; 0 mod Patch: https://git.openjdk.java.net/jdk17/pull/112.diff Fetch: git fetch https://git.openjdk.java.net/jdk17 pull/112/head:pull/112 PR: https://git.openjdk.java.net/jdk17/pull/112
Re: [jdk17] RFR: 8269096: Add java.util.Objects.newIdentity method [v3]
On Tue, 22 Jun 2021 16:18:11 GMT, Roger Riggs wrote: >> Add java.util.Objects.newIdentity to supply a unique object with identity. >> This is a replacement code can be used today for the traditional new >> Object() idiom, which will be deprecated under Project Valhalla. >> Refer to [JEP 401: Primitive Objects >> (Preview)](https://openjdk.java.net/jeps/401) for background. > > Roger Riggs has updated the pull request incrementally with one additional > commit since the last revision: > > Update copyright in BasicObjectsTest Marked as reviewed by chegar (Reviewer). - PR: https://git.openjdk.java.net/jdk17/pull/112
Re: [jdk17] RFR: 8269096: Add java.util.Objects.newIdentity method [v3]
On Tue, 22 Jun 2021 18:01:46 GMT, Chris Hegarty wrote: >> Roger Riggs has updated the pull request incrementally with one additional >> commit since the last revision: >> >> Update copyright in BasicObjectsTest > > src/java.base/share/classes/java/util/Objects.java line 492: > >> 490: /** >> 491: * {@return a new instance of an unspecified class} >> 492: * The object has a unique identity; no other references to it >> exist. > > Is this a new javadoc style/tag ? Yes, it optimizes the case where the first sentence and the @ return tags have the same string. See [JDK-8075778](https://bugs.openjdk.java.net/browse/JDK-8075778): Add javadoc tag to avoid duplication of return information in simple situations. - PR: https://git.openjdk.java.net/jdk17/pull/112
Re: [jdk17] RFR: 8269096: Add java.util.Objects.newIdentity method [v3]
On Tue, 22 Jun 2021 16:18:11 GMT, Roger Riggs wrote: >> Add java.util.Objects.newIdentity to supply a unique object with identity. >> This is a replacement code can be used today for the traditional new >> Object() idiom, which will be deprecated under Project Valhalla. >> Refer to [JEP 401: Primitive Objects >> (Preview)](https://openjdk.java.net/jeps/401) for background. > > Roger Riggs has updated the pull request incrementally with one additional > commit since the last revision: > > Update copyright in BasicObjectsTest src/java.base/share/classes/java/util/Objects.java line 492: > 490: /** > 491: * {@return a new instance of an unspecified class} > 492: * The object has a unique identity; no other references to it exist. Is this a new javadoc style/tag ? - PR: https://git.openjdk.java.net/jdk17/pull/112
Re: [jdk17] RFR: 8269096: Add java.util.Objects.newIdentity method [v3]
On Tue, 22 Jun 2021 16:18:11 GMT, Roger Riggs wrote: >> Add java.util.Objects.newIdentity to supply a unique object with identity. >> This is a replacement code can be used today for the traditional new >> Object() idiom, which will be deprecated under Project Valhalla. >> Refer to [JEP 401: Primitive Objects >> (Preview)](https://openjdk.java.net/jeps/401) for background. > > Roger Riggs has updated the pull request incrementally with one additional > commit since the last revision: > > Update copyright in BasicObjectsTest Marked as reviewed by naoto (Reviewer). - PR: https://git.openjdk.java.net/jdk17/pull/112
Re: [jdk17] RFR: 8269096: Add java.util.Objects.newIdentity method [v3]
On Tue, 22 Jun 2021 16:18:11 GMT, Roger Riggs wrote: >> Add java.util.Objects.newIdentity to supply a unique object with identity. >> This is a replacement code can be used today for the traditional new >> Object() idiom, which will be deprecated under Project Valhalla. >> Refer to [JEP 401: Primitive Objects >> (Preview)](https://openjdk.java.net/jeps/401) for background. > > Roger Riggs has updated the pull request incrementally with one additional > commit since the last revision: > > Update copyright in BasicObjectsTest Marked as reviewed by bpb (Reviewer). - PR: https://git.openjdk.java.net/jdk17/pull/112
Re: [jdk17] RFR: 8269096: Add java.util.Objects.newIdentity method [v3]
On Tue, 22 Jun 2021 16:18:11 GMT, Roger Riggs wrote: >> Add java.util.Objects.newIdentity to supply a unique object with identity. >> This is a replacement code can be used today for the traditional new >> Object() idiom, which will be deprecated under Project Valhalla. >> Refer to [JEP 401: Primitive Objects >> (Preview)](https://openjdk.java.net/jeps/401) for background. > > Roger Riggs has updated the pull request incrementally with one additional > commit since the last revision: > > Update copyright in BasicObjectsTest Marked as reviewed by mchung (Reviewer). - PR: https://git.openjdk.java.net/jdk17/pull/112
Re: [jdk17] RFR: 8269096: Add java.util.Objects.newIdentity method [v3]
> Add java.util.Objects.newIdentity to supply a unique object with identity. > This is a replacement code can be used today for the traditional new Object() > idiom, which will be deprecated under Project Valhalla. > Refer to [JEP 401: Primitive Objects > (Preview)](https://openjdk.java.net/jeps/401) for background. Roger Riggs has updated the pull request incrementally with one additional commit since the last revision: Update copyright in BasicObjectsTest - Changes: - all: https://git.openjdk.java.net/jdk17/pull/112/files - new: https://git.openjdk.java.net/jdk17/pull/112/files/42883a17..bc73f6dd Webrevs: - full: https://webrevs.openjdk.java.net/?repo=jdk17=112=02 - incr: https://webrevs.openjdk.java.net/?repo=jdk17=112=01-02 Stats: 1 line in 1 file changed: 0 ins; 0 del; 1 mod Patch: https://git.openjdk.java.net/jdk17/pull/112.diff Fetch: git fetch https://git.openjdk.java.net/jdk17 pull/112/head:pull/112 PR: https://git.openjdk.java.net/jdk17/pull/112
Re: [jdk17] RFR: 8269096: Add java.util.Objects.newIdentity method [v2]
> Add java.util.Objects.newIdentity to supply a unique object with identity. > This is a replacement code can be used today for the traditional new Object() > idiom, which will be deprecated under Project Valhalla. > Refer to [JEP 401: Primitive Objects > (Preview)](https://openjdk.java.net/jeps/401) for background. Roger Riggs has updated the pull request incrementally with one additional commit since the last revision: Add @see link to java.lang.Object to Objects.newIdentity - Changes: - all: https://git.openjdk.java.net/jdk17/pull/112/files - new: https://git.openjdk.java.net/jdk17/pull/112/files/6c871906..42883a17 Webrevs: - full: https://webrevs.openjdk.java.net/?repo=jdk17=112=01 - incr: https://webrevs.openjdk.java.net/?repo=jdk17=112=00-01 Stats: 3 lines in 1 file changed: 3 ins; 0 del; 0 mod Patch: https://git.openjdk.java.net/jdk17/pull/112.diff Fetch: git fetch https://git.openjdk.java.net/jdk17 pull/112/head:pull/112 PR: https://git.openjdk.java.net/jdk17/pull/112
Re: [jdk17] RFR: 8269096: Add java.util.Objects.newIdentity method
On Mon, 21 Jun 2021 22:25:49 GMT, Roger Riggs wrote: > Add java.util.Objects.newIdentity to supply a unique object with identity. > This is a replacement code can be used today for the traditional new Object() > idiom, which will be deprecated under Project Valhalla. > Refer to [JEP 401: Primitive Objects > (Preview)](https://openjdk.java.net/jeps/401) for background. Looks okay in general. It'd be useful for the javadoc of `Object()` constructor to suggest using `Objects::newIdentity` instead of the constructor. - PR: https://git.openjdk.java.net/jdk17/pull/112
[jdk17] RFR: 8269096: Add java.util.Objects.newIdentity method
Add java.util.Objects.newIdentity to supply a unique object with identity. This is a replacement code can be used today for the traditional new Object() idiom, which will be deprecated under Project Valhalla. Refer to [JEP 401: Primitive Objects (Preview)](https://openjdk.java.net/jeps/401) for background. - Commit messages: - Copyright update and cleanup punctuation - 8269096: Add java.util.Objects.newIdentity method Changes: https://git.openjdk.java.net/jdk17/pull/112/files Webrev: https://webrevs.openjdk.java.net/?repo=jdk17=112=00 Issue: https://bugs.openjdk.java.net/browse/JDK-8269096 Stats: 29 lines in 2 files changed: 28 ins; 0 del; 1 mod Patch: https://git.openjdk.java.net/jdk17/pull/112.diff Fetch: git fetch https://git.openjdk.java.net/jdk17 pull/112/head:pull/112 PR: https://git.openjdk.java.net/jdk17/pull/112