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/tc09x002.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: TC9 <br>
42
* Description: Breakpoints updated correctly <br>
43
* Steps: 1.Set breakpoint at lines 36 and 39 <br>
44
* (printing 1 and 4) <br>
45
* 2.Debug Main <br>
46
* X. Stops on line 36 <br>
47
* 3.Delete line 37 <br>
48
* 4.Smart Swap <br>
49
* X. Breakpoints still set and valid at 36 <br>
50
* and 38 <br>
51
* 5.Resume <br>
52
* X. Stops on line 38 <br>
53
* <br>
54
* The description was drown up according to steps under JBuilder.
55
*
56
* Of course, the test has own line numbers and method/class names and
57
* works as follow:
58
* When the test is starting debugee, debugger sets breakpoints at
59
* the 47th and 49th line (method <code>method_C</code>).
60
* After the first breakpoint is reached, debugger redefines debugee
61
* deleting 48th line and attempts to set another breakpoint at 49th line.
62
* Because line number info is not available after redefining, it is
63
* expected IndexOutOfBoundsException will be thrown.
64
*/
65
66
public class tc09x002 {
67
68
public final static String UNEXPECTED_STRING = "***Unexpected exception ";
69
70
private final static String prefix = "nsk.jdi.BScenarios.hotswap.";
71
private final static String debuggerName = prefix + "tc09x002";
72
private final static String debugeeName = debuggerName + "a";
73
74
private final static String newClassFile = "newclass" + File.separator
75
+ debugeeName.replace('.',File.separatorChar)
76
+ ".class";
77
78
private static int exitStatus;
79
private static Log log;
80
private static Debugee debugee;
81
private static long waitTime;
82
private static String classDir;
83
84
private int eventCount;
85
private int expectedEventCount = 1;
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
tc09x002 thisTest = new tc09x002();
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
BreakpointRequest brkpRequest1, brkpRequest2;
142
long totalTime = waitTime;
143
long tmp, begin = System.currentTimeMillis(),
144
delta = 0;
145
boolean exit = false;
146
147
eventCount = 0;
148
EventRequestManager evm = debugee.getEventRequestManager();
149
ClassPrepareRequest req = evm.createClassPrepareRequest();
150
req.addClassFilter(debugeeName);
151
req.enable();
152
debugee.resume();
153
154
while (totalTime > 0 && !exit) {
155
if (eventIterator == null || !eventIterator.hasNext()) {
156
try {
157
eventSet = debugee.VM().eventQueue().remove(totalTime);
158
} catch (InterruptedException e) {
159
new Failure(e);
160
}
161
if (eventSet != null) {
162
eventIterator = eventSet.eventIterator();
163
} else {
164
eventIterator = null;
165
}
166
}
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
176
brkpRequest1 = debugee.setBreakpoint(debugeeClass,
177
tc09x002a.brkpMethodName,
178
tc09x002a.brkpLineNumber1);
179
180
brkpRequest2 = debugee.setBreakpoint(debugeeClass,
181
tc09x002a.brkpMethodName,
182
tc09x002a.brkpLineNumber2);
183
184
breakpointInfo(brkpRequest1);
185
breakpointInfo(brkpRequest2);
186
187
debugee.resume();
188
189
} else if (event instanceof BreakpointEvent) {
190
display("\n event ===>>> " + event);
191
hitBreakpoint((BreakpointEvent )event);
192
193
if (eventCount == 1) {
194
display("redefining...");
195
redefineDebugee();
196
Method method = null;
197
try {
198
method = ((BreakpointEvent )event).thread().frame(0).location().method();
199
} catch (IncompatibleThreadStateException e) {
200
throw new Failure(UNEXPECTED_STRING + e);
201
}
202
203
display("\nsetting breakpoint at the redefined method...");
204
try {
205
Location location = debugee.getLineLocation(method, tc09x002a.brkpLineNumber2);
206
if (location != null) {
207
brkpRequest2 = evm.createBreakpointRequest(location);
208
if (method.isObsolete()) {
209
complain("Locations of the redefined method "
210
+ "should be not available: " + location);
211
complain("BreakpointRequest for not available location "
212
+ "should be created: " + brkpRequest2);
213
exitStatus = Consts.TEST_FAILED;
214
} else {
215
display("No location found for unavailable line after class redefinition");
216
}
217
}
218
} catch (Exception e) {
219
display("Unspecified exception caught while setting breakpoint "
220
+ "to unavailable line after class redefinition:\n\t" + e);
221
exitStatus = Consts.TEST_FAILED;
222
}
223
}
224
debugee.resume();
225
226
} else if (event instanceof VMDeathEvent) {
227
exit = true;
228
break;
229
} else if (event instanceof VMDisconnectEvent) {
230
exit = true;
231
break;
232
} // if
233
} // while
234
tmp = System.currentTimeMillis();
235
delta = tmp - begin;
236
totalTime -= delta;
237
begin = tmp;
238
}
239
240
if (eventCount != expectedEventCount) {
241
if (totalTime <= 0) {
242
complain("out of wait time...");
243
}
244
complain("expecting " + expectedEventCount
245
+ " events, but "
246
+ eventCount + " events arrived.");
247
exitStatus = Consts.TEST_FAILED;
248
}
249
250
display("=============");
251
display("TEST FINISHES\n");
252
}
253
254
private void redefineDebugee() {
255
Map<? extends com.sun.jdi.ReferenceType,byte[]> mapBytes;
256
boolean alreadyComplained = false;
257
mapBytes = mapClassToBytes(newClassFile);
258
try {
259
debugee.VM().redefineClasses(mapBytes);
260
} catch (Exception e) {
261
throw new Failure(UNEXPECTED_STRING + e);
262
}
263
}
264
265
private Map<? extends com.sun.jdi.ReferenceType,byte[]> mapClassToBytes(String fileName) {
266
display("class-file\t:" + fileName);
267
File fileToBeRedefined = new File(classDir + File.separator + fileName);
268
int fileToRedefineLength = (int )fileToBeRedefined.length();
269
byte[] arrayToRedefine = new byte[fileToRedefineLength];
270
271
FileInputStream inputFile;
272
try {
273
inputFile = new FileInputStream(fileToBeRedefined);
274
} catch (FileNotFoundException e) {
275
throw new Failure(UNEXPECTED_STRING + e);
276
}
277
278
try {
279
inputFile.read(arrayToRedefine);
280
inputFile.close();
281
} catch (IOException e) {
282
throw new Failure(UNEXPECTED_STRING + e);
283
}
284
HashMap<com.sun.jdi.ReferenceType,byte[]> mapForClass = new HashMap<com.sun.jdi.ReferenceType,byte[]>();
285
mapForClass.put(debugeeClass, arrayToRedefine);
286
return mapForClass;
287
}
288
289
private void hitBreakpoint(BreakpointEvent event) {
290
eventInfo(event);
291
if (event.location().lineNumber() == tc09x002a.checkLastLine &&
292
eventCount == 1) {
293
display("!!!BreakpointEvent steps to the expected line "
294
+ event.location().lineNumber() + "!!!");
295
} else {
296
complain("BreakpointEvent steps to line " + event.location().lineNumber()
297
+ ", expected line number is "
298
+ tc09x002a.checkLastLine);
299
exitStatus = Consts.TEST_FAILED;
300
}
301
display("");
302
}
303
304
private void eventInfo(LocatableEvent event) {
305
eventCount++;
306
display("event info: #" + eventCount);
307
display("\tthread\t- " + event.thread().name());
308
locationInfo(event);
309
}
310
311
private void breakpointInfo(BreakpointRequest request) {
312
display("breakpoint info: ");
313
display("\tis enabled - " + request.isEnabled());
314
locationInfo(request);
315
}
316
317
private void locationInfo(Locatable loc) {
318
try {
319
display("\tsource\t- " + loc.location().sourceName());
320
display("\tmethod\t- " + loc.location().method().name());
321
display("\tline\t- " + loc.location().lineNumber());
322
} catch (AbsentInformationException e) {
323
display("***information is not available***");
324
}
325
}
326
}
327
328