Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/share/jdi/JDIBase.java
41161 views
1
/*
2
* Copyright (c) 2020, 2021, 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.share.jdi;
25
26
import com.sun.jdi.IntegerValue;
27
import com.sun.jdi.Location;
28
import com.sun.jdi.Method;
29
import com.sun.jdi.ReferenceType;
30
import com.sun.jdi.ThreadReference;
31
import com.sun.jdi.VirtualMachine;
32
import com.sun.jdi.event.BreakpointEvent;
33
import com.sun.jdi.event.Event;
34
import com.sun.jdi.event.EventIterator;
35
import com.sun.jdi.event.EventQueue;
36
import com.sun.jdi.event.EventSet;
37
import com.sun.jdi.event.ThreadDeathEvent;
38
import com.sun.jdi.event.ThreadStartEvent;
39
import com.sun.jdi.request.BreakpointRequest;
40
import com.sun.jdi.request.EventRequest;
41
import com.sun.jdi.request.EventRequestManager;
42
import java.util.List;
43
import nsk.share.Log;
44
45
public class JDIBase {
46
47
// Exit code constants
48
public static final int PASSED = 0;
49
public static final int FAILED = 2;
50
public static final int PASS_BASE = 95;
51
52
53
// Log helpers
54
private final String sHeader1 = "\n=> " + this.getClass().getName().replace(".", "/") + " ";
55
56
private static final String
57
sHeader2 = "--> debugger: ",
58
sHeader3 = "##> debugger: ";
59
60
public final void log1(String message) {
61
logHandler.display(sHeader1 + message);
62
}
63
64
public final void log2(String message) {
65
logHandler.display(sHeader2 + message);
66
}
67
68
public final void log3(String message) {
69
logHandler.complain(sHeader3 + message);
70
}
71
72
protected Log logHandler;
73
74
// common variables used by tests
75
protected Debugee debuggee;
76
protected ArgumentHandler argsHandler;
77
protected VirtualMachine vm;
78
protected ReferenceType debuggeeClass;
79
protected static int testExitCode = PASSED;
80
protected long waitTime;
81
82
// used by tests with breakpoint communication
83
protected EventRequestManager eventRManager;
84
protected EventQueue eventQueue;
85
protected EventSet eventSet;
86
protected EventIterator eventIterator;
87
88
// additional fields initialized during breakpoint communication
89
protected Location breakpLocation = null;
90
protected BreakpointEvent bpEvent;
91
92
protected final BreakpointRequest settingBreakpoint(ThreadReference thread,
93
ReferenceType testedClass,
94
String methodName,
95
String bpLine,
96
String property)
97
throws JDITestRuntimeException {
98
99
log2("......setting up a breakpoint:");
100
log2(" thread: " + thread + "; class: " + testedClass +
101
"; method: " + methodName + "; line: " + bpLine);
102
103
List alllineLocations = null;
104
Location lineLocation = null;
105
BreakpointRequest breakpRequest = null;
106
107
try {
108
Method method = (Method) testedClass.methodsByName(methodName).get(0);
109
110
alllineLocations = method.allLineLocations();
111
112
int n =
113
((IntegerValue) testedClass.getValue(testedClass.fieldByName(bpLine))).value();
114
if (n > alllineLocations.size()) {
115
log3("ERROR: TEST_ERROR_IN_settingBreakpoint(): number is out of bound of method's lines");
116
} else {
117
lineLocation = (Location) alllineLocations.get(n);
118
breakpLocation = lineLocation;
119
try {
120
breakpRequest = eventRManager.createBreakpointRequest(lineLocation);
121
breakpRequest.putProperty("number", property);
122
breakpRequest.addThreadFilter(thread);
123
breakpRequest.setSuspendPolicy(EventRequest.SUSPEND_EVENT_THREAD);
124
} catch (Exception e1) {
125
log3("ERROR: inner Exception within settingBreakpoint() : " + e1);
126
breakpRequest = null;
127
}
128
}
129
} catch (Exception e2) {
130
log3("ERROR: ATTENTION: outer Exception within settingBreakpoint() : " + e2);
131
breakpRequest = null;
132
}
133
134
if (breakpRequest == null) {
135
log2(" A BREAKPOINT HAS NOT BEEN SET UP");
136
throw new JDITestRuntimeException("**FAILURE to set up a breakpoint**");
137
}
138
139
log2(" a breakpoint has been set up");
140
return breakpRequest;
141
}
142
143
protected final void getEventSet() throws JDITestRuntimeException {
144
try {
145
eventSet = eventQueue.remove(waitTime);
146
if (eventSet == null) {
147
throw new JDITestRuntimeException("** TIMEOUT while waiting for event **");
148
}
149
eventIterator = eventSet.eventIterator();
150
} catch (Exception e) {
151
throw new JDITestRuntimeException("** EXCEPTION while waiting for event ** : " + e);
152
}
153
}
154
155
// Special version of getEventSet for ThreadStartEvent/ThreadDeathEvent.
156
// When ThreadStartRequest and/or ThreadDeathRequest are enabled,
157
// we can get the events from system threads unexpected for tests.
158
// The method skips ThreadStartEvent/ThreadDeathEvent events
159
// for all threads except the expected one.
160
protected void getEventSetForThreadStartDeath(String threadName) throws JDITestRuntimeException {
161
boolean gotDesiredEvent = false;
162
while (!gotDesiredEvent) {
163
getEventSet();
164
Event event = eventIterator.nextEvent();
165
if (event instanceof ThreadStartEvent evt) {
166
if (evt.thread().name().equals(threadName)) {
167
gotDesiredEvent = true;
168
} else {
169
log2("Got ThreadStartEvent for wrong thread: " + event);
170
}
171
} else if (event instanceof ThreadDeathEvent evt) {
172
if (evt.thread().name().equals(threadName)) {
173
gotDesiredEvent = true;
174
} else {
175
log2("Got ThreadDeathEvent for wrong thread: " + event);
176
}
177
} else {
178
// not ThreadStartEvent nor ThreadDeathEvent
179
gotDesiredEvent = true;
180
}
181
}
182
// reset the iterator before return
183
eventIterator = eventSet.eventIterator();
184
}
185
186
protected void breakpointForCommunication() throws JDITestRuntimeException {
187
188
log2("breakpointForCommunication");
189
getEventSet();
190
191
Event event = eventIterator.nextEvent();
192
if (event instanceof BreakpointEvent) {
193
bpEvent = (BreakpointEvent) event;
194
return;
195
}
196
197
throw new JDITestRuntimeException("** event '" + event + "' IS NOT a breakpoint **");
198
}
199
200
}
201
202