test/runtime/SharedArchiveFile/SpaceUtilizationCheck.java

Fri, 19 Sep 2014 11:12:39 -0400

author
mseledtsov
date
Fri, 19 Sep 2014 11:12:39 -0400
changeset 7202
9c8439756c05
permissions
-rw-r--r--

8052313: Backport CDS tests from JDK-9 to jdk8_u40
Summary: Copied CDS tests from jdk-9 to jdk8u40
Reviewed-by: ccheung, dholmes

mseledtsov@7202 1 /*
mseledtsov@7202 2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
mseledtsov@7202 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
mseledtsov@7202 4 *
mseledtsov@7202 5 * This code is free software; you can redistribute it and/or modify it
mseledtsov@7202 6 * under the terms of the GNU General Public License version 2 only, as
mseledtsov@7202 7 * published by the Free Software Foundation.
mseledtsov@7202 8 *
mseledtsov@7202 9 * This code is distributed in the hope that it will be useful, but WITHOUT
mseledtsov@7202 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
mseledtsov@7202 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
mseledtsov@7202 12 * version 2 for more details (a copy is included in the LICENSE file that
mseledtsov@7202 13 * accompanied this code).
mseledtsov@7202 14 *
mseledtsov@7202 15 * You should have received a copy of the GNU General Public License version
mseledtsov@7202 16 * 2 along with this work; if not, write to the Free Software Foundation,
mseledtsov@7202 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
mseledtsov@7202 18 *
mseledtsov@7202 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
mseledtsov@7202 20 * or visit www.oracle.com if you need additional information or have any
mseledtsov@7202 21 * questions.
mseledtsov@7202 22 */
mseledtsov@7202 23
mseledtsov@7202 24 /*
mseledtsov@7202 25 * @test SpaceUtilizationCheck
mseledtsov@7202 26 * @summary Check if the space utilization for shared spaces is adequate
mseledtsov@7202 27 * @library /testlibrary
mseledtsov@7202 28 * @run main SpaceUtilizationCheck
mseledtsov@7202 29 */
mseledtsov@7202 30
mseledtsov@7202 31 import com.oracle.java.testlibrary.*;
mseledtsov@7202 32
mseledtsov@7202 33 import java.util.regex.Pattern;
mseledtsov@7202 34 import java.util.regex.Matcher;
mseledtsov@7202 35 import java.util.ArrayList;
mseledtsov@7202 36 import java.lang.Integer;
mseledtsov@7202 37
mseledtsov@7202 38 public class SpaceUtilizationCheck {
mseledtsov@7202 39 // Minimum allowed utilization value (percent)
mseledtsov@7202 40 // The goal is to have this number to be 50% for RO and RW regions
mseledtsov@7202 41 // Once that feature is implemented, increase the MIN_UTILIZATION to 50
mseledtsov@7202 42 private static final int MIN_UTILIZATION = 30;
mseledtsov@7202 43
mseledtsov@7202 44 // Only RO and RW regions are considered for this check, since they
mseledtsov@7202 45 // currently account for the bulk of the shared space
mseledtsov@7202 46 private static final int NUMBER_OF_CHECKED_SHARED_REGIONS = 2;
mseledtsov@7202 47
mseledtsov@7202 48 public static void main(String[] args) throws Exception {
mseledtsov@7202 49 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
mseledtsov@7202 50 "-XX:+UnlockDiagnosticVMOptions",
mseledtsov@7202 51 "-XX:SharedArchiveFile=./test.jsa",
mseledtsov@7202 52 "-Xshare:dump");
mseledtsov@7202 53
mseledtsov@7202 54 OutputAnalyzer output = new OutputAnalyzer(pb.start());
mseledtsov@7202 55 String stdout = output.getStdout();
mseledtsov@7202 56 ArrayList<String> utilization = findUtilization(stdout);
mseledtsov@7202 57
mseledtsov@7202 58 if (utilization.size() != NUMBER_OF_CHECKED_SHARED_REGIONS )
mseledtsov@7202 59 throw new RuntimeException("The output format of sharing summary has changed");
mseledtsov@7202 60
mseledtsov@7202 61 for(String str : utilization) {
mseledtsov@7202 62 int value = Integer.parseInt(str);
mseledtsov@7202 63 if (value < MIN_UTILIZATION) {
mseledtsov@7202 64 System.out.println(stdout);
mseledtsov@7202 65 throw new RuntimeException("Utilization for one of the regions" +
mseledtsov@7202 66 "is below a threshold of " + MIN_UTILIZATION + "%");
mseledtsov@7202 67 }
mseledtsov@7202 68 }
mseledtsov@7202 69 }
mseledtsov@7202 70
mseledtsov@7202 71 public static ArrayList<String> findUtilization(String input) {
mseledtsov@7202 72 ArrayList<String> regions = filterRegionsOfInterest(input.split("\n"));
mseledtsov@7202 73 return filterByPattern(filterByPattern(regions, "bytes \\[.*% used\\]"), "\\d+");
mseledtsov@7202 74 }
mseledtsov@7202 75
mseledtsov@7202 76 private static ArrayList<String> filterByPattern(Iterable<String> input, String pattern) {
mseledtsov@7202 77 ArrayList<String> result = new ArrayList<String>();
mseledtsov@7202 78 for (String str : input) {
mseledtsov@7202 79 Matcher matcher = Pattern.compile(pattern).matcher(str);
mseledtsov@7202 80 if (matcher.find()) {
mseledtsov@7202 81 result.add(matcher.group());
mseledtsov@7202 82 }
mseledtsov@7202 83 }
mseledtsov@7202 84 return result;
mseledtsov@7202 85 }
mseledtsov@7202 86
mseledtsov@7202 87 private static ArrayList<String> filterRegionsOfInterest(String[] inputLines) {
mseledtsov@7202 88 ArrayList<String> result = new ArrayList<String>();
mseledtsov@7202 89 for (String str : inputLines) {
mseledtsov@7202 90 if (str.contains("ro space:") || str.contains("rw space:")) {
mseledtsov@7202 91 result.add(str);
mseledtsov@7202 92 }
mseledtsov@7202 93 }
mseledtsov@7202 94 return result;
mseledtsov@7202 95 }
mseledtsov@7202 96 }

mercurial