Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdb/methods/methods002/methods002.java
40951 views
1
/*
2
* Copyright (c) 2003, 2020, 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
25
/*
26
* @test
27
*
28
* @summary converted from VM Testbase nsk/jdb/methods/methods002.
29
* VM Testbase keywords: [jpda, jdb]
30
* VM Testbase readme:
31
* DESCRIPTION
32
* This is a test for the 'methods' command.
33
* The test checks the following cases
34
* - class with various method modifiers,
35
* - class with various constructors,
36
* - class with various overloaded methods,
37
* - abstract class and interface,
38
* - implementing class,
39
* - class with inherited methods,
40
* - class with inherited and overrided methods.
41
* The test passes if signatures for all expected methods are listed
42
* in reply on command for every case.
43
* The test consists of two parts:
44
* methods002.java - test driver, i.e. launches jdb and debuggee,
45
* writes commands to jdb, reads the jdb output,
46
* methods002a.java - the debugged application.
47
* COMMENTS
48
* This test replaces the nsk/jdb/methods/methods001 one.
49
*
50
* @library /vmTestbase
51
* /test/lib
52
* @build nsk.jdb.methods.methods002.methods002a
53
* @run main/othervm
54
* nsk.jdb.methods.methods002.methods002
55
* -arch=${os.family}-${os.simpleArch}
56
* -waittime=5
57
* -debugee.vmkind=java
58
* -transport.address=dynamic
59
* -jdb=${test.jdk}/bin/jdb
60
* -java.options="${test.vm.opts} ${test.java.opts}"
61
* -workdir=.
62
* -debugee.vmkeys="${test.vm.opts} ${test.java.opts}"
63
*/
64
65
package nsk.jdb.methods.methods002;
66
67
import nsk.share.*;
68
import nsk.share.jdb.*;
69
70
import java.io.*;
71
import java.util.*;
72
73
public class methods002 extends JdbTest {
74
75
public static void main (String argv[]) {
76
System.exit(run(argv, System.out) + JCK_STATUS_BASE);
77
}
78
79
public static int run(String argv[], PrintStream out) {
80
debuggeeClass = DEBUGGEE_CLASS;
81
firstBreak = FIRST_BREAK;
82
lastBreak = LAST_BREAK;
83
return new methods002().runTest(argv, out);
84
}
85
86
static final String PACKAGE_NAME = "nsk.jdb.methods.methods002";
87
static final String TEST_CLASS = PACKAGE_NAME + ".methods002";
88
static final String DEBUGGEE_CLASS = TEST_CLASS + "a";
89
static final String FIRST_BREAK = DEBUGGEE_CLASS + ".main";
90
static final String LAST_BREAK = DEBUGGEE_CLASS + ".lastBreak";
91
92
protected void runCases() {
93
String[] reply;
94
Paragrep grep;
95
int count;
96
Vector v;
97
String found;
98
99
jdb.setBreakpointInMethod(LAST_BREAK);
100
reply = jdb.receiveReplyFor(JdbCommand.cont);
101
102
// Case for class with method modifiers
103
String testedClass1 = TEST_CLASS + "a";
104
reply = jdb.receiveReplyFor(JdbCommand.methods + testedClass1);
105
for (int i = 1; i <= 33; i++) {
106
checkMethod( reply, "m" + intToString(i), 1, testedClass1, testedClass1 );
107
}
108
for (int i = 1; i <= 3; i++) {
109
checkMethod( reply, "f" + intToString(i), 1, testedClass1, testedClass1 );
110
}
111
112
// Case for class with many constructors
113
String testedClass2 = TEST_CLASS + "b";
114
reply = jdb.receiveReplyFor(JdbCommand.methods + testedClass2);
115
String[] reply1 = toStringArray(reply); // on Windows reply is single string with embedded \r\n symbols
116
checkMethod( reply1, "<init>", 4, testedClass2, testedClass2 );
117
118
// Case for class with overloaded methods
119
String testedClass3 = TEST_CLASS + "c";
120
reply = jdb.receiveReplyFor(JdbCommand.methods + testedClass3);
121
reply1 = toStringArray(reply); // // on Windows reply is single string with embedded \r\n symbols
122
checkMethod( reply1, "m01", 3, testedClass3, testedClass3 );
123
124
// Case for abstract class
125
String testedClass4 = TEST_CLASS + "d";
126
reply = jdb.receiveReplyFor(JdbCommand.methods + testedClass4);
127
checkMethod( reply, "m01", 1, testedClass4, testedClass4 );
128
129
// Case for interface
130
String testedClass5 = TEST_CLASS + "i";
131
reply = jdb.receiveReplyFor(JdbCommand.methods + testedClass5);
132
checkMethod( reply, "i01", 1, testedClass5, testedClass5 );
133
134
// Case for class with implemented method
135
String testedClass6 = TEST_CLASS + "e";
136
reply = jdb.receiveReplyFor(JdbCommand.methods + testedClass6);
137
checkMethod( reply, "m01", 1, testedClass4, testedClass6 );
138
checkMethod( reply, "i01", 1, testedClass5, testedClass6 );
139
checkMethod( reply, "m01", 1, testedClass6, testedClass6 );
140
141
// Case for class with inherited methods
142
String testedClass7 = TEST_CLASS + "f";
143
reply = jdb.receiveReplyFor(JdbCommand.methods + testedClass7);
144
for (int i = 1; i <= 33; i++) {
145
checkMethod( reply, "m" + intToString(i), 1, testedClass1, testedClass7 );
146
}
147
for (int i = 1; i <= 3; i++) {
148
checkMethod( reply, "f" + intToString(i), 1, testedClass1, testedClass7 );
149
}
150
151
// Case for class with inherited and overrided methods
152
String testedClass8 = TEST_CLASS + "g";
153
reply = jdb.receiveReplyFor(JdbCommand.methods + testedClass8);
154
for (int i = 1; i <= 33; i++) {
155
checkMethod( reply, "m" + intToString(i), 1, testedClass8, testedClass8 );
156
}
157
for (int i = 1; i <= 33; i++) {
158
checkMethod( reply, "m" + intToString(i), 1, testedClass1, testedClass8 );
159
}
160
for (int i = 1; i <= 3; i++) {
161
checkMethod( reply, "f" + intToString(i), 1, testedClass1, testedClass8 );
162
}
163
164
jdb.contToExit(1);
165
}
166
167
private void checkMethod (
168
String[] reply, /* reply on 'methods' command */
169
String methodName, /* method name */
170
int expOccur, /* expected number of occurences of the method */
171
String ownerClass, /* name of class defining method */
172
String testedClass /* name of tested class */
173
) {
174
175
Paragrep grep = new Paragrep(reply);
176
Vector v = new Vector();
177
178
v.add(ownerClass);
179
v.add(methodName);
180
int j = grep.find(v);
181
if (j != expOccur) {
182
failure("Wrong number of occurences of method " + methodName +
183
"\n\t of class " + ownerClass +
184
"\n\t in class " + testedClass +
185
"\n\t expected number: " + expOccur + " got: " + j);
186
}
187
}
188
189
private String[] toStringArray (String[] arr) {
190
Vector v = new Vector();
191
for (int i = 0; i < arr.length; i++) {
192
StringTokenizer st = new StringTokenizer(arr[i], "\r\n");
193
while (st.hasMoreTokens()) {
194
v.add(st.nextToken());
195
}
196
}
197
Object[] objects = v.toArray();
198
String[] results = new String[objects.length];
199
for (int i = 0; i < objects.length; i++) {
200
results[i] = (String)objects[i];
201
}
202
return results;
203
}
204
205
private String intToString (int i) {
206
String s = String.valueOf(i);
207
if (s.length()==1)
208
s = "0" + s;
209
return s;
210
}
211
}
212
213