|
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 /** |
|
26 * @test |
|
27 * @comment the test uses -XX:ArchiveRelocationMode=1 to force relocation. |
|
28 * @requires vm.cds |
|
29 * @summary Testing relocation of dynamic CDS archive (during both dump time and run time) |
|
30 * @comment JDK-8231610 Relocate the CDS archive if it cannot be mapped to the requested address |
|
31 * @bug 8231610 |
|
32 * @library /test/lib /test/hotspot/jtreg/runtime/cds/appcds /test/hotspot/jtreg/runtime/cds/appcds/test-classes |
|
33 * @build Hello |
|
34 * @run driver ClassFileInstaller -jar hello.jar Hello |
|
35 * @run driver DynamicArchiveRelocationTest |
|
36 */ |
|
37 |
|
38 import jdk.test.lib.process.OutputAnalyzer; |
|
39 import jtreg.SkippedException; |
|
40 |
|
41 public class DynamicArchiveRelocationTest extends DynamicArchiveTestBase { |
|
42 public static void main(String... args) throws Exception { |
|
43 try { |
|
44 testOuter(false); |
|
45 testOuter(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 void testOuter(boolean dump_base_reloc) throws Exception { |
|
53 testInner(dump_base_reloc, true, false); |
|
54 testInner(dump_base_reloc, false, true); |
|
55 testInner(dump_base_reloc, true, true); |
|
56 } |
|
57 |
|
58 static boolean dump_base_reloc, dump_top_reloc, run_reloc; |
|
59 |
|
60 // dump_base_reloc - force relocation of archive when dumping base archive |
|
61 // dump_top_reloc - force relocation of archive when dumping top archive |
|
62 // run_reloc - force relocation of archive when running |
|
63 static void testInner(boolean dump_base_reloc, boolean dump_top_reloc, boolean run_reloc) throws Exception { |
|
64 DynamicArchiveRelocationTest.dump_base_reloc = dump_base_reloc; |
|
65 DynamicArchiveRelocationTest.dump_top_reloc = dump_top_reloc; |
|
66 DynamicArchiveRelocationTest.run_reloc = run_reloc; |
|
67 |
|
68 runTest(DynamicArchiveRelocationTest::doTest); |
|
69 } |
|
70 |
|
71 static int caseCount = 0; |
|
72 static void doTest() throws Exception { |
|
73 caseCount += 1; |
|
74 System.out.println("============================================================"); |
|
75 System.out.println("case = " + caseCount + ", base = " + dump_base_reloc |
|
76 + ", top = " + dump_top_reloc |
|
77 + ", run = " + run_reloc); |
|
78 System.out.println("============================================================"); |
|
79 |
|
80 String appJar = ClassFileInstaller.getJarPath("hello.jar"); |
|
81 String mainClass = "Hello"; |
|
82 String forceRelocation = "-XX:ArchiveRelocationMode=1"; |
|
83 String dumpBaseRelocArg = dump_base_reloc ? forceRelocation : "-showversion"; |
|
84 String dumpTopRelocArg = dump_top_reloc ? forceRelocation : "-showversion"; |
|
85 String runRelocArg = run_reloc ? forceRelocation : "-showversion"; |
|
86 String logArg = "-Xlog:cds=debug,cds+reloc=debug"; |
|
87 |
|
88 String baseArchiveName = getNewArchiveName("base"); |
|
89 String topArchiveName = getNewArchiveName("top"); |
|
90 |
|
91 String runtimeMsg1 = "ArchiveRelocationMode == 1: always map archive(s) at an alternative address"; |
|
92 String runtimeMsg2 = "runtime archive relocation start"; |
|
93 String runtimeMsg3 = "runtime archive relocation done"; |
|
94 String unlockArg = "-XX:+UnlockDiagnosticVMOptions"; |
|
95 |
|
96 // (1) Dump base archive (static) |
|
97 |
|
98 OutputAnalyzer out = dumpBaseArchive(baseArchiveName, unlockArg, dumpBaseRelocArg, logArg); |
|
99 if (dump_base_reloc) { |
|
100 out.shouldContain("ArchiveRelocationMode == 1: always allocate class space at an alternative address"); |
|
101 out.shouldContain("Relocating archive from"); |
|
102 } |
|
103 |
|
104 // (2) Dump top archive (dynamic) |
|
105 |
|
106 dump2(baseArchiveName, topArchiveName, |
|
107 unlockArg, |
|
108 dumpTopRelocArg, |
|
109 logArg, |
|
110 "-cp", appJar, mainClass) |
|
111 .assertNormalExit(output -> { |
|
112 if (dump_top_reloc) { |
|
113 output.shouldContain(runtimeMsg1); |
|
114 output.shouldContain(runtimeMsg2); |
|
115 output.shouldContain(runtimeMsg3); |
|
116 } |
|
117 }); |
|
118 |
|
119 run2(baseArchiveName, topArchiveName, |
|
120 unlockArg, |
|
121 runRelocArg, |
|
122 logArg, |
|
123 "-cp", appJar, mainClass) |
|
124 .assertNormalExit(output -> { |
|
125 if (run_reloc) { |
|
126 output.shouldContain(runtimeMsg1); |
|
127 output.shouldContain(runtimeMsg2); |
|
128 output.shouldContain(runtimeMsg3); |
|
129 } |
|
130 }); |
|
131 } |
|
132 } |