Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
8263470: Consolidate copies of getClassBytes in various tests
Reviewed-by: hseigel, stuefe, mseledtsov
  • Loading branch information
coleenp committed Mar 12, 2021
1 parent 0ea48d9 commit b932a62c441c8ffd0967782a7faed8071855233f
Showing with 130 additions and 175 deletions.
  1. +3 −2 test/hotspot/jtreg/runtime/BadObjectClass/TestUnloadClassError.java
  2. +3 −3 test/hotspot/jtreg/runtime/ClassUnload/ConstantPoolDependsTest.java
  3. +3 −2 test/hotspot/jtreg/runtime/ClassUnload/DictionaryDependsTest.java
  4. +3 −2 test/hotspot/jtreg/runtime/ClassUnload/KeepAliveClass.java
  5. +3 −2 test/hotspot/jtreg/runtime/ClassUnload/KeepAliveClassLoader.java
  6. +3 −2 test/hotspot/jtreg/runtime/ClassUnload/KeepAliveObject.java
  7. +3 −2 test/hotspot/jtreg/runtime/ClassUnload/KeepAliveSoftReference.java
  8. +3 −17 test/hotspot/jtreg/runtime/ClassUnload/MyDiffClassLoader.java
  9. +4 −2 test/hotspot/jtreg/runtime/ClassUnload/SuperDependsTest.java
  10. +3 −2 test/hotspot/jtreg/runtime/ClassUnload/UnloadInterfaceTest.java
  11. +3 −2 test/hotspot/jtreg/runtime/ClassUnload/UnloadTest.java
  12. +2 −10 test/hotspot/jtreg/runtime/DefineClass/NullClassBytesTest.java
  13. +3 −2 test/hotspot/jtreg/runtime/MemberName/MemberNameLeak.java
  14. +3 −1 test/hotspot/jtreg/runtime/Nestmates/membership/TestNestHostErrorWithClassUnload.java
  15. +7 −4 test/hotspot/jtreg/runtime/cds/appcds/customLoader/HelloCustom.java
  16. +7 −4 test/hotspot/jtreg/runtime/cds/appcds/customLoader/HelloCustom_JFR.java
  17. +12 −10 test/hotspot/jtreg/runtime/cds/appcds/customLoader/UnloadUnregisteredLoaderTest.java
  18. +2 −1 test/hotspot/jtreg/runtime/cds/appcds/customLoader/test-classes/HelloUnload.java
  19. +2 −1 test/hotspot/jtreg/runtime/cds/appcds/customLoader/test-classes/UnloadUnregisteredLoader.java
  20. +6 −3 test/hotspot/jtreg/runtime/cds/appcds/dynamicArchive/HelloDynamicCustom.java
  21. +6 −3 test/hotspot/jtreg/runtime/cds/appcds/dynamicArchive/HelloDynamicCustomUnload.java
  22. +3 −2 test/hotspot/jtreg/runtime/defineAnonClass/TestAnonSymbolLeak.java
  23. +4 −2 test/hotspot/jtreg/runtime/logging/ClassLoadUnloadTest.java
  24. +4 −2 test/hotspot/jtreg/runtime/logging/LoaderConstraintsTest.java
  25. +4 −20 test/hotspot/jtreg/runtime/logging/loadLibraryTest/LoadLibraryTest.java
  26. +2 −1 test/hotspot/jtreg/runtime/modules/AccessCheck/UmodDiffCL_Umod.java
  27. +2 −1 test/hotspot/jtreg/runtime/modules/AccessCheck/UmodDiffCL_UmodUpkg.java
  28. +2 −1 test/hotspot/jtreg/runtime/modules/AccessCheck/UmodUpkgDiffCL_Umod.java
  29. +2 −1 test/hotspot/jtreg/runtime/modules/AccessCheck/UmodUpkg_Umod.java
  30. +2 −1 test/hotspot/jtreg/runtime/modules/AccessCheck/Umod_UmodUpkg.java
  31. +3 −17 test/hotspot/jtreg/runtime/modules/AccessCheck/myloaders/MyDiffClassLoader.java
  32. +3 −17 test/hotspot/jtreg/runtime/modules/AccessCheck/myloaders/MySameClassLoader.java
  33. +5 −19 test/hotspot/jtreg/runtime/modules/CCE_module_msg.java
  34. +7 −13 test/{hotspot/jtreg/runtime/testlibrary → lib/jdk/test/lib/classloader}/ClassUnloadCommon.java
  35. +3 −1 ...ot/jtreg/runtime/testlibrary → lib/jdk/test/lib/classloader}/ClassWithManyMethodsClassLoader.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 {

@@ -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,15 +28,15 @@
* @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
* @run main/othervm -Xbootclasspath/a:. -Xmn8m -XX:+UnlockDiagnosticVMOptions -Xlog:class+unload -XX:+WhiteBoxAPI ConstantPoolDependsTest
*/

import sun.hotspot.WhiteBox;

import jdk.test.lib.classloader.ClassUnloadCommon;

public class ConstantPoolDependsTest {
public static WhiteBox wb = WhiteBox.getWhiteBox();
@@ -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,14 +28,15 @@
* @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
* @run main/othervm -Xbootclasspath/a:. -Xmn8m -XX:+UnlockDiagnosticVMOptions -Xlog:class+unload -XX:+WhiteBoxAPI DictionaryDependsTest
*/
import sun.hotspot.WhiteBox;
import java.lang.reflect.Method;
import jdk.test.lib.classloader.ClassUnloadCommon;

public class DictionaryDependsTest {
public static WhiteBox wb = WhiteBox.getWhiteBox();
@@ -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.
@@ -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,14 +26,15 @@
* @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
* @run main/othervm -Xbootclasspath/a:. -Xmn8m -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI KeepAliveClassLoader
*/

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.
@@ -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,14 +26,15 @@
* @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
* @run main/othervm -Xbootclasspath/a:. -Xmn8m -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI KeepAliveObject
*/

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.
@@ -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.
@@ -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 loadClass(String name) throws ClassNotFoundException {
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<cnt; i++) c[i] = b[i];
return c;
} catch (IOException e) {
return null;
}
}

// Return p2.c2 with everything removed
byte[] getNewClassData(String name) {
@@ -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,14 +28,16 @@
* @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
* @run main/othervm -Xbootclasspath/a:. -Xmn8m -XX:+UnlockDiagnosticVMOptions -Xlog:class+unload -XX:+WhiteBoxAPI SuperDependsTest
*/

import sun.hotspot.WhiteBox;
import p2.*;
import jdk.test.lib.classloader.ClassUnloadCommon;

public class SuperDependsTest {
public static WhiteBox wb = WhiteBox.getWhiteBox();
@@ -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
@@ -25,7 +25,7 @@
* @test UnloadInterfaceTest
* @requires vm.opt.final.ClassUnloading
* @modules java.base/jdk.internal.misc
* @library /runtime/testlibrary /test/lib
* @library /test/lib
* @compile test/Interface.java
* @compile test/ImplementorClass.java
* @build sun.hotspot.WhiteBox
@@ -35,6 +35,7 @@
import sun.hotspot.WhiteBox;
import test.Interface;
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
@@ -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,13 +26,14 @@
* @bug 8210559
* @requires vm.opt.final.ClassUnloading
* @modules java.base/jdk.internal.misc
* @library /runtime/testlibrary /test/lib
* @library /test/lib
* @library classes
* @build sun.hotspot.WhiteBox test.Empty
* @run driver ClassFileInstaller sun.hotspot.WhiteBox
* @run main/othervm -Xbootclasspath/a:. -Xmn8m -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xlog:class+unload=debug UnloadTest
*/
import sun.hotspot.WhiteBox;
import jdk.test.lib.classloader.ClassUnloadCommon;

/**
* Test that verifies that classes are unloaded when they are no longer reachable.
@@ -31,7 +31,7 @@
* @run main/native NullClassBytesTest
*/

import java.io.*;
import jdk.test.lib.classloader.ClassUnloadCommon;

public class NullClassBytesTest {

@@ -50,7 +50,7 @@ public Class<?> loadClass(String name) throws ClassNotFoundException {

// load the class data from the connection
if (name.equals("A")) {
byte[] b = getClassData("A");
byte[] b = ClassUnloadCommon.getClassData("A");
return defineClass(name, b, 0, b.length);
} else if (name.equals("B")) {
byte[] b = new byte[0];
@@ -69,14 +69,6 @@ public Class<?> loadClass(String name) throws ClassNotFoundException {
}
}
}

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 {
@@ -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.
*
* This code is free software; you can redistribute it and/or modify it
@@ -25,7 +25,7 @@
* @test
* @bug 8174749 8213307
* @summary MemberNameTable should reuse entries
* @library /test/lib /runtime/testlibrary
* @library /test/lib
* @modules java.base/jdk.internal.misc
* @modules java.compiler
* @build sun.hotspot.WhiteBox
@@ -45,6 +45,7 @@
import sun.hotspot.WhiteBox;
import sun.hotspot.code.Compiler;
import sun.hotspot.gc.GC;
import jdk.test.lib.classloader.ClassWithManyMethodsClassLoader;

public class MemberNameLeak {
private static String className = "MemberNameLeakTestClass";
@@ -28,7 +28,7 @@
* successfully but fail validation. This tests a specific, otherwise
* untested, code path in ResolutionErrorTable::free_entry.
*
* @library /runtime/testlibrary
* @library /test/lib
* @compile TestNestHostErrorWithClassUnload.java
* Helper.java
* PackagedNestHost.java
@@ -62,6 +62,8 @@
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;

import jdk.test.lib.classloader.ClassUnloadCommon;

public class TestNestHostErrorWithClassUnload {

static final MethodType INVOKE_T = MethodType.methodType(void.class);
@@ -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.
*
* 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
* @requires vm.cds
* @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
* @build sun.hotspot.WhiteBox ClassUnloadCommon
* @run driver ClassFileInstaller -jar hello.jar HelloUnload ClassUnloadCommon ClassUnloadCommon$1 ClassUnloadCommon$TestFailure
* @build sun.hotspot.WhiteBox jdk.test.lib.classloader.ClassUnloadCommon
* @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 WhiteBox.jar sun.hotspot.WhiteBox
* @run driver HelloCustom

0 comments on commit b932a62

Please sign in to comment.