Path: blob/master/test/hotspot/jtreg/runtime/CompressedOops/ObjectAlignment.java
40942 views
/*1* Copyright (c) 2014, 2020, 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* @test25* @bug 802286526* @summary Tests for the -XX:ObjectAlignmentInBytes command line option27* @library /test/lib28* @modules java.base/jdk.internal.misc29* java.management30* @run driver ObjectAlignment31*/3233import jdk.test.lib.Platform;34import jdk.test.lib.process.ProcessTools;35import jdk.test.lib.process.OutputAnalyzer;3637public class ObjectAlignment {3839public static void main(String[] args) throws Exception {4041if (Platform.is64bit()) {42// Minimum alignment should be 843testObjectAlignment(4)44.shouldContain("outside the allowed range")45.shouldHaveExitValue(1);4647// Alignment has to be a power of 248testObjectAlignment(9)49.shouldContain("must be power of 2")50.shouldHaveExitValue(1);5152testObjectAlignment(-1)53.shouldContain("outside the allowed range")54.shouldHaveExitValue(1);5556// Maximum alignment allowed is 25657testObjectAlignment(512)58.shouldContain("outside the allowed range")59.shouldHaveExitValue(1);6061// Valid alignments should work62testObjectAlignment(8).shouldHaveExitValue(0);63testObjectAlignment(16).shouldHaveExitValue(0);64testObjectAlignment(256).shouldHaveExitValue(0);6566} else {67// For a 32bit JVM the option isn't there, make sure it's not silently ignored68testObjectAlignment(8)69.shouldContain("Unrecognized VM option 'ObjectAlignmentInBytes=8'")70.shouldHaveExitValue(1);71}72}7374private static OutputAnalyzer testObjectAlignment(int alignment) throws Exception {75ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:ObjectAlignmentInBytes=" + alignment,76"-version");77return new OutputAnalyzer(pb.start());78}79}808182