RFR [lworld] 8239929: Object.newIdentity() replacement for new Object()
Mandy Chung
mandy.chung at oracle.com
Fri Feb 28 17:02:06 UTC 2020
Maybe suppress the warning from java.base in the build for the time
being. Any other module using new Object()?
Mandy
On 2/27/20 6:06 PM, Roger Riggs wrote:
> Hi Mandy,
>
> I don't think we are ready for the storm of compiler warnings.
> There are 100 in java.base alone. We can change that later when we
> are ready to phase it in.
>
> Roger
>
>
> On 2/27/20 5:40 PM, Mandy Chung wrote:
>> 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