Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ObjectReference/EnableCollection/enablecol001.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.ObjectReference.EnableCollection;
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: ObjectReference.EnableCollection.
34
*
35
* See enablecol001.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 enablecol001 {
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.ObjectReference.EnableCollection";
58
static final String TEST_CLASS_NAME = PACKAGE_NAME + "." + "enablecol001";
59
static final String DEBUGEE_CLASS_NAME = TEST_CLASS_NAME + "a";
60
61
// tested JDWP command constants
62
static final String JDWP_COMMAND_NAME = "ObjectReference.EnableCollection";
63
static final int JDWP_COMMAND_ID = JDWP.Command.ObjectReference.EnableCollection;
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 OBJECT_FIELD_NAME = enablecol001a.OBJECT_FIELD_NAME;
71
72
// usual scaffold objects
73
ArgumentHandler argumentHandler = null;
74
Log log = null;
75
Binder binder = null;
76
Debugee debugee = null;
77
Transport transport = null;
78
IOPipe pipe = null;
79
80
// test passed or not
81
boolean success = true;
82
83
// -------------------------------------------------------------------
84
85
/**
86
* Start test from command line.
87
*/
88
public static void main (String argv[]) {
89
System.exit(run(argv,System.out) + JCK_STATUS_BASE);
90
}
91
92
/**
93
* Start JCK-compilant test.
94
*/
95
public static int run(String argv[], PrintStream out) {
96
return new enablecol001().runIt(argv, out);
97
}
98
99
// -------------------------------------------------------------------
100
101
/**
102
* Perform test execution.
103
*/
104
public int runIt(String argv[], PrintStream out) {
105
106
// make log for debugger messages
107
argumentHandler = new ArgumentHandler(argv);
108
log = new Log(out, argumentHandler);
109
110
// execute test and display results
111
try {
112
log.display("\n>>> Preparing debugee for testing \n");
113
114
// launch debuggee
115
binder = new Binder(argumentHandler, log);
116
log.display("Launching debugee");
117
debugee = binder.bindToDebugee(DEBUGEE_CLASS_NAME);
118
transport = debugee.getTransport();
119
pipe = debugee.createIOPipe();
120
121
// make debuggee ready for testing
122
prepareDebugee();
123
124
// work with prepared debuggee
125
try {
126
log.display("\n>>> Obtaining requred data from debuggee \n");
127
128
// query debuggee for classID of tested class
129
log.display("Getting classID by signature:\n"
130
+ " " + TESTED_CLASS_SIGNATURE);
131
long classID = debugee.getReferenceTypeID(TESTED_CLASS_SIGNATURE);
132
log.display(" got classID: " + classID);
133
134
// query debuggee for objectID value from static field
135
log.display("Getting objectID value from static field: "
136
+ OBJECT_FIELD_NAME);
137
long objectID = queryObjectID(classID,
138
OBJECT_FIELD_NAME, JDWP.Tag.OBJECT);
139
log.display(" got objectID: " + objectID);
140
141
// query debuggee to disable garbage collection for this object
142
log.display("Disabling garbage collection for objectID: " + objectID);
143
disableObjectCollection(objectID);
144
145
// perform testing JDWP command
146
log.display("\n>>> Testing JDWP command \n");
147
testCommand(objectID);
148
149
} finally {
150
log.display("\n>>> Finishing test \n");
151
152
// quit debugee
153
quitDebugee();
154
}
155
156
} catch (Failure e) {
157
log.complain("TEST FAILED: " + e.getMessage());
158
success = false;
159
} catch (Exception e) {
160
e.printStackTrace(out);
161
log.complain("Caught unexpected exception while running the test:\n\t" + e);
162
success = false;
163
}
164
165
if (!success) {
166
log.complain("TEST FAILED");
167
return FAILED;
168
}
169
170
out.println("TEST PASSED");
171
return PASSED;
172
173
}
174
175
/**
176
* Prepare debugee for testing and waiting for ready signal.
177
*/
178
void prepareDebugee() {
179
// wait for VM_INIT event from debugee
180
log.display("Waiting for VM_INIT event");
181
debugee.waitForVMInit();
182
183
// query debugee for VM-dependent ID sizes
184
log.display("Querying for IDSizes");
185
debugee.queryForIDSizes();
186
187
// resume initially suspended debugee
188
log.display("Resuming debugee VM");
189
debugee.resume();
190
191
// wait for READY signal from debugee
192
log.display("Waiting for signal from debugee: " + READY);
193
String signal = pipe.readln();
194
log.display("Received signal from debugee: " + signal);
195
if (signal == null) {
196
throw new TestBug("Null signal received from debugee: " + signal
197
+ " (expected: " + READY + ")");
198
} else if (signal.equals(ERROR)) {
199
throw new TestBug("Debugee was not able to start tested thread"
200
+ " (received signal: " + signal + ")");
201
} else if (!signal.equals(READY)) {
202
throw new TestBug("Unexpected signal received from 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 threadID.
250
*/
251
void disableObjectCollection(long objectID) {
252
CommandPacket command = new CommandPacket(JDWP.Command.ObjectReference.DisableCollection);
253
command.addObjectID(objectID);
254
ReplyPacket reply = debugee.receiveReplyFor(command);
255
}
256
257
/**
258
* Perform testing JDWP command for specified threadID.
259
*/
260
void testCommand(long objectID) {
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(" objectID: " + objectID);
266
command.addObjectID(objectID);
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
// check for extra data in reply packet
307
if (!reply.isParsed()) {
308
log.complain("Extra trailing bytes found in reply packet at: "
309
+ reply.offsetString());
310
success = false;
311
}
312
313
}
314
315
}
316
317