Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/LocatableEvent/thread/thread001.java
41161 views
1
/*
2
* Copyright (c) 2001, 2020, 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.jdi.LocatableEvent.thread;
25
26
import nsk.share.*;
27
import nsk.share.jpda.*;
28
import nsk.share.jdi.*;
29
30
import com.sun.jdi.*;
31
import com.sun.jdi.event.*;
32
import com.sun.jdi.request.*;
33
34
import java.util.*;
35
import java.io.*;
36
37
/**
38
* The test for the implementation of an object of the type <BR>
39
* LocatableEvent. <BR>
40
* <BR>
41
* The test checks that results of the method <BR>
42
* <code>com.sun.jdi.LocatableEvent.thread()</code> <BR>
43
* complies with its spec. <BR>
44
* <BR>
45
* The cases for testing include all Locatable events. <BR>
46
* The test checks that <BR>
47
* for each type of LocatableEvent received in a debugger, <BR>
48
* a value returned by the method invoked on <BR>
49
* a <type>Event object corresponds to a thread <BR>
50
* which debuggee's counterpart event was generated in. <BR>
51
* <BR>
52
* The test has three phases and works as follows. <BR>
53
* <BR>
54
* In first phase, <BR>
55
* upon launching debuggee's VM which will be suspended, <BR>
56
* a debugger waits for the VMStartEvent within a predefined <BR>
57
* time interval. If no the VMStartEvent received, the test is FAILED. <BR>
58
* Upon getting the VMStartEvent, it makes the request for debuggee's <BR>
59
* ClassPrepareEvent with SUSPEND_EVENT_THREAD, resumes the VM, <BR>
60
* and waits for the event within the predefined time interval. <BR>
61
* If no the ClassPrepareEvent received, the test is FAILED. <BR>
62
* Upon getting the ClassPrepareEvent, <BR>
63
* the debugger sets up the breakpoint with SUSPEND_EVENT_THREAD <BR>
64
* within debuggee's special methodForCommunication(). <BR>
65
* <BR>
66
* In second phase to check Locatable events, <BR>
67
* the debugger and the debuggee perform the following. <BR>
68
* - The debugger resumes the debuggee and waits for the BreakpointEvent.<BR>
69
* - The debuggee creates a number of threads, one for each check case <BR>
70
* and invokes the methodForCommunication to be suspended and <BR>
71
* to inform the debugger with the event. <BR>
72
* - Upon getting the BreakpointEvent, the debugger <BR>
73
* gets ThreadReferences mirroring all tested threads in the debuggee,<BR>
74
* sets up Requests within them to get Events to check up on, <BR>
75
* resumes the debuggee, waits for events, and upon getting them, <BR>
76
* compares ThreadReferences put into Requests to ones from Events; <BR>
77
* if any mismatch, the test FAILED. <BR>
78
* <BR>
79
* Note. To inform each other of needed actions, the debugger and <BR>
80
* and the debuggee use debuggeee's variable "instruction". <BR>
81
* <BR>
82
* In third phase when at the end, <BR>
83
* the debuggee changes the value of the "instruction" <BR>
84
* to inform the debugger of checks finished, and both end. <BR>
85
* <BR>
86
*/
87
88
public class thread001 extends JDIBase {
89
90
public static void main (String argv[]) {
91
92
int result = run(argv, System.out);
93
94
System.exit(result + PASS_BASE);
95
}
96
97
public static int run (String argv[], PrintStream out) {
98
99
int exitCode = new thread001().runThis(argv, out);
100
101
if (exitCode != PASSED) {
102
System.out.println("TEST FAILED");
103
}
104
return testExitCode;
105
}
106
107
// ************************************************ test parameters
108
109
private String debuggeeName =
110
"nsk.jdi.LocatableEvent.thread.thread001a";
111
112
private String testedClassName =
113
"nsk.jdi.LocatableEvent.thread.TestClass";
114
115
//====================================================== test program
116
117
private int runThis (String argv[], PrintStream out) {
118
119
argsHandler = new ArgumentHandler(argv);
120
logHandler = new Log(out, argsHandler);
121
Binder binder = new Binder(argsHandler, logHandler);
122
123
waitTime = argsHandler.getWaitTime() * 60000;
124
125
try {
126
log2("launching a debuggee :");
127
log2(" " + debuggeeName);
128
if (argsHandler.verbose()) {
129
debuggee = binder.bindToDebugee(debuggeeName + " -vbs");
130
} else {
131
debuggee = binder.bindToDebugee(debuggeeName);
132
}
133
if (debuggee == null) {
134
log3("ERROR: no debuggee launched");
135
return FAILED;
136
}
137
log2("debuggee launched");
138
} catch ( Exception e ) {
139
log3("ERROR: Exception : " + e);
140
log2(" test cancelled");
141
return FAILED;
142
}
143
144
debuggee.redirectOutput(logHandler);
145
146
vm = debuggee.VM();
147
148
eventQueue = vm.eventQueue();
149
if (eventQueue == null) {
150
log3("ERROR: eventQueue == null : TEST ABORTED");
151
vm.exit(PASS_BASE);
152
return FAILED;
153
}
154
155
log2("invocation of the method runTest()");
156
switch (runTest()) {
157
158
case 0 : log2("test phase has finished normally");
159
log2(" waiting for the debuggee to finish ...");
160
debuggee.waitFor();
161
162
log2("......getting the debuggee's exit status");
163
int status = debuggee.getStatus();
164
if (status != PASS_BASE) {
165
log3("ERROR: debuggee returned UNEXPECTED exit status: " +
166
status + " != PASS_BASE");
167
testExitCode = FAILED;
168
} else {
169
log2("......debuggee returned expected exit status: " +
170
status + " == PASS_BASE");
171
}
172
break;
173
174
default : log3("ERROR: runTest() returned unexpected value");
175
176
case 1 : log3("test phase has not finished normally: debuggee is still alive");
177
log2("......forcing: vm.exit();");
178
testExitCode = FAILED;
179
try {
180
vm.exit(PASS_BASE);
181
} catch ( Exception e ) {
182
log3("ERROR: Exception : e");
183
}
184
break;
185
186
case 2 : log3("test cancelled due to VMDisconnectedException");
187
log2("......trying: vm.process().destroy();");
188
testExitCode = FAILED;
189
try {
190
Process vmProcess = vm.process();
191
if (vmProcess != null) {
192
vmProcess.destroy();
193
}
194
} catch ( Exception e ) {
195
log3("ERROR: Exception : e");
196
}
197
break;
198
}
199
200
return testExitCode;
201
}
202
203
204
/*
205
* Return value: 0 - normal end of the test
206
* 1 - ubnormal end of the test
207
* 2 - VMDisconnectedException while test phase
208
*/
209
210
private int runTest() {
211
212
try {
213
testRun();
214
215
log2("waiting for VMDeathEvent");
216
getEventSet();
217
if (eventIterator.nextEvent() instanceof VMDeathEvent)
218
return 0;
219
220
log3("ERROR: last event is not the VMDeathEvent");
221
return 1;
222
} catch ( VMDisconnectedException e ) {
223
log3("ERROR: VMDisconnectedException : " + e);
224
return 2;
225
} catch ( Exception e ) {
226
log3("ERROR: Exception : " + e);
227
return 1;
228
}
229
230
}
231
232
private void testRun()
233
throws JDITestRuntimeException, Exception {
234
235
eventRManager = vm.eventRequestManager();
236
237
ClassPrepareRequest cpRequest = eventRManager.createClassPrepareRequest();
238
cpRequest.setSuspendPolicy( EventRequest.SUSPEND_EVENT_THREAD);
239
cpRequest.addClassFilter(debuggeeName);
240
241
cpRequest.enable();
242
vm.resume();
243
getEventSet();
244
cpRequest.disable();
245
246
ClassPrepareEvent event = (ClassPrepareEvent) eventIterator.next();
247
debuggeeClass = event.referenceType();
248
249
if (!debuggeeClass.name().equals(debuggeeName))
250
throw new JDITestRuntimeException("** Unexpected ClassName for ClassPrepareEvent **");
251
252
log2(" received: ClassPrepareEvent for debuggeeClass");
253
254
String bPointMethod = "methodForCommunication";
255
String lineForComm = "lineForComm";
256
BreakpointRequest bpRequest;
257
258
bpRequest = settingBreakpoint(debuggee.threadByNameOrThrow("main"),
259
debuggeeClass,
260
bPointMethod, lineForComm, "zero");
261
bpRequest.enable();
262
263
//------------------------------------------------------ testing section
264
265
log1(" TESTING BEGINS");
266
267
for (int i = 0; ; i++) {
268
269
vm.resume();
270
breakpointForCommunication();
271
272
int instruction = ((IntegerValue)
273
(debuggeeClass.getValue(debuggeeClass.fieldByName("instruction")))).value();
274
275
if (instruction == 0) {
276
vm.resume();
277
break;
278
}
279
280
log1(":::::: case: # " + i);
281
282
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ variable part
283
284
String accWatchpointName = "var1";
285
String modWatchpointName = "var2";
286
String bpLineName = "breakpointLine";
287
String bpMethodName = "method";
288
String awFieldName = "awFieldName";
289
String mwFieldName = "mwFieldName";
290
String excName = "method";
291
String menName = "method";
292
String mexName = "method";
293
294
String namesArray = "threadNames";
295
296
String threadNames[] = {
297
"awThread" ,
298
"mwThread" ,
299
"bpThread" ,
300
"excThread" ,
301
"menThread" ,
302
"mexThread" ,
303
"stThread"
304
};
305
306
307
EventRequest eRequests[] = new EventRequest[threadNames.length];
308
int flags = 0;
309
310
ThreadReference eventThreads[] = new ThreadReference[threadNames.length];
311
312
313
List allThreads = vm.allThreads();
314
315
log2("......getting: ArrayReference namesRef = (ArrayReference) debuggeeClass.getValue(debuggeeClass.fieldByName(namesArray));");
316
ArrayReference namesRef = (ArrayReference)
317
debuggeeClass.getValue(debuggeeClass.fieldByName(namesArray));
318
log2(" namesRef.length() == " + namesRef.length());
319
320
log2("......getting and chcking up on debuggee threads' names");
321
for (int n1 = 0; n1 < namesRef.length(); n1++) {
322
323
log2(" String name = ((StringReference) namesRef.getValue(n1)).value();");
324
String name = ((StringReference) namesRef.getValue(n1)).value();
325
326
label0: {
327
for (int n2 = 0; n2 < threadNames.length; n2++) {
328
329
if (name.equals(threadNames[n2])) {
330
ListIterator li = allThreads.listIterator();
331
for (; li.hasNext(); ) {
332
ThreadReference thread = (ThreadReference) li.next();
333
if (thread.name().equals(name)) {
334
eventThreads[n1] = thread;
335
break;
336
}
337
}
338
break label0;
339
}
340
}
341
testExitCode = FAILED;
342
log3("ERROR: no thread found in the debuggee : " + name);
343
}
344
}
345
if (testExitCode == FAILED)
346
break;
347
348
349
log2("......ReferenceType testClass = (ReferenceType) (vm.classesByName(testedClassName)).get(0);");
350
ReferenceType testClass = (ReferenceType) (vm.classesByName(testedClassName)).get(0);
351
352
log2("......setting up Requests");
353
for ( int n3 = 0; n3 < namesRef.length(); n3++) {
354
switch (n3) {
355
case 0:
356
if (vm.canWatchFieldAccess()) {
357
String awName = ( (StringReference) testClass.getValue(
358
testClass.fieldByName(awFieldName))).value();
359
eRequests[n3] = settingAccessWatchpoint(eventThreads[n3],
360
testClass, awName, threadNames[n3]);
361
eRequests[n3].enable();
362
flags |= 1;
363
}
364
break;
365
366
case 1:
367
if (vm.canWatchFieldModification() ) {
368
String mwName = ( (StringReference) testClass.getValue(
369
testClass.fieldByName(mwFieldName))).value();
370
eRequests[n3] = settingModificationWatchpoint(eventThreads[n3],
371
testClass, mwName, threadNames[n3]);
372
eRequests[n3].enable();
373
flags |= 1<<1;
374
}
375
break;
376
377
case 2:
378
eRequests[n3] = settingBreakpoint(eventThreads[n3], testClass,
379
bpMethodName, bpLineName, threadNames[n3]);
380
eRequests[n3].setSuspendPolicy( EventRequest.SUSPEND_NONE);
381
eRequests[n3].enable();
382
flags |= 1<<2;
383
break;
384
385
case 3:
386
eRequests[n3] = settingException(eventThreads[n3], debuggeeClass, //testClass,
387
threadNames[n3]);
388
eRequests[n3].enable();
389
flags |= 1<<3;
390
break;
391
392
case 4:
393
eRequests[n3] = settingMethodEntry(eventThreads[n3], testClass,
394
threadNames[n3]);
395
eRequests[n3].enable();
396
flags |= 1<<4;
397
break;
398
399
case 5:
400
eRequests[n3] = settingMethodExit(eventThreads[n3], testClass,
401
threadNames[n3]);
402
eRequests[n3].enable();
403
flags |= 1<<5;
404
break;
405
406
case 6:
407
eRequests[n3] = settingStep(eventThreads[n3], threadNames[n3]);
408
eRequests[n3].enable();
409
flags |= 1<<6;
410
break;
411
412
default:
413
throw new JDITestRuntimeException("** default case while prepareing requests**");
414
}
415
}
416
417
log2(":::::::::vm.resume();");
418
vm.resume();
419
420
Event event1 = null;
421
String threadName = null;
422
int flagsCopy = flags;
423
String eName = null;
424
425
log2("......getting and checking up on Events");
426
for (int n4 = 0; n4 < namesRef.length(); n4++) {
427
int flag;
428
int index;
429
getEventSet();
430
event1 = eventIterator.nextEvent();
431
432
if (event1 instanceof AccessWatchpointEvent) {
433
eName = "AccessWatchpointEvent";
434
index = 0;
435
} else if (event1 instanceof ModificationWatchpointEvent ) {
436
eName = "ModificationWatchpointEvent";
437
index = 1;
438
} else if (event1 instanceof BreakpointEvent ) {
439
eName = "BreakpointEvent";
440
index = 2;
441
} else if (event1 instanceof ExceptionEvent ) {
442
eName = "ExceptionEvent";
443
index = 3;
444
} else if (event1 instanceof MethodEntryEvent ) {
445
eName = "MethodEntryEvent";
446
index = 4;
447
} else if (event1 instanceof MethodExitEvent ) {
448
eName = "MethodExitEvent";
449
index = 5;
450
} else if (event1 instanceof StepEvent ) {
451
eName = "StepEvent";
452
index = 6;
453
} else {
454
log3("ERROR: else clause in detecting type of event1");
455
testExitCode = FAILED;
456
throw new JDITestRuntimeException("** unexpected event **");
457
}
458
log2("--------> got: " + eName);
459
460
ThreadReference threadRef = ((LocatableEvent) event1).thread();
461
462
label0: {
463
for (int n5 = 0; n5 < namesRef.length(); n5++) {
464
if (threadRef.equals(eventThreads[n5])) {
465
eventThreads[n5] = null;
466
threadName = threadNames[index];
467
break label0;
468
}
469
}
470
testExitCode = FAILED;
471
log3("ERROR: event's thread is not equal to any tested");
472
log3(" thread's name == " + threadRef.name());
473
}
474
475
flag = 1 << index;
476
if ((flagsCopy & flag) == 0) {
477
log3("ERROR: event duplication: " + eName);
478
testExitCode = FAILED;
479
} else {
480
flagsCopy ^= flag;
481
flags |= flag;
482
}
483
}
484
485
breakpointForCommunication();
486
487
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
488
}
489
log1(" TESTING ENDS");
490
return;
491
}
492
493
// ============================== test's additional methods
494
495
private AccessWatchpointRequest settingAccessWatchpoint (
496
ThreadReference thread,
497
ReferenceType testedClass,
498
String fieldName,
499
String property)
500
throws JDITestRuntimeException {
501
502
log2("......setting up AccessWatchpoint:");
503
log2(" thread: " + thread + "; class: " + testedClass +
504
"; fieldName: " + fieldName);
505
506
AccessWatchpointRequest awRequest = null;
507
try {
508
Field field = testedClass.fieldByName(fieldName);
509
awRequest = eventRManager.createAccessWatchpointRequest(field);
510
awRequest.putProperty("number", property);
511
awRequest.addThreadFilter(thread);
512
awRequest.setSuspendPolicy( EventRequest.SUSPEND_NONE);
513
} catch ( Exception e ) {
514
log3("ERROR: ATTENTION: Exception within settingAccessWatchpoint() : " + e);
515
log3(" AN ACCESSWATCHPOINT HAS NOT BEEN SET UP");
516
throw new JDITestRuntimeException("** FAILURE to set up an AccessWatchpoint **");
517
}
518
519
log2(" an AccessWatchpoint has been set up");
520
return awRequest;
521
}
522
523
private ModificationWatchpointRequest settingModificationWatchpoint (
524
ThreadReference thread,
525
ReferenceType testedClass,
526
String fieldName,
527
String property)
528
throws JDITestRuntimeException {
529
530
log2("......setting up ModificationWatchpoint:");
531
log2(" thread: " + thread + "; class: " + testedClass +
532
"; fieldName: " + fieldName);
533
534
ModificationWatchpointRequest mwRequest = null;
535
try {
536
Field field = testedClass.fieldByName(fieldName);
537
mwRequest = eventRManager.createModificationWatchpointRequest(field);
538
mwRequest.putProperty("number", property);
539
mwRequest.addThreadFilter(thread);
540
mwRequest.setSuspendPolicy( EventRequest.SUSPEND_NONE);
541
} catch ( Exception e ) {
542
log3("ERROR: ATTENTION: Exception within settingModificationWatchpoint() : " + e);
543
log3(" AN ModificationWATCHPOINT HAS NOT BEEN SET UP");
544
throw new JDITestRuntimeException("** FAILURE to set up an AccessWatchpoint **");
545
}
546
547
log2(" a ModificationWatchpoint has been set up");
548
return mwRequest;
549
}
550
551
private MethodEntryRequest settingMethodEntry ( ThreadReference thread,
552
ReferenceType testedClass,
553
String property)
554
throws JDITestRuntimeException {
555
556
log2("......setting up MethodEntry:");
557
log2(" thread: " + thread + "; class: " + testedClass +
558
"; property: " + property);
559
560
MethodEntryRequest menRequest = null;
561
try {
562
menRequest = eventRManager.createMethodEntryRequest();
563
menRequest.putProperty("number", property);
564
menRequest.addThreadFilter(thread);
565
menRequest.addClassFilter(testedClass);
566
menRequest.setSuspendPolicy( EventRequest.SUSPEND_NONE);
567
} catch ( Exception e ) {
568
log3("ERROR: ATTENTION: Exception within settingMethodEntry() : " + e);
569
log3(" A MethodEntry HAS NOT BEEN SET UP");
570
throw new JDITestRuntimeException("** FAILURE to set up a MethodEntry **");
571
}
572
573
log2(" a MethodEntry has been set up");
574
return menRequest;
575
}
576
577
private MethodExitRequest settingMethodExit ( ThreadReference thread,
578
ReferenceType testedClass,
579
String property)
580
throws JDITestRuntimeException {
581
582
log2("......setting up MethodExit:");
583
log2(" thread: " + thread + "; class: " + testedClass +
584
"; property: " + property);
585
586
MethodExitRequest mexRequest = null;
587
try {
588
mexRequest = eventRManager.createMethodExitRequest();
589
mexRequest.putProperty("number", property);
590
mexRequest.addThreadFilter(thread);
591
mexRequest.addClassFilter(testedClass);
592
mexRequest.setSuspendPolicy( EventRequest.SUSPEND_NONE);
593
} catch ( Exception e ) {
594
log3("ERROR: ATTENTION: Exception within settingMethodExit() : " + e);
595
log3(" A MethodExit HAS NOT BEEN SET UP");
596
throw new JDITestRuntimeException("** FAILURE to set up a MethodExit **");
597
}
598
599
log2(" a MethodExit has been set up");
600
return mexRequest;
601
}
602
603
private StepRequest settingStep ( ThreadReference thread, String property)
604
throws JDITestRuntimeException {
605
606
log2("......setting up Step:");
607
log2(" thread: " + thread + "; property: " + property);
608
609
StepRequest stRequest = null;
610
try {
611
stRequest = eventRManager.createStepRequest(thread, StepRequest.STEP_LINE, StepRequest.STEP_OVER);
612
stRequest.putProperty("number", property);
613
stRequest.addCountFilter(1);
614
stRequest.setSuspendPolicy( EventRequest.SUSPEND_NONE);
615
} catch ( Exception e ) {
616
log3("ERROR: ATTENTION: Exception within settingStep() : " + e);
617
log3(" A Step HAS NOT BEEN SET UP");
618
throw new JDITestRuntimeException("** FAILURE to set up a Step **");
619
}
620
621
log2(" a Step has been set up");
622
return stRequest;
623
}
624
625
626
private ExceptionRequest settingException ( ThreadReference thread,
627
ReferenceType testedClass,
628
String property)
629
throws JDITestRuntimeException {
630
631
log2("......setting up Exception:");
632
log2(" thread: " + thread + "; class: " + testedClass +
633
"; property: " + property);
634
635
ExceptionRequest excRequest = null;
636
try {
637
excRequest = eventRManager.createExceptionRequest(null, true, true);
638
excRequest.putProperty("number", property);
639
excRequest.addThreadFilter(thread);
640
excRequest.addClassFilter(testedClass);
641
excRequest.setSuspendPolicy( EventRequest.SUSPEND_NONE);
642
} catch ( Exception e ) {
643
log3("ERROR: ATTENTION: Exception within settingException() : " + e);
644
log3(" A Exception HAS NOT BEEN SET UP");
645
throw new JDITestRuntimeException("** FAILURE to set up a Exception **");
646
}
647
648
log2(" a Exception has been set up");
649
return excRequest;
650
}
651
652
}
653
654