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/tc10x001.java
41161 views
1
/*
2
* Copyright (c) 2002, 2019, 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 35th line (method <code>main</code>).
57
* After the breakpoint is reached, debugger redefines debugee changing
58
* type of local variable and resumes debugee.
59
* After resuming debugee sends value of the variable via IOPipe channel,
60
* debugger reads this value and compares it with expected the one.
61
* In this case expected value is the value before redefinition.
62
*/
63
64
public class tc10x001 {
65
public final static String SGL_QUIT = "quit";
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 + "tc10x001";
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
87
private static void display(String msg) {
88
log.display(msg);
89
}
90
91
private static void complain(String msg) {
92
log.complain("debugger FAILURE> " + msg + "\n");
93
}
94
95
public static void main(String argv[]) {
96
System.exit(Consts.JCK_STATUS_BASE + run(argv, System.out));
97
}
98
99
public static int run(String argv[], PrintStream out) {
100
101
exitStatus = Consts.TEST_PASSED;
102
103
tc10x001 thisTest = new tc10x001();
104
105
ArgumentHandler argHandler = new ArgumentHandler(argv);
106
log = new Log(out, argHandler);
107
108
classDir = argv[0];
109
waitTime = argHandler.getWaitTime() * 60000;
110
111
Binder binder = new Binder(argHandler, log);
112
debugee = binder.bindToDebugee(debugeeName);
113
debugee.createIOPipe();
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 brkpRequest;
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
brkpRequest = debugee.setBreakpoint(debugeeClass,
177
tc10x001a.brkpMethodName,
178
tc10x001a.brkpLineNumber);
179
debugee.resume();
180
181
} else if (event instanceof BreakpointEvent) {
182
display("\n event ===>>> " + event);
183
hitBreakpoint((BreakpointEvent )event);
184
185
display("redefining...");
186
redefineDebugee();
187
188
Receiver recv = new Receiver();
189
recv.start();
190
191
debugee.resume();
192
193
} else if (event instanceof VMDeathEvent) {
194
exit = true;
195
break;
196
} else if (event instanceof VMDisconnectEvent) {
197
exit = true;
198
break;
199
} // if
200
} // while
201
tmp = System.currentTimeMillis();
202
delta = tmp - begin;
203
totalTime -= delta;
204
begin = tmp;
205
}
206
207
if (eventCount != expectedEventCount) {
208
if (totalTime <= 0) {
209
complain("out of wait time...");
210
}
211
complain("expecting " + expectedEventCount
212
+ " events, but "
213
+ eventCount + " events arrived.");
214
exitStatus = Consts.TEST_FAILED;
215
}
216
217
display("=============");
218
display("TEST FINISHES\n");
219
}
220
221
private void redefineDebugee() {
222
Map<? extends com.sun.jdi.ReferenceType,byte[]> mapBytes;
223
boolean alreadyComplained = false;
224
mapBytes = mapClassToBytes(newClassFile);
225
try {
226
debugee.VM().redefineClasses(mapBytes);
227
} catch (Exception e) {
228
throw new Failure(UNEXPECTED_STRING + e);
229
}
230
}
231
232
private Map<? extends com.sun.jdi.ReferenceType,byte[]> mapClassToBytes(String fileName) {
233
display("class-file\t:" + fileName);
234
File fileToBeRedefined = new File(classDir + File.separator + fileName);
235
int fileToRedefineLength = (int )fileToBeRedefined.length();
236
byte[] arrayToRedefine = new byte[fileToRedefineLength];
237
238
FileInputStream inputFile;
239
try {
240
inputFile = new FileInputStream(fileToBeRedefined);
241
} catch (FileNotFoundException e) {
242
throw new Failure(UNEXPECTED_STRING + e);
243
}
244
245
try {
246
inputFile.read(arrayToRedefine);
247
inputFile.close();
248
} catch (IOException e) {
249
throw new Failure(UNEXPECTED_STRING + e);
250
}
251
HashMap<com.sun.jdi.ReferenceType,byte[]> mapForClass = new HashMap<com.sun.jdi.ReferenceType,byte[]>();
252
mapForClass.put(debugeeClass, arrayToRedefine);
253
return mapForClass;
254
}
255
256
private void hitBreakpoint(BreakpointEvent event) {
257
eventInfo(event);
258
if (event.location().lineNumber() == tc10x001a.checkLastLine &&
259
eventCount == 1) {
260
display("!!!BreakpointEvent steps to the expected line "
261
+ event.location().lineNumber() + "!!!");
262
} else {
263
complain("BreakpointEvent steps to line " + event.location().lineNumber()
264
+ ", expected line number is "
265
+ tc10x001a.checkLastLine);
266
exitStatus = Consts.TEST_FAILED;
267
}
268
display("");
269
}
270
271
private void eventInfo(LocatableEvent event) {
272
eventCount++;
273
display("event info: #" + eventCount);
274
display("\tthread\t- " + event.thread().name());
275
locationInfo(event);
276
}
277
278
private void locationInfo(Locatable loc) {
279
try {
280
display("\tsource\t- " + loc.location().sourceName());
281
display("\tmethod\t- " + loc.location().method().name());
282
display("\tline\t- " + loc.location().lineNumber());
283
} catch (AbsentInformationException e) {
284
display("***information is not available***");
285
}
286
}
287
288
class Receiver extends Thread {
289
public void run() {
290
try {
291
String tmp = debugee.receiveSignal();
292
display("received value:\t" + tmp);
293
int actualValue = Integer.parseInt(tmp.substring(1));
294
if (actualValue != tc10x001a.INITIAL_INT_VALUE) {
295
complain("Unexpected value of local variable - " + actualValue);
296
exitStatus = Consts.TEST_FAILED;
297
} else {
298
display("!!!Expected value of local variable - " + actualValue);
299
}
300
} catch (Throwable e) {
301
complain(UNEXPECTED_STRING + e);
302
exitStatus = Consts.TEST_FAILED;
303
} finally {
304
debugee.sendSignal(tc10x001.SGL_QUIT); // Acknowledge debugee result received.
305
}
306
}
307
}
308
}
309
310