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/tc09x001.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: 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 resumes debugee. No breakpoints are
62
* expected anymore.
63
*/
64
65
public class tc09x001 {
66
67
public final static String UNEXPECTED_STRING = "***Unexpected exception ";
68
69
private final static String prefix = "nsk.jdi.BScenarios.hotswap.";
70
private final static String debuggerName = prefix + "tc09x001";
71
private final static String debugeeName = debuggerName + "a";
72
73
private final static String newClassFile = "newclass" + File.separator
74
+ debugeeName.replace('.',File.separatorChar)
75
+ ".class";
76
77
private static int exitStatus;
78
private static Log log;
79
private static Debugee debugee;
80
private static long waitTime;
81
private static String classDir;
82
83
private int eventCount;
84
private int expectedEventCount = 1;
85
private ReferenceType debugeeClass;
86
private BreakpointRequest brkpRequest1 = null,
87
brkpRequest2 = null;
88
89
private static void display(String msg) {
90
log.display(msg);
91
}
92
93
private static void complain(String msg) {
94
log.complain("debugger FAILURE> " + msg + "\n");
95
}
96
97
public static void main(String argv[]) {
98
System.exit(Consts.JCK_STATUS_BASE + run(argv, System.out));
99
}
100
101
public static int run(String argv[], PrintStream out) {
102
103
exitStatus = Consts.TEST_PASSED;
104
105
tc09x001 thisTest = new tc09x001();
106
107
ArgumentHandler argHandler = new ArgumentHandler(argv);
108
log = new Log(out, argHandler);
109
110
classDir = argv[0];
111
waitTime = argHandler.getWaitTime() * 60000;
112
113
Binder binder = new Binder(argHandler, log);
114
debugee = binder.bindToDebugee(debugeeName);
115
116
try {
117
thisTest.execTest();
118
} catch (Throwable e) {
119
exitStatus = Consts.TEST_FAILED;
120
e.printStackTrace();
121
} finally {
122
debugee.endDebugee();
123
}
124
display("Test finished. exitStatus = " + exitStatus);
125
126
return exitStatus;
127
}
128
129
private void execTest() throws Failure {
130
131
if (!debugee.VM().canRedefineClasses()) {
132
display("\n>>>canRedefineClasses() is false<<< test canceled.\n");
133
return;
134
}
135
136
display("\nTEST BEGINS");
137
display("===========");
138
139
EventSet eventSet = null;
140
EventIterator eventIterator = null;
141
Event event;
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
if (eventIterator != null) {
168
while (eventIterator.hasNext()) {
169
event = eventIterator.nextEvent();
170
// display("\n event ===>>> " + event);
171
172
if (event instanceof ClassPrepareEvent) {
173
display("\n event ===>>> " + event);
174
debugeeClass = ((ClassPrepareEvent )event).referenceType();
175
display("Tested class\t:" + debugeeClass.name());
176
177
brkpRequest1 = debugee.setBreakpoint(debugeeClass,
178
tc09x001a.brkpMethodName,
179
tc09x001a.brkpLineNumber1);
180
181
brkpRequest2 = debugee.setBreakpoint(debugeeClass,
182
tc09x001a.brkpMethodName,
183
tc09x001a.brkpLineNumber2);
184
185
breakpointInfo(brkpRequest1);
186
breakpointInfo(brkpRequest2);
187
188
debugee.resume();
189
190
} else if (event instanceof BreakpointEvent) {
191
display("\n event ===>>> " + event);
192
hitBreakpoint((BreakpointEvent )event);
193
if (eventCount == 1) {
194
display("redefining...");
195
redefineDebugee();
196
breakpointInfo(brkpRequest1);
197
breakpointInfo(brkpRequest2);
198
}
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 void hitBreakpoint(BreakpointEvent event) {
266
eventInfo(event);
267
if (event.location().lineNumber() == tc09x001a.checkLastLine &&
268
eventCount == 1) {
269
display("!!!BreakpointEvent steps to the expected line "
270
+ event.location().lineNumber() + "!!!");
271
} else {
272
complain("BreakpointEvent steps to line " + event.location().lineNumber()
273
+ ", expected line number is "
274
+ tc09x001a.checkLastLine);
275
exitStatus = Consts.TEST_FAILED;
276
}
277
display("");
278
}
279
280
private void eventInfo(LocatableEvent event) {
281
eventCount++;
282
display("event info: #" + eventCount);
283
display("\tthread\t- " + event.thread().name());
284
locationInfo(event);
285
}
286
287
private void breakpointInfo(BreakpointRequest request) {
288
display("breakpoint info: ");
289
display("\tis enabled - " + request.isEnabled());
290
locationInfo(request);
291
}
292
293
private void locationInfo(Locatable loc) {
294
try {
295
display("\tsource\t- " + loc.location().sourceName());
296
display("\tmethod\t- " + loc.location().method().name());
297
display("\tline\t- " + loc.location().lineNumber());
298
} catch (AbsentInformationException e) {
299
display("***information is not available***");
300
}
301
}
302
}
303
304