Skip to content
Permalink
Browse files
8267348: Rewrite gc/epsilon/TestClasses.java to use Metaspace with le…
…ss classes

Reviewed-by: clanger
Backport-of: 7b98400
  • Loading branch information
shipilev committed Jul 27, 2021
1 parent d7a6e51 commit 227610d9b61b99d85833dd5912ac71239d38eace
Showing with 16 additions and 4 deletions.
  1. +16 −4 test/hotspot/jtreg/gc/epsilon/TestClasses.java
@@ -25,12 +25,12 @@
* @test TestClasses
* @key gc
* @requires vm.gc.Epsilon & !vm.graal.enabled
* @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 TestClasses
* @run main/othervm -Xmx1g -XX:MetaspaceSize=1m -XX:MaxMetaspaceSize=64m -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC -Xlog:gc -Xlog:gc+metaspace TestClasses
*/

import jdk.internal.org.objectweb.asm.ClassWriter;
@@ -43,14 +43,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();
}

@@ -65,7 +77,7 @@

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");

1 comment on commit 227610d

@openjdk-notifier

This comment has been minimized.

Copy link

@openjdk-notifier openjdk-notifier bot commented on 227610d Jul 27, 2021

Please sign in to comment.