Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdb/kill/kill001/kill001a.java
40951 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.jdb.kill.kill001;
25
26
import nsk.share.*;
27
import nsk.share.jpda.*;
28
import nsk.share.jdb.*;
29
30
import java.io.*;
31
import java.util.*;
32
33
/* This is debuggee aplication */
34
public class kill001a {
35
public static void main(String args[]) {
36
kill001a _kill001a = new kill001a();
37
System.exit(kill001.JCK_STATUS_BASE + _kill001a.runIt(args, System.out));
38
}
39
40
static void breakHere () {}
41
42
static final String MYTHREAD = "MyThread";
43
static final int numThreads = 5; // number of threads. one lock per thread.
44
static Object lock = new Object();
45
static Object waitnotify = new Object();
46
public static volatile int notKilled = 0;
47
static final String message = "kill001a's Exception";
48
static int waitTime;
49
50
static JdbArgumentHandler argumentHandler;
51
static Log log;
52
53
static final Throwable[] exceptions = {
54
new ThreadDeath(),
55
new NullPointerException(message),
56
new SecurityException(message),
57
new com.sun.jdi.IncompatibleThreadStateException(message),
58
new MyException(message)
59
};
60
61
62
public int runIt(String args[], PrintStream out) {
63
64
argumentHandler = new JdbArgumentHandler(args);
65
log = new Log(out, argumentHandler);
66
waitTime = argumentHandler.getWaitTime() * 60 * 1000;
67
68
int i;
69
Thread holder [] = new Thread[numThreads];
70
71
for (i = 0; i < numThreads ; i++) {
72
holder[i] = new MyThread(MYTHREAD + "-" + i);
73
}
74
75
// lock monitor to prevent threads from finishing after they started
76
synchronized (lock) {
77
synchronized (waitnotify) {
78
for (i = 0; i < numThreads ; i++) {
79
holder[i].start();
80
try {
81
waitnotify.wait();
82
} catch (InterruptedException e) {
83
log.complain("Main thread was interrupted while waiting for start of " + MYTHREAD + "-" + i);
84
return kill001.FAILED;
85
}
86
}
87
}
88
breakHere(); // a break to get thread ids and then to kill MyThreads.
89
}
90
91
// wait during watTime until all MyThreads will be killed
92
long oldTime = System.currentTimeMillis();
93
while ((System.currentTimeMillis() - oldTime) <= kill001a.waitTime) {
94
boolean waited = false;
95
for (i = 0; i < numThreads ; i++) {
96
if (holder[i].isAlive()) {
97
waited = true;
98
try {
99
synchronized(waitnotify) {
100
waitnotify.wait(1000);
101
}
102
} catch (InterruptedException e) {
103
log.display("Main thread was interrupted while waiting for killing of " + MYTHREAD + "-" + i);
104
}
105
}
106
}
107
if (!waited) {
108
break;
109
}
110
}
111
breakHere(); // a break to check if MyThreads were killed
112
log.display("notKilled == " + notKilled);
113
114
for (i = 0; i < numThreads ; i++) {
115
if (holder[i].isAlive()) {
116
log.display("Debuggee FAILED");
117
return kill001.FAILED;
118
}
119
}
120
121
log.display("Debuggee PASSED");
122
return kill001.PASSED;
123
}
124
125
static class MyException extends Exception {
126
MyException (String message) {
127
super(message);
128
}
129
}
130
}
131
132
133
class MyThread extends Thread {
134
String name;
135
136
public MyThread (String n) {
137
name = n;
138
}
139
140
public void run() {
141
// Concatenate strings in advance to avoid lambda calculations later
142
String ThreadFinished = "WARNING: Thread finished: " + this.name;
143
String ThreadInterrupted = "WARNING: Thread was interrupted while waiting for killing: " + this.name;
144
kill001a.log.display("Thread started: " + this.name);
145
146
synchronized (kill001a.waitnotify) {
147
kill001a.waitnotify.notify();
148
}
149
// prevent thread from early finish
150
synchronized (kill001a.lock) {}
151
152
// sleep during waitTime to give debugger a chance to kill debugee's thread
153
try {
154
Thread.currentThread().sleep(kill001a.waitTime);
155
} catch (InterruptedException e) {
156
kill001a.log.display(ThreadInterrupted);
157
e.printStackTrace(kill001a.log.getOutStream());
158
}
159
160
kill001a.notKilled++;
161
kill001a.log.display(ThreadFinished);
162
}
163
}
164
165