Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/ClassPrepareEvent/thread/thread001a.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.jdi.ClassPrepareEvent.thread;
25
26
import nsk.share.*;
27
import nsk.share.jpda.*;
28
import nsk.share.jdi.*;
29
30
import java.io.*;
31
32
// This class is the debugged application in the test
33
34
class thread001a {
35
public static Object threadExitLock = new Object();
36
37
public static void main(String args[]) {
38
thread001a _thread001a = new thread001a();
39
System.exit(thread001.JCK_STATUS_BASE + _thread001a.runIt(args, System.err));
40
}
41
42
int runIt(String args[], PrintStream out) {
43
ArgumentHandler argHandler = new ArgumentHandler(args);
44
IOPipe pipe = argHandler.createDebugeeIOPipe();
45
final Log log = new Log(out, argHandler);
46
47
// final long threadStartTimeout = 10 * 100; // milliseconds
48
49
// notify debugger that debugge started
50
pipe.println(thread001.COMMAND_READY);
51
52
// wait for command RUN from debugger to create another thread
53
String command = pipe.readln();
54
if (!command.equals(thread001.COMMAND_RUN)) {
55
log.complain("TEST BUG: Debugee: unknown command: " + command);
56
return thread001.FAILED;
57
}
58
59
class InnerThread extends Thread {
60
public volatile boolean started = false;
61
public volatile Object startedNotification = new Object();
62
63
InnerThread (String name) {
64
super(name);
65
}
66
67
public void run() {
68
ClassForInnerThread a = new ClassForInnerThread();
69
70
// start outer thread from inner thread and wait tor it started
71
OuterThread outerThread = new OuterThread("outerThread");
72
synchronized (outerThread.startedNotification) {
73
outerThread.start();
74
try {
75
outerThread.startedNotification.wait();
76
} catch (InterruptedException e) {
77
log.complain("Unexpected InterruptedException while waiting for outer thread started: " + e);
78
return;
79
}
80
}
81
82
// check if outer thread actually started
83
if (!outerThread.started) {
84
log.complain("Outer thread NOT started from inner thread in debuggee: "
85
+ outerThread.getName());
86
outerThread.interrupt();
87
return;
88
}
89
90
// notify main thread that both threads started
91
synchronized (startedNotification) {
92
started = true;
93
startedNotification.notify();
94
}
95
96
// wait for main thread releases mionitor to permint this thread to finish
97
synchronized (thread001a.threadExitLock) {
98
}
99
100
}
101
}
102
103
// prevent further started thread from exit
104
synchronized (threadExitLock) {
105
106
// start an inner thread from main thread and wait for it started
107
InnerThread innerThread = new InnerThread("innerThread");
108
synchronized (innerThread.startedNotification) {
109
innerThread.start();
110
try {
111
innerThread.startedNotification.wait();
112
} catch (InterruptedException e) {
113
log.complain("Unexpected InterruptedException while waiting for inner thread started: " + e);
114
return thread001.FAILED;
115
}
116
}
117
118
// check if threads really started and notify debugger
119
if (!innerThread.started) {
120
log.complain("Inner thread NOT started from main thread in debuggee: "
121
+ innerThread.getName());
122
innerThread.interrupt();
123
pipe.println(thread001.COMMAND_ERROR);
124
} else {
125
log.display("All threads started in debuggee");
126
pipe.println(thread001.COMMAND_DONE);
127
}
128
129
// wait for command QUIT from debugger to release started threads and exit
130
command = pipe.readln();
131
if (!command.equals(thread001.COMMAND_QUIT)) {
132
log.complain("TEST BUG: Debugee: unknown command: " + command);
133
return thread001.FAILED;
134
}
135
136
// release monitor to permit started threads to finish
137
}
138
139
return thread001.PASSED;
140
}
141
}
142
143
class OuterThread extends Thread {
144
public volatile boolean started = false;
145
public volatile Object startedNotification = new Object();
146
147
OuterThread (String name) {
148
super(name);
149
}
150
151
public void run() {
152
ClassForOuterThread a = new ClassForOuterThread();
153
154
// notify main thread that this thread started
155
synchronized (startedNotification) {
156
started = true;
157
startedNotification.notify();
158
}
159
160
// wait for main thread releases mionitor to permint this thread to finish
161
synchronized (thread001a.threadExitLock) {
162
}
163
}
164
}
165
166
class ClassForInnerThread {}
167
168
class ClassForOuterThread {}
169
170