Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdwp/StringReference/Value/value001.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.StringReference.Value;
25
26
import nsk.share.*;
27
import nsk.share.jpda.*;
28
import nsk.share.jdwp.*;
29
30
import java.io.*;
31
import java.util.*;
32
33
public class value001 {
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.StringReference.Value";
38
static final String TEST_CLASS_NAME = PACKAGE_NAME + "." + "value001";
39
static final String DEBUGEE_CLASS_NAME = TEST_CLASS_NAME + "a";
40
41
static final String JDWP_COMMAND_NAME = "StringReference.Value";
42
static final int JDWP_COMMAND_ID = JDWP.Command.StringReference.Value;
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 value001().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
try {
82
83
// create string in debugee
84
85
String originalStringValue = "Testing string value";
86
long stringID = 0;
87
88
{
89
// Suspend debuggee to avoid GC
90
log.display("Suspending debuggee");
91
debugee.suspend();
92
log.display("Debuggee suspended");
93
94
log.display("Create command packet" + "CreateString"
95
+ " with string value: " + originalStringValue);
96
CommandPacket command = new CommandPacket(JDWP.Command.VirtualMachine.CreateString);
97
command.addString(originalStringValue);
98
command.setLength();
99
100
log.display("Waiting for reply to command");
101
ReplyPacket reply = debugee.receiveReplyFor(command);
102
log.display("Valid reply packet received");
103
104
log.display("Parsing reply packet");
105
reply.resetPosition();
106
107
stringID = reply.getObjectID();
108
log.display(" stringID: " + stringID);
109
110
// Disable garbage collection of the String
111
log.display("Disabling collection of String object");
112
command = new CommandPacket(JDWP.Command.ObjectReference.DisableCollection);
113
command.addObjectID(stringID);
114
command.setLength();
115
reply = debugee.receiveReplyFor(command);
116
reply.resetPosition();
117
log.display("Collection disabled");
118
119
// Resume debugee now that we have disabled collection of the String
120
log.display("Resuming debuggee");
121
debugee.resume();
122
log.display("Debuggee resumed");
123
}
124
125
// begint test of JDWP command
126
127
log.display("Create command packet" + JDWP_COMMAND_NAME
128
+ "with stringID: " + stringID);
129
CommandPacket command = new CommandPacket(JDWP_COMMAND_ID);
130
command.addObjectID(stringID);
131
command.setLength();
132
133
log.display("Sending command packet:\n" + command);
134
transport.write(command);
135
136
log.display("Waiting for reply packet");
137
ReplyPacket reply = new ReplyPacket();
138
transport.read(reply);
139
log.display("Reply packet received:\n" + reply);
140
141
log.display("Checking reply packet header");
142
reply.checkHeader(command.getPacketID());
143
144
log.display("Parsing reply packet:");
145
reply.resetPosition();
146
147
String stringValue = reply.getString();
148
log.display(" stringValue: " + stringValue);
149
150
if (! stringValue.equals(originalStringValue)) {
151
log.complain("Received value does not equals original value:"
152
+ originalStringValue);
153
success = false;
154
}
155
156
if (! reply.isParsed()) {
157
log.complain("Extra trailing bytes found in reply packet at: " + reply.currentPosition());
158
success = false;
159
} else {
160
log.display("Reply packet parsed successfully");
161
}
162
163
// end test of JDWP command
164
165
// Re-enable garbage collection of the String
166
log.display("Enabling collection of String object");
167
command = new CommandPacket(JDWP.Command.ObjectReference.EnableCollection);
168
command.addObjectID(stringID);
169
command.setLength();
170
reply = debugee.receiveReplyFor(command);
171
reply.resetPosition();
172
log.display("Collection enabled");
173
174
} catch (Exception e) {
175
log.complain("Caught exception while testing JDWP command: " + e);
176
success = false;
177
} finally {
178
log.display("Sending command: " + "quit");
179
pipe.println("quit");
180
181
log.display("Waiting for debugee exits");
182
int code = debugee.waitFor();
183
if (code == JCK_STATUS_BASE + PASSED) {
184
log.display("Debugee PASSED with exit code: " + code);
185
} else {
186
log.complain("Debugee FAILED with exit code: " + code);
187
success = false;
188
}
189
}
190
191
} catch (Exception e) {
192
log.complain("Caught unexpected exception while communicating with debugee: " + e);
193
e.printStackTrace(out);
194
success = false;
195
}
196
197
if (!success) {
198
log.complain("TEST FAILED");
199
return FAILED;
200
}
201
202
} catch (Exception e) {
203
out.println("Caught unexpected exception while starting the test: " + e);
204
e.printStackTrace(out);
205
out.println("TEST FAILED");
206
return FAILED;
207
}
208
209
out.println("TEST PASSED");
210
return PASSED;
211
212
}
213
214
}
215
216