changeset 52830:248cd28491c1 nestmates

Use requested class name for non-findable class
author mchung
date Wed, 07 Nov 2018 15:09:20 -0800
parents fe6635dd87e6
children 8c1871e941dc
files src/hotspot/share/classfile/classFileParser.cpp src/java.base/share/classes/java/lang/Class.java src/java.base/share/classes/java/lang/invoke/InvokerBytecodeGenerator.java src/java.base/share/classes/java/lang/invoke/MethodHandles.java src/java.base/share/classes/jdk/internal/reflect/NativeConstructorAccessorImpl.java src/java.base/share/classes/jdk/internal/reflect/NativeMethodAccessorImpl.java src/java.base/share/classes/jdk/internal/reflect/ReflectionFactory.java src/java.base/share/classes/sun/reflect/misc/ReflectUtil.java test/jdk/ProblemList.txt test/jdk/java/lang/StackWalker/VerifyStackTrace.java test/jdk/java/lang/invoke/defineClass/DefineClassTest.java test/jdk/java/lang/invoke/defineClass/DefineClassWithClassData.java
diffstat 12 files changed, 49 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- a/src/hotspot/share/classfile/classFileParser.cpp	Wed Nov 07 15:34:41 2018 -0500
+++ b/src/hotspot/share/classfile/classFileParser.cpp	Wed Nov 07 15:09:20 2018 -0800
@@ -6144,6 +6144,15 @@
                        CHECK);
   }
 
+  // For nonfindable classes, fix up the class name to the
+  // requested name.
+  if (_requested_name != NULL &&
+      _requested_name != _class_name &&
+      _is_nonfindable) {
+    _class_name = (Symbol*)_requested_name;
+    cp->symbol_at_put(cp->klass_name_index_at(_this_class_index), _class_name);
+  }
+
   // Checks if name in class file matches requested name
   if (_requested_name != NULL && _requested_name != _class_name) {
     ResourceMark rm(THREAD);
--- a/src/java.base/share/classes/java/lang/Class.java	Wed Nov 07 15:34:41 2018 -0500
+++ b/src/java.base/share/classes/java/lang/Class.java	Wed Nov 07 15:09:20 2018 -0800
@@ -4087,7 +4087,15 @@
      * @see MethodHandles.Lookup#defineClass(byte[], MethodHandles.Lookup.ClassProperty[])
      */
     public boolean isHidden() {
-        // TODO: replace this with VM support
-        return ReflectUtil.isVMAnonymousClass(this);
+        return getName().indexOf('\\') > -1 || isVMAnonymousClass();
+    }
+
+    /**
+     * Checks if this {@code Class} is a VM-anonymous class
+     * as defined by {@link jdk.internal.misc.Unsafe#defineAnonymousClass}
+     * (not to be confused with a Java Language anonymous inner class).
+     */
+    private boolean isVMAnonymousClass() {
+        return getName().indexOf('/') > -1;
     }
 }
--- a/src/java.base/share/classes/java/lang/invoke/InvokerBytecodeGenerator.java	Wed Nov 07 15:34:41 2018 -0500
+++ b/src/java.base/share/classes/java/lang/invoke/InvokerBytecodeGenerator.java	Wed Nov 07 15:09:20 2018 -0800
@@ -1027,7 +1027,7 @@
             return false;  // inner class of some sort
         if (cls.getClassLoader() != MethodHandle.class.getClassLoader())
             return false;  // not on BCP
-        if (ReflectUtil.isVMAnonymousClass(cls)) // FIXME: switch to supported API once it is added
+        if (cls.isHidden())
             return false;
         if (!isStaticallyInvocableType(member.getMethodOrFieldType()))
             return false;
@@ -1051,14 +1051,14 @@
         if (cls == Object.class)
             return true;
         if (MethodHandle.class.isAssignableFrom(cls)) {
-            assert(!ReflectUtil.isVMAnonymousClass(cls));
+            assert(!cls.isHidden());
             return true;
         }
         while (cls.isArray())
             cls = cls.getComponentType();
         if (cls.isPrimitive())
             return true;  // int[].class, for example
