Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/LocalVariable/hashCode/hashcode001.java
41161 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.jdi.LocalVariable.hashCode;
25
26
import nsk.share.*;
27
import nsk.share.jpda.*;
28
import nsk.share.jdi.*;
29
30
import com.sun.jdi.*;
31
import java.util.*;
32
import java.io.*;
33
34
/**
35
* The test for the implementation of an object of the type <BR>
36
* LocalVariable. <BR>
37
* <BR>
38
* The test checks up that results of the method <BR>
39
* complies with its spec. <BR>
40
* <BR>
41
* The cases for testing are as follows. <BR>
42
* <BR>
43
* When a gebuggee creates an object containing two <BR>
44
* methods with equal sets of variables and arguments, <BR>
45
* a debugger creates following LocalVariable objects: <BR>
46
* - two for the same variable in the debuggee; <BR>
47
* - for "the same type - different name" variable in <BR>
48
* the same method in the debuggee; <BR>
49
* - for "same name-type - different methods" variable; <BR>
50
* <BR>
51
* applies the method LocalVariable.hashCode() and <BR>
52
* compares pairs of hashCodes to check up that <BR>
53
* - hashCodes are equal if two LocalVariable mirror <BR>
54
* the same variable or argument <BR>
55
* in the same method in the debuggee; <BR>
56
* - hashCodes are not equal otherwise. <BR>
57
* <BR>
58
*/
59
60
public class hashcode001 {
61
62
//----------------------------------------------------- templete section
63
static final int PASSED = 0;
64
static final int FAILED = 2;
65
static final int PASS_BASE = 95;
66
67
//----------------------------------------------------- templete parameters
68
static final String
69
sHeader1 = "\n==> nsk/jdi/LocalVariable/hashCode/hashcode001 ",
70
sHeader2 = "--> hashcode001: ",
71
sHeader3 = "##> hashcode001: ";
72
73
//----------------------------------------------------- main method
74
75
public static void main (String argv[]) {
76
int result = run(argv, System.out);
77
System.exit(result + PASS_BASE);
78
}
79
80
public static int run (String argv[], PrintStream out) {
81
return new hashcode001().runThis(argv, out);
82
}
83
84
//-------------------------------------------------- log procedures
85
86
//private static boolean verbMode = false;
87
88
private static Log logHandler;
89
90
private static void log1(String message) {
91
logHandler.display(sHeader1 + message);
92
}
93
private static void log2(String message) {
94
logHandler.display(sHeader2 + message);
95
}
96
private static void log3(String message) {
97
logHandler.complain(sHeader3 + message);
98
}
99
100
// ************************************************ test parameters
101
102
private String debuggeeName =
103
"nsk.jdi.LocalVariable.hashCode.hashcode001a";
104
105
String mName = "nsk.jdi.LocalVariable.hashCode";
106
107
//====================================================== test program
108
109
static ArgumentHandler argsHandler;
110
static int testExitCode = PASSED;
111
112
//------------------------------------------------------ common section
113
114
private int runThis (String argv[], PrintStream out) {
115
116
Debugee debuggee;
117
118
argsHandler = new ArgumentHandler(argv);
119
logHandler = new Log(out, argsHandler);
120
Binder binder = new Binder(argsHandler, logHandler);
121
122
if (argsHandler.verbose()) {
123
debuggee = binder.bindToDebugee(debuggeeName + " -vbs"); // *** tp
124
} else {
125
debuggee = binder.bindToDebugee(debuggeeName); // *** tp
126
}
127
128
IOPipe pipe = new IOPipe(debuggee);
129
130
debuggee.redirectStderr(out);
131
log2("hashcode001a debuggee launched");
132
debuggee.resume();
133
134
String line = pipe.readln();
135
if ((line == null) || !line.equals("ready")) {
136
log3("signal received is not 'ready' but: " + line);
137
return FAILED;
138
} else {
139
log2("'ready' recieved");
140
}
141
142
VirtualMachine vm = debuggee.VM();
143
144
//------------------------------------------------------ testing section
145
log1(" TESTING BEGINS");
146
147
for (int i = 0; ; i++) {
148
pipe.println("newcheck");
149
line = pipe.readln();
150
151
if (line.equals("checkend")) {
152
log2(" : returned string is 'checkend'");
153
break ;
154
} else if (!line.equals("checkready")) {
155
log3("ERROR: returned string is not 'checkready'");
156
testExitCode = FAILED;
157
break ;
158
}
159
160
log1("new check: #" + i);
161
162
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ variable part
163
164
List listOfLoadedClasses = vm.classesByName(mName + ".TestClass");
165
166
if (listOfLoadedClasses.size() != 1) {
167
testExitCode = FAILED;
168
log3("ERROR: listOfLoadedClasses.size() != 1 " +
169
listOfLoadedClasses.size());
170
break ;
171
}
172
173
List methods1 =
174
((ReferenceType) listOfLoadedClasses.get(0)).
175
methodsByName("testmethod1");
176
List methods2 =
177
((ReferenceType) listOfLoadedClasses.get(0)).
178
methodsByName("testmethod2");
179
180
Method testMethod1 = (Method) methods1.get(0);
181
Method testMethod2 = (Method) methods2.get(0);
182
183
String names1[] = { "bl1", "bt1", "ch1", "db1",
184
"fl1", "in1", "ln1", "sh1",
185
"class2_1", "iface_1", "cfc_1", "param1" };
186
String names2[] = { "bl2", "bt2", "ch2", "db2",
187
"fl2", "in2", "ln2", "sh2",
188
"class2_2", "iface_2", "cfc_2", "param2" };
189
190
int i2;
191
192
for (i2 = 0; i2 < names1.length; i2++) {
193
194
log2("new check: #" + i2);
195
196
List lVars1 = null;
197
List lVars2 = null;
198
List lVars3 = null;
199
List lVars4 = null;
200
201
try {
202
lVars1 = testMethod1.variablesByName(names1[i2]);
203
lVars2 = testMethod1.variablesByName(names1[i2]);
204
lVars3 = testMethod1.variablesByName(names2[i2]);
205
lVars4 = testMethod2.variablesByName(names1[i2]);
206
} catch ( AbsentInformationException e ) {
207
log3("ERROR: AbsentInformationException for " +
208
"lVars = testMethod_i.variablesByName(names[i2])" );
209
testExitCode = FAILED;
210
continue;
211
}
212
if (lVars1.size() != 1 || lVars2.size() != 1 ||
213
lVars3.size() != 1 || lVars4.size() != 1 ) {
214
testExitCode = FAILED;
215
log3("ERROR: lVars-i.size() != 1 for i2= " + i2);
216
continue;
217
}
218
219
LocalVariable lVar1 = (LocalVariable) lVars1.get(0);
220
LocalVariable lVar2 = (LocalVariable) lVars2.get(0);
221
LocalVariable lVar3 = (LocalVariable) lVars3.get(0);
222
LocalVariable lVar4 = (LocalVariable) lVars4.get(0);
223
224
225
if (lVar1.hashCode() != lVar2.hashCode()) {
226
testExitCode = FAILED;
227
log3("ERROR: lVar1.hashCode() != lVar2.hashCode() for check# " + i2);
228
}
229
if (lVar1.hashCode() == lVar3.hashCode()) {
230
testExitCode = FAILED;
231
log3("ERROR: lVar1.hashCode() == lVar3.hashCode()) for check# " + i2);
232
}
233
if (lVar1.hashCode() == lVar4.hashCode()) {
234
testExitCode = FAILED;
235
log3("ERROR: lVar1.hashCode() == lVar4.hashCode() for check# " + i2);
236
}
237
}
238
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
239
}
240
log1(" TESTING ENDS");
241
242
//-------------------------------------------------- test summary section
243
//------------------------------------------------- standard end section
244
245
pipe.println("quit");
246
log2("waiting for the debuggee to finish ...");
247
debuggee.waitFor();
248
249
int status = debuggee.getStatus();
250
if (status != PASSED + PASS_BASE) {
251
log3("debuggee returned UNEXPECTED exit status: " +
252
status + " != PASS_BASE");
253
testExitCode = FAILED;
254
} else {
255
log2("debuggee returned expected exit status: " +
256
status + " == PASS_BASE");
257
}
258
259
if (testExitCode != PASSED) {
260
logHandler.complain("TEST FAILED");
261
}
262
return testExitCode;
263
}
264
}
265
266