Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/HoldEvents/holdevents002.java
41161 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.VirtualMachine.HoldEvents;
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: VirtualMachine.HoldEvents.
34
*
35
* See holdevents002.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
*
40
* @see #runIt()
41
*/
42
public class holdevents002 {
43
44
// exit status constants
45
static final int JCK_STATUS_BASE = 95;
46
static final int PASSED = 0;
47
static final int FAILED = 2;
48
49
// package and classes names constants
50
static final String PACKAGE_NAME = "nsk.jdwp.VirtualMachine.HoldEvents";
51
static final String TEST_CLASS_NAME = PACKAGE_NAME + "." + "holdevents002";
52
static final String DEBUGEE_CLASS_NAME = TEST_CLASS_NAME + "a";
53
54
// tested JDWP command constants
55
static final String JDWP_COMMAND_NAME = "VirtualMachine.HoldEvents";
56
static final int JDWP_COMMAND_ID = JDWP.Command.VirtualMachine.HoldEvents;
57
static final byte TESTED_EVENT_KIND = JDWP.EventKind.BREAKPOINT;
58
static final byte TESTED_EVENT_SUSPEND_POLICY = JDWP.SuspendPolicy.ALL;
59
static final byte TESTED_EVENT_MODIFIER = JDWP.EventModifierKind.LOCATION_ONLY;
60
61
// name and signature of the tested class
62
static final String TESTED_CLASS_NAME = DEBUGEE_CLASS_NAME + "$" + "TestedClass";
63
static final String TESTED_CLASS_SIGNATURE = "L" + TESTED_CLASS_NAME.replace('.', '/') + ";";
64
65
// name of field and method of tested class
66
static final String TESTED_METHOD_NAME = "run";
67
static final int BREAKPOINT_LINE = holdevents002a.BREAKPOINT_LINE;
68
69
// usual scaffold objects
70
ArgumentHandler argumentHandler = null;
71
Log log = null;
72
Binder binder = null;
73
Debugee debugee = null;
74
Transport transport = null;
75
int waitTime = 0; // minutes
76
long timeout = 0; // milliseconds
77
boolean dead = false;
78
boolean success = true;
79
80
// obtained data
81
long testedClassID = 0;
82
long testedMethodID = 0;
83
int eventRequestID = 0;
84
85
// -------------------------------------------------------------------
86
87
/**
88
* Start test from command line.
89
*/
90
public static void main(String argv[]) {
91
System.exit(run(argv,System.out) + JCK_STATUS_BASE);
92
}
93
94
/**
95
* Start test from JCK-compilant environment.
96
*/
97
public static int run(String argv[], PrintStream out) {
98
return new holdevents002().runIt(argv, out);
99
}
100
101
// -------------------------------------------------------------------
102
103
/**
104
* Perform test execution.
105
*/
106
public int runIt(String argv[], PrintStream out) {
107
108
// make log for debugger messages
109
argumentHandler = new ArgumentHandler(argv);
110
log = new Log(out, argumentHandler);
111
waitTime = argumentHandler.getWaitTime();
112
timeout = waitTime * 60 * 1000;
113
114
// execute test and display results
115
try {
116
log.display("\n>>> Starting debugee \n");
117
118
// launch debuggee
119
binder = new Binder(argumentHandler, log);
120
log.display("Launching debugee");
121
debugee = binder.bindToDebugee(DEBUGEE_CLASS_NAME);
122
transport = debugee.getTransport();
123
log.display(" ... debugee launched");
124
log.display("");
125
126
// set timeout for debuggee responces
127
log.display("Setting timeout for debuggee responces: " + waitTime + " minute(s)");
128
transport.setReadTimeout(timeout);
129
log.display(" ... timeout set");
130
131
// wait for debuggee started
132
log.display("Waiting for VM_INIT event");
133
debugee.waitForVMInit();
134
log.display(" ... VM_INIT event received");
135
136
// query debugee for VM-dependent ID sizes
137
log.display("Querying for IDSizes");
138
debugee.queryForIDSizes();
139
log.display(" ... size of VM-dependent types adjusted");
140
141
// get debuggee prepared for testing
142
log.display("\n>>> Get debuggee prepared for testing \n");
143
prepareForTest();
144
145
// test JDWP command
146
log.display("\n>>> Testing JDWP command \n");
147
148
log.display("Holding events into debuggee");
149
holdEvents();
150
log.display(" ... events held");
151
152
// resume debuggee
153
log.display("Resuming debuggee");
154
debugee.resume();
155
log.display(" ... debuggee resumed");
156
157
// wait for BREAKPOINT event NOT occured
158
log.display("Waiting for BREAKPOINT event NOT received");
159
waitForBreakpointEvent();
160
161
} catch (Failure e) {
162
log.complain("TEST FAILED: " + e.getMessage());
163
success = false;
164
} catch (Exception e) {
165
e.printStackTrace(out);
166
log.complain("Caught unexpected exception while running the test:\n\t" + e);
167
success = false;
168
} finally {
169
// quit debugee
170
log.display("\n>>> Finishing test \n");
171
quitDebugee();
172
}
173
174
// check test results
175
if (!success) {
176
log.complain("TEST FAILED");
177
return FAILED;
178
}
179
180
out.println("TEST PASSED");
181
return PASSED;
182
183
}
184
185
/**
186
* Prepare debuggee for testing.
187
*/
188
void prepareForTest() {
189
// wait for tested class loaded
190
log.display("Waiting for tested class loaded");
191
testedClassID = debugee.waitForClassLoaded(TESTED_CLASS_NAME, JDWP.SuspendPolicy.ALL);
192
log.display(" ... got classID: " + testedClassID);
193
log.display("");
194
195
// get methodID for breakpoint method
196
log.display("Getting breakpoint methodID by name: " + TESTED_METHOD_NAME);
197
testedMethodID = debugee.getMethodID(testedClassID, TESTED_METHOD_NAME, true);
198
log.display(" ... got methodID: " + testedMethodID);
199
200
// make request for BREAKPOINT event
201
log.display("Making request for BREAKPOINT event at: "
202
+ TESTED_METHOD_NAME + ":" + BREAKPOINT_LINE);
203
eventRequestID = debugee.requestBreakpointEvent(JDWP.TypeTag.CLASS, testedClassID,
204
testedMethodID, BREAKPOINT_LINE,
205
JDWP.SuspendPolicy.ALL);
206
log.display(" ... got requestID: " + eventRequestID);
207
}
208
209
/**
210
* Hold events into debuggee.
211
*/
212
void holdEvents() {
213
CommandPacket command = new CommandPacket(JDWP.Command.VirtualMachine.HoldEvents);
214
ReplyPacket reply = debugee.receiveReplyFor(command);
215
}
216
217
/**
218
* Wait for requested BREAKPOINT event NOT occured.
219
*/
220
void waitForBreakpointEvent() {
221
222
EventPacket eventPacket = new EventPacket();
223
224
// receive reply packet from debugee
225
try {
226
log.display("Waiting for event packet");
227
transport.setReadTimeout(timeout);
228
transport.read(eventPacket);
229
log.display(" ... event packet received:\n" + eventPacket);
230
} catch (IOException e) {
231
log.display("No event packet received for default timeout:\n\t" + e);
232
log.display("Requested BREAKPOINT event is not received after holding events");
233
return;
234
}
235
236
log.complain("An event received after holding events into debuggee");
237
log.display("");
238
239
// check reply packet header
240
try{
241
log.display("Checking header of event packet");
242
eventPacket.checkHeader();
243
log.display(" ... packet header is correct");
244
} catch (BoundException e) {
245
log.complain("Bad header of received event packet:\n\t"
246
+ e.getMessage());
247
success = false;
248
return;
249
}
250
251
// start parsing reply packet data
252
log.display("Parsing event packet:");
253
eventPacket.resetPosition();
254
255
// get suspendPolicy value
256
byte suspendPolicy = 0;
257
try {
258
suspendPolicy = eventPacket.getByte();
259
log.display(" suspendPolicy: " + suspendPolicy);
260
} catch (BoundException e) {
261
log.complain("Unable to get suspendPolicy value from received event packet:\n\t"
262
+ e.getMessage());
263
success = false;
264
return;
265
}
266
267
// get events count
268
int events = 0;
269
try {
270
events = eventPacket.getInt();
271
log.display(" events: " + events);
272
} catch (BoundException e) {
273
log.complain("Unable to get events count from received event packet:\n\t"
274
+ e.getMessage());
275
success = false;
276
return;
277
}
278
279
// check events count
280
if (events < 0) {
281
log.complain("Negative value of events number in received event packet: " +
282
events + " (expected: " + 1 + ")");
283
success = false;
284
} else if (events != 1) {
285
log.complain("Invalid number of events in received event packet: " +
286
events + " (expected: " + 1 + ")");
287
success = false;
288
}
289
290
// extract each event
291
long eventThreadID = 0;
292
for (int i = 0; i < events; i++) {
293
log.display(" event #" + i + ":");
294
295
// get eventKind
296
byte eventKind = 0;
297
try {
298
eventKind = eventPacket.getByte();
299
log.display(" eventKind: " + eventKind);
300
} catch (BoundException e) {
301
log.complain("Unable to get eventKind of event #" + i + " from received event packet:\n\t"
302
+ e.getMessage());
303
success = false;
304
return;
305
}
306
307
// check eventKind
308
if (eventKind == JDWP.EventKind.VM_DEATH) {
309
log.display("Unexpected VM_DEATH event received intead of BREAKPOINT event");
310
success = false;
311
dead = true;
312
return;
313
} else if (eventKind == JDWP.EventKind.BREAKPOINT) {
314
log.complain("Hold BREAKPOINT event received in event packet: " +
315
eventKind + " (expected: " + JDWP.EventKind.BREAKPOINT + ")");
316
success = false;
317
} else {
318
log.complain("Unexpected eventKind of event " + i + " in event packet: " +
319
eventKind + " (expected: " + JDWP.EventKind.BREAKPOINT + ")");
320
success = false;
321
return;
322
}
323
324
// get requestID
325
int requestID = 0;
326
try {
327
requestID = eventPacket.getInt();
328
log.display(" requestID: " + requestID);
329
} catch (BoundException e) {
330
log.complain("Unable to get requestID of event #" + i + " from BREAKPOINT event packet:\n\t"
331
+ e.getMessage());
332
success = false;
333
return;
334
}
335
336
// check requestID
337
if (requestID != eventRequestID) {
338
log.complain("Unexpected requestID of event " + i + " in BREAKPOINT event packet: " +
339
requestID + " (expected: " + eventRequestID + ")");
340
success = false;
341
}
342
343
// get threadID
344
long threadID = 0;
345
try {
346
threadID = eventPacket.getObjectID();
347
log.display(" threadID: " + threadID);
348
} catch (BoundException e) {
349
log.complain("Unable to get threadID of event #" + i + " from BREAKPOINT event packet:\n\t"
350
+ e.getMessage());
351
success = false;
352
return;
353
}
354
355
// get location
356
JDWP.Location location = null;
357
try {
358
location = eventPacket.getLocation();
359
log.display(" location: " + location);
360
} catch (BoundException e) {
361
log.complain("Unable to get location of event #" + i + " from BREAKPOINT event packet:\n\t"
362
+ e.getMessage());
363
success = false;
364
return;
365
}
366
}
367
368
// check for extra data in event packet
369
if (!eventPacket.isParsed()) {
370
log.complain("Extra trailing bytes found in event packet at: "
371
+ eventPacket.offsetString());
372
success = false;
373
}
374
375
log.display(" ... event packet parsed");
376
}
377
378
/**
379
* Disconnect debuggee and wait for it exited.
380
*/
381
void quitDebugee() {
382
if (debugee == null)
383
return;
384
385
// disconnect debugee if not dead
386
if (!dead) {
387
try {
388
log.display("Disconnecting debuggee");
389
debugee.dispose();
390
log.display(" ... debuggee disconnected");
391
} catch (Failure e) {
392
log.display("Failed to finally disconnect debuggee:\n\t"
393
+ e.getMessage());
394
}
395
}
396
397
// wait for debugee exited
398
log.display("Waiting for debuggee exit");
399
int code = debugee.waitFor();
400
log.display(" ... debuggee exited with exit code: " + code);
401
402
// analize debugee exit status code
403
if (code != JCK_STATUS_BASE + PASSED) {
404
log.complain("Debuggee FAILED with exit code: " + code);
405
success = false;
406
}
407
}
408
409
}
410
411