annotate agent/src/share/classes/sun/jvm/hotspot/oops/Field.java @ 0:a61af66fc99e jdk7-b24

Initial load
author duke
date Sat, 01 Dec 2007 00:00:00 +0000
parents
children c18cbe5936b8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
2 * Copyright 2000-2003 Sun Microsystems, Inc. All Rights Reserved.
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 *
a61af66fc99e Initial load
duke
parents:
diff changeset
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
a61af66fc99e Initial load
duke
parents:
diff changeset
20 * CA 95054 USA or visit www.sun.com if you need additional information or
a61af66fc99e Initial load
duke
parents:
diff changeset
21 * have any questions.
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) */
a61af66fc99e Initial load
duke
parents:
diff changeset
42 Field(InstanceKlass holder, int fieldArrayIndex) {
a61af66fc99e Initial load
duke
parents:
diff changeset
43 this.holder = holder;
a61af66fc99e Initial load
duke
parents:
diff changeset
44 this.fieldArrayIndex = fieldArrayIndex;
a61af66fc99e Initial load
duke
parents:
diff changeset
45
a61af66fc99e Initial load
duke
parents:
diff changeset
46 ConstantPool cp = holder.getConstants();
a61af66fc99e Initial load
duke
parents:
diff changeset
47 TypeArray fields = holder.getFields();
a61af66fc99e Initial load
duke
parents:
diff changeset
48 short access = fields.getShortAt(fieldArrayIndex + InstanceKlass.ACCESS_FLAGS_OFFSET);
a61af66fc99e Initial load
duke
parents:
diff changeset
49 short nameIndex = fields.getShortAt(fieldArrayIndex + InstanceKlass.NAME_INDEX_OFFSET);
a61af66fc99e Initial load
duke
parents:
diff changeset
50 short signatureIndex = fields.getShortAt(fieldArrayIndex + InstanceKlass.SIGNATURE_INDEX_OFFSET);
a61af66fc99e Initial load
duke
parents:
diff changeset
51 offset = VM.getVM().buildIntFromShorts(fields.getShortAt(fieldArrayIndex + InstanceKlass.LOW_OFFSET),
a61af66fc99e Initial load
duke
parents:
diff changeset
52 fields.getShortAt(fieldArrayIndex + InstanceKlass.HIGH_OFFSET));
a61af66fc99e Initial load
duke
parents:
diff changeset
53 short genericSignatureIndex = fields.getShortAt(fieldArrayIndex + InstanceKlass.GENERIC_SIGNATURE_INDEX_OFFSET);
a61af66fc99e Initial load
duke
parents:
diff changeset
54 Symbol name = cp.getSymbolAt(nameIndex);
a61af66fc99e Initial load
duke
parents:
diff changeset
55 id = new NamedFieldIdentifier(name.asString());
a61af66fc99e Initial load
duke
parents:
diff changeset
56 signature = cp.getSymbolAt(signatureIndex);
a61af66fc99e Initial load
duke
parents:
diff changeset
57 if (genericSignatureIndex != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
58 genericSignature = cp.getSymbolAt(genericSignatureIndex);
a61af66fc99e Initial load
duke
parents:
diff changeset
59 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
60 genericSignature = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
61 }
a61af66fc99e Initial load
duke
parents:
diff changeset
62
a61af66fc99e Initial load
duke
parents:
diff changeset
63 fieldType = new FieldType(signature);
a61af66fc99e Initial load
duke
parents:
diff changeset
64 accessFlags = new AccessFlags(access);
a61af66fc99e Initial load
duke
parents:
diff changeset
65 }
a61af66fc99e Initial load
duke
parents:
diff changeset
66
a61af66fc99e Initial load
duke
parents:
diff changeset
67 private long offset;
a61af66fc99e Initial load
duke
parents:
diff changeset
68 private FieldIdentifier id;
a61af66fc99e Initial load
duke
parents:
diff changeset
69 private boolean isVMField;
a61af66fc99e Initial load
duke
parents:
diff changeset
70 // Java fields only
a61af66fc99e Initial load
duke
parents:
diff changeset
71 private InstanceKlass holder;
a61af66fc99e Initial load
duke
parents:
diff changeset
72 private FieldType fieldType;
a61af66fc99e Initial load
duke
parents:
diff changeset
73 private Symbol signature;
a61af66fc99e Initial load
duke
parents:
diff changeset
74 private Symbol genericSignature;
a61af66fc99e Initial load
duke
parents:
diff changeset
75 private AccessFlags accessFlags;
a61af66fc99e Initial load
duke
parents:
diff changeset
76 private int fieldArrayIndex;
a61af66fc99e Initial load
duke
parents:
diff changeset
77
a61af66fc99e Initial load
duke
parents:
diff changeset
78 /** Returns the byte offset of the field within the object or klass */
a61af66fc99e Initial load
duke
parents:
diff changeset
79 public long getOffset() { return offset; }
a61af66fc99e Initial load
duke
parents:
diff changeset
80
a61af66fc99e Initial load
duke
parents:
diff changeset
81 /** Returns the identifier of the field */
a61af66fc99e Initial load
duke
parents:
diff changeset
82 public FieldIdentifier getID() { return id; }
a61af66fc99e Initial load
duke
parents:
diff changeset
83
a61af66fc99e Initial load
duke
parents:
diff changeset
84 /** Indicates whether this is a VM field */
a61af66fc99e Initial load
duke
parents:
diff changeset
85 public boolean isVMField() { return isVMField; }
a61af66fc99e Initial load
duke
parents:
diff changeset
86
a61af66fc99e Initial load
duke
parents:
diff changeset
87 /** Indicates whether this is a named field */
a61af66fc99e Initial load
duke
parents:
diff changeset
88 public boolean isNamedField() { return (id instanceof NamedFieldIdentifier); }
a61af66fc99e Initial load
duke
parents:
diff changeset
89
a61af66fc99e Initial load
duke
parents:
diff changeset
90 public void printOn(PrintStream tty) {
a61af66fc99e Initial load
duke
parents:
diff changeset
91 getID().printOn(tty);
a61af66fc99e Initial load
duke
parents:
diff changeset
92 tty.print(" {" + getOffset() + "} :");
a61af66fc99e Initial load
duke
parents:
diff changeset
93 }
a61af66fc99e Initial load
duke
parents:
diff changeset
94
a61af66fc99e Initial load
duke
parents:
diff changeset
95 /** (Named, non-VM fields only) Returns the InstanceKlass containing
a61af66fc99e Initial load
duke
parents:
diff changeset
96 this (static or non-static) field. */
a61af66fc99e Initial load
duke
parents:
diff changeset
97 public InstanceKlass getFieldHolder() {
a61af66fc99e Initial load
duke
parents:
diff changeset
98 return holder;
a61af66fc99e Initial load
duke
parents:
diff changeset
99 }
a61af66fc99e Initial load
duke
parents:
diff changeset
100
a61af66fc99e Initial load
duke
parents:
diff changeset
101 /** (Named, non-VM fields only) Returns the index in the fields
a61af66fc99e Initial load
duke
parents:
diff changeset
102 TypeArray for this field. Equivalent to the "index" in the VM's
a61af66fc99e Initial load
duke
parents:
diff changeset
103 fieldDescriptors. */
a61af66fc99e Initial load
duke
parents:
diff changeset
104 public int getFieldArrayIndex() {
a61af66fc99e Initial load
duke
parents:
diff changeset
105 return fieldArrayIndex;
a61af66fc99e Initial load
duke
parents:
diff changeset
106 }
a61af66fc99e Initial load
duke
parents:
diff changeset
107
a61af66fc99e Initial load
duke
parents:
diff changeset
108 /** (Named, non-VM fields only) Retrieves the access flags. */
a61af66fc99e Initial load
duke
parents:
diff changeset
109 public long getAccessFlags() { return accessFlags.getValue(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
110 public AccessFlags getAccessFlagsObj() { return accessFlags; }
a61af66fc99e Initial load
duke
parents:
diff changeset
111
a61af66fc99e Initial load
duke
parents:
diff changeset
112 /** (Named, non-VM fields only) Returns the type of this field. */
a61af66fc99e Initial load
duke
parents:
diff changeset
113 public FieldType getFieldType() { return fieldType; }
a61af66fc99e Initial load
duke
parents:
diff changeset
114
a61af66fc99e Initial load
duke
parents:
diff changeset
115 /** (Named, non-VM fields only) Returns the signature of this
a61af66fc99e Initial load
duke
parents:
diff changeset
116 field. */
a61af66fc99e Initial load
duke
parents:
diff changeset
117 public Symbol getSignature() { return signature; }
a61af66fc99e Initial load
duke
parents:
diff changeset
118 public Symbol getGenericSignature() { return genericSignature; }
a61af66fc99e Initial load
duke
parents:
diff changeset
119
a61af66fc99e Initial load
duke
parents:
diff changeset
120 //
a61af66fc99e Initial load
duke
parents:
diff changeset
121 // Following acccessors are for named, non-VM fields only
a61af66fc99e Initial load
duke
parents:
diff changeset
122 //
a61af66fc99e Initial load
duke
parents:
diff changeset
123 public boolean isPublic() { return accessFlags.isPublic(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
124 public boolean isPrivate() { return accessFlags.isPrivate(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
125 public boolean isProtected() { return accessFlags.isProtected(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
126 public boolean isPackagePrivate() { return !isPublic() && !isPrivate() && !isProtected(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
127
a61af66fc99e Initial load
duke
parents:
diff changeset
128 public boolean isStatic() { return accessFlags.isStatic(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
129 public boolean isFinal() { return accessFlags.isFinal(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
130 public boolean isVolatile() { return accessFlags.isVolatile(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
131 public boolean isTransient() { return accessFlags.isTransient(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
132
a61af66fc99e Initial load
duke
parents:
diff changeset
133 public boolean isSynthetic() { return accessFlags.isSynthetic(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
134 public boolean isEnumConstant() { return accessFlags.isEnum(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
135
a61af66fc99e Initial load
duke
parents:
diff changeset
136 public boolean equals(Object obj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
137 if (obj == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
138 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
139 }
a61af66fc99e Initial load
duke
parents:
diff changeset
140
a61af66fc99e Initial load
duke
parents:
diff changeset
141 if (! (obj instanceof Field)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
142 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
143 }
a61af66fc99e Initial load
duke
parents:
diff changeset
144
a61af66fc99e Initial load
duke
parents:
diff changeset
145 Field other = (Field) obj;
a61af66fc99e Initial load
duke
parents:
diff changeset
146 return this.getFieldHolder().equals(other.getFieldHolder()) &&
a61af66fc99e Initial load
duke
parents:
diff changeset
147 this.getID().equals(other.getID());
a61af66fc99e Initial load
duke
parents:
diff changeset
148 }
a61af66fc99e Initial load
duke
parents:
diff changeset
149
a61af66fc99e Initial load
duke
parents:
diff changeset
150 public int hashCode() {
a61af66fc99e Initial load
duke
parents:
diff changeset
151 return getFieldHolder().hashCode() ^ getID().hashCode();
a61af66fc99e Initial load
duke
parents:
diff changeset
152 }
a61af66fc99e Initial load
duke
parents:
diff changeset
153 }