8186459: [JVMCI] ClassNotFoundException thrown by CompilerToVM.lookupType() should be converted to a LinkageError
authordnsimon
Wed, 23 Aug 2017 23:38:06 +0200
changeset 46972 3e88de95fccf
parent 46971 8d189e2ebebd
child 46973 149e5319c938
child 46974 2c6c8846e176
8186459: [JVMCI] ClassNotFoundException thrown by CompilerToVM.lookupType() should be converted to a LinkageError Reviewed-by: kvn, iveresov
hotspot/src/jdk.internal.vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/CompilerToVM.java
hotspot/src/jdk.internal.vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotJVMCIRuntime.java
hotspot/test/compiler/jvmci/common/patches/jdk.internal.vm.ci/jdk/vm/ci/hotspot/CompilerToVMHelper.java
hotspot/test/compiler/jvmci/compilerToVM/FindUniqueConcreteMethodTest.java
hotspot/test/compiler/jvmci/compilerToVM/GetClassInitializerTest.java
hotspot/test/compiler/jvmci/compilerToVM/GetConstantPoolTest.java
hotspot/test/compiler/jvmci/compilerToVM/GetImplementorTest.java
hotspot/test/compiler/jvmci/compilerToVM/GetVtableIndexForInterfaceTest.java
hotspot/test/compiler/jvmci/compilerToVM/HasFinalizableSubclassTest.java
hotspot/test/compiler/jvmci/compilerToVM/ResolveMethodTest.java
--- a/hotspot/src/jdk.internal.vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/CompilerToVM.java	Thu Aug 24 08:38:50 2017 +0000
+++ b/hotspot/src/jdk.internal.vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/CompilerToVM.java	Wed Aug 23 23:38:06 2017 +0200
@@ -153,9 +153,9 @@
      * @param resolve force resolution to a {@link ResolvedJavaType}. If true, this method will
      *            either return a {@link ResolvedJavaType} or throw an exception
      * @return the type for {@code name} or 0 if resolution failed and {@code resolve == false}
-     * @throws LinkageError if {@code resolve == true} and the resolution failed
+     * @throws ClassNotFoundException if {@code resolve == true} and the resolution failed
      */
