Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach045/attach045Target.java
40951 views
1
/*
2
* Copyright (c) 2007, 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
package nsk.jvmti.AttachOnDemand.attach045;
24
25
import nsk.share.CustomClassLoader;
26
import nsk.share.TestBug;
27
import nsk.share.aod.*;
28
import java.util.*;
29
30
/*
31
* This target application provokes following events:
32
* - ClassLoad
33
* - ClassPrepare
34
* - ThreadStart
35
* - ThreadEnd
36
* - VMObjectAlloc
37
*
38
* Note: number of generated events should be up-to-date with numbers expected by test agents
39
*/
40
public class attach045Target extends TargetApplicationWaitingAgents {
41
42
static final String classPathOption = "classPath";
43
44
List<Thread> threadsGeneratingEvents = new ArrayList<Thread>();
45
46
static class ArgParser extends AODTargetArgParser {
47
ArgParser(String[] args) {
48
super(args);
49
}
50
51
protected boolean checkOption(String option, String value) {
52
if (super.checkOption(option, value))
53
return true;
54
55
if (option.equals(classPathOption))
56
return true;
57
58
return false;
59
}
60
61
protected void checkOptions() {
62
super.checkOptions();
63
64
if (!options.containsKey(classPathOption))
65
throw new TestBug("Classpath wasn't specified");
66
}
67
68
String getClasspath() {
69
return options.getProperty(classPathOption);
70
}
71
}
72
73
protected AODTargetArgParser createArgParser(String[] args) {
74
return new ArgParser(args);
75
}
76
77
protected void init(String[] args) {
78
for (int i = 0; i < 10; i++) {
79
ClassEventsThread thread = new ClassEventsThread(50, ((ArgParser)argParser).getClasspath());
80
thread.setName("attach045-ClassEventsThread-" + i);
81
threadsGeneratingEvents.add(thread);
82
}
83
}
84
85
static final String CLASS_TO_LOAD_NAME = "nsk.jvmti.AttachOnDemand.attach045.ClassToLoad";
86
87
static class TestClassLoader extends CustomClassLoader {
88
public Class<?> loadClass(String name) throws ClassNotFoundException {
89
if (name.equals(CLASS_TO_LOAD_NAME))
90
return findClass(name);
91
else
92
return super.loadClass(name);
93
}
94
}
95
96
class ClassEventsThread extends Thread {
97
int eventsNumber;
98
String classPath;
99
100
ClassEventsThread(int eventsNumber, String classPath) {
101
this.eventsNumber = eventsNumber;
102
this.classPath = classPath;
103
}
104
105
public void run() {
106
try {
107
for (int i = 0; i < eventsNumber; i++) {
108
/*
109
* Provoke ClassLoad/ClassPrepare events
110
*/
111
TestClassLoader classLoader = new TestClassLoader();
112
classLoader.setClassPath(classPath);
113
Class<?> klass = Class.forName(CLASS_TO_LOAD_NAME, true, classLoader);
114
115
/*
116
* Provoke VMObjectAlloc event
117
*/
118
klass.newInstance();
119
}
120
} catch (Throwable t) {
121
setStatusFailed(t);
122
}
123
}
124
}
125
126
protected void targetApplicationActions() throws Throwable {
127
for (Thread thread : threadsGeneratingEvents) {
128
thread.start();
129
}
130
131
log.display("Starting to generate events");
132
133
/*
134
* Provoke ThreadStart/ThreadEnd events
135
*/
136
for (int i = 0; i < 100; i++) {
137
Thread thread = new Thread(new Runnable() {
138
public void run() {
139
// do nothing
140
}
141
});
142
thread.setName("attach045-ThreadStartEndEventsThread-" + i);
143
thread.start();
144
thread.join();
145
}
146
147
for (Thread thread : threadsGeneratingEvents) {
148
thread.join();
149
}
150
151
log.display("All events were generated");
152
}
153
154
public static void main(String[] args) {
155
new attach045Target().runTargetApplication(args);
156
}
157
}
158
159