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/compiler/OopMapValue.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.compiler;
26
27
import java.util.*;
28
29
import sun.jvm.hotspot.code.*;
30
import sun.jvm.hotspot.runtime.*;
31
import sun.jvm.hotspot.types.*;
32
import sun.jvm.hotspot.utilities.*;
33
import sun.jvm.hotspot.utilities.Observable;
34
import sun.jvm.hotspot.utilities.Observer;
35
36
public class OopMapValue {
37
private short value;
38
private short contentReg;
39
40
/** Read from target VM; located in compiler/oopMap.hpp */
41
// How bits are organized
42
static int TYPE_BITS;
43
static int REGISTER_BITS;
44
static int TYPE_SHIFT;
45
static int REGISTER_SHIFT;
46
static int TYPE_MASK;
47
static int TYPE_MASK_IN_PLACE;
48
static int REGISTER_MASK;
49
static int REGISTER_MASK_IN_PLACE;
50
51
// Types of OopValues
52
static int OOP_VALUE;
53
static int NARROWOOP_VALUE;
54
static int CALLEE_SAVED_VALUE;
55
static int DERIVED_OOP_VALUE;
56
57
static {
58
VM.registerVMInitializedObserver(new Observer() {
59
public void update(Observable o, Object data) {
60
initialize(VM.getVM().getTypeDataBase());
61
}
62
});
63
}
64
65
private static void initialize(TypeDataBase db) {
66
TYPE_BITS = db.lookupIntConstant("OopMapValue::type_bits").intValue();
67
REGISTER_BITS = db.lookupIntConstant("OopMapValue::register_bits").intValue();
68
TYPE_SHIFT = db.lookupIntConstant("OopMapValue::type_shift").intValue();
69
REGISTER_SHIFT = db.lookupIntConstant("OopMapValue::register_shift").intValue();
70
TYPE_MASK = db.lookupIntConstant("OopMapValue::type_mask").intValue();
71
TYPE_MASK_IN_PLACE = db.lookupIntConstant("OopMapValue::type_mask_in_place").intValue();
72
REGISTER_MASK = db.lookupIntConstant("OopMapValue::register_mask").intValue();
73
REGISTER_MASK_IN_PLACE = db.lookupIntConstant("OopMapValue::register_mask_in_place").intValue();
74
OOP_VALUE = db.lookupIntConstant("OopMapValue::oop_value").intValue();
75
NARROWOOP_VALUE = db.lookupIntConstant("OopMapValue::narrowoop_value").intValue();
76
CALLEE_SAVED_VALUE = db.lookupIntConstant("OopMapValue::callee_saved_value").intValue();
77
DERIVED_OOP_VALUE = db.lookupIntConstant("OopMapValue::derived_oop_value").intValue();
78
}
79
80
public static abstract class OopTypes {
81
public static final OopTypes OOP_VALUE = new OopTypes() { int getValue() { return OopMapValue.OOP_VALUE; }};
82
public static final OopTypes NARROWOOP_VALUE = new OopTypes() { int getValue() { return OopMapValue.NARROWOOP_VALUE; }};
83
public static final OopTypes CALLEE_SAVED_VALUE = new OopTypes() { int getValue() { return OopMapValue.CALLEE_SAVED_VALUE; }};
84
public static final OopTypes DERIVED_OOP_VALUE = new OopTypes() { int getValue() { return OopMapValue.DERIVED_OOP_VALUE; }};
85
86
abstract int getValue();
87
protected OopTypes() {}
88
}
89
90
public OopMapValue() { setValue((short) 0); setContentReg(new VMReg(0)); }
91
public OopMapValue(VMReg reg, OopTypes t) { setReg(reg); setType(t); }
92
public OopMapValue(VMReg reg, OopTypes t, VMReg reg2) { setReg(reg); setType(t); setContentReg(reg2); }
93
public OopMapValue(CompressedReadStream stream) { readFrom(stream); }
94
95
public void readFrom(CompressedReadStream stream) {
96
setValue((short) stream.readInt());
97
if (isCalleeSaved() || isDerivedOop()) {
98
setContentReg(new VMReg(stream.readInt()));
99
}
100
}
101
102
// Querying
103
public boolean isOop() { return (getValue() & TYPE_MASK_IN_PLACE) == OOP_VALUE; }
104
public boolean isNarrowOop() { return (getValue() & TYPE_MASK_IN_PLACE) == NARROWOOP_VALUE; }
105
public boolean isCalleeSaved() { return (getValue() & TYPE_MASK_IN_PLACE) == CALLEE_SAVED_VALUE; }
106
public boolean isDerivedOop() { return (getValue() & TYPE_MASK_IN_PLACE) == DERIVED_OOP_VALUE; }
107
108
public VMReg getReg() { return new VMReg((getValue() & REGISTER_MASK_IN_PLACE) >> REGISTER_SHIFT); }
109
public void setReg(VMReg r) { setValue((short) (r.getValue() << REGISTER_SHIFT | (getValue() & TYPE_MASK_IN_PLACE))); }
110
111
public OopTypes getType() {
112
int which = (getValue() & TYPE_MASK_IN_PLACE);
113
if (which == OOP_VALUE) return OopTypes.OOP_VALUE;
114
else if (which == NARROWOOP_VALUE) return OopTypes.NARROWOOP_VALUE;
115
else if (which == CALLEE_SAVED_VALUE) return OopTypes.CALLEE_SAVED_VALUE;
116
else if (which == DERIVED_OOP_VALUE) return OopTypes.DERIVED_OOP_VALUE;
117
else throw new InternalError("unknown which " + which + " (TYPE_MASK_IN_PLACE = " + TYPE_MASK_IN_PLACE + ")");
118
}
119
public void setType(OopTypes t) { setValue((short) ((getValue() & REGISTER_MASK_IN_PLACE) | t.getValue())); }
120
121
public VMReg getContentReg() { return new VMReg(contentReg); }
122
public void setContentReg(VMReg r) { contentReg = (short) r.getValue(); }
123
124
/** Physical location queries */
125
public boolean isRegisterLoc() { return (getReg().lessThan(VM.getVM().getVMRegImplInfo().getStack0())); }
126
public boolean isStackLoc() { return (getReg().greaterThanOrEqual(VM.getVM().getVMRegImplInfo().getStack0())); }
127
128
/** Returns offset from sp. */
129
public int getStackOffset() {
130
if (Assert.ASSERTS_ENABLED) {
131
Assert.that(isStackLoc(), "must be stack location");
132
}
133
return getReg().minus(VM.getVM().getVMRegImplInfo().getStack0());
134
}
135
136
//--------------------------------------------------------------------------------
137
// Internals only below this point
138
//
139
140
private void setValue(short value) {
141
this.value = value;
142
}
143
144
private int getValue() {
145
return value;
146
}
147
}
148
149