Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/EventRequestManager/createStepRequest/crstepreq004a.java
41161 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.jdi.EventRequestManager.createStepRequest;
25
26
import nsk.share.*;
27
import nsk.share.jpda.*;
28
import nsk.share.jdi.*;
29
30
// THIS TEST IS LINE NUMBER SENSITIVE
31
32
/**
33
* The debugged application of the test.
34
*/
35
public class crstepreq004a {
36
37
//----------------------------------------------------- immutable common fields
38
39
static final int PASSED = 0;
40
static final int FAILED = 2;
41
static final int PASS_BASE = 95;
42
static final int quit = -1;
43
44
static int instruction = 1;
45
static int lineForComm = 2;
46
static int exitCode = PASSED;
47
48
private static ArgumentHandler argHandler;
49
private static Log log;
50
private static IOPipe pipe;
51
52
//------------------------------------------------------ mutable common fields
53
54
//------------------------------------------------------ test specific fields
55
56
static Object lockObj = new Object();
57
static Object lockObj1 = new Object();
58
private static volatile boolean isFirstThreadReady = false;
59
private static volatile boolean isSecondThreadReady = false;
60
61
//------------------------------------------------------ mutable common method
62
63
public static void main (String argv[]) {
64
65
argHandler = new ArgumentHandler(argv);
66
log = new Log(System.out, argHandler);
67
pipe = argHandler.createDebugeeIOPipe(log);
68
69
display("debuggee started!");
70
71
label0:
72
for (int testCase = 0; instruction != quit; testCase++) {
73
74
switch (testCase) {
75
case 0:
76
case 1:
77
case 2:
78
runTestCase(testCase);
79
break;
80
default:
81
instruction = quit;
82
break;
83
}
84
85
if (instruction == quit)
86
break;
87
}
88
89
display("debuggee exits");
90
System.exit(PASSED + PASS_BASE);
91
}
92
93
//--------------------------------------------------------- test specific methodss
94
95
private static void runTestCase(int testCaseId) {
96
isFirstThreadReady = false;
97
isSecondThreadReady = false;
98
Thread thread1 = new Thread1crstepreq004a("thread1");
99
Thread thread2 = new Thread2crstepreq004a("thread2");
100
synchronized (lockObj) {
101
thread1.start();
102
while (!isFirstThreadReady) {
103
shortSleep();
104
}
105
thread2.start();
106
while (!isSecondThreadReady) {
107
shortSleep();
108
}
109
110
display("call methodForCommunication() #" + testCaseId);
111
methodForCommunication();
112
}
113
threadJoin(thread1, "1");
114
threadJoin(thread2, "2");
115
}
116
117
static void threadJoin (Thread t, String number) {
118
try {
119
t.join();
120
} catch ( InterruptedException e ) {
121
exitCode = FAILED;
122
complain("Case #" + number + ": caught unexpected InterruptedException while waiting for thread finish" );
123
}
124
}
125
126
//---------------------------------------------------------- immutable common methods
127
128
static void shortSleep() {
129
try {
130
Thread.currentThread().sleep(10);
131
} catch (InterruptedException e) {
132
e.printStackTrace();
133
}
134
}
135
136
static void display(String msg) {
137
log.display("debuggee > " + msg);
138
}
139
140
static void complain(String msg) {
141
log.complain("debuggee FAILURE > " + msg);
142
}
143
144
private static void methodForCommunication() {
145
int i = instruction;
146
int curInstruction = i; // crstepreq004.lineForBreakInThread
147
}
148
149
static void lockAndNotify1() {
150
synchronized(lockObj1) {
151
isFirstThreadReady = true;
152
synchronized(lockObj) {
153
}
154
}
155
}
156
157
static void lockAndNotify2() {
158
isSecondThreadReady = true;
159
synchronized(lockObj1) { // thread is waiting here the lock when step request is created.
160
int i = 1; // This is line of step event for STEP_INTO and STEP_OVER -- crstepreq004.checkedLines[0-1]
161
} // crstepreq004.checkedLinesAlt[0-1]
162
}
163
}
164
165
//--------------------------------------------------------- test specific classes
166
167
/**
168
* First thread which owns and locks the crstepreq004a.lockObj1 monitor .
169
*/
170
class Thread1crstepreq004a extends Thread {
171
public Thread1crstepreq004a (String name) {
172
super(name);
173
}
174
175
public void run() {
176
crstepreq004a.display("enter thread " + getName());
177
crstepreq004a.lockAndNotify1();
178
crstepreq004a.display("exit thread " + getName());
179
}
180
}
181
182
/**
183
* Second thread which who owns the crstepreq004a.lockObj1 monitor .
184
*/
185
class Thread2crstepreq004a extends Thread {
186
public Thread2crstepreq004a (String name) {
187
super(name);
188
}
189
190
public void run() {
191
crstepreq004a.display("enter thread " + getName());
192
crstepreq004a.lockAndNotify2();
193
crstepreq004a.display("exit thread " + getName()); // This is line of step event for STEP_OUT -- crstepreq004.checkedLines[2] checkedLinesAlt[2].
194
}
195
}
196
197