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

Roger Riggs Roger.Riggs at oracle.com
Fri Feb 28 18:21:00 UTC 2020


Hi Mandy,

We can add the @deprecated later when we get closer to the whole 
replacing it implementation.

BTW, What should happen to the Annotation on new Object: 
"@HotSpotIntrinsicCandidate'?
Who decides about that, does it move to the static factory or to the 
constructor of the implementation
or is it just unnecessary.

Yep, there are a *lot* of uses of new Object() in many modules.

By module: Total 504 - (via fgrep/awk)
java.base: 109
java.datatransfer: 1
java.desktop: 121
java.logging: 1
java.management: 5
java.naming: 1
java.net <http://java.net/>.http: 10
java.prefs: 1
java.rmi: 5
java.security.jgss: 2
java.sql: 2
java.xml: 1
jdk.accessibility: 2
jdk.attach: 1
jdk.compiler: 3
jdk.crypto.cryptoki: 4
jdk.dynalink: 2
jdk.hotspot.agent: 9
jdk.httpserver: 4
jdk.incubator.jpackage: 3
jdk.internal.le: 5
jdk.internal.vm.compiler: 142
jdk.jconsole: 3
jdk.jdi: 8
jdk.jfr: 7
jdk.jshell: 3
jdk.management: 1
jdk.management.agent: 1
jdk.naming.dns: 2
jdk.scripting.nashorn: 37
jdk.sctp: 8 Roger


On 2/28/20 12:02 PM, Mandy Chung wrote:
> 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