--- /dev/null 2014-03-24 12:22:27.984991188 -0400 +++ new/test/runtime/SharedArchiveFile/SpaceUtilizationCheck.java 2014-03-27 15:15:23.122777984 -0400 @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test SpaceUtilizationCheck + * @summary Check if the space utilization for shared spaces is adequate + * @library /testlibrary + * @run main SpaceUtilizationCheck + */ + +import com.oracle.java.testlibrary.*; + +import java.util.regex.Pattern; +import java.util.regex.Matcher; +import java.util.ArrayList; +import java.lang.Integer; + +public class SpaceUtilizationCheck { + private static final int NUMBER_OF_SHARED_REGIONS = 4; + + // Minimum allowed utilization value (percent) + // The goal is to have this number to be 75% for RO and RW regions + // Once that feature is implemented, increase the MIN_UTILIZATION to 75 + // The utilization for MC region is less important since the size of the region is small + private static final int MIN_UTILIZATION = 25; + + public static void main(String[] args) throws Exception { + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( + "-XX:+UnlockDiagnosticVMOptions", + "-XX:SharedArchiveFile=./test.jsa", + "-Xshare:dump"); + + OutputAnalyzer output = new OutputAnalyzer(pb.start()); + String stdout = output.getStdout(); + ArrayList utilization = findUtilization(stdout); + + if (utilization.size() != (NUMBER_OF_SHARED_REGIONS + 1) ) + throw new RuntimeException("The output format of sharing summary has changed"); + + for(String str : utilization) { + int value = Integer.parseInt(str); + if (value < MIN_UTILIZATION) { + System.out.println(stdout); + throw new RuntimeException("Utilization for one of the regions" + + "is below a threshold of " + MIN_UTILIZATION + "%"); + } + } + } + + public static ArrayList findUtilization(String input) { + ArrayList result = new ArrayList(); + + String dm = "\\d"; // digit matcher + // matching "[dd.d% used]" + String regex = "\\[" + dm + dm + "\\." + dm + "% used" + "\\]"; + Matcher m = Pattern.compile(regex, Pattern.MULTILINE).matcher(input); + + while (m.find()) + result.add(input.substring(m.start() + 1, m.start() + 3 )); + + return result; + } + +}