Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/ExceptionRequest/addClassExclusionFilter/filter001.java
41162 views
1
/*
2
* Copyright (c) 2001, 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.ExceptionRequest.addClassExclusionFilter;
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.event.*;
32
import com.sun.jdi.request.*;
33
34
import java.util.*;
35
import java.io.*;
36
37
/**
38
* The test for the implementation of an object of the type
39
* ExceptionRequest.
40
*
41
* The test checks that results of the method
42
* <code>com.sun.jdi.ExceptionRequest.addClassExclusionFilter()</code>
43
* complies with its spec.
44
*
45
* The test checks up on the following assertion:
46
* Restricts the events generated by this request to those
47
* whose location is in a class whose name does not match a
48
* restricted regular expression.
49
* The cases to check include both a pattern that begins with '*' and
50
* one that end with '*'.
51
*
52
* The test works as follows.
53
* - The debugger
54
* - sets up two ExceptionRequests,
55
* - restricts the Requests using patterns that begins with '*' and
56
* ends with *, so that, events will be filtered only from thread1,
57
* - resumes the debuggee, and
58
* - waits for expected ExceptionEvents.
59
* - The debuggee creates and starts two threads, thread1 and thread2,
60
* that being run, throw NullPointerExceptions used
61
* to generate Events and to test the filters.
62
* - Upon getting the events, the debugger performs checks required.
63
*/
64
65
public class filter001 extends TestDebuggerType1 {
66
67
public static void main (String argv[]) {
68
System.exit(run(argv, System.out) + Consts.JCK_STATUS_BASE);
69
}
70
71
public static int run (String argv[], PrintStream out) {
72
debuggeeName = "nsk.jdi.ExceptionRequest.addClassExclusionFilter.filter001a";
73
return new filter001().runThis(argv, out);
74
}
75
76
private String testedClassName1 = "TestClass11";
77
private String testedClassName2 = "nsk.jdi.ExceptionRequest.addClassExclusionFilter.Thread2filter001a";
78
79
protected void testRun() {
80
81
String property1 = "ExceptionRequest1";
82
String property2 = "ExceptionRequest2";
83
84
Event newEvent = null;
85
86
for (int i = 0; ; i++) {
87
88
if (!shouldRunAfterBreakpoint()) {
89
vm.resume();
90
break;
91
}
92
93
display(":::::: case: # " + i);
94
95
switch (i) {
96
97
case 0:
98
final EventRequest eventRequest1 = setting23ExceptionRequest( null,
99
"*" + testedClassName1,
100
EventRequest.SUSPEND_NONE,
101
property1);
102
eventRequest1.enable();
103
eventHandler.addListener(
104
new EventHandler.EventListener() {
105
public boolean eventReceived(Event event) {
106
if (event instanceof ExceptionEvent && event.request().equals(eventRequest1)) {
107
String str = ((ExceptionEvent)event).location().declaringType().name();
108
if (str.endsWith(testedClassName1)) {
109
setFailedStatus("eventRequest1: Received unexpected ExceptionEvent for excluded class:" + str);
110
} else {
111
display("eventRequest1: Received expected ExceptionEvent for " + str);
112
}
113
return true;
114
}
115
return false;
116
}
117
}
118
);
119
120
display("......waiting1 for ExceptionEvent in expected thread");
121
vm.resume();
122
break;
123
124
case 1:
125
final EventRequest eventRequest2 = setting23ExceptionRequest( null,
126
testedClassName2 + "*",
127
EventRequest.SUSPEND_NONE,
128
property2);
129
eventRequest2.enable();
130
eventHandler.addListener(
131
new EventHandler.EventListener() {
132
public boolean eventReceived(Event event) {
133
if (event instanceof ExceptionEvent && event.request().equals(eventRequest2)) {
134
String str = ((ExceptionEvent)event).location().declaringType().name();
135
if (str.endsWith(testedClassName2)) {
136
setFailedStatus("eventRequest2: Received ExceptionEvent for excluded class:" + str);
137
} else {
138
display("eventRequest2: Received expected ExceptionEvent for " + str);
139
}
140
return true;
141
}
142
return false;
143
}
144
}
145
);
146
147
display("......waiting for ExceptionEvent in expected thread");
148
vm.resume();
149
break;
150
151
default:
152
throw new Failure("** default case 2 **");
153
}
154
}
155
return;
156
}
157
158
private ExceptionRequest setting23ExceptionRequest ( ThreadReference thread,
159
String testedClass,
160
int suspendPolicy,
161
String property ) {
162
try {
163
display("......setting up ExceptionRequest:");
164
display(" thread: " + thread + "; class exclude filter: " + testedClass + "; property: " + property);
165
166
ExceptionRequest
167
excr = eventRManager.createExceptionRequest(null, true, true);
168
excr.putProperty("number", property);
169
if (thread != null)
170
excr.addThreadFilter(thread);
171
excr.addClassExclusionFilter(testedClass);
172
excr.setSuspendPolicy(suspendPolicy);
173
174
display(" ExceptionRequest has been set up");
175
return excr;
176
} catch ( Exception e ) {
177
throw new Failure("** FAILURE to set up ExceptionRequest **");
178
}
179
}
180
}
181
182