Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdwp/StackFrame/ThisObject/thisobject001a.java
41162 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.jdwp.StackFrame.ThisObject;
25
26
import nsk.share.*;
27
import nsk.share.jpda.*;
28
import nsk.share.jdwp.*;
29
30
import java.io.*;
31
32
/**
33
* This class represents debuggee part in the test.
34
*/
35
public class thisobject001a {
36
37
// name of the tested object and thread classes
38
public static final String OBJECT_CLASS_NAME = "TestedObjectClass";
39
public static final String THREAD_CLASS_NAME = "TestedThreadClass";
40
public static final String THREAD_NAME = "TestedThreadName";
41
42
// name of the static fields with the tested object values
43
public static final String THREAD_FIELD_NAME = "thread";
44
public static final String OBJECT_FIELD_NAME = "object";
45
46
// notification object to notify debuggee that thread is ready
47
private static Object threadReady = new Object();
48
// lock object to prevent thread from exit
49
private static Object threadLock = new Object();
50
51
// scaffold objects
52
private static volatile ArgumentHandler argumentHandler = null;
53
private static volatile Log log = null;
54
55
public static void main(String args[]) {
56
thisobject001a _thisobject001a = new thisobject001a();
57
System.exit(thisobject001.JCK_STATUS_BASE + _thisobject001a.runIt(args, System.err));
58
}
59
60
public int runIt(String args[], PrintStream out) {
61
//make log for debugee messages
62
argumentHandler = new ArgumentHandler(args);
63
log = new Log(out, argumentHandler);
64
65
// make communication pipe to debugger
66
log.display("Creating pipe");
67
IOPipe pipe = argumentHandler.createDebugeeIOPipe(log);
68
69
// lock the object to prevent thread from exit
70
synchronized (threadLock) {
71
72
// load tested class and create tested thread and object
73
log.display("Creating object of tested class");
74
TestedObjectClass.object = new TestedObjectClass();
75
log.display("Creating tested thread");
76
TestedObjectClass.thread = new TestedThreadClass(THREAD_NAME);
77
78
// start the thread and wait for notification from it
79
synchronized (threadReady) {
80
TestedObjectClass.thread.start();
81
try {
82
threadReady.wait();
83
// send debugger signal READY
84
log.display("Sending signal to debugger: " + thisobject001.READY);
85
pipe.println(thisobject001.READY);
86
} catch (InterruptedException e) {
87
log.complain("Interruption while waiting for thread started: " + e);
88
pipe.println(thisobject001.ERROR);
89
}
90
}
91
92
// wait for signal QUIT from debugeer
93
log.display("Waiting for signal from debugger: " + thisobject001.QUIT);
94
String signal = pipe.readln();
95
log.display("Received signal from debugger: " + signal);
96
97
// check received signal
98
if (signal == null || !signal.equals(thisobject001.QUIT)) {
99
log.complain("Unexpected communication signal from debugee: " + signal
100
+ " (expected: " + thisobject001.QUIT + ")");
101
log.complain("Debugee FAILED");
102
return thisobject001.FAILED;
103
}
104
105
// allow started thread to finish
106
}
107
108
// wait for tested thread finished
109
try {
110
log.display("Waiting for tested thread finished");
111
TestedObjectClass.thread.join();
112
} catch (InterruptedException e) {
113
log.complain("Interruption while waiting for tested thread finished:\n\t"
114
+ e);
115
log.complain("Debugee FAILED");
116
return thisobject001.FAILED;
117
}
118
119
// exit debugee
120
log.display("Debugee PASSED");
121
return thisobject001.PASSED;
122
}
123
124
// tested thread class
125
public static class TestedThreadClass extends Thread {
126
127
TestedThreadClass(String name) {
128
super(name);
129
}
130
131
public void run() {
132
log.display("Tested thread started");
133
134
// invoke tested method for the tested object from the tested thread
135
int foo = 100;
136
TestedObjectClass.object.testedMethod(foo);
137
138
log.display("Tested thread finished");
139
}
140
141
}
142
143
// tested object class
144
public static class TestedObjectClass {
145
146
// field with the tested thread and object values
147
public static volatile TestedThreadClass thread = null;
148
public static volatile TestedObjectClass object = null;
149
150
public void testedMethod(int foo) {
151
log.display("Tested frame entered");
152
153
// local variables
154
int boo = foo;
155
156
// notify debuggee that tested thread ready for testing
157
synchronized (threadReady) {
158
threadReady.notifyAll();
159
}
160
161
// wait for lock object released
162
synchronized (threadLock) {
163
log.display("Tested frame dropped");
164
}
165
}
166
167
}
168
169
}
170
171