diff --git a/test/hotspot/jtreg/runtime/InvocationTests/shared/AbstractGenerator.java b/test/hotspot/jtreg/runtime/InvocationTests/shared/AbstractGenerator.java index 9d5a7925fab..bfc793a0aa2 100644 --- a/test/hotspot/jtreg/runtime/InvocationTests/shared/AbstractGenerator.java +++ b/test/hotspot/jtreg/runtime/InvocationTests/shared/AbstractGenerator.java @@ -35,6 +35,7 @@ public abstract class AbstractGenerator { protected final boolean dumpClasses; protected final boolean executeTests; private static int testNum = 0; + private static int classesBeforeGC = 0; protected AbstractGenerator(String[] args) { List params = new ArrayList(Arrays.asList(args)); @@ -96,6 +97,14 @@ public abstract class AbstractGenerator { testNum++; + // Every N-th classes, force a GC to kick out the loaded classes from previous tests. + // Different tests come in with different number of classes, so testNum is not reliable. + classesBeforeGC -= classes.size(); + if (classesBeforeGC <= 0) { + System.gc(); + classesBeforeGC = 3000; + } + String caseDescription = String.format("%4d| %s", testNum, description); // Create test executor for a single case