Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/jdk17u
Path: blob/master/test/hotspot/jtreg/serviceability/jvmti/RedefineClasses/RetransformClassesZeroLength.java
66646 views
1
/*
2
* Copyright (c) 2018, 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 8198393
27
* @summary Instrumentation.retransformClasses(new Class[0]) should be NOP
28
* @requires vm.jvmti
29
* @requires vm.flagless
30
* @library /test/lib
31
* @modules java.instrument
32
* @compile RetransformClassesZeroLength.java
33
* @run driver RetransformClassesZeroLength
34
*/
35
36
import java.lang.instrument.ClassFileTransformer;
37
import java.lang.instrument.IllegalClassFormatException;
38
import java.lang.instrument.Instrumentation;
39
import java.lang.instrument.UnmodifiableClassException;
40
import java.nio.file.Files;
41
import java.nio.file.Path;
42
import java.nio.file.Paths;
43
import java.security.ProtectionDomain;
44
45
import jdk.test.lib.process.ProcessTools;
46
import jdk.test.lib.helpers.ClassFileInstaller;
47
48
public class RetransformClassesZeroLength {
49
50
private static String manifest =
51
"Premain-Class: " + RetransformClassesZeroLength.Agent.class.getName() + "\n"
52
+ "Can-Retransform-Classes: true\n";
53
54
private static String CP = System.getProperty("test.classes");
55
56
public static void main(String args[]) throws Throwable {
57
String agentJar = buildAgent();
58
ProcessTools.executeProcess(
59
ProcessTools.createJavaProcessBuilder(
60
"-javaagent:" + agentJar,
61
"-version")
62
).shouldHaveExitValue(0);
63
}
64
65
private static String buildAgent() throws Exception {
66
Path jar = Files.createTempFile(Paths.get("."), null, ".jar");
67
String jarPath = jar.toAbsolutePath().toString();
68
ClassFileInstaller.writeJar(jarPath,
69
ClassFileInstaller.Manifest.fromString(manifest),
70
RetransformClassesZeroLength.class.getName());
71
return jarPath;
72
}
73
74
75
public static class Agent implements ClassFileTransformer {
76
public static void premain(String args, Instrumentation inst) {
77
inst.addTransformer(new NoOpTransformer());
78
try {
79
inst.retransformClasses(new Class[0]);
80
} catch (UnmodifiableClassException ex) {
81
throw new AssertionError(ex);
82
}
83
}
84
}
85
86
private static class NoOpTransformer implements ClassFileTransformer {
87
@Override
88
public byte[] transform(ClassLoader loader,
89
String className,
90
Class<?> classBeingRedefined,
91
ProtectionDomain protectionDomain,
92
byte[] classfileBuffer
93
) throws IllegalClassFormatException {
94
return null; // no transform
95
}
96
}
97
}
98
99