Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdb/interrupt/interrupt001/interrupt001.java
40955 views
1
/*
2
* Copyright (c) 2002, 2020, 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
25
/*
26
* @test
27
*
28
* @summary converted from VM Testbase nsk/jdb/interrupt/interrupt001.
29
* VM Testbase keywords: [jpda, jdb]
30
* VM Testbase readme:
31
* DECSRIPTION
32
* A positive test case for the 'interrupt <thread id>' command.
33
* The debuggee program (interrupt001a.java) creates a number of additional
34
* threads with name like "MyThread-<number>" and starts them. The jdb
35
* suspends the debuggee at a moment when the additional threads are
36
* waiting for notification for lock objects and then tries to interrupt them.
37
* If these threads are interrupted then a value of the special
38
* "notInterrupted" variable should not be modified.
39
* Value of "notInterrupted" variable is checked by "eval <expr>" command.
40
* The test passes if the value is equal to 0 and fails otherwise..
41
* COMMENTS
42
* Modified due to fix of the bug:
43
* 4760826 TTY: 'interrupt <threadID>' command sometimes does not work in Mantis
44
* Modified due to fix of the bug:
45
* 4974992 Missed prompt with jdb testcase nsk/jdb/interrupt/interrupt001
46
*
47
* @library /vmTestbase
48
* /test/lib
49
* @build nsk.jdb.interrupt.interrupt001.interrupt001a
50
* @run main/othervm
51
* nsk.jdb.interrupt.interrupt001.interrupt001
52
* -arch=${os.family}-${os.simpleArch}
53
* -waittime=5
54
* -debugee.vmkind=java
55
* -transport.address=dynamic
56
* -jdb=${test.jdk}/bin/jdb
57
* -java.options="${test.vm.opts} ${test.java.opts}"
58
* -workdir=.
59
* -debugee.vmkeys="${test.vm.opts} ${test.java.opts}"
60
*/
61
62
package nsk.jdb.interrupt.interrupt001;
63
64
import nsk.share.*;
65
import nsk.share.jdb.*;
66
67
import java.io.*;
68
import java.util.*;
69
import java.util.regex.Matcher;
70
import java.util.regex.Pattern;
71
import java.util.stream.Collectors;
72
73
public class interrupt001 extends JdbTest {
74
75
public static void main (String argv[]) {
76
System.exit(run(argv, System.out) + JCK_STATUS_BASE);
77
}
78
79
public static int run(String argv[], PrintStream out) {
80
debuggeeClass = DEBUGGEE_CLASS;
81
firstBreak = FIRST_BREAK;
82
return new interrupt001().runTest(argv, out);
83
}
84
85
static final String PACKAGE_NAME = "nsk.jdb.interrupt.interrupt001";
86
static final String TEST_CLASS = PACKAGE_NAME + ".interrupt001";
87
static final String DEBUGGEE_CLASS = TEST_CLASS + "a";
88
static final String FIRST_BREAK = DEBUGGEE_CLASS + ".main";
89
static final String LAST_BREAK = DEBUGGEE_CLASS + ".breakHere";
90
static final String MYTHREAD = "MyThread";
91
static final String DEBUGGEE_THREAD = DEBUGGEE_CLASS + "$" + MYTHREAD;
92
static final String DEBUGGEE_RESULT = DEBUGGEE_CLASS + ".notInterrupted.get()";
93
94
static int numThreads = nsk.jdb.interrupt.interrupt001.interrupt001a.numThreads;
95
96
/*
97
* Pattern for finding the thread ID in a line like the following:
98
* (nsk.jdb.interrupt.interrupt001.interrupt001a$MyThread)651 Thread-0 cond. waiting
99
* Note we can't match on DEBUGGEE_THREAD because it includes a $, which Pattern
100
* uses to match the end of a line.
101
*/
102
private static Pattern tidPattern = Pattern.compile("\\(.+" + MYTHREAD + "\\)(\\S+)");
103
104
protected void runCases() {
105
String[] reply;
106
Paragrep grep;
107
String found;
108
String[] threads;
109
110
jdb.setBreakpointInMethod(LAST_BREAK);
111
reply = jdb.receiveReplyFor(JdbCommand.cont);
112
113
threads = jdb.getThreadIds(DEBUGGEE_THREAD);
114
115
if (threads.length != numThreads) {
116
log.complain("jdb should report " + numThreads + " instance of " + DEBUGGEE_THREAD);
117
log.complain("Found: " + threads.length);
118
success = false;
119
}
120
121
pauseTillAllThreadsWaiting(threads);
122
123
for (int i = 0; i < threads.length; i++) {
124
reply = jdb.receiveReplyFor(JdbCommand.interrupt + threads[i]);
125
}
126
127
reply = jdb.receiveReplyFor(JdbCommand.threads);
128
reply = jdb.receiveReplyFor(JdbCommand.cont, true);
129
130
reply = jdb.receiveReplyFor(JdbCommand.eval + DEBUGGEE_RESULT);
131
grep = new Paragrep(reply);
132
found = grep.findFirst(DEBUGGEE_RESULT + " =" );
133
if (found.length() > 0) {
134
if (found.indexOf(DEBUGGEE_RESULT + " = 0") < 0) {
135
log.complain("Not all " + MYTHREAD + "s were interrupted.");
136
log.complain(found);
137
success = false;
138
}
139
} else {
140
log.complain("TEST BUG: not found value for " + DEBUGGEE_RESULT);
141
}
142
143
jdb.contToExit(1);
144
}
145
146
private void pauseTillAllThreadsWaiting(String[] threads) {
147
String[] reply;
148
boolean tidswaiting = false;
149
150
Set<String> tids = new HashSet<>(Arrays.asList(threads));
151
Set<String> waitingTids = null;
152
153
do {
154
String[] thrdsRply = (String[])jdb.receiveReplyFor(JdbCommand.threads);
155
waitingTids = Arrays.asList(thrdsRply).stream()
156
.filter((r)-> r.endsWith("waiting"))
157
.map((r)->{
158
Matcher m = tidPattern.matcher(r);
159
if (m.find()) {
160
return m.group(1);
161
}
162
return null;
163
})
164
.filter((r)-> r != null)
165
.collect(Collectors.toSet());
166
167
// If all Tids are waiting set allWorkersAreWaiting to true so
168
// the main test thread will get out of its breakpoint loop
169
// and continue with the test.
170
if (waitingTids.containsAll(tids)) {
171
reply = jdb.receiveReplyFor(JdbCommand.set + DEBUGGEE_CLASS + ".allWorkersAreWaiting=true");
172
tidswaiting = true;
173
} else {
174
reply = jdb.receiveReplyFor(JdbCommand.cont);
175
}
176
} while (!tidswaiting);
177
}
178
}
179
180