Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/EventRequest/disable/disable003.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.EventRequest.disable;
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
* The test checks up <code>com.sun.jdi.EventRequest.disable()</code> after
39
* class file redefinition.
40
*
41
* The test performs as follow:
42
* Debuggee has two classes. Debugger creates a <code>BreakpointRequest</code>
43
* at the first class and waits a corresponding event. After getting
44
* <code>BreakpointEvent</code>, debugger redefines the second class, tries to
45
* disable the set breakpoint and checks status of the <code>BreakpointRequest</code>
46
* to be disabled.
47
*/
48
49
public class disable003 {
50
51
public final static String UNEXPECTED_STRING = "***Unexpected exception ";
52
53
private final static String prefix = "nsk.jdi.EventRequest.disable.";
54
private final static String debuggerName = prefix + "disable003";
55
public final static String debugeeName = debuggerName + "a";
56
public final static String testedClassName = debuggerName + "b";
57
58
private final static String classFileName = "disable003b.class";
59
private final static String newClassFile = "newclass" + File.separator
60
+ prefix.replace('.',File.separatorChar)
61
+ classFileName;
62
63
private static int exitStatus;
64
private static Log log;
65
private static Debugee debugee;
66
private static long waitTime;
67
private static String classDir;
68
69
public final static int expectedEventCount = 1;
70
private ReferenceType debugeeClass;
71
72
private static void display(String msg) {
73
log.display(msg);
74
}
75
76
private static void complain(String msg) {
77
log.complain(msg + "\n");
78
}
79
80
public static void main(String argv[]) {
81
System.exit(Consts.JCK_STATUS_BASE + run(argv, System.out));
82
}
83
84
public static int run(String argv[], PrintStream out) {
85
86
exitStatus = Consts.TEST_PASSED;
87
88
disable003 thisTest = new disable003();
89
90
ArgumentHandler argHandler = new ArgumentHandler(argv);
91
log = new Log(out, argHandler);
92
93
classDir = argv[0];
94
waitTime = argHandler.getWaitTime() * 60000;
95
96
Binder binder = new Binder(argHandler, log);
97
debugee = binder.bindToDebugee(debugeeName);
98
debugee.redirectOutput(log);
99
100
try {
101
thisTest.execTest();
102
} catch (Throwable e) {
103
exitStatus = Consts.TEST_FAILED;
104
e.printStackTrace();
105
} finally {
106
debugee.endDebugee();
107
}
108
display("Test finished. exitStatus = " + exitStatus);
109
110
return exitStatus;
111
}
112
113
private void execTest() throws Failure {
114
115
if (!debugee.VM().canRedefineClasses()) {
116
display("\n>>>canRedefineClasses() is false<<< test canceled.\n");
117
return;
118
}
119
120
display("\nTEST BEGINS");
121
display("===========");
122
123
EventSet eventSet = null;
124
EventIterator eventIterator = null;
125
Event event;
126
long totalTime = waitTime;
127
long tmp, begin = System.currentTimeMillis(),
128
delta = 0;
129
boolean exit = false;
130
131
EventRequestManager evm = debugee.getEventRequestManager();
132
ClassPrepareRequest req = evm.createClassPrepareRequest();
133
req.addClassFilter(debugeeName);
134
req.enable();
135
debugee.resume();
136
137
int eventCount = 0;
138
while (totalTime > 0 && !exit) {
139
if (eventIterator == null || !eventIterator.hasNext()) {
140
try {
141
eventSet = debugee.VM().eventQueue().remove(totalTime);
142
} catch (InterruptedException e) {
143
new Failure(e);
144
}
145
if (eventSet != null) {
146
eventIterator = eventSet.eventIterator();
147
} else {
148
eventIterator = null;
149
}
150
}
151
if (eventIterator != null) {
152
while (eventIterator.hasNext()) {
153
event = eventIterator.nextEvent();
154
// display("\nevent ===>>> " + event);
155
156
if (event instanceof ClassPrepareEvent) {
157
display("\nevent ===>>> " + event);
158
prepareTestCases();
159
debugee.resume();
160
161
} else if (event instanceof BreakpointEvent) {
162
display("\nevent ===>>> " + event);
163
ClassType testedClass;
164
testedClass = (ClassType )debugee.classByName(testedClassName);
165
166
display("\nredefinition of the \""
167
+ testedClassName + "\" class");
168
redefineDebugee(testedClass, newClassFile);
169
170
eventCount++;
171
boolean isBrkpEnabled = event.request().isEnabled();
172
if (!isBrkpEnabled) {
173
complain("breakpoint was disabled after "
174
+ "the redefinition of an other class");
175
exitStatus = Consts.TEST_FAILED;
176
} else {
177
display("\nis breakpoint enabled?\t" + isBrkpEnabled);
178
display("\ndisabling the breakpoint request...");
179
event.request().disable();
180
if (event.request().isEnabled()) {
181
complain("breakpoint is not disabled");
182
exitStatus = Consts.TEST_FAILED;
183
}
184
}
185
debugee.resume();
186
187
} else if (event instanceof VMDeathEvent) {
188
exit = true;
189
break;
190
} else if (event instanceof VMDisconnectEvent) {
191
exit = true;
192
break;
193
} // if
194
} // while
195
} // if
196
tmp = System.currentTimeMillis();
197
delta = tmp - begin;
198
totalTime -= delta;
199
begin = tmp;
200
}
201
202
if (totalTime <= 0) {
203
complain("out of wait time...");
204
exitStatus = Consts.TEST_FAILED;
205
}
206
if (eventCount != expectedEventCount) {
207
complain("expecting " + expectedEventCount
208
+ " events, but "
209
+ eventCount + " events arrived.");
210
exitStatus = Consts.TEST_FAILED;
211
}
212
213
display("=============");
214
display("TEST FINISHES\n");
215
}
216
217
private void redefineDebugee(ReferenceType refType, String classFileName) {
218
Map<? extends com.sun.jdi.ReferenceType,byte[]> mapBytes;
219
boolean alreadyComplained = false;
220
mapBytes = mapClassToBytes(refType, classFileName);
221
try {
222
debugee.VM().redefineClasses(mapBytes);
223
} catch (Exception e) {
224
throw new Failure(UNEXPECTED_STRING + e);
225
}
226
}
227
228
private Map<? extends com.sun.jdi.ReferenceType,byte[]> mapClassToBytes(ReferenceType refType, String fileName) {
229
display("a new class-file\t:" + fileName);
230
File fileToBeRedefined = new File(classDir + File.separator + fileName);
231
int fileToRedefineLength = (int )fileToBeRedefined.length();
232
byte[] arrayToRedefine = new byte[fileToRedefineLength];
233
234
FileInputStream inputFile;
235
try {
236
inputFile = new FileInputStream(fileToBeRedefined);
237
} catch (FileNotFoundException e) {
238
throw new Failure(UNEXPECTED_STRING + e);
239
}
240
241
try {
242
inputFile.read(arrayToRedefine);
243
inputFile.close();
244
} catch (IOException e) {
245
throw new Failure(UNEXPECTED_STRING + e);
246
}
247
HashMap<com.sun.jdi.ReferenceType,byte[]> mapForClass = new HashMap<com.sun.jdi.ReferenceType,byte[]>();
248
mapForClass.put(refType, arrayToRedefine);
249
return mapForClass;
250
}
251
252
private void prepareTestCases() {
253
debugeeClass = debugee.classByName(debugeeName);
254
display("debugeeClass\t\t:" + debugeeClass.name());
255
display("setting breakpoint...");
256
debugee.setBreakpoint(debugeeClass,
257
disable003a.brkpMethodName,
258
disable003a.brkpLineNumber);
259
}
260
}
261
262