annotate agent/src/share/classes/sun/jvm/hotspot/jdi/FieldImpl.java @ 6725:da91efe96a93

6964458: Reimplement class meta-data storage to use native memory Summary: Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland Contributed-by: jmasa <jon.masamitsu@oracle.com>, stefank <stefan.karlsson@oracle.com>, mgerdin <mikael.gerdin@oracle.com>, never <tom.rodriguez@oracle.com>
author coleenp
date Sat, 01 Sep 2012 13:25:18 -0400
parents 37be97a58393
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
2376
c7f3d0b4570f 7017732: move static fields into Class to prepare for perm gen removal
never
parents: 1552
diff changeset
2 * Copyright (c) 2002, 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.jdi;
a61af66fc99e Initial load
duke
parents:
diff changeset
26
a61af66fc99e Initial load
duke
parents:
diff changeset
27 import com.sun.jdi.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
28 import sun.jvm.hotspot.oops.Oop;
a61af66fc99e Initial load
duke
parents:
diff changeset
29 import sun.jvm.hotspot.oops.Instance;
a61af66fc99e Initial load
duke
parents:
diff changeset
30 import sun.jvm.hotspot.oops.Array;
a61af66fc99e Initial load
duke
parents:
diff changeset
31 import sun.jvm.hotspot.oops.InstanceKlass;
a61af66fc99e Initial load
duke
parents:
diff changeset
32 import sun.jvm.hotspot.oops.Symbol;
a61af66fc99e Initial load
duke
parents:
diff changeset
33 import sun.jvm.hotspot.oops.FieldIdentifier;
a61af66fc99e Initial load
duke
parents:
diff changeset
34
a61af66fc99e Initial load
duke
parents:
diff changeset
35 import java.util.List;
a61af66fc99e Initial load
duke
parents:
diff changeset
36 import java.util.Iterator;
a61af66fc99e Initial load
duke
parents:
diff changeset
37 import java.util.ArrayList;
a61af66fc99e Initial load
duke
parents:
diff changeset
38 import java.util.Comparator;
a61af66fc99e Initial load
duke
parents:
diff changeset
39
a61af66fc99e Initial load
duke
parents:
diff changeset
40 public class FieldImpl extends TypeComponentImpl implements Field {
a61af66fc99e Initial load
duke
parents:
diff changeset
41 private JNITypeParser signatureParser;
a61af66fc99e Initial load
duke
parents:
diff changeset
42 private sun.jvm.hotspot.oops.Field saField;
a61af66fc99e Initial load
duke
parents:
diff changeset
43
a61af66fc99e Initial load
duke
parents:
diff changeset
44 FieldImpl( VirtualMachine vm, ReferenceTypeImpl declaringType,
a61af66fc99e Initial load
duke
parents:
diff changeset
45 sun.jvm.hotspot.oops.Field saField) {
a61af66fc99e Initial load
duke
parents:
diff changeset
46 super(vm, declaringType);
a61af66fc99e Initial load
duke
parents:
diff changeset
47 this.saField = saField;
a61af66fc99e Initial load
duke
parents:
diff changeset
48 getParser();
a61af66fc99e Initial load
duke
parents:
diff changeset
49 }
a61af66fc99e Initial load
duke
parents:
diff changeset
50
a61af66fc99e Initial load
duke
parents:
diff changeset
51 private void getParser() {
a61af66fc99e Initial load
duke
parents:
diff changeset
52 if (signatureParser == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
53 Symbol sig1 = saField.getSignature();
a61af66fc99e Initial load
duke
parents:
diff changeset
54 signature = sig1.asString();
a61af66fc99e Initial load
duke
parents:
diff changeset
55 signatureParser = new JNITypeParser(signature);
a61af66fc99e Initial load
duke
parents:
diff changeset
56 }
a61af66fc99e Initial load
duke
parents:
diff changeset
57 }
a61af66fc99e Initial load
duke
parents:
diff changeset
58
a61af66fc99e Initial load
duke
parents:
diff changeset
59 sun.jvm.hotspot.oops.Field ref() {
a61af66fc99e Initial load
duke
parents:
diff changeset
60 return saField;
a61af66fc99e Initial load
duke
parents:
diff changeset
61 }
a61af66fc99e Initial load
duke
parents:
diff changeset
62
a61af66fc99e Initial load
duke
parents:
diff changeset
63 // get the value of static field
a61af66fc99e Initial load
duke
parents:
diff changeset
64 ValueImpl getValue() {
2376
c7f3d0b4570f 7017732: move static fields into Class to prepare for perm gen removal
never
parents: 1552
diff changeset
65 return getValue(saField.getFieldHolder().getJavaMirror());
0
a61af66fc99e Initial load
duke
parents:
diff changeset
66 }
a61af66fc99e Initial load
duke
parents:
diff changeset
67
a61af66fc99e Initial load
duke
parents:
diff changeset
68 // get the value of this Field from a specific Oop
a61af66fc99e Initial load
duke
parents:
diff changeset
69 ValueImpl getValue(Oop target) {
a61af66fc99e Initial load
duke
parents:
diff changeset
70 ValueImpl valueImpl;
a61af66fc99e Initial load
duke
parents:
diff changeset
71 sun.jvm.hotspot.oops.Field saField = (sun.jvm.hotspot.oops.Field) ref();
a61af66fc99e Initial load
duke
parents:
diff changeset
72 sun.jvm.hotspot.oops.FieldType ft = saField.getFieldType();
a61af66fc99e Initial load
duke
parents:
diff changeset
73 if (ft.isArray()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
74 sun.jvm.hotspot.oops.OopField of = (sun.jvm.hotspot.oops.OopField)saField;
a61af66fc99e Initial load
duke
parents:
diff changeset
75 valueImpl = (ArrayReferenceImpl) vm.arrayMirror((Array)of.getValue(target));
a61af66fc99e Initial load
duke
parents:
diff changeset
76 } else if (ft.isObject()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
77 sun.jvm.hotspot.oops.OopField of = (sun.jvm.hotspot.oops.OopField)saField;
a61af66fc99e Initial load
duke
parents:
diff changeset
78 valueImpl = (ObjectReferenceImpl) vm.objectMirror(of.getValue(target));
a61af66fc99e Initial load
duke
parents:
diff changeset
79 } else if (ft.isByte()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
80 sun.jvm.hotspot.oops.ByteField bf = (sun.jvm.hotspot.oops.ByteField)saField;
a61af66fc99e Initial load
duke
parents:
diff changeset
81 valueImpl = (ByteValueImpl) vm.mirrorOf(bf.getValue(target));
a61af66fc99e Initial load
duke
parents:
diff changeset
82 } else if (ft.isChar()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
83 sun.jvm.hotspot.oops.CharField cf = (sun.jvm.hotspot.oops.CharField)saField;
a61af66fc99e Initial load
duke
parents:
diff changeset
84 valueImpl = (CharValueImpl) vm.mirrorOf(cf.getValue(target));
a61af66fc99e Initial load
duke
parents:
diff changeset
85 } else if (ft.isDouble()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
86 sun.jvm.hotspot.oops.DoubleField df = (sun.jvm.hotspot.oops.DoubleField)saField;
a61af66fc99e Initial load
duke
parents:
diff changeset
87 valueImpl = (DoubleValueImpl) vm.mirrorOf(df.getValue(target));
a61af66fc99e Initial load
duke
parents:
diff changeset
88 } else if (ft.isFloat()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
89 sun.jvm.hotspot.oops.FloatField ff = (sun.jvm.hotspot.oops.FloatField)saField;
a61af66fc99e Initial load
duke
parents:
diff changeset
90 valueImpl = (FloatValueImpl) vm.mirrorOf(ff.getValue(target));
a61af66fc99e Initial load
duke
parents:
diff changeset
91 } else if (ft.isInt()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
92 sun.jvm.hotspot.oops.IntField iif = (sun.jvm.hotspot.oops.IntField)saField;
a61af66fc99e Initial load
duke
parents:
diff changeset
93 valueImpl = (IntegerValueImpl) vm.mirrorOf(iif.getValue(target));
a61af66fc99e Initial load
duke
parents:
diff changeset
94 } else if (ft.isLong()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
95 sun.jvm.hotspot.oops.LongField lf = (sun.jvm.hotspot.oops.LongField)saField;
a61af66fc99e Initial load
duke
parents:
diff changeset
96 valueImpl = (LongValueImpl) vm.mirrorOf(lf.getValue(target));
a61af66fc99e Initial load
duke
parents:
diff changeset
97 } else if (ft.isShort()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
98 sun.jvm.hotspot.oops.ShortField sf = (sun.jvm.hotspot.oops.ShortField)saField;
a61af66fc99e Initial load
duke
parents:
diff changeset
99 valueImpl = (ShortValueImpl) vm.mirrorOf(sf.getValue(target));
a61af66fc99e Initial load
duke
parents:
diff changeset
100 } else if (ft.isBoolean()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
101 sun.jvm.hotspot.oops.BooleanField bf = (sun.jvm.hotspot.oops.BooleanField)saField;
a61af66fc99e Initial load
duke
parents:
diff changeset
102 valueImpl = (BooleanValueImpl) vm.mirrorOf(bf.getValue(target));
a61af66fc99e Initial load
duke
parents:
diff changeset
103 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
104 throw new RuntimeException("Should not reach here");
a61af66fc99e Initial load
duke
parents:
diff changeset
105 }
a61af66fc99e Initial load
duke
parents:
diff changeset
106 return valueImpl;
a61af66fc99e Initial load
duke
parents:
diff changeset
107 }
a61af66fc99e Initial load
duke
parents:
diff changeset
108
a61af66fc99e Initial load
duke
parents:
diff changeset
109 public boolean equals(Object obj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
110 if ((obj != null) && (obj instanceof FieldImpl)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
111 FieldImpl other = (FieldImpl)obj;
a61af66fc99e Initial load
duke
parents:
diff changeset
112 return (declaringType().equals(other.declaringType())) &&
a61af66fc99e Initial load
duke
parents:
diff changeset
113 (ref().equals(other.ref())) &&
a61af66fc99e Initial load
duke
parents:
diff changeset
114 super.equals(obj);
a61af66fc99e Initial load
duke
parents:
diff changeset
115 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
116 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
117 }
a61af66fc99e Initial load
duke
parents:
diff changeset
118 }
a61af66fc99e Initial load
duke
parents:
diff changeset
119
a61af66fc99e Initial load
duke
parents:
diff changeset
120 public boolean isTransient() {
a61af66fc99e Initial load
duke
parents:
diff changeset
121 return saField.isTransient();
a61af66fc99e Initial load
duke
parents:
diff changeset
122 }
a61af66fc99e Initial load
duke
parents:
diff changeset
123
a61af66fc99e Initial load
duke
parents:
diff changeset
124 public boolean isVolatile() {
a61af66fc99e Initial load
duke
parents:
diff changeset
125 return saField.isVolatile();
a61af66fc99e Initial load
duke
parents:
diff changeset
126 }
a61af66fc99e Initial load
duke
parents:
diff changeset
127
a61af66fc99e Initial load
duke
parents:
diff changeset
128 public boolean isEnumConstant() {
a61af66fc99e Initial load
duke
parents:
diff changeset
129 return saField.isEnumConstant();
a61af66fc99e Initial load
duke
parents:
diff changeset
130 }
a61af66fc99e Initial load
duke
parents:
diff changeset
131
a61af66fc99e Initial load
duke
parents:
diff changeset
132 public Type type() throws ClassNotLoadedException {
a61af66fc99e Initial load
duke
parents:
diff changeset
133 // So, we do it just like JDI does by searching the enclosing type.
a61af66fc99e Initial load
duke
parents:
diff changeset
134 return findType(signature());
a61af66fc99e Initial load
duke
parents:
diff changeset
135 }
a61af66fc99e Initial load
duke
parents:
diff changeset
136
a61af66fc99e Initial load
duke
parents:
diff changeset
137 public String typeName() { //fixme jjh: jpda version creates redundant JNITypeParsers
a61af66fc99e Initial load
duke
parents:
diff changeset
138 getParser();
a61af66fc99e Initial load
duke
parents:
diff changeset
139 return signatureParser.typeName();
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 String genericSignature() {
a61af66fc99e Initial load
duke
parents:
diff changeset
143 Symbol genSig = saField.getGenericSignature();
a61af66fc99e Initial load
duke
parents:
diff changeset
144 return (genSig != null)? genSig.asString() : null;
a61af66fc99e Initial load
duke
parents:
diff changeset
145 }
a61af66fc99e Initial load
duke
parents:
diff changeset
146
a61af66fc99e Initial load
duke
parents:
diff changeset
147 // From interface Comparable
2471
37be97a58393 7010849: 5/5 Extraneous javac source/target options when building sa-jdi
andrew
parents: 2376
diff changeset
148 public int compareTo(Field field) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
149 ReferenceTypeImpl declaringType = (ReferenceTypeImpl)declaringType();
a61af66fc99e Initial load
duke
parents:
diff changeset
150 int rc = declaringType.compareTo(field.declaringType());
a61af66fc99e Initial load
duke
parents:
diff changeset
151 if (rc == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
152 rc = declaringType.indexOf(this) -
a61af66fc99e Initial load
duke
parents:
diff changeset
153 declaringType.indexOf(field);
a61af66fc99e Initial load
duke
parents:
diff changeset
154 }
a61af66fc99e Initial load
duke
parents:
diff changeset
155 return rc;
a61af66fc99e Initial load
duke
parents:
diff changeset
156 }
a61af66fc99e Initial load
duke
parents:
diff changeset
157
a61af66fc99e Initial load
duke
parents:
diff changeset
158 // from interface Mirror
a61af66fc99e Initial load
duke
parents:
diff changeset
159 public String toString() {
a61af66fc99e Initial load
duke
parents:
diff changeset
160 StringBuffer buf = new StringBuffer();
a61af66fc99e Initial load
duke
parents:
diff changeset
161
a61af66fc99e Initial load
duke
parents:
diff changeset
162 buf.append(declaringType().name());
a61af66fc99e Initial load
duke
parents:
diff changeset
163 buf.append('.');
a61af66fc99e Initial load
duke
parents:
diff changeset
164 buf.append(name());
a61af66fc99e Initial load
duke
parents:
diff changeset
165 return buf.toString();
a61af66fc99e Initial load
duke
parents:
diff changeset
166 }
a61af66fc99e Initial load
duke
parents:
diff changeset
167
a61af66fc99e Initial load
duke
parents:
diff changeset
168 public String name() {
a61af66fc99e Initial load
duke
parents:
diff changeset
169 FieldIdentifier myName = saField.getID();
a61af66fc99e Initial load
duke
parents:
diff changeset
170 return myName.getName();
a61af66fc99e Initial load
duke
parents:
diff changeset
171 }
a61af66fc99e Initial load
duke
parents:
diff changeset
172
a61af66fc99e Initial load
duke
parents:
diff changeset
173 // From interface Accessible
a61af66fc99e Initial load
duke
parents:
diff changeset
174 public int modifiers() {
a61af66fc99e Initial load
duke
parents:
diff changeset
175 return saField.getAccessFlagsObj().getStandardFlags();
a61af66fc99e Initial load
duke
parents:
diff changeset
176 }
a61af66fc99e Initial load
duke
parents:
diff changeset
177
a61af66fc99e Initial load
duke
parents:
diff changeset
178 public boolean isPackagePrivate() {
a61af66fc99e Initial load
duke
parents:
diff changeset
179 return saField.isPackagePrivate();
a61af66fc99e Initial load
duke
parents:
diff changeset
180 }
a61af66fc99e Initial load
duke
parents:
diff changeset
181
a61af66fc99e Initial load
duke
parents:
diff changeset
182 public boolean isPrivate() {
a61af66fc99e Initial load
duke
parents:
diff changeset
183 return saField.isPrivate();
a61af66fc99e Initial load
duke
parents:
diff changeset
184 }
a61af66fc99e Initial load
duke
parents:
diff changeset
185
a61af66fc99e Initial load
duke
parents:
diff changeset
186 public boolean isProtected() {
a61af66fc99e Initial load
duke
parents:
diff changeset
187 return saField.isProtected();
a61af66fc99e Initial load
duke
parents:
diff changeset
188 }
a61af66fc99e Initial load
duke
parents:
diff changeset
189
a61af66fc99e Initial load
duke
parents:
diff changeset
190 public boolean isPublic() {
a61af66fc99e Initial load
duke
parents:
diff changeset
191 return saField.isPublic();
a61af66fc99e Initial load
duke
parents:
diff changeset
192 }
a61af66fc99e Initial load
duke
parents:
diff changeset
193
a61af66fc99e Initial load
duke
parents:
diff changeset
194 public boolean isStatic() {
a61af66fc99e Initial load
duke
parents:
diff changeset
195 return saField.isStatic();
a61af66fc99e Initial load
duke
parents:
diff changeset
196 }
a61af66fc99e Initial load
duke
parents:
diff changeset
197
a61af66fc99e Initial load
duke
parents:
diff changeset
198 public boolean isFinal() {
a61af66fc99e Initial load
duke
parents:
diff changeset
199 return saField.isFinal();
a61af66fc99e Initial load
duke
parents:
diff changeset
200 }
a61af66fc99e Initial load
duke
parents:
diff changeset
201
a61af66fc99e Initial load
duke
parents:
diff changeset
202 public boolean isSynthetic() {
a61af66fc99e Initial load
duke
parents:
diff changeset
203 return saField.isSynthetic();
a61af66fc99e Initial load
duke
parents:
diff changeset
204 }
a61af66fc99e Initial load
duke
parents:
diff changeset
205
a61af66fc99e Initial load
duke
parents:
diff changeset
206 public int hashCode() {
a61af66fc99e Initial load
duke
parents:
diff changeset
207 return saField.hashCode();
a61af66fc99e Initial load
duke
parents:
diff changeset
208 }
a61af66fc99e Initial load
duke
parents:
diff changeset
209
a61af66fc99e Initial load
duke
parents:
diff changeset
210
a61af66fc99e Initial load
duke
parents:
diff changeset
211 private Type findType(String signature) throws ClassNotLoadedException {
a61af66fc99e Initial load
duke
parents:
diff changeset
212 ReferenceTypeImpl enclosing = (ReferenceTypeImpl)declaringType();
a61af66fc99e Initial load
duke
parents:
diff changeset
213 return enclosing.findType(signature);
a61af66fc99e Initial load
duke
parents:
diff changeset
214 }
a61af66fc99e Initial load
duke
parents:
diff changeset
215
a61af66fc99e Initial load
duke
parents:
diff changeset
216 }