hotspot/test/runtime/SharedArchiveFile/CdsDifferentObjectAlignment.java
author ctornqvi
Thu, 13 Jun 2013 22:00:06 +0200
changeset 18071 156996e4323f
child 22892 1709e0e0b87c
permissions -rw-r--r--
8015324: Create tests for CDS feature Summary: Wrote tests for use of CDS with ObjectAlignmentInBytes CL option Reviewed-by: coleenp, ctornqvi, hseigel Contributed-by: Mikhailo Seledtsov <mikhailo.seledtsov@oracle.com>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
18071
156996e4323f 8015324: Create tests for CDS feature
ctornqvi
parents:
diff changeset
     1
/*
156996e4323f 8015324: Create tests for CDS feature
ctornqvi
parents:
diff changeset
     2
 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
156996e4323f 8015324: Create tests for CDS feature
ctornqvi
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
156996e4323f 8015324: Create tests for CDS feature
ctornqvi
parents:
diff changeset
     4
 *
156996e4323f 8015324: Create tests for CDS feature
ctornqvi
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
156996e4323f 8015324: Create tests for CDS feature
ctornqvi
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
156996e4323f 8015324: Create tests for CDS feature
ctornqvi
parents:
diff changeset
     7
 * published by the Free Software Foundation.
156996e4323f 8015324: Create tests for CDS feature
ctornqvi
parents:
diff changeset
     8
 *
156996e4323f 8015324: Create tests for CDS feature
ctornqvi
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
156996e4323f 8015324: Create tests for CDS feature
ctornqvi
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
156996e4323f 8015324: Create tests for CDS feature
ctornqvi
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
156996e4323f 8015324: Create tests for CDS feature
ctornqvi
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
156996e4323f 8015324: Create tests for CDS feature
ctornqvi
parents:
diff changeset
    13
 * accompanied this code).
156996e4323f 8015324: Create tests for CDS feature
ctornqvi
parents:
diff changeset
    14
 *
156996e4323f 8015324: Create tests for CDS feature
ctornqvi
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
156996e4323f 8015324: Create tests for CDS feature
ctornqvi
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
156996e4323f 8015324: Create tests for CDS feature
ctornqvi
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
156996e4323f 8015324: Create tests for CDS feature
ctornqvi
parents:
diff changeset
    18
 *
156996e4323f 8015324: Create tests for CDS feature
ctornqvi
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
156996e4323f 8015324: Create tests for CDS feature
ctornqvi
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
156996e4323f 8015324: Create tests for CDS feature
ctornqvi
parents:
diff changeset
    21
 * questions.
156996e4323f 8015324: Create tests for CDS feature
ctornqvi
parents:
diff changeset
    22
 */
156996e4323f 8015324: Create tests for CDS feature
ctornqvi
parents:
diff changeset
    23
156996e4323f 8015324: Create tests for CDS feature
ctornqvi
parents:
diff changeset
    24
/*
156996e4323f 8015324: Create tests for CDS feature
ctornqvi
parents:
diff changeset
    25
 * @test CdsDifferentObjectAlignment
156996e4323f 8015324: Create tests for CDS feature
ctornqvi
parents:
diff changeset
    26
 * @summary Testing CDS (class data sharing) using varying object alignment.
156996e4323f 8015324: Create tests for CDS feature
ctornqvi
parents:
diff changeset
    27
 *          Using different object alignment for each dump/load pair.
156996e4323f 8015324: Create tests for CDS feature
ctornqvi
parents:
diff changeset
    28
 *          This is a negative test; using  object alignment for loading that
156996e4323f 8015324: Create tests for CDS feature
ctornqvi
parents:
diff changeset
    29
 *          is different from object alignment for creating a CDS file
156996e4323f 8015324: Create tests for CDS feature
ctornqvi
parents:
diff changeset
    30
 *          should fail when loading.
156996e4323f 8015324: Create tests for CDS feature
ctornqvi
parents:
diff changeset
    31
 * @library /testlibrary
156996e4323f 8015324: Create tests for CDS feature
ctornqvi
parents:
diff changeset
    32
 */
