Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/test/runtime/SharedArchiveFile/CdsSameObjectAlignment.java
32284 views
/*1* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test CdsSameObjectAlignment25* @summary Testing CDS (class data sharing) using varying object alignment.26* Using same object alignment for each dump/load pair27* @library /testlibrary28*/2930import com.oracle.java.testlibrary.*;3132public class CdsSameObjectAlignment {33public static void main(String[] args) throws Exception {34String nativeWordSize = System.getProperty("sun.arch.data.model");35if (!Platform.is64bit()) {36System.out.println("ObjectAlignmentInBytes for CDS is only " +37"supported on 64bit platforms; this plaform is " +38nativeWordSize);39System.out.println("Skipping the test");40} else {41dumpAndLoadSharedArchive(8);42dumpAndLoadSharedArchive(16);43dumpAndLoadSharedArchive(32);44dumpAndLoadSharedArchive(64);45}46}4748private static void49dumpAndLoadSharedArchive(int objectAlignmentInBytes) throws Exception {50String objectAlignmentArg = "-XX:ObjectAlignmentInBytes="51+ objectAlignmentInBytes;52System.out.println("dumpAndLoadSharedArchive(): objectAlignmentInBytes = "53+ objectAlignmentInBytes);5455// create shared archive56ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(57"-XX:+UnlockDiagnosticVMOptions",58"-XX:SharedArchiveFile=./sample.jsa",59"-Xshare:dump",60objectAlignmentArg);6162OutputAnalyzer output = new OutputAnalyzer(pb.start());63output.shouldContain("Loading classes to share");64output.shouldHaveExitValue(0);656667// run using the shared archive68pb = ProcessTools.createJavaProcessBuilder(69"-XX:+UnlockDiagnosticVMOptions",70"-XX:SharedArchiveFile=./sample.jsa",71"-Xshare:on",72objectAlignmentArg,73"-version");7475output = new OutputAnalyzer(pb.start());7677try {78output.shouldContain("sharing");79output.shouldHaveExitValue(0);80} catch (RuntimeException e) {81// CDS uses absolute addresses for performance.82// It will try to reserve memory at a specific address;83// there is a chance such reservation will fail84// If it does, it is NOT considered a failure of the feature,85// rather a possible expected outcome, though not likely86output.shouldContain("Unable to use shared archive");87output.shouldHaveExitValue(1);88}89}90}919293