Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jvmti/CompiledMethodUnload/compmethunload001.java
40948 views
1
/*
2
* Copyright (c) 2003, 2018, 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
package nsk.jvmti.CompiledMethodUnload;
25
26
import java.io.*;
27
import java.math.*;
28
import java.util.*;
29
30
import nsk.share.*;
31
import nsk.share.jvmti.*;
32
33
/**
34
* This test exercises the JVMTI event <code>CompiledMethodUnload</code>.
35
* <br>It creates an instance of tested class 'HotClass'. Then special
36
* 'hot' methods are called in a loop in order to be compiled/inlined.
37
* Then the class is provoked to be unloaded and, thus, CompiledMethodUnload
38
* events generation for the compiled methods mentioned above.<br>
39
* The CompiledMethodUnload events, if they occur, must be sent only
40
* during the live phase of the VM execution.
41
*/
42
public class compmethunload001 {
43
44
/**
45
* class signature to be loaded and then unloaded
46
*/
47
private final static String CLS_TO_BE_UNLOADED =
48
"nsk.jvmti.CompiledMethodUnload.compmethunload001u";
49
50
private final static int MAX_ITERATIONS = 5;
51
52
static {
53
try {
54
System.loadLibrary("compmethunload001");
55
} catch (UnsatisfiedLinkError ule) {
56
System.err.println("Could not load \"compmethunload001\" library");
57
System.err.println("java.library.path:"
58
+ System.getProperty("java.library.path"));
59
throw ule;
60
}
61
}
62
63
native int check();
64
native int unloaded();
65
66
public static void main(String[] argv) throws Exception {
67
argv = nsk.share.jvmti.JVMTITest.commonInit(argv);
68
69
// produce JCK-like exit status
70
System.exit(run(argv, System.out) + Consts.JCK_STATUS_BASE);
71
}
72
73
public static int run(String argv[], PrintStream out) throws Exception {
74
return new compmethunload001().runThis(argv, out);
75
}
76
77
public static void callHotClass(String location) throws Exception {
78
String clsDir = location + File.separator + "loadclass";
79
80
ClassUnloader clsUnLoader = new ClassUnloader();
81
// load the class
82
System.out.println("\nTrying to load class from "
83
+ clsDir + " ...");
84
clsUnLoader.loadClass(CLS_TO_BE_UNLOADED, clsDir);
85
86
Class<?> c = clsUnLoader.getLoadedClass();
87
Object hotCls = c.newInstance();
88
89
// Call hot methods that get compiled
90
c.getMethod("entryMethod").invoke(hotCls);
91
c.getMethod("entryNewMethod").invoke(hotCls);
92
// provoke unloading of previously compiled methods
93
hotCls = null;
94
c = null;
95
96
boolean clsUnloaded = clsUnLoader.unloadClass();
97
clsUnLoader = null;
98
System.gc();
99
}
100
101
private int runThis(String argv[], PrintStream out) throws Exception {
102
ArgumentHandler argHandler = new ArgumentHandler(argv);
103
String args[] = argHandler.getArguments();
104
if (args.length < 1)
105
throw new Failure("TEST BUG: path for class to be loaded is not specified");
106
107
callHotClass(args[0]);
108
109
// Wait until something is unloaded
110
int num = unloaded();
111
int iter = 0;
112
while (num == 0) {
113
System.gc();
114
num = unloaded();
115
iter++;
116
if (iter > MAX_ITERATIONS) {
117
throw new Failure("PRODUCT BUG: class was not unloaded in " + MAX_ITERATIONS);
118
}
119
}
120
System.out.println("Number of unloaded events " + num + " number of iterations " + iter);
121
return check();
122
}
123
}
124
125