test/hotspot/jtreg/runtime/SharedArchiveFile/CheckDefaultArchiveFile.java
author jiangli
Fri, 05 Oct 2018 18:56:11 -0400
changeset 52030 57862a02bf4b
child 57562 e2b758f8e77a
permissions -rw-r--r--
8202951: Implementation of JEP 341: Default CDS Archives 8210592: Convert CDS-mode test sets in tier5 and tier6 to non-CDS-mode tests 8209739: [TESTBUG] javax/imageio/plugins/png/ItxtUtf8Test.java fails with OutOfMemoryError when running in CDS mode Summary: Generate the default CDS archive at JDK build time. Reviewed-by: erikj, ihse, dholmes, iklam, ccheung, mseledtsov Contributed-by: erik.joelsson@oracle.com, jiangli.zhou@oracle.com, calvin.cheung@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
52030
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents:
diff changeset
     1
/*
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents:
diff changeset
     2
 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents:
diff changeset
     4
 *
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents:
diff changeset
     7
 * published by the Free Software Foundation.
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents:
diff changeset
     8
 *
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents:
diff changeset
    13
 * accompanied this code).
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents:
diff changeset
    14
 *
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents:
diff changeset
    18
 *
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents:
diff changeset
    21
 * questions.
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents:
diff changeset
    22
 */
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents:
diff changeset
    23
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents:
diff changeset
    24
/**
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents:
diff changeset
    25
 * @test Default CDS archive file
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents:
diff changeset
    26
 * @summary JDK platforms/binaries do not support default CDS archive should
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents:
diff changeset
    27
 *          not contain classes.jsa in the default location.
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents:
diff changeset
    28
 * @library /test/lib
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents:
diff changeset
    29
 * @modules java.base/jdk.internal.misc
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents:
diff changeset
    30
 *          java.management
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents:
diff changeset
    31
 * @build sun.hotspot.WhiteBox
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents:
diff changeset
    32
 * @run driver ClassFileInstaller sun.hotspot.WhiteBox
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents:
diff changeset
    33
 * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents:
diff changeset
    34
 *      -XX:+WhiteBoxAPI CheckDefaultArchiveFile
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents:
diff changeset
    35
 */
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents:
diff changeset
    36
import java.nio.file.Files;
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents:
diff changeset
    37
import java.nio.file.Path;
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents:
diff changeset
    38
import java.nio.file.Paths;
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents:
diff changeset
    39
import jdk.test.lib.Platform;
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents:
diff changeset
    40
import jdk.test.lib.cds.CDSTestUtils;
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents:
diff changeset
    41
import jtreg.SkippedException;
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents:
diff changeset
    42
import sun.hotspot.WhiteBox;
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents:
diff changeset
    43
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents:
diff changeset
    44
public class CheckDefaultArchiveFile {
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents:
diff changeset
    45
    public static void main(String[] args) throws Exception {
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents:
diff changeset
    46
        WhiteBox wb = WhiteBox.getWhiteBox();
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents:
diff changeset
    47
        String osArch = Platform.getOsArch();
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents:
diff changeset
    48
        String vmName = System.getProperty("java.vm.name");
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents:
diff changeset
    49
        String vmString = vmName + "(" + osArch + ")";
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents:
diff changeset
    50
        String jsaString = wb.getDefaultArchivePath();
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents:
diff changeset
    51
        Path jsa = Paths.get(jsaString);
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents:
diff changeset
    52
        if (Platform.isDefaultCDSArchiveSupported()) {
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents:
diff changeset
    53
            if (Files.exists(jsa)) {
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents:
diff changeset
    54
                System.out.println("Passed. " + vmString +
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents:
diff changeset
    55
                                   ": has default classes.jsa file");
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents:
diff changeset
    56
            } else {
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents:
diff changeset
    57
                throw new RuntimeException(vmString + "has no " + jsaString);
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents:
diff changeset
    58
            }
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents:
diff changeset
    59
        } else {
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents:
diff changeset
    60
            throw new SkippedException("Default CDS archive is not supported");
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents:
diff changeset
    61
        }
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents:
diff changeset
    62
    }
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents:
diff changeset
    63
}