Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/EventRequest/putProperty/putproperty001.java
41161 views
1
/*
2
* Copyright (c) 2001, 2020, 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.EventRequest.putProperty;
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
/**
38
* The test for the implementation of an object of the type <BR>
39
* EventRequest. <BR>
40
* <BR>
41
* The test checks that results of the method <BR>
42
* <code>com.sun.jdi.EventRequest.putProperty()</code> <BR>
43
* complies with its spec. <BR>
44
* <BR>
45
* The test checks up on following assertions: <BR>
46
* - a value of property is equal to one assigned by <BR>
47
* last method putProperty(key, value); <BR>
48
* - after calling putProperty(key, null) <BR>
49
* the value of the property 'key' is also null. <BR>
50
* The cases to check include Requests of all sub-types. <BR>
51
* <BR>
52
* The test has three phases and works as follows. <BR>
53
* <BR>
54
* In first phase, <BR>
55
* upon launching debuggee's VM which will be suspended, <BR>
56
* a debugger waits for the VMStartEvent within a predefined <BR>
57
* time interval. If no the VMStartEvent received, the test is FAILED. <BR>
58
* Upon getting the VMStartEvent, it makes the request for debuggee's <BR>
59
* ClassPrepareEvent with SUSPEND_EVENT_THREAD, resumes the VM, <BR>
60
* and waits for the event within the predefined time interval. <BR>
61
* If no the ClassPrepareEvent received, the test is FAILED. <BR>
62
* Upon getting the ClassPrepareEvent, <BR>
63
* the debugger sets up the breakpoint with SUSPEND_ALL <BR>
64
* within debuggee's special methodForCommunication(). <BR>
65
* <BR>
66
* In second phase to check the assertion, <BR>
67
* the debugger and the debuggee perform the following loop. <BR>
68
* - The debugger resumes the debuggee and waits for the BreakpointEvent.<BR>
69
* - The debuggee prepares new check case (as if) and invokes <BR>
70
* the methodForCommunication to be suspended and <BR>
71
* to inform the debugger with the event. <BR>
72
* - Upon getting the BreakpointEvent, <BR>
73
* the debugger performs the check case required. <BR>
74
* <BR>
75
* In third phase, at the end of the test, the debuggee changes <BR>
76
* the value of the "instruction" which the debugger and debuggee <BR>
77
* use to inform each other of needed actions, and both end. <BR>
78
* <BR>
79
*/
80
81
public class putproperty001 extends JDIBase {
82
83
public static void main (String argv[]) {
84
85
int result = run(argv, System.out);
86
87
System.exit(result + PASS_BASE);
88
}
89
90
public static int run (String argv[], PrintStream out) {
91
92
int exitCode = new putproperty001().runThis(argv, out);
93
94
if (exitCode != PASSED) {
95
System.out.println("TEST FAILED");
96
}
97
return testExitCode;
98
}
99
100
// ************************************************ test parameters
101
102
private String debuggeeName =
103
"nsk.jdi.EventRequest.putProperty.putproperty001a";
104
105
private String testedClassName =
106
"nsk.jdi.EventRequest.putProperty.TestClass11";
107
108
//====================================================== test program
109
110
private int runThis (String argv[], PrintStream out) {
111
112
argsHandler = new ArgumentHandler(argv);
113
logHandler = new Log(out, argsHandler);
114
Binder binder = new Binder(argsHandler, logHandler);
115
116
waitTime = argsHandler.getWaitTime() * 60000;
117
118
try {
119
log2("launching a debuggee :");
120
log2(" " + debuggeeName);
121
if (argsHandler.verbose()) {
122
debuggee = binder.bindToDebugee(debuggeeName + " -vbs");
123
} else {
124
debuggee = binder.bindToDebugee(debuggeeName);
125
}
126
if (debuggee == null) {
127
log3("ERROR: no debuggee launched");
128
return FAILED;
129
}
130
log2("debuggee launched");
131
} catch ( Exception e ) {
132
log3("ERROR: Exception : " + e);
133
log2(" test cancelled");
134
return FAILED;
135
}
136
137
debuggee.redirectOutput(logHandler);
138
139
vm = debuggee.VM();
140
141
eventQueue = vm.eventQueue();
142
if (eventQueue == null) {
143
log3("ERROR: eventQueue == null : TEST ABORTED");
144
vm.exit(PASS_BASE);
145
return FAILED;
146
}
147
148
log2("invocation of the method runTest()");
149
switch (runTest()) {
150
151
case 0 : log2("test phase has finished normally");
152
log2(" waiting for the debuggee to finish ...");
153
debuggee.waitFor();
154
155
log2("......getting the debuggee's exit status");
156
int status = debuggee.getStatus();
157
if (status != PASS_BASE) {
158
log3("ERROR: debuggee returned UNEXPECTED exit status: " +
159
status + " != PASS_BASE");
160
testExitCode = FAILED;
161
} else {
162
log2("......debuggee returned expected exit status: " +
163
status + " == PASS_BASE");
164
}
165
break;
166
167
default : log3("ERROR: runTest() returned unexpected value");
168
169
case 1 : log3("test phase has not finished normally: debuggee is still alive");
170
log2("......forcing: vm.exit();");
171
testExitCode = FAILED;
172
try {
173
vm.exit(PASS_BASE);
174
} catch ( Exception e ) {
175
log3("ERROR: Exception : " + e);
176
}
177
break;
178
179
case 2 : log3("test cancelled due to VMDisconnectedException");
180
log2("......trying: vm.process().destroy();");
181
testExitCode = FAILED;
182
try {
183
Process vmProcess = vm.process();
184
if (vmProcess != null) {
185
vmProcess.destroy();
186
}
187
} catch ( Exception e ) {
188
log3("ERROR: Exception : " + e);
189
}
190
break;
191
}
192
193
return testExitCode;
194
}
195
196
197
/*
198
* Return value: 0 - normal end of the test
199
* 1 - ubnormal end of the test
200
* 2 - VMDisconnectedException while test phase
201
*/
202
203
private int runTest() {
204
205
try {
206
testRun();
207
208
log2("waiting for VMDeathEvent");
209
getEventSet();
210
if (eventIterator.nextEvent() instanceof VMDeathEvent)
211
return 0;
212
213
log3("ERROR: last event is not the VMDeathEvent");
214
return 1;
215
} catch ( VMDisconnectedException e ) {
216
log3("ERROR: VMDisconnectedException : " + e);
217
return 2;
218
} catch ( Exception e ) {
219
log3("ERROR: Exception : " + e);
220
return 1;
221
}
222
223
}
224
225
private void testRun()
226
throws JDITestRuntimeException, Exception {
227
228
eventRManager = vm.eventRequestManager();
229
230
ClassPrepareRequest cpRequest = eventRManager.createClassPrepareRequest();
231
cpRequest.setSuspendPolicy( EventRequest.SUSPEND_EVENT_THREAD);
232
cpRequest.addClassFilter(debuggeeName);
233
234
cpRequest.enable();
235
vm.resume();
236
getEventSet();
237
cpRequest.disable();
238
239
ClassPrepareEvent event = (ClassPrepareEvent) eventIterator.next();
240
debuggeeClass = event.referenceType();
241
242
if (!debuggeeClass.name().equals(debuggeeName))
243
throw new JDITestRuntimeException("** Unexpected ClassName for ClassPrepareEvent **");
244
245
log2(" received: ClassPrepareEvent for debuggeeClass");
246
247
String bPointMethod = "methodForCommunication";
248
String lineForComm = "lineForComm";
249
250
ThreadReference mainThread = debuggee.threadByNameOrThrow("main");
251
252
BreakpointRequest bpRequest = settingBreakpoint(mainThread,
253
debuggeeClass,
254
bPointMethod, lineForComm, "zero");
255
bpRequest.enable();
256
257
//------------------------------------------------------ testing section
258
259
260
EventRequest eventRequest1 = null;
261
262
String fieldName1 = "var101";
263
String fieldName2 = "excObj";
264
265
ThreadReference thread1 = null;
266
String threadName1 = "thread1";
267
268
ReferenceType testClassReference = null;
269
270
String propertyName = "name";
271
String propertyValue1 = "value1";
272
String propertyValue2 = "value2";
273
274
275
log1(" TESTING BEGINS");
276
277
for (int i = 0; ; i++) {
278
279
vm.resume();
280
breakpointForCommunication();
281
282
int instruction = ((IntegerValue)
283
(debuggeeClass.getValue(debuggeeClass.fieldByName("instruction")))).value();
284
285
if (instruction == 0) {
286
vm.resume();
287
break;
288
}
289
290
log1(":::::: case: # " + i);
291
292
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ variable part
293
294
295
switch (i) {
296
297
case 0:
298
thread1 = debuggee.threadByNameOrThrow(threadName1);
299
300
log2("......setting up StepRequest");
301
eventRequest1 = eventRManager.createStepRequest
302
(thread1, StepRequest.STEP_MIN, StepRequest.STEP_INTO);
303
break;
304
305
case 1:
306
testClassReference = (ReferenceType) vm.classesByName(testedClassName).get(0);
307
308
log2("......setting up AccessWatchpointRequest");
309
eventRequest1 = eventRManager.createAccessWatchpointRequest
310
(testClassReference.fieldByName(fieldName1));
311
break;
312
313
case 2:
314
log2(".....setting up ModificationWatchpointRequest");
315
eventRequest1 = eventRManager.createModificationWatchpointRequest
316
(testClassReference.fieldByName(fieldName1));
317
break;
318
319
case 3:
320
log2(".....setting up ClassPrepareRequest");
321
eventRequest1 = eventRManager.createClassPrepareRequest();
322
break;
323
324
case 4:
325
log2(".....setting up ClassUnloadRequest");
326
eventRequest1 = eventRManager.createClassUnloadRequest();
327
break;
328
329
case 5:
330
log2(".....setting up MethodEntryRequest");
331
eventRequest1 = eventRManager.createMethodEntryRequest();
332
break;
333
334
case 6:
335
log2(".....setting up MethodExitRequest");
336
eventRequest1 = eventRManager.createMethodExitRequest();
337
break;
338
339
case 7:
340
log2(".....setting up ThreadDeathRequest");
341
eventRequest1 = eventRManager.createThreadDeathRequest();
342
break;
343
344
case 8:
345
log2(".....setting up ThreadStartRequest");
346
eventRequest1 = eventRManager.createThreadStartRequest();
347
break;
348
349
case 9:
350
log2(".....setting up VMDeathRequest");
351
eventRequest1 = eventRManager.createVMDeathRequest();
352
break;
353
354
case 10:
355
log2(".....setting up ExceptionRequest");
356
eventRequest1 = eventRManager.createExceptionRequest(
357
(ReferenceType)
358
(debuggeeClass.getValue(debuggeeClass.fieldByName(fieldName2))).type(),
359
true, true );
360
break;
361
362
case 11:
363
log2(".....setting up BreakpointRequest");
364
eventRequest1 = eventRManager.createBreakpointRequest(breakpLocation);
365
break;
366
367
368
default:
369
throw new JDITestRuntimeException("** default case 2 **");
370
}
371
372
log2("......eventRequest1.putProperty(propertyName, propertyValue1);");
373
eventRequest1.putProperty(propertyName, propertyValue1);
374
log2(" eventRequest1.putProperty(propertyName, propertyValue2);");
375
eventRequest1.putProperty(propertyName, propertyValue2);
376
377
log2(" checking up on eventRequest1");
378
if ( !eventRequest1.getProperty(propertyName).equals(propertyValue2) ) {
379
testExitCode = FAILED;
380
log3("ERROR: property is not expected");
381
}
382
383
log2("......eventRequest1.putProperty(propertyName, null);");
384
eventRequest1.putProperty(propertyName, null);
385
386
log2(" checking up on eventRequest1");
387
if ( eventRequest1.getProperty(propertyName)!= null ) {
388
testExitCode = FAILED;
389
log3("ERROR: property is not the null");
390
}
391
392
eventRequest1.setEnabled(false);
393
394
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
395
}
396
log1(" TESTING ENDS");
397
return;
398
}
399
400
}
401
402