Fri, 19 Sep 2014 11:12:39 -0400
8052313: Backport CDS tests from JDK-9 to jdk8_u40
Summary: Copied CDS tests from jdk-9 to jdk8u40
Reviewed-by: ccheung, dholmes
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/test/runtime/SharedArchiveFile/ArchiveDoesNotExist.java Fri Sep 19 11:12:39 2014 -0400 1.3 @@ -0,0 +1,68 @@ 1.4 +/* 1.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + */ 1.26 + 1.27 +/* 1.28 + * @test ArchiveDoesNotExist 1.29 + * @summary Test how VM handles "file does not exist" situation while 1.30 + * attempting to use CDS archive. JVM should exit gracefully 1.31 + * when sharing mode is ON, and continue w/o sharing if sharing 1.32 + * mode is AUTO. 1.33 + * @library /testlibrary 1.34 + * @run main ArchiveDoesNotExist 1.35 + */ 1.36 + 1.37 +import com.oracle.java.testlibrary.*; 1.38 +import java.io.File; 1.39 + 1.40 +public class ArchiveDoesNotExist { 1.41 + public static void main(String[] args) throws Exception { 1.42 + String fileName = "test.jsa"; 1.43 + 1.44 + File cdsFile = new File(fileName); 1.45 + if (cdsFile.exists()) 1.46 + throw new RuntimeException("Test error: cds file already exists"); 1.47 + 1.48 + // Sharing: on 1.49 + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( 1.50 + "-XX:+UnlockDiagnosticVMOptions", 1.51 + "-XX:SharedArchiveFile=./" + fileName, 1.52 + "-Xshare:on", 1.53 + "-version"); 1.54 + 1.55 + OutputAnalyzer output = new OutputAnalyzer(pb.start()); 1.56 + output.shouldContain("Specified shared archive not found"); 1.57 + output.shouldHaveExitValue(1); 1.58 + 1.59 + // Sharing: auto 1.60 + pb = ProcessTools.createJavaProcessBuilder( 1.61 + "-XX:+UnlockDiagnosticVMOptions", 1.62 + "-XX:SharedArchiveFile=./" + fileName, 1.63 + "-Xshare:auto", 1.64 + "-version"); 1.65 + 1.66 + output = new OutputAnalyzer(pb.start()); 1.67 + output.shouldMatch("(java|openjdk) version"); 1.68 + output.shouldNotContain("sharing"); 1.69 + output.shouldHaveExitValue(0); 1.70 + } 1.71 +}
2.1 --- a/test/runtime/SharedArchiveFile/CdsDifferentObjectAlignment.java Fri Sep 19 02:23:20 2014 -0700 2.2 +++ b/test/runtime/SharedArchiveFile/CdsDifferentObjectAlignment.java Fri Sep 19 11:12:39 2014 -0400 2.3 @@ -1,5 +1,5 @@ 2.4 /* 2.5 - * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 2.6 + * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved. 2.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 2.8 * 2.9 * This code is free software; you can redistribute it and/or modify it 2.10 @@ -29,6 +29,7 @@ 2.11 * is different from object alignment for creating a CDS file 2.12 * should fail when loading. 2.13 * @library /testlibrary 2.14 + * @bug 8025642 2.15 */ 2.16 2.17 import com.oracle.java.testlibrary.*; 2.18 @@ -82,7 +83,11 @@ 2.19 createAlignment, 2.20 loadAlignment); 2.21 2.22 - output.shouldContain(expectedErrorMsg); 2.23 + try { 2.24 + output.shouldContain(expectedErrorMsg); 2.25 + } catch (RuntimeException e) { 2.26 + output.shouldContain("Unable to use shared archive"); 2.27 + } 2.28 output.shouldHaveExitValue(1); 2.29 } 2.30 }
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/test/runtime/SharedArchiveFile/DefaultUseWithClient.java Fri Sep 19 11:12:39 2014 -0400 3.3 @@ -0,0 +1,72 @@ 3.4 +/* 3.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 3.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3.7 + * 3.8 + * This code is free software; you can redistribute it and/or modify it 3.9 + * under the terms of the GNU General Public License version 2 only, as 3.10 + * published by the Free Software Foundation. 3.11 + * 3.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 3.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 3.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 3.15 + * version 2 for more details (a copy is included in the LICENSE file that 3.16 + * accompanied this code). 3.17 + * 3.18 + * You should have received a copy of the GNU General Public License version 3.19 + * 2 along with this work; if not, write to the Free Software Foundation, 3.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 3.21 + * 3.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 3.23 + * or visit www.oracle.com if you need additional information or have any 3.24 + * questions. 3.25 + */ 3.26 + 3.27 +/* 3.28 + * @test DefaultUseWithClient 3.29 + * @summary Test default behavior of sharing with -client 3.30 + * @library /testlibrary 3.31 + * @run main DefaultUseWithClient 3.32 + * @bug 8032224 3.33 + */ 3.34 + 3.35 +import com.oracle.java.testlibrary.*; 3.36 +import java.io.File; 3.37 + 3.38 +public class DefaultUseWithClient { 3.39 + public static void main(String[] args) throws Exception { 3.40 + String fileName = "test.jsa"; 3.41 + 3.42 + // On 32-bit windows CDS should be on by default in "-client" config 3.43 + // Skip this test on any other platform 3.44 + boolean is32BitWindows = (Platform.isWindows() && Platform.is32bit()); 3.45 + if (!is32BitWindows) { 3.46 + System.out.println("Test only applicable on 32-bit Windows. Skipping"); 3.47 + return; 3.48 + } 3.49 + 3.50 + // create the archive 3.51 + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( 3.52 + "-XX:+UnlockDiagnosticVMOptions", 3.53 + "-XX:SharedArchiveFile=./" + fileName, 3.54 + "-Xshare:dump"); 3.55 + OutputAnalyzer output = new OutputAnalyzer(pb.start()); 3.56 + output.shouldHaveExitValue(0); 3.57 + 3.58 + pb = ProcessTools.createJavaProcessBuilder( 3.59 + "-XX:+UnlockDiagnosticVMOptions", 3.60 + "-XX:SharedArchiveFile=./" + fileName, 3.61 + "-client", 3.62 + "-XX:+PrintSharedSpaces", 3.63 + "-version"); 3.64 + 3.65 + output = new OutputAnalyzer(pb.start()); 3.66 + try { 3.67 + output.shouldContain("sharing"); 3.68 + } catch (RuntimeException e) { 3.69 + // if sharing failed due to ASLR or similar reasons, 3.70 + // check whether sharing was attempted at all (UseSharedSpaces) 3.71 + output.shouldContain("UseSharedSpaces:"); 3.72 + } 3.73 + output.shouldHaveExitValue(0); 3.74 + } 3.75 +}
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 4.2 +++ b/test/runtime/SharedArchiveFile/LimitSharedSizes.java Fri Sep 19 11:12:39 2014 -0400 4.3 @@ -0,0 +1,92 @@ 4.4 +/* 4.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 4.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4.7 + * 4.8 + * This code is free software; you can redistribute it and/or modify it 4.9 + * under the terms of the GNU General Public License version 2 only, as 4.10 + * published by the Free Software Foundation. 4.11 + * 4.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 4.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 4.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 4.15 + * version 2 for more details (a copy is included in the LICENSE file that 4.16 + * accompanied this code). 4.17 + * 4.18 + * You should have received a copy of the GNU General Public License version 4.19 + * 2 along with this work; if not, write to the Free Software Foundation, 4.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 4.21 + * 4.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 4.23 + * or visit www.oracle.com if you need additional information or have any 4.24 + * questions. 4.25 + */ 4.26 + 4.27 +/* @test LimitSharedSizes 4.28 + * @summary Test handling of limits on shared space size 4.29 + * @library /testlibrary 4.30 + * @run main LimitSharedSizes 4.31 + */ 4.32 + 4.33 +import com.oracle.java.testlibrary.*; 4.34 + 4.35 +public class LimitSharedSizes { 4.36 + private static class SharedSizeTestData { 4.37 + public String optionName; 4.38 + public String optionValue; 4.39 + public String expectedErrorMsg; 4.40 + 4.41 + public SharedSizeTestData(String name, String value, String msg) { 4.42 + optionName = name; 4.43 + optionValue = value; 4.44 + expectedErrorMsg = msg; 4.45 + } 4.46 + } 4.47 + 4.48 + private static final SharedSizeTestData[] testTable = { 4.49 + // values in this part of the test table should cause failure 4.50 + // (shared space sizes are deliberately too small) 4.51 + new SharedSizeTestData("-XX:SharedReadOnlySize", "4M", "read only"), 4.52 + new SharedSizeTestData("-XX:SharedReadWriteSize","4M", "read write"), 4.53 + 4.54 + // Known issue, JDK-8038422 (assert() on Windows) 4.55 + // new SharedSizeTestData("-XX:SharedMiscDataSize", "500k", "miscellaneous data"), 4.56 + 4.57 + // This will cause a VM crash; commenting out for now; see bug JDK-8038268 4.58 + // @ignore JDK-8038268 4.59 + // new SharedSizeTestData("-XX:SharedMiscCodeSize", "20k", "miscellaneous code"), 4.60 + 4.61 + // these values are larger than default ones, but should 4.62 + // be acceptable and not cause failure 4.63 + new SharedSizeTestData("-XX:SharedReadOnlySize", "20M", null), 4.64 + new SharedSizeTestData("-XX:SharedReadWriteSize", "20M", null), 4.65 + new SharedSizeTestData("-XX:SharedMiscDataSize", "20M", null), 4.66 + new SharedSizeTestData("-XX:SharedMiscCodeSize", "20M", null) 4.67 + }; 4.68 + 4.69 + public static void main(String[] args) throws Exception { 4.70 + String fileName = "test.jsa"; 4.71 + 4.72 + for (SharedSizeTestData td : testTable) { 4.73 + String option = td.optionName + "=" + td.optionValue; 4.74 + System.out.println("testing option <" + option + ">"); 4.75 + 4.76 + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( 4.77 + "-XX:+UnlockDiagnosticVMOptions", 4.78 + "-XX:SharedArchiveFile=./" + fileName, 4.79 + option, 4.80 + "-Xshare:dump"); 4.81 + 4.82 + OutputAnalyzer output = new OutputAnalyzer(pb.start()); 4.83 + 4.84 + if (td.expectedErrorMsg != null) { 4.85 + output.shouldContain("The shared " + td.expectedErrorMsg 4.86 + + " space is not large enough"); 4.87 + 4.88 + output.shouldHaveExitValue(2); 4.89 + } else { 4.90 + output.shouldNotContain("space is not large enough"); 4.91 + output.shouldHaveExitValue(0); 4.92 + } 4.93 + } 4.94 + } 4.95 +}
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 5.2 +++ b/test/runtime/SharedArchiveFile/SharedBaseAddress.java Fri Sep 19 11:12:39 2014 -0400 5.3 @@ -0,0 +1,77 @@ 5.4 +/* 5.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 5.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5.7 + * 5.8 + * This code is free software; you can redistribute it and/or modify it 5.9 + * under the terms of the GNU General Public License version 2 only, as 5.10 + * published by the Free Software Foundation. 5.11 + * 5.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 5.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 5.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 5.15 + * version 2 for more details (a copy is included in the LICENSE file that 5.16 + * accompanied this code). 5.17 + * 5.18 + * You should have received a copy of the GNU General Public License version 5.19 + * 2 along with this work; if not, write to the Free Software Foundation, 5.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 5.21 + * 5.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 5.23 + * or visit www.oracle.com if you need additional information or have any 5.24 + * questions. 5.25 + */ 5.26 + 5.27 +/* 5.28 + * @test SharedBaseAddress 5.29 + * @summary Test variety of values for SharedBaseAddress, making sure 5.30 + * VM handles normal values as well as edge values w/o a crash. 5.31 + * @library /testlibrary 5.32 + * @run main SharedBaseAddress 5.33 + */ 5.34 + 5.35 +import com.oracle.java.testlibrary.*; 5.36 + 5.37 +public class SharedBaseAddress { 5.38 + 5.39 + // shared base address test table 5.40 + private static final String[] testTable = { 5.41 + "1g", "8g", "64g","512g", "4t", 5.42 + "32t", "128t", "0", 5.43 + "1", "64k", "64M" 5.44 + }; 5.45 + 5.46 + public static void main(String[] args) throws Exception { 5.47 + // Known issue on Solaris-Sparc 5.48 + // @ignore JDK-8044600 5.49 + if (Platform.isSolaris() && Platform.isSparc()) 5.50 + return; 5.51 + 5.52 + for (String testEntry : testTable) { 5.53 + System.out.println("sharedBaseAddress = " + testEntry); 5.54 + 5.55 + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( 5.56 + "-XX:+UnlockDiagnosticVMOptions", 5.57 + "-XX:SharedArchiveFile=test.jsa", 5.58 + "-XX:SharedBaseAddress=" + testEntry, 5.59 + "-Xshare:dump"); 5.60 + 5.61 + OutputAnalyzer output = new OutputAnalyzer(pb.start()); 5.62 + 5.63 + output.shouldContain("Loading classes to share"); 5.64 + 5.65 + try { 5.66 + pb = ProcessTools.createJavaProcessBuilder( 5.67 + "-XX:+UnlockDiagnosticVMOptions", 5.68 + "-XX:SharedArchiveFile=test.jsa", 5.69 + "-Xshare:on", 5.70 + "-version"); 5.71 + output = new OutputAnalyzer(pb.start()); 5.72 + output.shouldContain("sharing"); 5.73 + output.shouldHaveExitValue(0); 5.74 + } catch (RuntimeException e) { 5.75 + output.shouldContain("Unable to use shared archive"); 5.76 + output.shouldHaveExitValue(1); 5.77 + } 5.78 + } 5.79 + } 5.80 +}
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 6.2 +++ b/test/runtime/SharedArchiveFile/SpaceUtilizationCheck.java Fri Sep 19 11:12:39 2014 -0400 6.3 @@ -0,0 +1,96 @@ 6.4 +/* 6.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 6.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 6.7 + * 6.8 + * This code is free software; you can redistribute it and/or modify it 6.9 + * under the terms of the GNU General Public License version 2 only, as 6.10 + * published by the Free Software Foundation. 6.11 + * 6.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 6.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 6.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 6.15 + * version 2 for more details (a copy is included in the LICENSE file that 6.16 + * accompanied this code). 6.17 + * 6.18 + * You should have received a copy of the GNU General Public License version 6.19 + * 2 along with this work; if not, write to the Free Software Foundation, 6.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 6.21 + * 6.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 6.23 + * or visit www.oracle.com if you need additional information or have any 6.24 + * questions. 6.25 + */ 6.26 + 6.27 +/* 6.28 + * @test SpaceUtilizationCheck 6.29 + * @summary Check if the space utilization for shared spaces is adequate 6.30 + * @library /testlibrary 6.31 + * @run main SpaceUtilizationCheck 6.32 + */ 6.33 + 6.34 +import com.oracle.java.testlibrary.*; 6.35 + 6.36 +import java.util.regex.Pattern; 6.37 +import java.util.regex.Matcher; 6.38 +import java.util.ArrayList; 6.39 +import java.lang.Integer; 6.40 + 6.41 +public class SpaceUtilizationCheck { 6.42 + // Minimum allowed utilization value (percent) 6.43 + // The goal is to have this number to be 50% for RO and RW regions 6.44 + // Once that feature is implemented, increase the MIN_UTILIZATION to 50 6.45 + private static final int MIN_UTILIZATION = 30; 6.46 + 6.47 + // Only RO and RW regions are considered for this check, since they 6.48 + // currently account for the bulk of the shared space 6.49 + private static final int NUMBER_OF_CHECKED_SHARED_REGIONS = 2; 6.50 + 6.51 + public static void main(String[] args) throws Exception { 6.52 + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( 6.53 + "-XX:+UnlockDiagnosticVMOptions", 6.54 + "-XX:SharedArchiveFile=./test.jsa", 6.55 + "-Xshare:dump"); 6.56 + 6.57 + OutputAnalyzer output = new OutputAnalyzer(pb.start()); 6.58 + String stdout = output.getStdout(); 6.59 + ArrayList<String> utilization = findUtilization(stdout); 6.60 + 6.61 + if (utilization.size() != NUMBER_OF_CHECKED_SHARED_REGIONS ) 6.62 + throw new RuntimeException("The output format of sharing summary has changed"); 6.63 + 6.64 + for(String str : utilization) { 6.65 + int value = Integer.parseInt(str); 6.66 + if (value < MIN_UTILIZATION) { 6.67 + System.out.println(stdout); 6.68 + throw new RuntimeException("Utilization for one of the regions" + 6.69 + "is below a threshold of " + MIN_UTILIZATION + "%"); 6.70 + } 6.71 + } 6.72 + } 6.73 + 6.74 + public static ArrayList<String> findUtilization(String input) { 6.75 + ArrayList<String> regions = filterRegionsOfInterest(input.split("\n")); 6.76 + return filterByPattern(filterByPattern(regions, "bytes \\[.*% used\\]"), "\\d+"); 6.77 + } 6.78 + 6.79 + private static ArrayList<String> filterByPattern(Iterable<String> input, String pattern) { 6.80 + ArrayList<String> result = new ArrayList<String>(); 6.81 + for (String str : input) { 6.82 + Matcher matcher = Pattern.compile(pattern).matcher(str); 6.83 + if (matcher.find()) { 6.84 + result.add(matcher.group()); 6.85 + } 6.86 + } 6.87 + return result; 6.88 + } 6.89 + 6.90 + private static ArrayList<String> filterRegionsOfInterest(String[] inputLines) { 6.91 + ArrayList<String> result = new ArrayList<String>(); 6.92 + for (String str : inputLines) { 6.93 + if (str.contains("ro space:") || str.contains("rw space:")) { 6.94 + result.add(str); 6.95 + } 6.96 + } 6.97 + return result; 6.98 + } 6.99 +}