Path: blob/master/test/hotspot/jtreg/gc/g1/TestG1SkipCompaction.java
40942 views
/*1* Copyright (c) 2021, Huawei Technologies Co. Ltd. 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*/2223/*24* @test TestG1SkipCompaction25* @summary Test for JDK-8262068 Improve G1 Full GC by skipping compaction26* for regions with high survival ratio.27* @requires vm.gc.G128* @library /test/lib29* @modules java.base/jdk.internal.misc30* java.management31* @run main/othervm -Xms256m -Xmx256m TestG1SkipCompaction32*/33import java.util.regex.Matcher;34import java.util.regex.Pattern;3536import java.util.ArrayList;37import java.util.List;3839import jdk.test.lib.Platform;40import jdk.test.lib.process.OutputAnalyzer;41import jdk.test.lib.process.ProcessTools;4243public class TestG1SkipCompaction {44public static void runTest() throws Exception {45final String[] arguments = {46"-XX:+UseG1GC",47"-XX:MarkSweepDeadRatio=3",48"-Xmx8m",49"-Xms8M",50"-Xlog:gc+phases=trace",51"-XX:G1HeapRegionSize=1m",52GCTest.class.getName()53};54ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(arguments);55OutputAnalyzer output = new OutputAnalyzer(pb.start());56System.out.println(output.getStdout());5758String pattern = ".*skip compaction region.*";59Pattern r = Pattern.compile(pattern);60Matcher m = r.matcher(output.getStdout());6162if (!m.find()) {63throw new RuntimeException("Could not find any not compacted regions in the logs");64}65}6667public static void main(String[] args) throws Exception {68runTest();69}7071static class GCTest {72public static List<char[]> memory;73public static void main(String[] args) throws Exception {74memory = new ArrayList<>();75try {76while (true) {77memory.add(new char[8 * 1024]);78System.gc();79}80} catch (OutOfMemoryError e) {81memory = null;82System.gc();83}84}85}86}87888990