hotspot/test/runtime/CompressedOops/ObjectAlignment.java
author gziemski
Thu, 18 Jun 2015 14:39:38 -0500
changeset 31371 311143309e73
parent 30604 b8d532cb6420
child 31995 aa4049b4184a
permissions -rw-r--r--
8122937: [JEP 245] Validate JVM Command-Line Flag Arguments. Summary: Validate the arguments to all JVM command-line flags so as to avoid crashes, and ensure that appropriate error messages are displayed when they are invalid. Reviewed-by: ddmitriev, dholmes, kbarrett, drwhite, brutisso, coleenp
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
26688
bb0cdd873e51 8022865: [TESTBUG] Compressed Oops testing needs to be revised
ctornqvi
parents:
diff changeset
     1
/*
29678
dd2f3932c21e 8075586: Add @modules as needed to the open hotspot tests
ykantser
parents: 26688
diff changeset
     2
 * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
26688
bb0cdd873e51 8022865: [TESTBUG] Compressed Oops testing needs to be revised
ctornqvi
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
bb0cdd873e51 8022865: [TESTBUG] Compressed Oops testing needs to be revised
ctornqvi
parents:
diff changeset
     4
 *
bb0cdd873e51 8022865: [TESTBUG] Compressed Oops testing needs to be revised
ctornqvi
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
bb0cdd873e51 8022865: [TESTBUG] Compressed Oops testing needs to be revised
ctornqvi
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
bb0cdd873e51 8022865: [TESTBUG] Compressed Oops testing needs to be revised
ctornqvi
parents:
diff changeset
     7
 * published by the Free Software Foundation.
bb0cdd873e51 8022865: [TESTBUG] Compressed Oops testing needs to be revised
ctornqvi
parents:
diff changeset
     8
 *
bb0cdd873e51 8022865: [TESTBUG] Compressed Oops testing needs to be revised
ctornqvi
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
bb0cdd873e51 8022865: [TESTBUG] Compressed Oops testing needs to be revised
ctornqvi
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
bb0cdd873e51 8022865: [TESTBUG] Compressed Oops testing needs to be revised
ctornqvi
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
bb0cdd873e51 8022865: [TESTBUG] Compressed Oops testing needs to be revised
ctornqvi
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
bb0cdd873e51 8022865: [TESTBUG] Compressed Oops testing needs to be revised
ctornqvi
parents:
diff changeset
    13
 * accompanied this code).
bb0cdd873e51 8022865: [TESTBUG] Compressed Oops testing needs to be revised
ctornqvi
parents:
diff changeset
    14
 *
bb0cdd873e51 8022865: [TESTBUG] Compressed Oops testing needs to be revised
ctornqvi
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
bb0cdd873e51 8022865: [TESTBUG] Compressed Oops testing needs to be revised
ctornqvi
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
bb0cdd873e51 8022865: [TESTBUG] Compressed Oops testing needs to be revised
ctornqvi
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
bb0cdd873e51 8022865: [TESTBUG] Compressed Oops testing needs to be revised
ctornqvi
parents:
diff changeset
    18
 *
bb0cdd873e51 8022865: [TESTBUG] Compressed Oops testing needs to be revised
ctornqvi
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
bb0cdd873e51 8022865: [TESTBUG] Compressed Oops testing needs to be revised
ctornqvi
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
bb0cdd873e51 8022865: [TESTBUG] Compressed Oops testing needs to be revised
ctornqvi
parents:
diff changeset
    21
 * questions.
bb0cdd873e51 8022865: [TESTBUG] Compressed Oops testing needs to be revised
ctornqvi
parents:
diff changeset
    22
 */
bb0cdd873e51 8022865: [TESTBUG] Compressed Oops testing needs to be revised
ctornqvi
parents:
diff changeset
    23
bb0cdd873e51 8022865: [TESTBUG] Compressed Oops testing needs to be revised
ctornqvi
parents:
diff changeset
    24
