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