Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Event/BREAKPOINT/breakpoint001.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.Event.BREAKPOINT;
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 event: BREAKPOINT.
34
*
35
* See breakpoint001.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 event is tested in the method waitForTestedEvent().
40
*
41
* @see #runIt()
42
* @see #waitForTestedEvent()
43
*/
44
public class breakpoint001 {
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
// package and classes names constants
52
static final String PACKAGE_NAME = "nsk.jdwp.Event.BREAKPOINT";
53
static final String TEST_CLASS_NAME = PACKAGE_NAME + "." + "breakpoint001";
54
static final String DEBUGEE_CLASS_NAME = TEST_CLASS_NAME + "a";
55
56
// tested JDWP event constants
57
static final byte TESTED_EVENT_KIND = JDWP.EventKind.BREAKPOINT;
58
static final byte TESTED_EVENT_SUSPEND_POLICY = JDWP.SuspendPolicy.ALL;
59
60
// name and signature of the tested class
61
static final String TESTED_CLASS_NAME = DEBUGEE_CLASS_NAME + "$" + "TestedClass";
62
static final String TESTED_CLASS_SIGNATURE = "L" + TESTED_CLASS_NAME.replace('.', '/') + ";";
63
static final String TESTED_THREAD_NAME = "TestedThread";
64
65
// name of field and method of tested class
66
static final String THREAD_FIELD_NAME = "thread";
67
static final String TESTED_METHOD_NAME = "run";
68
static final int BREAKPOINT_LINE = breakpoint001a.BREAKPOINT_LINE;
69
70
// usual scaffold objects
71
ArgumentHandler argumentHandler = null;
72
Log log = null;
73
Binder binder = null;
74
Debugee debugee = null;
75
Transport transport = null;
76
int waitTime = 0; // minutes
77
long timeout = 0; // milliseconds
78
boolean dead = false;
79
boolean success = true;
80
81
// obtained data
82
long testedClassID = 0;
83
long testedThreadID = 0;
84
long testedMethodID = 0;
85
JDWP.Location testedLocation = null;
86
int eventRequestID = 0;
87
88
// -------------------------------------------------------------------
89
90
/**
91
* Start test from command line.
92
*/
93
public static void main(String argv[]) {
94
System.exit(run(argv,System.out) + JCK_STATUS_BASE);
95
}
96
97
/**
98
* Start test from JCK-compilant environment.
99
*/
100
public static int run(String argv[], PrintStream out) {
101
return new breakpoint001().runIt(argv, out);
102
}
103
104
// -------------------------------------------------------------------
105
106
/**
107
* Perform test execution.
108
*/
109
public int runIt(String argv[], PrintStream out) {
110
111
// make log for debugger messages
112
argumentHandler = new ArgumentHandler(argv);
113
log = new Log(out, argumentHandler);
114
waitTime = argumentHandler.getWaitTime();
115
timeout = waitTime * 60 * 1000;
116
117
// execute test and display results
118
try {
119
log.display("\n>>> Starting debugee \n");
120
121
// launch debuggee
122
binder = new Binder(argumentHandler, log);
123
log.display("Launching debugee");
124
debugee = binder.bindToDebugee(DEBUGEE_CLASS_NAME);
125
transport = debugee.getTransport();
126
log.display(" ... debugee launched");
127
log.display("");
128
129
// set timeout for debuggee responces
130
log.display("Setting timeout for debuggee responces: " + waitTime + " minute(s)");
131
transport.setReadTimeout(timeout);
132
log.display(" ... timeout set");
133
134
// wait for debuggee started
135
log.display("Waiting for VM_INIT event");
136
debugee.waitForVMInit();
137
log.display(" ... VM_INIT event received");
138
139
// query debugee for VM-dependent ID sizes
140
log.display("Querying for IDSizes");
141
debugee.queryForIDSizes();
142
log.display(" ... size of VM-dependent types adjusted");
143
144
// get debuggee prepared for testing
145
log.display("\n>>> Getting prepared for testing \n");
146
prepareForTest();
147
148
// test JDWP event
149
log.display("\n>>> Testing JDWP event \n");
150
151
// request tested event
152
log.display("Making request for BREAKPOINT event at: "
153
+ TESTED_METHOD_NAME + ":" + BREAKPOINT_LINE);
154
requestTestedEvent();
155
log.display(" ... got requestID: " + eventRequestID);
156
log.display("");
157
158
// resume debuggee
159
log.display("Resumindg debuggee");
160
debugee.resume();
161
log.display(" ... debuggee resumed");
162
log.display("");
163
164
// wait for tested BREAKPOINT event
165
log.display("Waiting for BREAKPOINT event received");
166
waitForTestedEvent();
167
log.display(" ... event received");
168
log.display("");
169
170
// check if event is for expected thread
171
if (success) {
172
log.display("Checking thread of BREAKPOINT event");
173
checkThread();
174
log.display("");
175
}
176
177
178
// clear tested request for BREAKPOINT event
179
log.display("Clearing request for tested event");
180
clearTestedRequest();
181
log.display(" ... request removed");
182
183
// finish debuggee after testing
184
log.display("\n>>> Finishing debuggee \n");
185
186
// resume debuggee
187
log.display("Resuming debuggee");
188
debugee.resume();
189
log.display(" ... debuggee resumed");
190
191
// wait for debuggee exited
192
log.display("Waiting for VM_DEATH event");
193
debugee.waitForVMDeath();
194
dead = true;
195
log.display(" ... VM_DEATH event received");
196
197
} catch (Failure e) {
198
log.complain("TEST FAILED: " + e.getMessage());
199
success = false;
200
} catch (Exception e) {
201
e.printStackTrace(out);
202
log.complain("Caught unexpected exception while running the test:\n\t" + e);
203
success = false;
204
} finally {
205
// quit debugee
206
log.display("\n>>> Finishing test \n");
207
quitDebugee();
208
}
209
210
// check test results
211
if (!success) {
212
log.complain("TEST FAILED");
213
return FAILED;
214
}
215
216
out.println("TEST PASSED");
217
return PASSED;
218
219
}
220
221
/**
222
* Get debuggee prepared for testing and obtain required data.
223
*/
224
void prepareForTest() {
225
// wait for tested class loaded
226
log.display("Waiting for tested class loaded");
227
testedClassID = debugee.waitForClassLoaded(TESTED_CLASS_NAME, JDWP.SuspendPolicy.ALL);
228
log.display(" ... got classID: " + testedClassID);
229
log.display("");
230
231
// get methodID for tested method
232
log.display("Getting tested methodID by name: " + TESTED_METHOD_NAME);
233
testedMethodID = debugee.getMethodID(testedClassID, TESTED_METHOD_NAME, true);
234
log.display(" ... got methodID: " + testedMethodID);
235
236
// get codeIndex for breakpoint line
237
log.display("Getting codeIndex for breakpoint line: " + BREAKPOINT_LINE);
238
long codeIndex = debugee.getCodeIndex(testedClassID, testedMethodID, BREAKPOINT_LINE);
239
log.display(" ... got index: " + codeIndex);
240
241
// create location for breakpoint
242
log.display("Creating location for breakpoint request");
243
testedLocation = new JDWP.Location(JDWP.TypeTag.CLASS, testedClassID,
244
testedMethodID, codeIndex);
245
log.display(" ... got location: " + testedLocation);
246
}
247
248
/**
249
* Make request for tested BREAKPOINT event.
250
*/
251
void requestTestedEvent() {
252
Failure failure = new Failure("Error occured while makind request for tested event");
253
254
// create command packet and fill requred out data
255
log.display("Create command packet: " + "EventRequest.Set");
256
CommandPacket command = new CommandPacket(JDWP.Command.EventRequest.Set);
257
log.display(" eventKind: " + TESTED_EVENT_KIND);
258
command.addByte(TESTED_EVENT_KIND);
259
log.display(" eventPolicy: " + TESTED_EVENT_SUSPEND_POLICY);
260
command.addByte(TESTED_EVENT_SUSPEND_POLICY);
261
log.display(" modifiers: " + 1);
262
command.addInt(1);
263
log.display(" modKind: " + JDWP.EventModifierKind.LOCATION_ONLY);
264
command.addByte(JDWP.EventModifierKind.LOCATION_ONLY);
265
log.display(" location: " + testedLocation);
266
command.addLocation(testedLocation);
267
command.setLength();
268
log.display(" ... command packet composed");
269
log.display("");
270
271
// send command packet to debugee
272
try {
273
log.display("Sending command packet:\n" + command);
274
transport.write(command);
275
log.display(" ... command packet sent");
276
} catch (IOException e) {
277
log.complain("Unable to send command packet:\n\t" + e);
278
success = false;
279
throw failure;
280
}
281
log.display("");
282
283
// receive reply packet from debugee
284
ReplyPacket reply = new ReplyPacket();
285
try {
286
log.display("Waiting for reply packet");
287
transport.read(reply);
288
log.display(" ... packet received:\n" + reply);
289
} catch (IOException e) {
290
log.complain("Unable to read reply packet:\n\t" + e);
291
success = false;
292
throw failure;
293
}
294
log.display("");
295
296
// check reply packet header
297
try{
298
log.display("Checking header of reply packet");
299
reply.checkHeader(command.getPacketID());
300
log.display(" .. packet header is correct");
301
} catch (BoundException e) {
302
log.complain("Bad header of reply packet:\n\t" + e.getMessage());
303
success = false;
304
throw failure;
305
}
306
307
// start parsing reply packet data
308
log.display("Parsing reply packet:");
309
reply.resetPosition();
310
311
// extract requestID
312
int requestID = 0;
313
try {
314
requestID = reply.getInt();
315
log.display(" requestID: " + requestID);
316
} catch (BoundException e) {
317
log.complain("Unable to extract requestID from request reply packet:\n\t"
318
+ e.getMessage());
319
success = false;
320
throw failure;
321
}
322
323
// check requestID
324
if (requestID == 0) {
325
log.complain("Unexpected null requestID returned: " + requestID);
326
success = false;
327
throw failure;
328
}
329
330
eventRequestID = requestID;
331
332
// check for extra data in reply packet
333
if (!reply.isParsed()) {
334
log.complain("Extra trailing bytes found in request reply packet at: "
335
+ reply.offsetString());
336
success = false;
337
}
338
339
log.display(" ... reply packet parsed");
340
}
341
342
/**
343
* Clear request for tested BREAKPOINT event.
344
*/
345
void clearTestedRequest() {
346
Failure failure = new Failure("Error occured while clearing request for tested event");
347
348
// create command packet and fill requred out data
349
log.display("Create command packet: " + "EventRequest.Clear");
350
CommandPacket command = new CommandPacket(JDWP.Command.EventRequest.Clear);
351
log.display(" event: " + TESTED_EVENT_KIND);
352
command.addByte(TESTED_EVENT_KIND);
353
log.display(" requestID: " + eventRequestID);
354
command.addInt(eventRequestID);
355
log.display(" ... command packet composed");
356
log.display("");
357
358
// send command packet to debugee
359
try {
360
log.display("Sending command packet:\n" + command);
361
transport.write(command);
362
log.display(" ... command packet sent");
363
} catch (IOException e) {
364
log.complain("Unable to send command packet:\n\t" + e);
365
success = false;
366
throw failure;
367
}
368
log.display("");
369
370
ReplyPacket reply = new ReplyPacket();
371
372
// receive reply packet from debugee
373
try {
374
log.display("Waiting for reply packet");
375
transport.read(reply);
376
log.display(" ... packet received:\n" + reply);
377
} catch (IOException e) {
378
log.complain("Unable to read reply packet:\n\t" + e);
379
success = false;
380
throw failure;
381
}
382
383
// check reply packet header
384
try{
385
log.display("Checking header of reply packet");
386
reply.checkHeader(command.getPacketID());
387
log.display(" .. packet header is correct");
388
} catch (BoundException e) {
389
log.complain("Bad header of reply packet:\n\t" + e.getMessage());
390
success = false;
391
throw failure;
392
}
393
394
// start parsing reply packet data
395
log.display("Parsing reply packet:");
396
reply.resetPosition();
397
398
log.display(" no data");
399
400
// check for extra data in reply packet
401
if (!reply.isParsed()) {
402
log.complain("Extra trailing bytes found in request reply packet at: "
403
+ reply.offsetString());
404
success = false;
405
}
406
407
log.display(" ... reply packet parsed");
408
}
409
410
/**
411
* Wait for tested BREAKPOINT event.
412
*/
413
void waitForTestedEvent() {
414
415
EventPacket eventPacket = null;
416
417
// receive reply packet from debugee
418
try {
419
log.display("Waiting for event packet");
420
eventPacket = debugee.getEventPacket(timeout);
421
log.display(" ... event packet received:\n" + eventPacket);
422
} catch (IOException e) {
423
log.complain("Unable to read tested event packet:\n\t" + e);
424
success = false;
425
return;
426
}
427
log.display("");
428
429
// check reply packet header
430
try{
431
log.display("Checking header of event packet");
432
eventPacket.checkHeader();
433
log.display(" ... packet header is correct");
434
} catch (BoundException e) {
435
log.complain("Bad header of tested event packet:\n\t"
436
+ e.getMessage());
437
success = false;
438
return;
439
}
440
441
// start parsing reply packet data
442
log.display("Parsing event packet:");
443
eventPacket.resetPosition();
444
445
// get suspendPolicy value
446
byte suspendPolicy = 0;
447
try {
448
suspendPolicy = eventPacket.getByte();
449
log.display(" suspendPolicy: " + suspendPolicy);
450
} catch (BoundException e) {
451
log.complain("Unable to get suspendPolicy value from tested event packet:\n\t"
452
+ e.getMessage());
453
success = false;
454
return;
455
}
456
457
// check suspendPolicy value
458
if (suspendPolicy != TESTED_EVENT_SUSPEND_POLICY) {
459
log.complain("Unexpected SuspendPolicy in tested event packet: " +
460
suspendPolicy + " (expected: " + TESTED_EVENT_SUSPEND_POLICY + ")");
461
success = false;
462
}
463
464
// get events count
465
int events = 0;
466
try {
467
events = eventPacket.getInt();
468
log.display(" events: " + events);
469
} catch (BoundException e) {
470
log.complain("Unable to get events count from tested event packet:\n\t"
471
+ e.getMessage());
472
success = false;
473
return;
474
}
475
476
// check events count
477
if (events < 0) {
478
log.complain("Negative value of events number in tested event packet: " +
479
events + " (expected: " + 1 + ")");
480
success = false;
481
} else if (events != 1) {
482
log.complain("Invalid number of events in tested event packet: " +
483
events + " (expected: " + 1 + ")");
484
success = false;
485
}
486
487
// extract each event
488
long eventThreadID = 0;
489
for (int i = 0; i < events; i++) {
490
log.display(" event #" + i + ":");
491
492
// get eventKind
493
byte eventKind = 0;
494
try {
495
eventKind = eventPacket.getByte();
496
log.display(" eventKind: " + eventKind);
497
} catch (BoundException e) {
498
log.complain("Unable to get eventKind of event #" + i + " from tested event packet:\n\t"
499
+ e.getMessage());
500
success = false;
501
return;
502
}
503
504
// check eventKind
505
if (eventKind == JDWP.EventKind.VM_DEATH) {
506
log.complain("Unexpected VM_DEATH event received: " +
507
eventKind + " (expected: " + JDWP.EventKind.BREAKPOINT + ")");
508
dead = true;
509
success = false;
510
return;
511
} else if (eventKind != JDWP.EventKind.BREAKPOINT) {
512
log.complain("Unexpected eventKind of event " + i + " in tested event packet: " +
513
eventKind + " (expected: " + JDWP.EventKind.BREAKPOINT + ")");
514
success = false;
515
return;
516
}
517
518
// get requestID
519
int requestID = 0;
520
try {
521
requestID = eventPacket.getInt();
522
log.display(" requestID: " + requestID);
523
} catch (BoundException e) {
524
log.complain("Unable to get requestID of event #" + i + " from tested event packet:\n\t"
525
+ e.getMessage());
526
success = false;
527
return;
528
}
529
530
// check requestID
531
if (requestID != eventRequestID) {
532
log.complain("Unexpected requestID of event " + i + " in tested event packet: " +
533
requestID + " (expected: " + eventRequestID + ")");
534
success = false;
535
}
536
537
// get threadID
538
long threadID = 0;
539
try {
540
threadID = eventPacket.getObjectID();
541
log.display(" threadID: " + threadID);
542
} catch (BoundException e) {
543
log.complain("Unable to get threadID of event #" + i + " from tested event packet:\n\t"
544
+ e.getMessage());
545
success = false;
546
return;
547
}
548
549
// save threadID for further checking
550
testedThreadID = threadID;
551
552
// get location
553
JDWP.Location location = null;
554
try {
555
location = eventPacket.getLocation();
556
log.display(" location: " + location);
557
} catch (BoundException e) {
558
log.complain("Unable to get location of event #" + i + " from tested event packet:\n\t"
559
+ e.getMessage());
560
success = false;
561
return;
562
}
563
564
// check location
565
if (location.getTag() != testedLocation.getTag()) {
566
log.complain("Unexpected class tag of location of event " + i
567
+ " in tested event packet: " + location.getTag()
568
+ " (expected: " + testedLocation.getTag() + ")");
569
success = false;
570
}
571
if (location.getClassID() != testedLocation.getClassID()) {
572
log.complain("Unexpected classID of location of event " + i
573
+ " in tested event packet: " + location.getClassID()
574
+ " (expected: " + testedLocation.getClassID() + ")");
575
success = false;
576
}
577
if (location.getMethodID() != testedLocation.getMethodID()) {
578
log.complain("Unexpected methodID of location of event " + i
579
+ " in tested event packet: " + location.getMethodID()
580
+ " (expected: " + testedLocation.getMethodID() + ")");
581
success = false;
582
}
583
if (location.getIndex() != testedLocation.getIndex()) {
584
log.complain("Unexpected codeIndex of location of event " + i
585
+ " in tested event packet: " + location.getIndex()
586
+ " (expected: " + testedLocation.getIndex() + ")");
587
success = false;
588
}
589
}
590
591
// check for extra data in event packet
592
if (!eventPacket.isParsed()) {
593
log.complain("Extra trailing bytes found in event packet at: "
594
+ eventPacket.offsetString());
595
success = false;
596
}
597
598
log.display(" ... event packet parsed");
599
}
600
601
/**
602
* Check if threadID received by BREAKPOINT event is as expected one.
603
*/
604
void checkThread() {
605
// get thread value from static field of tested class
606
log.display("Getting thread value from static field: " + THREAD_FIELD_NAME);
607
JDWP.Value value = debugee.getStaticFieldValue(testedClassID, THREAD_FIELD_NAME,
608
JDWP.Tag.THREAD);
609
long threadID = ((Long)value.getValue()).longValue();
610
log.display(" ... got threadID: " + testedThreadID);
611
612
// check threadID
613
if (threadID != testedThreadID) {
614
log.complain("Unexpected threadID of BREAKPOINT event received: " +
615
testedThreadID + " (expected: " + threadID + ")");
616
success = false;
617
} else {
618
log.display("Received threadID is as expected");
619
}
620
}
621
622
/**
623
* Disconnect debuggee and wait for it exited.
624
*/
625
void quitDebugee() {
626
if (debugee == null)
627
return;
628
629
// disconnect debugee
630
if (!dead) {
631
try {
632
log.display("Disconnecting debuggee");
633
debugee.dispose();
634
log.display(" ... debuggee disconnected");
635
} catch (Failure e) {
636
log.display("Failed to finally disconnect debuggee:\n\t"
637
+ e.getMessage());
638
}
639
}
640
641
// wait for debugee exited
642
log.display("Waiting for debuggee exit");
643
int code = debugee.waitFor();
644
log.display(" ... debuggee exited with exit code: " + code);
645
646
// analize debugee exit status code
647
if (code != JCK_STATUS_BASE + PASSED) {
648
log.complain("Debuggee FAILED with exit code: " + code);
649
success = false;
650
}
651
}
652
653
}
654
655