Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/share/jdi/HeapwalkingDebuggee.java
41161 views
1
/*
2
* Copyright (c) 2006, 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
package nsk.share.jdi;
24
25
import java.io.*;
26
import java.util.*;
27
import java.lang.reflect.Method;
28
import nsk.share.Log;
29
import nsk.share.ObjectInstancesManager;
30
import nsk.share.TestBug;
31
import nsk.share.jpda.DebugeeArgumentHandler;
32
import nsk.share.jpda.IOPipe;
33
34
/*
35
* Debuggee class used in tests for heapwalking(tests for VirtualMachine.instanceCounts, ReferenceType.instances, ObjectReference.referrers).
36
* Handle commands related to creation of objects instances with given reference type
37
* and given referrers number, use for this purposes nsk.share.ObjectInstancesManager.
38
*/
39
public class HeapwalkingDebuggee extends AbstractJDIDebuggee {
40
protected ObjectInstancesManager objectInstancesManager;
41
42
// reference of this type should be included in ObjectReference.referringObjects
43
public static Set<String> includedIntoReferrersCountTypes = new HashSet<String>();
44
45
// reference of this type should be included in ReferenceType.instances
46
public static Set<String> includedIntoInstancesCountTypes = new HashSet<String>();
47
48
static {
49
includedIntoInstancesCountTypes.add(ObjectInstancesManager.STRONG_REFERENCE);
50
includedIntoInstancesCountTypes.add(ObjectInstancesManager.WEAK_REFERENCE);
51
includedIntoInstancesCountTypes.add(ObjectInstancesManager.SOFT_REFERENCE);
52
includedIntoInstancesCountTypes.add(ObjectInstancesManager.PHANTOM_REFERENCE);
53
includedIntoInstancesCountTypes.add(ObjectInstancesManager.JNI_GLOBAL_REFERENCE);
54
includedIntoInstancesCountTypes.add(ObjectInstancesManager.JNI_LOCAL_REFERENCE);
55
56
includedIntoReferrersCountTypes.add(ObjectInstancesManager.STRONG_REFERENCE);
57
includedIntoReferrersCountTypes.add(ObjectInstancesManager.WEAK_REFERENCE);
58
includedIntoReferrersCountTypes.add(ObjectInstancesManager.SOFT_REFERENCE);
59
includedIntoReferrersCountTypes.add(ObjectInstancesManager.PHANTOM_REFERENCE);
60
}
61
62
//create number instance of class with given name, command format: createInstances:class_name:instance_count[:referrer_count:referrer_type]
63
static public final String COMMAND_CREATE_INSTANCES = "createInstances";
64
65
//'delete'(make unreachable) number instance of class with given name, command format: deleteInstances:class_name:instance_count:referrer_count
66
static public final String COMMAND_DELETE_INSTANCES = "deleteInstances";
67
68
//delete number referrers
69
static public final String COMMAND_DELETE_REFERRERS = "deleteReferrers";
70
71
//create instance with all type referrers
72
static public final String COMMAND_CREATE_ALL_TYPE_REFERENCES = "createAllTypeReferences";
73
74
// check jfr is active process
75
public static boolean isJFRActive;
76
77
protected void init(String args[]) {
78
super.init(args);
79
objectInstancesManager = new ObjectInstancesManager(log);
80
isJFRActive = isJFRActive();
81
}
82
83
public void initDebuggee(DebugeeArgumentHandler argHandler, Log log, IOPipe pipe, String args[], boolean callExit) {
84
super.initDebuggee(argHandler, log, pipe, args, callExit);
85
objectInstancesManager = new ObjectInstancesManager(log);
86
}
87
88
public boolean parseCommand(String command) {
89
if (super.parseCommand(command))
90
return true;
91
92
try {
93
StreamTokenizer tokenizer = new StreamTokenizer(new StringReader(command));
94
tokenizer.whitespaceChars(':', ':');
95
tokenizer.wordChars('_', '_');
96
tokenizer.wordChars('$', '$');
97
tokenizer.wordChars('[', ']');
98
tokenizer.wordChars('|', '|');
99
100
if (command.startsWith(COMMAND_CREATE_INSTANCES)) {
101
//createInstances:class_name:instance_count[:referrer_count:referrer_type]
102
103
tokenizer.nextToken();
104
105
if (tokenizer.nextToken() != StreamTokenizer.TT_WORD)
106
throw new TestBug("Invalid command format: " + command);
107
108
String className = tokenizer.sval;
109
110
if (tokenizer.nextToken() != StreamTokenizer.TT_NUMBER)
111
throw new TestBug("Invalid command format: " + command);
112
113
int instanceCounts = (int) tokenizer.nval;
114
115
int referrerCount = 1;
116
Set<String> referrerType = new HashSet<String>();
117
118
if (tokenizer.nextToken() == StreamTokenizer.TT_NUMBER) {
119
referrerCount = (int) tokenizer.nval;
120
121
if (tokenizer.nextToken() == StreamTokenizer.TT_WORD)
122
referrerType.addAll(Arrays.asList(tokenizer.sval.split("\\|")));
123
}
124
if (referrerType.isEmpty()) {
125
referrerType.add(ObjectInstancesManager.STRONG_REFERENCE);
126
}
127
128
objectInstancesManager.createReferences(instanceCounts, className, referrerCount, referrerType);
129
130
return true;
131
} else if (command.startsWith(COMMAND_DELETE_INSTANCES)) {
132
//deleteInstances:class_name:instance_count:referrer_count
133
134
tokenizer.nextToken();
135
136
if (tokenizer.nextToken() != StreamTokenizer.TT_WORD)
137
throw new TestBug("Invalid command format: " + command);
138
139
String className = tokenizer.sval;
140
141
if (tokenizer.nextToken() != StreamTokenizer.TT_NUMBER)
142
throw new TestBug("Invalid command format: " + command);
143
144
int instanceCounts = (int) tokenizer.nval;
145
146
objectInstancesManager.deleteAllReferrers(instanceCounts, className);
147
148
return true;
149
} else if (command.startsWith(COMMAND_DELETE_REFERRERS)) {
150
tokenizer.nextToken();
151
152
if (tokenizer.nextToken() != StreamTokenizer.TT_WORD)
153
throw new TestBug("Invalid command format: " + command);
154
155
String className = tokenizer.sval;
156
157
if (tokenizer.nextToken() != StreamTokenizer.TT_NUMBER)
158
throw new TestBug("Invalid command format: " + command);
159
160
int referrersCount = (int) tokenizer.nval;
161
162
Set<String> referrerTypes = new HashSet<String>();
163
if (tokenizer.nextToken() == StreamTokenizer.TT_WORD) {
164
referrerTypes.addAll(Arrays.asList(tokenizer.sval.split("\\|")));
165
}
166
167
objectInstancesManager.deleteReferrers(className, referrersCount, referrerTypes);
168
169
return true;
170
} else if (command.startsWith(COMMAND_CREATE_ALL_TYPE_REFERENCES)) {
171
tokenizer.nextToken();
172
173
if (tokenizer.nextToken() != StreamTokenizer.TT_WORD)
174
throw new TestBug("Invalid command format: " + command);
175
176
String className = tokenizer.sval;
177
178
if (tokenizer.nextToken() != StreamTokenizer.TT_NUMBER)
179
throw new TestBug("Invalid command format: " + command);
180
181
int instanceCounts = (int) tokenizer.nval;
182
183
objectInstancesManager.createAllTypeReferences(className, instanceCounts);
184
185
return true;
186
}
187
} catch (IOException e) {
188
throw new TestBug("Invalid command format: " + command);
189
}
190
191
return false;
192
}
193
194
// check if jfr is initialized
195
public static boolean isJFRActive() {
196
try {
197
Class cls = Class.forName("jdk.jfr.FlightRecorder");
198
Method method = cls.getDeclaredMethod("isInitialized", new Class[0]);
199
return (Boolean)method.invoke(cls, new Object[0]);
200
} catch(Exception e) {
201
return false;
202
}
203
}
204
205
// is reference with given type should be included in ObjectReference.referringObjects
206
static public boolean isIncludedIntoReferrersCount(String referenceType) {
207
if (!ObjectInstancesManager.allReferenceTypes.contains(referenceType)) {
208
throw new TestBug("Invalid reference type: " + referenceType);
209
}
210
211
return includedIntoReferrersCountTypes.contains(referenceType);
212
}
213
214
// is reference with given type should be included in ReferenceType.instances
215
static public boolean isIncludedIntoInstancesCount(String referenceType) {
216
if (!ObjectInstancesManager.allReferenceTypes.contains(referenceType)) {
217
throw new TestBug("Invalid reference type: " + referenceType);
218
}
219
220
return includedIntoInstancesCountTypes.contains(referenceType);
221
}
222
223
public static void main(String args[]) {
224
HeapwalkingDebuggee debuggee = new HeapwalkingDebuggee();
225
debuggee.init(args);
226
debuggee.doTest();
227
}
228
}
229
230