Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/jdk17u
Path: blob/master/test/hotspot/jtreg/serviceability/jvmti/RedefineClasses/TransformerDeadlockTest.java
66646 views
1
/*
2
* Copyright (c) 2020, 2021, 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
* @bug 8241390
27
* @summary Test recursively retransforms the same class. The test hangs if
28
* a deadlock happens.
29
* @requires vm.jvmti
30
* @requires vm.flagless
31
* @library /test/lib
32
* @modules java.instrument
33
* @compile TransformerDeadlockTest.java
34
* @run driver TransformerDeadlockTest
35
*/
36
37
import jdk.test.lib.process.ProcessTools;
38
import jdk.test.lib.helpers.ClassFileInstaller;
39
40
import java.lang.instrument.ClassFileTransformer;
41
import java.lang.instrument.IllegalClassFormatException;
42
import java.lang.instrument.Instrumentation;
43
import java.nio.file.Files;
44
import java.nio.file.Path;
45
import java.nio.file.Paths;
46
import java.security.ProtectionDomain;
47
48
public class TransformerDeadlockTest {
49
50
private static String manifest = "Premain-Class: " +
51
TransformerDeadlockTest.Agent.class.getName() + "\n"
52
+ "Can-Retransform-Classes: true\n"
53
+ "Can-Retransform-Classes: true\n";
54
55
private static String CP = System.getProperty("test.classes");
56
57
public static void main(String args[]) throws Throwable {
58
String agentJar = buildAgent();
59
ProcessTools.executeProcess(
60
ProcessTools.createJavaProcessBuilder(
61
"-javaagent:" + agentJar,
62
TransformerDeadlockTest.Agent.class.getName())
63
).shouldHaveExitValue(0);
64
}
65
66
private static String buildAgent() throws Exception {
67
Path jar = Files.createTempFile(Paths.get("."), null, ".jar");
68
String jarPath = jar.toAbsolutePath().toString();
69
ClassFileInstaller.writeJar(jarPath,
70
ClassFileInstaller.Manifest.fromString(manifest),
71
TransformerDeadlockTest.class.getName());
72
return jarPath;
73
}
74
75
public static class Agent implements ClassFileTransformer {
76
private static Instrumentation instrumentation;
77
78
public static void premain(String agentArgs, Instrumentation inst) {
79
instrumentation = inst;
80
}
81
82
@Override
83
public byte[] transform(
84
ClassLoader loader,
85
String className,
86
Class<?> classBeingRedefined,
87
ProtectionDomain protectionDomain,
88
byte[] classfileBuffer)
89
throws IllegalClassFormatException {
90
91
if (!TransformerDeadlockTest.class.getName().replace(".", "/").equals(className)) {
92
return null;
93
}
94
invokeRetransform();
95
return classfileBuffer;
96
97
}
98
99
public static void main(String[] args) throws Exception {
100
instrumentation.addTransformer(new TransformerDeadlockTest.Agent(), true);
101
102
try {
103
instrumentation.retransformClasses(TransformerDeadlockTest.class);
104
} catch (Exception e) {
105
throw new RuntimeException(e);
106
}
107
}
108
109
private static void invokeRetransform() {
110
try {
111
instrumentation.retransformClasses(TransformerDeadlockTest.class);
112
} catch (Exception e) {
113
throw new RuntimeException(e);
114
} finally {
115
}
116
}
117
}
118
}
119
120