-    native HotSpotResolvedObjectTypeImpl lookupType(String name, Class<?> accessingClass, boolean resolve);
+    native HotSpotResolvedObjectTypeImpl lookupType(String name, Class<?> accessingClass, boolean resolve) throws ClassNotFoundException;
 
     /**
      * Resolves the entry at index {@code cpi} in {@code constantPool} to an object.
--- a/hotspot/src/jdk.internal.vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotJVMCIRuntime.java	Thu Aug 24 08:38:50 2017 +0000
+++ b/hotspot/src/jdk.internal.vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotJVMCIRuntime.java	Wed Aug 23 23:38:06 2017 +0200
@@ -367,13 +367,17 @@
 
         // Resolve non-primitive types in the VM.
         HotSpotResolvedObjectTypeImpl hsAccessingType = (HotSpotResolvedObjectTypeImpl) accessingType;
-        final HotSpotResolvedObjectTypeImpl klass = compilerToVm.lookupType(name, hsAccessingType.mirror(), resolve);
+        try {
+            final HotSpotResolvedObjectTypeImpl klass = compilerToVm.lookupType(name, hsAccessingType.mirror(), resolve);
 
-        if (klass == null) {
-            assert resolve == false;
-            return HotSpotUnresolvedJavaType.create(this, name);
+            if (klass == null) {
+                assert resolve == false;
+                return HotSpotUnresolvedJavaType.create(this, name);
+            }
+            return klass;
+        } catch (ClassNotFoundException e) {
+            throw (NoClassDefFoundError) new NoClassDefFoundError().initCause(e);
         }
-        return klass;
     }
 
     public JVMCIBackend getHostJVMCIBackend() {
--- a/hotspot/test/compiler/jvmci/common/patches/jdk.internal.vm.ci/jdk/vm/ci/hotspot/CompilerToVMHelper.java	Thu Aug 24 08:38:50 2017 +0000
+++ b/hotspot/test/compiler/jvmci/common/patches/jdk.internal.vm.ci/jdk/vm/ci/hotspot/CompilerToVMHelper.java	Wed Aug 23 23:38:06 2017 +0200
@@ -79,8 +79,17 @@
     }
 
     public static HotSpotResolvedObjectType lookupType(String name,
+            Class<?> accessingClass, boolean resolve) throws ClassNotFoundException {
+        return CTVM.lookupType(name, accessingClass, resolve);
+    }
+
+    public static HotSpotResolvedObjectType lookupTypeHelper(String name,
             Class<?> accessingClass, boolean resolve) {
-        return CTVM.lookupType(name, accessingClass, resolve);
+        try {
+            return lookupType(name, accessingClass, resolve);
+        } catch (ClassNotFoundException e) {
+            throw (NoClassDefFoundError) new NoClassDefFoundError().initCause(e);
+        }
     }
 
     public static Object resolveConstantInPool(ConstantPool constantPool, int cpi) {
--- a/hotspot/test/compiler/jvmci/compilerToVM/FindUniqueConcreteMethodTest.java	Thu Aug 24 08:38:50 2017 +0000
+++ b/hotspot/test/compiler/jvmci/compilerToVM/FindUniqueConcreteMethodTest.java	Wed Aug 23 23:38:06 2017 +0200
@@ -107,7 +107,7 @@
         HotSpotResolvedJavaMethod testMethod = CTVMUtilities.getResolvedMethod(method);
 
         HotSpotResolvedObjectType resolvedType = CompilerToVMHelper
-                .lookupType(Utils.toJVMTypeSignature(tcase.receiver), getClass(),
+                .lookupTypeHelper(Utils.toJVMTypeSignature(tcase.receiver), getClass(),
                 /* resolve = */ true);
         HotSpotResolvedJavaMethod concreteMethod = CompilerToVMHelper
                 .findUniqueConcreteMethod(resolvedType, testMethod);
--- a/hotspot/test/compiler/jvmci/compilerToVM/GetClassInitializerTest.java	Thu Aug 24 08:38:50 2017 +0000
+++ b/hotspot/test/compiler/jvmci/compilerToVM/GetClassInitializerTest.java	Wed Aug 23 23:38:06 2017 +0200
@@ -82,7 +82,7 @@
         System.out.println(tcase);
         String className = tcase.holder.getName();
         HotSpotResolvedObjectType resolvedClazz = CompilerToVMHelper
