Skip to content

Commit

Permalink
8267348: Rewrite gc/epsilon/TestClasses.java to use Metaspace with le…
Browse files Browse the repository at this point in the history
…ss classes

Reviewed-by: stuefe
  • Loading branch information
shipilev committed May 20, 2021
1 parent ca93399 commit 7b98400
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
1 change: 0 additions & 1 deletion test/hotspot/jtreg/ProblemList.txt
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ gc/stress/gclocker/TestGCLockerWithParallel.java 8180622 generic-all
gc/stress/gclocker/TestGCLockerWithG1.java 8180622 generic-all
gc/stress/TestJNIBlockFullGC/TestJNIBlockFullGC.java 8192647 generic-all
gc/metaspace/CompressedClassSpaceSizeInJmapHeap.java 8241293 macosx-x64
gc/epsilon/TestClasses.java 8267348 linux-x64

#############################################################################

Expand Down
20 changes: 16 additions & 4 deletions test/hotspot/jtreg/gc/epsilon/TestClasses.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@
/**
* @test TestClasses
* @requires vm.gc.Epsilon
* @summary Epsilon is able to allocate a lot of classes
* @summary Epsilon is able to allocate a lot of classes, resizing Metaspace
*
* @modules java.base/jdk.internal.org.objectweb.asm
* java.base/jdk.internal.misc
*
* @run main/othervm -Xmx128m -XX:MetaspaceSize=1m -XX:MaxMetaspaceSize=64m -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC -Xlog:gc -Xlog:gc+metaspace gc.epsilon.TestClasses
* @run main/othervm -Xmx1g -XX:MetaspaceSize=1m -XX:MaxMetaspaceSize=64m -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC -Xlog:gc -Xlog:gc+metaspace gc.epsilon.TestClasses
*/

import jdk.internal.org.objectweb.asm.ClassWriter;
Expand All @@ -44,14 +44,26 @@

public class TestClasses {

static final int COUNT = 32*1024;
static final int CLASSES = 1024;
static final int FIELDS = 1024;

static volatile Object sink;

static class MyClassLoader extends ClassLoader {
static final String[] FIELD_NAMES;
static {
FIELD_NAMES = new String[FIELDS];
for (int c = 0; c < FIELDS; c++) {
FIELD_NAMES[c] = "f" + c;
}
}

public byte[] createClass(String name) {
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);
cw.visit(Opcodes.V1_8, Opcodes.ACC_PUBLIC | Opcodes.ACC_SUPER, name, null, "java/lang/Object", null);
for (String fName : FIELD_NAMES) {
cw.visitField(Opcodes.ACC_STATIC | Opcodes.ACC_PRIVATE, fName, "J", null, null);
}
return cw.toByteArray();
}

Expand All @@ -66,7 +78,7 @@ public Class<?> loadClass(String name) throws ClassNotFoundException {

public static void main(String[] args) throws Exception {
ClassLoader cl = new MyClassLoader();
for (int c = 0; c < COUNT; c++) {
for (int c = 0; c < CLASSES; c++) {
Class<?> clazz = Class.forName("Dummy" + c, true, cl);
if (clazz.getClassLoader() != cl) {
throw new IllegalStateException("Should have loaded by target loader");
Expand Down

1 comment on commit 7b98400

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.