Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/serviceability/jvmti/RedefineClasses/TestMultipleClasses.java
41153 views
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
* @test
26
* @bug 8139551
27
* @summary Scalability problem with redefinition - multiple code cache walks
28
* @requires vm.jvmti
29
* @library /test/lib
30
* @modules java.base/jdk.internal.misc
31
* @modules java.compiler
32
* java.instrument
33
* jdk.jartool/sun.tools.jar
34
* @run main RedefineClassHelper
35
* @run main/othervm/timeout=180 -javaagent:redefineagent.jar -XX:CompileThreshold=100 -Xlog:redefine+class+nmethod=debug TestMultipleClasses
36
*/
37
38
import java.lang.instrument.*;
39
import java.lang.reflect.*;
40
import jdk.test.lib.compiler.InMemoryJavaCompiler;
41
42
public class TestMultipleClasses extends ClassLoader {
43
44
public static String B(int count) {
45
return new String("public class B" + count + " {" +
46
" public static void compiledMethod() { " +
47
" try{" +
48
" Thread.sleep(1); " +
49
" } catch(InterruptedException ie) {" +
50
" }" +
51
" }" +
52
"}");
53
}
54
55
static String newB(int count) {
56
return new String("public class B" + count + " {" +
57
" public static void compiledMethod() { " +
58
" System.out.println(\"compiledMethod called " + count + "\");" +
59
" }" +
60
"}");
61
}
62
63
static int index = 0;
64
65
@Override
66
protected Class<?> findClass(String name) throws ClassNotFoundException {
67
if (name.equals("B" + index)) {
68
byte[] b = InMemoryJavaCompiler.compile(name, B(index));
69
return defineClass(name, b, 0, b.length);
70
} else {
71
return super.findClass(name);
72
}
73
}
74
75
static void runCompiledMethodMethods(Class c, int count) throws Exception {
76
// Run for a while so they compile.
77
Object o = c.newInstance();
78
Method m = c.getMethod("compiledMethod");
79
for (int i = 0; i < count; i++) {
80
m.invoke(o);
81
}
82
}
83
84
public static void main(String[] args) throws Exception {
85
86
final int numberOfClasses = 20;
87
Class[] classes = new Class[numberOfClasses];
88
byte[][] newClass = new byte[numberOfClasses][];
89
ClassDefinition[] defs = new ClassDefinition[numberOfClasses];
90
91
TestMultipleClasses loader = new TestMultipleClasses();
92
93
// Load and start all the classes.
94
for (index = 0; index < numberOfClasses; index++) {
95
String name = new String("B" + index);
96
Class c = loader.findClass(name);
97
98
runCompiledMethodMethods(c, 500);
99
// Make class definition for redefinition
100
classes[index] = c;
101
newClass[index] = InMemoryJavaCompiler.compile(c.getName(), newB(index));
102
defs[index] = new ClassDefinition(c, newClass[index]);
103
}
104
105
long startTime = System.currentTimeMillis();
106
107
// Redefine all classes.
108
RedefineClassHelper.instrumentation.redefineClasses(defs);
109
110
long endTime = System.currentTimeMillis();
111
112
System.out.println("Redefinition took " + (endTime - startTime) + " milliseconds");
113
114
System.gc();
115
116
// Run all new classes.
117
for (index = 0; index < numberOfClasses; index++) {
118
runCompiledMethodMethods(classes[index], 1);
119
}
120
}
121
}
122
123