8222103: [testbug] compiler/compilercontrol/jcmd/ClearDirectivesFileStackTest may exceed VM limit

Reviewed-by: iignatyev, mdoerr
diff --git a/test/hotspot/jtreg/ProblemList.txt b/test/hotspot/jtreg/ProblemList.txt
index 23765bc..2fa1f64 100644
--- a/test/hotspot/jtreg/ProblemList.txt
+++ b/test/hotspot/jtreg/ProblemList.txt
@@ -43,7 +43,6 @@
 compiler/ciReplay/TestSAServer.java 8029528 generic-all
 compiler/codecache/stress/OverloadCompileQueueTest.java 8166554 generic-all
 compiler/codegen/Test6896617.java 8193479 generic-all
-compiler/compilercontrol/jcmd/ClearDirectivesFileStackTest.java 8140405 generic-all
 compiler/jvmci/compilerToVM/GetFlagValueTest.java 8204459 generic-all
 compiler/jvmci/compilerToVM/GetResolvedJavaTypeTest.java 8158860 generic-all
 compiler/jvmci/compilerToVM/InvalidateInstalledCodeTest.java 8163894 generic-all
diff --git a/test/hotspot/jtreg/compiler/compilercontrol/jcmd/ClearDirectivesFileStackTest.java b/test/hotspot/jtreg/compiler/compilercontrol/jcmd/ClearDirectivesFileStackTest.java
index cb474d0..418172b 100644
--- a/test/hotspot/jtreg/compiler/compilercontrol/jcmd/ClearDirectivesFileStackTest.java
+++ b/test/hotspot/jtreg/compiler/compilercontrol/jcmd/ClearDirectivesFileStackTest.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2019, 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
@@ -31,7 +31,10 @@
  * @build sun.hotspot.WhiteBox
  * @run driver ClassFileInstaller sun.hotspot.WhiteBox
  *                                sun.hotspot.WhiteBox$WhiteBoxPermission
- * @run driver compiler.compilercontrol.jcmd.ClearDirectivesFileStackTest
+ *
+ * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
+ *                   -XX:+WhiteBoxAPI
+ *                   compiler.compilercontrol.jcmd.ClearDirectivesFileStackTest
  */
 
 package compiler.compilercontrol.jcmd;
@@ -44,11 +47,14 @@
 import compiler.compilercontrol.share.scenario.JcmdCommand;
 import compiler.compilercontrol.share.scenario.Scenario;
 import jdk.test.lib.Utils;
+import sun.hotspot.WhiteBox;
 
 import java.lang.reflect.Executable;
 
 public class ClearDirectivesFileStackTest extends AbstractTestBase {
-    private static final int AMOUNT = Utils.getRandomInstance().nextInt(100);
+    private static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox();
+    private static final int LIMIT = WHITE_BOX.getIntVMFlag("CompilerDirectivesLimit").intValue();
+    private static final int AMOUNT = Utils.getRandomInstance().nextInt(LIMIT);
     private final CommandGenerator cmdGen = new CommandGenerator();
 
     public static void main(String[] args) {