Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/AllClassesWithGeneric/allclswithgeneric001.java
41161 views
1
/*
2
* Copyright (c) 2003, 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.AllClassesWithGeneric;
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
/**
34
* This test checks that the JDWP command <code>AllClassesWithGeneric</code>
35
* from the <code>VirtualMachine</code> command set returns generic signature
36
* information properly.<br>
37
* Debuggee part of the test creates instances of several tested classes. Some
38
* of the classes are generic. Debugger part obtains signature information of
39
* all loaded classes by sending the tested JDWP command. Proper generic
40
* signature should be returned for each tested class which is generic, or
41
* an empty string for non-generic one. All tested classes should be found
42
* in reply packet as well.
43
*/
44
public class allclswithgeneric001 {
45
static final String DEBUGGEE_CLASS =
46
"nsk.jdwp.VirtualMachine.AllClassesWithGeneric.allclswithgeneric001t";
47
48
static final String JDWP_COMMAND_NAME = "VirtualMachine.AllClassesWithGeneric";
49
static final int JDWP_COMMAND_ID =
50
JDWP.Command.VirtualMachine.AllClassesWithGeneric;
51
52
static final String COMMAND_READY = "ready";
53
static final String COMMAND_QUIT = "quit";
54
55
static final String[][] classes = {
56
{"Lnsk/jdwp/VirtualMachine/AllClassesWithGeneric/allclswithgeneric001t;",
57
"NULL"},
58
59
{"Lnsk/jdwp/VirtualMachine/AllClassesWithGeneric/allclswithgeneric001b;",
60
"<L:Ljava/lang/String;>Ljava/lang/Object;"},
61
62
{"Lnsk/jdwp/VirtualMachine/AllClassesWithGeneric/allclswithgeneric001c;",
63
"<A:Ljava/lang/Object;B:Ljava/lang/Integer;>Ljava/lang/Object;"},
64
65
{"Lnsk/jdwp/VirtualMachine/AllClassesWithGeneric/allclswithgeneric001d;",
66
"<T:Ljava/lang/Object;>Ljava/lang/Object;Lnsk/jdwp/VirtualMachine/AllClassesWithGeneric/allclswithgeneric001if<TT;>;"},
67
68
{"Lnsk/jdwp/VirtualMachine/AllClassesWithGeneric/allclswithgeneric001e;",
69
"NULL"},
70
71
{"Lnsk/jdwp/VirtualMachine/AllClassesWithGeneric/allclswithgeneric001if;",
72
"<I:Ljava/lang/Object;>Ljava/lang/Object;"},
73
74
{"Lnsk/jdwp/VirtualMachine/AllClassesWithGeneric/allclswithgeneric001f;",
75
"NULL"},
76
77
{"Lnsk/jdwp/VirtualMachine/AllClassesWithGeneric/allclswithgeneric001g;",
78
"<E:Lnsk/jdwp/VirtualMachine/AllClassesWithGeneric/allclswithgeneric001e;:Lnsk/jdwp/VirtualMachine/AllClassesWithGeneric/allclswithgeneric001if;>Ljava/lang/Object;"},
79
80
{"Lnsk/jdwp/VirtualMachine/AllClassesWithGeneric/allclswithgeneric001h;",
81
"<A1:Ljava/lang/Object;B1:Ljava/lang/Object;C1:Ljava/lang/Object;>Lnsk/jdwp/VirtualMachine/AllClassesWithGeneric/allclswithgeneric001d<TA1;>;Lnsk/jdwp/VirtualMachine/AllClassesWithGeneric/allclswithgeneric001if2<TA1;TB1;TC1;>;"}
82
};
83
84
static final int CLS_NUM = classes.length;
85
86
private int foundClasses[] = new int[CLS_NUM];
87
88
private Log log;
89
90
public static void main(String argv[]) {
91
System.exit(run(argv,System.out) + Consts.JCK_STATUS_BASE);
92
}
93
94
public static int run(String argv[], PrintStream out) {
95
return new allclswithgeneric001().runThis(argv, out);
96
}
97
98
public int runThis(String argv[], PrintStream out) {
99
ArgumentHandler argumentHandler = new ArgumentHandler(argv);
100
log = new Log(out, argumentHandler);
101
boolean result = true;
102
103
try {
104
for(int i=0; i<CLS_NUM; i++)
105
foundClasses[i] = 0;
106
107
Binder binder = new Binder(argumentHandler, log);
108
109
log.display("Starting debuggee VM ...");
110
Debugee debuggee = binder.bindToDebugee(DEBUGGEE_CLASS);
111
112
Transport transport = debuggee.getTransport();
113
IOPipe pipe = debuggee.createIOPipe();
114
115
log.display("Waiting for VM_INIT event ...");
116
debuggee.waitForVMInit();
117
118
log.display("Querying for IDSizes ...");
119
debuggee.queryForIDSizes();
120
121
log.display("Resuming debuggee VM ...");
122
debuggee.resume();
123
124
log.display("Waiting for command: " + COMMAND_READY
125
+ " ...");
126
String cmd = pipe.readln();
127
log.display(" ... Received command: " + cmd);
128
129
try {
130
/////// begin test of JDWP command
131
log.display("\n>>>>>> Create command " + JDWP_COMMAND_NAME);
132
CommandPacket command = new CommandPacket(JDWP_COMMAND_ID);
133
134
log.display("Sending command packet:\n" + command);
135
transport.write(command);
136
137
log.display("\nWaiting for reply packet ...");
138
ReplyPacket reply = new ReplyPacket();
139
transport.read(reply);
140
log.display(" ... Reply packet received:\n" + reply);
141
142
log.display("\nChecking reply packet header");
143
reply.checkHeader(command.getPacketID());
144
145
/* parsing of reply data:
146
int classes - Number of reference types that follow
147
148
---- Repeated 'classes' times:
149
byte refTypeTag - Kind of following reference type.
150
referenceTypeID typeID - Loaded reference type.
151
string signature - The JNI signature for the loaded reference type.
152
string genericSignature - The generic signature for the loaded reference type
153
or an empty string if there is none.
154
int status - The current class status.
155
----
156
*/
157
log.display("\nParsing reply packet:");
158
reply.resetPosition();
159
160
int cls_num = reply.getInt();
161
log.display("\tclasses: " + cls_num);
162
163
for (int i=0; i<cls_num; i++) {
164
byte refTypeTag = reply.getByte();
165
long typeID = reply.getReferenceTypeID();
166
String signature = reply.getString();
167
String genSignature = reply.getString();
168
int status = reply.getInt();
169
170
int idx = findClass(signature);
171
if (idx != -1) {
172
foundClasses[idx]++;
173
174
log.display("\n--> found tested class "
175
+ classes[idx][0] + " :"
176
+ "\n\t\trefTypeTag: " + refTypeTag
177
+ "\n\t\ttypeID: " + typeID
178
+ "\n\t\tsignature: " + signature);
179
180
if (genSignature.length() == 0) // a non-generic class
181
genSignature = "NULL";
182
if (!genSignature.equals(classes[idx][1])) {
183
log.complain("TEST FAILED: Unexpected generic signature of tested class #"
184
+ (i+1) + " (" + classes[idx][0] + ")"
185
+ " in the reply packet:"
186
+ "\n\tGot: " + genSignature
187
+ "\n\tExpected: " + classes[idx][1] + "\n");
188
result = false;
189
}
190
else
191
log.display("\t\tgeneric signature: " + genSignature);
192
193
log.display("\t\tstatus: " + status);
194
}
195
}
196
197
if (!reply.isParsed()) {
198
log.complain("TEST FAILED: Extra trailing bytes found in reply packet at: "
199
+ reply.currentPosition());
200
result = false;
201
} else
202
log.display("\n<<<<<< Reply packet parsed");
203
/////// end test of JDWP command
204
205
for (int i=0; i<CLS_NUM; i++)
206
if (foundClasses[i] != 1) {
207
result = false;
208
log.complain("TEST FAILED: Unexpected number of reference types for the tested class\n\t"
209
+ classes[i][0] + "\n\tin reply packet on "
210
+ JDWP_COMMAND_NAME
211
+ ":\n\tGot: " + foundClasses[i]
212
+ "\n\tExpected: 1");
213
}
214
215
} catch (Exception e) {
216
e.printStackTrace(out);
217
log.complain("Caught exception while testing JDWP command: "
218
+ e);
219
result = false;
220
} finally {
221
log.display("Sending command: " + COMMAND_QUIT + " ...");
222
pipe.println(COMMAND_QUIT);
223
224
log.display("Waiting for debuggee exits ...");
225
int code = debuggee.waitFor();
226
if (code == Consts.JCK_STATUS_BASE + Consts.TEST_PASSED) {
227
log.display(" ... Debuggee PASSED with the exit code: "
228
+ code);
229
} else {
230
log.complain(" ... Debuggee FAILED with the exit code: "
231
+ code);
232
result = false;
233
}
234
}
235
236
} catch (Exception e) {
237
e.printStackTrace(out);
238
log.complain("Caught unexpected exception while communicating with debugee: "
239
+ e);
240
result = false;
241
}
242
243
if (!result)
244
return Consts.TEST_FAILED;
245
246
return Consts.TEST_PASSED;
247
}
248
249
private int findClass(String cls) {
250
for (int i=0; i<CLS_NUM; i++)
251
if (cls.equals(classes[i][0]))
252
return i; // the tested class found
253
254
return -1; // the tested class not found
255
}
256
}
257
258