Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Method/IsObsolete/isobsolete001.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.Method.IsObsolete;
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: Method.IsObsolete.
34
*
35
* See isobsolete001.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 isobsolete001 {
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.Method.IsObsolete";
57
static final String TEST_CLASS_NAME = PACKAGE_NAME + "." + "isobsolete001";
58
static final String DEBUGEE_CLASS_NAME = TEST_CLASS_NAME + "a";
59
60
// VM capability constatnts
61
static final int VM_CAPABILITY_NUMBER = JDWP.Capability.CAN_REDEFINE_CLASSES;
62
static final String VM_CAPABILITY_NAME = "canRedefineClasses";
63
64
// tested JDWP command constants
65
static final String JDWP_COMMAND_NAME = "Method.IsObsolete";
66
static final int JDWP_COMMAND_ID = JDWP.Command.Method.IsObsolete;
67
68
// tested class name and signature constants
69
static final String TESTED_CLASS_NAME = DEBUGEE_CLASS_NAME + "$" + "TestedClass";
70
static final String TESTED_CLASS_SIGNATURE = "L" + TESTED_CLASS_NAME.replace('.', '/') + ";";
71
72
// tested method name constant
73
static final String TESTED_METHOD_NAME = "testedMethod";
74
75
// usual scaffold objects
76
ArgumentHandler argumentHandler = null;
77
Log log = null;
78
Binder binder = null;
79
Debugee debugee = null;
80
Transport transport = null;
81
IOPipe pipe = null;
82
83
// test passed or not
84
boolean success = true;
85
86
// -------------------------------------------------------------------
87
88
/**
89
* Start test from command line.
90
*/
91
public static void main (String argv[]) {
92
System.exit(run(argv,System.out) + JCK_STATUS_BASE);
93
}
94
95
/**
96
* Start JCK-compilant test.
97
*/
98
public static int run(String argv[], PrintStream out) {
99
return new isobsolete001().runIt(argv, out);
100
}
101
102
// -------------------------------------------------------------------
103
104
/**
105
* Perform test execution.
106
*/
107
public int runIt(String argv[], PrintStream out) {
108
109
// make log for debugger messages
110
argumentHandler = new ArgumentHandler(argv);
111
log = new Log(out, argumentHandler);
112
113
// execute test and display results
114
try {
115
log.display("\n>>> Preparing debugee for testing \n");
116
117
// launch debuggee
118
binder = new Binder(argumentHandler, log);
119
log.display("Launching debugee");
120
debugee = binder.bindToDebugee(DEBUGEE_CLASS_NAME);
121
transport = debugee.getTransport();
122
pipe = debugee.createIOPipe();
123
124
// make debuggee ready for testing
125
prepareDebugee();
126
127
// work with prepared debuggee
128
try {
129
log.display("\n>>> Checking VM capability \n");
130
131
// check for VM capability
132
log.display("Checking VM capability: " + VM_CAPABILITY_NAME);
133
if (!debugee.getNewCapability(VM_CAPABILITY_NUMBER, VM_CAPABILITY_NAME)) {
134
out.println("TEST PASSED: unsupported VM capability: "
135
+ VM_CAPABILITY_NAME);
136
return PASSED;
137
}
138
139
log.display("\n>>> Obtaining requred data from debugee \n");
140
141
// query debuggee for classID of tested class
142
log.display("Getting classID by signature:\n"
143
+ " " + TESTED_CLASS_SIGNATURE);
144
long classID = debugee.getReferenceTypeID(TESTED_CLASS_SIGNATURE);
145
log.display(" got classID: " + classID);
146
147
// query debuggee for methodID of tested method (declared in the class)
148
log.display("Getting methodID by name: " + TESTED_METHOD_NAME);
149
long methodID = debugee.getMethodID(classID, TESTED_METHOD_NAME, true);
150
log.display(" got methodID: " + methodID);
151
152
// perform testing JDWP command
153
log.display("\n>>> Testing JDWP command \n");
154
testCommand(classID, methodID);
155
156
} finally {
157
// quit debugee
158
log.display("\n>>> Finishing test \n");
159
quitDebugee();
160
}
161
162
} catch (Failure e) {
163
log.complain("TEST FAILED: " + e.getMessage());
164
success = false;
165
} catch (Exception e) {
166
e.printStackTrace(out);
167
log.complain("Caught unexpected exception while running the test:\n\t" + e);
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 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
* Perform testing JDWP command for specified TypeID.
230
*/
231
void testCommand(long classID, long methodID) {
232
// create command packet and fill requred out data
233
log.display("Create command packet:");
234
log.display("Command: " + JDWP_COMMAND_NAME);
235
CommandPacket command = new CommandPacket(JDWP_COMMAND_ID);
236
log.display(" referenceTypeID: " + classID);
237
command.addReferenceTypeID(classID);
238
log.display(" methodID: " + methodID);
239
command.addMethodID(methodID);
240
command.setLength();
241
242
// send command packet to debugee
243
try {
244
log.display("Sending command packet:\n" + command);
245
transport.write(command);
246
} catch (IOException e) {
247
log.complain("Unable to send command packet:\n\t" + e);
248
success = false;
249
return;
250
}
251
252
ReplyPacket reply = new ReplyPacket();
253
254
// receive reply packet from debugee
255
try {
256
log.display("Waiting for reply packet");
257
transport.read(reply);
258
log.display("Reply packet received:\n" + reply);
259
} catch (IOException e) {
260
log.complain("Unable to read reply packet:\n\t" + e);
261
success = false;
262
return;
263
}
264
265
// check reply packet header
266
try{
267
log.display("Checking reply packet header");
268
reply.checkHeader(command.getPacketID());
269
} catch (BoundException e) {
270
log.complain("Bad header of reply packet:\n\t" + e.getMessage());
271
success = false;
272
return;
273
}
274
275
// start parsing reply packet data
276
log.display("Parsing reply packet:");
277
reply.resetPosition();
278
279
// extract boolean result
280
byte isObsolete = 0;
281
try {
282
isObsolete = reply.getByte();
283
log.display(" isObsolete: " + isObsolete);
284
} catch (BoundException e) {
285
log.complain("Unable to extract isObsolete value from reply packet:\n\t"
286
+ e.getMessage());
287
success = false;
288
return;
289
}
290
291
// check for extra data in reply packet
292
if (!reply.isParsed()) {
293
log.complain("Extra trailing bytes found in reply packet at: "
294
+ reply.offsetString());
295
success = false;
296
}
297
298
// check that result value is false
299
if (isObsolete != 0) {
300
log.complain("Unexpected true isObsolete value received for not obsolete method: "
301
+ isObsolete);
302
success = false;
303
}
304
}
305
306
}
307
308