Skip to content
This repository was archived by the owner on Aug 27, 2022. It is now read-only.

Commit b932a62

Browse files
committed
8263470: Consolidate copies of getClassBytes in various tests
Reviewed-by: hseigel, stuefe, mseledtsov
1 parent 0ea48d9 commit b932a62

35 files changed

+130
-175
lines changed

test/hotspot/jtreg/runtime/BadObjectClass/TestUnloadClassError.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -29,13 +29,14 @@
2929
* java.lang.Object class.
3030
* Also, make sure the vm doesn't crash on notification for unloading an invalid
3131
* java.lang.Object class.
32-
* @library /runtime/testlibrary /test/lib
32+
* @library /test/lib
3333
* @modules java.base/jdk.internal.misc
3434
* java.compiler
3535
* @run main TestUnloadClassError
3636
*/
3737

3838
import jdk.test.lib.compiler.InMemoryJavaCompiler;
39+
import jdk.test.lib.classloader.ClassUnloadCommon;
3940

4041
public class TestUnloadClassError extends ClassLoader {
4142

test/hotspot/jtreg/runtime/ClassUnload/ConstantPoolDependsTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -28,15 +28,15 @@
2828
* @requires vm.opt.final.ClassUnloading
2929
* @modules java.base/jdk.internal.misc
3030
* java.compiler
31-
* @library /runtime/testlibrary /test/lib
31+
* @library /test/lib
3232
* @build sun.hotspot.WhiteBox
3333
* @compile p2/c2.java MyDiffClassLoader.java
3434
* @run driver ClassFileInstaller sun.hotspot.WhiteBox
3535
* @run main/othervm -Xbootclasspath/a:. -Xmn8m -XX:+UnlockDiagnosticVMOptions -Xlog:class+unload -XX:+WhiteBoxAPI ConstantPoolDependsTest
3636
*/
3737

3838
import sun.hotspot.WhiteBox;
39-
39+
import jdk.test.lib.classloader.ClassUnloadCommon;
4040

4141
public class ConstantPoolDependsTest {
4242
public static WhiteBox wb = WhiteBox.getWhiteBox();

test/hotspot/jtreg/runtime/ClassUnload/DictionaryDependsTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -28,14 +28,15 @@
2828
* @requires vm.opt.final.ClassUnloading
2929
* @modules java.base/jdk.internal.misc
3030
* java.compiler
31-
* @library /runtime/testlibrary /test/lib
31+
* @library /test/lib
3232
* @build sun.hotspot.WhiteBox
3333
* @compile p2/c2.java MyDiffClassLoader.java
3434
* @run driver ClassFileInstaller sun.hotspot.WhiteBox
3535
* @run main/othervm -Xbootclasspath/a:. -Xmn8m -XX:+UnlockDiagnosticVMOptions -Xlog:class+unload -XX:+WhiteBoxAPI DictionaryDependsTest
3636
*/
3737
import sun.hotspot.WhiteBox;
3838
import java.lang.reflect.Method;
39+
import jdk.test.lib.classloader.ClassUnloadCommon;
3940

4041
public class DictionaryDependsTest {
4142
public static WhiteBox wb = WhiteBox.getWhiteBox();

test/hotspot/jtreg/runtime/ClassUnload/KeepAliveClass.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2013, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2013, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -26,7 +26,7 @@
2626
* @summary This test case uses a java.lang.Class instance to keep a class alive.
2727
* @requires vm.opt.final.ClassUnloading
2828
* @modules java.base/jdk.internal.misc
29-
* @library /test/lib /runtime/testlibrary
29+
* @library /test/lib
3030
* @library classes
3131
* @build sun.hotspot.WhiteBox test.Empty
3232
* @run driver ClassFileInstaller sun.hotspot.WhiteBox
@@ -35,6 +35,7 @@
3535

3636
import java.lang.ref.SoftReference;
3737
import sun.hotspot.WhiteBox;
38+
import jdk.test.lib.classloader.ClassUnloadCommon;
3839

3940
/**
4041
* Test that verifies that classes are not unloaded when specific types of references are kept to them.

test/hotspot/jtreg/runtime/ClassUnload/KeepAliveClassLoader.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2013, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2013, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -26,14 +26,15 @@
2626
* @summary This test case uses a java.lang.ClassLoader instance to keep a class alive.
2727
* @requires vm.opt.final.ClassUnloading
2828
* @modules java.base/jdk.internal.misc
29-
* @library /test/lib /runtime/testlibrary
29+
* @library /test/lib
3030
* @library classes
3131
* @build sun.hotspot.WhiteBox test.Empty
3232
* @run driver ClassFileInstaller sun.hotspot.WhiteBox
3333
* @run main/othervm -Xbootclasspath/a:. -Xmn8m -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI KeepAliveClassLoader
3434
*/
3535

3636
import sun.hotspot.WhiteBox;
37+
import jdk.test.lib.classloader.ClassUnloadCommon;
3738

3839
/**
3940
* Test that verifies that classes are not unloaded when specific types of references are kept to them.

test/hotspot/jtreg/runtime/ClassUnload/KeepAliveObject.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2013, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2013, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -26,14 +26,15 @@
2626
* @summary This test case uses a class instance to keep the class alive.
2727
* @requires vm.opt.final.ClassUnloading
2828
* @modules java.base/jdk.internal.misc
29-
* @library /test/lib /runtime/testlibrary
29+
* @library /test/lib
3030
* @library classes
3131
* @build sun.hotspot.WhiteBox test.Empty
3232
* @run driver ClassFileInstaller sun.hotspot.WhiteBox
3333
* @run main/othervm -Xbootclasspath/a:. -Xmn8m -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI KeepAliveObject
3434
*/
3535

3636
import sun.hotspot.WhiteBox;
37+
import jdk.test.lib.classloader.ClassUnloadCommon;
3738

3839
/**
3940
* Test that verifies that classes are not unloaded when specific types of references are kept to them.

test/hotspot/jtreg/runtime/ClassUnload/KeepAliveSoftReference.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2013, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2013, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -26,7 +26,7 @@
2626
* @summary This test case uses a java.lang.ref.SoftReference referencing a class instance to keep a class alive.
2727
* @requires vm.opt.final.ClassUnloading
2828
* @modules java.base/jdk.internal.misc
29-
* @library /test/lib /runtime/testlibrary
29+
* @library /test/lib
3030
* @library classes
3131
* @build sun.hotspot.WhiteBox test.Empty
3232
* @run driver ClassFileInstaller sun.hotspot.WhiteBox
@@ -35,6 +35,7 @@
3535

3636
import java.lang.ref.SoftReference;
3737
import sun.hotspot.WhiteBox;
38+
import jdk.test.lib.classloader.ClassUnloadCommon;
3839

3940
/**
4041
* Test that verifies that classes are not unloaded when specific types of references are kept to them.

test/hotspot/jtreg/runtime/ClassUnload/MyDiffClassLoader.java

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -23,6 +23,7 @@
2323

2424
import java.io.*;
2525
import jdk.test.lib.compiler.InMemoryJavaCompiler;
26+
import jdk.test.lib.classloader.ClassUnloadCommon;
2627

2728
public class MyDiffClassLoader extends ClassLoader {
2829

@@ -48,25 +49,10 @@ public Class loadClass(String name) throws ClassNotFoundException {
4849
return c;
4950
}
5051

51-
byte[] data = switchClassData ? getNewClassData(name) : getClassData(name);
52+
byte[] data = switchClassData ? getNewClassData(name) : ClassUnloadCommon.getClassData(name);
5253
System.out.println("name is " + name);
5354
return defineClass(name, data, 0, data.length);
5455
}
55-
byte[] getClassData(String name) {
56-
try {
57-
String TempName = name.replaceAll("\\.", "/");
58-
String currentDir = System.getProperty("test.classes");
59-
String filename = currentDir + File.separator + TempName + ".class";
60-
FileInputStream fis = new FileInputStream(filename);
61-
byte[] b = new byte[5000];
62-
int cnt = fis.read(b, 0, 5000);
63-
byte[] c = new byte[cnt];
64-
for (int i=0; i<cnt; i++) c[i] = b[i];
65-
return c;
66-
} catch (IOException e) {
67-
return null;
68-
}
69-
}
7056

7157
// Return p2.c2 with everything removed
7258
byte[] getNewClassData(String name) {

test/hotspot/jtreg/runtime/ClassUnload/SuperDependsTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -28,14 +28,16 @@
2828
* @requires vm.opt.final.ClassUnloading
2929
* @modules java.base/jdk.internal.misc
3030
* java.compiler
31-
* @library /runtime/testlibrary /test/lib
31+
* @library /test/lib
3232
* @build sun.hotspot.WhiteBox
3333
* @compile p2/c2.java MyDiffClassLoader.java
3434
* @run driver ClassFileInstaller sun.hotspot.WhiteBox
3535
* @run main/othervm -Xbootclasspath/a:. -Xmn8m -XX:+UnlockDiagnosticVMOptions -Xlog:class+unload -XX:+WhiteBoxAPI SuperDependsTest
3636
*/
37+
3738
import sun.hotspot.WhiteBox;
3839
import p2.*;
40+
import jdk.test.lib.classloader.ClassUnloadCommon;
3941

4042
public class SuperDependsTest {
4143
public static WhiteBox wb = WhiteBox.getWhiteBox();

test/hotspot/jtreg/runtime/ClassUnload/UnloadInterfaceTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -25,7 +25,7 @@
2525
* @test UnloadInterfaceTest
2626
* @requires vm.opt.final.ClassUnloading
2727
* @modules java.base/jdk.internal.misc
28-
* @library /runtime/testlibrary /test/lib
28+
* @library /test/lib
2929
* @compile test/Interface.java
3030
* @compile test/ImplementorClass.java
3131
* @build sun.hotspot.WhiteBox
@@ -35,6 +35,7 @@
3535
import sun.hotspot.WhiteBox;
3636
import test.Interface;
3737
import java.lang.ClassLoader;
38+
import jdk.test.lib.classloader.ClassUnloadCommon;
3839

3940
/**
4041
* Test that verifies that class unloaded removes the implementor from its the interface that it implements

0 commit comments

Comments
 (0)