@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2020, 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
@@ -25,33 +25,44 @@
/*
* @test TestSmallHeap
* @requires vm.gc.Z & !vm.graal.enabled & vm.compMode != "Xcomp"
* @requires vm.gc.Z & !vm.graal.enabled
* @summary Test ZGC with small heaps
* @library /
* @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseZGC -Xlog:gc,gc+init,gc+heap -Xmx8M gc.z.TestSmallHeap
* @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseZGC -Xlog:gc,gc+init,gc+heap -Xmx16M gc.z.TestSmallHeap
* @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseZGC -Xlog:gc,gc+init,gc+heap -Xmx32M gc.z.TestSmallHeap
* @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseZGC -Xlog:gc,gc+init,gc+heap -Xmx64M gc.z.TestSmallHeap
* @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseZGC -Xlog:gc,gc+init,gc+heap -Xmx128M gc.z.TestSmallHeap
* @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseZGC -Xlog:gc,gc+init,gc+heap -Xmx256M gc.z.TestSmallHeap
* @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseZGC -Xlog:gc,gc+init,gc+heap -Xmx512M gc.z.TestSmallHeap
* @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseZGC -Xlog:gc,gc+init,gc+heap -Xmx1024M gc.z.TestSmallHeap
* @library / /test/lib
* @run main/othervm gc.z.TestSmallHeap 8M 16M 32M 64M 128M 256M 512M 1024M
*/
import jdk .test .lib .process .ProcessTools ;
import static gc .testlibrary .Allocation .blackHole ;
public class TestSmallHeap {
public static void main (String [] args ) throws Exception {
final long maxCapacity = Runtime .getRuntime ().maxMemory ();
System .out .println ("Max Capacity " + maxCapacity + " bytes" );
public static class Test {
public static void main (String [] args ) throws Exception {
final long maxCapacity = Runtime .getRuntime ().maxMemory ();
System .out .println ("Max Capacity " + maxCapacity + " bytes" );
// Allocate byte arrays of increasing length, so that
// all allocation paths (small/medium/large) are tested.
for (int length = 16 ; length <= maxCapacity / 16 ; length *= 2 ) {
System .out .println ("Allocating " + length + " bytes" );
blackHole (new byte [length ]);
}
// Allocate byte arrays of increasing length, so that
// all allocation paths (small/medium/large) are tested.
for (int length = 16 ; length <= maxCapacity / 16 ; length *= 2 ) {
System .out .println ("Allocating " + length + " bytes" );
blackHole (new byte [length ]);
System .out .println ("Success" );
}
}
System .out .println ("Success" );
public static void main (String [] args ) throws Exception {
for (var maxCapacity : args ) {
ProcessTools .executeProcess (ProcessTools .createJavaProcessBuilder (new String [] {
"-XX:+UnlockExperimentalVMOptions" ,
"-XX:+UseZGC" ,
"-Xlog:gc,gc+init,gc+reloc,gc+heap" ,
"-Xmx" + maxCapacity ,
Test .class .getName () }))
.outputTo (System .out )
.errorTo (System .out )
.shouldContain ("Success" )
.shouldHaveExitValue (0 );
}
}
}