Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Method/Bytecodes/bytecodes001.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.Method.Bytecodes;
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: Method.Bytecodes.
34
*
35
* See bytecodes001.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 bytecodes001 {
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 QUIT = "quit";
54
55
// package and classes names constants
56
static final String PACKAGE_NAME = "nsk.jdwp.Method.Bytecodes";
57
static final String TEST_CLASS_NAME = PACKAGE_NAME + "." + "bytecodes001";
58
static final String DEBUGEE_CLASS_NAME = TEST_CLASS_NAME + "a";
59
60
// VM capability constatnts
61
static final int VM_CAPABILITY_NUMBER = JDWP.Capability.CAN_GET_BYTECODES;
62
static final String VM_CAPABILITY_NAME = "canGetBytecodes";
63
64
// tested JDWP command constants
65
static final String JDWP_COMMAND_NAME = "Method.Bytecodes";
66
static final int JDWP_COMMAND_ID = JDWP.Command.Method.Bytecodes;
67
68
// tested class name and signature constants
69
static final String TESTED_CLASS_NAME = DEBUGEE_CLASS_NAME + "$" + "TestedClass";
70
static final String TESTED_CLASS_SIGNATURE = "L" + TESTED_CLASS_NAME.replace('.', '/') + ";";
71
72
// tested method name constant
73
static final String TESTED_METHOD_NAME = "testedMethod";
74
75
// expected values for bound line numbers
76
static final int FIRST_LINE_NUMBER = bytecodes001a.FIRST_LINE_NUMBER;
77
static final int LAST_LINE_NUMBER = bytecodes001a.LAST_LINE_NUMBER;
78
79
// usual scaffold objects
80
ArgumentHandler argumentHandler = null;
81
Log log = null;
82
Binder binder = null;
83
Debugee debugee = null;
84
Transport transport = null;
85
IOPipe pipe = null;
86
87
// test passed or not
88
boolean success = true;
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 bytecodes001().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
117
// execute test and display results
118
try {
119
log.display("\n>>> Preparing debugee for testing \n");
120
121
// launch debuggee
122
binder = new Binder(argumentHandler, log);
123
log.display("Launching debugee");
124
debugee = binder.bindToDebugee(DEBUGEE_CLASS_NAME);
125
transport = debugee.getTransport();
126
pipe = debugee.createIOPipe();
127
128
// make debuggee ready for testing
129
prepareDebugee();
130
131
// work with prepared debuggee
132
try {
133
log.display("\n>>> Checking VM capability \n");
134
135
// check for VM capability
136
log.display("Checking VM capability: " + VM_CAPABILITY_NAME);
137
if (!debugee.getCapability(VM_CAPABILITY_NUMBER, VM_CAPABILITY_NAME)) {
138
out.println("TEST PASSED: unsupported VM capability: "
139
+ VM_CAPABILITY_NAME);
140
return PASSED;
141
}
142
143
log.display("\n>>> Obtaining requred data from debugee \n");
144
145
// query debuggee for classID of tested class
146
log.display("Getting classID by signature:\n"
147
+ " " + TESTED_CLASS_SIGNATURE);
148
long classID = debugee.getReferenceTypeID(TESTED_CLASS_SIGNATURE);
149
log.display(" got classID: " + classID);
150
151
// query debuggee for methodID of tested method (declared in the class)
152
log.display("Getting methodID by name: " + TESTED_METHOD_NAME);
153
long methodID = debugee.getMethodID(classID, TESTED_METHOD_NAME, true);
154
log.display(" got methodID: " + methodID);
155
156
// perform testing JDWP command
157
log.display("\n>>> Testing JDWP command \n");
158
testCommand(classID, methodID);
159
160
} finally {
161
// quit debugee
162
log.display("\n>>> Finishing test \n");
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.equals(READY)) {
206
throw new TestBug("Unexpected signal received from debugee: " + signal
207
+ " (expected: " + READY + ")");
208
}
209
}
210
211
/**
212
* Sending debugee signal to quit and waiting for it exits.
213
*/
214
void quitDebugee() {
215
// send debugee signal to quit
216
log.display("Sending signal to debugee: " + QUIT);
217
pipe.println(QUIT);
218
219
// wait for debugee exits
220
log.display("Waiting for debugee exits");
221
int code = debugee.waitFor();
222
223
// analize debugee exit status code
224
if (code == JCK_STATUS_BASE + PASSED) {
225
log.display("Debugee PASSED with exit code: " + code);
226
} else {
227
log.complain("Debugee FAILED with exit code: " + code);
228
success = false;
229
}
230
}
231
232
/**
233
* Perform testing JDWP command for specified TypeID.
234
*/
235
void testCommand(long classID, long methodID) {
236
// create command packet and fill requred out data
237
log.display("Create command packet:");
238
log.display("Command: " + JDWP_COMMAND_NAME);
239
CommandPacket command = new CommandPacket(JDWP_COMMAND_ID);
240
log.display(" referenceTypeID: " + classID);
241
command.addReferenceTypeID(classID);
242
log.display(" methodID: " + methodID);
243
command.addMethodID(methodID);
244
command.setLength();
245
246
// send command packet to debugee
247
try {
248
log.display("Sending command packet:\n" + command);
249
transport.write(command);
250
} catch (IOException e) {
251
log.complain("Unable to send command packet:\n\t" + e);
252
success = false;
253
return;
254
}
255
256
ReplyPacket reply = new ReplyPacket();
257
258
// receive reply packet from debugee
259
try {
260
log.display("Waiting for reply packet");
261
transport.read(reply);
262
log.display("Reply packet received:\n" + reply);
263
} catch (IOException e) {
264
log.complain("Unable to read reply packet:\n\t" + e);
265
success = false;
266
return;
267
}
268
269
// check reply packet header
270
try{
271
log.display("Checking reply packet header");
272
reply.checkHeader(command.getPacketID());
273
} catch (BoundException e) {
274
log.complain("Bad header of reply packet:\n\t" + e.getMessage());
275
success = false;
276
}
277
278
// start parsing reply packet data
279
log.display("Parsing reply packet:");
280
reply.resetPosition();
281
282
// extract and check reply data
283
284
// extract number of lines
285
int bytes = 0;
286
try {
287
bytes = reply.getInt();
288
log.display(" bytes: " + bytes);
289
} catch (BoundException e) {
290
log.complain("Unable to extract number of bytes from reply packet:\n\t"
291
+ e.getMessage());
292
success = false;
293
return;
294
}
295
296
if (bytes < 0) {
297
log.complain("Negative number of bytes in reply packet: " + bytes);
298
success = false;
299
return;
300
}
301
302
if (bytes == 0) {
303
log.complain("Zero number of bytes in reply packet: " + bytes);
304
success = false;
305
return;
306
}
307
308
// extract all bytes
309
ByteBuffer bytecode = new ByteBuffer();
310
for (int i = 0; i < bytes; i++) {
311
// extract next byte of bytecode
312
try {
313
byte aByte = reply.getByte();
314
bytecode.addByte(aByte);
315
} catch (BoundException e) {
316
log.complain("Unable to extract byte #" + i
317
+ " from reply packet:\n\t"
318
+ e.getMessage());
319
success = false;
320
return;
321
}
322
}
323
324
log.display(" bytecode:\n" + bytecode);
325
326
// check for extra data in reply packet
327
if (!reply.isParsed()) {
328
log.complain("Extra trailing bytes found in reply packet at: "
329
+ reply.offsetString());
330
success = false;
331
}
332
}
333
334
}
335
336