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