Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/share/jdi/OwnedMonitorsDebuggee.java
41161 views
1
/*
2
* Copyright (c) 2006, 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.share.jdi;
24
25
import java.io.*;
26
import java.util.*;
27
import nsk.share.locks.LockingThread;
28
import nsk.share.TestBug;
29
30
/*
31
* Class is used as base debuggee in tests for ThreadReference.ownedMonitorsAndFrames().
32
*
33
* Class handle commands for creating threads which acquires and relinquish locks in different ways,
34
* nsk.share.locks.LockingThread is used for this purposes.
35
*
36
* Information about acquired monitors can be stored in static array 'monitorsInfo' and in this way this
37
* data is available for debugger.
38
*/
39
public class OwnedMonitorsDebuggee extends AbstractJDIDebuggee {
40
// command:threadName:stackFrameDescription
41
public static final String COMMAND_CREATE_LOCKING_THREAD = "createLockingThread";
42
43
// command:threadName
44
public static final String COMMAND_STOP_LOCKING_THREAD = "stopLockingThread";
45
46
// command:threadName
47
public static final String COMMAND_UPDATE_MONITOR_INFO = "updateMonitorInfo";
48
49
// command:threadName
50
public static final String COMMAND_EXIT_SINGLE_FRAME = "exitSingleFrame";
51
52
// command:threadName:monitorIndex
53
public static final String COMMAND_RELINQUISH_MONITOR = "relinquishMonitor";
54
55
// command:threadName
56
public static final String COMMAND_ACQUIRE_RELINQUISHED_MONITOR = "acquireRelinquishedMonitor";
57
58
// from this array information about acquired monitors is available for debugger
59
// (this class is used in stress tests where several tests are executed consecutively, but in this case using of
60
// static array shouldn't cause problems because of before using of array 'monitorsInfo' debugger
61
// uses COMMAND_UPDATE_MONITOR_INFO which updates this array with latest data, so excution of one test shouldn't
62
// affect other tests)
63
public static LockingThread.DebugMonitorInfo monitorsInfo[];
64
65
private boolean returnJNIMonitors;
66
67
public final static String mainThreadName = "OwnedMonitorDebuggeeMainThread";
68
69
protected String[] doInit(String[] args) {
70
Thread.currentThread().setName(mainThreadName);
71
72
args = super.doInit(args);
73
74
ArrayList<String> standardArgs = new ArrayList<String>();
75
76
for (int i = 0; i < args.length; i++) {
77
if (args[i].equalsIgnoreCase("-returnJNIMonitors")) {
78
returnJNIMonitors = true;
79
} else
80
standardArgs.add(args[i]);
81
}
82
83
return standardArgs.toArray(new String[] {});
84
}
85
86
public boolean parseCommand(String command) {
87
if (super.parseCommand(command))
88
return true;
89
90
StreamTokenizer tokenizer = new StreamTokenizer(new StringReader(command));
91
tokenizer.whitespaceChars(':', ':');
92
tokenizer.wordChars('_', '_');
93
94
try {
95
if (command.startsWith(COMMAND_ACQUIRE_RELINQUISHED_MONITOR)) {
96
tokenizer.nextToken();
97
98
if (tokenizer.nextToken() != StreamTokenizer.TT_WORD)
99
throw new TestBug("Invalid command format: " + command);
100
101
String threadName = tokenizer.sval;
102
103
acquireRelinquishMonitor(threadName);
104
105
return true;
106
} else if (command.startsWith(COMMAND_RELINQUISH_MONITOR)) {
107
tokenizer.nextToken();
108
109
if (tokenizer.nextToken() != StreamTokenizer.TT_WORD)
110
throw new TestBug("Invalid command format: " + command);
111
112
String threadName = tokenizer.sval;
113
114
if (tokenizer.nextToken() != StreamTokenizer.TT_NUMBER)
115
throw new TestBug("Invalid command format: " + command);
116
117
int monitorIndex = (int) tokenizer.nval;
118
119
relinquishMonitor(threadName, monitorIndex);
120
121
return true;
122
} else if (command.startsWith(COMMAND_CREATE_LOCKING_THREAD)) {
123
tokenizer.nextToken();
124
125
if (tokenizer.nextToken() != StreamTokenizer.TT_WORD)
126
throw new TestBug("Invalid command format: " + command);
127
128
String threadName = tokenizer.sval;
129
130
List<String> stackFramesDescription = new ArrayList<String>();
131
132
while (tokenizer.nextToken() == StreamTokenizer.TT_WORD) {
133
stackFramesDescription.add(tokenizer.sval);
134
}
135
136
createLockingThread(threadName, stackFramesDescription);
137
return true;
138
} else if (command.startsWith(COMMAND_STOP_LOCKING_THREAD)) {
139
tokenizer.nextToken();
140
141
if (tokenizer.nextToken() != StreamTokenizer.TT_WORD)
142
throw new TestBug("Invalid command format: " + command);
143
144
String threadName = tokenizer.sval;
145
146
stopLockingThread(threadName);
147
148
return true;
149
} else if (command.startsWith(COMMAND_UPDATE_MONITOR_INFO)) {
150
tokenizer.nextToken();
151
152
if (tokenizer.nextToken() != StreamTokenizer.TT_WORD)
153
throw new TestBug("Invalid command format: " + command);
154
155
String threadName = tokenizer.sval;
156
157
updateMonitorInfo(threadName);
158
159
return true;
160
} else if (command.startsWith(COMMAND_EXIT_SINGLE_FRAME)) {
161
tokenizer.nextToken();
162
163
if (tokenizer.nextToken() != StreamTokenizer.TT_WORD)
164
throw new TestBug("Invalid command format: " + command);
165
166
String threadName = tokenizer.sval;
167
168
exitSingleFrame(threadName);
169
170
return true;
171
}
172
} catch (IOException e) {
173
throw new TestBug("Invalid command format: " + command);
174
}
175
176
return false;
177
}
178
179
public void acquireRelinquishMonitor(String threadName) {
180
LockingThread thread = getThread(threadName);
181
thread.acquireRelinquishedMonitor();
182
183
thread.waitState();
184
updateMonitorInfo(threadName);
185
}
186
187
public void relinquishMonitor(String threadName, int monitorIndex) {
188
LockingThread thread = getThread(threadName);
189
thread.relinquishMonitor(monitorIndex);
190
191
thread.waitState();
192
updateMonitorInfo(threadName);
193
}
194
195
private void updateMonitorInfo(String threadName) {
196
LockingThread thread = getThread(threadName);
197
monitorsInfo = thread.getMonitorsInfo(returnJNIMonitors);
198
}
199
200
private Map<String, LockingThread> threads = new TreeMap<String, LockingThread>();
201
202
private LockingThread getThread(String threadName) {
203
LockingThread thread = threads.get(threadName);
204
205
if (thread == null)
206
throw new TestBug("Locking thread with name: " + threadName + " was not created");
207
208
return thread;
209
}
210
211
private void stopLockingThread(String threadName) {
212
LockingThread thread = getThread(threadName);
213
thread.stopLockingThread();
214
thread.waitState();
215
216
updateMonitorInfo(threadName);
217
}
218
219
private void exitSingleFrame(String threadName) {
220
LockingThread thread = getThread(threadName);
221
thread.exitSingleFrame();
222
thread.waitState();
223
224
updateMonitorInfo(threadName);
225
}
226
227
private void createLockingThread(String threadName, List<String> stackFramesDescription) {
228
if (threads.get(threadName) != null)
229
throw new TestBug("Locking thread with name: " + threadName + " already exists");
230
231
LockingThread thread = new LockingThread(log, stackFramesDescription);
232
thread.setName(threadName);
233
thread.start();
234
thread.waitState();
235
236
threads.put(threadName, thread);
237
238
updateMonitorInfo(threadName);
239
}
240
241
public static void main(String args[]) {
242
OwnedMonitorsDebuggee debuggee = new OwnedMonitorsDebuggee();
243
debuggee.doTest(args);
244
}
245
246
}
247
248