--- /dev/null 2014-03-24 12:22:27.984991188 -0400 +++ new/test/runtime/SharedArchiveFile/ClassListExerciser.java 2014-03-27 15:15:22.366787489 -0400 @@ -0,0 +1,142 @@ +/* + * 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. + */ + +import java.io.IOException; +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.FileNotFoundException; +import java.io.IOException; +import com.oracle.java.testlibrary.*; + + +/* + * @test ClassListExerciser + * @summary Exercise loading of classes from the classlist, make sure + * no crashes or exceptions occur + * @library /testlibrary + * @run main/othervm ClassListExerciser createSharedArchive + * @run main/othervm ClassListExerciser $JAVA_HOME/jre/lib/classlist + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:SharedArchiveFile=./test.jsa -Xshare:auto ClassListExerciser $JAVA_HOME/jre/lib/classlist + */ + +/* What this class does: + * - read the boot classlist + * - for each class in a classlist: + * - load it + * - instantiate it (if default constructor exists) + */ +public class ClassListExerciser { + private final static boolean DIAGNOSTIC_MODE = false; + + public static void main(String[] args) throws Exception { + String firstArg = args[0]; + + if (args[0].equals("createSharedArchive")) { + createSharedArchive(); + } else { + String classListPath = args[0].replace("$JAVA_HOME", + System.getProperty("test.jdk")); + ClassListExerciser cle = new ClassListExerciser(); + ClassLoader classLoader = cle.getClassLoader(); + cle.exercise(classListPath, classLoader); + } + } + + private static void createSharedArchive() throws Exception { + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( + "-XX:+UnlockDiagnosticVMOptions", "-XX:SharedArchiveFile=./test.jsa", + "-Xshare:dump"); + OutputAnalyzer output = new OutputAnalyzer(pb.start()); + output.shouldContain("Loading classes to share"); + output.shouldHaveExitValue(0); + } + + // This method is used to get the class loader for use in this test + // Ideally, the bootstrap class loader should be used. However, it is + // not accessible via Java API. Using system or application class loader is + // fine in this case, since since by design such class loaders will + // delegate loading of bootstrap classes to the bootstrap class loader. + private ClassLoader getClassLoader() { + return ClassLoader.getSystemClassLoader(); + } + + private String getClassName(String lineFromClassList) { + return lineFromClassList.split("\\.class")[0].replace('/', '.'); + } + + // A filter to skip a given class, which has known problems loading + // Returns true for skipping + private boolean skipClass(String className) { + if ( className.startsWith("sun.awt.X11.XErrorHandler") || + (className.charAt(0) == '#') ) { + return true; + } + + // java.lang.ClassNotFoundException: javax.swing.text.AbstractDocument$InsertStringResult + // on Windows only + if (Platform.isWindows() && + className.equals("javax.swing.text.AbstractDocument$InsertStringResult") ) { + return true; + } + + // java.lang.ClassNotFoundException: java.lang.invoke.MagicLambdaImpl + // on Mac OSX only + if (Platform.isOSX() && + (className.equals("java.lang.invoke.MagicLambdaImpl") || + className.equals("sun.lwawt.macosx.LWCToolkit$5") ) ) { + return true; + } + + return false; + } + + public void exercise(String classListName, ClassLoader classLoader) + throws RuntimeException, FileNotFoundException, IOException, + ClassNotFoundException { + + BufferedReader reader = new BufferedReader(new FileReader(classListName)); + String line = null; + int nrOfLoadedClasses = 0; + + try { + while ((line = reader.readLine()) != null) { + + String className = getClassName(line); + + if (DIAGNOSTIC_MODE) + System.out.println(className); + + if (skipClass(className)) + continue; + + Class c = classLoader.loadClass(className); + nrOfLoadedClasses++; + } + } finally { + reader.close(); + } + + System.out.println("Number of loaded classes is " + nrOfLoadedClasses); + } + +} --- /dev/null 2014-03-24 12:22:27.984991188 -0400 +++ new/test/runtime/SharedArchiveFile/LimitSharedSizes.java 2014-03-27 15:15:22.754782612 -0400 @@ -0,0 +1,93 @@ +/* + * 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 LimitSharedSizes + * @summary Test handling of limits on shared space size + * @library /testlibrary + * @run main LimitSharedSizes + */ + +import com.oracle.java.testlibrary.*; + +public class LimitSharedSizes { + private static class SharedSizeTestData { + public String optionName; + public String optionValue; + public String expectedErrorMsg; + + public SharedSizeTestData(String name, String value, String msg) { + optionName = name; + optionValue = value; + expectedErrorMsg = msg; + } + } + + private static final SharedSizeTestData[] testTable = { + // values in this part of the test table should cause failure + // (shared space sizes are deliberately too small) + new SharedSizeTestData("-XX:SharedReadOnlySize", "4M", "read only"), + new SharedSizeTestData("-XX:SharedReadWriteSize","4M", "read write"), + + // Known issue, JDK-8038422 (assert() on Windows) + // new SharedSizeTestData("-XX:SharedMiscDataSize", "500k", "miscellaneous data"), + + // This will cause a VM crash; commenting out for now; see bug JDK-8038268 + // @ignore JDK-8038268 + // new SharedSizeTestData("-XX:SharedMiscCodeSize", "20k", "miscellaneous code"), + + // these values are larger than default ones, but should + // be acceptable and not cause failure + new SharedSizeTestData("-XX:SharedReadOnlySize", "20M", null), + new SharedSizeTestData("-XX:SharedReadWriteSize", "20M", null), + new SharedSizeTestData("-XX:SharedMiscDataSize", "20M", null), + new SharedSizeTestData("-XX:SharedMiscCodeSize", "20M", null) + }; + + public static void main(String[] args) throws Exception { + String fileName = "test.jsa"; + + for (SharedSizeTestData td : testTable) { + String option = td.optionName + "=" + td.optionValue; + System.out.println("testing option <" + option + ">"); + + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( + "-XX:+UnlockDiagnosticVMOptions", + "-XX:SharedArchiveFile=./" + fileName, + option, + "-Xshare:dump"); + + OutputAnalyzer output = new OutputAnalyzer(pb.start()); + + if (td.expectedErrorMsg != null) { + output.shouldContain("The shared " + td.expectedErrorMsg + + " space is not large enough"); + + output.shouldHaveExitValue(2); + } else { + output.shouldNotContain("space is not large enough"); + output.shouldHaveExitValue(0); + } + } + } +} --- /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; + } + +}