8263470: Consolidate copies of getClassBytes in various tests

Reviewed-by: hseigel, stuefe, mseledtsov
This commit is contained in:
Coleen Phillimore 2021-03-12 20:48:51 +00:00
parent 0ea48d9d65
commit b932a62c44
35 changed files with 130 additions and 175 deletions

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -29,13 +29,14 @@
* java.lang.Object class. * java.lang.Object class.
* Also, make sure the vm doesn't crash on notification for unloading an invalid * Also, make sure the vm doesn't crash on notification for unloading an invalid
* java.lang.Object class. * java.lang.Object class.
* @library /runtime/testlibrary /test/lib * @library /test/lib
* @modules java.base/jdk.internal.misc * @modules java.base/jdk.internal.misc
* java.compiler * java.compiler
* @run main TestUnloadClassError * @run main TestUnloadClassError
*/ */
import jdk.test.lib.compiler.InMemoryJavaCompiler; import jdk.test.lib.compiler.InMemoryJavaCompiler;
import jdk.test.lib.classloader.ClassUnloadCommon;
public class TestUnloadClassError extends ClassLoader { public class TestUnloadClassError extends ClassLoader {

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -28,7 +28,7 @@
* @requires vm.opt.final.ClassUnloading * @requires vm.opt.final.ClassUnloading
* @modules java.base/jdk.internal.misc * @modules java.base/jdk.internal.misc
* java.compiler * java.compiler
* @library /runtime/testlibrary /test/lib * @library /test/lib
* @build sun.hotspot.WhiteBox * @build sun.hotspot.WhiteBox
* @compile p2/c2.java MyDiffClassLoader.java * @compile p2/c2.java MyDiffClassLoader.java
* @run driver ClassFileInstaller sun.hotspot.WhiteBox * @run driver ClassFileInstaller sun.hotspot.WhiteBox
@ -36,7 +36,7 @@
*/ */
import sun.hotspot.WhiteBox; import sun.hotspot.WhiteBox;
import jdk.test.lib.classloader.ClassUnloadCommon;
public class ConstantPoolDependsTest { public class ConstantPoolDependsTest {
public static WhiteBox wb = WhiteBox.getWhiteBox(); public static WhiteBox wb = WhiteBox.getWhiteBox();

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -28,7 +28,7 @@
* @requires vm.opt.final.ClassUnloading * @requires vm.opt.final.ClassUnloading
* @modules java.base/jdk.internal.misc * @modules java.base/jdk.internal.misc
* java.compiler * java.compiler
* @library /runtime/testlibrary /test/lib * @library /test/lib
* @build sun.hotspot.WhiteBox * @build sun.hotspot.WhiteBox
* @compile p2/c2.java MyDiffClassLoader.java * @compile p2/c2.java MyDiffClassLoader.java
* @run driver ClassFileInstaller sun.hotspot.WhiteBox * @run driver ClassFileInstaller sun.hotspot.WhiteBox
@ -36,6 +36,7 @@
*/ */
import sun.hotspot.WhiteBox; import sun.hotspot.WhiteBox;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import jdk.test.lib.classloader.ClassUnloadCommon;
public class DictionaryDependsTest { public class DictionaryDependsTest {
public static WhiteBox wb = WhiteBox.getWhiteBox(); public static WhiteBox wb = WhiteBox.getWhiteBox();

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * 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. * @summary This test case uses a java.lang.Class instance to keep a class alive.
* @requires vm.opt.final.ClassUnloading * @requires vm.opt.final.ClassUnloading
* @modules java.base/jdk.internal.misc * @modules java.base/jdk.internal.misc
* @library /test/lib /runtime/testlibrary * @library /test/lib
* @library classes * @library classes
* @build sun.hotspot.WhiteBox test.Empty * @build sun.hotspot.WhiteBox test.Empty
* @run driver ClassFileInstaller sun.hotspot.WhiteBox * @run driver ClassFileInstaller sun.hotspot.WhiteBox
@ -35,6 +35,7 @@
import java.lang.ref.SoftReference; import java.lang.ref.SoftReference;
import sun.hotspot.WhiteBox; 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. * Test that verifies that classes are not unloaded when specific types of references are kept to them.

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * 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. * @summary This test case uses a java.lang.ClassLoader instance to keep a class alive.
* @requires vm.opt.final.ClassUnloading * @requires vm.opt.final.ClassUnloading
* @modules java.base/jdk.internal.misc * @modules java.base/jdk.internal.misc
* @library /test/lib /runtime/testlibrary * @library /test/lib
* @library classes * @library classes
* @build sun.hotspot.WhiteBox test.Empty * @build sun.hotspot.WhiteBox test.Empty
* @run driver ClassFileInstaller sun.hotspot.WhiteBox * @run driver ClassFileInstaller sun.hotspot.WhiteBox
@ -34,6 +34,7 @@
*/ */
import sun.hotspot.WhiteBox; 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. * Test that verifies that classes are not unloaded when specific types of references are kept to them.

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * 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. * @summary This test case uses a class instance to keep the class alive.
* @requires vm.opt.final.ClassUnloading * @requires vm.opt.final.ClassUnloading
* @modules java.base/jdk.internal.misc * @modules java.base/jdk.internal.misc
* @library /test/lib /runtime/testlibrary * @library /test/lib
* @library classes * @library classes
* @build sun.hotspot.WhiteBox test.Empty * @build sun.hotspot.WhiteBox test.Empty
* @run driver ClassFileInstaller sun.hotspot.WhiteBox * @run driver ClassFileInstaller sun.hotspot.WhiteBox
@ -34,6 +34,7 @@
*/ */
import sun.hotspot.WhiteBox; 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. * Test that verifies that classes are not unloaded when specific types of references are kept to them.

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * 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. * @summary This test case uses a java.lang.ref.SoftReference referencing a class instance to keep a class alive.
* @requires vm.opt.final.ClassUnloading * @requires vm.opt.final.ClassUnloading
* @modules java.base/jdk.internal.misc * @modules java.base/jdk.internal.misc
* @library /test/lib /runtime/testlibrary * @library /test/lib
* @library classes * @library classes
* @build sun.hotspot.WhiteBox test.Empty * @build sun.hotspot.WhiteBox test.Empty
* @run driver ClassFileInstaller sun.hotspot.WhiteBox * @run driver ClassFileInstaller sun.hotspot.WhiteBox
@ -35,6 +35,7 @@
import java.lang.ref.SoftReference; import java.lang.ref.SoftReference;
import sun.hotspot.WhiteBox; 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. * Test that verifies that classes are not unloaded when specific types of references are kept to them.

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -23,6 +23,7 @@
import java.io.*; import java.io.*;
import jdk.test.lib.compiler.InMemoryJavaCompiler; import jdk.test.lib.compiler.InMemoryJavaCompiler;
import jdk.test.lib.classloader.ClassUnloadCommon;
public class MyDiffClassLoader extends ClassLoader { public class MyDiffClassLoader extends ClassLoader {
@ -48,25 +49,10 @@ public class MyDiffClassLoader extends ClassLoader {
return c; return c;
} }
byte[] data = switchClassData ? getNewClassData(name) : getClassData(name); byte[] data = switchClassData ? getNewClassData(name) : ClassUnloadCommon.getClassData(name);
System.out.println("name is " + name); System.out.println("name is " + name);
return defineClass(name, data, 0, data.length); 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<cnt; i++) c[i] = b[i];
return c;
} catch (IOException e) {
return null;
}
}
// Return p2.c2 with everything removed // Return p2.c2 with everything removed
byte[] getNewClassData(String name) { byte[] getNewClassData(String name) {

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -28,14 +28,16 @@
* @requires vm.opt.final.ClassUnloading * @requires vm.opt.final.ClassUnloading
* @modules java.base/jdk.internal.misc * @modules java.base/jdk.internal.misc
* java.compiler * java.compiler
* @library /runtime/testlibrary /test/lib * @library /test/lib
* @build sun.hotspot.WhiteBox * @build sun.hotspot.WhiteBox
* @compile p2/c2.java MyDiffClassLoader.java * @compile p2/c2.java MyDiffClassLoader.java
* @run driver ClassFileInstaller sun.hotspot.WhiteBox * @run driver ClassFileInstaller sun.hotspot.WhiteBox
* @run main/othervm -Xbootclasspath/a:. -Xmn8m -XX:+UnlockDiagnosticVMOptions -Xlog:class+unload -XX:+WhiteBoxAPI SuperDependsTest * @run main/othervm -Xbootclasspath/a:. -Xmn8m -XX:+UnlockDiagnosticVMOptions -Xlog:class+unload -XX:+WhiteBoxAPI SuperDependsTest
*/ */
import sun.hotspot.WhiteBox; import sun.hotspot.WhiteBox;
import p2.*; import p2.*;
import jdk.test.lib.classloader.ClassUnloadCommon;
public class SuperDependsTest { public class SuperDependsTest {
public static WhiteBox wb = WhiteBox.getWhiteBox(); public static WhiteBox wb = WhiteBox.getWhiteBox();

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -25,7 +25,7 @@
* @test UnloadInterfaceTest * @test UnloadInterfaceTest
* @requires vm.opt.final.ClassUnloading * @requires vm.opt.final.ClassUnloading
* @modules java.base/jdk.internal.misc * @modules java.base/jdk.internal.misc
* @library /runtime/testlibrary /test/lib * @library /test/lib
* @compile test/Interface.java * @compile test/Interface.java
* @compile test/ImplementorClass.java * @compile test/ImplementorClass.java
* @build sun.hotspot.WhiteBox * @build sun.hotspot.WhiteBox
@ -35,6 +35,7 @@
import sun.hotspot.WhiteBox; import sun.hotspot.WhiteBox;
import test.Interface; import test.Interface;
import java.lang.ClassLoader; import java.lang.ClassLoader;
import jdk.test.lib.classloader.ClassUnloadCommon;
/** /**
* Test that verifies that class unloaded removes the implementor from its the interface that it implements * Test that verifies that class unloaded removes the implementor from its the interface that it implements

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -26,13 +26,14 @@
* @bug 8210559 * @bug 8210559
* @requires vm.opt.final.ClassUnloading * @requires vm.opt.final.ClassUnloading
* @modules java.base/jdk.internal.misc * @modules java.base/jdk.internal.misc
* @library /runtime/testlibrary /test/lib * @library /test/lib
* @library classes * @library classes
* @build sun.hotspot.WhiteBox test.Empty * @build sun.hotspot.WhiteBox test.Empty
* @run driver ClassFileInstaller sun.hotspot.WhiteBox * @run driver ClassFileInstaller sun.hotspot.WhiteBox
* @run main/othervm -Xbootclasspath/a:. -Xmn8m -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xlog:class+unload=debug UnloadTest * @run main/othervm -Xbootclasspath/a:. -Xmn8m -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xlog:class+unload=debug UnloadTest
*/ */
import sun.hotspot.WhiteBox; import sun.hotspot.WhiteBox;
import jdk.test.lib.classloader.ClassUnloadCommon;
/** /**
* Test that verifies that classes are unloaded when they are no longer reachable. * Test that verifies that classes are unloaded when they are no longer reachable.

View File

@ -31,7 +31,7 @@
* @run main/native NullClassBytesTest * @run main/native NullClassBytesTest
*/ */
import java.io.*; import jdk.test.lib.classloader.ClassUnloadCommon;
public class NullClassBytesTest { public class NullClassBytesTest {
@ -50,7 +50,7 @@ public class NullClassBytesTest {
// load the class data from the connection // load the class data from the connection
if (name.equals("A")) { if (name.equals("A")) {
byte[] b = getClassData("A"); byte[] b = ClassUnloadCommon.getClassData("A");
return defineClass(name, b, 0, b.length); return defineClass(name, b, 0, b.length);
} else if (name.equals("B")) { } else if (name.equals("B")) {
byte[] b = new byte[0]; byte[] b = new byte[0];
@ -69,14 +69,6 @@ public class NullClassBytesTest {
} }
} }
} }
byte[] getClassData(String name) {
try {
return SimpleLoader.class.getClassLoader().getResourceAsStream(name + ".class").readAllBytes();
} catch (IOException e) {
return null;
}
}
} }
public static void main(java.lang.String[] unused) throws Exception { public static void main(java.lang.String[] unused) throws Exception {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -25,7 +25,7 @@
* @test * @test
* @bug 8174749 8213307 * @bug 8174749 8213307
* @summary MemberNameTable should reuse entries * @summary MemberNameTable should reuse entries
* @library /test/lib /runtime/testlibrary * @library /test/lib
* @modules java.base/jdk.internal.misc * @modules java.base/jdk.internal.misc
* @modules java.compiler * @modules java.compiler
* @build sun.hotspot.WhiteBox * @build sun.hotspot.WhiteBox
@ -45,6 +45,7 @@ import jdk.test.lib.Utils;
import sun.hotspot.WhiteBox; import sun.hotspot.WhiteBox;
import sun.hotspot.code.Compiler; import sun.hotspot.code.Compiler;
import sun.hotspot.gc.GC; import sun.hotspot.gc.GC;
import jdk.test.lib.classloader.ClassWithManyMethodsClassLoader;
public class MemberNameLeak { public class MemberNameLeak {
private static String className = "MemberNameLeakTestClass"; private static String className = "MemberNameLeakTestClass";

View File

@ -28,7 +28,7 @@
* successfully but fail validation. This tests a specific, otherwise * successfully but fail validation. This tests a specific, otherwise
* untested, code path in ResolutionErrorTable::free_entry. * untested, code path in ResolutionErrorTable::free_entry.
* *
* @library /runtime/testlibrary * @library /test/lib
* @compile TestNestHostErrorWithClassUnload.java * @compile TestNestHostErrorWithClassUnload.java
* Helper.java * Helper.java
* PackagedNestHost.java * PackagedNestHost.java
@ -62,6 +62,8 @@ import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles; import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType; import java.lang.invoke.MethodType;
import jdk.test.lib.classloader.ClassUnloadCommon;
public class TestNestHostErrorWithClassUnload { public class TestNestHostErrorWithClassUnload {
static final MethodType INVOKE_T = MethodType.methodType(void.class); static final MethodType INVOKE_T = MethodType.methodType(void.class);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2015, 2019, 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -27,10 +27,13 @@
* @summary Hello World test for AppCDS custom loader support * @summary Hello World test for AppCDS custom loader support
* @requires vm.cds * @requires vm.cds
* @requires vm.cds.custom.loaders * @requires vm.cds.custom.loaders
* @library /test/lib /test/hotspot/jtreg/runtime/cds/appcds /runtime/testlibrary * @library /test/lib /test/hotspot/jtreg/runtime/cds/appcds
* @compile test-classes/HelloUnload.java test-classes/CustomLoadee.java * @compile test-classes/HelloUnload.java test-classes/CustomLoadee.java
* @build sun.hotspot.WhiteBox ClassUnloadCommon * @build sun.hotspot.WhiteBox jdk.test.lib.classloader.ClassUnloadCommon
* @run driver ClassFileInstaller -jar hello.jar HelloUnload ClassUnloadCommon ClassUnloadCommon$1 ClassUnloadCommon$TestFailure * @run driver ClassFileInstaller -jar hello.jar HelloUnload
* jdk.test.lib.classloader.ClassUnloadCommon
* jdk.test.lib.classloader.ClassUnloadCommon$1
* jdk.test.lib.classloader.ClassUnloadCommon$TestFailure
* @run driver ClassFileInstaller -jar hello_custom.jar CustomLoadee * @run driver ClassFileInstaller -jar hello_custom.jar CustomLoadee
* @run driver ClassFileInstaller -jar WhiteBox.jar sun.hotspot.WhiteBox * @run driver ClassFileInstaller -jar WhiteBox.jar sun.hotspot.WhiteBox
* @run driver HelloCustom * @run driver HelloCustom

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -30,10 +30,13 @@
* @requires vm.hasJFR * @requires vm.hasJFR
* @requires vm.cds * @requires vm.cds
* @requires vm.cds.custom.loaders * @requires vm.cds.custom.loaders
* @library /test/lib /test/hotspot/jtreg/runtime/cds/appcds /runtime/testlibrary * @library /test/lib /test/hotspot/jtreg/runtime/cds/appcds
* @compile test-classes/HelloUnload.java test-classes/CustomLoadee.java * @compile test-classes/HelloUnload.java test-classes/CustomLoadee.java
* @build sun.hotspot.WhiteBox ClassUnloadCommon * @build sun.hotspot.WhiteBox jdk.test.lib.classloader.ClassUnloadCommon
* @run driver ClassFileInstaller -jar hello.jar HelloUnload ClassUnloadCommon ClassUnloadCommon$1 ClassUnloadCommon$TestFailure * @run driver ClassFileInstaller -jar hello.jar HelloUnload
* jdk.test.lib.classloader.ClassUnloadCommon
* jdk.test.lib.classloader.ClassUnloadCommon$1
* jdk.test.lib.classloader.ClassUnloadCommon$TestFailure
* @run driver ClassFileInstaller -jar hello_custom.jar CustomLoadee * @run driver ClassFileInstaller -jar hello_custom.jar CustomLoadee
* @run driver ClassFileInstaller -jar WhiteBox.jar sun.hotspot.WhiteBox * @run driver ClassFileInstaller -jar WhiteBox.jar sun.hotspot.WhiteBox
* @run driver HelloCustom_JFR * @run driver HelloCustom_JFR

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2015, 2020, 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -29,13 +29,13 @@
* @requires vm.cds * @requires vm.cds
* @requires vm.cds.custom.loaders * @requires vm.cds.custom.loaders
* @requires vm.opt.final.ClassUnloading * @requires vm.opt.final.ClassUnloading
* @library /test/lib /test/hotspot/jtreg/runtime/cds/appcds /test/hotspot/jtreg/runtime/testlibrary * @library /test/lib /test/hotspot/jtreg/runtime/cds/appcds
* @build sun.hotspot.WhiteBox ClassUnloadCommon * @build sun.hotspot.WhiteBox jdk.test.lib.classloader.ClassUnloadCommon
* @compile test-classes/UnloadUnregisteredLoader.java test-classes/CustomLoadee.java * @compile test-classes/UnloadUnregisteredLoader.java test-classes/CustomLoadee.java
* @run driver ClassFileInstaller sun.hotspot.WhiteBox * @run driver ClassFileInstaller sun.hotspot.WhiteBox
* ClassUnloadCommon * jdk.test.lib.classloader.ClassUnloadCommon
* ClassUnloadCommon$1 * jdk.test.lib.classloader.ClassUnloadCommon$1
* ClassUnloadCommon$TestFailure * jdk.test.lib.classloader.ClassUnloadCommon$TestFailure
* @run driver UnloadUnregisteredLoaderTest * @run driver UnloadUnregisteredLoaderTest
*/ */
@ -46,7 +46,9 @@ public class UnloadUnregisteredLoaderTest {
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
String appJar1 = JarBuilder.build("UnloadUnregisteredLoader_app1", "UnloadUnregisteredLoader"); String appJar1 = JarBuilder.build("UnloadUnregisteredLoader_app1", "UnloadUnregisteredLoader");
String appJar2 = JarBuilder.build(true, "UnloadUnregisteredLoader_app2", String appJar2 = JarBuilder.build(true, "UnloadUnregisteredLoader_app2",
"ClassUnloadCommon", "ClassUnloadCommon$1", "ClassUnloadCommon$TestFailure"); "jdk/test/lib/classloader/ClassUnloadCommon",
"jdk/test/lib/classloader/ClassUnloadCommon$1",
"jdk/test/lib/classloader/ClassUnloadCommon$TestFailure");
String customJarPath = JarBuilder.build("UnloadUnregisteredLoader_custom", "CustomLoadee"); String customJarPath = JarBuilder.build("UnloadUnregisteredLoader_custom", "CustomLoadee");
String wbJar = JarBuilder.build(true, "WhiteBox", "sun/hotspot/WhiteBox"); String wbJar = JarBuilder.build(true, "WhiteBox", "sun/hotspot/WhiteBox");
String use_whitebox_jar = "-Xbootclasspath/a:" + wbJar; String use_whitebox_jar = "-Xbootclasspath/a:" + wbJar;
@ -54,9 +56,9 @@ public class UnloadUnregisteredLoaderTest {
String classpath = TestCommon.concatPaths(appJar1, appJar2); String classpath = TestCommon.concatPaths(appJar1, appJar2);
String classlist[] = new String[] { String classlist[] = new String[] {
"UnloadUnregisteredLoader", "UnloadUnregisteredLoader",
"ClassUnloadCommon", "jdk/test/lib/classloader/ClassUnloadCommon",
"ClassUnloadCommon$1", "jdk/test/lib/classloader/ClassUnloadCommon$1",
"ClassUnloadCommon$TestFailure", "jdk/test/lib/classloader/ClassUnloadCommon$TestFailure",
"java/lang/Object id: 1", "java/lang/Object id: 1",
"CustomLoadee id: 2 super: 1 source: " + customJarPath, "CustomLoadee id: 2 super: 1 source: " + customJarPath,
}; };

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -26,6 +26,7 @@ import java.io.File;
import java.net.URL; import java.net.URL;
import java.net.URLClassLoader; import java.net.URLClassLoader;
import sun.hotspot.WhiteBox; import sun.hotspot.WhiteBox;
import jdk.test.lib.classloader.ClassUnloadCommon;
public class HelloUnload { public class HelloUnload {
private static String className = "CustomLoadee"; private static String className = "CustomLoadee";

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2015, 2019, 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -26,6 +26,7 @@ import java.io.File;
import java.net.URL; import java.net.URL;
import java.net.URLClassLoader; import java.net.URLClassLoader;
import sun.hotspot.WhiteBox; import sun.hotspot.WhiteBox;
import jdk.test.lib.classloader.ClassUnloadCommon;
public class UnloadUnregisteredLoader { public class UnloadUnregisteredLoader {
public static void main(String args[]) throws Exception { public static void main(String args[]) throws Exception {

View File

@ -26,10 +26,13 @@
* @test * @test
* @summary Hello World test for dynamic archive with custom loader * @summary Hello World test for dynamic archive with custom loader
* @requires vm.cds * @requires vm.cds
* @library /test/lib /test/hotspot/jtreg/runtime/cds/appcds /test/hotspot/jtreg/runtime/cds/appcds/customLoader/test-classes /runtime/testlibrary * @library /test/lib /test/hotspot/jtreg/runtime/cds/appcds /test/hotspot/jtreg/runtime/cds/appcds/customLoader/test-classes
* @build HelloUnload CustomLoadee ClassUnloadCommon * @build HelloUnload CustomLoadee jdk.test.lib.classloader.ClassUnloadCommon
* @build sun.hotspot.WhiteBox * @build sun.hotspot.WhiteBox
* @run driver ClassFileInstaller -jar hello.jar HelloUnload ClassUnloadCommon ClassUnloadCommon$1 ClassUnloadCommon$TestFailure * @run driver ClassFileInstaller -jar hello.jar HelloUnload
* jdk.test.lib.classloader.ClassUnloadCommon
* jdk.test.lib.classloader.ClassUnloadCommon$1
* jdk.test.lib.classloader.ClassUnloadCommon$TestFailure
* @run driver ClassFileInstaller -jar hello_custom.jar CustomLoadee * @run driver ClassFileInstaller -jar hello_custom.jar CustomLoadee
* @run driver ClassFileInstaller -jar WhiteBox.jar sun.hotspot.WhiteBox * @run driver ClassFileInstaller -jar WhiteBox.jar sun.hotspot.WhiteBox
* @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:./WhiteBox.jar HelloDynamicCustom * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:./WhiteBox.jar HelloDynamicCustom

View File

@ -29,10 +29,13 @@
* dump time and run time. The custom loader will be unloaded * dump time and run time. The custom loader will be unloaded
* during dump time. * during dump time.
* @requires vm.cds * @requires vm.cds
* @library /test/lib /test/hotspot/jtreg/runtime/cds/appcds /test/hotspot/jtreg/runtime/cds/appcds/customLoader/test-classes /runtime/testlibrary * @library /test/lib /test/hotspot/jtreg/runtime/cds/appcds /test/hotspot/jtreg/runtime/cds/appcds/customLoader/test-classes
* @build HelloUnload CustomLoadee ClassUnloadCommon * @build HelloUnload CustomLoadee jdk.test.lib.classloader.ClassUnloadCommon
* @build sun.hotspot.WhiteBox * @build sun.hotspot.WhiteBox
* @run driver ClassFileInstaller -jar hello.jar HelloUnload ClassUnloadCommon ClassUnloadCommon$1 ClassUnloadCommon$TestFailure * @run driver ClassFileInstaller -jar hello.jar HelloUnload
* jdk.test.lib.classloader.ClassUnloadCommon
* jdk.test.lib.classloader.ClassUnloadCommon$1
* jdk.test.lib.classloader.ClassUnloadCommon$TestFailure
* @run driver ClassFileInstaller -jar hello_custom.jar CustomLoadee * @run driver ClassFileInstaller -jar hello_custom.jar CustomLoadee
* @run driver ClassFileInstaller -jar WhiteBox.jar sun.hotspot.WhiteBox * @run driver ClassFileInstaller -jar WhiteBox.jar sun.hotspot.WhiteBox
* @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:./WhiteBox.jar HelloDynamicCustomUnload * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:./WhiteBox.jar HelloDynamicCustomUnload

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -29,7 +29,7 @@
* @modules java.base/jdk.internal.misc * @modules java.base/jdk.internal.misc
* java.base/jdk.internal.org.objectweb.asm * java.base/jdk.internal.org.objectweb.asm
* java.management * java.management
* @library /test/lib /runtime/testlibrary * @library /test/lib
* @build p1.AnonSymbolLeak * @build p1.AnonSymbolLeak
* @build sun.hotspot.WhiteBox * @build sun.hotspot.WhiteBox
* @run driver ClassFileInstaller sun.hotspot.WhiteBox * @run driver ClassFileInstaller sun.hotspot.WhiteBox
@ -39,6 +39,7 @@
import java.lang.reflect.Method; import java.lang.reflect.Method;
import sun.hotspot.WhiteBox; import sun.hotspot.WhiteBox;
import jdk.test.lib.Asserts; import jdk.test.lib.Asserts;
import jdk.test.lib.classloader.ClassUnloadCommon;
public class TestAnonSymbolLeak { public class TestAnonSymbolLeak {
static String className = "p1.AnonSymbolLeak"; static String className = "p1.AnonSymbolLeak";

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2016, 2020, 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -27,7 +27,7 @@
* @bug 8142506 * @bug 8142506
* @requires vm.opt.final.ClassUnloading * @requires vm.opt.final.ClassUnloading
* @modules java.base/jdk.internal.misc * @modules java.base/jdk.internal.misc
* @library /test/lib /runtime/testlibrary * @library /test/lib
* @library classes * @library classes
* @build test.Empty * @build test.Empty
* @run driver ClassLoadUnloadTest * @run driver ClassLoadUnloadTest
@ -41,6 +41,8 @@ import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import jdk.test.lib.classloader.ClassUnloadCommon;
public class ClassLoadUnloadTest { public class ClassLoadUnloadTest {
private static OutputAnalyzer out; private static OutputAnalyzer out;
private static ProcessBuilder pb; private static ProcessBuilder pb;

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2016, 2020, 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -26,7 +26,7 @@
* @test LoaderConstraintsTest * @test LoaderConstraintsTest
* @bug 8149996 * @bug 8149996
* @modules java.base/jdk.internal.misc * @modules java.base/jdk.internal.misc
* @library /test/lib /runtime/testlibrary classes * @library /test/lib classes
* @run driver LoaderConstraintsTest * @run driver LoaderConstraintsTest
*/ */
@ -38,6 +38,8 @@ import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import jdk.test.lib.classloader.ClassUnloadCommon;
public class LoaderConstraintsTest { public class LoaderConstraintsTest {
private static OutputAnalyzer out; private static OutputAnalyzer out;
private static ProcessBuilder pb; private static ProcessBuilder pb;

View File

@ -25,23 +25,18 @@
* @test * @test
* @bug 8187305 * @bug 8187305
* @summary Tests logging of shared library loads and unloads. * @summary Tests logging of shared library loads and unloads.
* @library /runtime/testlibrary /test/lib * @library /test/lib
* @build sun.hotspot.WhiteBox * @build sun.hotspot.WhiteBox
* @run driver ClassFileInstaller sun.hotspot.WhiteBox * @run driver ClassFileInstaller sun.hotspot.WhiteBox
* @run main LoadLibraryTest * @run main LoadLibraryTest
*/ */
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import jdk.test.lib.process.ProcessTools; import jdk.test.lib.process.ProcessTools;
import jdk.test.lib.process.OutputAnalyzer; import jdk.test.lib.process.OutputAnalyzer;
import jtreg.SkippedException; import jtreg.SkippedException;
import sun.hotspot.WhiteBox; import sun.hotspot.WhiteBox;
import jdk.test.lib.classloader.ClassUnloadCommon;
public class LoadLibraryTest { public class LoadLibraryTest {
@ -86,18 +81,6 @@ public class LoadLibraryTest {
public static class MyClassLoader extends ClassLoader { public static class MyClassLoader extends ClassLoader {
static ByteBuffer readClassFile(String name) {
File f = new File(testClasses, name);
try (FileInputStream fin = new FileInputStream(f);
FileChannel fc = fin.getChannel())
{
return fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size());
} catch (IOException e) {
throw new RuntimeException("Can't open file: " + name +
", exception: " + e.toString());
}
}
protected Class<?> loadClass(String name, boolean resolve) protected Class<?> loadClass(String name, boolean resolve)
throws ClassNotFoundException { throws ClassNotFoundException {
Class<?> c; Class<?> c;
@ -117,7 +100,8 @@ public class LoadLibraryTest {
if (!CLASS_NAME.equals(name)) { if (!CLASS_NAME.equals(name)) {
throw new ClassNotFoundException("Unexpected class: " + 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 } // MyClassLoader
} }

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * 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 * defined in an unnamed module. Access allowed since unnamed module
* can read unnamed module even when class p1.c1 is loaded by * can read unnamed module even when class p1.c1 is loaded by
* a different loader than p2.c2. * a different loader than p2.c2.
* @library /test/lib
* @compile myloaders/MyDiffClassLoader.java * @compile myloaders/MyDiffClassLoader.java
* @compile p2/c2.java * @compile p2/c2.java
* @compile p1/c1.java * @compile p1/c1.java

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * 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 * @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 * defined in an unnamed package in an unnamed module. Access allowed since
* any class in an unnamed module can read an unnamed module. * any class in an unnamed module can read an unnamed module.
* @library /test/lib
* @compile myloaders/MyDiffClassLoader.java * @compile myloaders/MyDiffClassLoader.java
* @compile c4.java * @compile c4.java
* @compile p3/c3.jcod * @compile p3/c3.jcod

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -25,6 +25,7 @@
* @test * @test
* @summary Test public type c5 defined in an unnamed package and unnamed module can * @summary Test public type c5 defined in an unnamed package and unnamed module can
* access public type p6.c6 defined in an unnamed module. * access public type p6.c6 defined in an unnamed module.
* @library /test/lib
* @compile myloaders/MyDiffClassLoader.java * @compile myloaders/MyDiffClassLoader.java
* @compile p6/c6.java * @compile p6/c6.java
* @compile c5.java * @compile c5.java

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -25,6 +25,7 @@
* @test * @test
* @summary Test public type c5 defined in an unnamed package and unnamed module can * @summary Test public type c5 defined in an unnamed package and unnamed module can
* access public type p6.c6 defined in an unnamed module. * access public type p6.c6 defined in an unnamed module.
* @library /test/lib
* @compile myloaders/MySameClassLoader.java * @compile myloaders/MySameClassLoader.java
* @compile p6/c6.java * @compile p6/c6.java
* @compile c5.java * @compile c5.java

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * 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 * @summary class p3.c3 defined in an unnamed module tries to access c4 defined in an unnamed package
* and an unnamed module. * and an unnamed module.
* Access allowed since any class in an unnamed module can read 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 myloaders/MySameClassLoader.java
* @compile c4.java * @compile c4.java
* @compile p3/c3.jcod * @compile p3/c3.jcod

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -24,6 +24,7 @@ package myloaders;
import java.io.*; import java.io.*;
import java.lang.module.ModuleReference; import java.lang.module.ModuleReference;
import jdk.test.lib.classloader.ClassUnloadCommon;
// Declare a MyDiffClassLoader class to be used to map modules to. // Declare a MyDiffClassLoader class to be used to map modules to.
// This class loader will also be used to load classes within modules. // 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); return MyDiffClassLoader.loader2.loadClass(name);
} }
byte[] data = getClassData(name); byte[] data = ClassUnloadCommon.getClassData(name);
return defineClass(name, data, 0, data.length); 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<cnt; i++) c[i] = b[i];
return c;
} catch (IOException e) {
return null;
}
}
public void register(ModuleReference mref) { } public void register(ModuleReference mref) { }
} }

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -24,6 +24,7 @@ package myloaders;
import java.io.*; import java.io.*;
import java.lang.module.ModuleReference; import java.lang.module.ModuleReference;
import jdk.test.lib.classloader.ClassUnloadCommon;
// Declare a MySameClassLoader class to be used to map modules to the same // Declare a MySameClassLoader class to be used to map modules to the same
// class loader. This class loader will also be used to load classes // class loader. This class loader will also be used to load classes
@ -45,24 +46,9 @@ public class MySameClassLoader extends ClassLoader
!name.equals("p6.c6")) { !name.equals("p6.c6")) {
return super.loadClass(name); return super.loadClass(name);
} }
byte[] data = getClassData(name); byte[] data = ClassUnloadCommon.getClassData(name);
return defineClass(name, data, 0, data.length); 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<cnt; i++) c[i] = b[i];
return c;
} catch (IOException e) {
return null;
}
}
public void register(ModuleReference mref) { } public void register(ModuleReference mref) { }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2016, 2020, 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -24,7 +24,7 @@
/** /**
* @test * @test
* @modules java.base/jdk.internal.misc * @modules java.base/jdk.internal.misc
* @library /test/lib .. * @library /test/lib
* @compile p2/c2.java * @compile p2/c2.java
* @compile p4/c4.java * @compile p4/c4.java
* @build sun.hotspot.WhiteBox * @build sun.hotspot.WhiteBox
@ -40,6 +40,8 @@ import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import static jdk.test.lib.Asserts.*; import static jdk.test.lib.Asserts.*;
import jdk.test.lib.classloader.ClassUnloadCommon;
// Test that the message in a runtime ClassCastException contains module info. // Test that the message in a runtime ClassCastException contains module info.
public class CCE_module_msg { public class CCE_module_msg {
private static final Path CLASSES_DIR = Paths.get("classes"); private static final Path CLASSES_DIR = Paths.get("classes");
@ -208,23 +210,7 @@ class MyURLClassLoader extends URLClassLoader {
if (!name.equals("p4.c4")) { if (!name.equals("p4.c4")) {
return super.loadClass(name); return super.loadClass(name);
} }
byte[] data = getClassData(name); byte[] data = ClassUnloadCommon.getClassData(name);
return defineClass(name, data, 0, data.length); 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<cnt; i++) c[i] = b[i];
return c;
} catch (IOException e) {
return null;
}
}
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2013, 2019, 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -28,6 +28,8 @@
*/ */
package jdk.test.lib.classloader;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
@ -111,18 +113,10 @@ public class ClassUnloadCommon {
// Get data for pre-compiled class file to load. // Get data for pre-compiled class file to load.
public static byte[] getClassData(String name) { public static byte[] getClassData(String name) {
try { try {
String TempName = name.replaceAll("\\.", "/"); String tempName = name.replaceAll("\\.", "/");
String currentDir = System.getProperty("test.classes"); return ClassUnloadCommon.class.getClassLoader().getResourceAsStream(tempName + ".class").readAllBytes();
String filename = currentDir + File.separator + TempName + ".class"; } catch (Exception e) {
System.out.println("filename is " + filename); return null;
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<cnt; i++) c[i] = b[i];
return c;
} catch (IOException e) {
return null;
} }
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -21,6 +21,8 @@
* questions. * questions.
*/ */
package jdk.test.lib.classloader;
import java.io.DataInputStream; import java.io.DataInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.File; import java.io.File;