Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/EventSet/virtualMachine/virtualmachine001.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.EventSet.virtualMachine;
25
26
import nsk.share.*;
27
import nsk.share.jdi.*;
28
import com.sun.jdi.*;
29
import com.sun.jdi.request.*;
30
import com.sun.jdi.event.*;
31
import java.io.*;
32
33
/**
34
* The debugger application of the test.
35
*/
36
public class virtualmachine001 {
37
38
//------------------------------------------------------- immutable common fields
39
40
final static String SIGNAL_READY = "ready";
41
final static String SIGNAL_GO = "go";
42
final static String SIGNAL_QUIT = "quit";
43
44
private static int waitTime;
45
private static int exitStatus;
46
private static ArgumentHandler argHandler;
47
private static Log log;
48
private static Debugee debuggee;
49
private static ReferenceType debuggeeClass;
50
51
//------------------------------------------------------- mutable common fields
52
53
private final static String prefix = "nsk.jdi.EventSet.virtualMachine.";
54
private final static String className = "virtualmachine001";
55
private final static String debuggerName = prefix + className;
56
private final static String debuggeeName = debuggerName + "a";
57
58
//------------------------------------------------------- test specific fields
59
60
private static VirtualMachine vm;
61
62
//------------------------------------------------------- immutable common methods
63
64
public static void main(String argv[]) {
65
System.exit(Consts.JCK_STATUS_BASE + run(argv, System.out));
66
}
67
68
private static void display(String msg) {
69
log.display("debugger > " + msg);
70
}
71
72
private static void complain(String msg) {
73
log.complain("debugger FAILURE > " + msg);
74
}
75
76
public static int run(String argv[], PrintStream out) {
77
78
exitStatus = Consts.TEST_PASSED;
79
80
argHandler = new ArgumentHandler(argv);
81
log = new Log(out, argHandler);
82
waitTime = argHandler.getWaitTime() * 60000;
83
84
debuggee = Debugee.prepareDebugee(argHandler, log, debuggeeName);
85
86
debuggeeClass = debuggee.classByName(debuggeeName);
87
if ( debuggeeClass == null ) {
88
complain("Class '" + debuggeeName + "' not found.");
89
exitStatus = Consts.TEST_FAILED;
90
}
91
92
execTest();
93
94
debuggee.quit();
95
96
return exitStatus;
97
}
98
99
//------------------------------------------------------ mutable common method
100
101
private static void execTest() {
102
103
BreakpointRequest brkp = debuggee.setBreakpoint(debuggeeClass,
104
virtualmachine001a.brkpMethodName,
105
virtualmachine001a.brkpLineNumber);
106
debuggee.resume();
107
108
// get expected reference for comparison.
109
vm = debuggee.VM();
110
111
debuggee.sendSignal(SIGNAL_GO);
112
EventSet eventSet = null;
113
114
// waiting the breakpoint event
115
try {
116
eventSet = waitEventSet(brkp, waitTime);
117
} catch (InterruptedException e) {
118
throw new Failure("unexpected InterruptedException while waiting for Breakpoint event");
119
}
120
if (eventSet == null)
121
throw new Failure("Expected EventSet didn't arrive");
122
123
if (!(eventSet.eventIterator().nextEvent() instanceof BreakpointEvent)) {
124
debuggee.resume();
125
throw new Failure("BreakpointEvent didn't arrive");
126
}
127
128
display("Checking virtualMachine() method for eventSet of Breakpoint event");
129
checkVM (eventSet);
130
131
display("Checking completed!");
132
debuggee.resume();
133
}
134
135
//--------------------------------------------------------- test specific methods
136
137
private static EventSet waitEventSet(EventRequest request, long timeout)
138
throws InterruptedException {
139
Event event;
140
long totalTime = timeout;
141
long tmp, begin = System.currentTimeMillis(),
142
delta = 0;
143
boolean exit = false;
144
EventIterator eventIterator = null;
145
EventSet eventSet = null;
146
147
while (totalTime > 0 && !exit) {
148
if (eventIterator == null || !eventIterator.hasNext()) {
149
eventSet = debuggee.VM().eventQueue().remove(totalTime);
150
if (eventSet != null) {
151
eventIterator = eventSet.eventIterator();
152
} else {
153
eventIterator = null;
154
}
155
}
156
if (eventIterator != null) {
157
while (eventIterator.hasNext()) {
158
event = eventIterator.nextEvent();
159
display(" event ===>>> " + event);
160
if (event.request() != null && event.request().equals(request)) {
161
return eventSet;
162
} else if (request == null && event instanceof VMStartEvent) {
163
return eventSet;
164
} else if (event instanceof VMDisconnectEvent) {
165
exit = true;
166
break;
167
} // if
168
} // while
169
} // if
170
tmp = System.currentTimeMillis();
171
delta = tmp - begin;
172
totalTime -= delta;
173
begin = tmp;
174
}
175
return null;
176
}
177
178
private static void checkVM (EventSet eventSet) {
179
VirtualMachine vm1 = eventSet.virtualMachine();
180
if (vm1 == null) {
181
complain("virtualMachine() returns null for event set");
182
exitStatus = Consts.TEST_FAILED;
183
} else if (vm1 != vm) {
184
complain("virtualMachine() returns different VirtualMachine object");
185
exitStatus = Consts.TEST_FAILED;
186
}
187
}
188
}
189
//--------------------------------------------------------- test specific classes
190
191