changeset 45825:4fa7bd62eb84

8183503: Update hotspot tests to allow for unique test classes directory Reviewed-by: iklam
author alanb
date Wed, 05 Jul 2017 13:25:45 +0100
parents 9ef5029b247b
children be3f105090e2 cef226af6c02
files hotspot/test/compiler/classUnloading/anonymousClass/TestAnonymousClassUnloading.java hotspot/test/runtime/logging/ClassLoadUnloadTest.java hotspot/test/runtime/testlibrary/ClassUnloadCommon.java
diffstat 3 files changed, 42 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/hotspot/test/compiler/classUnloading/anonymousClass/TestAnonymousClassUnloading.java	Thu Aug 24 16:25:08 2017 +0200
+++ b/hotspot/test/compiler/classUnloading/anonymousClass/TestAnonymousClassUnloading.java	Wed Jul 05 13:25:45 2017 +0100
@@ -108,8 +108,8 @@
      */
     static public void main(String[] args) throws Exception {
         // (1) Load an anonymous version of this class using the corresponding Unsafe method
-        URL classUrl = TestAnonymousClassUnloading.class.getResource(
-                TestAnonymousClassUnloading.class.getName().replace('.', '/') + ".class");
+        String rn = TestAnonymousClassUnloading.class.getSimpleName() + ".class";
+        URL classUrl = TestAnonymousClassUnloading.class.getResource(rn);
         URLConnection connection = classUrl.openConnection();
 
         int length = connection.getContentLength();
--- a/hotspot/test/runtime/logging/ClassLoadUnloadTest.java	Thu Aug 24 16:25:08 2017 +0200
+++ b/hotspot/test/runtime/logging/ClassLoadUnloadTest.java	Wed Jul 05 13:25:45 2017 +0100
@@ -74,7 +74,7 @@
         List<String> argsList = new ArrayList<>();
         Collections.addAll(argsList, args);
         Collections.addAll(argsList, "-Xmn8m");
-        Collections.addAll(argsList, "-Dtest.classes=" + System.getProperty("test.classes","."));
+        Collections.addAll(argsList, "-Dtest.class.path=" + System.getProperty("test.class.path", "."));
         Collections.addAll(argsList, ClassUnloadTestMain.class.getName());
         return ProcessTools.createJavaProcessBuilder(argsList.toArray(new String[argsList.size()]));
     }
--- a/hotspot/test/runtime/testlibrary/ClassUnloadCommon.java	Thu Aug 24 16:25:08 2017 +0200
+++ b/hotspot/test/runtime/testlibrary/ClassUnloadCommon.java	Wed Jul 05 13:25:45 2017 +0100
@@ -31,8 +31,10 @@
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.net.URLClassLoader;
+import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.util.ArrayList;
+import java.util.stream.Stream;
 
 public class ClassUnloadCommon {
     public static class TestFailure extends RuntimeException {
@@ -61,14 +63,45 @@
         System.gc();
     }
 
+    /**
+     * Creates a class loader that loads classes from {@code ${test.class.path}}
+     * before delegating to the system class loader.
+     */
     public static ClassLoader newClassLoader() {
+        String cp = System.getProperty("test.class.path", ".");
+        URL[] urls = Stream.of(cp.split(File.pathSeparator))
+                .map(Paths::get)
+                .map(ClassUnloadCommon::toURL)
+                .toArray(URL[]::new);
+        return new URLClassLoader(urls) {
+            @Override
+            public Class<?> loadClass(String cn, boolean resolve)
+                throws ClassNotFoundException
+            {
+                synchronized (getClassLoadingLock(cn)) {
+                    Class<?> c = findLoadedClass(cn);
+                    if (c == null) {
+                        try {
+                            c = findClass(cn);
+                        } catch (ClassNotFoundException e) {
+                            c = getParent().loadClass(cn);
+                        }
+
+                    }
+                    if (resolve) {
+                        resolveClass(c);
+                    }
+                    return c;
+                }
+            }
+        };
+    }
+
+    static URL toURL(Path path) {
         try {
-            return new URLClassLoader(new URL[] {
-                Paths.get(System.getProperty("test.classes",".") + File.separatorChar + "classes").toUri().toURL(),
-            }, null);
-        } catch (MalformedURLException e){
-            throw new RuntimeException("Unexpected URL conversion failure", e);
+            return path.toUri().toURL();
+        } catch (MalformedURLException e) {
+            throw new RuntimeException(e);
         }
     }
-
 }