Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadReference/FrameCount/framecnt001.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.ThreadReference.FrameCount;
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: ThreadReference.FrameCount.
34
*
35
* See framecnt001.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 framecnt001 {
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
// communication signals constants
52
static final String READY = "ready";
53
static final String ERROR = "error";
54
static final String QUIT = "quit";
55
56
// package and classes names constants
57
static final String PACKAGE_NAME = "nsk.jdwp.ThreadReference.FrameCount";
58
static final String TEST_CLASS_NAME = PACKAGE_NAME + "." + "framecnt001";
59
static final String DEBUGEE_CLASS_NAME = TEST_CLASS_NAME + "a";
60
61
// tested JDWP command constants
62
static final String JDWP_COMMAND_NAME = "ThreadReference.FrameCount";
63
static final int JDWP_COMMAND_ID = JDWP.Command.ThreadReference.FrameCount;
64
65
// tested class name and signature constants
66
static final String TESTED_CLASS_NAME = DEBUGEE_CLASS_NAME + "$" + "TestedClass";
67
static final String TESTED_CLASS_SIGNATURE = "L" + TESTED_CLASS_NAME.replace('.', '/') + ";";
68
69
// name of the tested thread and statioc field with thread value
70
static final String TESTED_CLASS_FIELD_NAME = framecnt001a.FIELD_NAME;
71
static final String TESTED_THREAD_NAME = framecnt001a.THREAD_NAME;
72
73
// expected number of frames count
74
static final int FRAMES_COUNT = framecnt001a.FRAMES_COUNT;
75
76
// usual scaffold objects
77
ArgumentHandler argumentHandler = null;
78
Log log = null;
79
Binder binder = null;
80
Debugee debugee = null;
81
Transport transport = null;
82
IOPipe pipe = null;
83
84
// test passed or not
85
boolean success = true;
86
87
// -------------------------------------------------------------------
88
89
/**
90
* Start test from command line.
91
*/
92
public static void main (String argv[]) {
93
System.exit(run(argv,System.out) + JCK_STATUS_BASE);
94
}
95
96
/**
97
* Start JCK-compilant test.
98
*/
99
public static int run(String argv[], PrintStream out) {
100
return new framecnt001().runIt(argv, out);
101
}
102
103
// -------------------------------------------------------------------
104
105
/**
106
* Perform test execution.
107
*/
108
public int runIt(String argv[], PrintStream out) {
109
110
// make log for debugger messages
111
argumentHandler = new ArgumentHandler(argv);
112
log = new Log(out, argumentHandler);
113
114
// execute test and display results
115
try {
116
log.display("\n>>> Preparing debugee for testing \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
pipe = debugee.createIOPipe();
124
125
// make debuggee ready for testing
126
prepareDebugee();
127
128
// work with prepared debuggee
129
long threadID = 0;
130
try {
131
log.display("\n>>> Obtaining requred data from debugee \n");
132
133
// query debuggee for classID of tested class
134
log.display("Getting classID by signature:\n"
135
+ " " + TESTED_CLASS_SIGNATURE);
136
long classID = debugee.getReferenceTypeID(TESTED_CLASS_SIGNATURE);
137
log.display(" got classID: " + classID);
138
139
// query debuggee for threadID value from a static field
140
log.display("Getting threadID value from static field: "
141
+ TESTED_CLASS_FIELD_NAME);
142
threadID = queryThreadID(classID, TESTED_CLASS_FIELD_NAME);
143
log.display(" got threadID: " + threadID);
144
145
// suspend tested thread into debyggee
146
log.display("Suspending thread into debuggee for threadID: " + threadID);
147
debugee.suspendThread(threadID);
148
149
// perform testing JDWP command
150
log.display("\n>>> Testing JDWP command \n");
151
testCommand(threadID);
152
153
} finally {
154
log.display("\n>>> Finishing test \n");
155
156
// resume suspended thread
157
if (threadID != 0) {
158
log.display("Resuming suspended thread");
159
debugee.resumeThread(threadID);
160
}
161
162
// quit debugee
163
quitDebugee();
164
}
165
166
} catch (Failure e) {
167
log.complain("TEST FAILED: " + e.getMessage());
168
success = false;
169
} catch (Exception e) {
170
e.printStackTrace(out);
171
log.complain("Caught unexpected exception while running the test:\n\t" + e);
172
success = false;
173
}
174
175
if (!success) {
176
log.complain("TEST FAILED");
177
return FAILED;
178
}
179
180
out.println("TEST PASSED");
181
return PASSED;
182
183
}
184
185
/**
186
* Prepare debugee for testing and waiting for ready signal.
187
*/
188
void prepareDebugee() {
189
// wait for VM_INIT event from debugee
190
log.display("Waiting for VM_INIT event");
191
debugee.waitForVMInit();
192
193
// query debugee for VM-dependent ID sizes
194
log.display("Querying for IDSizes");
195
debugee.queryForIDSizes();
196
197
// resume initially suspended debugee
198
log.display("Resuming debugee VM");
199
debugee.resume();
200
201
// wait for READY signal from debugee
202
log.display("Waiting for signal from debugee: " + READY);
203
String signal = pipe.readln();
204
log.display("Received signal from debugee: " + signal);
205
if (signal == null) {
206
throw new TestBug("Null signal received from debugee: " + signal
207
+ " (expected: " + READY + ")");
208
} else if (signal.equals(ERROR)) {
209
throw new TestBug("Debugee was not able to start tested thread"
210
+ " (received signal: " + signal + ")");
211
} else if (!signal.equals(READY)) {
212
throw new TestBug("Unexpected signal received from debugee: " + signal
213
+ " (expected: " + READY + ")");
214
}
215
}
216
217
/**
218
* Sending debugee signal to quit and waiting for it exits.
219
*/
220
void quitDebugee() {
221
// send debugee signal to quit
222
log.display("Sending signal to debugee: " + QUIT);
223
pipe.println(QUIT);
224
225
// wait for debugee exits
226
log.display("Waiting for debugee exits");
227
int code = debugee.waitFor();
228
229
// analize debugee exit status code
230
if (code == JCK_STATUS_BASE + PASSED) {
231
log.display("Debugee PASSED with exit code: " + code);
232
} else {
233
log.complain("Debugee FAILED with exit code: " + code);
234
success = false;
235
}
236
}
237
238
/**
239
* Query debuggee for threadID value of statuic field of the class.
240
*/
241
long queryThreadID(long classID, String fieldName) {
242
// get fieledID for static field (declared in the class)
243
long fieldID = debugee.getClassFieldID(classID, fieldName, true);
244
// get value of the field
245
JDWP.Value value = debugee.getStaticFieldValue(classID, fieldID);
246
247
// check that value has THREAD tag
248
if (value.getTag() != JDWP.Tag.THREAD) {
249
throw new Failure("Not threadID value returned from debuggee: " + value);
250
}
251
252
// extract threadID from the value
253
long threadID = ((Long)value.getValue()).longValue();
254
return threadID;
255
}
256
257
/**
258
* Perform testing JDWP command for specified threadID.
259
*/
260
void testCommand(long threadID) {
261
// create command packet and fill requred out data
262
log.display("Create command packet:");
263
log.display("Command: " + JDWP_COMMAND_NAME);
264
CommandPacket command = new CommandPacket(JDWP_COMMAND_ID);
265
log.display(" threadID: " + threadID);
266
command.addObjectID(threadID);
267
command.setLength();
268
269
// send command packet to debugee
270
try {
271
log.display("Sending command packet:\n" + command);
272
transport.write(command);
273
} catch (IOException e) {
274
log.complain("Unable to send command packet:\n\t" + e);
275
success = false;
276
return;
277
}
278
279
ReplyPacket reply = new ReplyPacket();
280
281
// receive reply packet from debugee
282
try {
283
log.display("Waiting for reply packet");
284
transport.read(reply);
285
log.display("Reply packet received:\n" + reply);
286
} catch (IOException e) {
287
log.complain("Unable to read reply packet:\n\t" + e);
288
success = false;
289
return;
290
}
291
292
// check reply packet header
293
try{
294
log.display("Checking reply packet header");
295
reply.checkHeader(command.getPacketID());
296
} catch (BoundException e) {
297
log.complain("Bad header of reply packet:\n\t" + e.getMessage());
298
success = false;
299
return;
300
}
301
302
// start parsing reply packet data
303
log.display("Parsing reply packet:");
304
reply.resetPosition();
305
306
// extract frames count
307
int frameCount = 0;
308
try {
309
frameCount = reply.getInt();
310
log.display(" frameCount: " + frameCount);
311
} catch (BoundException e) {
312
log.complain("Unable to extract frames count from reply packet:\n\t"
313
+ e.getMessage());
314
success = false;
315
return;
316
}
317
318
// check that frames count is not negative
319
if (frameCount < 0) {
320
log.complain("Negative value of frames count in reply packet: "
321
+ frameCount);
322
success = false;
323
}
324
325
// check that thread has an expected state
326
if (frameCount != FRAMES_COUNT) {
327
log.complain("Unexpected number of frames count returned: "
328
+ frameCount + " (expected: " + FRAMES_COUNT + ")");
329
success = false;
330
}
331
332
// check for extra data in reply packet
333
if (!reply.isParsed()) {
334
log.complain("Extra trailing bytes found in reply packet at: "
335
+ reply.offsetString());
336
success = false;
337
}
338
}
339
340
}
341
342