-                .lookupType(Utils.toJVMTypeSignature(tcase.holder),
+                .lookupTypeHelper(Utils.toJVMTypeSignature(tcase.holder),
                         getClass(), /* resolve = */ true);
         HotSpotResolvedJavaMethod initializer = CompilerToVMHelper
                 .getClassInitializer(resolvedClazz);
--- a/hotspot/test/compiler/jvmci/compilerToVM/GetConstantPoolTest.java	Thu Aug 24 08:38:50 2017 +0000
+++ b/hotspot/test/compiler/jvmci/compilerToVM/GetConstantPoolTest.java	Wed Aug 23 23:38:06 2017 +0200
@@ -65,7 +65,7 @@
 
     public static void testClass(Class cls) {
         HotSpotResolvedObjectType type = CompilerToVMHelper
-                .lookupType(Utils.toJVMTypeSignature(cls),
+                .lookupTypeHelper(Utils.toJVMTypeSignature(cls),
                         GetConstantPoolTest.class, /* resolve = */ true);
         test(type);
     }
--- a/hotspot/test/compiler/jvmci/compilerToVM/GetImplementorTest.java	Thu Aug 24 08:38:50 2017 +0000
+++ b/hotspot/test/compiler/jvmci/compilerToVM/GetImplementorTest.java	Wed Aug 23 23:38:06 2017 +0200
@@ -101,13 +101,13 @@
     private void runTest(TestCase tcase) {
         System.out.println(tcase);
         HotSpotResolvedObjectType resolvedIface = CompilerToVMHelper
-                .lookupType(Utils.toJVMTypeSignature(tcase.anInterface),
+                .lookupTypeHelper(Utils.toJVMTypeSignature(tcase.anInterface),
                         getClass(), /* resolve = */ true);
         HotSpotResolvedObjectType resolvedImplementer = CompilerToVMHelper
                 .getImplementor(resolvedIface);
         HotSpotResolvedObjectType resolvedExpected = null;
         if (tcase.expectedImplementer != null) {
-            resolvedExpected = CompilerToVMHelper.lookupType(Utils
+            resolvedExpected = CompilerToVMHelper.lookupTypeHelper(Utils
                     .toJVMTypeSignature(tcase.expectedImplementer),
                     getClass(), /* resolve = */ true);
         }
--- a/hotspot/test/compiler/jvmci/compilerToVM/GetVtableIndexForInterfaceTest.java	Thu Aug 24 08:38:50 2017 +0000
+++ b/hotspot/test/compiler/jvmci/compilerToVM/GetVtableIndexForInterfaceTest.java	Wed Aug 23 23:38:06 2017 +0200
@@ -131,7 +131,7 @@
         System.out.println(tcase);
         Method method = tcase.holder.getDeclaredMethod(tcase.methodName);
         HotSpotResolvedObjectType metaspaceKlass = CompilerToVMHelper
-                .lookupType(Utils.toJVMTypeSignature(tcase.receiver),
+                .lookupTypeHelper(Utils.toJVMTypeSignature(tcase.receiver),
                         getClass(), /* resolve = */ true);
         HotSpotResolvedJavaMethod metaspaceMethod = CTVMUtilities
                 .getResolvedMethod(tcase.holder, method);
--- a/hotspot/test/compiler/jvmci/compilerToVM/HasFinalizableSubclassTest.java	Thu Aug 24 08:38:50 2017 +0000
+++ b/hotspot/test/compiler/jvmci/compilerToVM/HasFinalizableSubclassTest.java	Wed Aug 23 23:38:06 2017 +0200
@@ -85,7 +85,7 @@
     private void runTest(TestCase tcase) {
         System.out.println(tcase);
         HotSpotResolvedObjectType metaspaceKlass = CompilerToVMHelper
-                .lookupType(Utils.toJVMTypeSignature(tcase.aClass),
+                .lookupTypeHelper(Utils.toJVMTypeSignature(tcase.aClass),
                         getClass(), /* resolve = */ true);
         Asserts.assertEQ(tcase.expected,
                 CompilerToVMHelper.hasFinalizableSubclass(metaspaceKlass),
--- a/hotspot/test/compiler/jvmci/compilerToVM/ResolveMethodTest.java	Thu Aug 24 08:38:50 2017 +0000
+++ b/hotspot/test/compiler/jvmci/compilerToVM/ResolveMethodTest.java	Wed Aug 23 23:38:06 2017 +0200
@@ -134,13 +134,13 @@
                 .getResolvedMethod(tcase.holder,
                         tcase.holder.getDeclaredMethod(tcase.methodName));
         HotSpotResolvedObjectType holderMetaspace = CompilerToVMHelper
-                .lookupType(Utils.toJVMTypeSignature(tcase.holder),
+                .lookupTypeHelper(Utils.toJVMTypeSignature(tcase.holder),
                         getClass(), /* resolve = */ true);
         HotSpotResolvedObjectType callerMetaspace = CompilerToVMHelper
-                .lookupType(Utils.toJVMTypeSignature(tcase.caller),
+                .lookupTypeHelper(Utils.toJVMTypeSignature(tcase.caller),
                         getClass(), /* resolve = */ true);
         HotSpotResolvedObjectType receiverMetaspace = CompilerToVMHelper
-                .lookupType(Utils.toJVMTypeSignature(tcase.receiver),
+                .lookupTypeHelper(Utils.toJVMTypeSignature(tcase.receiver),
                         getClass(), /* resolve = */ true);
 
         // Can only resolve methods on a linked class so force initialization