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/oops/Field.java
41161 views
1
/*
2
* Copyright (c) 2000, 2018, 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.oops;
26
27
import java.io.*;
28
29
import sun.jvm.hotspot.runtime.*;
30
import sun.jvm.hotspot.utilities.*;
31
32
// Super class for all fields in an object
33
public class Field {
34
35
Field(FieldIdentifier id, long offset, boolean isVMField) {
36
this.offset = offset;
37
this.id = id;
38
this.isVMField = isVMField;
39
}
40
41
/** Constructor for fields that are named in an InstanceKlass's
42
fields array (i.e., named, non-VM fields) */
43
Field(InstanceKlass holder, int fieldIndex) {
44
this.holder = holder;
45
this.fieldIndex = fieldIndex;
46
47
offset = holder.getFieldOffset(fieldIndex);
48
genericSignature = holder.getFieldGenericSignature(fieldIndex);
49
50
name = holder.getFieldName(fieldIndex);
51
id = new NamedFieldIdentifier(name.asString());
52
53
signature = holder.getFieldSignature(fieldIndex);
54
fieldType = new FieldType(signature);
55
56
short access = holder.getFieldAccessFlags(fieldIndex);
57
accessFlags = new AccessFlags(access);
58
}
59
60
private Symbol name;
61
private long offset;
62
private FieldIdentifier id;
63
private boolean isVMField;
64
// Java fields only
65
private InstanceKlass holder;
66
private FieldType fieldType;
67
private Symbol signature;
68
private Symbol genericSignature;
69
private AccessFlags accessFlags;
70
private int fieldIndex;
71
72
/** Returns the byte offset of the field within the object or klass */
73
public long getOffset() { return offset; }
74
75
/** Returns the identifier of the field */
76
public FieldIdentifier getID() { return id; }
77
78
public Symbol getName() { return name; }
79
80
/** Indicates whether this is a VM field */
81
public boolean isVMField() { return isVMField; }
82
83
/** Indicates whether this is a named field */
84
public boolean isNamedField() { return (id instanceof NamedFieldIdentifier); }
85
86
public void printOn(PrintStream tty) {
87
getID().printOn(tty);
88
tty.print(" {" + getOffset() + "} :");
89
}
90
91
/** (Named, non-VM fields only) Returns the InstanceKlass containing
92
this (static or non-static) field. */
93
public InstanceKlass getFieldHolder() {
94
return holder;
95
}
96
97
/** (Named, non-VM fields only) Returns the index in the fields
98
TypeArray for this field. Equivalent to the "index" in the VM's
99
fieldDescriptors. */
100
public int getFieldIndex() {
101
return fieldIndex;
102
}
103
104
/** (Named, non-VM fields only) Retrieves the access flags. */
105
public long getAccessFlags() { return accessFlags.getValue(); }
106
public AccessFlags getAccessFlagsObj() { return accessFlags; }
107
108
/** (Named, non-VM fields only) Returns the type of this field. */
109
public FieldType getFieldType() { return fieldType; }
110
111
/** (Named, non-VM fields only) Returns the signature of this
112
field. */
113
public Symbol getSignature() { return signature; }
114
public Symbol getGenericSignature() { return genericSignature; }
115
116
public boolean hasInitialValue() { return holder.getFieldInitialValueIndex(fieldIndex) != 0; }
117
118
//
119
// Following acccessors are for named, non-VM fields only
120
//
121
public boolean isPublic() { return accessFlags.isPublic(); }
122
public boolean isPrivate() { return accessFlags.isPrivate(); }
123
public boolean isProtected() { return accessFlags.isProtected(); }
124
public boolean isPackagePrivate() { return !isPublic() && !isPrivate() && !isProtected(); }
125
126
public boolean isStatic() { return accessFlags.isStatic(); }
127
public boolean isFinal() { return accessFlags.isFinal(); }
128
public boolean isVolatile() { return accessFlags.isVolatile(); }
129
public boolean isTransient() { return accessFlags.isTransient(); }
130
131
public boolean isSynthetic() { return accessFlags.isSynthetic(); }
132
public boolean isEnumConstant() { return accessFlags.isEnum(); }
133
134
public boolean equals(Object obj) {
135
if (obj == null) {
136
return false;
137
}
138
139
if (! (obj instanceof Field)) {
140
return false;
141
}
142
143
Field other = (Field) obj;
144
return this.getFieldHolder().equals(other.getFieldHolder()) &&
145
this.getID().equals(other.getID());
146
}
147
148
public int hashCode() {
149
return getFieldHolder().hashCode() ^ getID().hashCode();
150
}
151
}
152
153