Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/LocalVariable/toString/tostring001.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.LocalVariable.toString;
25
26
import nsk.share.*;
27
import nsk.share.jpda.*;
28
import nsk.share.jdi.*;
29
30
import com.sun.jdi.*;
31
import com.sun.jdi.request.*;
32
import com.sun.jdi.event.*;
33
import com.sun.jdi.connect.*;
34
import java.io.*;
35
import java.util.*;
36
37
/**
38
* The debugger application of the test.
39
*/
40
public class tostring001 {
41
42
//------------------------------------------------------- immutable common fields
43
44
final static String SIGNAL_READY = "ready";
45
final static String SIGNAL_GO = "go";
46
final static String SIGNAL_QUIT = "quit";
47
48
private static int waitTime;
49
private static int exitStatus;
50
private static ArgumentHandler argHandler;
51
private static Log log;
52
private static Debugee debuggee;
53
private static ReferenceType debuggeeClass;
54
55
//------------------------------------------------------- mutable common fields
56
57
private final static String prefix = "nsk.jdi.LocalVariable.toString.";
58
private final static String className = "tostring001";
59
private final static String debuggerName = prefix + className;
60
private final static String debuggeeName = debuggerName + "a";
61
62
//------------------------------------------------------- test specific fields
63
64
/** debuggee's local variables for check **/
65
private final static String checkedVars[] = {
66
"z0", "z1", "z2",
67
"b0", "b1", "b2",
68
"c0", "c1", "c2",
69
"d0", "d1", "d2",
70
"f0", "f1", "f2",
71
"i0", "i1", "i2",
72
"l0", "l1", "l2",
73
"r0", "r1", "r2",
74
"Z0", "Z1", "Z2",
75
"B0", "B1", "B2",
76
"C0", "C1", "C2",
77
"D0", "D1", "D2",
78
"F0", "F1", "F2",
79
"I0", "I1", "I2",
80
"L0", "L1", "L2",
81
"R0", "R1", "R2",
82
"s0", "s1", "s2",
83
"o0", "o1", "o2",
84
"p0", "p1", "p2",
85
"m0", "m1", "m2"
86
};
87
88
//------------------------------------------------------- immutable common methods
89
90
public static void main(String argv[]) {
91
System.exit(Consts.JCK_STATUS_BASE + run(argv, System.out));
92
}
93
94
private static void display(String msg) {
95
log.display("debugger > " + msg);
96
}
97
98
private static void complain(String msg) {
99
log.complain("debugger FAILURE > " + msg);
100
}
101
102
public static int run(String argv[], PrintStream out) {
103
104
exitStatus = Consts.TEST_PASSED;
105
106
argHandler = new ArgumentHandler(argv);
107
log = new Log(out, argHandler);
108
waitTime = argHandler.getWaitTime() * 60000;
109
110
debuggee = Debugee.prepareDebugee(argHandler, log, debuggeeName);
111
112
debuggeeClass = debuggee.classByName(debuggeeName);
113
if ( debuggeeClass == null ) {
114
complain("Class '" + debuggeeName + "' not found.");
115
exitStatus = Consts.TEST_FAILED;
116
}
117
118
execTest();
119
120
debuggee.quit();
121
122
return exitStatus;
123
}
124
125
//------------------------------------------------------ mutable common method
126
127
private static void execTest() {
128
129
// Finding of debuggee's main method
130
Method mainMethod = methodByName(debuggeeClass, "main");
131
132
display("Checking toString() method for local variables of debuggee's main method...");
133
134
// Check all methods from debuggee
135
for (int i = 0; i < checkedVars.length; i++) {
136
137
LocalVariable localVar = variableByName(mainMethod, checkedVars[i]);
138
139
try {
140
String str = localVar.toString();
141
if (str == null) {
142
complain("toString() returns null for LocalVariable of debuggee's local variable: " + checkedVars[i]);
143
exitStatus = Consts.TEST_FAILED;
144
} else if (str.length() == 0) {
145
complain("toString() returns empty string for LocalVariable of debuggee's local variable: " + checkedVars[i]);
146
exitStatus = Consts.TEST_FAILED;
147
} else {
148
display("toString() returns for debuggee's local variable " + checkedVars[i] + " : " + str);
149
}
150
} catch(Exception e) {
151
complain("Unexpected " + e + " when getting LocalVariable of debuggee's local variable: " + checkedVars[i]);
152
exitStatus = Consts.TEST_FAILED;
153
}
154
155
}
156
157
display("Checking completed!");
158
}
159
160
//--------------------------------------------------------- test specific methods
161
162
private static Method methodByName(ReferenceType refType, String methodName) {
163
List methodList = refType.methodsByName(methodName);
164
if (methodList == null) {
165
throw new Failure("Can not find method: " + methodName);
166
}
167
if (methodList.size() > 1) {
168
throw new Failure("Found more than one method with name : " + methodName);
169
}
170
171
Method method = (Method) methodList.get(0);
172
return method;
173
}
174
175
private static LocalVariable variableByName(Method method, String varName) {
176
List varList = null;
177
try {
178
varList = method.variablesByName(varName);
179
} catch (AbsentInformationException e) {
180
throw new Failure("Unexpected AbsentInformationException while getting variable: " + varName);
181
}
182
if (varList == null) {
183
throw new Failure("Can not find variable: " + varName);
184
}
185
if (varList.size() > 1) {
186
throw new Failure("Found more than one variable with name : " + varName);
187
}
188
189
LocalVariable var = (LocalVariable) varList.get(0);
190
return var;
191
}
192
}
193
//--------------------------------------------------------- test specific classes
194
195