Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
8240714: ZGC: TestSmallHeap.java failed due to OutOfMemoryError
Reviewed-by: eosterlund
  • Loading branch information
pliden committed Mar 13, 2020
1 parent 9d502f6 commit 9e9457207883626c9f0bf5391f95a521ad9a670e
Showing with 31 additions and 20 deletions.
  1. +31 −20 test/hotspot/jtreg/gc/z/TestSmallHeap.java
@@ -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);
}
}
}

0 comments on commit 9e94572

Please sign in to comment.