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/tc05x001.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: 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
* Working of debugger and debugee is synchronized via IOPipe channel.
63
*/
64
65
public class tc05x001 {
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 + "tc05x001";
71
private final static String debugeeName = debuggerName + "a";
72
73
public final static String PERFORM_SGL = "perform";
74
75
private final static String newClassFile = "newclass" + File.separator
76
+ debugeeName.replace('.',File.separatorChar)
77
+ ".class";
78
79
private static int exitStatus;
80
private static Log log;
81
private static Debugee debugee;
82
private static long waitTime;
83
private static String testDir;
84
85
private static final String firstMethodName = "method_B";
86
87
private int eventCount;
88
private int expectedEventCount = 2;
89
private ClassType debugeeClass;
90
StepRequest stepRequest = null;
91
92
private static void display(String msg) {
93
log.display(msg);
94
}
95
96
private static void complain(String msg) {
97
log.complain("debugger FAILURE> " + msg + "\n");
98
}
99
100
public static void main(String argv[]) {
101
System.exit(Consts.JCK_STATUS_BASE + run(argv, System.out));
102
}
103
104
public static int run(String argv[], PrintStream out) {
105
106
exitStatus = Consts.TEST_PASSED;
107
108
tc05x001 thisTest = new tc05x001();
109
110
ArgumentHandler argHandler = new ArgumentHandler(argv);
111
log = new Log(out, argHandler);
112
113
testDir = argv[0];
114
waitTime = argHandler.getWaitTime() * 60000;
115
116
debugee = Debugee.prepareDebugee(argHandler, log, debugeeName);
117
118
try {
119
thisTest.execTest();
120
} catch (Throwable e) {
121
exitStatus = Consts.TEST_FAILED;
122
e.printStackTrace();
123
} finally {
124
debugee.resume();
125
debugee.quit();
126
}
127
display("Test finished. exitStatus = " + exitStatus);
128
129
return exitStatus;
130
}
131
132
private void execTest() throws Failure {
133
134
if (!debugee.VM().canRedefineClasses()) {
135
display("\n>>>canRedefineClasses() is false<<< test canceled.\n");
136
return;
137
}
138
139
debugeeClass = (ClassType)debugee.classByName(debugeeName);
140
141
display("\nTEST BEGINS");
142
display("===========");
143
144
debugee.VM().suspend();
145
146
display("Tested class\t:" + debugeeClass.name());
147
148
BreakpointRequest brkp = debugee.setBreakpoint(debugeeClass,
149
tc05x001a.brkpMethodName,
150
tc05x001a.brkpLineNumber);
151
debugee.resume();
152
debugee.sendSignal(PERFORM_SGL);
153
154
BreakpointEvent brkpEvent = waitBreakpointEvent(brkp, waitTime);
155
156
display("\nredefining...");
157
redefineDebugee();
158
159
ThreadReference thread = brkpEvent.thread();
160
161
EventRequestManager evm = debugee.getEventRequestManager();
162
163
display("creating step request INTO...");
164
stepRequest = evm.createStepRequest(thread, StepRequest.STEP_LINE,
165
StepRequest.STEP_INTO);
166
stepRequest.addClassFilter(debugeeClass);
167
stepRequest.enable();
168
debugee.resume();
169
170
boolean cmp = false;
171
StepEvent stepEvent;
172
Event event;
173
for (int i = 0; i < 3; i++) {
174
// waiting the breakpoint event
175
display("waiting step event...");
176
try {
177
event = debugee.waitingEvent(stepRequest, waitTime);
178
} catch (Exception e) {
179
stepRequest.disable();
180
throw new Failure(UNEXPECTED_STRING + e);
181
}
182
if (!(event instanceof StepEvent )) {
183
stepRequest.disable();
184
throw new Failure("StepEvent didn't arrive");
185
}
186
if (hitStep((StepEvent )event)) {
187
break;
188
}
189
debugee.resume();
190
}
191
evm.deleteEventRequest(stepRequest);
192
debugee.resume();
193
194
display("=============");
195
display("TEST FINISHES\n");
196
}
197
198
private void redefineDebugee() {
199
Map<com.sun.jdi.ReferenceType,byte[]> mapBytes;
200
boolean alreadyComplained = false;
201
mapBytes = mapClassToBytes(newClassFile);
202
try {
203
debugee.VM().redefineClasses(mapBytes);
204
} catch (Exception e) {
205
throw new Failure(UNEXPECTED_STRING + e);
206
}
207
}
208
209
private Map<com.sun.jdi.ReferenceType,byte[]> mapClassToBytes(String fileName) {
210
display("class-file\t:" + fileName);
211
File fileToBeRedefined = new File(testDir + File.separator + fileName);
212
int fileToRedefineLength = (int )fileToBeRedefined.length();
213
byte[] arrayToRedefine = new byte[fileToRedefineLength];
214
215
FileInputStream inputFile;
216
try {
217
inputFile = new FileInputStream(fileToBeRedefined);
218
} catch (FileNotFoundException e) {
219
throw new Failure(UNEXPECTED_STRING + e);
220
}
221
222
try {
223
inputFile.read(arrayToRedefine);
224
inputFile.close();
225
} catch (IOException e) {
226
throw new Failure(UNEXPECTED_STRING + e);
227
}
228
HashMap<com.sun.jdi.ReferenceType,byte[]> mapForClass = new HashMap<com.sun.jdi.ReferenceType,byte[]>();
229
mapForClass.put(debugeeClass, arrayToRedefine);
230
return mapForClass;
231
}
232
233
private BreakpointEvent waitBreakpointEvent(BreakpointRequest brkp, long waitTime) {
234
Event event;
235
try {
236
event = debugee.waitingEvent(brkp, waitTime);
237
} catch (InterruptedException e) {
238
throw new Failure(UNEXPECTED_STRING + e);
239
}
240
if (!(event instanceof BreakpointEvent )) {
241
throw new Failure("BreakpointEvent didn't arrive");
242
}
243
244
return (BreakpointEvent )event;
245
}
246
247
private boolean hitStep(StepEvent event) {
248
locationInfo(event);
249
String methodName = event.location().method().name();
250
boolean ret = methodName.compareTo(firstMethodName) != 0;
251
if (ret) {
252
if (!event.location().method().isObsolete()) {
253
complain("Unexpected event" + event);
254
exitStatus = Consts.TEST_FAILED;
255
} else {
256
display("!!!Expected event location at \"" + methodName + "\"");
257
}
258
} else {
259
display("!!!Expected event location at \"" + methodName + "\"");
260
stepRequest.disable();
261
}
262
display("");
263
return !ret;
264
}
265
266
private void locationInfo(LocatableEvent event) {
267
eventCount++;
268
display("event info: #" + eventCount);
269
display("\tthread\t- " + event.thread().name());
270
try {
271
display("\tsource\t- " + event.location().sourceName());
272
display("\tmethod\t- " + event.location().method().name());
273
display("\tline\t- " + event.location().lineNumber());
274
} catch (AbsentInformationException e) {
275
}
276
}
277
}
278
279