Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdb/unwatch/unwatch002/unwatch002.java
40951 views
1
/*
2
* Copyright (c) 2002, 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/unwatch/unwatch002.
29
* VM Testbase keywords: [jpda, jdb]
30
* VM Testbase readme:
31
* DECSRIPTION
32
* A positive test case for the 'unwatch all <class id>.<field name>' command.
33
* There are two test cases:
34
* - unwatch all for the fields defined in class,
35
* - unwatch all for the fields defined in inner class.
36
* At first phase of testing the full watch is set for all checked fields with
37
* "watch all" command. Then debugged application invokes the methods (updateFields)
38
* in which all checked fields participate in assigned expressions as well as are
39
* assigned to. Thus the jdb should report the access event and modification event
40
* for the fields.
41
* At seconds phase of testing all watch monitors are deleted with the tested
42
* command. Then updateFields methods are invoked in debuggee again.
43
* The test passes jdb reports only once an access and modification events for
44
* every checked fields. Correct report message in jdb stdout should contain full
45
* name of the field and "access encountered" or "will be" words.
46
* The test consists of two program:
47
* watch002.java - launches jdb and debuggee, writes commands to jdb, reads the jdb output,
48
* watch002a.java - the debugged application.
49
* COMMENTS
50
*
51
* @library /vmTestbase
52
* /test/lib
53
* @build nsk.jdb.unwatch.unwatch002.unwatch002a
54
* @run main/othervm
55
* nsk.jdb.unwatch.unwatch002.unwatch002
56
* -arch=${os.family}-${os.simpleArch}
57
* -waittime=5
58
* -debugee.vmkind=java
59
* -transport.address=dynamic
60
* -jdb=${test.jdk}/bin/jdb
61
* -java.options="${test.vm.opts} ${test.java.opts}"
62
* -workdir=.
63
* -debugee.vmkeys="${test.vm.opts} ${test.java.opts}"
64
*/
65
66
package nsk.jdb.unwatch.unwatch002;
67
68
import nsk.share.*;
69
import nsk.share.jdb.*;
70
71
import java.io.*;
72
import java.util.*;
73
74
public class unwatch002 extends JdbTest {
75
76
public static void main (String argv[]) {
77
System.exit(run(argv, System.out) + JCK_STATUS_BASE);
78
}
79
80
public static int run(String argv[], PrintStream out) {
81
debuggeeClass = DEBUGGEE_CLASS;
82
firstBreak = FIRST_BREAK;
83
lastBreak = LAST_BREAK;
84
return new unwatch002().runTest(argv, out);
85
}
86
87
static final String PACKAGE_NAME = "nsk.jdb.unwatch.unwatch002";
88
static final String TEST_CLASS = PACKAGE_NAME + ".unwatch002";
89
static final String DEBUGGEE_CLASS = TEST_CLASS + "a";
90
static final String DEBUGGEE_CLASS2 = DEBUGGEE_CLASS + "$CheckedFields";
91
static final String FIRST_BREAK = DEBUGGEE_CLASS + ".main";
92
static final String LAST_BREAK = DEBUGGEE_CLASS + ".breakHere";
93
static final String expectedPrompt = "main[1]";
94
95
static String[] checkedFields = { "FS1" };
96
static String[] checkedFields2 = { "FT1", "FV1" };
97
98
protected void runCases() {
99
String[] reply;
100
Paragrep grep;
101
int count;
102
Vector v;
103
String found;
104
105
jdb.setBreakpointInMethod(LAST_BREAK);
106
107
reply = jdb.receiveReplyFor(JdbCommand.fields + DEBUGGEE_CLASS);
108
109
reply = jdb.receiveReplyFor(JdbCommand.fields + DEBUGGEE_CLASS2);
110
111
watchFields (DEBUGGEE_CLASS, checkedFields);
112
watchFields (DEBUGGEE_CLASS2, checkedFields2);
113
114
// jdb.contToExit((checkedFields.length *2) + (checkedFields2.length *2) + 2);
115
for (int i = 0; i < (checkedFields.length *2 + checkedFields2.length*2 + 2); i++) {
116
reply = jdb.receiveReplyForWithMessageWait(JdbCommand.cont, expectedPrompt);
117
}
118
119
unwatchFields (DEBUGGEE_CLASS, checkedFields);
120
unwatchFields (DEBUGGEE_CLASS2, checkedFields2);
121
122
// excessive number of cont commands in case if unwatch command does not work.
123
jdb.contToExit(checkedFields.length*2 + checkedFields2.length*2 + 1);
124
125
reply = jdb.getTotalReply();
126
if (!checkFields (DEBUGGEE_CLASS, reply, checkedFields)) {
127
success = false;
128
}
129
if (!checkFields (DEBUGGEE_CLASS2, reply, checkedFields2)) {
130
success = false;
131
}
132
}
133
134
private void watchFields (String className, String[] checkedFields) {
135
String[] reply;
136
137
for (int i = 0; i < checkedFields.length; i++) {
138
reply = jdb.receiveReplyFor(JdbCommand.watch + " all " + className + "." + checkedFields[i]);
139
}
140
141
}
142
143
private void unwatchFields (String className, String[] checkedFields) {
144
String[] reply;
145
146
for (int i = 0; i < checkedFields.length; i++) {
147
reply = jdb.receiveReplyFor(JdbCommand.unwatch + " all " + className + "." + checkedFields[i]);
148
}
149
150
}
151
152
private boolean checkFields (String className, String[] reply, String[] checkedFields) {
153
Paragrep grep;
154
String found;
155
boolean result = true;
156
int count;
157
Vector v = new Vector();
158
159
grep = new Paragrep(reply);
160
v.add("access encountered");
161
for (int i = 0; i < checkedFields.length; i++) {
162
v.removeAllElements();
163
v.add("access encountered");
164
v.add(className + "." + checkedFields[i]);
165
166
count = grep.find(v);
167
if (count != 1) {
168
log.complain("jdb reported wrong number of access to the field " + className + "." + checkedFields[i]);
169
log.complain("Should be 1, reported: " + count);
170
result = false;
171
}
172
173
v.removeAllElements();
174
v.add(className + "." + checkedFields[i]);
175
v.add("will be instance");
176
177
count = grep.find(v);
178
if (count != 1) {
179
log.complain("jdb reported wrong number of modification of the field " + className + "." + checkedFields[i]);
180
log.complain("Should be 1, reported: " + count);
181
result = false;
182
}
183
184
}
185
return result;
186
}
187
}
188
189