Path: blob/master/test/hotspot/jtreg/runtime/LoadClass/TestResize.java
40942 views
/*1* Copyright (c) 2017, 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*/2223/*24* @test25* @bug 818476526* @summary make sure the SystemDictionary gets resized when load factor is too high27* @requires vm.debug28* @library /test/lib29* @modules java.base/jdk.internal.misc30* java.management31* @compile TriggerResize.java32* @run driver TestResize33*/3435import jdk.test.lib.Platform;36import jdk.test.lib.process.OutputAnalyzer;37import jdk.test.lib.process.ProcessTools;38import java.io.BufferedReader;39import java.io.InputStreamReader;40import java.lang.Process;41import java.lang.ProcessBuilder;42import java.util.Scanner;4344public class TestResize {4546static double MAX_LOAD_FACTOR = 5.0; // see _resize_load_trigger in dictionary.cpp4748static int getInt(String string) {49int start = 0;50for (int i = 0; i < string.length(); i++) {51if (!Character.isDigit(string.charAt(i))) {52start++;53} else {54break;55}56}57int end = start;58for (int i = end; i < string.length(); i++) {59if (Character.isDigit(string.charAt(i))) {60end++;61} else {62break;63}64}65return Integer.parseInt(string.substring(start, end));66}6768static void analyzeOutputOn(ProcessBuilder pb) throws Exception {69OutputAnalyzer analyzer = new OutputAnalyzer(pb.start());70String output = analyzer.getStdout();71analyzer.shouldHaveExitValue(0);7273boolean resized = false;7475// Split string into lines using platform independent end of line marker.76String[] lines = output.split("\\R");77for (String line : lines) {78if (!resized) {79// ex. [0.563s][info][safepoint,cleanup] resizing system dictionaries, 0.0000002 secs80if (line.contains("resizing system dictionaries")) {81resized = true;82}83} else if (resized && line.startsWith("Java dictionary (")) {84// ex. Java dictionary (table_size=10103, classes=5002)85Scanner scanner = new Scanner(line);86scanner.next(); // skip "Java"87scanner.next(); // skip "dictionary"88int table_size = getInt(scanner.next()); // process "(table_size=40423"89int classes = getInt(scanner.next()); // process ", classes=50002"90scanner.close();9192double loadFactor = (double)classes / (double)table_size;93if (loadFactor > MAX_LOAD_FACTOR) {9495// We've hit an error, so print all of the output.96System.out.println(output);9798throw new RuntimeException("Load factor too high, expected MAX " + MAX_LOAD_FACTOR +99", got " + loadFactor + " [table size " + table_size + ", number of clases " + classes + "]");100} else {101System.out.println("PASS table_size: " + table_size + ", classes: " + classes +102", load factor: " + loadFactor + " <= " + MAX_LOAD_FACTOR);103// There are more than one system dictionary to check, so keep looking...104}105}106}107108if (!resized) {109System.out.println("PASS trivially. No resizing occurred, so did not check the load.");110}111}112113public static void main(String[] args) throws Exception {114// -XX:+PrintSystemDictionaryAtExit will print the details of system dictionary,115// that will allow us to calculate the table's load factor.116// -Xlog:safepoint+cleanup will print out cleanup details at safepoint117// that will allow us to detect if the system dictionary resized.118ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+PrintSystemDictionaryAtExit",119"-Xlog:safepoint+cleanup",120"TriggerResize",121"50000");122analyzeOutputOn(pb);123}124}125126127