Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdb/where/where006/where006a.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.where.where006;
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 where006a {
34
public static void main(String args[]) {
35
where006a _where006a = new where006a();
36
System.exit(where006.JCK_STATUS_BASE + _where006a.runIt(args, System.out));
37
}
38
39
static void lastBreak () {}
40
41
static int numThreads = 5; // number of threads. one lock per thread.
42
43
static Object lock = new Object();
44
static Object waitnotify = new Object();
45
46
public int runIt(String args[], PrintStream out) {
47
JdbArgumentHandler argumentHandler = new JdbArgumentHandler(args);
48
Log log = new Log(out, argumentHandler);
49
50
Thread holder [] = new Thread[numThreads];
51
Lock locks[] = new Lock[numThreads];
52
53
for (int i = 0; i < numThreads ; i++) {
54
locks[i] = new Lock();
55
holder[i] = new MyThread(locks[i],"MyThread-" + i);
56
}
57
58
// lock monitor to prevent threads from finishing after they started
59
synchronized (lock) {
60
synchronized (waitnotify) {
61
for (int i = 0; i < numThreads ; i++) {
62
holder[i].start();
63
try {
64
waitnotify.wait();
65
} catch ( Exception e ) {
66
System.err.println("TEST ERROR: caught Exception while waiting: " + e);
67
e.printStackTrace();
68
}
69
}
70
}
71
lastBreak(); // dummy breakpoint
72
}
73
74
for (int i = 0; i < numThreads ; i++) {
75
if (holder[i].isAlive()) {
76
try {
77
holder[i].join(argumentHandler.getWaitTime() * 60000);
78
} catch (InterruptedException e) {
79
throw new Failure("Unexpected InterruptedException catched while waiting for join of: " + holder[i]);
80
}
81
}
82
}
83
84
log.display("Debuggee PASSED");
85
return where006.PASSED;
86
}
87
88
}
89
90
class Lock {
91
boolean lockSet;
92
93
synchronized void setLock() throws InterruptedException {
94
while (lockSet == true )
95
wait();
96
lockSet = true;
97
}
98
99
synchronized void releaseLock() {
100
if (lockSet == true) {
101
lockSet = false;
102
notify();
103
}
104
}
105
}
106
107
class MyThread extends Thread {
108
Lock lock;
109
String name;
110
MyThread(Lock l, String n) {this.lock = l; name = n;}
111
112
public void run() {
113
// Concatenate strings in advance to avoid lambda calculations later
114
final String ThreadFinished = "Thread finished: " + this.name;
115
int square = func1(10);
116
lock.releaseLock();
117
System.out.println(ThreadFinished);
118
}
119
120
public int func1(int i) {
121
return func2(i);
122
}
123
124
public int func2(int i) {
125
return func3(i);
126
}
127
128
public int func3(int i) {
129
return func4(i);
130
}
131
132
public int func4(int i) {
133
return func5(i);
134
}
135
136
public int func5(int i) {
137
synchronized (where006a.waitnotify) {
138
where006a.waitnotify.notify();
139
}
140
// prevent thread for early finish
141
synchronized (where006a.lock) {}
142
return i*i;
143
}
144
}
145
146