/*
bb0cdd873e51 8022865: [TESTBUG] Compressed Oops testing needs to be revised
ctornqvi
parents:
diff changeset
    25
 * @test
bb0cdd873e51 8022865: [TESTBUG] Compressed Oops testing needs to be revised
ctornqvi
parents:
diff changeset
    26
 * @bug 8022865
bb0cdd873e51 8022865: [TESTBUG] Compressed Oops testing needs to be revised
ctornqvi
parents:
diff changeset
    27
 * @summary Tests for the -XX:ObjectAlignmentInBytes command line option
bb0cdd873e51 8022865: [TESTBUG] Compressed Oops testing needs to be revised
ctornqvi
parents:
diff changeset
    28
 * @library /testlibrary
29678
dd2f3932c21e 8075586: Add @modules as needed to the open hotspot tests
ykantser
parents: 26688
diff changeset
    29
 * @modules java.base/sun.misc
dd2f3932c21e 8075586: Add @modules as needed to the open hotspot tests
ykantser
parents: 26688
diff changeset
    30
 *          java.management
26688
bb0cdd873e51 8022865: [TESTBUG] Compressed Oops testing needs to be revised
ctornqvi
parents:
diff changeset
    31
 * @run main ObjectAlignment
bb0cdd873e51 8022865: [TESTBUG] Compressed Oops testing needs to be revised
ctornqvi
parents:
diff changeset
    32
 */
30604
b8d532cb6420 8067013: Rename the com.oracle.java.testlibary package
ykantser
parents: 29678
diff changeset
    33
import jdk.test.lib.*;
26688
bb0cdd873e51 8022865: [TESTBUG] Compressed Oops testing needs to be revised
ctornqvi
parents:
diff changeset
    34
bb0cdd873e51 8022865: [TESTBUG] Compressed Oops testing needs to be revised
ctornqvi
parents:
diff changeset
    35
