test/runtime/SharedArchiveFile/CdsSameObjectAlignment.java

changeset 5257
1e9094165098
child 5528
740e263c80c6
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/runtime/SharedArchiveFile/CdsSameObjectAlignment.java	Thu Jun 13 22:00:06 2013 +0200
     1.3 @@ -0,0 +1,92 @@
     1.4 +/*
     1.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.23 + * or visit www.oracle.com if you need additional information or have any
    1.24 + * questions.
    1.25 + */
    1.26 +
    1.27 +/*
    1.28 + * @test CdsSameObjectAlignment
    1.29 + * @summary Testing CDS (class data sharing) using varying object alignment.
    1.30 + *          Using same object alignment for each dump/load pair
    1.31 + * @library /testlibrary
    1.32 + */
    1.33 +
    1.34 +import com.oracle.java.testlibrary.*;
    1.35 +
    1.36 +public class CdsSameObjectAlignment {
    1.37 +    public static void main(String[] args) throws Exception {
    1.38 +        String nativeWordSize = System.getProperty("sun.arch.data.model");
    1.39 +        if (!Platform.is64bit()) {
    1.40 +            System.out.println("ObjectAlignmentInBytes for CDS is only " +
    1.41 +                "supported on 64bit platforms; this plaform is " +
    1.42 +                nativeWordSize);
    1.43 +            System.out.println("Skipping the test");
    1.44 +        } else {
    1.45 +            dumpAndLoadSharedArchive(8);
    1.46 +            dumpAndLoadSharedArchive(16);
    1.47 +            dumpAndLoadSharedArchive(32);
    1.48 +            dumpAndLoadSharedArchive(64);
    1.49 +        }
    1.50 +    }
    1.51 +
    1.52 +    private static void
    1.53 +    dumpAndLoadSharedArchive(int objectAlignmentInBytes) throws Exception {
    1.54 +        String objectAlignmentArg = "-XX:ObjectAlignmentInBytes="
    1.55 +            + objectAlignmentInBytes;
    1.56 +        System.out.println("dumpAndLoadSharedArchive(): objectAlignmentInBytes = "
    1.57 +            + objectAlignmentInBytes);
    1.58 +
    1.59 +        // create shared archive
    1.60 +        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
    1.61 +            "-XX:+UnlockDiagnosticVMOptions",
    1.62 +            "-XX:SharedArchiveFile=./sample.jsa",
    1.63 +            "-Xshare:dump",
    1.64 +            objectAlignmentArg);
    1.65 +
    1.66 +        OutputAnalyzer output = new OutputAnalyzer(pb.start());
    1.67 +        output.shouldContain("Loading classes to share");
    1.68 +        output.shouldHaveExitValue(0);
    1.69 +
    1.70 +
    1.71 +        // run using the shared archive
    1.72 +        pb = ProcessTools.createJavaProcessBuilder(
    1.73 +            "-XX:+UnlockDiagnosticVMOptions",
    1.74 +            "-XX:SharedArchiveFile=./sample.jsa",
    1.75 +            "-Xshare:on",
    1.76 +            objectAlignmentArg,
    1.77 +            "-version");
    1.78 +
    1.79 +        output = new OutputAnalyzer(pb.start());
    1.80 +
    1.81 +        try {
    1.82 +            output.shouldContain("sharing");
    1.83 +            output.shouldHaveExitValue(0);
    1.84 +        } catch (RuntimeException e) {
    1.85 +            // CDS uses absolute addresses for performance.
    1.86 +            // It will try to reserve memory at a specific address;
    1.87 +            // there is a chance such reservation will fail
    1.88 +            // If it does, it is NOT considered a failure of the feature,
    1.89 +            // rather a possible expected outcome, though not likely
    1.90 +            output.shouldContain(
    1.91 +                "Unable to reserve shared space at required address");
    1.92 +            output.shouldHaveExitValue(1);
    1.93 +        }
    1.94 +    }
    1.95 +}

mercurial