Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/EventQueue/remove/remove002.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.jdi.EventQueue.remove;
25
26
import com.sun.jdi.VirtualMachine;
27
import com.sun.jdi.request.EventRequest;
28
import com.sun.jdi.VMDisconnectedException;
29
import com.sun.jdi.event.*;
30
31
import java.io.*;
32
33
import nsk.share.*;
34
import nsk.share.jpda.*;
35
import nsk.share.jdi.*;
36
37
/**
38
* The test checks that a VMDisconnectedException thrown by
39
* the JDI method <b>com.sun.jdi.request.EventQueue.remove()</b>
40
* will be preceded by a <code>VMDisconnectEvent</code>
41
* after <code>com.sun.jdi.VirtualMachine.dispose()</code> call.
42
*/
43
public class remove002 {
44
public static final int PASSED = 0;
45
public static final int FAILED = 2;
46
public static final int JCK_STATUS_BASE = 95;
47
static final String DEBUGGEE_CLASS =
48
"nsk.jdi.EventQueue.remove.remove002t";
49
static final String COMMAND_READY = "ready";
50
static final String COMMAND_QUIT = "quit";
51
52
private ArgumentHandler argHandler;
53
private Log log;
54
private IOPipe pipe;
55
private Debugee debuggee;
56
private CheckEvents chkEvents;
57
private EventQueue eventQ;
58
private volatile int tot_res = FAILED;
59
60
public static void main(String argv[]) {
61
System.exit(run(argv,System.out) + JCK_STATUS_BASE);
62
}
63
64
public static int run(String argv[], PrintStream out) {
65
return new remove002().runIt(argv, out);
66
}
67
68
private int runIt(String args[], PrintStream out) {
69
argHandler = new ArgumentHandler(args);
70
log = new Log(out, argHandler);
71
Binder binder = new Binder(argHandler, log);
72
73
debuggee = binder.bindToDebugee(DEBUGGEE_CLASS);
74
debuggee.redirectStderr(log, "remove002t.err> ");
75
pipe = debuggee.createIOPipe();
76
VirtualMachine vm = debuggee.VM();
77
78
eventQ = vm.eventQueue();
79
chkEvents = new CheckEvents();
80
chkEvents.setDaemon(true);
81
chkEvents.start();
82
83
debuggee.resume();
84
String cmd = pipe.readln();
85
if (!cmd.equals(COMMAND_READY)) {
86
log.complain("TEST BUG: unknown debuggee's command: " + cmd);
87
tot_res = FAILED;
88
return quitDebuggee(FAILED);
89
}
90
91
log.display("Invoking VirtualMachine.dispose() ...");
92
vm.dispose();
93
94
return quitDebuggee(PASSED);
95
}
96
97
class CheckEvents extends Thread {
98
public void run() {
99
boolean gotVMDisconnect = false; // VMDisconnectEvent is received
100
boolean gotVMDeath = false; // VMDeathEvent is received
101
EventSet eventSet = null;
102
103
log.display("CheckEvents: starts JDI events processing");
104
while (true) {
105
try {
106
eventSet = eventQ.remove();
107
EventIterator eventIter = eventSet.eventIterator();
108
while (eventIter.hasNext()) {
109
Event event = eventIter.nextEvent();
110
if (event instanceof VMDisconnectEvent) {
111
gotVMDisconnect = true;
112
log.display("CheckEvents: got expected VMDisconnectEvent");
113
break;
114
} else if (event instanceof VMStartEvent) {
115
log.display("CheckEvents: got VMStartEvent");
116
} else if (event instanceof VMDeathEvent) {
117
gotVMDeath = true;
118
log.display("CheckEvents: got VMDeathEvent");
119
}
120
if (!gotVMDisconnect && !gotVMDeath &&
121
eventSet.suspendPolicy() !=
122
EventRequest.SUSPEND_NONE) {
123
log.display("CheckEvents: calling EventSet.resume() ...");
124
eventSet.resume();
125
}
126
}
127
} catch(InterruptedException e) {
128
log.complain("TEST INCOMPLETE: caught " + e);
129
tot_res = FAILED;
130
} catch(VMDisconnectedException e) {
131
if (gotVMDisconnect) {
132
log.display("\nCHECK PASSED: caught expected VMDisconnectedException preceded by a VMDisconnectEvent\n");
133
tot_res = PASSED;
134
} else {
135
log.complain("\nTEST FAILED: caught VMDisconnectedException without preceding VMDisconnectEvent\n");
136
e.printStackTrace();
137
tot_res = FAILED;
138
}
139
break;
140
}
141
}
142
log.display("CheckEvents: stopped JDI events processing");
143
}
144
}
145
146
private int quitDebuggee(int stat) {
147
if (chkEvents != null) {
148
try {
149
if (chkEvents.isAlive())
150
chkEvents.join(argHandler.getWaitTime()*60000);
151
} catch (InterruptedException e) {
152
log.complain("TEST INCOMPLETE: caught InterruptedException "
153
+ e);
154
tot_res = FAILED;
155
}
156
if (chkEvents.isAlive()) {
157
if (stat == PASSED) {
158
log.complain("TEST FAILED: CheckEvents thread is still alive,\n"
159
+ "\tbut it should stop JDI events processing and exit");
160
chkEvents.interrupt();
161
tot_res = FAILED;
162
}
163
}
164
}
165
166
pipe.println(COMMAND_QUIT);
167
debuggee.waitFor();
168
int debStat = debuggee.getStatus();
169
if (debStat != (JCK_STATUS_BASE + PASSED)) {
170
log.complain("TEST FAILED: debuggee's process finished with status: "
171
+ debStat);
172
tot_res = FAILED;
173
} else
174
log.display("Debuggee's process finished with status: "
175
+ debStat);
176
177
return tot_res;
178
}
179
}
180
181