test/hotspot/jtreg/runtime/cds/appcds/ArchiveRelocationTest.java
author iklam
Thu, 14 Nov 2019 14:54:39 -0800
changeset 59098 124164752fe4
parent 59070 22ee476cc664
permissions -rw-r--r--
8234196: [TESTBUG] DynamicArchiveRelocationTest.java missing "ArchiveRelocationMode == 1 ...." Reviewed-by: dcubed
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
59070
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
     1
/*
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
     2
 * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
     4
 *
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
     7
 * published by the Free Software Foundation.
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
     8
 *
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    13
 * accompanied this code).
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    14
 *
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    18
 *
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    21
 * questions.
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    22
 */
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    23
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    24
/**
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    25
 * @test
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    26
 * @comment the test uses -XX:ArchiveRelocationMode=1 to force relocation.
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    27
 * @requires vm.cds
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    28
 * @summary Testing relocation of CDS archive (during both dump time and run time)
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    29
 * @comment JDK-8231610 Relocate the CDS archive if it cannot be mapped to the requested address
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    30
 * @bug 8231610
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    31
 * @library /test/lib /test/hotspot/jtreg/runtime/cds/appcds/test-classes
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    32
 * @build Hello
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    33
 * @run driver ClassFileInstaller -jar hello.jar Hello
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    34
 * @run driver ArchiveRelocationTest
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    35
 */
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    36
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    37
import jdk.test.lib.process.OutputAnalyzer;
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    38
import jtreg.SkippedException;
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    39
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    40
public class ArchiveRelocationTest {
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    41
    public static void main(String... args) throws Exception {
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    42
        try {
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    43
            test(true,  false);
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    44
            test(false, true);
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    45
            test(true,  true);
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    46
        } catch (SkippedException s) {
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    47
            s.printStackTrace();
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    48
            throw new RuntimeException("Archive mapping should always succeed after JDK-8231610 (did the machine run out of memory?)");
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    49
        }
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    50
    }
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    51
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    52
    static int caseCount = 0;
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    53
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    54
    // dump_reloc - force relocation of archive during dump time?
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    55
    // run_reloc  - force relocation of archive during run time?
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    56
    static void test(boolean dump_reloc, boolean run_reloc) throws Exception {
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    57
        caseCount += 1;
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    58
        System.out.println("============================================================");
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    59
        System.out.println("case = " + caseCount + ", dump = " + dump_reloc
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    60
                           + ", run = " + run_reloc);
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    61
        System.out.println("============================================================");
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    62
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    63
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    64
        String appJar = ClassFileInstaller.getJarPath("hello.jar");
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    65
        String mainClass = "Hello";
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    66
        String forceRelocation = "-XX:ArchiveRelocationMode=1";
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    67
        String dumpRelocArg = dump_reloc ? forceRelocation : "-showversion";
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    68
        String runRelocArg  = run_reloc  ? forceRelocation : "-showversion";
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    69
        String logArg = "-Xlog:cds=debug,cds+reloc=debug";
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    70
        String unlockArg = "-XX:+UnlockDiagnosticVMOptions";
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    71
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    72
        OutputAnalyzer out = TestCommon.dump(appJar,
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    73
                                             TestCommon.list(mainClass),
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    74
                                             unlockArg, dumpRelocArg, logArg);
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    75
        if (dump_reloc) {
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    76
            out.shouldContain("ArchiveRelocationMode == 1: always allocate class space at an alternative address");
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    77
            out.shouldContain("Relocating archive from");
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    78
        }
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    79
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    80
        TestCommon.run("-cp", appJar, unlockArg, runRelocArg, logArg,  mainClass)
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    81
            .assertNormalExit(output -> {
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    82
                    if (run_reloc) {
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    83
                        output.shouldContain("runtime archive relocation start");
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    84
                        output.shouldContain("runtime archive relocation done");
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    85
                    }
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    86
                });
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    87
    }
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    88
}