Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/ReleaseEvents/releaseevents002.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.ReleaseEvents;
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.ReleaseEvents.
34
*
35
* See releaseevents002.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 releaseevents002 {
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.ReleaseEvents";
51
static final String TEST_CLASS_NAME = PACKAGE_NAME + "." + "releaseevents002";
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.ReleaseEvents";
56
static final int JDWP_COMMAND_ID = JDWP.Command.VirtualMachine.ReleaseEvents;
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 = releaseevents002a.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 releaseevents002().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
// hold events
149
log.display("Holding events into debuggee");
150
holdEvents();
151
log.display(" ... events held");
152
153
// resume debuggee
154
log.display("Resuming debuggee");
155
debugee.resume();
156
log.display(" ... debuggee resumed");
157
158
// release events
159
log.display("Release events into debuggee");
160
releaseEvents();
161
log.display(" ... events released");
162
163
// wait for BREAKPOINT event
164
log.display("Waiting for BREAKPOINT event");
165
waitForBreakpointEvent();
166
167
} catch (Failure e) {
168
log.complain("TEST FAILED: " + e.getMessage());
169
success = false;
170
} catch (Exception e) {
171
e.printStackTrace(out);
172
log.complain("Caught unexpected exception while running the test:\n\t" + e);
173
success = false;
174
} finally {
175
// quit debugee
176
log.display("\n>>> Finishing test \n");
177
quitDebugee();
178
}
179
180
// check test results
181
if (!success) {
182
log.complain("TEST FAILED");
183
return FAILED;
184
}
185
186
out.println("TEST PASSED");
187
return PASSED;
188
189
}
190
191
/**
192
* Prepare debuggee for testing.
193
*/
194
void prepareForTest() {
195
// wait for tested class loaded
196
log.display("Waiting for tested class loaded");
197
testedClassID = debugee.waitForClassLoaded(TESTED_CLASS_NAME, JDWP.SuspendPolicy.ALL);
198
log.display(" ... got classID: " + testedClassID);
199
log.display("");
200
201
// get methodID for breakpoint method
202
log.display("Getting breakpoint methodID by name: " + TESTED_METHOD_NAME);
203
testedMethodID = debugee.getMethodID(testedClassID, TESTED_METHOD_NAME, true);
204
log.display(" ... got methodID: " + testedMethodID);
205
206
// make request for BREAKPOINT event
207
log.display("Making request for BREAKPOINT event at: "
208
+ TESTED_METHOD_NAME + ":" + BREAKPOINT_LINE);
209
eventRequestID = debugee.requestBreakpointEvent(JDWP.TypeTag.CLASS, testedClassID,
210
testedMethodID, BREAKPOINT_LINE,
211
JDWP.SuspendPolicy.ALL);
212
log.display(" ... got requestID: " + eventRequestID);
213
}
214
215
/**
216
* Hold events into debuggee.
217
*/
218
void holdEvents() {
219
CommandPacket command = new CommandPacket(JDWP.Command.VirtualMachine.HoldEvents);
220
ReplyPacket reply = debugee.receiveReplyFor(command);
221
}
222
223
/**
224
* Release events into debuggee.
225
*/
226
void releaseEvents() {
227
CommandPacket command = new CommandPacket(JDWP.Command.VirtualMachine.ReleaseEvents);
228
ReplyPacket reply = debugee.receiveReplyFor(command);
229
}
230
231
/**
232
* Wait for requested BREAKPOINT event NOT occured.
233
*/
234
void waitForBreakpointEvent() {
235
236
// receive event
237
EventPacket eventPacket = null;
238
try {
239
eventPacket = debugee.receiveEvent();
240
log.display("Event received after releasing events into debuggee");
241
} catch (Failure e) {
242
log.complain("No requested event received after releasing events into debuggee:\n\t"
243
+ e.getMessage());
244
success = false;
245
return;
246
}
247
248
// start parsing reply packet data
249
log.display("Parsing event packet:");
250
eventPacket.resetPosition();
251
252
// get suspendPolicy value
253
byte suspendPolicy = 0;
254
try {
255
suspendPolicy = eventPacket.getByte();
256
log.display(" suspendPolicy: " + suspendPolicy);
257
} catch (BoundException e) {
258
log.complain("Unable to get suspendPolicy value from received event packet:\n\t"
259
+ e.getMessage());
260
success = false;
261
return;
262
}
263
264
// get events count
265
int events = 0;
266
try {
267
events = eventPacket.getInt();
268
log.display(" events: " + events);
269
} catch (BoundException e) {
270
log.complain("Unable to get events count from received event packet:\n\t"
271
+ e.getMessage());
272
success = false;
273
return;
274
}
275
276
// check events count
277
if (events < 0) {
278
log.complain("Negative value of events number in received event packet: " +
279
events + " (expected: " + 1 + ")");
280
success = false;
281
} else if (events != 1) {
282
log.complain("Invalid number of events in received event packet: " +
283
events + " (expected: " + 1 + ")");
284
success = false;
285
}
286
287
// extract each event
288
long eventThreadID = 0;
289
for (int i = 0; i < events; i++) {
290
log.display(" event #" + i + ":");
291
292
// get eventKind
293
byte eventKind = 0;
294
try {
295
eventKind = eventPacket.getByte();
296
log.display(" eventKind: " + eventKind);
297
} catch (BoundException e) {
298
log.complain("Unable to get eventKind of event #" + i + " from received event packet:\n\t"
299
+ e.getMessage());
300
success = false;
301
return;
302
}
303
304
// check eventKind
305
if (eventKind == JDWP.EventKind.VM_DEATH) {
306
log.display("Unexpected VM_DEATH event received intead of BREAKPOINT event");
307
success = false;
308
dead = true;
309
return;
310
} else if (eventKind == JDWP.EventKind.BREAKPOINT) {
311
log.display("Expected BREAKPOINT event received in event packet: " +
312
eventKind + " (expected: " + JDWP.EventKind.BREAKPOINT + ")");
313
} else {
314
log.complain("Unexpected eventKind of event " + i + " in event packet: " +
315
eventKind + " (expected: " + JDWP.EventKind.BREAKPOINT + ")");
316
success = false;
317
return;
318
}
319
320
// get requestID
321
int requestID = 0;
322
try {
323
requestID = eventPacket.getInt();
324
log.display(" requestID: " + requestID);
325
} catch (BoundException e) {
326
log.complain("Unable to get requestID of event #" + i + " from BREAKPOINT event packet:\n\t"
327
+ e.getMessage());
328
success = false;
329
return;
330
}
331
332
// check requestID
333
if (requestID != eventRequestID) {
334
log.complain("Unexpected requestID of event " + i + " in BREAKPOINT event packet: " +
335
requestID + " (expected: " + eventRequestID + ")");
336
success = false;
337
}
338
339
// get threadID
340
long threadID = 0;
341
try {
342
threadID = eventPacket.getObjectID();
343
log.display(" threadID: " + threadID);
344
} catch (BoundException e) {
345
log.complain("Unable to get threadID of event #" + i + " from BREAKPOINT event packet:\n\t"
346
+ e.getMessage());
347
success = false;
348
return;
349
}
350
351
// get location
352
JDWP.Location location = null;
353
try {
354
location = eventPacket.getLocation();
355
log.display(" location: " + location);
356
} catch (BoundException e) {
357
log.complain("Unable to get location of event #" + i + " from BREAKPOINT event packet:\n\t"
358
+ e.getMessage());
359
success = false;
360
return;
361
}
362
}
363
364
// check for extra data in event packet
365
if (!eventPacket.isParsed()) {
366
log.complain("Extra trailing bytes found in event packet at: "
367
+ eventPacket.offsetString());
368
success = false;
369
}
370
371
log.display(" ... event packet parsed");
372
}
373
374
/**
375
* Disconnect debuggee and wait for it exited.
376
*/
377
void quitDebugee() {
378
if (debugee == null)
379
return;
380
381
// disconnect debugee if not dead
382
if (!dead) {
383
try {
384
log.display("Disconnecting debuggee");
385
debugee.dispose();
386
log.display(" ... debuggee disconnected");
387
} catch (Failure e) {
388
log.display("Failed to finally disconnect debuggee:\n\t"
389
+ e.getMessage());
390
}
391
}
392
393
// wait for debugee exited
394
log.display("Waiting for debuggee exit");
395
int code = debugee.waitFor();
396
log.display(" ... debuggee exited with exit code: " + code);
397
398
// analize debugee exit status code
399
if (code != JCK_STATUS_BASE + PASSED) {
400
log.complain("Debuggee FAILED with exit code: " + code);
401
success = false;
402
}
403
}
404
405
}
406
407