Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdb/suspend/suspend001/suspend001a.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.suspend.suspend001;
25
26
import nsk.share.*;
27
import nsk.share.jpda.*;
28
import nsk.share.jdb.*;
29
30
import java.io.*;
31
32
/* This is debuggee aplication */
33
public class suspend001a {
34
static suspend001a _suspend001a = new suspend001a();
35
36
static JdbArgumentHandler argumentHandler;
37
static Log log;
38
39
public static void main(String args[]) {
40
System.exit(suspend001.JCK_STATUS_BASE + _suspend001a.runIt(args, System.out));
41
}
42
43
static void breakHere () {}
44
45
static Object lock = new Object();
46
static Object waitnotify = new Object();
47
public static volatile int notSuspended = 0;
48
49
public int runIt(String args[], PrintStream out) {
50
argumentHandler = new JdbArgumentHandler(args);
51
log = new Log(out, argumentHandler);
52
53
Thread suspended = new Suspended("Suspended");
54
Thread myThread = new MyThread("MyThread");
55
56
// lock monitor to prevent threads from finishing after they started
57
synchronized (lock) {
58
synchronized (waitnotify) {
59
suspended.start();
60
try {
61
waitnotify.wait();
62
} catch (InterruptedException e) {
63
log.complain("Main thread was interrupted while waiting for start of Suspended thread");
64
return suspend001.FAILED;
65
}
66
67
myThread.start();
68
try {
69
waitnotify.wait();
70
} catch (InterruptedException e) {
71
log.complain("Main thread was interrupted while waiting for start of MyThread thread");
72
return suspend001.FAILED;
73
}
74
}
75
breakHere(); // a break to get thread ids and then to suspend Suspended thread.
76
}
77
78
// wait for MyThread completion
79
if (myThread.isAlive()) {
80
try {
81
myThread.join();
82
} catch (InterruptedException e) {
83
log.display("Main thread was interrupted while waiting for finish of MyThread thread");
84
}
85
}
86
87
// give 3 seconds for suspended thread to finish (if it is not really suspended).
88
try {
89
Thread.currentThread().sleep(3 * 1000);
90
} catch (InterruptedException e) {
91
log.display("Main thread was interrupted while sleeping");
92
}
93
94
breakHere(); // a break to check if Suspended was suspended
95
96
log.display("notSuspended == " + notSuspended);
97
log.display("Debuggee PASSED");
98
return suspend001.PASSED;
99
}
100
101
public static int getResult() {
102
return notSuspended;
103
}
104
}
105
106
class Suspended extends Thread {
107
String name;
108
109
public Suspended (String n) {
110
name = n;
111
}
112
113
public void run() {
114
// Concatenate strings in advance to avoid lambda calculations later
115
final String ThreadFinished = "Thread finished: " + this.name;
116
suspend001a.log.display("Thread started: " + this.name);
117
118
synchronized (suspend001a.waitnotify) {
119
suspend001a.waitnotify.notify();
120
}
121
// prevent thread from early finish
122
synchronized (suspend001a.lock) {}
123
124
suspend001a.notSuspended++;
125
126
suspend001a.log.display(ThreadFinished);
127
}
128
}
129
130
class MyThread extends Thread {
131
String name;
132
133
public MyThread (String n) {
134
name = n;
135
}
136
137
public void run() {
138
// Concatenate strings in advance to avoid lambda calculations later
139
final String ThreadFinished = "Thread finished: " + this.name;
140
suspend001a.log.display("Thread started: " + this.name);
141
142
synchronized (suspend001a.waitnotify) {
143
suspend001a.waitnotify.notify();
144
}
145
// prevent thread from early finish
146
synchronized (suspend001a.lock) {}
147
148
suspend001a.notSuspended++;
149
150
suspend001a.log.display(ThreadFinished);
151
}
152
}
153
154