Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/serviceability/jvmti/RedefineClasses/RedefineRunningMethodsWithBacktrace.java
41155 views
1
/*
2
* Copyright (c) 2015, 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 8087315 8010319
27
* @summary Get old method's stack trace elements after GC
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 -javaagent:redefineagent.jar RedefineRunningMethodsWithBacktrace
36
*/
37
38
import static jdk.test.lib.Asserts.*;
39
40
// package access top-level class to avoid problem with RedefineClassHelper
41
// and nested types.
42
43
class RedefineRunningMethodsWithBacktrace_B {
44
static int count1 = 0;
45
static int count2 = 0;
46
public static volatile boolean stop = false;
47
static void localSleep() {
48
try {
49
Thread.sleep(10);//sleep for 10 ms
50
} catch(InterruptedException ie) {
51
}
52
}
53
54
public static void infinite() {
55
while (!stop) { count1++; localSleep(); }
56
}
57
public static void throwable() {
58
// add some stuff to the original constant pool
59
String s1 = new String ("string1");
60
String s2 = new String ("string2");
61
String s3 = new String ("string3");
62
String s4 = new String ("string4");
63
String s5 = new String ("string5");
64
String s6 = new String ("string6");
65
String s7 = new String ("string7");
66
String s8 = new String ("string8");
67
String s9 = new String ("string9");
68
String s10 = new String ("string10");
69
String s11 = new String ("string11");
70
String s12 = new String ("string12");
71
String s13 = new String ("string13");
72
String s14 = new String ("string14");
73
String s15 = new String ("string15");
74
String s16 = new String ("string16");
75
String s17 = new String ("string17");
76
String s18 = new String ("string18");
77
String s19 = new String ("string19");
78
throw new RuntimeException("throwable called");
79
}
80
}
81
82
public class RedefineRunningMethodsWithBacktrace {
83
84
public static String newB =
85
"class RedefineRunningMethodsWithBacktrace_B {" +
86
" static int count1 = 0;" +
87
" static int count2 = 0;" +
88
" public static volatile boolean stop = false;" +
89
" static void localSleep() { " +
90
" try{ " +
91
" Thread.sleep(10);" +
92
" } catch(InterruptedException ie) { " +
93
" } " +
94
" } " +
95
" public static void infinite() { " +
96
" System.out.println(\"infinite called\");" +
97
" }" +
98
" public static void throwable() { " +
99
" throw new RuntimeException(\"throwable called\");" +
100
" }" +
101
"}";
102
103
public static String evenNewerB =
104
"class RedefineRunningMethodsWithBacktrace_B {" +
105
" static int count1 = 0;" +
106
" static int count2 = 0;" +
107
" public static volatile boolean stop = false;" +
108
" static void localSleep() { " +
109
" try{ " +
110
" Thread.sleep(1);" +
111
" } catch(InterruptedException ie) { " +
112
" } " +
113
" } " +
114
" public static void infinite() { }" +
115
" public static void throwable() { " +
116
" throw new RuntimeException(\"throwable called\");" +
117
" }" +
118
"}";
119
120
private static void touchRedefinedMethodInBacktrace(Throwable throwable) {
121
System.out.println("touchRedefinedMethodInBacktrace: ");
122
throwable.printStackTrace(); // this actually crashes with the bug in
123
// java_lang_StackTraceElement::create()
124
125
// Make sure that we can convert the backtrace, which is referring to
126
// the redefined method, to a StrackTraceElement[] without crashing.
127
StackTraceElement[] stackTrace = throwable.getStackTrace();
128
for (int i = 0; i < stackTrace.length; i++) {
129
StackTraceElement frame = stackTrace[i];
130
assertNotNull(frame.getClassName(),
131
"\nTest failed: trace[" + i + "].getClassName() returned null");
132
assertNotNull(frame.getMethodName(),
133
"\nTest failed: trace[" + i + "].getMethodName() returned null");
134
}
135
}
136
137
private static Throwable getThrowableInB() {
138
Throwable t = null;
139
try {
140
RedefineRunningMethodsWithBacktrace_B.throwable();
141
} catch (Exception e) {
142
t = e;
143
// Don't print here because Throwable will cache the constructed stacktrace
144
// e.printStackTrace();
145
}
146
return t;
147
}
148
149
150
public static void main(String[] args) throws Exception {
151
152
new Thread() {
153
public void run() {
154
RedefineRunningMethodsWithBacktrace_B.infinite();
155
}
156
}.start();
157
158
Throwable t1 = getThrowableInB();
159
160
RedefineClassHelper.redefineClass(RedefineRunningMethodsWithBacktrace_B.class, newB);
161
162
System.gc();
163
164
Throwable t2 = getThrowableInB();
165
166
RedefineRunningMethodsWithBacktrace_B.infinite();
167
168
for (int i = 0; i < 20 ; i++) {
169
String s = new String("some garbage");
170
System.gc();
171
}
172
173
RedefineClassHelper.redefineClass(RedefineRunningMethodsWithBacktrace_B.class, evenNewerB);
174
System.gc();
175
176
Throwable t3 = getThrowableInB();
177
178
for (int i = 0; i < 20 ; i++) {
179
RedefineRunningMethodsWithBacktrace_B.infinite();
180
String s = new String("some garbage");
181
System.gc();
182
}
183
184
touchRedefinedMethodInBacktrace(t1);
185
touchRedefinedMethodInBacktrace(t2);
186
touchRedefinedMethodInBacktrace(t3);
187
188
// purge should clean everything up.
189
RedefineRunningMethodsWithBacktrace_B.stop = true;
190
191
for (int i = 0; i < 20 ; i++) {
192
RedefineRunningMethodsWithBacktrace_B.infinite();
193
String s = new String("some garbage");
194
System.gc();
195
}
196
}
197
}
198
199