Path: blob/master/test/hotspot/jtreg/gc/serial/HeapChangeLogging.java
40942 views
/*1* Copyright (c) 2013, 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223package gc.serial;2425/*26* @test HeapChangeLogging.java27* @bug 802744028* @requires vm.gc.Serial29* @library /test/lib30* @modules java.base/jdk.internal.misc31* @summary Allocate to get a promotion failure and verify that that heap change logging is present.32* @run driver gc.serial.HeapChangeLogging33*/3435import java.util.regex.Matcher;36import java.util.regex.Pattern;3738import jdk.test.lib.process.ProcessTools;39import jdk.test.lib.process.OutputAnalyzer;4041public class HeapChangeLogging {42public static void main(String[] args) throws Exception {43ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-Xmx128m", "-Xmn100m", "-XX:+UseSerialGC", "-Xlog:gc", HeapFiller.class.getName());44OutputAnalyzer output = new OutputAnalyzer(pb.start());45String stdout = output.getStdout();46System.out.println(stdout);47Matcher stdoutMatcher = Pattern.compile(".*\\(Allocation Failure\\) [0-9]+[KMG]->[0-9]+[KMG]\\([0-9]+[KMG]\\)", Pattern.MULTILINE).matcher(stdout);48if (!stdoutMatcher.find()) {49throw new RuntimeException("No proper GC log line found");50}51output.shouldHaveExitValue(0);52}53}5455class HeapFiller {56public static Entry root;57private static final int PAYLOAD_SIZE = 1000;5859public static void main(String[] args) {60root = new Entry(PAYLOAD_SIZE, null);61Entry current = root;62try {63while (true) {64Entry newEntry = new Entry(PAYLOAD_SIZE, current);65current = newEntry;66}67} catch (OutOfMemoryError e) {68root = null;69}7071}72}7374class Entry {75public Entry previous;76public byte[] payload;7778Entry(int payloadSize, Entry previous) {79payload = new byte[payloadSize];80this.previous = previous;81}82}838485