< prev index next >

src/java.base/share/classes/jdk/internal/org/objectweb/asm/Type.java

Print this page
rev 55127 : 8223351: [lworld] Primary mirror and nullable mirror for inline type
Reviewed-by: tbd

@@ -57,10 +57,11 @@
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
 package jdk.internal.org.objectweb.asm;
 
 import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 
 /**
  * A Java field or method type. This class can be used to make it easier to manipulate type and
  * method descriptors.

@@ -665,27 +666,53 @@
                 throw new AssertionError();
             }
             stringBuilder.append(descriptor);
         } else {
             String name = currentClass.getName();
-            // Workarounds nasgen build that depends on ASM but compiled with
-            // the bootstrap JDK.  Can't use Class::isValue and Class::asValueType
-            int index = currentClass.getTypeName().lastIndexOf("/val");
-            if (index > 0) {
-                stringBuilder.append('Q');
-            } else {
+            if (Helper.isNullableType(currentClass)) {
                 stringBuilder.append('L');
+            } else {
+                stringBuilder.append('Q');
+
             }
             int nameLength = name.length();
             for (int i = 0; i < nameLength; ++i) {
                 char car = name.charAt(i);
                 stringBuilder.append(car == '.' ? '/' : car);
             }
             stringBuilder.append(';');
         }
     }
 
+    // Workarounds nasgen build that depends on ASM but compiled with
+    // the bootstrap JDK.  Can't reference Class::isNullableType
+    static class Helper {
+        static final Method isNullableTypeMethod = isNullableTypeMethod();
+        static Method isNullableTypeMethod() {
+            try {
+                return Class.class.getMethod("isNullableType");
+            } catch (NoSuchMethodException e) {
+                return null;
+            }
+        }
+
+        static boolean isNullableType(Class<?> clazz) {
+            int mods = clazz.getModifiers();
+            if ((mods & 0x00000100) != 0) {            // inline class
+                assert isNullableTypeMethod != null;
+                try {
+                    return (boolean)isNullableTypeMethod.invoke(clazz);
+                } catch (InvocationTargetException e) {
+                    throw new InternalError(e.getCause());
+                } catch (IllegalAccessException e) {
+                    throw new InternalError(e);
+                }
+            }
+            return true;
+        }
+    }
+
     // -----------------------------------------------------------------------------------------------
     // Methods to get the sort, dimension, size, and opcodes corresponding to a Type or descriptor.
     // -----------------------------------------------------------------------------------------------
 
     /**
< prev index next >