Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadReference/ThreadGroup/threadgroup001.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.ThreadReference.ThreadGroup;
25
26
import java.io.*;
27
import java.util.*;
28
29
import nsk.share.*;
30
import nsk.share.jpda.*;
31
import nsk.share.jdwp.*;
32
33
public class threadgroup001 {
34
static final int JCK_STATUS_BASE = 95;
35
static final int PASSED = 0;
36
static final int FAILED = 2;
37
static final String PACKAGE_NAME = "nsk.jdwp.ThreadReference.ThreadGroup";
38
static final String TEST_CLASS_NAME = PACKAGE_NAME + "." + "threadgroup001";
39
static final String DEBUGEE_CLASS_NAME = TEST_CLASS_NAME + "a";
40
41
static final String JDWP_COMMAND_NAME = "ThreadReference.ThreadGroup";
42
static final int JDWP_COMMAND_ID = JDWP.Command.ThreadReference.ThreadGroup;
43
44
public static void main (String argv[]) {
45
System.exit(run(argv,System.out) + JCK_STATUS_BASE);
46
}
47
48
public static int run(String argv[], PrintStream out) {
49
return new threadgroup001().runIt(argv, out);
50
}
51
52
public int runIt(String argv[], PrintStream out) {
53
54
boolean success = true;
55
56
try {
57
ArgumentHandler argumentHandler = new ArgumentHandler(argv);
58
Log log = new Log(out, argumentHandler);
59
60
try {
61
62
Binder binder = new Binder(argumentHandler, log);
63
log.display("Start debugee VM");
64
Debugee debugee = binder.bindToDebugee(DEBUGEE_CLASS_NAME);
65
Transport transport = debugee.getTransport();
66
IOPipe pipe = debugee.createIOPipe();
67
68
log.display("Waiting for VM_INIT event");
69
debugee.waitForVMInit();
70
71
log.display("Querying for IDSizes");
72
debugee.queryForIDSizes();
73
74
log.display("Resume debugee VM");
75
debugee.resume();
76
77
log.display("Waiting for command: " + "ready");
78
String cmd = pipe.readln();
79
log.display("Received command: " + cmd);
80
81
82
try {
83
84
// get top level thread groups
85
86
log.display("Getting IDs for top level thread groups");
87
88
long[] threadGroupIDs = null;
89
int groups = 0;
90
91
{
92
log.display("Create command packet " + "TopLevelThreadGroups");
93
CommandPacket command = new CommandPacket(JDWP.Command.VirtualMachine.TopLevelThreadGroups);
94
95
log.display("Waiting for reply to command");
96
ReplyPacket reply = debugee.receiveReplyFor(command);
97
log.display("Valid reply packet received");
98
99
log.display("Parsing reply packet:");
100
reply.resetPosition();
101
102
groups = reply.getInt();
103
log.display(" groups: " + groups);
104
105
threadGroupIDs = new long[groups];
106
107
for (int i = 0; i < groups; i++) {
108
long threadGroupID = reply.getObjectID();
109
log.display(" #" + i + " threadGroupID: " + threadGroupID);
110
threadGroupIDs[i] = threadGroupID;
111
}
112
113
if (groups < 0) {
114
log.complain("Negative number of thread groups returned while getting top level thread groups IDs: " + groups);
115
success = false;
116
}
117
118
if (groups == 0) {
119
log.complain("No thread groups IDs returned while getting top level thread groups IDs: " + groups);
120
success = false;
121
}
122
123
}
124
125
// get threads from all thread groups found
126
127
boolean found = false;
128
long checkedThreadGroupID = 0;
129
130
long[] threadIDs = null;
131
int threads = 0;
132
133
for (int i = 0; i < groups; i++) {
134
checkedThreadGroupID = threadGroupIDs[i];
135
log.display("Getting IDs of the thread from thread group: #" + i);
136
137
log.display("Create command packet " +
138
"ThreadGroupReference.Children");
139
CommandPacket command = new CommandPacket(JDWP.Command.ThreadGroupReference.Children);
140
command.addObjectID(checkedThreadGroupID);
141
command.setLength();
142
143
log.display("Waiting for reply to command");
144
ReplyPacket reply = debugee.receiveReplyFor(command);
145
log.display("Valid reply packet received");
146
147
log.display("Parsing reply packet:");
148
reply.resetPosition();
149
150
threads = reply.getInt();
151
log.display(" threads: " + threads);
152
153
threadIDs = new long[threads];
154
155
for (int j = 0; j < threads; j++) {
156
long threadID = reply.getObjectID();
157
log.display(" #" + j + " threadID: " + threadID);
158
threadIDs[j] = threadID;
159
}
160
161
if (threads < 0) {
162
log.complain("Negative number of threads in the thread group: " + threads);
163
success = false;
164
}
165
166
if (threads > 0) {
167
log.display("Testing threads from thread group: #" + i);
168
found = true;
169
}
170
}
171
172
if (!found) {
173
log.complain("No threads found in all top level thread groups");
174
success = false;
175
}
176
177
// begin test of JDWP command
178
179
for (int i = 0; i < threads; i++) {
180
181
long threadID = threadIDs[i];
182
183
log.display("");
184
log.display("Getting ThreadGroup ID for " + i + " thread ID: "
185
+ threadID);
186
log.display("Create command " + JDWP_COMMAND_NAME
187
+ " with thread ID: " + threadID);
188
CommandPacket command = new CommandPacket(JDWP_COMMAND_ID);
189
command.addObjectID(threadID);
190
command.setLength();
191
192
log.display("Sending command packet:\n" + command);
193
transport.write(command);
194
195
log.display("Waiting for reply packet");
196
ReplyPacket reply = new ReplyPacket();
197
transport.read(reply);
198
log.display("Reply packet received:\n" + reply);
199
200
log.display("Checking reply packet header");
201
reply.checkHeader(command.getPacketID());
202
203
log.display("Parsing reply packet:");
204
reply.resetPosition();
205
206
long threadGroupID = reply.getObjectID();
207
log.display(" group: " + threadGroupID);
208
209
if (threadGroupID != checkedThreadGroupID) {
210
log.complain("Unexpected threadGroupID returned for a thread: " + threadGroupID
211
+ " (expected: " + checkedThreadGroupID + ")");
212
success = false;
213
}
214
215
if (! reply.isParsed()) {
216
log.complain("Extra trailing bytes found in reply packet at: " + reply.currentPosition());
217
success = false;
218
} else {
219
log.display("Reply packet parsed successfully");
220
}
221
222
}
223
224
// end test of JDWP command
225
226
} catch (Exception e) {
227
log.complain("Caught exception while testing JDWP command: " + e);
228
success = false;
229
} finally {
230
log.display("");
231
log.display("Sending command: " + "quit");
232
pipe.println("quit");
233
234
log.display("Waiting for debugee exits");
235
int code = debugee.waitFor();
236
if (code == JCK_STATUS_BASE + PASSED) {
237
log.display("Debugee PASSED with exit code: " + code);
238
} else {
239
log.complain("Debugee FAILED with exit code: " + code);
240
success = false;
241
}
242
}
243
244
} catch (Exception e) {
245
log.complain("Caught unexpected exception while communicating with debugee: " + e);
246
e.printStackTrace(out);
247
success = false;
248
}
249
250
if (!success) {
251
log.complain("TEST FAILED");
252
return FAILED;
253
}
254
255
} catch (Exception e) {
256
out.println("Caught unexpected exception while starting the test: " + e);
257
e.printStackTrace(out);
258
out.println("TEST FAILED");
259
return FAILED;
260
}
261
262
out.println("TEST PASSED");
263
return PASSED;
264
265
}
266
267
}
268
269