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/runtime/JNIHandleBlock.java
41161 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.runtime;
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
/** */
36
public class JNIHandleBlock extends VMObject {
37
private static Field handlesField;
38
private static CIntegerField topField;
39
private static AddressField nextField;
40
41
private static int blockSizeInOops;
42
43
static {
44
VM.registerVMInitializedObserver(new Observer() {
45
public void update(Observable o, Object data) {
46
initialize(VM.getVM().getTypeDataBase());
47
}
48
});
49
}
50
51
private static synchronized void initialize(TypeDataBase db) {
52
Type type = db.lookupType("JNIHandleBlock");
53
54
handlesField = type.getField("_handles");
55
topField = type.getCIntegerField("_top");
56
nextField = type.getAddressField("_next");
57
58
blockSizeInOops = db.lookupIntConstant("JNIHandleBlock::block_size_in_oops").intValue();
59
}
60
61
public JNIHandleBlock(Address addr) {
62
super(addr);
63
}
64
65
public JNIHandleBlock next() {
66
Address handleAddr = nextField.getValue(addr);
67
if (handleAddr == null) {
68
return null;
69
}
70
71
/* the next handle block is valid only if the current block is full */
72
if (top() < blockSizeInOops) {
73
return null;
74
}
75
return new JNIHandleBlock(handleAddr);
76
}
77
78
public int top() {
79
return (int) topField.getValue(addr);
80
}
81
82
public void oopsDo(AddressVisitor visitor) {
83
// Visit handles in this block
84
for (int i = 0; i < top(); i++) {
85
Address cur = getOopHandleAddress(i);
86
if (cur != null) {
87
visitor.visitAddress(cur);
88
}
89
}
90
91
// Visit handles in subsequent blocks if necessary
92
JNIHandleBlock n = next();
93
if (n != null) {
94
n.oopsDo(visitor);
95
}
96
}
97
98
public OopHandle getOopHandle(int x) {
99
Address oopAddr = getOopHandleAddress(x);
100
if (oopAddr != null) {
101
return oopAddr.getOopHandleAt(0);
102
}
103
return null;
104
}
105
106
/** Debugging routine only. Returns non-null JNIHandleBlock
107
containing the JNI handle or null if this handle block and its
108
successors did not contain it. */
109
public JNIHandleBlock blockContainingHandle(Address jniHandle) {
110
JNIHandleBlock cur = this;
111
while (cur != null) {
112
if (indexOfHandle(jniHandle) >= 0) {
113
return cur;
114
}
115
cur = cur.next();
116
}
117
return null;
118
}
119
120
/** Debugging routine: returns the index (0..top() - 1) of the
121
handle in this block, or -1 if the handle was not contained in
122
this block. Does not search successor blocks. */
123
public int indexOfHandle(Address jniHandle) {
124
for (int i = 0; i < top(); i++) {
125
Address addr = getOopHandleAddress(i);
126
if (addr != null) {
127
if (addr.equals(jniHandle)) {
128
return i;
129
}
130
}
131
}
132
return -1;
133
}
134
135
public String toString() {
136
Address handleBase = addr.addOffsetTo(handlesField.getOffset());
137
Address handleEnd = addr.addOffsetTo(handlesField.getOffset() + top() * VM.getVM().getOopSize());
138
return "JNIHandleBlock [" + handleBase + ", " + handleEnd + ")";
139
}
140
141
/** Only returns addresses of valid OopHandles */
142
private Address getOopHandleAddress(int x) {
143
if (Assert.ASSERTS_ENABLED) {
144
Assert.that(x < top(), "out of bounds");
145
}
146
147
Address oopAddr = addr.addOffsetTo(handlesField.getOffset() + x * VM.getVM().getOopSize());
148
OopHandle handle = oopAddr.getOopHandleAt(0);
149
if (VM.getVM().getUniverse().isInReserved(handle)) {
150
/* the oop handle is valid only if it is not freed (i.e. reserved in heap) */
151
return oopAddr;
152
} else {
153
return null;
154
}
155
}
156
}
157
158