156996e4323f 8015324: Create tests for CDS feature
ctornqvi
parents:
diff changeset
    33
156996e4323f 8015324: Create tests for CDS feature
ctornqvi
parents:
diff changeset
    34
import com.oracle.java.testlibrary.*;
156996e4323f 8015324: Create tests for CDS feature
ctornqvi
parents:
diff changeset
    35
156996e4323f 8015324: Create tests for CDS feature
ctornqvi
parents:
diff changeset
    36
public class CdsDifferentObjectAlignment {
156996e4323f 8015324: Create tests for CDS feature
ctornqvi
parents:
diff changeset
    37
    public static void main(String[] args) throws Exception {
156996e4323f 8015324: Create tests for CDS feature
ctornqvi
parents:
diff changeset
    38
        String nativeWordSize = System.getProperty("sun.arch.data.model");
156996e4323f 8015324: Create tests for CDS feature
ctornqvi
parents:
diff changeset
    39
        if (!Platform.is64bit()) {
156996e4323f 8015324: Create tests for CDS feature
ctornqvi
parents:
diff changeset
    40
            System.out.println("ObjectAlignmentInBytes for CDS is only " +
156996e4323f 8015324: Create tests for CDS feature
ctornqvi
parents:
diff changeset
    41
                "supported on 64bit platforms; this plaform is " +
156996e4323f 8015324: Create tests for CDS feature
ctornqvi
parents:
diff changeset
    42
                nativeWordSize);
156996e4323f 8015324: Create tests for CDS feature
ctornqvi
parents:
diff changeset
    43
            System.out.println("Skipping the test");
156996e4323f 8015324: Create tests for CDS feature
ctornqvi
parents:
diff changeset
    44
        } else {
156996e4323f 8015324: Create tests for CDS feature
ctornqvi
parents:
diff changeset
    45
            createAndLoadSharedArchive(16, 64);
156996e4323f 8015324: Create tests for CDS feature
ctornqvi
parents:
diff changeset
    46
            createAndLoadSharedArchive(64, 32);
156996e4323f 8015324: Create tests for CDS feature
ctornqvi
parents:
diff changeset
    47
        }
156996e4323f 8015324: Create tests for CDS feature
ctornqvi
parents:
diff changeset
    48
    }
156996e4323f 8015324: Create tests for CDS feature
ctornqvi
parents:
diff changeset
    49
156996e4323f 8015324: Create tests for CDS feature
ctornqvi
parents:
diff changeset
    50
156996e4323f 8015324: Create tests for CDS feature
ctornqvi
parents:
diff changeset
    51
    // Parameters are object alignment expressed in bytes
156996e4323f 8015324: Create tests for CDS feature
ctornqvi
parents:
diff changeset
    52
    private static void
156996e4323f 8015324: Create tests for CDS feature
ctornqvi
parents:
diff changeset
    53
    createAndLoadSharedArchive(int createAlignment, int loadAlignment)
156996e4323f 8015324: Create tests for CDS feature
ctornqvi
parents:
diff changeset
    54
    throws Exception {
156996e4323f 8015324: Create tests for CDS feature
ctornqvi
parents:
diff changeset
    55
        String createAlignmentArgument = "-XX:ObjectAlignmentInBytes=" +
156996e4323f 8015324: Create tests for CDS feature
ctornqvi
parents:
diff changeset
    56
            createAlignment;
156996e4323f 8015324: Create tests for CDS feature
ctornqvi
parents:
diff changeset
    57
        String loadAlignmentArgument = "-XX:ObjectAlignmentInBytes=" +
156996e4323f 8015324: Create tests for CDS feature
ctornqvi
parents:
diff changeset
    58
            loadAlignment;
156996e4323f 8015324: Create tests for CDS feature
ctornqvi
parents:
diff changeset
    59
156996e4323f 8015324: Create tests for CDS feature
ctornqvi
parents:
diff changeset
    60
        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
156996e4323f 8015324: Create tests for CDS feature
ctornqvi
parents:
diff changeset
    61
            "-XX:+UnlockDiagnosticVMOptions",
156996e4323f 8015324: Create tests for CDS feature
ctornqvi
parents:
diff changeset
    62
            "-XX:SharedArchiveFile=./sample.jsa",
156996e4323f 8015324: Create tests for CDS feature
ctornqvi
parents:
diff changeset
    63
            "-Xshare:dump",
156996e4323f 8015324: Create tests for CDS feature
ctornqvi
parents:
diff changeset
    64
            createAlignmentArgument);
156996e4323f 8015324: Create tests for CDS feature
ctornqvi
parents:
diff changeset
    65
156996e4323f 8015324: Create tests for CDS feature
ctornqvi
parents:
diff changeset
    66
        OutputAnalyzer output = new OutputAnalyzer(pb.start());
156996e4323f 8015324: Create tests for CDS feature
ctornqvi
parents:
diff changeset
    67
        output.shouldContain("Loading classes to share");
156996e4323f 8015324: Create tests for CDS feature
ctornqvi
parents:
diff changeset
    68
        output.shouldHaveExitValue(0);
156996e4323f 8015324: Create tests for CDS feature
ctornqvi
parents:
diff changeset
    69
156996e4323f 8015324: Create tests for CDS feature
ctornqvi
parents:
diff changeset
    70
        pb = ProcessTools.createJavaProcessBuilder(
156996e4323f 8015324: Create tests for CDS feature
ctornqvi
parents:
diff changeset
    71
            "-XX:+UnlockDiagnosticVMOptions",
156996e4323f 8015324: Create tests for CDS feature
ctornqvi
parents:
diff changeset
    72
            "-XX:SharedArchiveFile=./sample.jsa",
156996e4323f 8015324: Create tests for CDS feature
ctornqvi
parents:
diff changeset
    73
            "-Xshare:on",
156996e4323f 8015324: Create tests for CDS feature
ctornqvi
parents:
diff changeset
    74
            loadAlignmentArgument,
156996e4323f 8015324: Create tests for CDS feature
ctornqvi
parents:
diff changeset
    75
            "-version");
156996e4323f 8015324: Create tests for CDS feature
ctornqvi
parents:
diff changeset
    76
156996e4323f 8015324: Create tests for CDS feature
ctornqvi
parents:
diff changeset
    77
        output = new OutputAnalyzer(pb.start());
156996e4323f 8015324: Create tests for CDS feature
ctornqvi
parents:
diff changeset
    78
        String expectedErrorMsg =
156996e4323f 8015324: Create tests for CDS feature
ctornqvi
parents:
diff changeset
    79
            String.format(
156996e4323f 8015324: Create tests for CDS feature
ctornqvi
parents:
diff changeset
    80
            "The shared archive file's ObjectAlignmentInBytes of %d " +
156996e4323f 8015324: Create tests for CDS feature
ctornqvi
parents:
diff changeset
    81
            "does not equal the current ObjectAlignmentInBytes of %d",
156996e4323f 8015324: Create tests for CDS feature
ctornqvi
parents:
diff changeset
    82
            createAlignment,
156996e4323f 8015324: Create tests for CDS feature
ctornqvi
parents:
diff changeset
    83
            loadAlignment);
156996e4323f 8015324: Create tests for CDS feature
ctornqvi
parents:
diff changeset
    84
156996e4323f 8015324: Create tests for CDS feature
ctornqvi
parents:
diff changeset
    85
        output.shouldContain(expectedErrorMsg);
156996e4323f 8015324: Create tests for CDS feature
ctornqvi
parents:
diff changeset
    86
        output.shouldHaveExitValue(1);
156996e4323f 8015324: Create tests for CDS feature
ctornqvi
parents:
diff changeset
    87
    }
156996e4323f 8015324: Create tests for CDS feature
ctornqvi
parents:
diff changeset
    88
}