Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdwp/StackFrame/PopFrames/popframes001.java
41162 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.StackFrame.PopFrames;
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: StackFrame.PopFrames.
34
*
35
* See popframes001.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 popframes001 {
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
// VM capability constatnts
52
static final int VM_CAPABILITY_NUMBER = JDWP.Capability.CAN_POP_FRAMES;
53
static final String VM_CAPABILITY_NAME = "canPopFrames";
54
55
// package and classes names
56
static final String PACKAGE_NAME = "nsk.jdwp.StackFrame.PopFrames";
57
static final String TEST_CLASS_NAME = PACKAGE_NAME + "." + "popframes001";
58
static final String DEBUGEE_CLASS_NAME = TEST_CLASS_NAME + "a";
59
60
// tested JDWP command
61
static final String JDWP_COMMAND_NAME = "StackFrame.PopFrames";
62
static final int JDWP_COMMAND_ID = JDWP.Command.StackFrame.PopFrames;
63
64
// tested class name and signature
65
static final String TESTED_CLASS_NAME = DEBUGEE_CLASS_NAME + "$" + "TestedThreadClass";
66
static final String TESTED_CLASS_SIGNATURE = "L" + TESTED_CLASS_NAME.replace('.', '/') + ";";
67
68
// field and method names
69
static final String TESTED_METHOD_NAME = "testedMethod";
70
static final int BREAKPOINT_LINE_NUMBER = popframes001a.BREAKPOINT_LINE_NUMBER;
71
72
// usual scaffold objects
73
ArgumentHandler argumentHandler = null;
74
Log log = null;
75
Binder binder = null;
76
Debugee debugee = null;
77
Transport transport = null;
78
int waitTime = 0; // minutes
79
long timeout = 0; // milliseconds
80
boolean dead = false;
81
boolean success = true;
82
83
// data obtained from debuggee
84
long testedClassID = 0;
85
long testedThreadID = 0;
86
long testedMethodID = 0;
87
long testedFrameID = 0;
88
int breakpointRequestID = 0;
89
90
// -------------------------------------------------------------------
91
92
/**
93
* Start test from command line.
94
*/
95
public static void main (String argv[]) {
96
System.exit(run(argv,System.out) + JCK_STATUS_BASE);
97
}
98
99
/**
100
* Start JCK-compilant test.
101
*/
102
public static int run(String argv[], PrintStream out) {
103
return new popframes001().runIt(argv, out);
104
}
105
106
// -------------------------------------------------------------------
107
108
/**
109
* Perform test execution.
110
*/
111
public int runIt(String argv[], PrintStream out) {
112
113
// make log for debugger messages
114
argumentHandler = new ArgumentHandler(argv);
115
log = new Log(out, argumentHandler);
116
waitTime = argumentHandler.getWaitTime(); // minutes
117
timeout = waitTime * 60 * 1000; // milliseconds
118
119
// execute test and display results
120
try {
121
log.display("\n>>> Starting debugee \n");
122
123
// launch debuggee
124
binder = new Binder(argumentHandler, log);
125
log.display("Launching debugee VM");
126
debugee = binder.bindToDebugee(DEBUGEE_CLASS_NAME);
127
transport = debugee.getTransport();
128
log.display(" ... debuggee launched");
129
130
// set timeout for debuggee responces
131
log.display("Setting timeout for debuggee responces: " + waitTime + " minute(s)");
132
transport.setReadTimeout(timeout);
133
log.display(" ... timeout set");
134
135
// wait for VM_INIT event
136
log.display("Waiting for VM_INIT event");
137
debugee.waitForVMInit();
138
log.display(" ... VM_INIT event received");
139
140
// query debugee for VM-dependent ID sizes
141
log.display("Querying for IDSizes");
142
debugee.queryForIDSizes();
143
log.display(" ... size of VM-dependent types adjusted");
144
145
// check for VM capability
146
log.display("\n>>> Checking VM capability \n");
147
log.display("Getting new VM capability: " + VM_CAPABILITY_NAME);
148
boolean capable = debugee.getNewCapability(VM_CAPABILITY_NUMBER, VM_CAPABILITY_NAME);
149
log.display(" ... got VM capability: " + capable);
150
151
// exit as PASSED if this capability is not supported
152
if (!capable) {
153
out.println("TEST PASSED: unsupported VM capability: "
154
+ VM_CAPABILITY_NAME);
155
return PASSED;
156
}
157
158
// prepare debuggee for testing and obtain required data
159
log.display("\n>>> Getting prepared for testing \n");
160
prepareForTest();
161
162
// test JDWP command
163
log.display("\n>> Testing JDWP command \n");
164
testCommand();
165
166
// check command results
167
if (success) {
168
log.display("\n>>> Checking result of tested command \n");
169
checkResult();
170
}
171
172
// finish debuggee
173
log.display("\n>> Finishing debuggee \n");
174
175
// clear BREAKPOIN event request
176
log.display("Clearing BREAKPOINT event requestID: " + breakpointRequestID);
177
debugee.clearEventRequest(JDWP.EventKind.BREAKPOINT, breakpointRequestID);
178
log.display(" ... request cleared");
179
180
// resume debuggee after testing command
181
log.display("Resuming debuggee");
182
debugee.resume();
183
log.display(" ... debuggee resumed");
184
185
// wait for VM_DEATH event
186
log.display("Waiting for VM_DEATH event");
187
debugee.waitForVMDeath();
188
log.display(" ... VM_DEATH event received");
189
dead = true;
190
191
} catch (Failure e) {
192
log.complain("TEST FAILED: " + e.getMessage());
193
success = false;
194
} catch (Exception e) {
195
e.printStackTrace(out);
196
log.complain("Caught unexpected exception while running the test:\n\t" + e);
197
success = false;
198
} finally {
199
log.display("\n>>> Finishing test \n");
200
201
// disconnect debugee and wait for its exit
202
if (debugee != null) {
203
quitDebugee();
204
}
205
}
206
207
// check result
208
if (!success) {
209
log.complain("TEST FAILED");
210
return FAILED;
211
}
212
out.println("TEST PASSED");
213
return PASSED;
214
}
215
216
/**
217
* Get debuggee prepared for testing and obtain required data.
218
*/
219
void prepareForTest() {
220
// wait for tested class loaded on debuggee startup and obtain its classID
221
log.display("Waiting for class loaded:\n\t" + TESTED_CLASS_NAME);
222
testedClassID = debugee.waitForClassLoaded(TESTED_CLASS_NAME,
223
JDWP.SuspendPolicy.ALL);
224
log.display(" ... class loaded with classID: " + testedClassID);
225
226
// query debuggee for tested methodID
227
log.display("Getting tested methodID by name: " + TESTED_METHOD_NAME);
228
testedMethodID = debugee.getMethodID(testedClassID, TESTED_METHOD_NAME, true);
229
log.display(" ... got methodID: " + testedMethodID);
230
log.display("");
231
232
// make BREAKPOINT event request
233
log.display("Creating breakpoint requests at: "
234
+ TESTED_METHOD_NAME + ":" + BREAKPOINT_LINE_NUMBER);
235
breakpointRequestID =
236
debugee.requestBreakpointEvent(JDWP.TypeTag.CLASS,
237
testedClassID, testedMethodID,
238
BREAKPOINT_LINE_NUMBER,
239
JDWP.SuspendPolicy.ALL);
240
log.display(" ... got breakpoint requestID: " + breakpointRequestID);
241
242
// resume debuggee after testing command
243
log.display("Resuming debuggee");
244
debugee.resume();
245
log.display(" ... debuggee resumed");
246
log.display("");
247
248
// wait for BREAKPOINT event
249
log.display("Waiting for BREAKPOINT event for requestID: " + breakpointRequestID);
250
testedThreadID = waitForBreakpointEvent(breakpointRequestID, "first");
251
log.display(" ... breakpoint reached with threadID: " + testedThreadID);
252
253
// query debuggee for top frameID
254
log.display("Getting top frameID for threadID: " + testedThreadID);
255
testedFrameID = queryTopFrameID(testedThreadID);
256
log.display(" ... got frameID: " + testedFrameID);
257
log.display("");
258
259
// tested thread is suspended by an event
260
log.display("Tested thread is suspended by BREAKPOINT event before pop frameID: "
261
+ testedFrameID);
262
}
263
264
/**
265
* Perform testing JDWP command.
266
*/
267
void testCommand() {
268
// create command packet and fill requred out data
269
log.display("Create command packet:");
270
log.display("Command: " + JDWP_COMMAND_NAME);
271
CommandPacket command = new CommandPacket(JDWP_COMMAND_ID);
272
log.display(" threadID: " + testedThreadID);
273
command.addObjectID(testedThreadID);
274
log.display(" frameID: " + testedFrameID);
275
command.addFrameID(testedFrameID);
276
command.setLength();
277
278
// send command packet to debugee
279
try {
280
log.display("Sending command packet:\n" + command);
281
transport.write(command);
282
} catch (IOException e) {
283
log.complain("Unable to send command packet:\n\t" + e);
284
success = false;
285
return;
286
}
287
288
// receive reply packet from debugee
289
ReplyPacket reply = new ReplyPacket();
290
try {
291
log.display("Waiting for reply packet");
292
transport.read(reply);
293
log.display(" ... reply packet received:\n" + reply);
294
} catch (IOException e) {
295
log.complain("Unable to read reply packet for tested command:\n\t" + e);
296
success = false;
297
return;
298
}
299
300
// check reply packet header
301
try{
302
log.display("Checking header of reply packet");
303
reply.checkHeader(command.getPacketID());
304
log.display(" ... packet header is correct");
305
} catch (BoundException e) {
306
log.complain("Wrong header of reply packet for tested command:\n\t"
307
+ e.getMessage());
308
success = false;
309
return;
310
}
311
312
// start parsing reply packet data
313
log.display("Parsing reply packet data:");
314
reply.resetPosition();
315
316
// no reply data to parse
317
log.display(" no reply data");
318
319
// check for extra data in reply packet
320
if (!reply.isParsed()) {
321
log.complain("Extra trailing bytes found in reply packet at: "
322
+ reply.offsetString());
323
success = false;
324
}
325
326
log.display(" ... packed data parsed");
327
}
328
329
/**
330
* Check result of the tested JDWP command.
331
*/
332
void checkResult() {
333
// resume debuggee after sending command
334
log.display("Resuming debuggee after command");
335
debugee.resume();
336
log.display(" ... debuggee resumed");
337
338
// wait for BREAKPOINT event
339
log.display("Waiting for second BREAKPOINT event for requestID: " + breakpointRequestID);
340
long threadID = waitForBreakpointEvent(breakpointRequestID, "second");
341
log.display(" ... breakpoint secondly reached with threadID: " + threadID);
342
343
log.display("Tested method was invoked two times as expected");
344
}
345
346
/**
347
* Query debuggee for top frameID value for given threadID.
348
*/
349
long queryTopFrameID(long threadID) {
350
String error = "Error occured while getting top frameID for threadID: " + threadID;
351
352
CommandPacket command = new CommandPacket(JDWP.Command.ThreadReference.Frames);
353
command.addObjectID(threadID);
354
command.addInt(0); // top frame index
355
command.addInt(1); // number of frames
356
357
ReplyPacket reply = debugee.receiveReplyFor(command, "ThreadReference.Frames");
358
reply.resetPosition();
359
360
try {
361
int frames = reply.getInt();
362
if (frames != 1) {
363
log.complain("Wrong number of frames returned in reply packet: " + frames
364
+ " (expected: " + 1 + ")");
365
throw new Failure(error);
366
}
367
long frameID = reply.getFrameID();
368
return frameID;
369
} catch (BoundException e) {
370
log.complain("Unable to extract data from reply packet:\n\t"
371
+ e.getMessage());
372
throw new Failure(error);
373
}
374
}
375
376
/**
377
* Wait for BREAKPOINT event made by the given request and return threadID.
378
* Debuggee will be left suspended by the BREAKPOINT event.
379
*/
380
public long waitForBreakpointEvent(int requestID, String kind) {
381
String error = "Error occured while waiting for " + kind + " BREAKPOINT event";
382
383
for(;;) {
384
EventPacket event = debugee.receiveEvent();
385
byte eventSuspendPolicy = 0;
386
long eventThreadID = 0;
387
try {
388
eventSuspendPolicy = event.getByte();
389
int events = event.getInt();
390
for (int i = 0; i < events; i++) {
391
// check event kind
392
byte eventKind = event.getByte();
393
if (eventKind == JDWP.EventKind.VM_DEATH) {
394
log.complain("Unexpected VM_DEATH event received: " + eventKind
395
+ " (expected: " + JDWP.EventKind.BREAKPOINT +")");
396
dead = true;
397
throw new Failure(error);
398
} else if (eventKind != JDWP.EventKind.BREAKPOINT) {
399
log.complain("Unexpected event kind received: " + eventKind
400
+ " (expected: " + JDWP.EventKind.BREAKPOINT +")");
401
throw new Failure(error);
402
}
403
404
// extract specific BREAKPOINT event data
405
int eventRequestID = event.getInt();
406
eventThreadID = event.getObjectID();
407
JDWP.Location eventLocation = event.getLocation();
408
409
if (eventRequestID == requestID) {
410
return eventThreadID;
411
} else {
412
log.complain("Unexpected BREAKPOINT event received with requestID: "
413
+ eventRequestID + " (expected: " + requestID + ")");
414
}
415
}
416
} catch (BoundException e) {
417
log.complain("Unable to extract data from event packet while waiting for BREAKPOINT event:\n\t"
418
+ e.getMessage() + "\n" + event);
419
throw new Failure(error);
420
}
421
422
// resume debuggee after unhandled event set
423
debugee.resumeEvent(eventSuspendPolicy, eventThreadID);
424
}
425
}
426
427
/**
428
* Disconnect debuggee and wait for it exited.
429
*/
430
void quitDebugee() {
431
if (debugee == null)
432
return;
433
434
// disconnect debugee
435
if (!dead) {
436
try {
437
log.display("Disconnecting debuggee");
438
debugee.dispose();
439
log.display(" ... debuggee disconnected");
440
} catch (Failure e) {
441
log.display("Failed to finally disconnect debuggee:\n\t"
442
+ e.getMessage());
443
}
444
}
445
446
// wait for debugee exited
447
log.display("Waiting for debuggee exit");
448
int code = debugee.waitFor();
449
log.display(" ... debuggee exited with exit code: " + code);
450
451
// analize debugee exit status code
452
if (code != JCK_STATUS_BASE + PASSED) {
453
log.complain("Debuggee FAILED with exit code: " + code);
454
success = false;
455
}
456
}
457
}
458
459