Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/EventRequestManager/createStepRequest/crstepreq001.java
41161 views
1
/*
2
* Copyright (c) 2001, 2019, 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.EventRequestManager.createStepRequest;
25
26
import com.sun.jdi.ThreadReference;
27
import com.sun.jdi.VirtualMachine;
28
import com.sun.jdi.request.StepRequest;
29
import com.sun.jdi.request.EventRequestManager;
30
import com.sun.jdi.request.DuplicateRequestException;
31
import com.sun.jdi.ObjectCollectedException;
32
import com.sun.jdi.VMMismatchException;
33
import java.util.Iterator;
34
import java.util.LinkedList;
35
import java.util.List;
36
import java.io.*;
37
import nsk.share.*;
38
import nsk.share.jpda.*;
39
import nsk.share.jdi.*;
40
41
42
/**
43
* The test checks that only one pending JDI step request is
44
* allowed per thread, i.e. the JDI method
45
* <code>com.sun.jdi.request.EventRequestManager.createStepRequest()</code>
46
* properly throws a <code>DuplicateRequestException</code> if there
47
* is already a pending step request for the specified thread.
48
*/
49
public class crstepreq001 {
50
public static final int PASSED = 0;
51
public static final int FAILED = 2;
52
public static final int JCK_STATUS_BASE = 95;
53
static final String DEBUGGEE_CLASS =
54
"nsk.jdi.EventRequestManager.createStepRequest.crstepreq001t";
55
static final String DEBUGGEE_THRD = "debuggee_thr";
56
static final String COMMAND_READY = "ready";
57
static final String COMMAND_QUIT = "quit";
58
59
static final int RSTS_NUM = 6;
60
static final int RESTRICTIONS[][] = {
61
{StepRequest.STEP_MIN, StepRequest.STEP_INTO},
62
{StepRequest.STEP_MIN, StepRequest.STEP_OVER},
63
{StepRequest.STEP_MIN, StepRequest.STEP_OUT},
64
{StepRequest.STEP_LINE, StepRequest.STEP_INTO},
65
{StepRequest.STEP_LINE, StepRequest.STEP_OVER},
66
{StepRequest.STEP_LINE, StepRequest.STEP_OUT}
67
};
68
69
private Log log;
70
private IOPipe pipe;
71
private Debugee debuggee;
72
private int tot_res = PASSED;
73
74
public static void main (String argv[]) {
75
System.exit(run(argv,System.out) + JCK_STATUS_BASE);
76
}
77
78
public static int run(String argv[], PrintStream out) {
79
return new crstepreq001().runIt(argv, out);
80
}
81
82
private int runIt(String args[], PrintStream out) {
83
ArgumentHandler argHandler = new ArgumentHandler(args);
84
log = new Log(out, argHandler);
85
Binder binder = new Binder(argHandler, log);
86
ThreadReference thR = null;
87
List threads;
88
List<StepRequest> enabledStepRequests = new LinkedList<>();
89
String cmd;
90
91
debuggee = binder.bindToDebugee(DEBUGGEE_CLASS);
92
pipe = debuggee.createIOPipe();
93
debuggee.redirectStderr(log, "crstepreq001t.err> ");
94
VirtualMachine vm = debuggee.VM();
95
EventRequestManager erManager = vm.eventRequestManager();
96
debuggee.resume();
97
cmd = pipe.readln();
98
if (!cmd.equals(COMMAND_READY)) {
99
log.complain("TEST BUG: unknown debuggee's command: "
100
+ cmd);
101
return quitDebuggee(FAILED);
102
}
103
104
try {
105
threads = vm.allThreads();
106
} catch (Exception e) {
107
log.complain("TEST FAILURE: allThreads: " + e);
108
return quitDebuggee(FAILED);
109
}
110
Iterator iter = threads.iterator();
111
while (iter.hasNext()) {
112
thR = (ThreadReference) iter.next();
113
if (thR.name().equals(DEBUGGEE_THRD)) {
114
log.display("\nCreating StepRequest for the debuggee's thread \""
115
+ thR.name() + "\"");
116
try {
117
StepRequest sReq = erManager.createStepRequest(thR,
118
RESTRICTIONS[0][0],RESTRICTIONS[0][1]);
119
sReq.enable();
120
enabledStepRequests.add(sReq);
121
} catch (DuplicateRequestException e) {
122
log.complain("TEST FAILURE: createStepRequest: caught " + e);
123
return quitDebuggee(FAILED);
124
} catch (ObjectCollectedException e) {
125
log.complain("TEST FAILURE: createStepRequest: caught " + e);
126
return quitDebuggee(FAILED);
127
} catch (VMMismatchException e) {
128
log.complain("TEST FAILURE: createStepRequest: caught " + e);
129
return quitDebuggee(FAILED);
130
}
131
break;
132
}
133
}
134
135
// Check that createStepRequest() throws DuplicateRequestException
136
// to indicate a duplicate event request per thread
137
for(int i=0; i<RSTS_NUM; i++) {
138
log.display("\n" + (i+1)
139
+ ") Trying to create a duplicate StepRequest object\n\twith size="
140
+ RESTRICTIONS[i][0] + "; depth="
141
+ RESTRICTIONS[i][1] + " for the debuggee's thread \""
142
+ thR.name() + "\"");
143
try {
144
StepRequest sReq = erManager.createStepRequest(thR,
145
RESTRICTIONS[i][0], RESTRICTIONS[i][1]);
146
log.complain("TEST CASE #" + (i+1)
147
+ " FAILED: createStepRequest successfully done\n"
148
+ "\tfor a duplicate StepRequest object per the specified thread \""
149
+ thR.name() + "\"\n"
150
+ "\tbut it should throw DuplicateRequestException");
151
tot_res = FAILED;
152
} catch (DuplicateRequestException e) {
153
log.display("TEST CASE #" + (i+1)
154
+ " PASSED: createStepRequest: caught " + e);
155
} catch (ObjectCollectedException e) {
156
log.complain("TEST CASE #" + (i+1)
157
+ " FAILED: createStepRequest: caught " + e);
158
log.complain("\tbut it should throw DuplicateRequestException");
159
tot_res = FAILED;
160
} catch (VMMismatchException e) {
161
log.complain("TEST CASE #" + (i+1)
162
+ " FAILED: createStepRequest: caught " + e);
163
log.complain("\tbut it should throw DuplicateRequestException");
164
tot_res = FAILED;
165
}
166
}
167
168
enabledStepRequests.forEach(s -> erManager.deleteEventRequest(s));
169
// There is a chance that a single step event had been posted after
170
// the step request was created and before it was deleted. In this
171
// case the debuggee VM is in the suspended state.
172
vm.resume();
173
return quitDebuggee(tot_res);
174
}
175
176
private int quitDebuggee(int stat) {
177
pipe.println(COMMAND_QUIT);
178
debuggee.waitFor();
179
return stat;
180
}
181
}
182
183