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/tc07x001.java
41171 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: TC7 <br>
42
* Description: After point of execution, different method - stepping <br>
43
* Steps: 1.Set breakpoint at line 24 (call from a() <br>
44
* to b()) <br>
45
* 2.Debug Main <br>
46
* 3.Insert as first line in b(): <br>
47
* System.err.println("foo"); <br>
48
* 4.Smart Swap <br>
49
* 5.F7 to step into <br>
50
* X. Steps into b() <br>
51
* 6.F7 to step into <br>
52
* X. Prints "foo" <br>
53
* 7.F7 to step into <br>
54
* X. Steps on to line that prints "1" <br>
55
* <br>
56
* The description was drown up according to steps under JBuilder.
57
*
58
* Of course, the test has own line numbers and method/class names and
59
* works as follow:
60
* When the test is starting debugee, debugger sets breakpoint at the 38th
61
* line (<code>method method_A</code>). After the breakpoint is reached,
62
* debugger redefines debugee inserting first line into method_B, creates
63
* <code>StepRequest</code> and resumes debugee. When the location of the
64
* current <code>StepEvent</code> is in <code>method_C</code>, created
65
* <code>StepRequest</code> is disabled.
66
* The test checks up location of every step event and that new code
67
* becomes actual.
68
*/
69
70
public class tc07x001 {
71
72
public final static String UNEXPECTED_STRING = "***Unexpected exception ";
73
74
private final static String prefix = "nsk.jdi.BScenarios.hotswap.";
75
private final static String debuggerName = prefix + "tc07x001";
76
private final static String debugeeName = debuggerName + "a";
77
78
private final static String newClassFile = "newclass" + File.separator
79
+ debugeeName.replace('.',File.separatorChar)
80
+ ".class";
81
82
private static int exitStatus;
83
private static Log log;
84
private static Debugee debugee;
85
private static long waitTime;
86
private static String classDir;
87
88
private static final String firstMethodName = "method_B";
89
private static final String lastMethodName = "method_C";
90
91
private int eventCount;
92
private int expectedEventCount = 4;
93
private ReferenceType debugeeClass;
94
95
private static void display(String msg) {
96
log.display(msg);
97
}
98
99
private static void complain(String msg) {
100
log.complain("debugger FAILURE> " + msg + "\n");
101
}
102
103
public static void main(String argv[]) {
104
System.exit(Consts.JCK_STATUS_BASE + run(argv, System.out));
105
}
106
107
public static int run(String argv[], PrintStream out) {
108
109
exitStatus = Consts.TEST_PASSED;
110
111
tc07x001 thisTest = new tc07x001();
112
113
ArgumentHandler argHandler = new ArgumentHandler(argv);
114
log = new Log(out, argHandler);
115
116
classDir = argv[0];
117
waitTime = argHandler.getWaitTime() * 60000;
118
119
Binder binder = new Binder(argHandler, log);
120
debugee = binder.bindToDebugee(debugeeName);
121
122
try {
123
thisTest.execTest();
124
} catch (Throwable e) {
125
exitStatus = Consts.TEST_FAILED;
126
e.printStackTrace();
127
} finally {
128
debugee.endDebugee();
129
}
130
display("Test finished. exitStatus = " + exitStatus);
131
132
return exitStatus;
133
}
134
135
private void execTest() throws Failure {
136
137
if (!debugee.VM().canRedefineClasses()) {
138
display("\n>>>canRedefineClasses() is false<<< test canceled.\n");
139
return;
140
}
141
142
display("\nTEST BEGINS");
143
display("===========");
144
145
EventSet eventSet = null;
146
EventIterator eventIterator = null;
147
Event event;
148
long totalTime = waitTime;
149
long tmp, begin = System.currentTimeMillis(),
150
delta = 0;
151
boolean exit = false;
152
153
eventCount = 0;
154
EventRequestManager evm = debugee.getEventRequestManager();
155
ClassPrepareRequest req = evm.createClassPrepareRequest();
156
req.addClassFilter(debugeeName);
157
req.enable();
158
debugee.resume();
159
160
while (totalTime > 0 && !exit) {
161
if (eventIterator == null || !eventIterator.hasNext()) {
162
try {
163
eventSet = debugee.VM().eventQueue().remove(totalTime);
164
} catch (InterruptedException e) {
165
new Failure(e);
166
}
167
if (eventSet != null) {
168
eventIterator = eventSet.eventIterator();
169
} else {
170
eventIterator = null;
171
}
172
}
173
if (eventIterator != null) {
174
while (eventIterator.hasNext()) {
175
event = eventIterator.nextEvent();
176
// display("\n event ===>>> " + event);
177
178
if (event instanceof ClassPrepareEvent) {
179
display("\n event ===>>> " + event);
180
debugeeClass = ((ClassPrepareEvent )event).referenceType();
181
display("Tested class\t:" + debugeeClass.name());
182
debugee.setBreakpoint(debugeeClass,
183
tc07x001a.brkpMethodName,
184
tc07x001a.brkpLineNumber);
185
186
debugee.resume();
187
188
} else if (event instanceof BreakpointEvent) {
189
display("\n event ===>>> " + event);
190
hitBreakpoint((BreakpointEvent )event);
191
display("redefining...");
192
redefineDebugee();
193
createStepRequest(((LocatableEvent )event).thread());
194
debugee.resume();
195
196
} else if (event instanceof StepEvent) {
197
display("\n event ===>>> " + event);
198
hitStep((StepEvent )event);
199
debugee.resume();
200
201
} else if (event instanceof VMDeathEvent) {
202
exit = true;
203
break;
204
} else if (event instanceof VMDisconnectEvent) {
205
exit = true;
206
break;
207
} // if
208
} // while
209
} // if
210
tmp = System.currentTimeMillis();
211
delta = tmp - begin;
212
totalTime -= delta;
213
begin = tmp;
214
}
215
216
if (eventCount != expectedEventCount) {
217
if (totalTime <= 0) {
218
complain("out of wait time...");
219
}
220
complain("expecting " + expectedEventCount
221
+ " events, but "
222
+ eventCount + " events arrived.");
223
exitStatus = Consts.TEST_FAILED;
224
}
225
226
display("=============");
227
display("TEST FINISHES\n");
228
}
229
230
private void redefineDebugee() {
231
Map<? extends com.sun.jdi.ReferenceType,byte[]> mapBytes;
232
boolean alreadyComplained = false;
233
mapBytes = mapClassToBytes(newClassFile);
234
try {
235
debugee.VM().redefineClasses(mapBytes);
236
} catch (Exception e) {
237
throw new Failure(UNEXPECTED_STRING + e);
238
}
239
}
240
241
private Map<? extends com.sun.jdi.ReferenceType,byte[]> mapClassToBytes(String fileName) {
242
display("class-file\t:" + fileName);
243
File fileToBeRedefined = new File(classDir + File.separator + fileName);
244
int fileToRedefineLength = (int )fileToBeRedefined.length();
245
byte[] arrayToRedefine = new byte[fileToRedefineLength];
246
247
FileInputStream inputFile;
248
try {
249
inputFile = new FileInputStream(fileToBeRedefined);
250
} catch (FileNotFoundException e) {
251
throw new Failure(UNEXPECTED_STRING + e);
252
}
253
254
try {
255
inputFile.read(arrayToRedefine);
256
inputFile.close();
257
} catch (IOException e) {
258
throw new Failure(UNEXPECTED_STRING + e);
259
}
260
HashMap<com.sun.jdi.ReferenceType,byte[]> mapForClass = new HashMap<com.sun.jdi.ReferenceType,byte[]>();
261
mapForClass.put(debugeeClass, arrayToRedefine);
262
return mapForClass;
263
}
264
265
private StepRequest createStepRequest(ThreadReference thread) {
266
EventRequestManager evm = debugee.getEventRequestManager();
267
StepRequest request = evm.createStepRequest(thread,
268
StepRequest.STEP_LINE,
269
StepRequest.STEP_INTO);
270
request.enable();
271
return request;
272
}
273
274
private void hitBreakpoint(BreakpointEvent event) {
275
locationInfo(event);
276
if (event.location().lineNumber() != tc07x001a.checkLastLine) {
277
complain("BreakpointEvent steps to line " + event.location().lineNumber()
278
+ ", expected line number is "
279
+ tc07x001a.checkLastLine);
280
exitStatus = Consts.TEST_FAILED;
281
} else {
282
display("!!!BreakpointEvent steps to the expected line "
283
+ event.location().lineNumber() + "!!!");
284
}
285
display("");
286
}
287
288
private void hitStep(StepEvent event) {
289
locationInfo(event);
290
String methodName = event.location().method().name();
291
StepRequest request = (StepRequest )event.request();
292
if (methodName.compareTo(lastMethodName) == 0) {
293
request.disable();
294
}
295
switch (eventCount) {
296
case 2:
297
checkLocMethod(methodName, firstMethodName);
298
break;
299
case 3:
300
checkLocMethod(methodName, firstMethodName);
301
Field fld = debugeeClass.fieldByName(tc07x001a.fieldToCheckName);
302
Value val = debugeeClass.getValue(fld);
303
if (((IntegerValue )val).value() != tc07x001a.CHANGED_VALUE) {
304
complain("Unexpected: new code is not actual");
305
complain("Unexpected value of checked field: "
306
+ val);
307
exitStatus = Consts.TEST_FAILED;
308
} else {
309
display("!!!Expected: Inserted line has worked");
310
}
311
break;
312
case 4:
313
checkLocMethod(methodName, lastMethodName);
314
break;
315
default:
316
complain("Unexpected event" + event);
317
exitStatus = Consts.TEST_FAILED;
318
}
319
display("");
320
}
321
322
private void checkLocMethod(String currentMethodName, String expectedMethodName) {
323
if (currentMethodName.compareTo(expectedMethodName) != 0) {
324
complain("Unexpected event location at \"" + currentMethodName + "\"");
325
exitStatus = Consts.TEST_FAILED;
326
} else {
327
display("!!!Expected event location at \"" + currentMethodName + "\"");
328
}
329
}
330
331
private void locationInfo(LocatableEvent event) {
332
eventCount++;
333
display("event info: #" + eventCount);
334
display("\tthread\t- " + event.thread().name());
335
try {
336
display("\tsource\t- " + event.location().sourceName());
337
display("\tmethod\t- " + event.location().method().name());
338
display("\tline\t- " + event.location().lineNumber());
339
} catch (AbsentInformationException e) {
340
}
341
}
342
}
343
344