-        if (ReflectUtil.isVMAnonymousClass(cls)) // FIXME: switch to supported API once it is added
+        if (cls.isHidden())
             return false;
         // could use VerifyAccess.isClassAccessible but the following is a safe approximation
         if (cls.getClassLoader() != Object.class.getClassLoader())
--- a/src/java.base/share/classes/java/lang/invoke/MethodHandles.java	Wed Nov 07 15:34:41 2018 -0500
+++ b/src/java.base/share/classes/java/lang/invoke/MethodHandles.java	Wed Nov 07 15:09:20 2018 -0800
@@ -1260,9 +1260,8 @@
             }
 
             if ((flags & NONFINDABLE_CLASS) != 0) {
-                // assign a new name
-                // cn = cn + "\\" + ++seq;
-                cn = null;
+                // ## TODO use '/' as in the name of the VM anonymous class.
+                cn = cn + '\\' + ++seq;
             }
 
             // invoke the class loader's defineClass method
--- a/src/java.base/share/classes/jdk/internal/reflect/NativeConstructorAccessorImpl.java	Wed Nov 07 15:34:41 2018 -0500
+++ b/src/java.base/share/classes/jdk/internal/reflect/NativeConstructorAccessorImpl.java	Wed Nov 07 15:09:20 2018 -0800
@@ -49,7 +49,7 @@
         // because that kind of class can't be referred to by name, hence can't
         // be found from the generated bytecode.
         if (++numInvocations > ReflectionFactory.inflationThreshold()
-                && !ReflectUtil.isVMAnonymousClass(c.getDeclaringClass())) {
+                && !c.getDeclaringClass().isHidden()) {
             ConstructorAccessorImpl acc = (ConstructorAccessorImpl)
                 new MethodAccessorGenerator().
                     generateConstructor(c.getDeclaringClass(),
--- a/src/java.base/share/classes/jdk/internal/reflect/NativeMethodAccessorImpl.java	Wed Nov 07 15:34:41 2018 -0500
+++ b/src/java.base/share/classes/jdk/internal/reflect/NativeMethodAccessorImpl.java	Wed Nov 07 15:09:20 2018 -0800
@@ -47,7 +47,7 @@
         // that kind of class can't be referred to by name, hence can't be
         // found from the generated bytecode.
         if (++numInvocations > ReflectionFactory.inflationThreshold()
-                && !ReflectUtil.isVMAnonymousClass(method.getDeclaringClass())) {
+                && !method.getDeclaringClass().isHidden()) {
             MethodAccessorImpl acc = (MethodAccessorImpl)
                 new MethodAccessorGenerator().
                     generateMethod(method.getDeclaringClass(),
--- a/src/java.base/share/classes/jdk/internal/reflect/ReflectionFactory.java	Wed Nov 07 15:34:41 2018 -0500
+++ b/src/java.base/share/classes/jdk/internal/reflect/ReflectionFactory.java	Wed Nov 07 15:09:20 2018 -0800
@@ -202,7 +202,7 @@
             method = root;
         }
 
-        if (noInflation && !ReflectUtil.isVMAnonymousClass(method.getDeclaringClass())) {
+        if (noInflation && !method.getDeclaringClass().isHidden()) {
             return new MethodAccessorGenerator().
                 generateMethod(method.getDeclaringClass(),
                                method.getName(),
@@ -246,7 +246,7 @@
             return new BootstrapConstructorAccessorImpl(c);
         }
 
-        if (noInflation && !ReflectUtil.isVMAnonymousClass(c.getDeclaringClass())) {
+        if (noInflation && !c.getDeclaringClass().isHidden()) {
             return new MethodAccessorGenerator().
                 generateConstructor(c.getDeclaringClass(),
                                     c.getParameterTypes(),
--- a/src/java.base/share/classes/sun/reflect/misc/ReflectUtil.java	Wed Nov 07 15:34:41 2018 -0500
+++ b/src/java.base/share/classes/sun/reflect/misc/ReflectUtil.java	Wed Nov 07 15:09:20 2018 -0800
@@ -312,13 +312,4 @@
         }
         return false;
     }
-
-    /**
-     * Checks if {@code Class cls} is a VM-anonymous class
-     * as defined by {@link jdk.internal.misc.Unsafe#defineAnonymousClass}
-     * (not to be confused with a Java Language anonymous inner class).
-     */
-    public static boolean isVMAnonymousClass(Class<?> cls) {
-        return cls.getName().indexOf('/') > -1;
-    }
 }
--- a/test/jdk/ProblemList.txt	Wed Nov 07 15:34:41 2018 -0500
+++ b/test/jdk/ProblemList.txt	Wed Nov 07 15:09:20 2018 -0800
@@ -511,6 +511,15 @@
 java/lang/ProcessBuilder/PipelineTest.java                      8211844 aix-ppc64
 java/lang/ProcessHandle/InfoTest.java                           8211847 aix-ppc64
 
+# jdk_lang failures in nestmates branches
+
+java/lang/System/LoggerFinder/internal/BaseDefaultLoggerFinderTest/BaseDefaultLoggerFinderTest.java	8213402 generic-all
+java/lang/System/LoggerFinder/internal/BaseLoggerBridgeTest/BaseLoggerBridgeTest.java			8213402 generic-all
+java/lang/System/LoggerFinder/internal/BasePlatformLoggerTest/BasePlatformLoggerTest.java		8213402 generic-all
+java/lang/System/LoggerFinder/internal/LoggerBridgeTest/LoggerBridgeTest.java				8213402 generic-all
+java/lang/System/LoggerFinder/internal/LoggerFinderLoaderTest/LoggerFinderLoaderTest.java		8213402 generic-all
+java/lang/System/LoggerFinder/internal/PlatformLoggerBridgeTest/PlatformLoggerBridgeTest.java		8213402 generic-all
+
 ############################################################################
 
 # jdk_instrument
--- a/test/jdk/java/lang/StackWalker/VerifyStackTrace.java	Wed Nov 07 15:34:41 2018 -0500
+++ b/test/jdk/java/lang/StackWalker/VerifyStackTrace.java	Wed Nov 07 15:09:20 2018 -0800
@@ -131,10 +131,10 @@
         // test output in here (don't forget the final \n):
         private final String expected =
             "1: VerifyStackTrace.lambda$test$1(VerifyStackTrace.java:213)\n" +
-            "2: VerifyStackTrace$$Lambda$1/0x00000007c0089430.run(Unknown Source)\n" +
+            "2: VerifyStackTrace$$Lambda$1\\10.run(Unknown Source)\n" +
             "3: VerifyStackTrace$Handle.execute(VerifyStackTrace.java:149)\n" +
-            "4: java.base/java.lang.invoke.LambdaForm$DMH/0x00000007c008a830.invokeVirtual_LL_V(LambdaForm$DMH)\n" +
-            "5: java.base/java.lang.invoke.LambdaForm$MH/0x00000007c008a830.invoke_MT(LambdaForm$MH)\n" +
+            "4: java.base/java.lang.invoke.LambdaForm$DMH\\11.invokeVirtual_LL_V(LambdaForm$DMH)\n" +
+            "5: java.base/java.lang.invoke.LambdaForm$MH\\12.invoke_MT(LambdaForm$MH)\n" +
             "6: VerifyStackTrace$Handle.run(VerifyStackTrace.java:162)\n" +
             "7: VerifyStackTrace.invoke(VerifyStackTrace.java:192)\n" +
             "8: java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\n" +
@@ -201,8 +201,8 @@
             // out before comparing. We also erase the hash-like names of
             // synthetic frames introduced by lambdas & method handles
             return produced.replaceAll(":[1-9][0-9]*\\)", ":00)")
-                    .replaceAll("/0x[0-9a-f]+\\.run", "/xxxxxxxx.run")
-                    .replaceAll("/0x[0-9a-f]+\\.invoke", "/xxxxxxxx.invoke")
+                    .replaceAll("\\\\[0-9]+\\.run", "/xxxxxxxx.run")
+                    .replaceAll("\\\\[0-9]+\\.invoke", "/xxxxxxxx.invoke")
                     // LFs may or may not be pre-generated, making frames differ
                     .replaceAll("DirectMethodHandle\\$Holder", "LambdaForm\\$DMH")
                     .replaceAll("Invokers\\$Holder", "LambdaForm\\$MH")
--- a/test/jdk/java/lang/invoke/defineClass/DefineClassTest.java	Wed Nov 07 15:34:41 2018 -0500
+++ b/test/jdk/java/lang/invoke/defineClass/DefineClassTest.java	Wed Nov 07 15:09:20 2018 -0800
@@ -103,7 +103,7 @@
         Class<?> c = lookup.defineClass(bytes, NESTMATE, HIDDEN);
         System.out.println(c.getName());
         assertTrue(c.getNestHost() == DefineClassTest.class);
-        // assertTrue(c.isHidden());
+        assertTrue(c.isHidden());
 
         // invoke int test(DefineClassTest o)
         int x = testInjectedClass(c);
@@ -121,7 +121,7 @@
         Class<?> c = lookup.defineClass(bytes, WEAK);
         System.out.println(c.getName());
         assertTrue(c.getNestHost() == c);
-        // assertTrue(c.isHidden());
+        assertTrue(c.isHidden());
     }
 
     @Test(expectedExceptions = IllegalAccessError.class)
@@ -129,7 +129,7 @@
         Lookup lookup = MethodHandles.lookup().dropLookupMode(Lookup.PRIVATE);
         Class<?> c = lookup.defineClass(bytes, HIDDEN);
         assertTrue(c.getNestHost() == c);
-        // assertTrue(c.isHidden());
+        assertTrue(c.isHidden());
 
         // fail to access DefineClassTest::privMethod method
         testInjectedClass(c);
@@ -145,7 +145,7 @@
     public void teleportToNestmate() throws Throwable {
         Class<?> c = MethodHandles.lookup().defineClass(bytes, NESTMATE, HIDDEN);
         assertTrue(c.getNestHost() == DefineClassTest.class);
-        // assertTrue(c.isHidden());
+        assertTrue(c.isHidden());
 
         // Teleport to a nestmate
         Lookup lookup =  MethodHandles.lookup().in(c);
--- a/test/jdk/java/lang/invoke/defineClass/DefineClassWithClassData.java	Wed Nov 07 15:34:41 2018 -0500
+++ b/test/jdk/java/lang/invoke/defineClass/DefineClassWithClassData.java	Wed Nov 07 15:09:20 2018 -0800
@@ -92,7 +92,7 @@
         Lookup lookup = MethodHandles.lookup();
         Class<?> c = lookup.defineClassWithClassData(ClassByteBuilder.classBytes("T"), classData, NESTMATE, HIDDEN);
         assertTrue(c.getNestHost() == DefineClassWithClassData.class);
-        // assertTrue(c.isHidden());
+        assertTrue(c.isHidden());
         assertEquals(classData, injectedData(c));
 
         // invoke int test(DefineClassWithClassData o)
@@ -110,7 +110,7 @@
         Lookup lookup = MethodHandles.lookup().dropLookupMode(Lookup.PRIVATE);
         Class<?> c = lookup.defineClassWithClassData(ClassByteBuilder.classBytes("T"), classData, WEAK);
         assertTrue(c.getNestHost() == c);
-        // assertTrue(c.isHidden());
+        assertTrue(c.isHidden());
     }
 
     @Test(expectedExceptions = IllegalAccessException.class)
@@ -126,7 +126,7 @@
             .defineClassWithClassData(classBytes, classData, NESTMATE, HIDDEN);
         assertTrue(c.getNestHost() == DefineClassWithClassData.class);
         assertEquals(classData, injectedData(c));
-        // assertTrue(c.isHidden());
+        assertTrue(c.isHidden());
 
         // Teleport to a nestmate
         Lookup lookup =  MethodHandles.lookup().in(c);