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