Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdb/kill/kill002/kill002a.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
package nsk.jdb.kill.kill002;
24
25
import nsk.share.*;
26
import nsk.share.jpda.*;
27
import nsk.share.jdb.*;
28
29
import java.io.*;
30
31
/* This is debuggee aplication */
32
public class kill002a {
33
public static void main(String args[]) {
34
kill002a _kill002a = new kill002a();
35
System.exit(kill002.JCK_STATUS_BASE + _kill002a.runIt(args, System.out));
36
}
37
38
static void breakHere () {}
39
40
static final String MYTHREAD = "MyThread";
41
static final int numThreads = 5; // number of threads
42
static Object waitnotify = new Object();
43
public static volatile int notKilled = 0;
44
static final String message = "kill002a's Exception";
45
46
static JdbArgumentHandler argumentHandler;
47
static Log log;
48
49
static final Exception[] exceptions = {
50
new InterruptedException(message),
51
new NullPointerException(message),
52
new SecurityException(message),
53
new com.sun.jdi.IncompatibleThreadStateException(message),
54
new MyException(message)
55
};
56
57
public int runIt(String args[], PrintStream out) {
58
59
argumentHandler = new JdbArgumentHandler(args);
60
log = new Log(out, argumentHandler);
61
62
int i;
63
Thread[] holder = new Thread[numThreads];
64
Object[] locks = new Object[numThreads];
65
66
for (i = 0; i < numThreads ; i++) {
67
locks[i] = new Object();
68
holder[i] = new MyThread(locks[i], MYTHREAD + "-" + i);
69
}
70
71
synchronized (waitnotify) {
72
for (i = 0; i < numThreads ; i++) {
73
holder[i].start();
74
try {
75
waitnotify.wait();
76
} catch (InterruptedException e) {
77
log.complain("Main thread was interrupted while waiting for start of " + MYTHREAD + "-" + i);
78
return kill002.FAILED;
79
}
80
81
synchronized (locks[i]) { // holder[i] must wait on its lock[i] at this moment.
82
log.display("Thread " + MYTHREAD + "-" + i + " is waiting");
83
}
84
}
85
}
86
breakHere(); // a break to get thread ids and then to kill MyThreads.
87
88
// waits on all MyThreads completion in case they were not killed
89
for (i = 0; i < numThreads ; i++) {
90
synchronized (locks[i]) {
91
locks[i].notifyAll();
92
}
93
if (holder[i].isAlive() && !holder[i].interrupted()) {
94
try {
95
holder[i].join();
96
} catch (InterruptedException e) {
97
log.display("Main thread was interrupted while waiting for finish of " + MYTHREAD + "-" + i);
98
}
99
}
100
}
101
breakHere(); // a break to check if MyThreads were killed
102
103
log.display("notKilled == " + notKilled);
104
log.display("Debuggee PASSED");
105
return kill002.PASSED;
106
}
107
108
static class MyException extends Exception {
109
MyException (String message) {
110
super(message);
111
}
112
}
113
}
114
115
116
class MyThread extends Thread {
117
Object lock;
118
String name;
119
120
public MyThread (Object l, String n) {
121
lock = l;
122
name = n;
123
}
124
125
public void run() {
126
// Concatenate strings in advance to avoid lambda calculations later
127
final String ThreadFinished = "WARNING: Thread finished: " + this.name;
128
String ThreadInterrupted = "WARNING: Thread was interrupted while waiting for killing: " + this.name;
129
kill002a.log.display("Thread started: " + this.name);
130
131
synchronized (lock) {
132
synchronized (kill002a.waitnotify) {
133
kill002a.waitnotify.notify();
134
}
135
136
try {
137
lock.wait();
138
kill002a.notKilled++;
139
kill002a.log.display(ThreadFinished);
140
} catch (Exception e) {
141
kill002a.log.display(ThreadInterrupted);
142
e.printStackTrace(kill002a.log.getOutStream());
143
}
144
}
145
}
146
}
147
148