diff --git a/test/hotspot/jtreg/runtime/BadObjectClass/TestUnloadClassError.java b/test/hotspot/jtreg/runtime/BadObjectClass/TestUnloadClassError.java index 5f406b9265c..59aa8e9ac6e 100644 --- a/test/hotspot/jtreg/runtime/BadObjectClass/TestUnloadClassError.java +++ b/test/hotspot/jtreg/runtime/BadObjectClass/TestUnloadClassError.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -29,13 +29,14 @@ * java.lang.Object class. * Also, make sure the vm doesn't crash on notification for unloading an invalid * java.lang.Object class. - * @library /runtime/testlibrary /test/lib + * @library /test/lib * @modules java.base/jdk.internal.misc * java.compiler * @run main TestUnloadClassError */ import jdk.test.lib.compiler.InMemoryJavaCompiler; +import jdk.test.lib.classloader.ClassUnloadCommon; public class TestUnloadClassError extends ClassLoader { diff --git a/test/hotspot/jtreg/runtime/ClassUnload/ConstantPoolDependsTest.java b/test/hotspot/jtreg/runtime/ClassUnload/ConstantPoolDependsTest.java index 3f98313ec4e..d6041c980d2 100644 --- a/test/hotspot/jtreg/runtime/ClassUnload/ConstantPoolDependsTest.java +++ b/test/hotspot/jtreg/runtime/ClassUnload/ConstantPoolDependsTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -28,7 +28,7 @@ * @requires vm.opt.final.ClassUnloading * @modules java.base/jdk.internal.misc * java.compiler - * @library /runtime/testlibrary /test/lib + * @library /test/lib * @build sun.hotspot.WhiteBox * @compile p2/c2.java MyDiffClassLoader.java * @run driver ClassFileInstaller sun.hotspot.WhiteBox @@ -36,7 +36,7 @@ */ import sun.hotspot.WhiteBox; - +import jdk.test.lib.classloader.ClassUnloadCommon; public class ConstantPoolDependsTest { public static WhiteBox wb = WhiteBox.getWhiteBox(); diff --git a/test/hotspot/jtreg/runtime/ClassUnload/DictionaryDependsTest.java b/test/hotspot/jtreg/runtime/ClassUnload/DictionaryDependsTest.java index 414b9b13ec8..86c06ae6337 100644 --- a/test/hotspot/jtreg/runtime/ClassUnload/DictionaryDependsTest.java +++ b/test/hotspot/jtreg/runtime/ClassUnload/DictionaryDependsTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -28,7 +28,7 @@ * @requires vm.opt.final.ClassUnloading * @modules java.base/jdk.internal.misc * java.compiler - * @library /runtime/testlibrary /test/lib + * @library /test/lib * @build sun.hotspot.WhiteBox * @compile p2/c2.java MyDiffClassLoader.java * @run driver ClassFileInstaller sun.hotspot.WhiteBox @@ -36,6 +36,7 @@ */ import sun.hotspot.WhiteBox; import java.lang.reflect.Method; +import jdk.test.lib.classloader.ClassUnloadCommon; public class DictionaryDependsTest { public static WhiteBox wb = WhiteBox.getWhiteBox(); diff --git a/test/hotspot/jtreg/runtime/ClassUnload/KeepAliveClass.java b/test/hotspot/jtreg/runtime/ClassUnload/KeepAliveClass.java index 07c894c5729..ba95b0ff8da 100644 --- a/test/hotspot/jtreg/runtime/ClassUnload/KeepAliveClass.java +++ b/test/hotspot/jtreg/runtime/ClassUnload/KeepAliveClass.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2021, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -26,7 +26,7 @@ * @summary This test case uses a java.lang.Class instance to keep a class alive. * @requires vm.opt.final.ClassUnloading * @modules java.base/jdk.internal.misc - * @library /test/lib /runtime/testlibrary + * @library /test/lib * @library classes * @build sun.hotspot.WhiteBox test.Empty * @run driver ClassFileInstaller sun.hotspot.WhiteBox @@ -35,6 +35,7 @@ import java.lang.ref.SoftReference; import sun.hotspot.WhiteBox; +import jdk.test.lib.classloader.ClassUnloadCommon; /** * Test that verifies that classes are not unloaded when specific types of references are kept to them. diff --git a/test/hotspot/jtreg/runtime/ClassUnload/KeepAliveClassLoader.java b/test/hotspot/jtreg/runtime/ClassUnload/KeepAliveClassLoader.java index b367f06be04..da85914d132 100644 --- a/test/hotspot/jtreg/runtime/ClassUnload/KeepAliveClassLoader.java +++ b/test/hotspot/jtreg/runtime/ClassUnload/KeepAliveClassLoader.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2021, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -26,7 +26,7 @@ * @summary This test case uses a java.lang.ClassLoader instance to keep a class alive. * @requires vm.opt.final.ClassUnloading * @modules java.base/jdk.internal.misc - * @library /test/lib /runtime/testlibrary + * @library /test/lib * @library classes * @build sun.hotspot.WhiteBox test.Empty * @run driver ClassFileInstaller sun.hotspot.WhiteBox @@ -34,6 +34,7 @@ */ import sun.hotspot.WhiteBox; +import jdk.test.lib.classloader.ClassUnloadCommon; /** * Test that verifies that classes are not unloaded when specific types of references are kept to them. diff --git a/test/hotspot/jtreg/runtime/ClassUnload/KeepAliveObject.java b/test/hotspot/jtreg/runtime/ClassUnload/KeepAliveObject.java index dbf51434204..8ecf6d8bfed 100644 --- a/test/hotspot/jtreg/runtime/ClassUnload/KeepAliveObject.java +++ b/test/hotspot/jtreg/runtime/ClassUnload/KeepAliveObject.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2021, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -26,7 +26,7 @@ * @summary This test case uses a class instance to keep the class alive. * @requires vm.opt.final.ClassUnloading * @modules java.base/jdk.internal.misc - * @library /test/lib /runtime/testlibrary + * @library /test/lib * @library classes * @build sun.hotspot.WhiteBox test.Empty * @run driver ClassFileInstaller sun.hotspot.WhiteBox @@ -34,6 +34,7 @@ */ import sun.hotspot.WhiteBox; +import jdk.test.lib.classloader.ClassUnloadCommon; /** * Test that verifies that classes are not unloaded when specific types of references are kept to them. diff --git a/test/hotspot/jtreg/runtime/ClassUnload/KeepAliveSoftReference.java b/test/hotspot/jtreg/runtime/ClassUnload/KeepAliveSoftReference.java index 020b47ab7c6..5c9d1eb42ea 100644 --- a/test/hotspot/jtreg/runtime/ClassUnload/KeepAliveSoftReference.java +++ b/test/hotspot/jtreg/runtime/ClassUnload/KeepAliveSoftReference.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2021, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -26,7 +26,7 @@ * @summary This test case uses a java.lang.ref.SoftReference referencing a class instance to keep a class alive. * @requires vm.opt.final.ClassUnloading * @modules java.base/jdk.internal.misc - * @library /test/lib /runtime/testlibrary + * @library /test/lib * @library classes * @build sun.hotspot.WhiteBox test.Empty * @run driver ClassFileInstaller sun.hotspot.WhiteBox @@ -35,6 +35,7 @@ import java.lang.ref.SoftReference; import sun.hotspot.WhiteBox; +import jdk.test.lib.classloader.ClassUnloadCommon; /** * Test that verifies that classes are not unloaded when specific types of references are kept to them. diff --git a/test/hotspot/jtreg/runtime/ClassUnload/MyDiffClassLoader.java b/test/hotspot/jtreg/runtime/ClassUnload/MyDiffClassLoader.java index 3ebb51f88a1..b90bc2e97bc 100644 --- a/test/hotspot/jtreg/runtime/ClassUnload/MyDiffClassLoader.java +++ b/test/hotspot/jtreg/runtime/ClassUnload/MyDiffClassLoader.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -23,6 +23,7 @@ import java.io.*; import jdk.test.lib.compiler.InMemoryJavaCompiler; +import jdk.test.lib.classloader.ClassUnloadCommon; public class MyDiffClassLoader extends ClassLoader { @@ -48,25 +49,10 @@ public class MyDiffClassLoader extends ClassLoader { return c; } - byte[] data = switchClassData ? getNewClassData(name) : getClassData(name); + byte[] data = switchClassData ? getNewClassData(name) : ClassUnloadCommon.getClassData(name); System.out.println("name is " + name); return defineClass(name, data, 0, data.length); } - byte[] getClassData(String name) { - try { - String TempName = name.replaceAll("\\.", "/"); - String currentDir = System.getProperty("test.classes"); - String filename = currentDir + File.separator + TempName + ".class"; - FileInputStream fis = new FileInputStream(filename); - byte[] b = new byte[5000]; - int cnt = fis.read(b, 0, 5000); - byte[] c = new byte[cnt]; - for (int i=0; i loadClass(String name, boolean resolve) throws ClassNotFoundException { Class c; @@ -117,7 +100,8 @@ public class LoadLibraryTest { if (!CLASS_NAME.equals(name)) { throw new ClassNotFoundException("Unexpected class: " + name); } - return defineClass(name, readClassFile(name + ".class"), null); + byte[] class_bytes = ClassUnloadCommon.getClassData(name); + return defineClass(name, class_bytes, 0, class_bytes.length); } } // MyClassLoader } diff --git a/test/hotspot/jtreg/runtime/modules/AccessCheck/UmodDiffCL_Umod.java b/test/hotspot/jtreg/runtime/modules/AccessCheck/UmodDiffCL_Umod.java index 26cec1f7fe2..28e2f8bfb64 100644 --- a/test/hotspot/jtreg/runtime/modules/AccessCheck/UmodDiffCL_Umod.java +++ b/test/hotspot/jtreg/runtime/modules/AccessCheck/UmodDiffCL_Umod.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -27,6 +27,7 @@ * defined in an unnamed module. Access allowed since unnamed module * can read unnamed module even when class p1.c1 is loaded by * a different loader than p2.c2. + * @library /test/lib * @compile myloaders/MyDiffClassLoader.java * @compile p2/c2.java * @compile p1/c1.java diff --git a/test/hotspot/jtreg/runtime/modules/AccessCheck/UmodDiffCL_UmodUpkg.java b/test/hotspot/jtreg/runtime/modules/AccessCheck/UmodDiffCL_UmodUpkg.java index 7d1192d4be1..4edbd04e47e 100644 --- a/test/hotspot/jtreg/runtime/modules/AccessCheck/UmodDiffCL_UmodUpkg.java +++ b/test/hotspot/jtreg/runtime/modules/AccessCheck/UmodDiffCL_UmodUpkg.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -26,6 +26,7 @@ * @summary class p3.c3 defined in a named package in an unnamed module tries to access c4 * defined in an unnamed package in an unnamed module. Access allowed since * any class in an unnamed module can read an unnamed module. + * @library /test/lib * @compile myloaders/MyDiffClassLoader.java * @compile c4.java * @compile p3/c3.jcod diff --git a/test/hotspot/jtreg/runtime/modules/AccessCheck/UmodUpkgDiffCL_Umod.java b/test/hotspot/jtreg/runtime/modules/AccessCheck/UmodUpkgDiffCL_Umod.java index 09e05e0a725..1864252f5bb 100644 --- a/test/hotspot/jtreg/runtime/modules/AccessCheck/UmodUpkgDiffCL_Umod.java +++ b/test/hotspot/jtreg/runtime/modules/AccessCheck/UmodUpkgDiffCL_Umod.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -25,6 +25,7 @@ * @test * @summary Test public type c5 defined in an unnamed package and unnamed module can * access public type p6.c6 defined in an unnamed module. + * @library /test/lib * @compile myloaders/MyDiffClassLoader.java * @compile p6/c6.java * @compile c5.java diff --git a/test/hotspot/jtreg/runtime/modules/AccessCheck/UmodUpkg_Umod.java b/test/hotspot/jtreg/runtime/modules/AccessCheck/UmodUpkg_Umod.java index 9a68288c29a..3e0a96be527 100644 --- a/test/hotspot/jtreg/runtime/modules/AccessCheck/UmodUpkg_Umod.java +++ b/test/hotspot/jtreg/runtime/modules/AccessCheck/UmodUpkg_Umod.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -25,6 +25,7 @@ * @test * @summary Test public type c5 defined in an unnamed package and unnamed module can * access public type p6.c6 defined in an unnamed module. + * @library /test/lib * @compile myloaders/MySameClassLoader.java * @compile p6/c6.java * @compile c5.java diff --git a/test/hotspot/jtreg/runtime/modules/AccessCheck/Umod_UmodUpkg.java b/test/hotspot/jtreg/runtime/modules/AccessCheck/Umod_UmodUpkg.java index 895a722718f..4447cfbe5b3 100644 --- a/test/hotspot/jtreg/runtime/modules/AccessCheck/Umod_UmodUpkg.java +++ b/test/hotspot/jtreg/runtime/modules/AccessCheck/Umod_UmodUpkg.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -26,6 +26,7 @@ * @summary class p3.c3 defined in an unnamed module tries to access c4 defined in an unnamed package * and an unnamed module. * Access allowed since any class in an unnamed module can read an unnamed module. + * @library /test/lib * @compile myloaders/MySameClassLoader.java * @compile c4.java * @compile p3/c3.jcod diff --git a/test/hotspot/jtreg/runtime/modules/AccessCheck/myloaders/MyDiffClassLoader.java b/test/hotspot/jtreg/runtime/modules/AccessCheck/myloaders/MyDiffClassLoader.java index 63627590ebc..74c8a8bfacf 100644 --- a/test/hotspot/jtreg/runtime/modules/AccessCheck/myloaders/MyDiffClassLoader.java +++ b/test/hotspot/jtreg/runtime/modules/AccessCheck/myloaders/MyDiffClassLoader.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2021, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -24,6 +24,7 @@ package myloaders; import java.io.*; import java.lang.module.ModuleReference; +import jdk.test.lib.classloader.ClassUnloadCommon; // Declare a MyDiffClassLoader class to be used to map modules to. // This class loader will also be used to load classes within modules. @@ -49,24 +50,9 @@ public class MyDiffClassLoader extends ClassLoader return MyDiffClassLoader.loader2.loadClass(name); } - byte[] data = getClassData(name); + byte[] data = ClassUnloadCommon.getClassData(name); return defineClass(name, data, 0, data.length); } - byte[] getClassData(String name) { - try { - String TempName = name.replaceAll("\\.", "/"); - String currentDir = System.getProperty("test.classes"); - String filename = currentDir + File.separator + TempName + ".class"; - FileInputStream fis = new FileInputStream(filename); - byte[] b = new byte[5000]; - int cnt = fis.read(b, 0, 5000); - byte[] c = new byte[cnt]; - for (int i=0; i