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/resume009.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 ThreadDeathEvent 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 ThreadDeathRequest, resumes
61
* the debuggee, and waits for the ThreadDeathEvent.
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 resume009 extends TestDebuggerType1 {
76
77
public static void main (String argv[]) {
78
System.exit(run(argv, System.out) + Consts.JCK_STATUS_BASE);
79
}
80
81
public static int run (String argv[], PrintStream out) {
82
debuggeeName = "nsk.jdi.EventSet.resume.resume009a";
83
return new resume009().runThis(argv, out);
84
}
85
86
private String testedClassName = "nsk.jdi.EventSet.resume.TestClass";
87
88
89
protected void testRun() {
90
91
EventRequest eventRequest = null;
92
93
final int SUSPEND_NONE = EventRequest.SUSPEND_NONE;
94
final int SUSPEND_THREAD = EventRequest.SUSPEND_EVENT_THREAD;
95
final int SUSPEND_ALL = EventRequest.SUSPEND_ALL;
96
97
ReferenceType testClassReference = null;
98
99
100
for (int i = 0; ; i++) {
101
102
if (!shouldRunAfterBreakpoint()) {
103
vm.resume();
104
break;
105
}
106
107
108
display(":::::: case: # " + i);
109
110
switch (i) {
111
112
case 0:
113
eventRequest = settingThreadDeathRequest (
114
SUSPEND_NONE, "ThreadDeathRequest1");
115
break;
116
117
case 1:
118
eventRequest = settingThreadDeathRequest (
119
SUSPEND_THREAD, "ThreadDeathRequest2");
120
break;
121
122
case 2:
123
eventRequest = settingThreadDeathRequest (
124
SUSPEND_ALL, "ThreadDeathRequest3");
125
break;
126
127
128
default:
129
throw new Failure("** default case 2 **");
130
}
131
132
display("......waiting for new ThreadDeathEvent : " + i);
133
EventSet eventSet = eventHandler.waitForRequestedEventSet(new EventRequest[]{eventRequest}, waitTime, true);
134
135
EventIterator eventIterator = eventSet.eventIterator();
136
Event newEvent = eventIterator.nextEvent();
137
138
if ( !(newEvent instanceof ThreadDeathEvent)) {
139
setFailedStatus("ERROR: new event is not ThreadDeathEvent");
140
} else {
141
142
String property = (String) newEvent.request().getProperty("number");
143
display(" got new ThreadDeathEvent with propety 'number' == " + property);
144
145
display("......checking up on EventSet.resume()");
146
display("......--> vm.suspend();");
147
vm.suspend();
148
149
display(" getting : Map<String, Integer> suspendsCounts1");
150
151
Map<String, Integer> suspendsCounts1 = new HashMap<String, Integer>();
152
for (ThreadReference threadReference : vm.allThreads()) {
153
suspendsCounts1.put(threadReference.name(), threadReference.suspendCount());
154
}
155
display(suspendsCounts1.toString());
156
157
display(" eventSet.resume;");
158
eventSet.resume();
159
160
display(" getting : Map<String, Integer> suspendsCounts2");
161
Map<String, Integer> suspendsCounts2 = new HashMap<String, Integer>();
162
for (ThreadReference threadReference : vm.allThreads()) {
163
suspendsCounts2.put(threadReference.name(), threadReference.suspendCount());
164
}
165
166
display(" getting : int policy = eventSet.suspendPolicy();");
167
int policy = eventSet.suspendPolicy();
168
display(suspendsCounts2.toString());
169
170
switch (policy) {
171
172
case SUSPEND_NONE :
173
display(" case SUSPEND_NONE");
174
for (String threadName : suspendsCounts1.keySet()) {
175
display(" checking " + threadName);
176
if (!suspendsCounts2.containsKey(threadName)) {
177
complain("ERROR: couldn't get ThreadReference for " + threadName);
178
testExitCode = TEST_FAILED;
179
break;
180
}
181
int count1 = suspendsCounts1.get(threadName);
182
int count2 = suspendsCounts2.get(threadName);
183
if (count1 != count2) {
184
complain("ERROR: suspendCounts don't match for : " + threadName);
185
complain("before resuming : " + count1);
186
complain("after resuming : " + count2);
187
testExitCode = TEST_FAILED;
188
break;
189
}
190
}
191
break;
192
193
case SUSPEND_THREAD :
194
display(" case SUSPEND_THREAD");
195
for (String threadName : suspendsCounts1.keySet()) {
196
display("checking " + threadName);
197
if (!suspendsCounts2.containsKey(threadName)) {
198
complain("ERROR: couldn't get ThreadReference for " + threadName);
199
testExitCode = TEST_FAILED;
200
break;
201
}
202
int count1 = suspendsCounts1.get(threadName);
203
int count2 = suspendsCounts2.get(threadName);
204
String eventThreadName = ((ThreadDeathEvent)newEvent).thread().name();
205
int expectedValue = count2 + (eventThreadName.equals(threadName) ? 1 : 0);
206
if (count1 != expectedValue) {
207
complain("ERROR: suspendCounts don't match for : " + threadName);
208
complain("before resuming : " + count1);
209
complain("after resuming : " + count2);
210
testExitCode = TEST_FAILED;
211
break;
212
}
213
}
214
break;
215
216
case SUSPEND_ALL :
217
218
display(" case SUSPEND_ALL");
219
for (String threadName : suspendsCounts1.keySet()) {
220
display("checking " + threadName);
221
222
if (!newEvent.request().equals(eventRequest))
223
break;
224
if (!suspendsCounts2.containsKey(threadName)) {
225
complain("ERROR: couldn't get ThreadReference for " + threadName);
226
testExitCode = TEST_FAILED;
227
break;
228
}
229
int count1 = suspendsCounts1.get(threadName);
230
int count2 = suspendsCounts2.get(threadName);
231
if (count1 != count2 + 1) {
232
complain("ERROR: suspendCounts don't match for : " + threadName);
233
complain("before resuming : " + count1);
234
complain("after resuming : " + count2);
235
testExitCode = TEST_FAILED;
236
break;
237
}
238
}
239
break;
240
241
default: throw new Failure("** default case 1 **");
242
}
243
informDebuggeeTestCase(i);
244
}
245
246
display("......--> vm.resume()");
247
vm.resume();
248
}
249
return;
250
}
251
252
private ThreadDeathRequest settingThreadDeathRequest(int suspendPolicy,
253
String property) {
254
try {
255
ThreadDeathRequest tsr = eventRManager.createThreadDeathRequest();
256
tsr.addCountFilter(1);
257
tsr.setSuspendPolicy(suspendPolicy);
258
tsr.putProperty("number", property);
259
return tsr;
260
} catch ( Exception e ) {
261
throw new Failure("** FAILURE to set up ThreadDeathRequest **");
262
}
263
}
264
/**
265
* Inform debuggee which thread test the debugger has completed.
266
* Used for synchronization, so the debuggee does not move too quickly.
267
* @param testCase index of just completed test
268
*/
269
void informDebuggeeTestCase(int testCase) {
270
try {
271
((ClassType)debuggeeClass)
272
.setValue(debuggeeClass.fieldByName("testCase"),
273
vm.mirrorOf(testCase));
274
} catch (InvalidTypeException ite) {
275
throw new Failure("** FAILURE setting testCase **");
276
} catch (ClassNotLoadedException cnle) {
277
throw new Failure("** FAILURE notifying debuggee **");
278
} catch (VMDisconnectedException e) {
279
throw new Failure("** FAILURE debuggee connection **");
280
}
281
}
282
}
283
284