Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/test/runtime/SharedArchiveFile/SpaceUtilizationCheck.java
32284 views
/*1* Copyright (c) 2014, 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* @test SpaceUtilizationCheck25* @summary Check if the space utilization for shared spaces is adequate26* @library /testlibrary27* @run main SpaceUtilizationCheck28*/2930import com.oracle.java.testlibrary.*;3132import java.util.regex.Pattern;33import java.util.regex.Matcher;34import java.util.ArrayList;35import java.lang.Integer;3637public class SpaceUtilizationCheck {38// Minimum allowed utilization value (percent)39// The goal is to have this number to be 50% for RO and RW regions40// Once that feature is implemented, increase the MIN_UTILIZATION to 5041private static final int MIN_UTILIZATION = 30;4243// Only RO and RW regions are considered for this check, since they44// currently account for the bulk of the shared space45private static final int NUMBER_OF_CHECKED_SHARED_REGIONS = 2;4647public static void main(String[] args) throws Exception {48ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(49"-XX:+UnlockDiagnosticVMOptions",50"-XX:SharedArchiveFile=./test.jsa",51"-Xshare:dump");5253OutputAnalyzer output = new OutputAnalyzer(pb.start());54String stdout = output.getStdout();55ArrayList<String> utilization = findUtilization(stdout);5657if (utilization.size() != NUMBER_OF_CHECKED_SHARED_REGIONS )58throw new RuntimeException("The output format of sharing summary has changed");5960for(String str : utilization) {61int value = Integer.parseInt(str);62if (value < MIN_UTILIZATION) {63System.out.println(stdout);64throw new RuntimeException("Utilization for one of the regions" +65"is below a threshold of " + MIN_UTILIZATION + "%");66}67}68}6970public static ArrayList<String> findUtilization(String input) {71ArrayList<String> regions = filterRegionsOfInterest(input.split("\n"));72return filterByPattern(filterByPattern(regions, "bytes \\[.*% used\\]"), "\\d+");73}7475private static ArrayList<String> filterByPattern(Iterable<String> input, String pattern) {76ArrayList<String> result = new ArrayList<String>();77for (String str : input) {78Matcher matcher = Pattern.compile(pattern).matcher(str);79if (matcher.find()) {80result.add(matcher.group());81}82}83return result;84}8586private static ArrayList<String> filterRegionsOfInterest(String[] inputLines) {87ArrayList<String> result = new ArrayList<String>();88for (String str : inputLines) {89if (str.contains("ro space:") || str.contains("rw space:")) {90result.add(str);91}92}93return result;94}95}969798