0
|
1 /*
|
|
2 * Copyright 2002-2003 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
20 * CA 95054 USA or visit www.sun.com if you need additional information or
|
|
21 * have any questions.
|
|
22 *
|
|
23 */
|
|
24
|
|
25 package sun.jvm.hotspot.jdi;
|
|
26
|
|
27 import com.sun.jdi.*;
|
|
28 import sun.jvm.hotspot.oops.Oop;
|
|
29 import sun.jvm.hotspot.oops.Instance;
|
|
30 import sun.jvm.hotspot.oops.Array;
|
|
31 import sun.jvm.hotspot.oops.InstanceKlass;
|
|
32 import sun.jvm.hotspot.oops.Symbol;
|
|
33 import sun.jvm.hotspot.oops.FieldIdentifier;
|
|
34
|
|
35 import java.util.List;
|
|
36 import java.util.Iterator;
|
|
37 import java.util.ArrayList;
|
|
38 import java.util.Comparator;
|
|
39
|
|
40 public class FieldImpl extends TypeComponentImpl implements Field {
|
|
41 private JNITypeParser signatureParser;
|
|
42 private sun.jvm.hotspot.oops.Field saField;
|
|
43
|
|
44 FieldImpl( VirtualMachine vm, ReferenceTypeImpl declaringType,
|
|
45 sun.jvm.hotspot.oops.Field saField) {
|
|
46 super(vm, declaringType);
|
|
47 this.saField = saField;
|
|
48 getParser();
|
|
49 }
|
|
50
|
|
51 private void getParser() {
|
|
52 if (signatureParser == null) {
|
|
53 Symbol sig1 = saField.getSignature();
|
|
54 signature = sig1.asString();
|
|
55 signatureParser = new JNITypeParser(signature);
|
|
56 }
|
|
57 }
|
|
58
|
|
59 sun.jvm.hotspot.oops.Field ref() {
|
|
60 return saField;
|
|
61 }
|
|
62
|
|
63 // get the value of static field
|
|
64 ValueImpl getValue() {
|
|
65 return getValue(saField.getFieldHolder());
|
|
66 }
|
|
67
|
|
68 // get the value of this Field from a specific Oop
|
|
69 ValueImpl getValue(Oop target) {
|
|
70 ValueImpl valueImpl;
|
|
71 sun.jvm.hotspot.oops.Field saField = (sun.jvm.hotspot.oops.Field) ref();
|
|
72 sun.jvm.hotspot.oops.FieldType ft = saField.getFieldType();
|
|
73 if (ft.isArray()) {
|
|
74 sun.jvm.hotspot.oops.OopField of = (sun.jvm.hotspot.oops.OopField)saField;
|
|
75 valueImpl = (ArrayReferenceImpl) vm.arrayMirror((Array)of.getValue(target));
|
|
76 } else if (ft.isObject()) {
|
|
77 sun.jvm.hotspot.oops.OopField of = (sun.jvm.hotspot.oops.OopField)saField;
|
|
78 valueImpl = (ObjectReferenceImpl) vm.objectMirror(of.getValue(target));
|
|
79 } else if (ft.isByte()) {
|
|
80 sun.jvm.hotspot.oops.ByteField bf = (sun.jvm.hotspot.oops.ByteField)saField;
|
|
81 valueImpl = (ByteValueImpl) vm.mirrorOf(bf.getValue(target));
|
|
82 } else if (ft.isChar()) {
|
|
83 sun.jvm.hotspot.oops.CharField cf = (sun.jvm.hotspot.oops.CharField)saField;
|
|
84 valueImpl = (CharValueImpl) vm.mirrorOf(cf.getValue(target));
|
|
85 } else if (ft.isDouble()) {
|
|
86 sun.jvm.hotspot.oops.DoubleField df = (sun.jvm.hotspot.oops.DoubleField)saField;
|
|
87 valueImpl = (DoubleValueImpl) vm.mirrorOf(df.getValue(target));
|
|
88 } else if (ft.isFloat()) {
|
|
89 sun.jvm.hotspot.oops.FloatField ff = (sun.jvm.hotspot.oops.FloatField)saField;
|
|
90 valueImpl = (FloatValueImpl) vm.mirrorOf(ff.getValue(target));
|
|
91 } else if (ft.isInt()) {
|
|
92 sun.jvm.hotspot.oops.IntField iif = (sun.jvm.hotspot.oops.IntField)saField;
|
|
93 valueImpl = (IntegerValueImpl) vm.mirrorOf(iif.getValue(target));
|
|
94 } else if (ft.isLong()) {
|
|
95 sun.jvm.hotspot.oops.LongField lf = (sun.jvm.hotspot.oops.LongField)saField;
|
|
96 valueImpl = (LongValueImpl) vm.mirrorOf(lf.getValue(target));
|
|
97 } else if (ft.isShort()) {
|
|
98 sun.jvm.hotspot.oops.ShortField sf = (sun.jvm.hotspot.oops.ShortField)saField;
|
|
99 valueImpl = (ShortValueImpl) vm.mirrorOf(sf.getValue(target));
|
|
100 } else if (ft.isBoolean()) {
|
|
101 sun.jvm.hotspot.oops.BooleanField bf = (sun.jvm.hotspot.oops.BooleanField)saField;
|
|
102 valueImpl = (BooleanValueImpl) vm.mirrorOf(bf.getValue(target));
|
|
103 } else {
|
|
104 throw new RuntimeException("Should not reach here");
|
|
105 }
|
|
106 return valueImpl;
|
|
107 }
|
|
108
|
|
109 public boolean equals(Object obj) {
|
|
110 if ((obj != null) && (obj instanceof FieldImpl)) {
|
|
111 FieldImpl other = (FieldImpl)obj;
|
|
112 return (declaringType().equals(other.declaringType())) &&
|
|
113 (ref().equals(other.ref())) &&
|
|
114 super.equals(obj);
|
|
115 } else {
|
|
116 return false;
|
|
117 }
|
|
118 }
|
|
119
|
|
120 public boolean isTransient() {
|
|
121 return saField.isTransient();
|
|
122 }
|
|
123
|
|
124 public boolean isVolatile() {
|
|
125 return saField.isVolatile();
|
|
126 }
|
|
127
|
|
128 public boolean isEnumConstant() {
|
|
129 return saField.isEnumConstant();
|
|
130 }
|
|
131
|
|
132 public Type type() throws ClassNotLoadedException {
|
|
133 // So, we do it just like JDI does by searching the enclosing type.
|
|
134 return findType(signature());
|
|
135 }
|
|
136
|
|
137 public String typeName() { //fixme jjh: jpda version creates redundant JNITypeParsers
|
|
138 getParser();
|
|
139 return signatureParser.typeName();
|
|
140 }
|
|
141
|
|
142 public String genericSignature() {
|
|
143 Symbol genSig = saField.getGenericSignature();
|
|
144 return (genSig != null)? genSig.asString() : null;
|
|
145 }
|
|
146
|
|
147 // From interface Comparable
|
|
148 public int compareTo(Object object) {
|
|
149 Field field = (Field)object;
|
|
150 ReferenceTypeImpl declaringType = (ReferenceTypeImpl)declaringType();
|
|
151 int rc = declaringType.compareTo(field.declaringType());
|
|
152 if (rc == 0) {
|
|
153 rc = declaringType.indexOf(this) -
|
|
154 declaringType.indexOf(field);
|
|
155 }
|
|
156 return rc;
|
|
157 }
|
|
158
|
|
159 // from interface Mirror
|
|
160 public String toString() {
|
|
161 StringBuffer buf = new StringBuffer();
|
|
162
|
|
163 buf.append(declaringType().name());
|
|
164 buf.append('.');
|
|
165 buf.append(name());
|
|
166 return buf.toString();
|
|
167 }
|
|
168
|
|
169 public String name() {
|
|
170 FieldIdentifier myName = saField.getID();
|
|
171 return myName.getName();
|
|
172 }
|
|
173
|
|
174 // From interface Accessible
|
|
175 public int modifiers() {
|
|
176 return saField.getAccessFlagsObj().getStandardFlags();
|
|
177 }
|
|
178
|
|
179 public boolean isPackagePrivate() {
|
|
180 return saField.isPackagePrivate();
|
|
181 }
|
|
182
|
|
183 public boolean isPrivate() {
|
|
184 return saField.isPrivate();
|
|
185 }
|
|
186
|
|
187 public boolean isProtected() {
|
|
188 return saField.isProtected();
|
|
189 }
|
|
190
|
|
191 public boolean isPublic() {
|
|
192 return saField.isPublic();
|
|
193 }
|
|
194
|
|
195 public boolean isStatic() {
|
|
196 return saField.isStatic();
|
|
197 }
|
|
198
|
|
199 public boolean isFinal() {
|
|
200 return saField.isFinal();
|
|
201 }
|
|
202
|
|
203 public boolean isSynthetic() {
|
|
204 return saField.isSynthetic();
|
|
205 }
|
|
206
|
|
207 public int hashCode() {
|
|
208 return saField.hashCode();
|
|
209 }
|
|
210
|
|
211
|
|
212 private Type findType(String signature) throws ClassNotLoadedException {
|
|
213 ReferenceTypeImpl enclosing = (ReferenceTypeImpl)declaringType();
|
|
214 return enclosing.findType(signature);
|
|
215 }
|
|
216
|
|
217 }
|