Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/Locatable/location/location005.java
41161 views
1
/*
2
* Copyright (c) 2001, 2019, 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.Locatable.location;
25
26
import nsk.share.*;
27
import nsk.share.jpda.*;
28
import nsk.share.jdi.*;
29
30
import com.sun.jdi.*;
31
import java.util.*;
32
import java.io.*;
33
34
import com.sun.jdi.event.*;
35
import com.sun.jdi.request.*;
36
37
/**
38
* The test for the implementation of an object of the type <BR>
39
* Locatable. <BR>
40
* <BR>
41
* The test checks up that results of the method <BR>
42
* <code>com.sun.jdi.Locatable.location()</code> <BR>
43
* complies with its spec when applied to an instance method. <BR>
44
* <BR>
45
* The cases for testing are as follows. <BR>
46
* 1) After getting a thread suspended but before to resume it, <BR>
47
* StackFrame.location() is invoked and its returned value <BR>
48
* must not be null. <BR>
49
* Since the thread is not resumed yet, <BR>
50
* InvalidStackFrameException must not be throw. <BR>
51
* 2) After resuming the thread, the tested method is invoked <BR>
52
* second time and InvalidStackFrameException must be thrown.<BR>
53
* <BR>
54
*/
55
56
public class location005 {
57
58
//----------------------------------------------------- templete section
59
static final int PASSED = 0;
60
static final int FAILED = 2;
61
static final int PASS_BASE = 95;
62
63
//----------------------------------------------------- templete parameters
64
static final String
65
sHeader1 = "\n==> nsk/jdi/Locatable/location/location005 ",
66
sHeader2 = "--> debugger: ",
67
sHeader3 = "##> debugger: ";
68
69
//----------------------------------------------------- main method
70
71
public static void main (String argv[]) {
72
int result = run(argv, System.out);
73
System.exit(result + PASS_BASE);
74
}
75
76
public static int run (String argv[], PrintStream out) {
77
return new location005().runThis(argv, out);
78
}
79
80
//-------------------------------------------------- log procedures
81
82
//private static boolean verbMode = false;
83
84
private static Log logHandler;
85
86
private static void log1(String message) {
87
logHandler.display(sHeader1 + message);
88
}
89
private static void log2(String message) {
90
logHandler.display(sHeader2 + message);
91
}
92
private static void log3(String message) {
93
logHandler.complain(sHeader3 + message);
94
}
95
96
// ************************************************ test parameters
97
98
private String debuggeeName =
99
"nsk.jdi.Locatable.location.location005a";
100
101
private String testedClassName =
102
"nsk.jdi.Locatable.location.Threadlocation005a";
103
104
String mName = "nsk.jdi.Locatable.location";
105
106
//====================================================== test program
107
//------------------------------------------------------ common section
108
static ArgumentHandler argsHandler;
109
110
static int waitTime;
111
112
static VirtualMachine vm = null;
113
static EventRequestManager eventRManager = null;
114
static EventQueue eventQueue = null;
115
static EventSet eventSet = null;
116
117
ReferenceType testedclass = null;
118
ThreadReference thread2 = null;
119
ThreadReference mainThread = null;
120
121
static int testExitCode = PASSED;
122
123
static final int returnCode0 = 0;
124
static final int returnCode1 = 1;
125
static final int returnCode2 = 2;
126
static final int returnCode3 = 3;
127
static final int returnCode4 = 4;
128
129
//------------------------------------------------------ methods
130
131
private int runThis (String argv[], PrintStream out) {
132
133
Debugee debuggee;
134
135
argsHandler = new ArgumentHandler(argv);
136
logHandler = new Log(out, argsHandler);
137
Binder binder = new Binder(argsHandler, logHandler);
138
139
if (argsHandler.verbose()) {
140
debuggee = binder.bindToDebugee(debuggeeName + " -vbs"); // *** tp
141
} else {
142
debuggee = binder.bindToDebugee(debuggeeName); // *** tp
143
}
144
145
waitTime = argsHandler.getWaitTime();
146
147
148
IOPipe pipe = new IOPipe(debuggee);
149
150
debuggee.redirectStderr(out);
151
log2(debuggeeName + " debuggee launched");
152
debuggee.resume();
153
154
String line = pipe.readln();
155
if ((line == null) || !line.equals("ready")) {
156
log3("signal received is not 'ready' but: " + line);
157
return FAILED;
158
} else {
159
log2("'ready' recieved");
160
}
161
162
VirtualMachine vm = debuggee.VM();
163
164
//------------------------------------------------------ testing section
165
log1(" TESTING BEGINS");
166
167
for (int i = 0; ; i++) {
168
pipe.println("newcheck");
169
line = pipe.readln();
170
171
if (line.equals("checkend")) {
172
log2(" : returned string is 'checkend'");
173
break ;
174
} else if (!line.equals("checkready")) {
175
log3("ERROR: returned string is not 'checkready'");
176
testExitCode = FAILED;
177
break ;
178
}
179
180
log1("new check: #" + i);
181
182
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ variable part
183
184
int expresult = returnCode0;
185
186
eventRManager = vm.eventRequestManager();
187
eventQueue = vm.eventQueue();
188
189
String threadName = "Thread2";
190
String breakpointMethod = "runt1";
191
String bpLine1 = "breakpointLineNumber1";
192
String breakpointMethod1 = "runt1";
193
194
BreakpointRequest breakpRequest1 = null;
195
196
List allThreads = null;
197
ListIterator listIterator = null;
198
List classes = null;
199
200
StackFrame stackFrame = null;
201
202
203
label0: {
204
205
log2("getting ThreadReference object");
206
try {
207
allThreads = vm.allThreads();
208
classes = vm.classesByName(testedClassName);
209
testedclass = (ReferenceType) classes.get(0);
210
} catch ( Exception e) {
211
log3("ERROR: Exception at very beginning !? : " + e);
212
expresult = returnCode1;
213
break label0;
214
}
215
216
listIterator = allThreads.listIterator();
217
for (;;) {
218
try {
219
thread2 = (ThreadReference) listIterator.next();
220
if (thread2.name().equals(threadName))
221
break ;
222
} catch ( NoSuchElementException e ) {
223
log3("ERROR: NoSuchElementException for listIterator.next()");
224
log3("ERROR: NO THREAD2 ?????????!!!!!!!");
225
expresult = returnCode1;
226
break label0;
227
}
228
}
229
230
log2("setting up breakpoint");
231
232
breakpRequest1 = settingBreakpoint(breakpointMethod1, bpLine1, "one");
233
if (breakpRequest1 == null) {
234
expresult = returnCode1;
235
break label0;
236
}
237
238
}
239
240
label1: {
241
242
if (expresult != returnCode0)
243
break label1;
244
245
log2(" enabling breakpRequest1");
246
breakpRequest1.enable();
247
248
log2(" forcing the main thread to leave synchronized block");
249
pipe.println("continue");
250
line = pipe.readln();
251
if (!line.equals("docontinue")) {
252
log3("ERROR: returned string is not 'docontinue'");
253
expresult = returnCode4;
254
break label1;
255
}
256
257
expresult = breakpoint();
258
if (expresult != returnCode0)
259
break label1;
260
261
262
log2(" stackFrame = thread2.frame(0);");
263
try {
264
stackFrame = thread2.frame(0);
265
} catch ( Exception e ) {
266
log3("ERROR: Exception: " + e);
267
expresult = returnCode1;
268
break label1;
269
}
270
271
272
Location stackLocation = null;
273
274
log2(" checking up: no InvalidStackFrameException when the thread2 is suspended");
275
try {
276
log2(" before: stackLocation = stackFrame.location();");
277
stackLocation = stackFrame.location();
278
if (stackLocation == null) {
279
log3("ERROR: stackLocation == null");
280
expresult = returnCode1;
281
}
282
} catch ( InvalidStackFrameException e ) {
283
log2("ERROR: InvalidStackFrameExceprtion");
284
}
285
286
log2(" resuming the thread2");
287
eventSet.resume();
288
289
if (expresult == returnCode1)
290
break label1;
291
292
log2(" checking up InvalidStackFrameException after resuming the thread2");
293
try {
294
log2(" before: stackLocation = stackFrame.location();");
295
stackLocation = stackFrame.location();
296
expresult = returnCode1;
297
log3("ERROR: no InvalidStackFrameExceprtion");
298
} catch ( InvalidStackFrameException e ) {
299
log2(" : InvalidStackFrameExceprtion");
300
}
301
}
302
303
log2(" resuming the thread2 for case it was suspended but not resumed yet");
304
eventSet.resume();
305
306
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
307
log2(" the end of testing");
308
if (expresult != returnCode0)
309
testExitCode = FAILED;
310
}
311
log1(" TESTING ENDS");
312
313
//-------------------------------------------------- test summary section
314
//------------------------------------------------- standard end section
315
316
pipe.println("quit");
317
log2("waiting for the debuggee to finish ...");
318
debuggee.waitFor();
319
320
int status = debuggee.getStatus();
321
if (status != PASSED + PASS_BASE) {
322
log3("debuggee returned UNEXPECTED exit status: " +
323
status + " != PASS_BASE");
324
testExitCode = FAILED;
325
} else {
326
log2("debuggee returned expected exit status: " +
327
status + " == PASS_BASE");
328
}
329
330
if (testExitCode != PASSED) {
331
logHandler.complain("TEST FAILED");
332
}
333
return testExitCode;
334
}
335
336
337
/*
338
* private BreakpointRequest settingBreakpoint(String, String, String)
339
*
340
* It sets up a breakpoint within a given method at given line number
341
* for the thread2 only.
342
* Third parameter is required for any case in future debugging, as if.
343
*
344
* Return codes:
345
* = BreakpointRequest object in case of success
346
* = null in case of an Exception thrown within the method
347
*/
348
349
private BreakpointRequest settingBreakpoint ( String methodName,
350
String bpLine,
351
String property) {
352
353
log2("setting up a breakpoint: method: '" + methodName + "' line: " + bpLine );
354
355
List alllineLocations = null;
356
Location lineLocation = null;
357
BreakpointRequest breakpRequest = null;
358
359
try {
360
Method method = (Method) testedclass.methodsByName(methodName).get(0);
361
362
alllineLocations = method.allLineLocations();
363
364
int n =
365
( (IntegerValue) testedclass.getValue(testedclass.fieldByName(bpLine) ) ).value();
366
if (n > alllineLocations.size()) {
367
log3("ERROR: TEST_ERROR_IN_settingBreakpoint(): number is out of bound of method's lines");
368
} else {
369
lineLocation = (Location) alllineLocations.get(n);
370
try {
371
breakpRequest = eventRManager.createBreakpointRequest(lineLocation);
372
breakpRequest.putProperty("number", property);
373
breakpRequest.addThreadFilter(thread2);
374
breakpRequest.setSuspendPolicy( EventRequest.SUSPEND_EVENT_THREAD);
375
} catch ( Exception e1 ) {
376
log3("ERROR: inner Exception within settingBreakpoint() : " + e1);
377
breakpRequest = null;
378
}
379
}
380
} catch ( Exception e2 ) {
381
log3("ERROR: ATTENTION: outer Exception within settingBreakpoint() : " + e2);
382
breakpRequest = null;
383
}
384
385
if (breakpRequest == null)
386
log2(" A BREAKPOINT HAS NOT BEEN SET UP");
387
else
388
log2(" a breakpoint has been set up");
389
390
return breakpRequest;
391
}
392
393
394
/*
395
* private int breakpoint ()
396
*
397
* It removes events from EventQueue until gets first BreakpointEvent.
398
* To get next EventSet value, it uses the method
399
* EventQueue.remove(int timeout)
400
* The timeout argument passed to the method, is "waitTime*60000".
401
* Note: the value of waitTime is set up with
402
* the method ArgumentHandler.getWaitTime() at the beginning of the test.
403
*
404
* Return codes:
405
* = returnCode0 - success;
406
* = returnCode2 - Exception when "eventSet = eventQueue.remove()" is executed
407
* = returnCode3 - default case when loop of processing an event, that is,
408
* an unspecified event was taken from the EventQueue
409
*/
410
411
private int breakpoint () {
412
413
int returnCode = returnCode0;
414
415
log2(" waiting for BreakpointEvent");
416
417
labelBP:
418
for (;;) {
419
420
log2(" new: eventSet = eventQueue.remove();");
421
try {
422
eventSet = eventQueue.remove(waitTime*60000);
423
if (eventSet == null) {
424
log3("ERROR: timeout for waiting for a BreakpintEvent");
425
returnCode = returnCode3;
426
break labelBP;
427
}
428
} catch ( Exception e ) {
429
log3("ERROR: Exception for eventSet = eventQueue.remove(); : " + e);
430
returnCode = 1;
431
break labelBP;
432
}
433
434
if (eventSet != null) {
435
436
log2(" : eventSet != null; size == " + eventSet.size());
437
438
EventIterator eIter = eventSet.eventIterator();
439
Event ev = null;
440
441
for (; eIter.hasNext(); ) {
442
443
if (returnCode != returnCode0)
444
break;
445
446
ev = eIter.nextEvent();
447
448
ll: for (int ifor =0; ; ifor++) {
449
450
try {
451
switch (ifor) {
452
453
case 0: AccessWatchpointEvent awe = (AccessWatchpointEvent) ev;
454
log2(" AccessWatchpointEvent removed");
455
break ll;
456
case 1: BreakpointEvent be = (BreakpointEvent) ev;
457
log2(" BreakpointEvent removed");
458
break labelBP;
459
case 2: ClassPrepareEvent cpe = (ClassPrepareEvent) ev;
460
log2(" ClassPreparEvent removed");
461
break ll;
462
case 3: ClassUnloadEvent cue = (ClassUnloadEvent) ev;
463
log2(" ClassUnloadEvent removed");
464
break ll;
465
case 4: ExceptionEvent ee = (ExceptionEvent) ev;
466
log2(" ExceptionEvent removed");
467
break ll;
468
case 5: MethodEntryEvent mene = (MethodEntryEvent) ev;
469
log2(" MethodEntryEvent removed");
470
break ll;
471
case 6: MethodExitEvent mexe = (MethodExitEvent) ev;
472
log2(" MethodExiEvent removed");
473
break ll;
474
case 7: ModificationWatchpointEvent mwe = (ModificationWatchpointEvent) ev;
475
log2(" ModificationWatchpointEvent removed");
476
break ll;
477
case 8: StepEvent se = (StepEvent) ev;
478
log2(" StepEvent removed");
479
break ll;
480
case 9: ThreadDeathEvent tde = (ThreadDeathEvent) ev;
481
log2(" ThreadDeathEvent removed");
482
break ll;
483
case 10: ThreadStartEvent tse = (ThreadStartEvent) ev;
484
log2(" ThreadStartEvent removed");
485
break ll;
486
case 11: VMDeathEvent vmde = (VMDeathEvent) ev;
487
log2(" VMDeathEvent removed");
488
break ll;
489
case 12: VMStartEvent vmse = (VMStartEvent) ev;
490
log2(" VMStartEvent removed");
491
break ll;
492
case 13: WatchpointEvent we = (WatchpointEvent) ev;
493
log2(" WatchpointEvent removed");
494
break ll;
495
496
default: log3("ERROR: default case for casting event");
497
returnCode = returnCode3;
498
break ll;
499
} // switch
500
} catch ( ClassCastException e ) {
501
} // try
502
} // ll: for (int ifor =0; ; ifor++)
503
} // for (; ev.hasNext(); )
504
}
505
}
506
if (returnCode == returnCode0)
507
log2(" : eventSet == null: EventQueue is empty");
508
509
return returnCode;
510
}
511
512
}
513
514