Path: blob/master/test/hotspot/jtreg/gc/g1/TestMixedGCLiveThreshold.java
64479 views
/*1* Copyright (c) 2021, 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.g1;2425/*26* @test id=0percent27* @summary Test G1MixedGCLiveThresholdPercent=0. Fill up a region to at least 33 percent,28* the region should not be selected for mixed GC cycle.29* @requires vm.gc.G130* @library /test/lib31* @build sun.hotspot.WhiteBox32* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox33* @run driver gc.g1.TestMixedGCLiveThreshold 0 false34*/3536/*37* @test id=25percent38* @summary Test G1MixedGCLiveThresholdPercent=25. Fill up a region to at least 33 percent,39* the region should not be selected for mixed GC cycle.40* @requires vm.gc.G141* @library /test/lib42* @build sun.hotspot.WhiteBox43* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox44* @run driver gc.g1.TestMixedGCLiveThreshold 25 false45*/4647/*48* @test id=100percent49* @summary Test G1MixedGCLiveThresholdPercent=100. Fill up a region to at least 33 percent,50* the region should be selected for mixed GC cycle.51* @requires vm.gc.G152* @library /test/lib53* @build sun.hotspot.WhiteBox54* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox55* @run driver gc.g1.TestMixedGCLiveThreshold 100 true56*/5758import java.util.ArrayList;59import java.util.Collections;60import java.util.regex.Pattern;61import java.util.regex.Matcher;6263import jdk.test.lib.process.OutputAnalyzer;64import jdk.test.lib.process.ProcessTools;65import jdk.test.lib.Asserts;66import sun.hotspot.WhiteBox;6768public class TestMixedGCLiveThreshold {69private static final String pattern = "Remembered Set Tracking update regions total ([0-9]+), selected ([0-9]+)$";7071public static void main(String[] args) throws Exception {72int liveThresholdPercent = Integer.parseInt(args[0]);73boolean expectRebuild = Boolean.parseBoolean(args[1]);74testMixedGCLiveThresholdPercent(liveThresholdPercent, expectRebuild);75}7677private static void testMixedGCLiveThresholdPercent(int liveThresholdPercent, boolean expectedRebuild) throws Exception {78OutputAnalyzer output = testWithMixedGCLiveThresholdPercent(liveThresholdPercent);7980boolean regionsSelected = regionsSelectedForRebuild(output.getStdout());8182Asserts.assertEquals(regionsSelected, expectedRebuild,83(expectedRebuild ?84"No Regions selected for rebuild. G1MixedGCLiveThresholdPercent=" + liveThresholdPercent +85" at least one region should be selected" :86"Regions selected for rebuild. G1MixedGCLiveThresholdPercent=" + liveThresholdPercent +87" no regions should be selected")88);89output.shouldHaveExitValue(0);90output.reportDiagnosticSummary();91}9293private static OutputAnalyzer testWithMixedGCLiveThresholdPercent(int percent) throws Exception {94ArrayList<String> basicOpts = new ArrayList<>();95Collections.addAll(basicOpts, new String[] {96"-Xbootclasspath/a:.",97"-XX:+UseG1GC",98"-XX:+UnlockDiagnosticVMOptions",99"-XX:+UnlockExperimentalVMOptions",100"-XX:+WhiteBoxAPI",101// Parallel full gc can distribute live objects into different regions.102"-XX:ParallelGCThreads=1",103"-Xlog:gc+remset+tracking=trace",104"-Xms10M",105"-Xmx10M"});106107basicOpts.add("-XX:G1MixedGCLiveThresholdPercent=" + percent);108109basicOpts.add(GCTest.class.getName());110111ProcessBuilder procBuilder = ProcessTools.createJavaProcessBuilder(basicOpts);112OutputAnalyzer analyzer = new OutputAnalyzer(procBuilder.start());113return analyzer;114}115116private static boolean regionsSelectedForRebuild(String output) throws Exception {117Matcher m = Pattern.compile(pattern, Pattern.MULTILINE).matcher(output);118119if (!m.find()) {120throw new Exception("Could not find correct output for Remembered Set Tracking in stdout," +121" should match the pattern \"" + pattern + "\", but stdout is \n" + output);122}123return Integer.parseInt(m.group(2)) > 0;124}125126public static class GCTest {127public static void main(String args[]) throws Exception {128WhiteBox wb = WhiteBox.getWhiteBox();129// Allocate some memory less than region size.130Object used = allocate();131132// Trigger the full GC using the WhiteBox API.133wb.fullGC(); // full134135// Memory objects have been promoted to old by full GC.136// Concurrent cycle may select regions for rebuilding137wb.g1StartConcMarkCycle(); // concurrent-start, remark and cleanup138139// Sleep to make sure concurrent cycle is done140while (wb.g1InConcurrentMark()) {141Thread.sleep(1000);142}143System.out.println(used);144}145146private static Object allocate() {147final int objectSize = WhiteBox.getWhiteBox().g1RegionSize() / 3;148Object ret = new byte[objectSize];149return ret;150}151}152}153154155