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/code/StubQueue.java
41171 views
1
/*
2
* Copyright (c) 2000, 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
package sun.jvm.hotspot.code;
26
27
import java.util.*;
28
import sun.jvm.hotspot.debugger.*;
29
import sun.jvm.hotspot.runtime.*;
30
import sun.jvm.hotspot.types.*;
31
import sun.jvm.hotspot.utilities.*;
32
import sun.jvm.hotspot.utilities.Observable;
33
import sun.jvm.hotspot.utilities.Observer;
34
35
/** <P> A port of the VM's StubQueue. Note that the VM implicitly
36
knows the type of the objects contained in each StubQueue because
37
it passes in an instance of a StubInterface to the StubQueue's
38
constructor; the goal in the VM was to save space in the generated
39
code. In the SA APIs the pattern has been to use the
40
VirtualConstructor mechanism to instantiate wrapper objects of the
41
appropriate type for objects down in the VM; see, for example, the
42
CodeCache, which identifies NMethods, RuntimeStubs, etc. </P>
43
44
<P> In this port we eliminate the StubInterface in favor of
45
passing in the class corresponding to the type of Stub which this
46
StubQueue contains. </P> */
47
48
public class StubQueue extends VMObject {
49
// FIXME: add the rest of the fields
50
private static AddressField stubBufferField;
51
private static CIntegerField bufferLimitField;
52
private static CIntegerField queueBeginField;
53
private static CIntegerField queueEndField;
54
private static CIntegerField numberOfStubsField;
55
56
// The type of the contained stubs (i.e., InterpreterCodelet,
57
// ICStub). Must be a subclass of type Stub.
58
private Class<?> stubType;
59
60
static {
61
VM.registerVMInitializedObserver(new Observer() {
62
public void update(Observable o, Object data) {
63
initialize(VM.getVM().getTypeDataBase());
64
}
65
});
66
}
67
68
private static synchronized void initialize(TypeDataBase db) {
69
Type type = db.lookupType("StubQueue");
70
71
stubBufferField = type.getAddressField("_stub_buffer");
72
bufferLimitField = type.getCIntegerField("_buffer_limit");
73
queueBeginField = type.getCIntegerField("_queue_begin");
74
queueEndField = type.getCIntegerField("_queue_end");
75
numberOfStubsField = type.getCIntegerField("_number_of_stubs");
76
}
77
78
public StubQueue(Address addr, Class stubType) {
79
super(addr);
80
this.stubType = stubType;
81
}
82
83
public boolean contains(Address pc) {
84
if (pc == null) return false;
85
long offset = pc.minus(getStubBuffer());
86
return ((0 <= offset) && (offset < getBufferLimit()));
87
}
88
89
public Stub getStubContaining(Address pc) {
90
if (contains(pc)) {
91
int i = 0;
92
for (Stub s = getFirst(); s != null; s = getNext(s)) {
93
if (stubContains(s, pc)) {
94
return s;
95
}
96
}
97
}
98
return null;
99
}
100
101
public boolean stubContains(Stub s, Address pc) {
102
return (s.codeBegin().lessThanOrEqual(pc) && s.codeEnd().greaterThan(pc));
103
}
104
105
public int getNumberOfStubs() {
106
return (int) numberOfStubsField.getValue(addr);
107
}
108
109
public Stub getFirst() {
110
return ((getNumberOfStubs() > 0) ? getStubAt(getQueueBegin()) : null);
111
}
112
113
public Stub getNext(Stub s) {
114
long i = getIndexOf(s) + getStubSize(s);
115
if (i == getBufferLimit()) {
116
i = 0;
117
}
118
return ((i == getQueueEnd()) ? null : getStubAt(i));
119
}
120
121
public Stub getPrev(Stub s) {
122
if (getIndexOf(s) == getQueueBegin()) {
123
return null;
124
}
125
126
Stub temp = getFirst();
127
Stub prev = null;
128
while (temp != null && getIndexOf(temp) != getIndexOf(s)) {
129
prev = temp;
130
temp = getNext(temp);
131
}
132
133
return prev;
134
}
135
136
//--------------------------------------------------------------------------------
137
// Internals only below this point
138
//
139
140
private long getQueueBegin() {
141
return queueBeginField.getValue(addr);
142
}
143
144
private long getQueueEnd() {
145
return queueEndField.getValue(addr);
146
}
147
148
private long getBufferLimit() {
149
return bufferLimitField.getValue(addr);
150
}
151
152
private Address getStubBuffer() {
153
return stubBufferField.getValue(addr);
154
}
155
156
private Stub getStubAt(long offset) {
157
checkIndex(offset);
158
return (Stub) VMObjectFactory.newObject(stubType, getStubBuffer().addOffsetTo(offset));
159
}
160
161
private long getIndexOf(Stub s) {
162
long i = s.getAddress().minus(getStubBuffer());
163
checkIndex(i);
164
return i;
165
}
166
167
private long getStubSize(Stub s) {
168
return s.getSize();
169
}
170
171
private void checkIndex(long i) {
172
if (Assert.ASSERTS_ENABLED) {
173
Assert.that(0 <= i && i < getBufferLimit() && (i % VM.getVM().getAddressSize() == 0), "illegal index");
174
}
175
}
176
}
177
178