Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/BScenarios/hotswap/tc10x002.java
41161 views
1
/*
2
* Copyright (c) 2002, 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.BScenarios.hotswap;
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.request.*;
32
import com.sun.jdi.event.*;
33
34
import java.util.*;
35
import java.io.*;
36
37
/**
38
* This test is from the group of so-called Borland's scenarios and
39
* implements the following test case: <br>
40
* Suite 3 - Hot Swap <br>
41
* Test case: TC10 <br>
42
* Description: Changing data type <br>
43
* Steps: 1.Set breakpoint on line 20 <br>
44
* 2.Debug Main <br>
45
* X. Stops on line 20 <br>
46
* 3.Change line 16 to boolean i = true; <br>
47
* 4.Smart Swap <br>
48
* 5.Resume <br>
49
* X. Prints "true" as last line of output <br>
50
* <br>
51
* The description was drown up according to steps under JBuilder.
52
*
53
* Of course, the test has own line numbers and method/class names and
54
* works as follow:
55
* When the test is starting debugee, debugger sets breakpoint at
56
* the 40th line (method <code>runIt</code>).
57
* Note: the <code>runIt</code> method was added into the test, to allow invoking
58
* <code>ThreadReference.popFrame()</code>. Current frame can not be reset because of
59
* there is no previous frame.
60
* After the breakpoint is reached, debugger redefines debugee changing type of
61
* local variable, pops current frame, sets a new breakpoint at 37th line and
62
* resumes debugee.
63
* When the second breakpoint hits, debugger requests value of the local
64
* variable <code>i</code> and compares got value with expected value.
65
* In this case expected value is the new value after redefinition.
66
*/
67
68
public class tc10x002 {
69
70
public final static String UNEXPECTED_STRING = "***Unexpected exception ";
71
72
private final static String prefix = "nsk.jdi.BScenarios.hotswap.";
73
private final static String debuggerName = prefix + "tc10x002";
74
private final static String debugeeName = debuggerName + "a";
75
76
private final static String newClassFile = "newclass" + File.separator
77
+ debugeeName.replace('.',File.separatorChar)
78
+ ".class";
79
80
private static int exitStatus;
81
private static Log log;
82
private static Debugee debugee;
83
private static long waitTime;
84
private static String classDir;
85
86
private int eventCount;
87
private int expectedEventCount = 2;
88
private ReferenceType debugeeClass;
89
90
private static void display(String msg) {
91
log.display(msg);
92
}
93
94
private static void complain(String msg) {
95
log.complain("debugger FAILURE> " + msg + "\n");
96
}
97
98
public static void main(String argv[]) {
99
System.exit(Consts.JCK_STATUS_BASE + run(argv, System.out));
100
}
101
102
public static int run(String argv[], PrintStream out) {
103
104
exitStatus = Consts.TEST_PASSED;
105
106
tc10x002 thisTest = new tc10x002();
107
108
ArgumentHandler argHandler = new ArgumentHandler(argv);
109
log = new Log(out, argHandler);
110
111
classDir = argv[0];
112
waitTime = argHandler.getWaitTime() * 60000;
113
114
Binder binder = new Binder(argHandler, log);
115
debugee = binder.bindToDebugee(debugeeName);
116
debugee.createIOPipe();
117
118
try {
119
thisTest.execTest();
120
} catch (Throwable e) {
121
exitStatus = Consts.TEST_FAILED;
122
e.printStackTrace();
123
} finally {
124
debugee.endDebugee();
125
}
126
display("Test finished. exitStatus = " + exitStatus);
127
128
return exitStatus;
129
}
130
131
private void execTest() throws Failure {
132
133
if (!debugee.VM().canRedefineClasses()) {
134
display("\n>>>canRedefineClasses() is false<<< test canceled.\n");
135
return;
136
}
137
138
display("\nTEST BEGINS");
139
display("===========");
140
141
EventSet eventSet = null;
142
EventIterator eventIterator = null;
143
Event event;
144
BreakpointRequest brkpRequest;
145
long totalTime = waitTime;
146
long tmp, begin = System.currentTimeMillis(),
147
delta = 0;
148
boolean exit = false;
149
150
eventCount = 0;
151
EventRequestManager evm = debugee.getEventRequestManager();
152
ClassPrepareRequest req = evm.createClassPrepareRequest();
153
req.addClassFilter(debugeeName);
154
req.enable();
155
debugee.resume();
156
157
while (totalTime > 0 && !exit) {
158
if (eventIterator == null || !eventIterator.hasNext()) {
159
try {
160
eventSet = debugee.VM().eventQueue().remove(totalTime);
161
} catch (InterruptedException e) {
162
new Failure(e);
163
}
164
if (eventSet != null) {
165
eventIterator = eventSet.eventIterator();
166
} else {
167
eventIterator = null;
168
}
169
}
170
while (eventIterator.hasNext()) {
171
event = eventIterator.nextEvent();
172
// display("\n event ===>>> " + event);
173
174
if (event instanceof ClassPrepareEvent) {
175
display("\n event ===>>> " + event);
176
debugeeClass = ((ClassPrepareEvent )event).referenceType();
177
display("Tested class\t:" + debugeeClass.name());
178
179
brkpRequest = debugee.setBreakpoint(debugeeClass,
180
tc10x002a.brkpMethodName,
181
tc10x002a.brkpLineNumber1);
182
debugee.resume();
183
184
} else if (event instanceof BreakpointEvent) {
185
display("\n event ===>>> " + event);
186
BreakpointEvent brkpEvent = (BreakpointEvent )event;
187
188
switch (eventCount) {
189
case 0:
190
hitBreakpoint(brkpEvent, tc10x002a.checkLastLine1);
191
display("redefining...");
192
redefineDebugee();
193
194
popFrames(brkpEvent.thread());
195
196
brkpRequest = debugee.setBreakpoint(debugeeClass,
197
tc10x002a.brkpMethodName,
198
tc10x002a.brkpLineNumber2);
199
break;
200
case 1:
201
Value val = null;
202
hitBreakpoint(brkpEvent, tc10x002a.checkLastLine2);
203
try {
204
StackFrame frame = brkpEvent.thread().frame(0);
205
LocalVariable var = frame.visibleVariableByName("i");
206
display("local variable:\t" + var);
207
val = frame.getValue(var);
208
} catch (Exception e) {
209
throw new Failure(UNEXPECTED_STRING + e);
210
}
211
display("\nValue of local variable:\t" + val);
212
if (((PrimitiveValue)val).booleanValue() ==
213
tc10x002a.INITIAL_BOOL_VALUE) {
214
display("!!!Expected value of local variable!!!\n");
215
} else {
216
complain("Unexpected value of local variable.\n");
217
exitStatus = Consts.TEST_FAILED;
218
}
219
break;
220
}
221
debugee.resume();
222
223
} else if (event instanceof VMDeathEvent) {
224
exit = true;
225
break;
226
} else if (event instanceof VMDisconnectEvent) {
227
exit = true;
228
break;
229
} // if
230
} // while
231
tmp = System.currentTimeMillis();
232
delta = tmp - begin;
233
totalTime -= delta;
234
begin = tmp;
235
}
236
237
if (eventCount != expectedEventCount) {
238
if (totalTime <= 0) {
239
complain("out of wait time...");
240
}
241
complain("expecting " + expectedEventCount
242
+ " events, but "
243
+ eventCount + " events arrived.");
244
exitStatus = Consts.TEST_FAILED;
245
}
246
247
display("=============");
248
display("TEST FINISHES\n");
249
}
250
251
private void redefineDebugee() {
252
Map<? extends com.sun.jdi.ReferenceType,byte[]> mapBytes;
253
boolean alreadyComplained = false;
254
mapBytes = mapClassToBytes(newClassFile);
255
try {
256
debugee.VM().redefineClasses(mapBytes);
257
} catch (Exception e) {
258
throw new Failure(UNEXPECTED_STRING + e);
259
}
260
}
261
262
private Map<? extends com.sun.jdi.ReferenceType,byte[]> mapClassToBytes(String fileName) {
263
display("class-file\t:" + fileName);
264
File fileToBeRedefined = new File(classDir + File.separator + fileName);
265
int fileToRedefineLength = (int )fileToBeRedefined.length();
266
byte[] arrayToRedefine = new byte[fileToRedefineLength];
267
268
FileInputStream inputFile;
269
try {
270
inputFile = new FileInputStream(fileToBeRedefined);
271
} catch (FileNotFoundException e) {
272
throw new Failure(UNEXPECTED_STRING + e);
273
}
274
275
try {
276
inputFile.read(arrayToRedefine);
277
inputFile.close();
278
} catch (IOException e) {
279
throw new Failure(UNEXPECTED_STRING + e);
280
}
281
HashMap<com.sun.jdi.ReferenceType,byte[]> mapForClass = new HashMap<com.sun.jdi.ReferenceType,byte[]>();
282
mapForClass.put(debugeeClass, arrayToRedefine);
283
return mapForClass;
284
}
285
286
private void popFrames(ThreadReference thread) {
287
display("\npop frames...");
288
try {
289
StackFrame frame = thread.frame(0);
290
Method mthd = frame.location().method();
291
do {
292
thread.popFrames(frame);
293
display(mthd.name() + " is resetted");
294
frame = thread.frame(0);
295
mthd = frame.location().method();
296
} while (mthd.isObsolete());
297
} catch (IncompatibleThreadStateException e) {
298
throw new Failure(UNEXPECTED_STRING + e);
299
}
300
display("");
301
}
302
303
private void hitBreakpoint(BreakpointEvent event, int expLine) {
304
eventInfo(event);
305
if (event.location().lineNumber() == expLine) {
306
display("!!!BreakpointEvent steps to the expected line "
307
+ event.location().lineNumber() + "!!!");
308
} else {
309
complain("BreakpointEvent steps to line " + event.location().lineNumber()
310
+ ", expected line number is "
311
+ expLine);
312
exitStatus = Consts.TEST_FAILED;
313
}
314
display("");
315
}
316
317
private void eventInfo(LocatableEvent event) {
318
eventCount++;
319
display("event info: #" + eventCount);
320
display("\tthread\t- " + event.thread().name());
321
locationInfo(event);
322
}
323
324
private void breakpointInfo(BreakpointRequest request) {
325
display("breakpoint info: ");
326
display("\tis enabled - " + request.isEnabled());
327
locationInfo(request);
328
}
329
330
private void locationInfo(Locatable loc) {
331
try {
332
display("\tsource\t- " + loc.location().sourceName());
333
display("\tmethod\t- " + loc.location().method().name());
334
display("\tline\t- " + loc.location().lineNumber());
335
} catch (AbsentInformationException e) {
336
display("***information is not available***");
337
}
338
}
339
340
private MethodExitRequest createMethodExitRequest(ReferenceType refType) {
341
EventRequestManager evm = debugee.getEventRequestManager();
342
MethodExitRequest request = evm.createMethodExitRequest();
343
request.addClassFilter(refType);
344
request.enable();
345
return request;
346
}
347
}
348
349