[lworld] RFR: 8237073: [lworld] Need special handling of jlO constructor invocation

Mandy Chung mchung at openjdk.java.net
Fri Jul 16 00:31:33 UTC 2021


On Thu, 15 Jul 2021 12:11:15 GMT, Srikanth Adayapalam <sadayapalam at openjdk.org> wrote:

> Translate new Object() instantiations down to invovations of java.util.Objects.newIdentity() call with an informational message at compie time

For `src/java.base/share/classes/java/lang/invoke/ClassSpecializer.java`, I suggest to replace it with a specific class like this:


diff --git a/src/java.base/share/classes/java/lang/invoke/ClassSpecializer.java b/src/java.base/share/classes/java/lang/invoke/ClassSpecializer.java
index b3c149492ac..a0707150cfa 100644
--- a/src/java.base/share/classes/java/lang/invoke/ClassSpecializer.java
+++ b/src/java.base/share/classes/java/lang/invoke/ClassSpecializer.java
@@ -152,12 +152,14 @@ abstract class ClassSpecializer<T,K,S extends ClassSpecializer<T,K,S>.SpeciesDat
         return new IllegalArgumentException(message, cause);
     }
 
-    private static final Function<Object, Object> CREATE_RESERVATION = new Function<>() {
-        @Override
-        public Object apply(Object key) {
-            return new Object();
-        }
-    };
+    static class CacheHolder {
+        static final Function<Object, Object> CREATE = new Function<>() {
+            @Override
+            public Object apply(Object key) {
+                return new CacheHolder();
+            }
+        };
+    }
 
     public final S findSpecies(K key) {
         // Note:  Species instantiation may throw VirtualMachineError because of
@@ -180,12 +182,12 @@ abstract class ClassSpecializer<T,K,S extends ClassSpecializer<T,K,S>.SpeciesDat
         // concrete class if ever.
         // The concrete class is published via SpeciesData instance
         // returned here only after the class and species data are linked together.
-        Object speciesDataOrReservation = cache.computeIfAbsent(key, CREATE_RESERVATION);
+        Object speciesDataOrReservation = cache.computeIfAbsent(key, CacheHolder.CREATE);
         // Separating the creation of a placeholder SpeciesData instance above
         // from the loading and linking a real one below ensures we can never
         // accidentally call computeIfAbsent recursively.
         S speciesData;
-        if (speciesDataOrReservation.getClass() == Object.class) {
+        if (speciesDataOrReservation.getClass() == CacheHolder.class) {
             synchronized (speciesDataOrReservation) {
                 Object existingSpeciesData = cache.get(key);
                 if (existingSpeciesData == speciesDataOrReservation) { // won the race

-------------

PR: https://git.openjdk.java.net/valhalla/pull/481


More information about the valhalla-dev mailing list