test/runtime/SharedArchiveFile/CdsSameObjectAlignment.java

Thu, 15 Aug 2013 20:04:10 -0400

author
hseigel
date
Thu, 15 Aug 2013 20:04:10 -0400
changeset 5528
740e263c80c6
parent 5257
1e9094165098
child 5625
35b99e7e0af2
permissions
-rw-r--r--

8003424: Enable Class Data Sharing for CompressedOops
8016729: ObjectAlignmentInBytes=16 now forces the use of heap based compressed oops
8005933: The -Xshare:auto option is ignored for -server
Summary: Move klass metaspace above the heap and support CDS with compressed klass ptrs.
Reviewed-by: coleenp, kvn, mgerdin, tschatzl, stefank

ctornqvi@5257 1 /*
ctornqvi@5257 2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
ctornqvi@5257 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ctornqvi@5257 4 *
ctornqvi@5257 5 * This code is free software; you can redistribute it and/or modify it
ctornqvi@5257 6 * under the terms of the GNU General Public License version 2 only, as
ctornqvi@5257 7 * published by the Free Software Foundation.
ctornqvi@5257 8 *
ctornqvi@5257 9 * This code is distributed in the hope that it will be useful, but WITHOUT
ctornqvi@5257 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ctornqvi@5257 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
ctornqvi@5257 12 * version 2 for more details (a copy is included in the LICENSE file that
ctornqvi@5257 13 * accompanied this code).
ctornqvi@5257 14 *
ctornqvi@5257 15 * You should have received a copy of the GNU General Public License version
ctornqvi@5257 16 * 2 along with this work; if not, write to the Free Software Foundation,
ctornqvi@5257 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ctornqvi@5257 18 *
ctornqvi@5257 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ctornqvi@5257 20 * or visit www.oracle.com if you need additional information or have any
ctornqvi@5257 21 * questions.
ctornqvi@5257 22 */
ctornqvi@5257 23
ctornqvi@5257 24 /*
ctornqvi@5257 25 * @test CdsSameObjectAlignment
ctornqvi@5257 26 * @summary Testing CDS (class data sharing) using varying object alignment.
ctornqvi@5257 27 * Using same object alignment for each dump/load pair
ctornqvi@5257 28 * @library /testlibrary
ctornqvi@5257 29 */
ctornqvi@5257 30
ctornqvi@5257 31 import com.oracle.java.testlibrary.*;
ctornqvi@5257 32
ctornqvi@5257 33 public class CdsSameObjectAlignment {
ctornqvi@5257 34 public static void main(String[] args) throws Exception {
ctornqvi@5257 35 String nativeWordSize = System.getProperty("sun.arch.data.model");
ctornqvi@5257 36 if (!Platform.is64bit()) {
ctornqvi@5257 37 System.out.println("ObjectAlignmentInBytes for CDS is only " +
ctornqvi@5257 38 "supported on 64bit platforms; this plaform is " +
ctornqvi@5257 39 nativeWordSize);
ctornqvi@5257 40 System.out.println("Skipping the test");
ctornqvi@5257 41 } else {
ctornqvi@5257 42 dumpAndLoadSharedArchive(8);
ctornqvi@5257 43 dumpAndLoadSharedArchive(16);
ctornqvi@5257 44 dumpAndLoadSharedArchive(32);
ctornqvi@5257 45 dumpAndLoadSharedArchive(64);
ctornqvi@5257 46 }
ctornqvi@5257 47 }
ctornqvi@5257 48
ctornqvi@5257 49 private static void
ctornqvi@5257 50 dumpAndLoadSharedArchive(int objectAlignmentInBytes) throws Exception {
ctornqvi@5257 51 String objectAlignmentArg = "-XX:ObjectAlignmentInBytes="
ctornqvi@5257 52 + objectAlignmentInBytes;
ctornqvi@5257 53 System.out.println("dumpAndLoadSharedArchive(): objectAlignmentInBytes = "
ctornqvi@5257 54 + objectAlignmentInBytes);
ctornqvi@5257 55
ctornqvi@5257 56 // create shared archive
ctornqvi@5257 57 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
ctornqvi@5257 58 "-XX:+UnlockDiagnosticVMOptions",
ctornqvi@5257 59 "-XX:SharedArchiveFile=./sample.jsa",
ctornqvi@5257 60 "-Xshare:dump",
ctornqvi@5257 61 objectAlignmentArg);
ctornqvi@5257 62
ctornqvi@5257 63 OutputAnalyzer output = new OutputAnalyzer(pb.start());
ctornqvi@5257 64 output.shouldContain("Loading classes to share");
ctornqvi@5257 65 output.shouldHaveExitValue(0);
ctornqvi@5257 66
ctornqvi@5257 67
ctornqvi@5257 68 // run using the shared archive
ctornqvi@5257 69 pb = ProcessTools.createJavaProcessBuilder(
ctornqvi@5257 70 "-XX:+UnlockDiagnosticVMOptions",
ctornqvi@5257 71 "-XX:SharedArchiveFile=./sample.jsa",
ctornqvi@5257 72 "-Xshare:on",
ctornqvi@5257 73 objectAlignmentArg,
ctornqvi@5257 74 "-version");
ctornqvi@5257 75
ctornqvi@5257 76 output = new OutputAnalyzer(pb.start());
ctornqvi@5257 77
ctornqvi@5257 78 try {
ctornqvi@5257 79 output.shouldContain("sharing");
ctornqvi@5257 80 output.shouldHaveExitValue(0);
ctornqvi@5257 81 } catch (RuntimeException e) {
ctornqvi@5257 82 // CDS uses absolute addresses for performance.
ctornqvi@5257 83 // It will try to reserve memory at a specific address;
ctornqvi@5257 84 // there is a chance such reservation will fail
ctornqvi@5257 85 // If it does, it is NOT considered a failure of the feature,
ctornqvi@5257 86 // rather a possible expected outcome, though not likely
hseigel@5528 87 output.shouldContain("Could not allocate metaspace at a compatible address");
ctornqvi@5257 88 output.shouldHaveExitValue(1);
ctornqvi@5257 89 }
ctornqvi@5257 90 }
ctornqvi@5257 91 }

mercurial