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