Thu, 13 Jun 2013 22:00:06 +0200
8015324: Create tests for CDS feature
Summary: Wrote tests for use of CDS with ObjectAlignmentInBytes CL option
Reviewed-by: coleenp, ctornqvi, hseigel
Contributed-by: Mikhailo Seledtsov <mikhailo.seledtsov@oracle.com>
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/test/runtime/SharedArchiveFile/CdsDifferentObjectAlignment.java Thu Jun 13 22:00:06 2013 +0200 1.3 @@ -0,0 +1,88 @@ 1.4 +/* 1.5 + * Copyright (c) 2013, 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 CdsDifferentObjectAlignment 1.29 + * @summary Testing CDS (class data sharing) using varying object alignment. 1.30 + * Using different object alignment for each dump/load pair. 1.31 + * This is a negative test; using object alignment for loading that 1.32 + * is different from object alignment for creating a CDS file 1.33 + * should fail when loading. 1.34 + * @library /testlibrary 1.35 + */ 1.36 + 1.37 +import com.oracle.java.testlibrary.*; 1.38 + 1.39 +public class CdsDifferentObjectAlignment { 1.40 + public static void main(String[] args) throws Exception { 1.41 + String nativeWordSize = System.getProperty("sun.arch.data.model"); 1.42 + if (!Platform.is64bit()) { 1.43 + System.out.println("ObjectAlignmentInBytes for CDS is only " + 1.44 + "supported on 64bit platforms; this plaform is " + 1.45 + nativeWordSize); 1.46 + System.out.println("Skipping the test"); 1.47 + } else { 1.48 + createAndLoadSharedArchive(16, 64); 1.49 + createAndLoadSharedArchive(64, 32); 1.50 + } 1.51 + } 1.52 + 1.53 + 1.54 + // Parameters are object alignment expressed in bytes 1.55 + private static void 1.56 + createAndLoadSharedArchive(int createAlignment, int loadAlignment) 1.57 + throws Exception { 1.58 + String createAlignmentArgument = "-XX:ObjectAlignmentInBytes=" + 1.59 + createAlignment; 1.60 + String loadAlignmentArgument = "-XX:ObjectAlignmentInBytes=" + 1.61 + loadAlignment; 1.62 + 1.63 + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( 1.64 + "-XX:+UnlockDiagnosticVMOptions", 1.65 + "-XX:SharedArchiveFile=./sample.jsa", 1.66 + "-Xshare:dump", 1.67 + createAlignmentArgument); 1.68 + 1.69 + OutputAnalyzer output = new OutputAnalyzer(pb.start()); 1.70 + output.shouldContain("Loading classes to share"); 1.71 + output.shouldHaveExitValue(0); 1.72 + 1.73 + pb = ProcessTools.createJavaProcessBuilder( 1.74 + "-XX:+UnlockDiagnosticVMOptions", 1.75 + "-XX:SharedArchiveFile=./sample.jsa", 1.76 + "-Xshare:on", 1.77 + loadAlignmentArgument, 1.78 + "-version"); 1.79 + 1.80 + output = new OutputAnalyzer(pb.start()); 1.81 + String expectedErrorMsg = 1.82 + String.format( 1.83 + "The shared archive file's ObjectAlignmentInBytes of %d " + 1.84 + "does not equal the current ObjectAlignmentInBytes of %d", 1.85 + createAlignment, 1.86 + loadAlignment); 1.87 + 1.88 + output.shouldContain(expectedErrorMsg); 1.89 + output.shouldHaveExitValue(1); 1.90 + } 1.91 +}
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/test/runtime/SharedArchiveFile/CdsSameObjectAlignment.java Thu Jun 13 22:00:06 2013 +0200 2.3 @@ -0,0 +1,92 @@ 2.4 +/* 2.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 2.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 2.7 + * 2.8 + * This code is free software; you can redistribute it and/or modify it 2.9 + * under the terms of the GNU General Public License version 2 only, as 2.10 + * published by the Free Software Foundation. 2.11 + * 2.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 2.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 2.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 2.15 + * version 2 for more details (a copy is included in the LICENSE file that 2.16 + * accompanied this code). 2.17 + * 2.18 + * You should have received a copy of the GNU General Public License version 2.19 + * 2 along with this work; if not, write to the Free Software Foundation, 2.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2.21 + * 2.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2.23 + * or visit www.oracle.com if you need additional information or have any 2.24 + * questions. 2.25 + */ 2.26 + 2.27 +/* 2.28 + * @test CdsSameObjectAlignment 2.29 + * @summary Testing CDS (class data sharing) using varying object alignment. 2.30 + * Using same object alignment for each dump/load pair 2.31 + * @library /testlibrary 2.32 + */ 2.33 + 2.34 +import com.oracle.java.testlibrary.*; 2.35 + 2.36 +public class CdsSameObjectAlignment { 2.37 + public static void main(String[] args) throws Exception { 2.38 + String nativeWordSize = System.getProperty("sun.arch.data.model"); 2.39 + if (!Platform.is64bit()) { 2.40 + System.out.println("ObjectAlignmentInBytes for CDS is only " + 2.41 + "supported on 64bit platforms; this plaform is " + 2.42 + nativeWordSize); 2.43 + System.out.println("Skipping the test"); 2.44 + } else { 2.45 + dumpAndLoadSharedArchive(8); 2.46 + dumpAndLoadSharedArchive(16); 2.47 + dumpAndLoadSharedArchive(32); 2.48 + dumpAndLoadSharedArchive(64); 2.49 + } 2.50 + } 2.51 + 2.52 + private static void 2.53 + dumpAndLoadSharedArchive(int objectAlignmentInBytes) throws Exception { 2.54 + String objectAlignmentArg = "-XX:ObjectAlignmentInBytes=" 2.55 + + objectAlignmentInBytes; 2.56 + System.out.println("dumpAndLoadSharedArchive(): objectAlignmentInBytes = " 2.57 + + objectAlignmentInBytes); 2.58 + 2.59 + // create shared archive 2.60 + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( 2.61 + "-XX:+UnlockDiagnosticVMOptions", 2.62 + "-XX:SharedArchiveFile=./sample.jsa", 2.63 + "-Xshare:dump", 2.64 + objectAlignmentArg); 2.65 + 2.66 + OutputAnalyzer output = new OutputAnalyzer(pb.start()); 2.67 + output.shouldContain("Loading classes to share"); 2.68 + output.shouldHaveExitValue(0); 2.69 + 2.70 + 2.71 + // run using the shared archive 2.72 + pb = ProcessTools.createJavaProcessBuilder( 2.73 + "-XX:+UnlockDiagnosticVMOptions", 2.74 + "-XX:SharedArchiveFile=./sample.jsa", 2.75 + "-Xshare:on", 2.76 + objectAlignmentArg, 2.77 + "-version"); 2.78 + 2.79 + output = new OutputAnalyzer(pb.start()); 2.80 + 2.81 + try { 2.82 + output.shouldContain("sharing"); 2.83 + output.shouldHaveExitValue(0); 2.84 + } catch (RuntimeException e) { 2.85 + // CDS uses absolute addresses for performance. 2.86 + // It will try to reserve memory at a specific address; 2.87 + // there is a chance such reservation will fail 2.88 + // If it does, it is NOT considered a failure of the feature, 2.89 + // rather a possible expected outcome, though not likely 2.90 + output.shouldContain( 2.91 + "Unable to reserve shared space at required address"); 2.92 + output.shouldHaveExitValue(1); 2.93 + } 2.94 + } 2.95 +}
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/test/testlibrary/com/oracle/java/testlibrary/Platform.java Thu Jun 13 22:00:06 2013 +0200 3.3 @@ -0,0 +1,62 @@ 3.4 +/* 3.5 + * Copyright (c) 2013, 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 +package com.oracle.java.testlibrary; 3.28 + 3.29 +public class Platform { 3.30 + private static final String osName = System.getProperty("os.name"); 3.31 + private static final String dataModel = System.getProperty("sun.arch.data.model"); 3.32 + private static final String vmVersion = System.getProperty("java.vm.version"); 3.33 + 3.34 + public static boolean is64bit() { 3.35 + return dataModel.equals("64"); 3.36 + } 3.37 + 3.38 + public static boolean isSolaris() { 3.39 + return osName.toLowerCase().startsWith("sunos"); 3.40 + } 3.41 + 3.42 + public static boolean isWindows() { 3.43 + return osName.toLowerCase().startsWith("win"); 3.44 + } 3.45 + 3.46 + public static boolean isOSX() { 3.47 + return osName.toLowerCase().startsWith("mac"); 3.48 + } 3.49 + 3.50 + public static boolean isLinux() { 3.51 + return osName.toLowerCase().startsWith("linux"); 3.52 + } 3.53 + 3.54 + public static String getOsName() { 3.55 + return osName; 3.56 + } 3.57 + 3.58 + public static boolean isDebugBuild() { 3.59 + return vmVersion.toLowerCase().contains("debug"); 3.60 + } 3.61 + 3.62 + public static String getVMVersion() { 3.63 + return vmVersion; 3.64 + } 3.65 +}
4.1 --- a/test/testlibrary/com/oracle/java/testlibrary/ProcessTools.java Thu Jun 13 21:57:56 2013 +0200 4.2 +++ b/test/testlibrary/com/oracle/java/testlibrary/ProcessTools.java Thu Jun 13 22:00:06 2013 +0200 4.3 @@ -112,10 +112,8 @@ 4.4 * @return String[] with platform specific arguments, empty if there are none 4.5 */ 4.6 public static String[] getPlatformSpecificVMArgs() { 4.7 - String osName = System.getProperty("os.name"); 4.8 - String dataModel = System.getProperty("sun.arch.data.model"); 4.9 4.10 - if (osName.equals("SunOS") && dataModel.equals("64")) { 4.11 + if (Platform.is64bit() && Platform.isSolaris()) { 4.12 return new String[] { "-d64" }; 4.13 } 4.14