test/hotspot/jtreg/runtime/cds/CheckSharingWithDefaultArchive.java
author chegar
Thu, 17 Oct 2019 20:54:25 +0100
branchdatagramsocketimpl-branch
changeset 58679 9c3209ff7550
parent 58678 9cf78a70fa4f
parent 57705 7cf02b2c1455
permissions -rw-r--r--
datagramsocketimpl-branch: merge with default
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
/*
57567
b000362a89a0 8202339: [TESTBUG] Consolidate the tests in runtime/SharedArchiveFile and runtime/appcds
coleenp
parents: 52030
diff changeset
     2
 * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
52030
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
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents:
diff changeset
    26
 * @summary Sharing should be enabled by default on supported platform/binaries.
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents:
diff changeset
    27
 *          No -Xshare:dump is needed. No -Xshare:auto or -Xshare:on in needed.
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents:
diff changeset
    28
 *          Verify a set of well-known shared classes.
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents:
diff changeset
    29
 * @requires vm.cds
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents:
diff changeset
    30
 * @library /test/lib
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 CheckSharingWithDefaultArchive -showversion
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 jdk.test.lib.Platform;
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents:
diff changeset
    37
import jtreg.SkippedException;
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents:
diff changeset
    38
import sun.hotspot.WhiteBox;
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents:
diff changeset
    39
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents:
diff changeset
    40
public class CheckSharingWithDefaultArchive {
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents:
diff changeset
    41
    public static void main(String[] args) throws Exception {
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents:
diff changeset
    42
        if (!Platform.isDefaultCDSArchiveSupported()) {
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents:
diff changeset
    43
            throw new SkippedException("Supported platform");
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents:
diff changeset
    44
        }
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents:
diff changeset
    45
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 classes[] = {"java.lang.Object",
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents:
diff changeset
    48
                            "java.lang.String",
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents:
diff changeset
    49
                            "java.lang.Class"};
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents:
diff changeset
    50
        // If maping fails, sharing is disabled
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents:
diff changeset
    51
        if (wb.isSharingEnabled()) {
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents:
diff changeset
    52
            for (int i = 0; i < classes.length; i++) {
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents:
diff changeset
    53
                Class c = Class.forName(classes[i]);
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents:
diff changeset
    54
                if (wb.isSharedClass(c)) {
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents:
diff changeset
    55
                    System.out.println(classes[i] + " is shared.");
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(classes[i] + " is not shared");
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
            }
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents:
diff changeset
    60
        } else {
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents:
diff changeset
    61
           throw new SkippedException("Sharing is not enabled.");
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
    }
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents:
diff changeset
    64
}