Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/DisposeObjects/disposeobj001.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.DisposeObjects;
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.DisposeObjects.
34
*
35
* See disposeobj001.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 disposeobj001 {
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.VirtualMachine.DisposeObjects";
57
static final String TEST_CLASS_NAME = PACKAGE_NAME + "." + "disposeobj001";
58
static final String DEBUGEE_CLASS_NAME = TEST_CLASS_NAME + "a";
59
60
// tested JDWP command constants
61
static final String JDWP_COMMAND_NAME = "VirtualMachine.DisposeObjects";
62
static final int JDWP_COMMAND_ID = JDWP.Command.VirtualMachine.DisposeObjects;
63
64
// tested class name and signature constants
65
static final String TESTED_CLASS_NAME = DEBUGEE_CLASS_NAME + "$" + "TestedClass";
66
static final String TESTED_CLASS_SIGNATURE = "L" + TESTED_CLASS_NAME.replace('.', '/') + ";";
67
68
// Number of references to free for tested objects
69
static final int REF_COUNT = 3;
70
71
// list of static fields with tested objects
72
static final String fieldsList[] = {
73
"objectValue",
74
"stringValue",
75
"classValue"
76
};
77
static final int fieldsCount = fieldsList.length;
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 disposeobj001().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>>> Obtaining requred data from debugee \n");
134
135
// query debuggee for classID of tested class
136
log.display("Getting classID by signature:\n"
137
+ " " + TESTED_CLASS_SIGNATURE);
138
long classID = debugee.getReferenceTypeID(TESTED_CLASS_SIGNATURE);
139
log.display(" got classID: " + classID);
140
141
// query debuggee for objectIDs values of static fields
142
long objectIDs[] = getObjectIDs(classID);
143
144
// perform testing JDWP command
145
log.display("\n>>> Testing JDWP command \n");
146
testCommand(objectIDs);
147
148
} finally {
149
// quit debugee
150
log.display("\n>>> Finishing test \n");
151
quitDebugee();
152
}
153
154
} catch (Failure e) {
155
log.complain("TEST FAILED: " + e.getMessage());
156
success = false;
157
} catch (Exception e) {
158
e.printStackTrace(out);
159
log.complain("Caught unexpected exception while running the test:\n\t" + e);
160
success = false;
161
}
162
163
if (!success) {
164
log.complain("TEST FAILED");
165
return FAILED;
166
}
167
168
out.println("TEST PASSED");
169
return PASSED;
170
171
}
172
173
/**
174
* Prepare debugee for testing and waiting for ready signal.
175
*/
176
void prepareDebugee() {
177
// wait for VM_INIT event from debugee
178
log.display("Waiting for VM_INIT event");
179
debugee.waitForVMInit();
180
181
// query debugee for VM-dependent ID sizes
182
log.display("Querying for IDSizes");
183
debugee.queryForIDSizes();
184
185
// resume initially suspended debugee
186
log.display("Resuming debugee VM");
187
debugee.resume();
188
189
// wait for READY signal from debugee
190
log.display("Waiting for signal from debugee: " + READY);
191
String signal = pipe.readln();
192
log.display("Received signal from debugee: " + signal);
193
if (! signal.equals(READY)) {
194
throw new TestBug("Unexpected signal received from debugee: " + signal
195
+ " (expected: " + READY + ")");
196
}
197
}
198
199
/**
200
* Sending debugee signal to quit and waiting for it exits.
201
*/
202
void quitDebugee() {
203
// send debugee signal to quit
204
log.display("Sending signal to debugee: " + QUIT);
205
pipe.println(QUIT);
206
207
// wait for debugee exits
208
log.display("Waiting for debugee exits");
209
int code = debugee.waitFor();
210
211
// analize debugee exit status code
212
if (code == JCK_STATUS_BASE + PASSED) {
213
log.display("Debugee PASSED with exit code: " + code);
214
} else {
215
log.complain("Debugee FAILED with exit code: " + code);
216
success = false;
217
}
218
}
219
220
/**
221
* Query debuggee for IDs of objects which are values of static fields.
222
*/
223
long[] getObjectIDs(long classID) {
224
long[] objectIDs = new long[fieldsCount];
225
226
for (int i = 0; i < fieldsCount; i++ ) {
227
String name = fieldsList[i];
228
229
log.display("Getting fieldID of static field: " + name);
230
long fieldID = debugee.getClassFieldID(classID, name, true);
231
log.display(" got fieldID: " + fieldID);
232
233
// query for objectID value REF_COUNT times
234
log.display("Getting " + REF_COUNT + " times value of static fieldID: "
235
+ fieldID);
236
for (int j = 0; j < REF_COUNT; j++) {
237
JDWP.Value value = debugee.getStaticFieldValue(classID, fieldID);
238
log.display(" #" + i + ": got value: " + value);
239
240
if (value.getTag() != JDWP.Tag.OBJECT
241
&& value.getTag() != JDWP.Tag.STRING) {
242
throw new Failure("Not object value returned for static field \""
243
+ name + "\": " + value);
244
}
245
long objectID = ((Long)value.getValue()).longValue();
246
247
// check that returned objectID is the same
248
if (j > 0) {
249
if (objectID != objectIDs[i]) {
250
throw new Failure("Last request for object value returned"
251
+ " unexpected objectID: " + objectID
252
+ "(expected: " + objectIDs[i] + ")");
253
}
254
} else {
255
objectIDs[i] = objectID;
256
}
257
}
258
}
259
return objectIDs;
260
}
261
262
/**
263
* Perform testing JDWP command for specified TypeID.
264
*/
265
void testCommand(long objectIDs[]) {
266
// create command packet and fill requred out data
267
log.display("Create command packet:");
268
log.display("Command: " + JDWP_COMMAND_NAME);
269
CommandPacket command = new CommandPacket(JDWP_COMMAND_ID);
270
271
log.display(" requested: " + fieldsCount);
272
command.addInt(fieldsCount);
273
274
for (int i = 0; i < fieldsCount; i++) {
275
log.display(" object: " + objectIDs[i]);
276
command.addObjectID(objectIDs[i]);
277
log.display(" refCnt: " + REF_COUNT);
278
command.addInt(REF_COUNT);
279
}
280
281
command.setLength();
282
283
// send command packet to debugee
284
try {
285
log.display("Sending command packet:\n" + command);
286
transport.write(command);
287
} catch (IOException e) {
288
log.complain("Unable to send command packet:\n\t" + e);
289
success = false;
290
return;
291
}
292
293
ReplyPacket reply = new ReplyPacket();
294
295
// receive reply packet from debugee
296
try {
297
log.display("Waiting for reply packet");
298
transport.read(reply);
299
log.display("Reply packet received:\n" + reply);
300
} catch (IOException e) {
301
log.complain("Unable to read reply packet:\n\t" + e);
302
success = false;
303
return;
304
}
305
306
// check reply packet header
307
try{
308
log.display("Checking reply packet header");
309
reply.checkHeader(command.getPacketID());
310
} catch (BoundException e) {
311
log.complain("Bad header of reply packet:\n\t" + e.getMessage());
312
success = false;
313
}
314
315
// start parsing reply packet data
316
log.display("Parsing reply packet:");
317
reply.resetPosition();
318
319
// check for extra data in reply packet
320
if (!reply.isParsed()) {
321
log.complain("Extra trailing bytes found in reply packet at: "
322
+ reply.offsetString());
323
success = false;
324
}
325
}
326
}
327
328