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