Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdb/trace/trace001/trace001a.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.trace.trace001;
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 trace001a {
34
public static void main(String args[]) {
35
trace001a _trace001a = new trace001a();
36
System.exit(trace001.JCK_STATUS_BASE + _trace001a.runIt(args, System.out));
37
}
38
39
static void lastBreak () {}
40
41
static final String MYTHREAD = "MyThread";
42
static final int numThreads = 2; // number of threads.
43
44
static Object waitnotify = new Object();
45
46
public int runIt(String args[], PrintStream out) {
47
48
JdbArgumentHandler argumentHandler = new JdbArgumentHandler(args);
49
Log log = new Log(out, argumentHandler);
50
51
int i;
52
Thread holder [] = new Thread[numThreads];
53
Object[] locks = new Object[numThreads];
54
55
for (i = 0; i < numThreads ; i++) {
56
locks[i] = new Object();
57
holder[i] = new MyThread(locks[i],MYTHREAD + "-" + i);
58
}
59
60
synchronized (waitnotify) {
61
for (i = 0; i < numThreads ; i++) {
62
holder[i].start();
63
try {
64
waitnotify.wait();
65
} catch (InterruptedException e) {
66
System.out.println("Main thread was interrupted while waiting for start of " + MYTHREAD + "-" + i);
67
return trace001.FAILED;
68
}
69
70
synchronized (locks[i]) { // holder[i] must wait on its lock[i] at this moment.
71
System.out.println("Thread " + MYTHREAD + "-" + i + " is waiting");
72
}
73
}
74
}
75
lastBreak(); // a break to get thread ids and then to turn on tracing.
76
77
// waits on all MyThreads completion
78
for (i = 0; i < numThreads ; i++) {
79
synchronized (locks[i]) {
80
locks[i].notifyAll();
81
}
82
if (holder[i].isAlive() && !holder[i].interrupted()) {
83
try {
84
holder[i].join();
85
} catch (InterruptedException e) {
86
System.out.println("Main thread was interrupted while waiting for finish of " + MYTHREAD + "-" + i);
87
return trace001.FAILED;
88
}
89
}
90
}
91
92
log.display("Debuggee PASSED");
93
return trace001.PASSED;
94
}
95
}
96
97
98
class MyThread extends Thread {
99
Object lock;
100
String name;
101
102
public MyThread (Object l, String n) {
103
lock = l;
104
name = n;
105
}
106
107
public void run() {
108
// Concatenate strings in advance to avoid lambda calculations later
109
final String ThreadFinished = "Thread finished: " + this.name;
110
final String ThreadInterrupted = "Thread was interrupted: " + this.name;
111
System.out.println("Thread started: " + this.name);
112
113
synchronized (lock) {
114
synchronized (trace001a.waitnotify) {
115
trace001a.waitnotify.notify();
116
}
117
118
try {
119
lock.wait();
120
int square = func1(100);
121
System.out.println(ThreadFinished);
122
} catch (InterruptedException e) {
123
System.out.println(ThreadInterrupted);
124
e.printStackTrace();
125
}
126
}
127
128
System.out.println(ThreadFinished);
129
}
130
131
public int func1(int i) {
132
return func2(i);
133
}
134
135
public int func2(int i) {
136
return func3(i);
137
}
138
139
public int func3(int i) {
140
return i*i;
141
}
142
}
143
144