ctornqvi@5257: /* ctornqvi@5257: * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. ctornqvi@5257: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. ctornqvi@5257: * ctornqvi@5257: * This code is free software; you can redistribute it and/or modify it ctornqvi@5257: * under the terms of the GNU General Public License version 2 only, as ctornqvi@5257: * published by the Free Software Foundation. ctornqvi@5257: * ctornqvi@5257: * This code is distributed in the hope that it will be useful, but WITHOUT ctornqvi@5257: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ctornqvi@5257: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ctornqvi@5257: * version 2 for more details (a copy is included in the LICENSE file that ctornqvi@5257: * accompanied this code). ctornqvi@5257: * ctornqvi@5257: * You should have received a copy of the GNU General Public License version ctornqvi@5257: * 2 along with this work; if not, write to the Free Software Foundation, ctornqvi@5257: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. ctornqvi@5257: * ctornqvi@5257: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA ctornqvi@5257: * or visit www.oracle.com if you need additional information or have any ctornqvi@5257: * questions. ctornqvi@5257: */ ctornqvi@5257: ctornqvi@5257: /* ctornqvi@5257: * @test CdsSameObjectAlignment ctornqvi@5257: * @summary Testing CDS (class data sharing) using varying object alignment. ctornqvi@5257: * Using same object alignment for each dump/load pair ctornqvi@5257: * @library /testlibrary ctornqvi@5257: */ ctornqvi@5257: ctornqvi@5257: import com.oracle.java.testlibrary.*; ctornqvi@5257: ctornqvi@5257: public class CdsSameObjectAlignment { ctornqvi@5257: public static void main(String[] args) throws Exception { ctornqvi@5257: String nativeWordSize = System.getProperty("sun.arch.data.model"); ctornqvi@5257: if (!Platform.is64bit()) { ctornqvi@5257: System.out.println("ObjectAlignmentInBytes for CDS is only " + ctornqvi@5257: "supported on 64bit platforms; this plaform is " + ctornqvi@5257: nativeWordSize); ctornqvi@5257: System.out.println("Skipping the test"); ctornqvi@5257: } else { ctornqvi@5257: dumpAndLoadSharedArchive(8); ctornqvi@5257: dumpAndLoadSharedArchive(16); ctornqvi@5257: dumpAndLoadSharedArchive(32); ctornqvi@5257: dumpAndLoadSharedArchive(64); ctornqvi@5257: } ctornqvi@5257: } ctornqvi@5257: ctornqvi@5257: private static void ctornqvi@5257: dumpAndLoadSharedArchive(int objectAlignmentInBytes) throws Exception { ctornqvi@5257: String objectAlignmentArg = "-XX:ObjectAlignmentInBytes=" ctornqvi@5257: + objectAlignmentInBytes; ctornqvi@5257: System.out.println("dumpAndLoadSharedArchive(): objectAlignmentInBytes = " ctornqvi@5257: + objectAlignmentInBytes); ctornqvi@5257: ctornqvi@5257: // create shared archive ctornqvi@5257: ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( ctornqvi@5257: "-XX:+UnlockDiagnosticVMOptions", ctornqvi@5257: "-XX:SharedArchiveFile=./sample.jsa", ctornqvi@5257: "-Xshare:dump", ctornqvi@5257: objectAlignmentArg); ctornqvi@5257: ctornqvi@5257: OutputAnalyzer output = new OutputAnalyzer(pb.start()); ctornqvi@5257: output.shouldContain("Loading classes to share"); ctornqvi@5257: output.shouldHaveExitValue(0); ctornqvi@5257: ctornqvi@5257: ctornqvi@5257: // run using the shared archive ctornqvi@5257: pb = ProcessTools.createJavaProcessBuilder( ctornqvi@5257: "-XX:+UnlockDiagnosticVMOptions", ctornqvi@5257: "-XX:SharedArchiveFile=./sample.jsa", ctornqvi@5257: "-Xshare:on", ctornqvi@5257: objectAlignmentArg, ctornqvi@5257: "-version"); ctornqvi@5257: ctornqvi@5257: output = new OutputAnalyzer(pb.start()); ctornqvi@5257: ctornqvi@5257: try { ctornqvi@5257: output.shouldContain("sharing"); ctornqvi@5257: output.shouldHaveExitValue(0); ctornqvi@5257: } catch (RuntimeException e) { ctornqvi@5257: // CDS uses absolute addresses for performance. ctornqvi@5257: // It will try to reserve memory at a specific address; ctornqvi@5257: // there is a chance such reservation will fail ctornqvi@5257: // If it does, it is NOT considered a failure of the feature, ctornqvi@5257: // rather a possible expected outcome, though not likely hseigel@5528: output.shouldContain("Could not allocate metaspace at a compatible address"); ctornqvi@5257: output.shouldHaveExitValue(1); ctornqvi@5257: } ctornqvi@5257: } ctornqvi@5257: }