Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ObjectReference/DisableCollection/disablecol001.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.DisableCollection;
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.DisableCollection.
34
*
35
* See disablecol001.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 disablecol001 {
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.DisableCollection";
58
static final String TEST_CLASS_NAME = PACKAGE_NAME + "." + "disablecol001";
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.DisableCollection";
63
static final int JDWP_COMMAND_ID = JDWP.Command.ObjectReference.DisableCollection;
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 = disablecol001a.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 disablecol001().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
// perform testing JDWP command
142
log.display("\n>>> Testing JDWP command \n");
143
testCommand(objectID);
144
145
} finally {
146
log.display("\n>>> Finishing test \n");
147
148
// quit debugee
149
quitDebugee();
150
}
151
152
} catch (Failure e) {
153
log.complain("TEST FAILED: " + e.getMessage());
154
success = false;
155
} catch (Exception e) {
156
e.printStackTrace(out);
157
log.complain("Caught unexpected exception while running the test:\n\t" + e);
158
success = false;
159
}
160
161
if (!success) {
162
log.complain("TEST FAILED");
163
return FAILED;
164
}
165
166
out.println("TEST PASSED");
167
return PASSED;
168
169
}
170
171
/**
172
* Prepare debugee for testing and waiting for ready signal.
173
*/
174
void prepareDebugee() {
175
// wait for VM_INIT event from debugee
176
log.display("Waiting for VM_INIT event");
177
debugee.waitForVMInit();
178
179
// query debugee for VM-dependent ID sizes
180
log.display("Querying for IDSizes");
181
debugee.queryForIDSizes();
182
183
// resume initially suspended debugee
184
log.display("Resuming debugee VM");
185
debugee.resume();
186
187
// wait for READY signal from debugee
188
log.display("Waiting for signal from debugee: " + READY);
189
String signal = pipe.readln();
190
log.display("Received signal from debugee: " + signal);
191
if (signal == null) {
192
throw new TestBug("Null signal received from debugee: " + signal
193
+ " (expected: " + READY + ")");
194
} else if (signal.equals(ERROR)) {
195
throw new TestBug("Debugee was not able to start tested thread"
196
+ " (received signal: " + signal + ")");
197
} else if (!signal.equals(READY)) {
198
throw new TestBug("Unexpected signal received from debugee: " + signal
199
+ " (expected: " + READY + ")");
200
}
201
}
202
203
/**
204
* Sending debugee signal to quit and waiting for it exits.
205
*/
206
void quitDebugee() {
207
// send debugee signal to quit
208
log.display("Sending signal to debugee: " + QUIT);
209
pipe.println(QUIT);
210
211
// wait for debugee exits
212
log.display("Waiting for debugee exits");
213
int code = debugee.waitFor();
214
215
// analize debugee exit status code
216
if (code == JCK_STATUS_BASE + PASSED) {
217
log.display("Debugee PASSED with exit code: " + code);
218
} else {
219
log.complain("Debugee FAILED with exit code: " + code);
220
success = false;
221
}
222
}
223
224
/**
225
* Query debuggee for objectID value of static class field.
226
*/
227
long queryObjectID(long classID, String fieldName, byte tag) {
228
// get fieledID for static field (declared in the class)
229
long fieldID = debugee.getClassFieldID(classID, fieldName, true);
230
// get value of the field
231
JDWP.Value value = debugee.getStaticFieldValue(classID, fieldID);
232
233
// check that value has THREAD tag
234
if (value.getTag() != tag) {
235
throw new Failure("Wrong objectID tag received from field \"" + fieldName
236
+ "\": " + value.getTag() + " (expected: " + tag + ")");
237
}
238
239
// extract threadID from the value
240
long objectID = ((Long)value.getValue()).longValue();
241
return objectID;
242
}
243
244
/**
245
* Perform testing JDWP command for specified threadID.
246
*/
247
void testCommand(long objectID) {
248
// create command packet and fill requred out data
249
log.display("Create command packet:");
250
log.display("Command: " + JDWP_COMMAND_NAME);
251
CommandPacket command = new CommandPacket(JDWP_COMMAND_ID);
252
log.display(" objectID: " + objectID);
253
command.addObjectID(objectID);
254
command.setLength();
255
256
// send command packet to debugee
257
try {
258
log.display("Sending command packet:\n" + command);
259
transport.write(command);
260
} catch (IOException e) {
261
log.complain("Unable to send command packet:\n\t" + e);
262
success = false;
263
return;
264
}
265
266
ReplyPacket reply = new ReplyPacket();
267
268
// receive reply packet from debugee
269
try {
270
log.display("Waiting for reply packet");
271
transport.read(reply);
272
log.display("Reply packet received:\n" + reply);
273
} catch (IOException e) {
274
log.complain("Unable to read reply packet:\n\t" + e);
275
success = false;
276
return;
277
}
278
279
// check reply packet header
280
try{
281
log.display("Checking reply packet header");
282
reply.checkHeader(command.getPacketID());
283
} catch (BoundException e) {
284
log.complain("Bad header of reply packet:\n\t" + e.getMessage());
285
success = false;
286
return;
287
}
288
289
// start parsing reply packet data
290
log.display("Parsing reply packet:");
291
reply.resetPosition();
292
293
// check for extra data in reply packet
294
if (!reply.isParsed()) {
295
log.complain("Extra trailing bytes found in reply packet at: "
296
+ reply.offsetString());
297
success = false;
298
}
299
300
}
301
302
}
303
304