annotate agent/src/share/classes/sun/jvm/hotspot/oops/Field.java @ 3939:f6f3bb0ee072

7088955: add C2 IR support to the SA Reviewed-by: kvn
author never
date Sun, 11 Sep 2011 14:48:24 -0700
parents e6b1331a51d2
children da91efe96a93
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
3939
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3938
diff changeset
2 * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
21 * questions.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 package sun.jvm.hotspot.oops;
a61af66fc99e Initial load
duke
parents:
diff changeset
26
a61af66fc99e Initial load
duke
parents:
diff changeset
27 import java.io.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
28
a61af66fc99e Initial load
duke
parents:
diff changeset
29 import sun.jvm.hotspot.runtime.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
30
a61af66fc99e Initial load
duke
parents:
diff changeset
31 // Super class for all fields in an object
a61af66fc99e Initial load
duke
parents:
diff changeset
32 public class Field {
a61af66fc99e Initial load
duke
parents:
diff changeset
33
a61af66fc99e Initial load
duke
parents:
diff changeset
34 Field(FieldIdentifier id, long offset, boolean isVMField) {
a61af66fc99e Initial load
duke
parents:
diff changeset
35 this.offset = offset;
a61af66fc99e Initial load
duke
parents:
diff changeset
36 this.id = id;
a61af66fc99e Initial load
duke
parents:
diff changeset
37 this.isVMField = isVMField;
a61af66fc99e Initial load
duke
parents:
diff changeset
38 }
a61af66fc99e Initial load
duke
parents:
diff changeset
39
a61af66fc99e Initial load
duke
parents:
diff changeset
40 /** Constructor for fields that are named in an InstanceKlass's
a61af66fc99e Initial load
duke
parents:
diff changeset
41 fields array (i.e., named, non-VM fields) */
3938
e6b1331a51d2 7086585: make Java field injection more flexible
never
parents: 1552
diff changeset
42 Field(InstanceKlass holder, int fieldIndex) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
43 this.holder = holder;
3938
e6b1331a51d2 7086585: make Java field injection more flexible
never
parents: 1552
diff changeset
44 this.fieldIndex = fieldIndex;
e6b1331a51d2 7086585: make Java field injection more flexible
never
parents: 1552
diff changeset
45
e6b1331a51d2 7086585: make Java field injection more flexible
never
parents: 1552
diff changeset
46 offset = holder.getFieldOffset(fieldIndex);
e6b1331a51d2 7086585: make Java field injection more flexible
never
parents: 1552
diff changeset
47 genericSignature = holder.getFieldGenericSignature(fieldIndex);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
48
3938
e6b1331a51d2 7086585: make Java field injection more flexible
never
parents: 1552
diff changeset
49 Symbol name = holder.getFieldName(fieldIndex);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
50 id = new NamedFieldIdentifier(name.asString());
a61af66fc99e Initial load
duke
parents:
diff changeset
51
3938
e6b1331a51d2 7086585: make Java field injection more flexible
never
parents: 1552
diff changeset
52 signature = holder.getFieldSignature(fieldIndex);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
53 fieldType = new FieldType(signature);
3938
e6b1331a51d2 7086585: make Java field injection more flexible
never
parents: 1552
diff changeset
54
e6b1331a51d2 7086585: make Java field injection more flexible
never
parents: 1552
diff changeset
55 short access = holder.getFieldAccessFlags(fieldIndex);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
56 accessFlags = new AccessFlags(access);
a61af66fc99e Initial load
duke
parents:
diff changeset
57 }
a61af66fc99e Initial load
duke
parents:
diff changeset
58
a61af66fc99e Initial load
duke
parents:
diff changeset
59 private long offset;
a61af66fc99e Initial load
duke
parents:
diff changeset
60 private FieldIdentifier id;
a61af66fc99e Initial load
duke
parents:
diff changeset
61 private boolean isVMField;
a61af66fc99e Initial load
duke
parents:
diff changeset
62 // Java fields only
a61af66fc99e Initial load
duke
parents:
diff changeset
63 private InstanceKlass holder;
a61af66fc99e Initial load
duke
parents:
diff changeset
64 private FieldType fieldType;
a61af66fc99e Initial load
duke
parents:
diff changeset
65 private Symbol signature;
a61af66fc99e Initial load
duke
parents:
diff changeset
66 private Symbol genericSignature;
a61af66fc99e Initial load
duke
parents:
diff changeset
67 private AccessFlags accessFlags;
3938
e6b1331a51d2 7086585: make Java field injection more flexible
never
parents: 1552
diff changeset
68 private int fieldIndex;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
69
a61af66fc99e Initial load
duke
parents:
diff changeset
70 /** Returns the byte offset of the field within the object or klass */
a61af66fc99e Initial load
duke
parents:
diff changeset
71 public long getOffset() { return offset; }
a61af66fc99e Initial load
duke
parents:
diff changeset
72
a61af66fc99e Initial load
duke
parents:
diff changeset
73 /** Returns the identifier of the field */
a61af66fc99e Initial load
duke
parents:
diff changeset
74 public FieldIdentifier getID() { return id; }
a61af66fc99e Initial load
duke
parents:
diff changeset
75
a61af66fc99e Initial load
duke
parents:
diff changeset
76 /** Indicates whether this is a VM field */
a61af66fc99e Initial load
duke
parents:
diff changeset
77 public boolean isVMField() { return isVMField; }
a61af66fc99e Initial load
duke
parents:
diff changeset
78
a61af66fc99e Initial load
duke
parents:
diff changeset
79 /** Indicates whether this is a named field */
a61af66fc99e Initial load
duke
parents:
diff changeset
80 public boolean isNamedField() { return (id instanceof NamedFieldIdentifier); }
a61af66fc99e Initial load
duke
parents:
diff changeset
81
a61af66fc99e Initial load
duke
parents:
diff changeset
82 public void printOn(PrintStream tty) {
a61af66fc99e Initial load
duke
parents:
diff changeset
83 getID().printOn(tty);
a61af66fc99e Initial load
duke
parents:
diff changeset
84 tty.print(" {" + getOffset() + "} :");
a61af66fc99e Initial load
duke
parents:
diff changeset
85 }
a61af66fc99e Initial load
duke
parents:
diff changeset
86
a61af66fc99e Initial load
duke
parents:
diff changeset
87 /** (Named, non-VM fields only) Returns the InstanceKlass containing
a61af66fc99e Initial load
duke
parents:
diff changeset
88 this (static or non-static) field. */
a61af66fc99e Initial load
duke
parents:
diff changeset
89 public InstanceKlass getFieldHolder() {
a61af66fc99e Initial load
duke
parents:
diff changeset
90 return holder;
a61af66fc99e Initial load
duke
parents:
diff changeset
91 }
a61af66fc99e Initial load
duke
parents:
diff changeset
92
a61af66fc99e Initial load
duke
parents:
diff changeset
93 /** (Named, non-VM fields only) Returns the index in the fields
a61af66fc99e Initial load
duke
parents:
diff changeset
94 TypeArray for this field. Equivalent to the "index" in the VM's
a61af66fc99e Initial load
duke
parents:
diff changeset
95 fieldDescriptors. */
3938
e6b1331a51d2 7086585: make Java field injection more flexible
never
parents: 1552
diff changeset
96 public int getFieldIndex() {
e6b1331a51d2 7086585: make Java field injection more flexible
never
parents: 1552
diff changeset
97 return fieldIndex;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
98 }
a61af66fc99e Initial load
duke
parents:
diff changeset
99
a61af66fc99e Initial load
duke
parents:
diff changeset
100 /** (Named, non-VM fields only) Retrieves the access flags. */
a61af66fc99e Initial load
duke
parents:
diff changeset
101 public long getAccessFlags() { return accessFlags.getValue(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
102 public AccessFlags getAccessFlagsObj() { return accessFlags; }
a61af66fc99e Initial load
duke
parents:
diff changeset
103
a61af66fc99e Initial load
duke
parents:
diff changeset
104 /** (Named, non-VM fields only) Returns the type of this field. */
a61af66fc99e Initial load
duke
parents:
diff changeset
105 public FieldType getFieldType() { return fieldType; }
a61af66fc99e Initial load
duke
parents:
diff changeset
106
a61af66fc99e Initial load
duke
parents:
diff changeset
107 /** (Named, non-VM fields only) Returns the signature of this
a61af66fc99e Initial load
duke
parents:
diff changeset
108 field. */
a61af66fc99e Initial load
duke
parents:
diff changeset
109 public Symbol getSignature() { return signature; }
a61af66fc99e Initial load
duke
parents:
diff changeset
110 public Symbol getGenericSignature() { return genericSignature; }
a61af66fc99e Initial load
duke
parents:
diff changeset
111
a61af66fc99e Initial load
duke
parents:
diff changeset
112 //
a61af66fc99e Initial load
duke
parents:
diff changeset
113 // Following acccessors are for named, non-VM fields only
a61af66fc99e Initial load
duke
parents:
diff changeset
114 //
a61af66fc99e Initial load
duke
parents:
diff changeset
115 public boolean isPublic() { return accessFlags.isPublic(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
116 public boolean isPrivate() { return accessFlags.isPrivate(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
117 public boolean isProtected() { return accessFlags.isProtected(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
118 public boolean isPackagePrivate() { return !isPublic() && !isPrivate() && !isProtected(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
119
a61af66fc99e Initial load
duke
parents:
diff changeset
120 public boolean isStatic() { return accessFlags.isStatic(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
121 public boolean isFinal() { return accessFlags.isFinal(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
122 public boolean isVolatile() { return accessFlags.isVolatile(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
123 public boolean isTransient() { return accessFlags.isTransient(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
124
a61af66fc99e Initial load
duke
parents:
diff changeset
125 public boolean isSynthetic() { return accessFlags.isSynthetic(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
126 public boolean isEnumConstant() { return accessFlags.isEnum(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
127
a61af66fc99e Initial load
duke
parents:
diff changeset
128 public boolean equals(Object obj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
129 if (obj == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
130 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
131 }
a61af66fc99e Initial load
duke
parents:
diff changeset
132
a61af66fc99e Initial load
duke
parents:
diff changeset
133 if (! (obj instanceof Field)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
134 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
135 }
a61af66fc99e Initial load
duke
parents:
diff changeset
136
a61af66fc99e Initial load
duke
parents:
diff changeset
137 Field other = (Field) obj;
a61af66fc99e Initial load
duke
parents:
diff changeset
138 return this.getFieldHolder().equals(other.getFieldHolder()) &&
a61af66fc99e Initial load
duke
parents:
diff changeset
139 this.getID().equals(other.getID());
a61af66fc99e Initial load
duke
parents:
diff changeset
140 }
a61af66fc99e Initial load
duke
parents:
diff changeset
141
a61af66fc99e Initial load
duke
parents:
diff changeset
142 public int hashCode() {
a61af66fc99e Initial load
duke
parents:
diff changeset
143 return getFieldHolder().hashCode() ^ getID().hashCode();
a61af66fc99e Initial load
duke
parents:
diff changeset
144 }
a61af66fc99e Initial load
duke
parents:
diff changeset
145 }