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