3636 * @modules java.base/jdk.internal.misc
3737 * java.management
3838 * jdk.jartool/sun.tools.jar
39- * @build JfrReporter
40- * @run driver TestJFREvents
39+ * @build JfrReporter jdk.test.whitebox.WhiteBox
40+ * @run driver jdk.test.lib.helpers.ClassFileInstaller -jar whitebox.jar jdk.test.whitebox.WhiteBox
41+ * @run main/othervm -Xbootclasspath/a:whitebox.jar -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI TestJFREvents
4142 */
4243import java .util .List ;
44+ import jdk .internal .platform .Metrics ;
4345import jdk .test .lib .containers .docker .Common ;
4446import jdk .test .lib .containers .docker .DockerRunOptions ;
4547import jdk .test .lib .containers .docker .DockerTestUtils ;
4648import jdk .test .lib .Asserts ;
4749import jdk .test .lib .process .OutputAnalyzer ;
4850import jdk .test .lib .Utils ;
49- import jdk .internal . platform . Metrics ;
51+ import jdk .test . whitebox . WhiteBox ;
5052
5153
5254public class TestJFREvents {
5355 private static final String imageName = Common .imageName ("jfr-events" );
5456 private static final String TEST_ENV_VARIABLE = "UNIQUE_VARIABLE_ABC592903XYZ" ;
5557 private static final String TEST_ENV_VALUE = "unique_value_abc592903xyz" ;
5658 private static final int availableCPUs = Runtime .getRuntime ().availableProcessors ();
57- private static final int UNKNOWN = -100 ;
5859 private static boolean isCgroupV1 = false ;
60+ private static final WhiteBox wb = WhiteBox .getWhiteBox ();
5961
6062 public static void main (String [] args ) throws Exception {
6163 System .out .println ("Test Environment: detected availableCPUs = " + availableCPUs );
@@ -99,7 +101,7 @@ public static void main(String[] args) throws Exception {
99101 }
100102
101103 private static void containerInfoTestCase () throws Exception {
102- long hostTotalMemory = getHostTotalMemory ();
104+ long hostTotalMemory = wb . hostPhysicalMemory ();
103105 System .out .println ("Debug: Host total memory is " + hostTotalMemory );
104106 // Leave one CPU for system and tools, otherwise this test may be unstable.
105107 // Try the memory sizes that were verified by testMemory tests before.
@@ -111,18 +113,6 @@ private static void containerInfoTestCase() throws Exception {
111113 }
112114 }
113115
114- private static long getHostTotalMemory () throws Exception {
115- DockerRunOptions opts = Common .newOpts (imageName );
116-
117- String hostMem = Common .run (opts ).firstMatch ("total physical memory: (\\ d+)" , 1 );
118- try {
119- return Long .parseLong (hostMem );
120- } catch (NumberFormatException e ) {
121- System .out .println ("Could not parse total physical memory '" + hostMem + "' returning " + UNKNOWN );
122- return UNKNOWN ;
123- }
124- }
125-
126116 private static void testContainerInfo (int expectedCPUs , int expectedMemoryMB , long hostTotalMemory ) throws Exception {
127117 Common .logNewTestCase ("ContainerInfo: --cpus=" + expectedCPUs + " --memory=" + expectedMemoryMB + "m" );
128118 String eventName = "jdk.ContainerConfiguration" ;
0 commit comments