Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdwp/StackFrame/SetValues/setvalues001a.java
41162 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.StackFrame.SetValues;
25
26
import nsk.share.*;
27
import nsk.share.jpda.*;
28
import nsk.share.jdwp.*;
29
30
import java.io.*;
31
32
/**
33
* This class represents debuggee part in the test.
34
*/
35
public class setvalues001a {
36
37
// name of the tested object and thread classes
38
public static final String OBJECT_CLASS_NAME = "TestedObjectClass";
39
public static final String THREAD_CLASS_NAME = "TestedThreadClass";
40
public static final String THREAD_NAME = "TestedThreadName";
41
42
// name of the static fields with the tested object values
43
public static final String THREAD_FIELD_NAME = "thread";
44
public static final String OBJECT_FIELD_NAME = "object";
45
public static final String OBJECT_METHOD_NAME = "testedMethod";
46
47
// notification object to notify debuggee that thread is ready
48
private static Object threadReady = new Object();
49
// lock object to prevent thread from exit
50
private static Object threadLock = new Object();
51
52
// scaffold objects
53
private static volatile ArgumentHandler argumentHandler = null;
54
private static volatile Log log = null;
55
56
public static void main(String args[]) {
57
setvalues001a _setvalues001a = new setvalues001a();
58
System.exit(setvalues001.JCK_STATUS_BASE + _setvalues001a.runIt(args, System.err));
59
}
60
61
public int runIt(String args[], PrintStream out) {
62
//make log for debugee messages
63
argumentHandler = new ArgumentHandler(args);
64
log = new Log(out, argumentHandler);
65
66
// make communication pipe to debugger
67
log.display("Creating pipe");
68
IOPipe pipe = argumentHandler.createDebugeeIOPipe(log);
69
70
// lock the object to prevent thread from running further
71
synchronized (threadLock) {
72
73
// load tested class and create tested thread and object
74
log.display("Creating object of tested class");
75
TestedObjectClass.object = new TestedObjectClass();
76
log.display("Creating tested thread");
77
TestedObjectClass.thread = new TestedThreadClass(THREAD_NAME);
78
79
OriginalValuesClass original = new OriginalValuesClass();
80
TargetValuesClass target = new TargetValuesClass();
81
82
// start the thread and wait for notification from it
83
synchronized (threadReady) {
84
TestedObjectClass.thread.start();
85
try {
86
threadReady.wait();
87
// send debugger signal READY
88
log.display("Sending signal to debugger: " + setvalues001.READY);
89
pipe.println(setvalues001.READY);
90
} catch (InterruptedException e) {
91
log.complain("Interruption while waiting for thread started: " + e);
92
pipe.println(setvalues001.ERROR);
93
// exit debuggee
94
log.complain("Debugee FAILED");
95
return setvalues001.FAILED;
96
}
97
}
98
99
// wait for signal RUN from debugeer
100
log.display("Waiting for signal from debugger: " + setvalues001.RUN);
101
String signal = pipe.readln();
102
log.display("Received signal from debugger: " + signal);
103
104
// check received signal
105
if (signal == null || !signal.equals(setvalues001.RUN)) {
106
log.complain("Unexpected communication signal from debugee: " + signal
107
+ " (expected: " + setvalues001.RUN + ")");
108
// skip checking for new values
109
TestedObjectClass.object.checking = false;
110
// exit debuggee
111
log.complain("Debugee FAILED");
112
return setvalues001.FAILED;
113
}
114
115
// allow started thread to run and finish
116
}
117
118
// wait for tested thread finished
119
try {
120
log.display("Waiting for tested thread finished");
121
TestedObjectClass.thread.join();
122
} catch (InterruptedException e) {
123
log.complain("Interruption while waiting for tested thread finished:\n\t"
124
+ e);
125
// exit debuggee
126
log.complain("Debugee FAILED");
127
return setvalues001.FAILED;
128
}
129
130
// confirm that new values of local variables are correct
131
if (TestedObjectClass.object.different == 0) {
132
log.display("Sending signal to debugger: " + setvalues001.DONE);
133
pipe.println(setvalues001.DONE);
134
} else {
135
log.complain("Values of " + TestedObjectClass.object.different +
136
" local variables have not been set correctly");
137
log.display("Sending signal to debugger: " + setvalues001.ERROR);
138
pipe.println(setvalues001.ERROR);
139
}
140
141
// wait for signal QUIT from debugeer
142
log.display("Waiting for signal from debugger: " + setvalues001.QUIT);
143
String signal = pipe.readln();
144
log.display("Received signal from debugger: " + signal);
145
146
// check received signal
147
if (signal == null || !signal.equals(setvalues001.QUIT)) {
148
log.complain("Unexpected communication signal from debugee: " + signal
149
+ " (expected: " + setvalues001.QUIT + ")");
150
// exit debuggee
151
log.complain("Debugee FAILED");
152
return setvalues001.FAILED;
153
}
154
155
// exit debugee
156
log.display("Debugee PASSED");
157
return setvalues001.PASSED;
158
}
159
160
// tested thread class
161
public static class TestedThreadClass extends Thread {
162
163
public TestedThreadClass(String name) {
164
super(name);
165
}
166
167
public void run() {
168
log.display("Tested thread started");
169
170
// invoke tested method for the tested object from the tested thread
171
TestedObjectClass.object.testedMethod();
172
173
log.display("Tested thread finished");
174
}
175
176
}
177
178
// tested object class
179
public static class TestedObjectClass {
180
181
// field with the tested thread and object values
182
public static volatile TestedThreadClass thread = null;
183
public static volatile TestedObjectClass object = null;
184
185
// allow to check new values of local variables
186
public volatile boolean checking = true;
187
// number of variables with unexpected new values
188
public volatile int different = 0;
189
190
// tested method with local variables
191
public void testedMethod() {
192
193
// local variables
194
boolean booleanValue = OriginalValuesClass.booleanValue;
195
byte byteValue = OriginalValuesClass.byteValue;
196
char charValue = OriginalValuesClass.charValue;
197
int intValue = OriginalValuesClass.intValue;
198
short shortValue = OriginalValuesClass.shortValue;
199
long longValue = OriginalValuesClass.longValue;
200
float floatValue = OriginalValuesClass.floatValue;
201
double doubleValue = OriginalValuesClass.doubleValue;
202
String stringValue = OriginalValuesClass.stringValue;
203
Object objectValue = OriginalValuesClass.objectValue;
204
205
log.display("Tested frame entered");
206
207
// notify debuggee that tested thread ready for testing
208
synchronized (threadReady) {
209
threadReady.notifyAll();
210
}
211
212
// wait for lock object released
213
synchronized (threadLock) {
214
log.display("Checking that values have been set correctly:");
215
}
216
217
// check new values of local variables
218
if (checking) {
219
220
// check value of the variable
221
if (booleanValue != TargetValuesClass.booleanValue) {
222
different++;
223
log.complain(" booleanValue = " + booleanValue + "\n"
224
+ " setting: " + OriginalValuesClass.booleanValue
225
+ " -> " + TargetValuesClass.booleanValue);
226
if (booleanValue == OriginalValuesClass.booleanValue) {
227
log.complain(" not changed!");
228
} else {
229
log.complain(" changed incorrectly!");
230
}
231
} else {
232
log.display(" booleanValue: " + OriginalValuesClass.booleanValue
233
+ " -> " + TargetValuesClass.booleanValue);
234
}
235
236
// check value of the variable
237
if (byteValue != TargetValuesClass.byteValue) {
238
different++;
239
log.complain(" byteValue = " + byteValue + "\n"
240
+ " setting: " + OriginalValuesClass.byteValue
241
+ " -> " + TargetValuesClass.byteValue);
242
if (byteValue == OriginalValuesClass.byteValue) {
243
log.complain(" not changed!");
244
} else {
245
log.complain(" changed incorrectly!");
246
}
247
} else {
248
log.display(" byteValue: " + OriginalValuesClass.byteValue
249
+ " -> " + TargetValuesClass.byteValue);
250
}
251
252
// check value of the variable
253
if (charValue != TargetValuesClass.charValue) {
254
different++;
255
log.complain(" charValue = " + charValue + "\n"
256
+ " setting: " + OriginalValuesClass.charValue
257
+ " -> " + TargetValuesClass.charValue);
258
if (charValue == OriginalValuesClass.charValue) {
259
log.complain(" not changed!");
260
} else {
261
log.complain(" changed incorrectly!");
262
}
263
} else {
264
log.display(" charValue: " + OriginalValuesClass.charValue
265
+ " -> " + TargetValuesClass.charValue);
266
}
267
268
// check value of the variable
269
if (intValue != TargetValuesClass.intValue) {
270
different++;
271
log.complain(" intValue = " + intValue + "\n"
272
+ " setting: " + OriginalValuesClass.intValue
273
+ " -> " + TargetValuesClass.intValue);
274
if (intValue == OriginalValuesClass.intValue) {
275
log.complain(" not changed!");
276
} else {
277
log.complain(" changed incorrectly!");
278
}
279
} else {
280
log.display(" intValue: " + OriginalValuesClass.intValue
281
+ " -> " + TargetValuesClass.intValue);
282
}
283
284
// check value of the variable
285
if (shortValue != TargetValuesClass.shortValue) {
286
different++;
287
log.complain(" shortValue = " + shortValue + "\n"
288
+ " setting: " + OriginalValuesClass.shortValue
289
+ " -> " + TargetValuesClass.shortValue);
290
if (shortValue == OriginalValuesClass.shortValue) {
291
log.complain(" not changed!");
292
} else {
293
log.complain(" changed incorrectly!");
294
}
295
} else {
296
log.display(" shortValue: " + OriginalValuesClass.shortValue
297
+ " -> " + TargetValuesClass.shortValue);
298
}
299
300
// check value of the variable
301
if (longValue != TargetValuesClass.longValue) {
302
different++;
303
log.complain(" longValue = " + longValue + "\n"
304
+ " setting: " + OriginalValuesClass.longValue
305
+ " -> " + TargetValuesClass.longValue);
306
if (longValue == OriginalValuesClass.longValue) {
307
log.complain(" not changed!");
308
} else {
309
log.complain(" changed incorrectly!");
310
}
311
} else {
312
log.display(" longValue: " + OriginalValuesClass.longValue
313
+ " -> " + TargetValuesClass.longValue);
314
}
315
316
// check value of the variable
317
if (floatValue != TargetValuesClass.floatValue) {
318
different++;
319
log.complain(" floatValue = " + floatValue + "\n"
320
+ " setting: " + OriginalValuesClass.floatValue
321
+ " -> " + TargetValuesClass.floatValue);
322
if (floatValue == OriginalValuesClass.floatValue) {
323
log.complain(" not changed!");
324
} else {
325
log.complain(" changed incorrectly!");
326
}
327
} else {
328
log.display(" floatValue: " + OriginalValuesClass.floatValue
329
+ " -> " + TargetValuesClass.floatValue);
330
}
331
332
// check value of the variable
333
if (doubleValue != TargetValuesClass.doubleValue) {
334
different++;
335
log.complain(" doubleValue = " + doubleValue + "\n"
336
+ " setting: " + OriginalValuesClass.doubleValue
337
+ " -> " + TargetValuesClass.doubleValue);
338
if (doubleValue == OriginalValuesClass.doubleValue) {
339
log.complain(" not changed!");
340
} else {
341
log.complain(" changed incorrectly!");
342
}
343
} else {
344
log.display(" doubleValue: " + OriginalValuesClass.doubleValue
345
+ " -> " + TargetValuesClass.doubleValue);
346
}
347
348
// check value of the variable
349
if (stringValue != TargetValuesClass.stringValue) {
350
different++;
351
log.complain(" stringValue = " + stringValue + "\n"
352
+ " setting: " + OriginalValuesClass.stringValue
353
+ " -> " + TargetValuesClass.stringValue);
354
if (stringValue == OriginalValuesClass.stringValue) {
355
log.complain(" not changed!");
356
} else {
357
log.complain(" changed incorrectly!");
358
}
359
} else {
360
log.display(" stringValue: " + OriginalValuesClass.stringValue
361
+ " -> " + TargetValuesClass.stringValue);
362
}
363
364
// check value of the variable
365
if (objectValue != TargetValuesClass.objectValue) {
366
different++;
367
log.complain(" objectValue = " + objectValue + "\n"
368
+ " setting: " + OriginalValuesClass.objectValue
369
+ " -> " + TargetValuesClass.objectValue);
370
if (objectValue == OriginalValuesClass.objectValue) {
371
log.complain(" not changed!");
372
} else {
373
log.complain(" changed incorrectly!");
374
}
375
} else {
376
log.display(" objectValue: " + OriginalValuesClass.objectValue
377
+ " -> " + TargetValuesClass.objectValue);
378
}
379
}
380
381
log.display("Tested frame dropped");
382
}
383
384
}
385
386
// class with the original values of static fields
387
public static class OriginalValuesClass {
388
static final boolean booleanValue = true;
389
static final byte byteValue = (byte)0x01;
390
static final char charValue = 'Z';
391
static final int intValue = 100;
392
static final short shortValue = (short)10;
393
static final long longValue = (long)1000000;
394
static final float floatValue = (float)3.14;
395
static final double doubleValue = (double)2.8e-12;
396
static final String stringValue = "text";
397
static final Object objectValue = new OriginalValuesClass();
398
}
399
400
// class with the original values of static fields
401
public static class TargetValuesClass {
402
static final boolean booleanValue = false;
403
static final byte byteValue = (byte)0x0F;
404
static final char charValue = 'A';
405
static final int intValue = 999;
406
static final short shortValue = (short)88;
407
static final long longValue = (long)11111111;
408
static final float floatValue = (float)7.19;
409
static final double doubleValue = (double)4.6e24;
410
static final String stringValue = "new text";
411
static final Object objectValue = new TargetValuesClass();
412
}
413
414
}
415
416