Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/serviceability/jvmti/RedefineClasses/RedefinePreviousVersions.java
41153 views
1
/*
2
* Copyright (c) 2016, 2020, 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 8165246 8010319
27
* @summary Test has_previous_versions flag and processing during class unloading.
28
* @requires vm.jvmti
29
* @requires vm.opt.final.ClassUnloading
30
* @library /test/lib
31
* @modules java.base/jdk.internal.misc
32
* @modules java.compiler
33
* java.instrument
34
* jdk.jartool/sun.tools.jar
35
* @run driver RedefineClassHelper
36
* @run driver RedefinePreviousVersions test
37
*/
38
39
import jdk.test.lib.process.ProcessTools;
40
import jdk.test.lib.process.OutputAnalyzer;
41
42
// package access top-level classes to avoid problem with RedefineClassHelper
43
// and nested types.
44
45
class RedefinePreviousVersions_B { }
46
47
class RedefinePreviousVersions_Running {
48
public static volatile boolean stop = false;
49
public static volatile boolean running = false;
50
static void localSleep() {
51
try {
52
Thread.sleep(10); // sleep for 10 ms
53
} catch(InterruptedException ie) {
54
}
55
}
56
57
public static void infinite() {
58
running = true;
59
while (!stop) { localSleep(); }
60
}
61
}
62
63
64
65
public class RedefinePreviousVersions {
66
67
public static String newB =
68
"class RedefinePreviousVersions_B {" +
69
"}";
70
71
public static String newRunning =
72
"class RedefinePreviousVersions_Running {" +
73
" public static volatile boolean stop = true;" +
74
" public static volatile boolean running = true;" +
75
" static void localSleep() { }" +
76
" public static void infinite() { }" +
77
"}";
78
79
public static void main(String[] args) throws Exception {
80
81
if (args.length > 0) {
82
83
// java -javaagent:redefineagent.jar -Xlog:stuff RedefinePreviousVersions
84
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( "-javaagent:redefineagent.jar",
85
"-Xlog:redefine+class+iklass+add=trace,redefine+class+iklass+purge=trace",
86
"RedefinePreviousVersions");
87
new OutputAnalyzer(pb.start())
88
.shouldContain("Class unloading: has_previous_versions = false")
89
.shouldContain("Class unloading: has_previous_versions = true")
90
.shouldHaveExitValue(0);
91
return;
92
}
93
94
// Redefine a class and create some garbage
95
// Since there are no methods running, the previous version is never added to the
96
// previous_version_list and the flag _has_previous_versions should stay false
97
RedefineClassHelper.redefineClass(RedefinePreviousVersions_B.class, newB);
98
99
for (int i = 0; i < 10 ; i++) {
100
String s = new String("some garbage");
101
System.gc();
102
}
103
104
// Start a class that has a method running
105
new Thread() {
106
public void run() {
107
RedefinePreviousVersions_Running.infinite();
108
}
109
}.start();
110
111
while (!RedefinePreviousVersions_Running.running) {
112
Thread.sleep(10); // sleep for 10 ms
113
}
114
115
// Since a method of newRunning is running, this class should be added to the previous_version_list
116
// of Running, and _has_previous_versions should return true at class unloading.
117
RedefineClassHelper.redefineClass(RedefinePreviousVersions_Running.class, newRunning);
118
119
for (int i = 0; i < 10 ; i++) {
120
String s = new String("some garbage");
121
System.gc();
122
}
123
124
// purge should clean everything up, except Xcomp it might not.
125
RedefinePreviousVersions_Running.stop = true;
126
127
for (int i = 0; i < 10 ; i++) {
128
String s = new String("some garbage");
129
System.gc();
130
}
131
}
132
}
133
134