public class ObjectAlignment {
bb0cdd873e51 8022865: [TESTBUG] Compressed Oops testing needs to be revised
ctornqvi
parents:
diff changeset
    36
bb0cdd873e51 8022865: [TESTBUG] Compressed Oops testing needs to be revised
ctornqvi
parents:
diff changeset
    37
    public static void main(String[] args) throws Exception {
bb0cdd873e51 8022865: [TESTBUG] Compressed Oops testing needs to be revised
ctornqvi
parents:
diff changeset
    38
bb0cdd873e51 8022865: [TESTBUG] Compressed Oops testing needs to be revised
ctornqvi
parents:
diff changeset
    39
        if (Platform.is64bit()) {
bb0cdd873e51 8022865: [TESTBUG] Compressed Oops testing needs to be revised
ctornqvi
parents:
diff changeset
    40
            // Minimum alignment should be 8
bb0cdd873e51 8022865: [TESTBUG] Compressed Oops testing needs to be revised
ctornqvi
parents:
diff changeset
    41
            testObjectAlignment(4)
31371
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 30604
diff changeset
    42
                .shouldContain("outside the allowed range")
26688
bb0cdd873e51 8022865: [TESTBUG] Compressed Oops testing needs to be revised
ctornqvi
parents:
diff changeset
    43
                .shouldHaveExitValue(1);
bb0cdd873e51 8022865: [TESTBUG] Compressed Oops testing needs to be revised
ctornqvi
parents:
diff changeset
    44
bb0cdd873e51 8022865: [TESTBUG] Compressed Oops testing needs to be revised
ctornqvi
parents:
diff changeset
    45
            // Alignment has to be a power of 2
bb0cdd873e51 8022865: [TESTBUG] Compressed Oops testing needs to be revised
ctornqvi
parents:
diff changeset
    46
            testObjectAlignment(9)
31371
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 30604
diff changeset
    47
                .shouldContain("must be power of 2")
26688
bb0cdd873e51 8022865: [TESTBUG] Compressed Oops testing needs to be revised
ctornqvi
parents:
diff changeset
    48
                .shouldHaveExitValue(1);
bb0cdd873e51 8022865: [TESTBUG] Compressed Oops testing needs to be revised
ctornqvi
parents:
diff changeset
    49
bb0cdd873e51 8022865: [TESTBUG] Compressed Oops testing needs to be revised
ctornqvi
parents:
diff changeset
    50
            testObjectAlignment(-1)
31371
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 30604
diff changeset
    51
                .shouldContain("must be power of 2")
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 30604
diff changeset
    52
                .shouldContain("outside the allowed range")
26688
bb0cdd873e51 8022865: [TESTBUG] Compressed Oops testing needs to be revised
ctornqvi
parents:
diff changeset
    53
                .shouldHaveExitValue(1);
bb0cdd873e51 8022865: [TESTBUG] Compressed Oops testing needs to be revised
ctornqvi
parents:
diff changeset
    54
bb0cdd873e51 8022865: [TESTBUG] Compressed Oops testing needs to be revised
ctornqvi
parents:
diff changeset
    55
            // Maximum alignment allowed is 256
bb0cdd873e51 8022865: [TESTBUG] Compressed Oops testing needs to be revised
ctornqvi
parents:
diff changeset
    56
            testObjectAlignment(512)
31371
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 30604
diff changeset
    57
                .shouldContain("outside the allowed range")
26688
bb0cdd873e51 8022865: [TESTBUG] Compressed Oops testing needs to be revised
ctornqvi
parents:
diff changeset
    58
                .shouldHaveExitValue(1);
bb0cdd873e51 8022865: [TESTBUG] Compressed Oops testing needs to be revised
ctornqvi
parents:
diff changeset
    59
bb0cdd873e51 8022865: [TESTBUG] Compressed Oops testing needs to be revised
ctornqvi
parents:
diff changeset
    60
            // Valid alignments should work
bb0cdd873e51 8022865: [TESTBUG] Compressed Oops testing needs to be revised
ctornqvi
parents:
diff changeset
    61
            testObjectAlignment(8).shouldHaveExitValue(0);
bb0cdd873e51 8022865: [TESTBUG] Compressed Oops testing needs to be revised
ctornqvi
parents:
diff changeset
    62
            testObjectAlignment(16).shouldHaveExitValue(0);
bb0cdd873e51 8022865: [TESTBUG] Compressed Oops testing needs to be revised
ctornqvi
parents:
diff changeset
    63
            testObjectAlignment(256).shouldHaveExitValue(0);
bb0cdd873e51 8022865: [TESTBUG] Compressed Oops testing needs to be revised
ctornqvi
parents:
diff changeset
    64
bb0cdd873e51 8022865: [TESTBUG] Compressed Oops testing needs to be revised
ctornqvi
parents:
diff changeset
    65
        } else {
bb0cdd873e51 8022865: [TESTBUG] Compressed Oops testing needs to be revised
ctornqvi
parents:
diff changeset
    66
            // For a 32bit JVM the option isn't there, make sure it's not silently ignored
bb0cdd873e51 8022865: [TESTBUG] Compressed Oops testing needs to be revised
ctornqvi
parents:
diff changeset
    67
            testObjectAlignment(8)
bb0cdd873e51 8022865: [TESTBUG] Compressed Oops testing needs to be revised
ctornqvi
parents:
diff changeset
    68
                .shouldContain("Unrecognized VM option 'ObjectAlignmentInBytes=8'")
bb0cdd873e51 8022865: [TESTBUG] Compressed Oops testing needs to be revised
ctornqvi
parents:
diff changeset
    69
                .shouldHaveExitValue(1);
bb0cdd873e51 8022865: [TESTBUG] Compressed Oops testing needs to be revised
ctornqvi
parents:
diff changeset
    70
        }
bb0cdd873e51 8022865: [TESTBUG] Compressed Oops testing needs to be revised
ctornqvi
parents:
diff changeset
    71
    }
bb0cdd873e51 8022865: [TESTBUG] Compressed Oops testing needs to be revised
ctornqvi
parents:
diff changeset
    72
bb0cdd873e51 8022865: [TESTBUG] Compressed Oops testing needs to be revised
ctornqvi
parents:
diff changeset
    73
    private static OutputAnalyzer testObjectAlignment(int alignment) throws Exception {
bb0cdd873e51 8022865: [TESTBUG] Compressed Oops testing needs to be revised
ctornqvi
parents:
diff changeset
    74
        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:ObjectAlignmentInBytes=" + alignment,
bb0cdd873e51 8022865: [TESTBUG] Compressed Oops testing needs to be revised
ctornqvi
parents:
diff changeset
    75
                                                                  "-version");
bb0cdd873e51 8022865: [TESTBUG] Compressed Oops testing needs to be revised
ctornqvi
parents:
diff changeset
    76
        return new OutputAnalyzer(pb.start());
bb0cdd873e51 8022865: [TESTBUG] Compressed Oops testing needs to be revised
ctornqvi
parents:
diff changeset
    77
    }
31371
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 30604
diff changeset
    78
}