Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/ci/ciMethodData.java
41161 views
1
/*
2
* Copyright (c) 2011, 2021, 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
package sun.jvm.hotspot.ci;
26
27
import java.io.*;
28
import java.util.*;
29
import sun.jvm.hotspot.debugger.*;
30
import sun.jvm.hotspot.runtime.*;
31
import sun.jvm.hotspot.oops.*;
32
import sun.jvm.hotspot.types.*;
33
import sun.jvm.hotspot.types.Field;
34
import sun.jvm.hotspot.utilities.Observable;
35
import sun.jvm.hotspot.utilities.Observer;
36
37
public class ciMethodData extends ciMetadata implements MethodDataInterface<ciKlass,ciMethod> {
38
static {
39
VM.registerVMInitializedObserver(new Observer() {
40
public void update(Observable o, Object data) {
41
initialize(VM.getVM().getTypeDataBase());
42
}
43
});
44
}
45
46
private static synchronized void initialize(TypeDataBase db) throws WrongTypeException {
47
Type type = db.lookupType("ciMethodData");
48
origField = type.getField("_orig");
49
currentMileageField = new CIntField(type.getCIntegerField("_current_mileage"), 0);
50
argReturnedField = new CIntField(type.getCIntegerField("_arg_returned"), 0);
51
argStackField = new CIntField(type.getCIntegerField("_arg_stack"), 0);
52
argLocalField = new CIntField(type.getCIntegerField("_arg_local"), 0);
53
eflagsField = new CIntField(type.getCIntegerField("_eflags"), 0);
54
hintDiField = new CIntField(type.getCIntegerField("_hint_di"), 0);
55
currentMileageField = new CIntField(type.getCIntegerField("_current_mileage"), 0);
56
dataField = type.getAddressField("_data");
57
extraDataSizeField = new CIntField(type.getCIntegerField("_extra_data_size"), 0);
58
dataSizeField = new CIntField(type.getCIntegerField("_data_size"), 0);
59
stateField = new CIntField(type.getCIntegerField("_state"), 0);
60
Type typeMethodData = db.lookupType("MethodData");
61
sizeofMethodDataOopDesc = (int)typeMethodData.getSize();
62
parametersTypeDataDi = new CIntField(typeMethodData.getCIntegerField("_parameters_type_data_di"), 0);
63
}
64
65
private static Field origField;
66
private static CIntField currentMileageField;
67
private static CIntField argReturnedField;
68
private static CIntField argStackField;
69
private static CIntField argLocalField;
70
private static CIntField eflagsField;
71
private static CIntField hintDiField;
72
private static AddressField dataField;
73
private static CIntField extraDataSizeField;
74
private static CIntField dataSizeField;
75
private static CIntField stateField;
76
private static int sizeofMethodDataOopDesc;
77
private static CIntField parametersTypeDataDi;
78
79
public ciMethodData(Address addr) {
80
super(addr);
81
}
82
83
public ciKlass getKlassAtAddress(Address addr) {
84
return (ciKlass)ciObjectFactory.getMetadata(addr);
85
}
86
87
public ciMethod getMethodAtAddress(Address addr) {
88
return (ciMethod)ciObjectFactory.getMetadata(addr);
89
}
90
91
public void printKlassValueOn(ciKlass klass, PrintStream st) {
92
klass.printValueOn(st);
93
}
94
95
public void printMethodValueOn(ciMethod method, PrintStream st) {
96
method.printValueOn(st);
97
}
98
99
private byte[] fetchDataAt(Address base, long size) {
100
byte[] result = new byte[(int)size];
101
for (int i = 0; i < size; i++) {
102
result[i] = base.getJByteAt(i);
103
}
104
return result;
105
}
106
107
public byte[] orig() {
108
// fetch the orig MethodData data between header and dataSize
109
Address base = getAddress().addOffsetTo(origField.getOffset());
110
byte[] result = new byte[(int)origField.getType().getSize()];
111
for (int i = 0; i < result.length; i++) {
112
result[i] = base.getJByteAt(i);
113
}
114
return result;
115
}
116
117
public long[] data() {
118
// Read the data as an array of intptr_t elements
119
Address base = dataField.getValue(getAddress());
120
int elements = (dataSize() + extraDataSize()) / MethodData.cellSize;
121
long[] result = new long[elements];
122
for (int i = 0; i < elements; i++) {
123
Address value = base.getAddressAt(i * MethodData.cellSize);
124
if (value != null) {
125
result[i] = value.minus(null);
126
}
127
}
128
return result;
129
}
130
131
int dataSize() {
132
return (int)dataSizeField.getValue(getAddress());
133
}
134
135
int extraDataSize() {
136
return (int)extraDataSizeField.getValue(getAddress());
137
}
138
139
int state() {
140
return (int)stateField.getValue(getAddress());
141
}
142
143
int currentMileage() {
144
return (int)currentMileageField.getValue(getAddress());
145
}
146
147
boolean outOfBounds(int dataIndex) {
148
return dataIndex >= dataSize();
149
}
150
151
ParametersTypeData<ciKlass,ciMethod> parametersTypeData() {
152
int di = (int)parametersTypeDataDi.getValue(getMetadata().getAddress());
153
if (di == -1 || di == -2) {
154
return null;
155
}
156
DataLayout dataLayout = new DataLayout(dataField.getValue(getAddress()), di);
157
return new ParametersTypeData<ciKlass,ciMethod>(this, dataLayout);
158
}
159
160
ProfileData dataAt(int dataIndex) {
161
if (outOfBounds(dataIndex)) {
162
return null;
163
}
164
DataLayout dataLayout = new DataLayout(dataField.getValue(getAddress()), dataIndex);
165
166
switch (dataLayout.tag()) {
167
case DataLayout.noTag:
168
default:
169
throw new InternalError();
170
case DataLayout.bitDataTag:
171
return new BitData(dataLayout);
172
case DataLayout.counterDataTag:
173
return new CounterData(dataLayout);
174
case DataLayout.jumpDataTag:
175
return new JumpData(dataLayout);
176
case DataLayout.receiverTypeDataTag:
177
return new ReceiverTypeData<ciKlass,ciMethod>(this, dataLayout);
178
case DataLayout.virtualCallDataTag:
179
return new VirtualCallData<ciKlass,ciMethod>(this, dataLayout);
180
case DataLayout.retDataTag:
181
return new RetData(dataLayout);
182
case DataLayout.branchDataTag:
183
return new BranchData(dataLayout);
184
case DataLayout.multiBranchDataTag:
185
return new MultiBranchData(dataLayout);
186
case DataLayout.callTypeDataTag:
187
return new CallTypeData<ciKlass,ciMethod>(this, dataLayout);
188
case DataLayout.virtualCallTypeDataTag:
189
return new VirtualCallTypeData<ciKlass,ciMethod>(this, dataLayout);
190
case DataLayout.parametersTypeDataTag:
191
return new ParametersTypeData<ciKlass,ciMethod>(this, dataLayout);
192
}
193
}
194
195
int dpToDi(int dp) {
196
return dp;
197
}
198
199
int firstDi() { return 0; }
200
ProfileData firstData() { return dataAt(firstDi()); }
201
ProfileData nextData(ProfileData current) {
202
int currentIndex = dpToDi(current.dp());
203
int nextIndex = currentIndex + current.sizeInBytes();
204
return dataAt(nextIndex);
205
}
206
boolean isValid(ProfileData current) { return current != null; }
207
208
DataLayout limitDataPosition() {
209
return new DataLayout(dataField.getValue(getAddress()), dataSize());
210
}
211
DataLayout extraDataBase() {
212
return limitDataPosition();
213
}
214
DataLayout extraDataLimit() {
215
return new DataLayout(dataField.getValue(getAddress()), dataSize() + extraDataSize());
216
}
217
DataLayout nextExtra(DataLayout dataLayout) {
218
return new DataLayout(dataField.getValue(getAddress()), dataLayout.dp() + DataLayout.computeSizeInBytes(MethodData.extraNbCells(dataLayout)));
219
}
220
221
public void printDataOn(PrintStream st) {
222
if (parametersTypeData() != null) {
223
parametersTypeData().printDataOn(st);
224
}
225
ProfileData data = firstData();
226
for ( ; isValid(data); data = nextData(data)) {
227
st.print(dpToDi(data.dp()));
228
st.print(" ");
229
// st->fillTo(6);
230
data.printDataOn(st);
231
}
232
st.println("--- Extra data:");
233
DataLayout dp = extraDataBase();
234
DataLayout end = extraDataLimit();
235
for (;; dp = nextExtra(dp)) {
236
switch(dp.tag()) {
237
case DataLayout.noTag:
238
continue;
239
case DataLayout.bitDataTag:
240
data = new BitData(dp);
241
break;
242
case DataLayout.speculativeTrapDataTag:
243
data = new SpeculativeTrapData<ciKlass,ciMethod>(this, dp);
244
break;
245
case DataLayout.argInfoDataTag:
246
data = new ArgInfoData(dp);
247
dp = end; // ArgInfoData is at the end of extra data section.
248
break;
249
default:
250
throw new InternalError("unexpected tag " + dp.tag());
251
}
252
st.print(dpToDi(data.dp()));
253
st.print(" ");
254
data.printDataOn(st);
255
if (dp == end) return;
256
}
257
}
258
259
int dumpReplayDataTypeHelper(PrintStream out, int round, int count, int index, ProfileData pdata, ciKlass k) {
260
if (k != null) {
261
if (round == 0) count++;
262
else out.print(" " + ((pdata.dp() + pdata.cellOffset(index)) / MethodData.cellSize) + " " + k.name());
263
}
264
return count;
265
}
266
267
int dumpReplayDataReceiverTypeHelper(PrintStream out, int round, int count, ReceiverTypeData<ciKlass,ciMethod> vdata) {
268
for (int i = 0; i < vdata.rowLimit(); i++) {
269
ciKlass k = vdata.receiver(i);
270
count = dumpReplayDataTypeHelper(out, round, count, vdata.receiverCellIndex(i), vdata, k);
271
}
272
return count;
273
}
274
275
int dumpReplayDataCallTypeHelper(PrintStream out, int round, int count, CallTypeDataInterface<ciKlass> callTypeData) {
276
if (callTypeData.hasArguments()) {
277
for (int i = 0; i < callTypeData.numberOfArguments(); i++) {
278
count = dumpReplayDataTypeHelper(out, round, count, callTypeData.argumentTypeIndex(i), (ProfileData)callTypeData, callTypeData.argumentType(i));
279
}
280
}
281
if (callTypeData.hasReturn()) {
282
count = dumpReplayDataTypeHelper(out, round, count, callTypeData.returnTypeIndex(), (ProfileData)callTypeData, callTypeData.returnType());
283
}
284
return count;
285
}
286
287
int dumpReplayDataExtraDataHelper(PrintStream out, int round, int count) {
288
DataLayout dp = extraDataBase();
289
DataLayout end = extraDataLimit();
290
291
for (;dp != end; dp = nextExtra(dp)) {
292
switch(dp.tag()) {
293
case DataLayout.noTag:
294
case DataLayout.argInfoDataTag:
295
return count;
296
case DataLayout.bitDataTag:
297
break;
298
case DataLayout.speculativeTrapDataTag: {
299
SpeculativeTrapData<ciKlass,ciMethod> data = new SpeculativeTrapData<ciKlass,ciMethod>(this, dp);
300
ciMethod m = data.method();
301
if (m != null) {
302
if (round == 0) {
303
count++;
304
} else {
305
out.print(" " + (dpToDi(data.dp() + data.cellOffset(SpeculativeTrapData.methodIndex())) / MethodData.cellSize) + " " + m.nameAsAscii());
306
}
307
}
308
break;
309
}
310
default:
311
throw new InternalError("bad tag " + dp.tag());
312
}
313
}
314
return count;
315
}
316
317
public void dumpReplayData(PrintStream out) {
318
MethodData mdo = (MethodData)getMetadata();
319
Method method = mdo.getMethod();
320
out.print("ciMethodData " +
321
method.nameAsAscii() + " " +
322
state() + " " + currentMileage());
323
byte[] orig = orig();
324
out.print(" orig " + orig.length);
325
for (int i = 0; i < orig.length; i++) {
326
out.print(" " + (orig[i] & 0xff));
327
}
328
329
long[] data = data();
330
out.print(" data " + data.length);
331
for (int i = 0; i < data.length; i++) {
332
out.print(" 0x" + Long.toHexString(data[i]));
333
}
334
int count = 0;
335
ParametersTypeData<ciKlass,ciMethod> parameters = parametersTypeData();
336
for (int round = 0; round < 2; round++) {
337
if (round == 1) out.print(" oops " + count);
338
ProfileData pdata = firstData();
339
for ( ; isValid(pdata); pdata = nextData(pdata)) {
340
if (pdata instanceof ReceiverTypeData) {
341
@SuppressWarnings("unchecked")
342
ReceiverTypeData<ciKlass,ciMethod> receiverTypeData = (ReceiverTypeData<ciKlass,ciMethod>)pdata;
343
count = dumpReplayDataReceiverTypeHelper(out, round, count, receiverTypeData);
344
}
345
if (pdata instanceof CallTypeDataInterface) {
346
@SuppressWarnings("unchecked")
347
CallTypeDataInterface<ciKlass> callTypeData = (CallTypeDataInterface<ciKlass>)pdata;
348
count = dumpReplayDataCallTypeHelper(out, round, count, callTypeData);
349
}
350
}
351
if (parameters != null) {
352
for (int i = 0; i < parameters.numberOfParameters(); i++) {
353
count = dumpReplayDataTypeHelper(out, round, count, ParametersTypeData.typeIndex(i), parameters, parameters.type(i));
354
}
355
}
356
}
357
count = 0;
358
for (int round = 0; round < 2; round++) {
359
if (round == 1) out.print(" methods " + count);
360
count = dumpReplayDataExtraDataHelper(out, round, count);
361
}
362
out.println();
363
}
364
}
365
366