Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadReference/Stop/stop001a.java
41161 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.jdwp.ThreadReference.Stop;
25
26
import nsk.share.*;
27
import nsk.share.jpda.*;
28
import nsk.share.jdwp.*;
29
30
import java.io.*;
31
32
/**
33
* This class represents debuggee part in the test.
34
*/
35
public class stop001a {
36
37
// name for the tested thread
38
public static final String THREAD_NAME = "TestedThreadName";
39
public static final String THREAD_FIELD_NAME = "thread";
40
public static final String THROWABLE_FIELD_NAME = "throwable";
41
42
// frames count for tested thread in recursive method invokation
43
public static final int FRAMES_COUNT = 10;
44
45
// notification object to notify debuggee that thread is started
46
private static Object threadStarting = new Object();
47
// object which thread will wait for before being interruted
48
private static Object threadWaiting = new Object();
49
50
// scaffold objects
51
private static volatile ArgumentHandler argumentHandler = null;
52
private static volatile Log log = null;
53
54
public static void main(String args[]) {
55
stop001a _stop001a = new stop001a();
56
System.exit(stop001.JCK_STATUS_BASE + _stop001a.runIt(args, System.err));
57
}
58
59
public int runIt(String args[], PrintStream out) {
60
//make log for debugee messages
61
argumentHandler = new ArgumentHandler(args);
62
log = new Log(out, argumentHandler);
63
long timeout = argumentHandler.getWaitTime() * 60 * 1000; // milliseconds
64
65
// make communication pipe to debugger
66
log.display("Creating pipe");
67
IOPipe pipe = argumentHandler.createDebugeeIOPipe(log);
68
69
// load tested class and create tested thread
70
log.display("Creating object of tested class");
71
TestedClass.thread = new TestedClass(THREAD_NAME);
72
73
// start the thread and wait for notification from it
74
synchronized (threadStarting) {
75
TestedClass.thread.start();
76
try {
77
threadStarting.wait();
78
} catch (InterruptedException e) {
79
log.complain("Interruption while waiting for thread started:\n\t" + e);
80
pipe.println(stop001.ERROR);
81
log.display("Debugee FAILED");
82
return stop001.FAILED;
83
}
84
85
// ensure that tested thread is waiting for object
86
synchronized (threadWaiting) {
87
// send debugger signal READY
88
log.display("Sending signal to debugger: " + stop001.READY);
89
pipe.println(stop001.READY);
90
}
91
}
92
93
// wait for signal QUIT from debugeer
94
log.display("Waiting for signal from debugger: " + stop001.RUN);
95
String signal = pipe.readln();
96
log.display("Received signal from debugger: " + signal);
97
98
// check received signal
99
if (signal == null || !signal.equals(stop001.RUN)) {
100
log.complain("Unexpected communication signal from debugee: " + signal
101
+ " (expected: " + stop001.RUN + ")");
102
log.display("Debugee FAILED");
103
return stop001.FAILED;
104
}
105
106
// wait for thread finished in a waittime interval
107
log.display("Waiting for tested thread finished for timeout: " + timeout);
108
try {
109
TestedClass.thread.join(timeout);
110
} catch (InterruptedException e) {
111
log.complain("Interruption while waiting for tested thread finished:\n\t" + e);
112
pipe.println(stop001.ERROR);
113
log.display("Debugee FAILED");
114
return stop001.FAILED;
115
}
116
117
// test if thread was interrupted by debugger
118
if (TestedClass.thread.isAlive()) {
119
log.display("Sending signal to debugger: " + stop001.NOT_STOPPED);
120
pipe.println(stop001.NOT_STOPPED);
121
// interrupt thread to allow it to finish
122
TestedClass.thread.interrupt();
123
} else {
124
log.display("Sending signal to debugger: " + stop001.STOPPED);
125
pipe.println(stop001.STOPPED);
126
}
127
128
// wait for signal QUIT from debugeer
129
log.display("Waiting for signal from debugger: " + stop001.QUIT);
130
signal = pipe.readln();
131
log.display("Received signal from debugger: " + signal);
132
133
// check received signal
134
if (signal == null || !signal.equals(stop001.QUIT)) {
135
log.complain("Unexpected communication signal from debugee: " + signal
136
+ " (expected: " + stop001.QUIT + ")");
137
log.display("Debugee FAILED");
138
return stop001.FAILED;
139
}
140
141
// exit debugee
142
log.display("Debugee PASSED");
143
return stop001.PASSED;
144
}
145
146
// tested thread class
147
public static class TestedClass extends Thread {
148
149
// field with the tested Thread value
150
public static volatile TestedClass thread = null;
151
152
// field with the tested Throwable value
153
public static volatile Throwable throwable = new Throwable("Tested throwable");
154
155
TestedClass(String name) {
156
super(name);
157
}
158
159
// start the thread and recursive invoke makeFrames()
160
public void run() {
161
log.display("Tested thread started");
162
163
synchronized (threadWaiting) {
164
165
// notify debuggee that thread started
166
synchronized (threadStarting) {
167
threadStarting.notifyAll();
168
}
169
170
// wait infinitely for notification object
171
try {
172
threadWaiting.wait();
173
log.complain("Tested thread NOT interrupted");
174
} catch (InterruptedException e) {
175
log.display("Tested thread interrupted");
176
}
177
}
178
179
log.display("Tested thread finished");
180
}
181
182
}
183
184
}
185
186