Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadReference/CurrentContendedMonitor/curcontmonitor001.java
42332 views
1
/*
2
* Copyright (c) 2001, 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.jdwp.ThreadReference.CurrentContendedMonitor;
25
26
import java.io.*;
27
28
import nsk.share.*;
29
import nsk.share.jpda.*;
30
import nsk.share.jdwp.*;
31
32
/**
33
* Test for JDWP command: ThreadReference.CurrentContendedMonitor.
34
*
35
* See curcontmonitor001.README for description of test execution.
36
*
37
* This class represents debugger part of the test.
38
* Test is executed by invoking method runIt().
39
* JDWP command is tested in the method testCommand().
40
*
41
* @see #runIt()
42
* @see #testCommand()
43
*/
44
public class curcontmonitor001 {
45
46
// exit status constants
47
static final int JCK_STATUS_BASE = 95;
48
static final int PASSED = 0;
49
static final int FAILED = 2;
50
51
// communication signals constants
52
static final String READY = "ready";
53
static final String ERROR = "error";
54
static final String QUIT = "quit";
55
56
// package and classes names constants
57
static final String PACKAGE_NAME = "nsk.jdwp.ThreadReference.CurrentContendedMonitor";
58
static final String TEST_CLASS_NAME = PACKAGE_NAME + "." + "curcontmonitor001";
59
static final String DEBUGEE_CLASS_NAME = TEST_CLASS_NAME + "a";
60
61
// VM capability constatnts
62
static final int VM_CAPABILITY_NUMBER = JDWP.Capability.CAN_GET_CURRENT_CONTENDED_MONITOR;
63
static final String VM_CAPABILITY_NAME = "canGetCurrentContendedMonitor";
64
65
// tested JDWP command constants
66
static final String JDWP_COMMAND_NAME = "ThreadReference.CurrentContendedMonitor";
67
static final int JDWP_COMMAND_ID = JDWP.Command.ThreadReference.CurrentContendedMonitor;
68
69
// tested class name and signature constants
70
static final String TESTED_CLASS_NAME = DEBUGEE_CLASS_NAME + "$" + "TestedClass";
71
static final String TESTED_CLASS_SIGNATURE = "L" + TESTED_CLASS_NAME.replace('.', '/') + ";";
72
73
// name of the tested thread and statioc field with thread value
74
static final String TESTED_THREAD_NAME = curcontmonitor001a.THREAD_NAME;
75
static final String THREAD_FIELD_NAME = curcontmonitor001a.THREAD_FIELD_NAME;
76
static final String MONITOR_FIELD_NAME = curcontmonitor001a.MONITOR_FIELD_NAME;
77
78
// usual scaffold objects
79
ArgumentHandler argumentHandler = null;
80
Log log = null;
81
Binder binder = null;
82
Debugee debugee = null;
83
Transport transport = null;
84
IOPipe pipe = null;
85
86
// test passed or not
87
boolean success = true;
88
89
// -------------------------------------------------------------------
90
91
/**
92
* Start test from command line.
93
*/
94
public static void main (String argv[]) {
95
System.exit(run(argv,System.out) + JCK_STATUS_BASE);
96
}
97
98
/**
99
* Start JCK-compilant test.
100
*/
101
public static int run(String argv[], PrintStream out) {
102
return new curcontmonitor001().runIt(argv, out);
103
}
104
105
// -------------------------------------------------------------------
106
107
/**
108
* Perform test execution.
109
*/
110
public int runIt(String argv[], PrintStream out) {
111
112
// make log for debugger messages
113
argumentHandler = new ArgumentHandler(argv);
114
log = new Log(out, argumentHandler);
115
116
// execute test and display results
117
try {
118
log.display("\n>>> Preparing debugee for testing \n");
119
120
// launch debuggee
121
binder = new Binder(argumentHandler, log);
122
log.display("Launching debugee");
123
debugee = binder.bindToDebugee(DEBUGEE_CLASS_NAME);
124
transport = debugee.getTransport();
125
pipe = debugee.createIOPipe();
126
127
// make debuggee ready for testing
128
prepareDebugee();
129
130
// work with prepared debuggee
131
long threadID = 0;
132
try {
133
log.display("\n>>> Checking VM capability \n");
134
135
// check for VM capability
136
log.display("Checking VM capability: " + VM_CAPABILITY_NAME);
137
if (!debugee.getCapability(VM_CAPABILITY_NUMBER, VM_CAPABILITY_NAME)) {
138
out.println("TEST PASSED: unsupported VM capability: "
139
+ VM_CAPABILITY_NAME);
140
return PASSED;
141
}
142
143
log.display("\n>>> Obtaining requred data from debugee \n");
144
145
// query debuggee for classID of tested class
146
log.display("Getting classID by signature:\n"
147
+ " " + TESTED_CLASS_SIGNATURE);
148
long classID = debugee.getReferenceTypeID(TESTED_CLASS_SIGNATURE);
149
log.display(" got classID: " + classID);
150
151
// query debuggee for threadID value from a static field
152
log.display("Getting threadID value from static field: "
153
+ THREAD_FIELD_NAME);
154
threadID = queryObjectID(classID, THREAD_FIELD_NAME, JDWP.Tag.THREAD);
155
log.display(" got threadID: " + threadID);
156
157
// query debuggee for objectID value for owned monitor from a static field
158
log.display("Getting objectID value for owned monitor from static field: "
159
+ MONITOR_FIELD_NAME);
160
long monitorID = queryObjectID(classID,
161
MONITOR_FIELD_NAME, JDWP.Tag.OBJECT);
162
log.display(" got objectID: " + monitorID);
163
164
// suspend all threads into debuggee
165
log.display("Suspending all threads into debuggee");
166
debugee.suspend();
167
log.display(" debuggee suspended");
168
169
// perform testing JDWP command
170
log.display("\n>>> Testing JDWP command \n");
171
testCommand(threadID, monitorID);
172
173
} finally {
174
log.display("\n>>> Finishing test \n");
175
176
// resume all threads into debuggee
177
log.display("resuming all threads into debuggee");
178
debugee.resume();
179
log.display(" debuggee resumed");
180
181
// quit debugee
182
quitDebugee();
183
}
184
185
} catch (Failure e) {
186
log.complain("TEST FAILED: " + e.getMessage());
187
success = false;
188
} catch (Exception e) {
189
e.printStackTrace(out);
190
log.complain("Caught unexpected exception while running the test:\n\t" + e);
191
success = false;
192
}
193
194
if (!success) {
195
log.complain("TEST FAILED");
196
return FAILED;
197
}
198
199
out.println("TEST PASSED");
200
return PASSED;
201
202
}
203
204
/**
205
* Prepare debugee for testing and waiting for ready signal.
206
*/
207
void prepareDebugee() {
208
// wait for VM_INIT event from debugee
209
log.display("Waiting for VM_INIT event");
210
debugee.waitForVMInit();
211
212
// query debugee for VM-dependent ID sizes
213
log.display("Querying for IDSizes");
214
debugee.queryForIDSizes();
215
216
// resume initially suspended debugee
217
log.display("Resuming debugee VM");
218
debugee.resume();
219
220
// wait for READY signal from debugee
221
log.display("Waiting for signal from debugee: " + READY);
222
String signal = pipe.readln();
223
log.display("Received signal from debugee: " + signal);
224
if (signal == null) {
225
throw new TestBug("Null signal received from debugee: " + signal
226
+ " (expected: " + READY + ")");
227
} else if (signal.equals(ERROR)) {
228
throw new TestBug("Debugee was not able to start tested thread"
229
+ " (received signal: " + signal + ")");
230
} else if (!signal.equals(READY)) {
231
throw new TestBug("Unexpected signal received from debugee: " + signal
232
+ " (expected: " + READY + ")");
233
}
234
}
235
236
/**
237
* Sending debugee signal to quit and waiting for it exits.
238
*/
239
void quitDebugee() {
240
// send debugee signal to quit
241
log.display("Sending signal to debugee: " + QUIT);
242
pipe.println(QUIT);
243
244
// wait for debugee exits
245
log.display("Waiting for debugee exits");
246
int code = debugee.waitFor();
247
248
// analize debugee exit status code
249
if (code == JCK_STATUS_BASE + PASSED) {
250
log.display("Debugee PASSED with exit code: " + code);
251
} else {
252
log.complain("Debugee FAILED with exit code: " + code);
253
success = false;
254
}
255
}
256
257
/**
258
* Query debuggee for objectID value of static class field.
259
*/
260
long queryObjectID(long classID, String fieldName, byte tag) {
261
// get fieledID for static field (declared in the class)
262
long fieldID = debugee.getClassFieldID(classID, fieldName, true);
263
// get value of the field
264
JDWP.Value value = debugee.getStaticFieldValue(classID, fieldID);
265
266
// check that value has THREAD tag
267
if (value.getTag() != tag) {
268
throw new Failure("Wrong objectID tag received from field \"" + fieldName
269
+ "\": " + value.getTag() + " (expected: " + tag + ")");
270
}
271
272
// extract threadID from the value
273
long objectID = ((Long)value.getValue()).longValue();
274
return objectID;
275
}
276
277
/**
278
* Perform testing JDWP command for specified threadID.
279
*/
280
void testCommand(long threadID, long monitorID) {
281
// create command packet and fill requred out data
282
log.display("Create command packet:");
283
log.display("Command: " + JDWP_COMMAND_NAME);
284
CommandPacket command = new CommandPacket(JDWP_COMMAND_ID);
285
log.display(" threadID: " + threadID);
286
command.addObjectID(threadID);
287
command.setLength();
288
289
// send command packet to debugee
290
try {
291
log.display("Sending command packet:\n" + command);
292
transport.write(command);
293
} catch (IOException e) {
294
log.complain("Unable to send command packet:\n\t" + e);
295
success = false;
296
return;
297
}
298
299
ReplyPacket reply = new ReplyPacket();
300
301
// receive reply packet from debugee
302
try {
303
log.display("Waiting for reply packet");
304
transport.read(reply);
305
log.display("Reply packet received:\n" + reply);
306
} catch (IOException e) {
307
log.complain("Unable to read reply packet:\n\t" + e);
308
success = false;
309
return;
310
}
311
312
// check reply packet header
313
try{
314
log.display("Checking reply packet header");
315
reply.checkHeader(command.getPacketID());
316
} catch (BoundException e) {
317
log.complain("Bad header of reply packet:\n\t" + e.getMessage());
318
success = false;
319
return;
320
}
321
322
// start parsing reply packet data
323
log.display("Parsing reply packet:");
324
reply.resetPosition();
325
326
// extract object tag
327
byte tag = (byte)0;
328
try {
329
tag = reply.getByte();
330
log.display(" tag: " + tag);
331
} catch (BoundException e) {
332
log.complain("Unable to extract tag for contended monitor object from reply packet:\n\t"
333
+ e.getMessage());
334
success = false;
335
return;
336
}
337
338
// extract objectID
339
long objectID = 0;
340
try {
341
objectID = reply.getObjectID();
342
log.display(" objectID: " + objectID);
343
} catch (BoundException e) {
344
log.complain("Unable to extract contended monitor objectID from reply packet:\n\t"
345
+ e.getMessage());
346
success = false;
347
return;
348
}
349
350
// check that tag is an OBJECT tag
351
if (tag != JDWP.Tag.OBJECT) {
352
log.complain("Unexpected tag for monitor object received:" + tag
353
+ " (expected" + JDWP.Tag.OBJECT);
354
success = false;
355
}
356
357
// check that objectID is not negative integer
358
if (objectID < 0) {
359
log.complain("Negative value of objectID received: " + objectID);
360
success = false;
361
}
362
363
// check that objectID is as expected
364
if (objectID != monitorID) {
365
log.display("Unexpected monitor objectID received: " + objectID
366
+ " (expected" + monitorID);
367
success = false;
368
}
369
370
// check for extra data in reply packet
371
if (!reply.isParsed()) {
372
log.complain("Extra trailing bytes found in reply packet at: "
373
+ reply.offsetString());
374
success = false;
375
}
376
377
}
378
379
}
380
381