Mercurial > hg > truffle
annotate agent/src/share/classes/sun/jvm/hotspot/oops/Field.java @ 3938:e6b1331a51d2
7086585: make Java field injection more flexible
Reviewed-by: jrose, twisti, kvn, coleenp
author | never |
---|---|
date | Sat, 10 Sep 2011 17:29:02 -0700 |
parents | c18cbe5936b8 |
children | f6f3bb0ee072 |
rev | line source |
---|---|
0 | 1 /* |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
0
diff
changeset
|
2 * Copyright (c) 2000, 2003, Oracle and/or its affiliates. All rights reserved. |
0 | 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 * | |
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 | 22 * |
23 */ | |
24 | |
25 package sun.jvm.hotspot.oops; | |
26 | |
27 import java.io.*; | |
28 | |
29 import sun.jvm.hotspot.runtime.*; | |
30 | |
31 // Super class for all fields in an object | |
32 public class Field { | |
33 | |
34 Field(FieldIdentifier id, long offset, boolean isVMField) { | |
35 this.offset = offset; | |
36 this.id = id; | |
37 this.isVMField = isVMField; | |
38 } | |
39 | |
40 /** Constructor for fields that are named in an InstanceKlass's | |
41 fields array (i.e., named, non-VM fields) */ | |
3938 | 42 Field(InstanceKlass holder, int fieldIndex) { |
0 | 43 this.holder = holder; |
3938 | 44 this.fieldIndex = fieldIndex; |
45 | |
46 offset = holder.getFieldOffset(fieldIndex); | |
47 genericSignature = holder.getFieldGenericSignature(fieldIndex); | |
0 | 48 |
3938 | 49 Symbol name = holder.getFieldName(fieldIndex); |
0 | 50 id = new NamedFieldIdentifier(name.asString()); |
51 | |
3938 | 52 signature = holder.getFieldSignature(fieldIndex); |
0 | 53 fieldType = new FieldType(signature); |
3938 | 54 |
55 short access = holder.getFieldAccessFlags(fieldIndex); | |
0 | 56 accessFlags = new AccessFlags(access); |
57 } | |
58 | |
59 private long offset; | |
60 private FieldIdentifier id; | |
61 private boolean isVMField; | |
62 // Java fields only | |
63 private InstanceKlass holder; | |
64 private FieldType fieldType; | |
65 private Symbol signature; | |
66 private Symbol genericSignature; | |
67 private AccessFlags accessFlags; | |
3938 | 68 private int fieldIndex; |
0 | 69 |
70 /** Returns the byte offset of the field within the object or klass */ | |
71 public long getOffset() { return offset; } | |
72 | |
73 /** Returns the identifier of the field */ | |
74 public FieldIdentifier getID() { return id; } | |
75 | |
76 /** Indicates whether this is a VM field */ | |
77 public boolean isVMField() { return isVMField; } | |
78 | |
79 /** Indicates whether this is a named field */ | |
80 public boolean isNamedField() { return (id instanceof NamedFieldIdentifier); } | |
81 | |
82 public void printOn(PrintStream tty) { | |
83 getID().printOn(tty); | |
84 tty.print(" {" + getOffset() + "} :"); | |
85 } | |
86 | |
87 /** (Named, non-VM fields only) Returns the InstanceKlass containing | |
88 this (static or non-static) field. */ | |
89 public InstanceKlass getFieldHolder() { | |
90 return holder; | |
91 } | |
92 | |
93 /** (Named, non-VM fields only) Returns the index in the fields | |
94 TypeArray for this field. Equivalent to the "index" in the VM's | |
95 fieldDescriptors. */ | |
3938 | 96 public int getFieldIndex() { |
97 return fieldIndex; | |
0 | 98 } |
99 | |
100 /** (Named, non-VM fields only) Retrieves the access flags. */ | |
101 public long getAccessFlags() { return accessFlags.getValue(); } | |
102 public AccessFlags getAccessFlagsObj() { return accessFlags; } | |
103 | |
104 /** (Named, non-VM fields only) Returns the type of this field. */ | |
105 public FieldType getFieldType() { return fieldType; } | |
106 | |
107 /** (Named, non-VM fields only) Returns the signature of this | |
108 field. */ | |
109 public Symbol getSignature() { return signature; } | |
110 public Symbol getGenericSignature() { return genericSignature; } | |
111 | |
112 // | |
113 // Following acccessors are for named, non-VM fields only | |
114 // | |
115 public boolean isPublic() { return accessFlags.isPublic(); } | |
116 public boolean isPrivate() { return accessFlags.isPrivate(); } | |
117 public boolean isProtected() { return accessFlags.isProtected(); } | |
118 public boolean isPackagePrivate() { return !isPublic() && !isPrivate() && !isProtected(); } | |
119 | |
120 public boolean isStatic() { return accessFlags.isStatic(); } | |
121 public boolean isFinal() { return accessFlags.isFinal(); } | |
122 public boolean isVolatile() { return accessFlags.isVolatile(); } | |
123 public boolean isTransient() { return accessFlags.isTransient(); } | |
124 | |
125 public boolean isSynthetic() { return accessFlags.isSynthetic(); } | |
126 public boolean isEnumConstant() { return accessFlags.isEnum(); } | |
127 | |
128 public boolean equals(Object obj) { | |
129 if (obj == null) { | |
130 return false; | |
131 } | |
132 | |
133 if (! (obj instanceof Field)) { | |
134 return false; | |
135 } | |
136 | |
137 Field other = (Field) obj; | |
138 return this.getFieldHolder().equals(other.getFieldHolder()) && | |
139 this.getID().equals(other.getID()); | |
140 } | |
141 | |
142 public int hashCode() { | |
143 return getFieldHolder().hashCode() ^ getID().hashCode(); | |
144 } | |
145 } |