Path: blob/master/test/hotspot/jtreg/gc/arguments/TestNewSizeThreadIncrease.java
40943 views
/*1* Copyright (c) 2015, 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.arguments;2425/*26* @test TestNewSizeThreadIncrease27* @bug 814452728* @summary Tests argument processing for NewSizeThreadIncrease29* @library /test/lib30* @library /31* @requires vm.gc.Serial32* @modules java.base/jdk.internal.misc33* java.management34* @run driver gc.arguments.TestNewSizeThreadIncrease35*/363738import jdk.test.lib.Platform;39import jdk.test.lib.process.OutputAnalyzer;40import jdk.test.lib.process.ProcessTools;414243// Range of NewSizeThreadIncrease is 0 ~ max_uintx.44// Total of 5 threads will be created (1 GCTest thread and 4 TestThread).45public class TestNewSizeThreadIncrease {46static final String VALID_VALUE = "2097152"; // 2MB4748// This value will make an overflow of 'thread count * NewSizeThreadIncrease' at DefNewGeneration::compute_new_size().49// = (max_uintx / 5) + 1, = (18446744073709551615 / 5) + 150static String INVALID_VALUE_1 = "3689348814741910324";5152// This string is contained when compute_new_size() expands or shrinks.53static final String LOG_NEWSIZE_CHANGED = "New generation size ";5455public static void main(String[] args) throws Exception {56if (Platform.is32bit()) {57// (max_uintx / 5) + 1, 4294967295/5 + 158INVALID_VALUE_1 = "858993460";59}6061// New size will be applied as NewSizeThreadIncrease is small enough to expand.62runNewSizeThreadIncreaseTest(VALID_VALUE, true);6364// New size will be ignored as 'thread count * NewSizeThreadIncrease' overflows.65runNewSizeThreadIncreaseTest(INVALID_VALUE_1, false);66}6768static void runNewSizeThreadIncreaseTest(String expectedValue, boolean isNewsizeChanged) throws Exception {69ProcessBuilder pb = GCArguments.createJavaProcessBuilder("-XX:+UseSerialGC",70"-Xms96M",71"-Xmx128M",72"-XX:NewRatio=2",73"-Xlog:gc+heap+ergo=debug",74"-XX:NewSizeThreadIncrease="+expectedValue,75GCTest.class.getName());76OutputAnalyzer output = new OutputAnalyzer(pb.start());7778output.shouldHaveExitValue(0);7980if (isNewsizeChanged) {81output.shouldContain(LOG_NEWSIZE_CHANGED);82} else {83output.shouldNotContain(LOG_NEWSIZE_CHANGED);84}85}8687static class GCTest {8889static final int MAX_THREADS_COUNT = 4;90static TestThread threads[] = new TestThread[MAX_THREADS_COUNT];9192public static void main(String[] args) {9394System.out.println("Creating garbage");9596for (int i=0; i<MAX_THREADS_COUNT; i++) {97threads[i] = new TestThread();98threads[i].start();99}100101System.gc();102103for (int i=0; i<MAX_THREADS_COUNT; i++) {104threads[i].stopRunning();105}106107System.out.println("Done");108}109110private static class TestThread extends Thread {111112volatile boolean isRunning = true;113114public void run() {115while (isRunning == true) {116try {117Thread.sleep(10);118} catch (Throwable t) {119}120}121}122123public void stopRunning() {124isRunning = false;125}126}127}128}129130131