Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/Event/hashCode/hashcode001.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
package nsk.jdi.Event.hashCode;
24
25
import nsk.share.*;
26
import nsk.share.jpda.*;
27
import nsk.share.jdi.*;
28
29
import com.sun.jdi.*;
30
import com.sun.jdi.request.*;
31
import com.sun.jdi.event.*;
32
import com.sun.jdi.connect.*;
33
import java.io.*;
34
import java.util.*;
35
36
/**
37
* The debugger application of the test.
38
*/
39
public class hashcode001 {
40
41
//------------------------------------------------------- immutable common fields
42
43
final static String SIGNAL_READY = "ready";
44
final static String SIGNAL_GO = "go";
45
final static String SIGNAL_QUIT = "quit";
46
47
private static int waitTime;
48
private static int exitStatus;
49
private static ArgumentHandler argHandler;
50
private static Log log;
51
private static Debugee debuggee;
52
private static ReferenceType debuggeeClass;
53
54
//------------------------------------------------------- mutable common fields
55
56
private final static String prefix = "nsk.jdi.Event.hashCode.";
57
private final static String className = "hashcode001";
58
private final static String debuggerName = prefix + className;
59
private final static String debuggeeName = debuggerName + "a";
60
61
//------------------------------------------------------- test specific fields
62
63
private final static String threadClassName = prefix + "hashcode001aThread";
64
private final static String threadName = "thread1";
65
private final static String methodName = "foo";
66
private final static String fieldName = "name";
67
private final static int brkpLineNumber = 145;
68
69
//------------------------------------------------------- immutable common methods
70
71
public static void main(String argv[]) {
72
System.exit(Consts.JCK_STATUS_BASE + run(argv, System.out));
73
}
74
75
private static void display(String msg) {
76
log.display("debugger > " + msg);
77
}
78
79
private static void complain(String msg) {
80
log.complain("debugger FAILURE > " + msg);
81
}
82
83
public static int run(String argv[], PrintStream out) {
84
85
exitStatus = Consts.TEST_PASSED;
86
87
argHandler = new ArgumentHandler(argv);
88
log = new Log(out, argHandler);
89
waitTime = argHandler.getWaitTime() * 60000;
90
91
debuggee = Debugee.prepareDebugee(argHandler, log, debuggeeName);
92
93
debuggeeClass = debuggee.classByName(debuggeeName);
94
if ( debuggeeClass == null ) {
95
throw new Failure("Class '" + debuggeeName + "' not found.");
96
}
97
98
execTest();
99
100
int status = debuggee.endDebugee();
101
if ( status != Consts.JCK_STATUS_BASE ) {
102
throw new Failure("UNEXPECTED Debugee's exit status : " + status);
103
}
104
display("expected Debugee's exit status : " + status);
105
106
return exitStatus;
107
}
108
109
//------------------------------------------------------ mutable common method
110
111
private static void execTest() {
112
113
EventRequestManager eventRequestManager = debuggee.VM().eventRequestManager();
114
EventRequest eventRequest;
115
116
ReferenceType testedClass = debuggee.classByName(threadClassName);
117
if ( testedClass == null ) {
118
throw new Failure("Class '" + threadClassName + "' not found.");
119
}
120
121
for (int i = 0; i < 11; i++) {
122
eventRequest = null;
123
switch (i) {
124
125
case 0:
126
ThreadReference thread = debuggee.threadByName(threadName);
127
128
display(".....setting up StepRequest");
129
eventRequest = eventRequestManager.createStepRequest
130
(thread, StepRequest.STEP_MIN, StepRequest.STEP_INTO);
131
break;
132
133
case 1:
134
display(".....setting up AccessWatchpointRequest");
135
eventRequest = eventRequestManager.createAccessWatchpointRequest
136
(testedClass.fieldByName(fieldName));
137
break;
138
139
case 2:
140
display(".....setting up ModificationWatchpointRequest");
141
eventRequest = eventRequestManager.createModificationWatchpointRequest
142
(testedClass.fieldByName(fieldName));
143
break;
144
145
case 3:
146
display(".....setting up ClassPrepareRequest");
147
eventRequest = eventRequestManager.createClassPrepareRequest();
148
break;
149
150
case 4:
151
display(".....setting up ClassUnloadRequest");
152
eventRequest = eventRequestManager.createClassUnloadRequest();
153
break;
154
155
case 5:
156
display(".....setting up MethodEntryRequest");
157
eventRequest = eventRequestManager.createMethodEntryRequest();
158
break;
159
160
case 6:
161
display(".....setting up MethodExitRequest");
162
eventRequest = eventRequestManager.createMethodExitRequest();
163
break;
164
165
case 7:
166
display(".....setting up ThreadDeathRequest");
167
eventRequest = eventRequestManager.createThreadDeathRequest();
168
break;
169
170
case 8:
171
display(".....setting up ThreadStartRequest");
172
eventRequest = eventRequestManager.createThreadStartRequest();
173
break;
174
175
case 9:
176
display(".....setting up ExceptionRequest");
177
eventRequest = eventRequestManager.createExceptionRequest( null, true, true );
178
break;
179
180
case 10:
181
display(".....setting up BreakpointRequest");
182
eventRequest = debuggee.makeBreakpoint(testedClass, methodName, brkpLineNumber);
183
break;
184
185
default:
186
throw new Failure("Wrong test case : " + i);
187
}
188
189
if (eventRequest == null) {
190
throw new Failure("Cannot create request case : " + i);
191
}
192
eventRequest.addCountFilter(1);
193
eventRequest.enable();
194
}
195
196
debuggee.sendSignal(SIGNAL_GO);
197
198
display("Checking hashCode() method for Event objects");
199
200
boolean exit = false;
201
boolean connected = true;
202
while (!exit) {
203
EventSet eventSet = getEventSet();
204
EventIterator eventIterator = eventSet.eventIterator();
205
206
while (eventIterator.hasNext()) {
207
Event event = eventIterator.nextEvent();
208
String eventName = null;
209
210
if (event instanceof VMDeathEvent) {
211
eventName = "VMDeathEvent";
212
connected = false;
213
} else if (event instanceof VMDisconnectEvent) {
214
eventName = "VMDisconnectEvent";
215
connected = false;
216
exit = true;
217
} else {
218
eventName = "" + event;
219
}
220
221
try {
222
int hCode = event.hashCode();
223
display("hashCode() returns " + hCode + " for Event object : " + eventName);
224
225
if (hCode == 0) {
226
complain("hashCode() returns 0 for Event object " + eventName);
227
exitStatus = Consts.TEST_FAILED;
228
}
229
230
int hCode1 = event.hashCode();
231
if (hCode != hCode1) {
232
complain("hashCode() is not consistent for Event object " + eventName +
233
"\n\t first value :" + hCode + " ; second value : " + hCode1);
234
exitStatus = Consts.TEST_FAILED;
235
}
236
237
} catch (VMDisconnectedException e) {
238
// skip error message if already disconnected
239
if (connected) {
240
throw new Failure("Caught unexpected VMDisconnectedException:\n\t" + e);
241
}
242
}
243
}
244
if (connected) {
245
eventSet.resume();
246
}
247
}
248
display("Checking completed!");
249
}
250
251
//--------------------------------------------------------- test specific methods
252
253
private static EventSet getEventSet() {
254
EventSet eventSet;
255
try {
256
eventSet = debuggee.VM().eventQueue().remove(waitTime);
257
if (eventSet == null) {
258
throw new Failure("TIMEOUT while waiting for event");
259
}
260
} catch ( Exception e ) {
261
throw new Failure("Unexpected exception while waiting for event " + e);
262
}
263
return eventSet;
264
}
265
}
266
//--------------------------------------------------------- test specific classes
267
268