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