Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/EventSet/resume/resume008.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.EventSet.resume;
25
26
import nsk.share.*;
27
import nsk.share.jpda.*;
28
import nsk.share.jdi.*;
29
30
import com.sun.jdi.*;
31
import com.sun.jdi.event.*;
32
import com.sun.jdi.request.*;
33
34
import java.util.*;
35
import java.io.*;
36
37
import static nsk.share.Consts.TEST_FAILED;
38
39
/**
40
* The test for the implementation of an object of the type
41
* EventSet.
42
*
43
* The test checks that results of the method
44
* <code>com.sun.jdi.EventSet.resume()</code>
45
* complies with its spec.
46
*
47
* Test cases include all three possible suspensions, NONE,
48
* EVENT_THREAD, and ALL, for ThreadStartEvent sets.
49
*
50
* To check up on the method, a debugger,
51
* upon getting new set for the EventSet,
52
* suspends VM with the method VirtualMachine.suspend(),
53
* gets the List of debuggee's threads calling VM.allThreads(),
54
* invokes the method EventSet.resume(), and
55
* gets another List of debuggee's threads.
56
* The debugger then compares values of
57
* each thread's suspendCount from first and second Lists.
58
*
59
* The test works as follows.
60
* - The debugger sets up a ThreadStartRequest, resumes
61
* the debuggee, and waits for the ThreadStartEvent.
62
* - The debuggee creates and starts new thread
63
* to be resulting in the event.
64
* - Upon getting new event, the debugger
65
* performs the check corresponding to the event.
66
* - The debugger informs the debuggee when it completes
67
* each test case, so it will wait before hitting
68
* communication breakpoints.
69
* This prevents the breakpoint SUSPEND_ALL policy
70
* disrupting the first test case check for
71
* SUSPEND_NONE, if the debuggee gets ahead of
72
* the debugger processing.
73
*/
74
75
public class resume008 extends TestDebuggerType1 {
76
77
78
public static void main (String argv[]) {
79
System.exit(run(argv, System.out) + Consts.JCK_STATUS_BASE);
80
}
81
82
public static int run (String argv[], PrintStream out) {
83
debuggeeName = "nsk.jdi.EventSet.resume.resume008a";
84
return new resume008().runThis(argv, out);
85
}
86
87
private String testedClassName = "nsk.jdi.EventSet.resume.TestClass";
88
89
90
protected void testRun() {
91
92
EventRequest eventRequest = null;
93
94
final int SUSPEND_NONE = EventRequest.SUSPEND_NONE;
95
final int SUSPEND_THREAD = EventRequest.SUSPEND_EVENT_THREAD;
96
final int SUSPEND_ALL = EventRequest.SUSPEND_ALL;
97
98
ReferenceType testClassReference = null;
99
100
101
for (int i = 0; ; i++) {
102
103
if (!shouldRunAfterBreakpoint()) {
104
vm.resume();
105
break;
106
}
107
108
109
display(":::::: case: # " + i);
110
111
switch (i) {
112
113
case 0:
114
eventRequest = settingThreadStartRequest (
115
SUSPEND_NONE, "ThreadStartRequest1");
116
break;
117
118
case 1:
119
eventRequest = settingThreadStartRequest (
120
SUSPEND_THREAD, "ThreadStartRequest2");
121
break;
122
123
case 2:
124
eventRequest = settingThreadStartRequest (
125
SUSPEND_ALL, "ThreadStartRequest3");
126
break;
127
128
129
default:
130
throw new Failure("** default case 2 **");
131
}
132
133
display("......waiting for new ThreadStartEvent : " + i);
134
EventSet eventSet = eventHandler
135
.waitForRequestedEventSet(new EventRequest[]{eventRequest},
136
waitTime, true);
137
138
EventIterator eventIterator = eventSet.eventIterator();
139
Event newEvent = eventIterator.nextEvent();
140
141
if ( !(newEvent instanceof ThreadStartEvent)) {
142
setFailedStatus("ERROR: new event is not ThreadStartEvent");
143
} else {
144
145
String property = (String) newEvent.request().getProperty("number");
146
display(" got new ThreadStartEvent with propety 'number' == "
147
+ property);
148
149
display("......checking up on EventSet.resume()");
150
display("......--> vm.suspend();");
151
vm.suspend();
152
153
display(" getting : Map<String, Integer> suspendsCounts1");
154
155
Map<String, Integer> suspendsCounts1 = new HashMap<String, Integer>();
156
for (ThreadReference threadReference : vm.allThreads()) {
157
suspendsCounts1.put(threadReference.name(),
158
threadReference.suspendCount());
159
}
160
display(suspendsCounts1.toString());
161
162
display(" eventSet.resume;");
163
eventSet.resume();
164
165
display(" getting : Map<String, Integer> suspendsCounts2");
166
Map<String, Integer> suspendsCounts2 = new HashMap<String, Integer>();
167
for (ThreadReference threadReference : vm.allThreads()) {
168
suspendsCounts2.put(threadReference.name(),
169
threadReference.suspendCount());
170
}
171
display(suspendsCounts2.toString());
172
173
display(" getting : int policy = eventSet.suspendPolicy();");
174
int policy = eventSet.suspendPolicy();
175
176
switch (policy) {
177
178
case SUSPEND_NONE :
179
display(" case SUSPEND_NONE");
180
for (String threadName : suspendsCounts1.keySet()) {
181
display(" checking " + threadName);
182
if (!suspendsCounts2.containsKey(threadName)) {
183
complain("ERROR: couldn't get ThreadReference for "
184
+ threadName);
185
testExitCode = TEST_FAILED;
186
break;
187
}
188
int count1 = suspendsCounts1.get(threadName);
189
int count2 = suspendsCounts2.get(threadName);
190
if (count1 != count2) {
191
complain("ERROR: suspendCounts don't match for : "
192
+ threadName);
193
complain("before resuming : " + count1);
194
complain("after resuming : " + count2);
195
testExitCode = TEST_FAILED;
196
break;
197
}
198
}
199
break;
200
201
case SUSPEND_THREAD :
202
display(" case SUSPEND_THREAD");
203
for (String threadName : suspendsCounts1.keySet()) {
204
display("checking " + threadName);
205
if (!suspendsCounts2.containsKey(threadName)) {
206
complain("ERROR: couldn't get ThreadReference for "
207
+ threadName);
208
testExitCode = TEST_FAILED;
209
break;
210
}
211
int count1 = suspendsCounts1.get(threadName);
212
int count2 = suspendsCounts2.get(threadName);
213
String eventThreadName = ((ThreadStartEvent)newEvent)
214
.thread().name();
215
int expectedValue = count2 +
216
(eventThreadName.equals(threadName) ? 1 : 0);
217
if (count1 != expectedValue) {
218
complain("ERROR: suspendCounts don't match for : "
219
+ threadName);
220
complain("before resuming : " + count1);
221
complain("after resuming : " + count2);
222
testExitCode = TEST_FAILED;
223
break;
224
}
225
}
226
break;
227
228
case SUSPEND_ALL :
229
display(" case SUSPEND_ALL");
230
for (String threadName : suspendsCounts1.keySet()) {
231
display("checking " + threadName);
232
if (!newEvent.request().equals(eventRequest))
233
break;
234
if (!suspendsCounts2.containsKey(threadName)) {
235
complain("ERROR: couldn't get ThreadReference for "
236
+ threadName);
237
testExitCode = TEST_FAILED;
238
break;
239
}
240
int count1 = suspendsCounts1.get(threadName);
241
int count2 = suspendsCounts2.get(threadName);
242
if (count1 != count2 + 1) {
243
complain("ERROR: suspendCounts don't match for : "
244
+ threadName);
245
complain("before resuming : " + count1);
246
complain("after resuming : " + count2);
247
testExitCode = TEST_FAILED;
248
break;
249
}
250
}
251
break;
252
default: throw new Failure("** default case 1 **");
253
}
254
informDebuggeeTestCase(i);
255
256
}
257
display("......--> vm.resume()");
258
vm.resume();
259
}
260
return;
261
}
262
private ThreadStartRequest settingThreadStartRequest(int suspendPolicy,
263
String property) {
264
try {
265
ThreadStartRequest tsr = eventRManager.createThreadStartRequest();
266
tsr.addCountFilter(1);
267
tsr.setSuspendPolicy(suspendPolicy);
268
tsr.putProperty("number", property);
269
return tsr;
270
} catch ( Exception e ) {
271
throw new Failure("** FAILURE to set up ThreadStartRequest **");
272
}
273
}
274
/**
275
* Inform debuggee which thread test the debugger has completed.
276
* Used for synchronization, so the debuggee does not move too quickly.
277
* @param testCase index of just completed test
278
*/
279
void informDebuggeeTestCase(int testCase) {
280
try {
281
((ClassType)debuggeeClass)
282
.setValue(debuggeeClass.fieldByName("testCase"),
283
vm.mirrorOf(testCase));
284
} catch (InvalidTypeException ite) {
285
throw new Failure("** FAILURE setting testCase **");
286
} catch (ClassNotLoadedException cnle) {
287
throw new Failure("** FAILURE notifying debuggee **");
288
} catch (VMDisconnectedException e) {
289
throw new Failure("** FAILURE debuggee connection **");
290
}
291
}
292
}
293
294