annotate agent/src/share/classes/sun/jvm/hotspot/utilities/soql/JSJavaInstanceKlass.java @ 17467:55fb97c4c58d hs25-b65

8029233: Update copyright year to match last edit in jdk8 hotspot repository for 2013 Summary: Copyright year updated for files modified during 2013 Reviewed-by: twisti, iveresov
author mikael
date Tue, 24 Dec 2013 11:48:39 -0800
parents 6bd680e9ea35
children 4ca6dc0799b6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
17467
55fb97c4c58d 8029233: Update copyright year to match last edit in jdk8 hotspot repository for 2013
mikael
parents: 10343
diff changeset
2 * Copyright (c) 2003, 2013, 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.utilities.soql;
a61af66fc99e Initial load
duke
parents:
diff changeset
26
a61af66fc99e Initial load
duke
parents:
diff changeset
27 import java.util.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
28 import sun.jvm.hotspot.oops.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
29 import sun.jvm.hotspot.utilities.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
30
a61af66fc99e Initial load
duke
parents:
diff changeset
31 /**
a61af66fc99e Initial load
duke
parents:
diff changeset
32 This is JavaScript wrapper for InstanceKlass.
a61af66fc99e Initial load
duke
parents:
diff changeset
33 */
a61af66fc99e Initial load
duke
parents:
diff changeset
34 public class JSJavaInstanceKlass extends JSJavaKlass {
a61af66fc99e Initial load
duke
parents:
diff changeset
35 private static final int FIELD_SOURCE_FILE = 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
36 private static final int FIELD_INTERFACES = 2;
a61af66fc99e Initial load
duke
parents:
diff changeset
37 private static final int FIELD_FIELDS = 3;
a61af66fc99e Initial load
duke
parents:
diff changeset
38 private static final int FIELD_METHODS = 4;
a61af66fc99e Initial load
duke
parents:
diff changeset
39 private static final int FIELD_IS_PRIVATE = 5;
a61af66fc99e Initial load
duke
parents:
diff changeset
40 private static final int FIELD_IS_PUBLIC = 6;
a61af66fc99e Initial load
duke
parents:
diff changeset
41 private static final int FIELD_IS_PROTECTED = 7;
a61af66fc99e Initial load
duke
parents:
diff changeset
42 private static final int FIELD_IS_PACKAGE_PRIVATE = 8;
a61af66fc99e Initial load
duke
parents:
diff changeset
43 private static final int FIELD_IS_STATIC = 9;
a61af66fc99e Initial load
duke
parents:
diff changeset
44 private static final int FIELD_IS_FINAL = 10;
a61af66fc99e Initial load
duke
parents:
diff changeset
45 private static final int FIELD_IS_ABSTRACT = 11;
a61af66fc99e Initial load
duke
parents:
diff changeset
46 private static final int FIELD_IS_STRICT = 12;
a61af66fc99e Initial load
duke
parents:
diff changeset
47 private static final int FIELD_IS_SYNTHETIC = 13;
a61af66fc99e Initial load
duke
parents:
diff changeset
48 private static final int FIELD_IS_INTERFACE = 14;
a61af66fc99e Initial load
duke
parents:
diff changeset
49 private static final int FIELD_CLASS_LOADER = 15;
a61af66fc99e Initial load
duke
parents:
diff changeset
50 private static final int FIELD_STATICS = 18;
a61af66fc99e Initial load
duke
parents:
diff changeset
51 private static final int FIELD_UNDEFINED = -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
52
a61af66fc99e Initial load
duke
parents:
diff changeset
53 public JSJavaInstanceKlass(InstanceKlass kls, JSJavaFactory fac) {
a61af66fc99e Initial load
duke
parents:
diff changeset
54 super(kls, fac);
a61af66fc99e Initial load
duke
parents:
diff changeset
55 this.instanceFields = new HashMap();
a61af66fc99e Initial load
duke
parents:
diff changeset
56 this.staticFields = new HashMap();
a61af66fc99e Initial load
duke
parents:
diff changeset
57 }
a61af66fc99e Initial load
duke
parents:
diff changeset
58
a61af66fc99e Initial load
duke
parents:
diff changeset
59 public final InstanceKlass getInstanceKlass() {
a61af66fc99e Initial load
duke
parents:
diff changeset
60 return (InstanceKlass) getKlass();
a61af66fc99e Initial load
duke
parents:
diff changeset
61 }
a61af66fc99e Initial load
duke
parents:
diff changeset
62
a61af66fc99e Initial load
duke
parents:
diff changeset
63 public Object getMetaClassFieldValue(String name) {
a61af66fc99e Initial load
duke
parents:
diff changeset
64 int fieldID = getFieldID(name);
a61af66fc99e Initial load
duke
parents:
diff changeset
65 InstanceKlass ik = getInstanceKlass();
a61af66fc99e Initial load
duke
parents:
diff changeset
66 switch (fieldID) {
a61af66fc99e Initial load
duke
parents:
diff changeset
67 case FIELD_SOURCE_FILE: {
a61af66fc99e Initial load
duke
parents:
diff changeset
68 Symbol sourceFile = ik.getSourceFileName();
a61af66fc99e Initial load
duke
parents:
diff changeset
69 return (sourceFile != null)? sourceFile.asString() : "<unknown>";
a61af66fc99e Initial load
duke
parents:
diff changeset
70 }
a61af66fc99e Initial load
duke
parents:
diff changeset
71 case FIELD_INTERFACES:
a61af66fc99e Initial load
duke
parents:
diff changeset
72 return getInterfaces();
a61af66fc99e Initial load
duke
parents:
diff changeset
73 case FIELD_FIELDS:
a61af66fc99e Initial load
duke
parents:
diff changeset
74 return factory.newJSList(ik.getImmediateFields());
a61af66fc99e Initial load
duke
parents:
diff changeset
75 case FIELD_METHODS:
a61af66fc99e Initial load
duke
parents:
diff changeset
76 return factory.newJSList(ik.getImmediateMethods());
a61af66fc99e Initial load
duke
parents:
diff changeset
77 case FIELD_IS_PRIVATE:
a61af66fc99e Initial load
duke
parents:
diff changeset
78 return Boolean.valueOf(getAccessFlags().isPrivate());
a61af66fc99e Initial load
duke
parents:
diff changeset
79 case FIELD_IS_PUBLIC:
a61af66fc99e Initial load
duke
parents:
diff changeset
80 return Boolean.valueOf(getAccessFlags().isPublic());
a61af66fc99e Initial load
duke
parents:
diff changeset
81 case FIELD_IS_PROTECTED:
a61af66fc99e Initial load
duke
parents:
diff changeset
82 return Boolean.valueOf(getAccessFlags().isProtected());
a61af66fc99e Initial load
duke
parents:
diff changeset
83 case FIELD_IS_PACKAGE_PRIVATE: {
a61af66fc99e Initial load
duke
parents:
diff changeset
84 AccessFlags acc = getAccessFlags();
a61af66fc99e Initial load
duke
parents:
diff changeset
85 return Boolean.valueOf(!acc.isPrivate() && !acc.isPublic() && !acc.isProtected());
a61af66fc99e Initial load
duke
parents:
diff changeset
86 }
a61af66fc99e Initial load
duke
parents:
diff changeset
87 case FIELD_IS_STATIC:
a61af66fc99e Initial load
duke
parents:
diff changeset
88 return Boolean.valueOf(getAccessFlags().isStatic());
a61af66fc99e Initial load
duke
parents:
diff changeset
89 case FIELD_IS_FINAL:
a61af66fc99e Initial load
duke
parents:
diff changeset
90 return Boolean.valueOf(getAccessFlags().isFinal());
a61af66fc99e Initial load
duke
parents:
diff changeset
91 case FIELD_IS_ABSTRACT:
a61af66fc99e Initial load
duke
parents:
diff changeset
92 return Boolean.valueOf(getAccessFlags().isAbstract());
a61af66fc99e Initial load
duke
parents:
diff changeset
93 case FIELD_IS_STRICT:
a61af66fc99e Initial load
duke
parents:
diff changeset
94 return Boolean.valueOf(getAccessFlags().isStrict());
a61af66fc99e Initial load
duke
parents:
diff changeset
95 case FIELD_IS_SYNTHETIC:
a61af66fc99e Initial load
duke
parents:
diff changeset
96 return Boolean.valueOf(getAccessFlags().isSynthetic());
a61af66fc99e Initial load
duke
parents:
diff changeset
97 case FIELD_IS_INTERFACE:
a61af66fc99e Initial load
duke
parents:
diff changeset
98 return Boolean.valueOf(ik.isInterface());
a61af66fc99e Initial load
duke
parents:
diff changeset
99 case FIELD_CLASS_LOADER:
a61af66fc99e Initial load
duke
parents:
diff changeset
100 return factory.newJSJavaObject(ik.getClassLoader());
a61af66fc99e Initial load
duke
parents:
diff changeset
101 case FIELD_STATICS:
a61af66fc99e Initial load
duke
parents:
diff changeset
102 return getStatics();
a61af66fc99e Initial load
duke
parents:
diff changeset
103 case FIELD_UNDEFINED:
a61af66fc99e Initial load
duke
parents:
diff changeset
104 default:
a61af66fc99e Initial load
duke
parents:
diff changeset
105 return super.getMetaClassFieldValue(name);
a61af66fc99e Initial load
duke
parents:
diff changeset
106 }
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 hasMetaClassField(String name) {
a61af66fc99e Initial load
duke
parents:
diff changeset
110 if (getFieldID(name) != FIELD_UNDEFINED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
111 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
112 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
113 return super.hasMetaClassField(name);
a61af66fc99e Initial load
duke
parents:
diff changeset
114 }
a61af66fc99e Initial load
duke
parents:
diff changeset
115 }
a61af66fc99e Initial load
duke
parents:
diff changeset
116
a61af66fc99e Initial load
duke
parents:
diff changeset
117 public String getName() {
a61af66fc99e Initial load
duke
parents:
diff changeset
118 return getInstanceKlass().getName().asString().replace('/', '.');
a61af66fc99e Initial load
duke
parents:
diff changeset
119 }
a61af66fc99e Initial load
duke
parents:
diff changeset
120
a61af66fc99e Initial load
duke
parents:
diff changeset
121 public boolean isArray() {
a61af66fc99e Initial load
duke
parents:
diff changeset
122 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
123 }
a61af66fc99e Initial load
duke
parents:
diff changeset
124
a61af66fc99e Initial load
duke
parents:
diff changeset
125 public String[] getMetaClassFieldNames() {
a61af66fc99e Initial load
duke
parents:
diff changeset
126 String[] superFields = super.getMetaClassFieldNames();
a61af66fc99e Initial load
duke
parents:
diff changeset
127 Set k = fields.keySet();
a61af66fc99e Initial load
duke
parents:
diff changeset
128 String[] res = new String[k.size() + superFields.length];
a61af66fc99e Initial load
duke
parents:
diff changeset
129 System.arraycopy(superFields, 0, res, 0, superFields.length);
a61af66fc99e Initial load
duke
parents:
diff changeset
130 int i = superFields.length;
a61af66fc99e Initial load
duke
parents:
diff changeset
131 for (Iterator itr = k.iterator(); itr.hasNext();) {
a61af66fc99e Initial load
duke
parents:
diff changeset
132 res[i] = (String) itr.next();
a61af66fc99e Initial load
duke
parents:
diff changeset
133 i++;
a61af66fc99e Initial load
duke
parents:
diff changeset
134 }
a61af66fc99e Initial load
duke
parents:
diff changeset
135 return res;
a61af66fc99e Initial load
duke
parents:
diff changeset
136 }
a61af66fc99e Initial load
duke
parents:
diff changeset
137
a61af66fc99e Initial load
duke
parents:
diff changeset
138 public Object getInstanceFieldValue(String name, Instance instance) throws NoSuchFieldException {
a61af66fc99e Initial load
duke
parents:
diff changeset
139 Field fld = findInstanceField(name);
a61af66fc99e Initial load
duke
parents:
diff changeset
140 if (fld != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
141 return getFieldValue(fld, name, instance);
a61af66fc99e Initial load
duke
parents:
diff changeset
142 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
143 throw new NoSuchFieldException(name + " is not field of "
a61af66fc99e Initial load
duke
parents:
diff changeset
144 + getInstanceKlass().getName().asString().replace('/', '.'));
a61af66fc99e Initial load
duke
parents:
diff changeset
145 }
a61af66fc99e Initial load
duke
parents:
diff changeset
146 }
a61af66fc99e Initial load
duke
parents:
diff changeset
147
a61af66fc99e Initial load
duke
parents:
diff changeset
148 public Object getStaticFieldValue(String name) throws NoSuchFieldException {
a61af66fc99e Initial load
duke
parents:
diff changeset
149 Field fld = findStaticField(name);
a61af66fc99e Initial load
duke
parents:
diff changeset
150 if (fld != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
151 return getFieldValue(fld, name, getInstanceKlass());
a61af66fc99e Initial load
duke
parents:
diff changeset
152 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
153 throw new NoSuchFieldException(name + " is not field of "
a61af66fc99e Initial load
duke
parents:
diff changeset
154 + getInstanceKlass().getName().asString().replace('/', '.'));
a61af66fc99e Initial load
duke
parents:
diff changeset
155 }
a61af66fc99e Initial load
duke
parents:
diff changeset
156 }
a61af66fc99e Initial load
duke
parents:
diff changeset
157
a61af66fc99e Initial load
duke
parents:
diff changeset
158 public String[] getInstanceFieldNames() {
a61af66fc99e Initial load
duke
parents:
diff changeset
159 if (instanceFieldNames == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
160 InstanceKlass current = getInstanceKlass();
a61af66fc99e Initial load
duke
parents:
diff changeset
161 while (current != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
162 List tmp = current.getImmediateFields();
a61af66fc99e Initial load
duke
parents:
diff changeset
163 for (Iterator itr = tmp.iterator(); itr.hasNext();) {
a61af66fc99e Initial load
duke
parents:
diff changeset
164 Field fld = (Field) itr.next();
a61af66fc99e Initial load
duke
parents:
diff changeset
165 if (!fld.isStatic()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
166 String name = fld.getID().getName();
a61af66fc99e Initial load
duke
parents:
diff changeset
167 if (instanceFields.get(name) == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
168 instanceFields.put(name, fld);
a61af66fc99e Initial load
duke
parents:
diff changeset
169 }
a61af66fc99e Initial load
duke
parents:
diff changeset
170 }
a61af66fc99e Initial load
duke
parents:
diff changeset
171 }
a61af66fc99e Initial load
duke
parents:
diff changeset
172 current = (InstanceKlass) current.getSuper();
a61af66fc99e Initial load
duke
parents:
diff changeset
173 }
a61af66fc99e Initial load
duke
parents:
diff changeset
174
a61af66fc99e Initial load
duke
parents:
diff changeset
175 Set s = instanceFields.keySet();
a61af66fc99e Initial load
duke
parents:
diff changeset
176 instanceFieldNames = new String[s.size()];
a61af66fc99e Initial load
duke
parents:
diff changeset
177 int i = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
178 for (Iterator itr = s.iterator(); itr.hasNext(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
179 instanceFieldNames[i] = (String) itr.next();
a61af66fc99e Initial load
duke
parents:
diff changeset
180 }
a61af66fc99e Initial load
duke
parents:
diff changeset
181 }
a61af66fc99e Initial load
duke
parents:
diff changeset
182 return instanceFieldNames;
a61af66fc99e Initial load
duke
parents:
diff changeset
183 }
a61af66fc99e Initial load
duke
parents:
diff changeset
184
a61af66fc99e Initial load
duke
parents:
diff changeset
185 public boolean hasInstanceField(String name) {
a61af66fc99e Initial load
duke
parents:
diff changeset
186 Field fld = findInstanceField(name);
a61af66fc99e Initial load
duke
parents:
diff changeset
187 return (fld != null)? true: false;
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 String[] getStaticFieldNames() {
a61af66fc99e Initial load
duke
parents:
diff changeset
191 if (staticFieldNames == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
192 InstanceKlass current = getInstanceKlass();
a61af66fc99e Initial load
duke
parents:
diff changeset
193 List tmp = current.getImmediateFields();
a61af66fc99e Initial load
duke
parents:
diff changeset
194 for (Iterator itr = tmp.iterator(); itr.hasNext();) {
a61af66fc99e Initial load
duke
parents:
diff changeset
195 Field fld = (Field) itr.next();
a61af66fc99e Initial load
duke
parents:
diff changeset
196 if (fld.isStatic()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
197 staticFields.put(fld.getID().getName(), fld);
a61af66fc99e Initial load
duke
parents:
diff changeset
198 }
a61af66fc99e Initial load
duke
parents:
diff changeset
199 }
a61af66fc99e Initial load
duke
parents:
diff changeset
200
a61af66fc99e Initial load
duke
parents:
diff changeset
201 Set s = staticFields.keySet();
a61af66fc99e Initial load
duke
parents:
diff changeset
202 staticFieldNames = new String[s.size()];
a61af66fc99e Initial load
duke
parents:
diff changeset
203 int i = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
204 for (Iterator itr = s.iterator(); itr.hasNext(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
205 staticFieldNames[i] = (String) itr.next();
a61af66fc99e Initial load
duke
parents:
diff changeset
206 }
a61af66fc99e Initial load
duke
parents:
diff changeset
207 }
a61af66fc99e Initial load
duke
parents:
diff changeset
208 return staticFieldNames;
a61af66fc99e Initial load
duke
parents:
diff changeset
209 }
a61af66fc99e Initial load
duke
parents:
diff changeset
210
a61af66fc99e Initial load
duke
parents:
diff changeset
211 public boolean hasStaticField(String name) {
a61af66fc99e Initial load
duke
parents:
diff changeset
212 Field fld = findStaticField(name);
a61af66fc99e Initial load
duke
parents:
diff changeset
213 return (fld != null)? true: false;
a61af66fc99e Initial load
duke
parents:
diff changeset
214 }
a61af66fc99e Initial load
duke
parents:
diff changeset
215
a61af66fc99e Initial load
duke
parents:
diff changeset
216 //-- Intenals only below this point
a61af66fc99e Initial load
duke
parents:
diff changeset
217 private static Map fields = new HashMap();
a61af66fc99e Initial load
duke
parents:
diff changeset
218 private static void addField(String name, int fieldId) {
a61af66fc99e Initial load
duke
parents:
diff changeset
219 fields.put(name, new Integer(fieldId));
a61af66fc99e Initial load
duke
parents:
diff changeset
220 }
a61af66fc99e Initial load
duke
parents:
diff changeset
221
a61af66fc99e Initial load
duke
parents:
diff changeset
222 private static int getFieldID(String name) {
a61af66fc99e Initial load
duke
parents:
diff changeset
223 Integer res = (Integer) fields.get(name);
a61af66fc99e Initial load
duke
parents:
diff changeset
224 return (res != null)? res.intValue() : FIELD_UNDEFINED;
a61af66fc99e Initial load
duke
parents:
diff changeset
225 }
a61af66fc99e Initial load
duke
parents:
diff changeset
226
a61af66fc99e Initial load
duke
parents:
diff changeset
227 static {
a61af66fc99e Initial load
duke
parents:
diff changeset
228 addField("sourceFile", FIELD_SOURCE_FILE);
a61af66fc99e Initial load
duke
parents:
diff changeset
229 addField("interfaces", FIELD_INTERFACES);
a61af66fc99e Initial load
duke
parents:
diff changeset
230 addField("fields", FIELD_FIELDS);
a61af66fc99e Initial load
duke
parents:
diff changeset
231 addField("methods", FIELD_METHODS);
a61af66fc99e Initial load
duke
parents:
diff changeset
232 addField("isPrivate", FIELD_IS_PRIVATE);
a61af66fc99e Initial load
duke
parents:
diff changeset
233 addField("isPublic", FIELD_IS_PUBLIC);
a61af66fc99e Initial load
duke
parents:
diff changeset
234 addField("isProtected", FIELD_IS_PROTECTED);
a61af66fc99e Initial load
duke
parents:
diff changeset
235 addField("isPackagePrivate", FIELD_IS_PACKAGE_PRIVATE);
a61af66fc99e Initial load
duke
parents:
diff changeset
236 addField("isStatic", FIELD_IS_STATIC);
a61af66fc99e Initial load
duke
parents:
diff changeset
237 addField("isFinal", FIELD_IS_FINAL);
a61af66fc99e Initial load
duke
parents:
diff changeset
238 addField("isAbstract", FIELD_IS_ABSTRACT);
a61af66fc99e Initial load
duke
parents:
diff changeset
239 addField("isStrict", FIELD_IS_STRICT);
a61af66fc99e Initial load
duke
parents:
diff changeset
240 addField("isSynthetic", FIELD_IS_SYNTHETIC);
a61af66fc99e Initial load
duke
parents:
diff changeset
241 addField("isInterface", FIELD_IS_INTERFACE);
a61af66fc99e Initial load
duke
parents:
diff changeset
242 addField("classLoader", FIELD_CLASS_LOADER);
a61af66fc99e Initial load
duke
parents:
diff changeset
243 addField("statics", FIELD_STATICS);
a61af66fc99e Initial load
duke
parents:
diff changeset
244 }
a61af66fc99e Initial load
duke
parents:
diff changeset
245
a61af66fc99e Initial load
duke
parents:
diff changeset
246 private AccessFlags getAccessFlags() {
a61af66fc99e Initial load
duke
parents:
diff changeset
247 if (accFlags == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
248 accFlags = new AccessFlags(getInstanceKlass().computeModifierFlags());
a61af66fc99e Initial load
duke
parents:
diff changeset
249 }
a61af66fc99e Initial load
duke
parents:
diff changeset
250 return accFlags;
a61af66fc99e Initial load
duke
parents:
diff changeset
251 }
a61af66fc99e Initial load
duke
parents:
diff changeset
252
a61af66fc99e Initial load
duke
parents:
diff changeset
253 private Object getFieldValue(Field fld, String name, Oop oop) {
a61af66fc99e Initial load
duke
parents:
diff changeset
254 FieldType fd = fld.getFieldType();
a61af66fc99e Initial load
duke
parents:
diff changeset
255 if (fd.isObject() || fd.isArray()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
256 return factory.newJSJavaObject(((OopField)fld).getValue(oop));
a61af66fc99e Initial load
duke
parents:
diff changeset
257 } else if (fd.isByte()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
258 return new Byte(((ByteField)fld).getValue(oop));
a61af66fc99e Initial load
duke
parents:
diff changeset
259 } else if (fd.isChar()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
260 return new String(new char[] { ((CharField)fld).getValue(oop) });
a61af66fc99e Initial load
duke
parents:
diff changeset
261 } else if (fd.isDouble()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
262 return new Double(((DoubleField)fld).getValue(oop));
a61af66fc99e Initial load
duke
parents:
diff changeset
263 } else if (fd.isFloat()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
264 return new Float(((FloatField)fld).getValue(oop));
a61af66fc99e Initial load
duke
parents:
diff changeset
265 } else if (fd.isInt()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
266 return new Integer(((IntField)fld).getValue(oop));
a61af66fc99e Initial load
duke
parents:
diff changeset
267 } else if (fd.isLong()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
268 return new Long(((LongField)fld).getValue(oop));
a61af66fc99e Initial load
duke
parents:
diff changeset
269 } else if (fd.isShort()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
270 return new Short(((ShortField)fld).getValue(oop));
a61af66fc99e Initial load
duke
parents:
diff changeset
271 } else if (fd.isBoolean()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
272 return Boolean.valueOf(((BooleanField)fld).getValue(oop));
a61af66fc99e Initial load
duke
parents:
diff changeset
273 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
274 if (Assert.ASSERTS_ENABLED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
275 Assert.that(false, "invalid field type for " + name);
a61af66fc99e Initial load
duke
parents:
diff changeset
276 }
a61af66fc99e Initial load
duke
parents:
diff changeset
277 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
278 }
a61af66fc99e Initial load
duke
parents:
diff changeset
279 }
a61af66fc99e Initial load
duke
parents:
diff changeset
280
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 1552
diff changeset
281 private Object getFieldValue(Field fld, String name, InstanceKlass oop) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 1552
diff changeset
282 FieldType fd = fld.getFieldType();
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 1552
diff changeset
283 if (fd.isObject() || fd.isArray()) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 1552
diff changeset
284 return factory.newJSJavaObject(((OopField)fld).getValue(oop));
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 1552
diff changeset
285 } else if (fd.isByte()) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 1552
diff changeset
286 return new Byte(((ByteField)fld).getValue(oop));
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 1552
diff changeset
287 } else if (fd.isChar()) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 1552
diff changeset
288 return new String(new char[] { ((CharField)fld).getValue(oop) });
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 1552
diff changeset
289 } else if (fd.isDouble()) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 1552
diff changeset
290 return new Double(((DoubleField)fld).getValue(oop));
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 1552
diff changeset
291 } else if (fd.isFloat()) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 1552
diff changeset
292 return new Float(((FloatField)fld).getValue(oop));
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 1552
diff changeset
293 } else if (fd.isInt()) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 1552
diff changeset
294 return new Integer(((IntField)fld).getValue(oop));
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 1552
diff changeset
295 } else if (fd.isLong()) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 1552
diff changeset
296 return new Long(((LongField)fld).getValue(oop));
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 1552
diff changeset
297 } else if (fd.isShort()) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 1552
diff changeset
298 return new Short(((ShortField)fld).getValue(oop));
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 1552
diff changeset
299 } else if (fd.isBoolean()) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 1552
diff changeset
300 return Boolean.valueOf(((BooleanField)fld).getValue(oop));
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 1552
diff changeset
301 } else {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 1552
diff changeset
302 if (Assert.ASSERTS_ENABLED) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 1552
diff changeset
303 Assert.that(false, "invalid field type for " + name);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 1552
diff changeset
304 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 1552
diff changeset
305 return null;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 1552
diff changeset
306 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 1552
diff changeset
307 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 1552
diff changeset
308
0
a61af66fc99e Initial load
duke
parents:
diff changeset
309 private Field findInstanceField(String name) {
a61af66fc99e Initial load
duke
parents:
diff changeset
310 Field fld = (Field) instanceFields.get(name);
a61af66fc99e Initial load
duke
parents:
diff changeset
311 if (fld != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
312 return fld;
a61af66fc99e Initial load
duke
parents:
diff changeset
313 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
314 InstanceKlass current = getInstanceKlass();
a61af66fc99e Initial load
duke
parents:
diff changeset
315 while (current != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
316 List tmp = current.getImmediateFields();
a61af66fc99e Initial load
duke
parents:
diff changeset
317 for (Iterator itr = tmp.iterator(); itr.hasNext();) {
a61af66fc99e Initial load
duke
parents:
diff changeset
318 fld = (Field) itr.next();
a61af66fc99e Initial load
duke
parents:
diff changeset
319 if (fld.getID().getName().equals(name) && !fld.isStatic()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
320 instanceFields.put(name, fld);
a61af66fc99e Initial load
duke
parents:
diff changeset
321 return fld;
a61af66fc99e Initial load
duke
parents:
diff changeset
322 }
a61af66fc99e Initial load
duke
parents:
diff changeset
323 }
a61af66fc99e Initial load
duke
parents:
diff changeset
324 // lookup in super class.
a61af66fc99e Initial load
duke
parents:
diff changeset
325 current = (InstanceKlass) current.getSuper();
a61af66fc99e Initial load
duke
parents:
diff changeset
326 }
a61af66fc99e Initial load
duke
parents:
diff changeset
327 }
a61af66fc99e Initial load
duke
parents:
diff changeset
328 // no match
a61af66fc99e Initial load
duke
parents:
diff changeset
329 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
330 }
a61af66fc99e Initial load
duke
parents:
diff changeset
331
a61af66fc99e Initial load
duke
parents:
diff changeset
332 private Field findStaticField(String name) {
a61af66fc99e Initial load
duke
parents:
diff changeset
333 Field fld = (Field) staticFields.get(name);
a61af66fc99e Initial load
duke
parents:
diff changeset
334 if (fld != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
335 return fld;
a61af66fc99e Initial load
duke
parents:
diff changeset
336 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
337 // static fields are searched only in current.
a61af66fc99e Initial load
duke
parents:
diff changeset
338 // Direct/indirect super classes and interfaces
a61af66fc99e Initial load
duke
parents:
diff changeset
339 // are not included in search.
a61af66fc99e Initial load
duke
parents:
diff changeset
340 InstanceKlass current = getInstanceKlass();
a61af66fc99e Initial load
duke
parents:
diff changeset
341 List tmp = current.getImmediateFields();
a61af66fc99e Initial load
duke
parents:
diff changeset
342 for (Iterator itr = tmp.iterator(); itr.hasNext();) {
a61af66fc99e Initial load
duke
parents:
diff changeset
343 fld = (Field) itr.next();
a61af66fc99e Initial load
duke
parents:
diff changeset
344 if (fld.getID().getName().equals(name) && fld.isStatic()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
345 staticFields.put(name, fld);
a61af66fc99e Initial load
duke
parents:
diff changeset
346 return fld;
a61af66fc99e Initial load
duke
parents:
diff changeset
347 }
a61af66fc99e Initial load
duke
parents:
diff changeset
348 }
a61af66fc99e Initial load
duke
parents:
diff changeset
349 // no match
a61af66fc99e Initial load
duke
parents:
diff changeset
350 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
351 }
a61af66fc99e Initial load
duke
parents:
diff changeset
352 }
a61af66fc99e Initial load
duke
parents:
diff changeset
353
a61af66fc99e Initial load
duke
parents:
diff changeset
354 private JSList getInterfaces() {
a61af66fc99e Initial load
duke
parents:
diff changeset
355 InstanceKlass ik = getInstanceKlass();
a61af66fc99e Initial load
duke
parents:
diff changeset
356 List intfs = ik.getDirectImplementedInterfaces();
a61af66fc99e Initial load
duke
parents:
diff changeset
357 List res = new ArrayList(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
358 for (Iterator itr = intfs.iterator(); itr.hasNext();) {
a61af66fc99e Initial load
duke
parents:
diff changeset
359 Klass k = (Klass) itr.next();
a61af66fc99e Initial load
duke
parents:
diff changeset
360 res.add(k.getJavaMirror());
a61af66fc99e Initial load
duke
parents:
diff changeset
361 }
a61af66fc99e Initial load
duke
parents:
diff changeset
362 return factory.newJSList(res);
a61af66fc99e Initial load
duke
parents:
diff changeset
363 }
a61af66fc99e Initial load
duke
parents:
diff changeset
364
a61af66fc99e Initial load
duke
parents:
diff changeset
365 private JSMap getStatics() {
a61af66fc99e Initial load
duke
parents:
diff changeset
366 String[] names = getStaticFieldNames();
a61af66fc99e Initial load
duke
parents:
diff changeset
367 Map map = new HashMap();
a61af66fc99e Initial load
duke
parents:
diff changeset
368 for (int i=0; i < names.length; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
369 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
370 map.put(names[i], getStaticFieldValue(names[i]));
a61af66fc99e Initial load
duke
parents:
diff changeset
371 } catch (NoSuchFieldException exp) {}
a61af66fc99e Initial load
duke
parents:
diff changeset
372 }
a61af66fc99e Initial load
duke
parents:
diff changeset
373 return factory.newJSMap(map);
a61af66fc99e Initial load
duke
parents:
diff changeset
374 }
a61af66fc99e Initial load
duke
parents:
diff changeset
375
a61af66fc99e Initial load
duke
parents:
diff changeset
376 private Map instanceFields;
a61af66fc99e Initial load
duke
parents:
diff changeset
377 private Map staticFields;
a61af66fc99e Initial load
duke
parents:
diff changeset
378 private String[] instanceFieldNames;
a61af66fc99e Initial load
duke
parents:
diff changeset
379 private String[] staticFieldNames;
a61af66fc99e Initial load
duke
parents:
diff changeset
380 private AccessFlags accFlags;
a61af66fc99e Initial load
duke
parents:
diff changeset
381 }