Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/Resume/resume001.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.VirtualMachine.Resume;
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 resume001 {
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.VirtualMachine.Resume";
38
static final String TEST_CLASS_NAME = PACKAGE_NAME + "." + "resume001";
39
static final String DEBUGEE_CLASS_NAME = TEST_CLASS_NAME + "a";
40
41
static final String JDWP_COMMAND_NAME = "VirtualMachine.Resume";
42
static final int JDWP_COMMAND_ID = JDWP.Command.VirtualMachine.Resume;
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 resume001().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
final Log log = new Log(out, argumentHandler);
59
long timeout = argumentHandler.getWaitTime() * 60 * 1000; // milliseconds
60
61
try {
62
63
Binder binder = new Binder(argumentHandler, log);
64
log.display("Start debugee VM");
65
Debugee debugee = binder.bindToDebugee(DEBUGEE_CLASS_NAME);
66
Transport transport = debugee.getTransport();
67
final IOPipe pipe = debugee.createIOPipe();
68
69
log.display("Waiting for VM_INIT event");
70
debugee.waitForVMInit();
71
72
log.display("Querying for IDSizes");
73
debugee.queryForIDSizes();
74
75
// begin test of JDWP command
76
77
try {
78
CommandPacket command = new CommandPacket(JDWP_COMMAND_ID);
79
80
log.display("Sending command packet:\n" + command);
81
transport.write(command);
82
83
log.display("Waiting for reply packet");
84
ReplyPacket reply = new ReplyPacket();
85
transport.read(reply);
86
log.display("Reply packet received:\n" + reply);
87
88
log.display("Checking reply packet header");
89
reply.checkHeader(command.getPacketID());
90
91
log.display("Parsing reply packet:");
92
reply.resetPosition();
93
94
if (! reply.isParsed()) {
95
log.complain("Extra bytes in reply packet at: " + reply.currentPosition());
96
success = false;
97
}
98
99
} catch (Exception e) {
100
log.complain("Caught exception: " + e);
101
success = false;
102
}
103
104
// check if debugee has been actually resumed
105
106
if (success) {
107
log.display("Waiting for debugee continues execution or timeout exceeds");
108
109
// separate thread for waiting for reply from debuggee
110
class TimeoutHandler extends Thread {
111
boolean success = false;
112
public void run() {
113
log.display("Waiting for command: " + "ready");
114
String cmd = pipe.readln();
115
log.display("Received command: " + cmd);
116
if (cmd.equals("ready")) {
117
success = true;
118
log.display("Debugee was resumed successfully");
119
} else {
120
log.complain("Unexpected command received: " + cmd);
121
}
122
}
123
}
124
125
// start separate thread
126
TimeoutHandler timeoutHandler = new TimeoutHandler();
127
timeoutHandler.start();
128
129
// wait for thread finished or timeout exceeds
130
try {
131
timeoutHandler.join(timeout);
132
if (timeoutHandler.isAlive()) {
133
log.display("Interrupting thread because timeout exceeds");
134
timeoutHandler.interrupt();
135
}
136
} catch (InterruptedException e) {
137
throw new Failure("Main thread interrupted: " + e);
138
}
139
140
// check resuts
141
if (!timeoutHandler.success) {
142
log.complain("Debugee has not been resumed by command");
143
success = false;
144
}
145
}
146
147
// end test of JDWP command
148
149
log.display("Sending command: " + "quit");
150
pipe.println("quit");
151
152
log.display("Waiting for debugee exits");
153
int code = debugee.waitFor();
154
if (code == JCK_STATUS_BASE + PASSED) {
155
log.display("Debugee PASSED: " + code);
156
} else {
157
log.complain("Debugee FAILED: " + code);
158
success = false;
159
}
160
161
} catch (Exception e) {
162
log.complain("Unexpected exception: " + e);
163
e.printStackTrace(out);
164
success = false;
165
}
166
167
if (!success) {
168
log.complain("TEST FAILED");
169
return FAILED;
170
}
171
172
} catch (Exception e) {
173
out.println("Unexpected exception: " + e);
174
e.printStackTrace(out);
175
out.println("TEST FAILED");
176
return FAILED;
177
}
178
179
out.println("TEST PASSED");
180
return PASSED;
181
182
}
183
184
}
185
186