1 /*
2 * Copyright (c) 2020, 2022, 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 * @bug 8249276
28 * @summary When dumping the CDS archive, try to lock some objects. These objects should be archived
29 * without the locking bits in the markWord.
30 * @library /test/lib /test/hotspot/jtreg/runtime/cds/appcds
31 * @requires vm.cds
32 * @requires vm.jvmti
33 * @modules java.instrument
34 * @run driver LockDuringDump
35 */
36
37 import jdk.test.lib.process.OutputAnalyzer;
38 import jdk.test.lib.helpers.ClassFileInstaller;
39
40 public class LockDuringDump {
41 public static String appClasses[] = {
42 LockDuringDumpApp.class.getName(),
43 };
44 public static String agentClasses[] = {
45 LockDuringDumpAgent.class.getName(),
46 };
47
48 private static final String MANIFEST =
49 "Manifest-Version: 1.0\nPremain-Class: LockDuringDumpAgent\n";
50
51 public static void main(String[] args) throws Throwable {
52 String agentJar =
53 ClassFileInstaller.writeJar("LockDuringDumpAgent.jar",
54 ClassFileInstaller.Manifest.fromString(MANIFEST),
55 agentClasses);
56
57 String appJar =
58 ClassFileInstaller.writeJar("LockDuringDumpApp.jar", appClasses);
59
60 for (int i = 0; i < 2; i++) {
61 // i = 0 -- dump without agent
62 // i = 1 -- dump with agent
63
64 String agentArg = (i == 0) ? "-showversion" : "-javaagent:" + agentJar;
65 String agentArg2 = (i == 0) ? "-showversion" : "-XX:+AllowArchivingWithJavaAgent";
66
67 OutputAnalyzer out =
68 TestCommon.testDump(appJar, TestCommon.list(LockDuringDumpApp.class.getName()),
69 "-XX:+UnlockDiagnosticVMOptions",
70 agentArg, agentArg2);
71 if (i != 0 && !out.getStdout().contains("LockDuringDumpAgent timeout")) {
72 out.shouldContain("Let's hold the lock on the literal string");
73 }
74
75 TestCommon.run(
76 "-cp", appJar,
77 "-XX:+UnlockDiagnosticVMOptions", agentArg2,
78 LockDuringDumpApp.class.getName())
79 .assertNormalExit("I am able to lock the literal string");
80 }
81 }
82 }
83
--- EOF ---