annotate agent/src/share/classes/sun/jvm/hotspot/oops/InstanceKlass.java @ 2376:c7f3d0b4570f

7017732: move static fields into Class to prepare for perm gen removal Reviewed-by: kvn, coleenp, twisti, stefank
author never
date Fri, 18 Mar 2011 16:00:34 -0700
parents 3582bf76420e
children 63997f575155
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: 2177
diff changeset
2 * Copyright (c) 2000, 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: 196
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 196
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: 196
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.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 import java.util.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
29 import sun.jvm.hotspot.debugger.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
30 import sun.jvm.hotspot.memory.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
31 import sun.jvm.hotspot.runtime.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
32 import sun.jvm.hotspot.types.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
33 import sun.jvm.hotspot.utilities.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
34
a61af66fc99e Initial load
duke
parents:
diff changeset
35 // An InstanceKlass is the VM level representation of a Java class.
a61af66fc99e Initial load
duke
parents:
diff changeset
36
a61af66fc99e Initial load
duke
parents:
diff changeset
37 public class InstanceKlass extends Klass {
a61af66fc99e Initial load
duke
parents:
diff changeset
38 static {
a61af66fc99e Initial load
duke
parents:
diff changeset
39 VM.registerVMInitializedObserver(new Observer() {
a61af66fc99e Initial load
duke
parents:
diff changeset
40 public void update(Observable o, Object data) {
a61af66fc99e Initial load
duke
parents:
diff changeset
41 initialize(VM.getVM().getTypeDataBase());
a61af66fc99e Initial load
duke
parents:
diff changeset
42 }
a61af66fc99e Initial load
duke
parents:
diff changeset
43 });
a61af66fc99e Initial load
duke
parents:
diff changeset
44 }
a61af66fc99e Initial load
duke
parents:
diff changeset
45
a61af66fc99e Initial load
duke
parents:
diff changeset
46 // field offset constants
a61af66fc99e Initial load
duke
parents:
diff changeset
47 public static int ACCESS_FLAGS_OFFSET;
a61af66fc99e Initial load
duke
parents:
diff changeset
48 public static int NAME_INDEX_OFFSET;
a61af66fc99e Initial load
duke
parents:
diff changeset
49 public static int SIGNATURE_INDEX_OFFSET;
a61af66fc99e Initial load
duke
parents:
diff changeset
50 public static int INITVAL_INDEX_OFFSET;
a61af66fc99e Initial load
duke
parents:
diff changeset
51 public static int LOW_OFFSET;
a61af66fc99e Initial load
duke
parents:
diff changeset
52 public static int HIGH_OFFSET;
a61af66fc99e Initial load
duke
parents:
diff changeset
53 public static int GENERIC_SIGNATURE_INDEX_OFFSET;
a61af66fc99e Initial load
duke
parents:
diff changeset
54 public static int NEXT_OFFSET;
a61af66fc99e Initial load
duke
parents:
diff changeset
55 public static int IMPLEMENTORS_LIMIT;
a61af66fc99e Initial load
duke
parents:
diff changeset
56
a61af66fc99e Initial load
duke
parents:
diff changeset
57 // ClassState constants
a61af66fc99e Initial load
duke
parents:
diff changeset
58 private static int CLASS_STATE_UNPARSABLE_BY_GC;
a61af66fc99e Initial load
duke
parents:
diff changeset
59 private static int CLASS_STATE_ALLOCATED;
a61af66fc99e Initial load
duke
parents:
diff changeset
60 private static int CLASS_STATE_LOADED;
a61af66fc99e Initial load
duke
parents:
diff changeset
61 private static int CLASS_STATE_LINKED;
a61af66fc99e Initial load
duke
parents:
diff changeset
62 private static int CLASS_STATE_BEING_INITIALIZED;
a61af66fc99e Initial load
duke
parents:
diff changeset
63 private static int CLASS_STATE_FULLY_INITIALIZED;
a61af66fc99e Initial load
duke
parents:
diff changeset
64 private static int CLASS_STATE_INITIALIZATION_ERROR;
a61af66fc99e Initial load
duke
parents:
diff changeset
65
a61af66fc99e Initial load
duke
parents:
diff changeset
66 private static synchronized void initialize(TypeDataBase db) throws WrongTypeException {
a61af66fc99e Initial load
duke
parents:
diff changeset
67 Type type = db.lookupType("instanceKlass");
a61af66fc99e Initial load
duke
parents:
diff changeset
68 arrayKlasses = new OopField(type.getOopField("_array_klasses"), Oop.getHeaderSize());
a61af66fc99e Initial load
duke
parents:
diff changeset
69 methods = new OopField(type.getOopField("_methods"), Oop.getHeaderSize());
a61af66fc99e Initial load
duke
parents:
diff changeset
70 methodOrdering = new OopField(type.getOopField("_method_ordering"), Oop.getHeaderSize());
a61af66fc99e Initial load
duke
parents:
diff changeset
71 localInterfaces = new OopField(type.getOopField("_local_interfaces"), Oop.getHeaderSize());
a61af66fc99e Initial load
duke
parents:
diff changeset
72 transitiveInterfaces = new OopField(type.getOopField("_transitive_interfaces"), Oop.getHeaderSize());
a61af66fc99e Initial load
duke
parents:
diff changeset
73 nofImplementors = new CIntField(type.getCIntegerField("_nof_implementors"), Oop.getHeaderSize());
a61af66fc99e Initial load
duke
parents:
diff changeset
74 IMPLEMENTORS_LIMIT = db.lookupIntConstant("instanceKlass::implementors_limit").intValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
75 implementors = new OopField[IMPLEMENTORS_LIMIT];
a61af66fc99e Initial load
duke
parents:
diff changeset
76 for (int i = 0; i < IMPLEMENTORS_LIMIT; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
77 long arrayOffset = Oop.getHeaderSize() + (i * db.getAddressSize());
a61af66fc99e Initial load
duke
parents:
diff changeset
78 implementors[i] = new OopField(type.getOopField("_implementors[0]"), arrayOffset);
a61af66fc99e Initial load
duke
parents:
diff changeset
79 }
a61af66fc99e Initial load
duke
parents:
diff changeset
80 fields = new OopField(type.getOopField("_fields"), Oop.getHeaderSize());
a61af66fc99e Initial load
duke
parents:
diff changeset
81 constants = new OopField(type.getOopField("_constants"), Oop.getHeaderSize());
a61af66fc99e Initial load
duke
parents:
diff changeset
82 classLoader = new OopField(type.getOopField("_class_loader"), Oop.getHeaderSize());
a61af66fc99e Initial load
duke
parents:
diff changeset
83 protectionDomain = new OopField(type.getOopField("_protection_domain"), Oop.getHeaderSize());
a61af66fc99e Initial load
duke
parents:
diff changeset
84 signers = new OopField(type.getOopField("_signers"), Oop.getHeaderSize());
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1552
diff changeset
85 sourceFileName = type.getAddressField("_source_file_name");
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1552
diff changeset
86 sourceDebugExtension = type.getAddressField("_source_debug_extension");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
87 innerClasses = new OopField(type.getOopField("_inner_classes"), Oop.getHeaderSize());
a61af66fc99e Initial load
duke
parents:
diff changeset
88 nonstaticFieldSize = new CIntField(type.getCIntegerField("_nonstatic_field_size"), Oop.getHeaderSize());
a61af66fc99e Initial load
duke
parents:
diff changeset
89 staticFieldSize = new CIntField(type.getCIntegerField("_static_field_size"), Oop.getHeaderSize());
2376
c7f3d0b4570f 7017732: move static fields into Class to prepare for perm gen removal
never
parents: 2177
diff changeset
90 staticOopFieldCount = new CIntField(type.getCIntegerField("_static_oop_field_count"), Oop.getHeaderSize());
0
a61af66fc99e Initial load
duke
parents:
diff changeset
91 nonstaticOopMapSize = new CIntField(type.getCIntegerField("_nonstatic_oop_map_size"), Oop.getHeaderSize());
a61af66fc99e Initial load
duke
parents:
diff changeset
92 isMarkedDependent = new CIntField(type.getCIntegerField("_is_marked_dependent"), Oop.getHeaderSize());
a61af66fc99e Initial load
duke
parents:
diff changeset
93 initState = new CIntField(type.getCIntegerField("_init_state"), Oop.getHeaderSize());
a61af66fc99e Initial load
duke
parents:
diff changeset
94 vtableLen = new CIntField(type.getCIntegerField("_vtable_len"), Oop.getHeaderSize());
a61af66fc99e Initial load
duke
parents:
diff changeset
95 itableLen = new CIntField(type.getCIntegerField("_itable_len"), Oop.getHeaderSize());
a61af66fc99e Initial load
duke
parents:
diff changeset
96 breakpoints = type.getAddressField("_breakpoints");
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1552
diff changeset
97 genericSignature = type.getAddressField("_generic_signature");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
98 majorVersion = new CIntField(type.getCIntegerField("_major_version"), Oop.getHeaderSize());
a61af66fc99e Initial load
duke
parents:
diff changeset
99 minorVersion = new CIntField(type.getCIntegerField("_minor_version"), Oop.getHeaderSize());
a61af66fc99e Initial load
duke
parents:
diff changeset
100 headerSize = alignObjectOffset(Oop.getHeaderSize() + type.getSize());
a61af66fc99e Initial load
duke
parents:
diff changeset
101
a61af66fc99e Initial load
duke
parents:
diff changeset
102 // read field offset constants
a61af66fc99e Initial load
duke
parents:
diff changeset
103 ACCESS_FLAGS_OFFSET = db.lookupIntConstant("instanceKlass::access_flags_offset").intValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
104 NAME_INDEX_OFFSET = db.lookupIntConstant("instanceKlass::name_index_offset").intValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
105 SIGNATURE_INDEX_OFFSET = db.lookupIntConstant("instanceKlass::signature_index_offset").intValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
106 INITVAL_INDEX_OFFSET = db.lookupIntConstant("instanceKlass::initval_index_offset").intValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
107 LOW_OFFSET = db.lookupIntConstant("instanceKlass::low_offset").intValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
108 HIGH_OFFSET = db.lookupIntConstant("instanceKlass::high_offset").intValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
109 GENERIC_SIGNATURE_INDEX_OFFSET = db.lookupIntConstant("instanceKlass::generic_signature_offset").intValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
110 NEXT_OFFSET = db.lookupIntConstant("instanceKlass::next_offset").intValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
111 // read ClassState constants
a61af66fc99e Initial load
duke
parents:
diff changeset
112 CLASS_STATE_UNPARSABLE_BY_GC = db.lookupIntConstant("instanceKlass::unparsable_by_gc").intValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
113 CLASS_STATE_ALLOCATED = db.lookupIntConstant("instanceKlass::allocated").intValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
114 CLASS_STATE_LOADED = db.lookupIntConstant("instanceKlass::loaded").intValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
115 CLASS_STATE_LINKED = db.lookupIntConstant("instanceKlass::linked").intValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
116 CLASS_STATE_BEING_INITIALIZED = db.lookupIntConstant("instanceKlass::being_initialized").intValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
117 CLASS_STATE_FULLY_INITIALIZED = db.lookupIntConstant("instanceKlass::fully_initialized").intValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
118 CLASS_STATE_INITIALIZATION_ERROR = db.lookupIntConstant("instanceKlass::initialization_error").intValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
119
a61af66fc99e Initial load
duke
parents:
diff changeset
120 }
a61af66fc99e Initial load
duke
parents:
diff changeset
121
a61af66fc99e Initial load
duke
parents:
diff changeset
122 InstanceKlass(OopHandle handle, ObjectHeap heap) {
a61af66fc99e Initial load
duke
parents:
diff changeset
123 super(handle, heap);
a61af66fc99e Initial load
duke
parents:
diff changeset
124 }
a61af66fc99e Initial load
duke
parents:
diff changeset
125
a61af66fc99e Initial load
duke
parents:
diff changeset
126 private static OopField arrayKlasses;
a61af66fc99e Initial load
duke
parents:
diff changeset
127 private static OopField methods;
a61af66fc99e Initial load
duke
parents:
diff changeset
128 private static OopField methodOrdering;
a61af66fc99e Initial load
duke
parents:
diff changeset
129 private static OopField localInterfaces;
a61af66fc99e Initial load
duke
parents:
diff changeset
130 private static OopField transitiveInterfaces;
a61af66fc99e Initial load
duke
parents:
diff changeset
131 private static CIntField nofImplementors;
a61af66fc99e Initial load
duke
parents:
diff changeset
132 private static OopField[] implementors;
a61af66fc99e Initial load
duke
parents:
diff changeset
133 private static OopField fields;
a61af66fc99e Initial load
duke
parents:
diff changeset
134 private static OopField constants;
a61af66fc99e Initial load
duke
parents:
diff changeset
135 private static OopField classLoader;
a61af66fc99e Initial load
duke
parents:
diff changeset
136 private static OopField protectionDomain;
a61af66fc99e Initial load
duke
parents:
diff changeset
137 private static OopField signers;
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1552
diff changeset
138 private static AddressField sourceFileName;
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1552
diff changeset
139 private static AddressField sourceDebugExtension;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
140 private static OopField innerClasses;
a61af66fc99e Initial load
duke
parents:
diff changeset
141 private static CIntField nonstaticFieldSize;
a61af66fc99e Initial load
duke
parents:
diff changeset
142 private static CIntField staticFieldSize;
2376
c7f3d0b4570f 7017732: move static fields into Class to prepare for perm gen removal
never
parents: 2177
diff changeset
143 private static CIntField staticOopFieldCount;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
144 private static CIntField nonstaticOopMapSize;
a61af66fc99e Initial load
duke
parents:
diff changeset
145 private static CIntField isMarkedDependent;
a61af66fc99e Initial load
duke
parents:
diff changeset
146 private static CIntField initState;
a61af66fc99e Initial load
duke
parents:
diff changeset
147 private static CIntField vtableLen;
a61af66fc99e Initial load
duke
parents:
diff changeset
148 private static CIntField itableLen;
a61af66fc99e Initial load
duke
parents:
diff changeset
149 private static AddressField breakpoints;
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1552
diff changeset
150 private static AddressField genericSignature;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
151 private static CIntField majorVersion;
a61af66fc99e Initial load
duke
parents:
diff changeset
152 private static CIntField minorVersion;
a61af66fc99e Initial load
duke
parents:
diff changeset
153
a61af66fc99e Initial load
duke
parents:
diff changeset
154 // type safe enum for ClassState from instanceKlass.hpp
a61af66fc99e Initial load
duke
parents:
diff changeset
155 public static class ClassState {
a61af66fc99e Initial load
duke
parents:
diff changeset
156 public static final ClassState UNPARSABLE_BY_GC = new ClassState("unparsable_by_gc");
a61af66fc99e Initial load
duke
parents:
diff changeset
157 public static final ClassState ALLOCATED = new ClassState("allocated");
a61af66fc99e Initial load
duke
parents:
diff changeset
158 public static final ClassState LOADED = new ClassState("loaded");
a61af66fc99e Initial load
duke
parents:
diff changeset
159 public static final ClassState LINKED = new ClassState("linked");
a61af66fc99e Initial load
duke
parents:
diff changeset
160 public static final ClassState BEING_INITIALIZED = new ClassState("beingInitialized");
a61af66fc99e Initial load
duke
parents:
diff changeset
161 public static final ClassState FULLY_INITIALIZED = new ClassState("fullyInitialized");
a61af66fc99e Initial load
duke
parents:
diff changeset
162 public static final ClassState INITIALIZATION_ERROR = new ClassState("initializationError");
a61af66fc99e Initial load
duke
parents:
diff changeset
163
a61af66fc99e Initial load
duke
parents:
diff changeset
164 private ClassState(String value) {
a61af66fc99e Initial load
duke
parents:
diff changeset
165 this.value = value;
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 toString() {
a61af66fc99e Initial load
duke
parents:
diff changeset
169 return value;
a61af66fc99e Initial load
duke
parents:
diff changeset
170 }
a61af66fc99e Initial load
duke
parents:
diff changeset
171
a61af66fc99e Initial load
duke
parents:
diff changeset
172 private String value;
a61af66fc99e Initial load
duke
parents:
diff changeset
173 }
a61af66fc99e Initial load
duke
parents:
diff changeset
174
a61af66fc99e Initial load
duke
parents:
diff changeset
175 private int getInitStateAsInt() { return (int) initState.getValue(this); }
a61af66fc99e Initial load
duke
parents:
diff changeset
176 public ClassState getInitState() {
a61af66fc99e Initial load
duke
parents:
diff changeset
177 int state = getInitStateAsInt();
a61af66fc99e Initial load
duke
parents:
diff changeset
178 if (state == CLASS_STATE_UNPARSABLE_BY_GC) {
a61af66fc99e Initial load
duke
parents:
diff changeset
179 return ClassState.UNPARSABLE_BY_GC;
a61af66fc99e Initial load
duke
parents:
diff changeset
180 } else if (state == CLASS_STATE_ALLOCATED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
181 return ClassState.ALLOCATED;
a61af66fc99e Initial load
duke
parents:
diff changeset
182 } else if (state == CLASS_STATE_LOADED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
183 return ClassState.LOADED;
a61af66fc99e Initial load
duke
parents:
diff changeset
184 } else if (state == CLASS_STATE_LINKED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
185 return ClassState.LINKED;
a61af66fc99e Initial load
duke
parents:
diff changeset
186 } else if (state == CLASS_STATE_BEING_INITIALIZED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
187 return ClassState.BEING_INITIALIZED;
a61af66fc99e Initial load
duke
parents:
diff changeset
188 } else if (state == CLASS_STATE_FULLY_INITIALIZED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
189 return ClassState.FULLY_INITIALIZED;
a61af66fc99e Initial load
duke
parents:
diff changeset
190 } else if (state == CLASS_STATE_INITIALIZATION_ERROR) {
a61af66fc99e Initial load
duke
parents:
diff changeset
191 return ClassState.INITIALIZATION_ERROR;
a61af66fc99e Initial load
duke
parents:
diff changeset
192 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
193 throw new RuntimeException("should not reach here");
a61af66fc99e Initial load
duke
parents:
diff changeset
194 }
a61af66fc99e Initial load
duke
parents:
diff changeset
195 }
a61af66fc99e Initial load
duke
parents:
diff changeset
196
a61af66fc99e Initial load
duke
parents:
diff changeset
197 // initialization state quaries
a61af66fc99e Initial load
duke
parents:
diff changeset
198 public boolean isLoaded() {
a61af66fc99e Initial load
duke
parents:
diff changeset
199 return getInitStateAsInt() >= CLASS_STATE_LOADED;
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 isLinked() {
a61af66fc99e Initial load
duke
parents:
diff changeset
203 return getInitStateAsInt() >= CLASS_STATE_LINKED;
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 boolean isInitialized() {
a61af66fc99e Initial load
duke
parents:
diff changeset
207 return getInitStateAsInt() == CLASS_STATE_FULLY_INITIALIZED;
a61af66fc99e Initial load
duke
parents:
diff changeset
208 }
a61af66fc99e Initial load
duke
parents:
diff changeset
209
a61af66fc99e Initial load
duke
parents:
diff changeset
210 public boolean isNotInitialized() {
a61af66fc99e Initial load
duke
parents:
diff changeset
211 return getInitStateAsInt() < CLASS_STATE_BEING_INITIALIZED;
a61af66fc99e Initial load
duke
parents:
diff changeset
212 }
a61af66fc99e Initial load
duke
parents:
diff changeset
213
a61af66fc99e Initial load
duke
parents:
diff changeset
214 public boolean isBeingInitialized() {
a61af66fc99e Initial load
duke
parents:
diff changeset
215 return getInitStateAsInt() == CLASS_STATE_BEING_INITIALIZED;
a61af66fc99e Initial load
duke
parents:
diff changeset
216 }
a61af66fc99e Initial load
duke
parents:
diff changeset
217
a61af66fc99e Initial load
duke
parents:
diff changeset
218 public boolean isInErrorState() {
a61af66fc99e Initial load
duke
parents:
diff changeset
219 return getInitStateAsInt() == CLASS_STATE_INITIALIZATION_ERROR;
a61af66fc99e Initial load
duke
parents:
diff changeset
220 }
a61af66fc99e Initial load
duke
parents:
diff changeset
221
a61af66fc99e Initial load
duke
parents:
diff changeset
222 public int getClassStatus() {
a61af66fc99e Initial load
duke
parents:
diff changeset
223 int result = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
224 if (isLinked()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
225 result |= JVMDIClassStatus.VERIFIED | JVMDIClassStatus.PREPARED;
a61af66fc99e Initial load
duke
parents:
diff changeset
226 }
a61af66fc99e Initial load
duke
parents:
diff changeset
227
a61af66fc99e Initial load
duke
parents:
diff changeset
228 if (isInitialized()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
229 if (Assert.ASSERTS_ENABLED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
230 Assert.that(isLinked(), "Class status is not consistent");
a61af66fc99e Initial load
duke
parents:
diff changeset
231 }
a61af66fc99e Initial load
duke
parents:
diff changeset
232 result |= JVMDIClassStatus.INITIALIZED;
a61af66fc99e Initial load
duke
parents:
diff changeset
233 }
a61af66fc99e Initial load
duke
parents:
diff changeset
234
a61af66fc99e Initial load
duke
parents:
diff changeset
235 if (isInErrorState()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
236 result |= JVMDIClassStatus.ERROR;
a61af66fc99e Initial load
duke
parents:
diff changeset
237 }
a61af66fc99e Initial load
duke
parents:
diff changeset
238 return result;
a61af66fc99e Initial load
duke
parents:
diff changeset
239 }
a61af66fc99e Initial load
duke
parents:
diff changeset
240
a61af66fc99e Initial load
duke
parents:
diff changeset
241 // Byteside of the header
a61af66fc99e Initial load
duke
parents:
diff changeset
242 private static long headerSize;
a61af66fc99e Initial load
duke
parents:
diff changeset
243
a61af66fc99e Initial load
duke
parents:
diff changeset
244 public static long getHeaderSize() { return headerSize; }
a61af66fc99e Initial load
duke
parents:
diff changeset
245
a61af66fc99e Initial load
duke
parents:
diff changeset
246 // Accessors for declared fields
a61af66fc99e Initial load
duke
parents:
diff changeset
247 public Klass getArrayKlasses() { return (Klass) arrayKlasses.getValue(this); }
a61af66fc99e Initial load
duke
parents:
diff changeset
248 public ObjArray getMethods() { return (ObjArray) methods.getValue(this); }
a61af66fc99e Initial load
duke
parents:
diff changeset
249 public TypeArray getMethodOrdering() { return (TypeArray) methodOrdering.getValue(this); }
a61af66fc99e Initial load
duke
parents:
diff changeset
250 public ObjArray getLocalInterfaces() { return (ObjArray) localInterfaces.getValue(this); }
a61af66fc99e Initial load
duke
parents:
diff changeset
251 public ObjArray getTransitiveInterfaces() { return (ObjArray) transitiveInterfaces.getValue(this); }
a61af66fc99e Initial load
duke
parents:
diff changeset
252 public long nofImplementors() { return nofImplementors.getValue(this); }
a61af66fc99e Initial load
duke
parents:
diff changeset
253 public Klass getImplementor() { return (Klass) implementors[0].getValue(this); }
a61af66fc99e Initial load
duke
parents:
diff changeset
254 public Klass getImplementor(int i) { return (Klass) implementors[i].getValue(this); }
a61af66fc99e Initial load
duke
parents:
diff changeset
255 public TypeArray getFields() { return (TypeArray) fields.getValue(this); }
a61af66fc99e Initial load
duke
parents:
diff changeset
256 public ConstantPool getConstants() { return (ConstantPool) constants.getValue(this); }
a61af66fc99e Initial load
duke
parents:
diff changeset
257 public Oop getClassLoader() { return classLoader.getValue(this); }
a61af66fc99e Initial load
duke
parents:
diff changeset
258 public Oop getProtectionDomain() { return protectionDomain.getValue(this); }
a61af66fc99e Initial load
duke
parents:
diff changeset
259 public ObjArray getSigners() { return (ObjArray) signers.getValue(this); }
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1552
diff changeset
260 public Symbol getSourceFileName() { return getSymbol(sourceFileName); }
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1552
diff changeset
261 public Symbol getSourceDebugExtension(){ return getSymbol(sourceDebugExtension); }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
262 public TypeArray getInnerClasses() { return (TypeArray) innerClasses.getValue(this); }
a61af66fc99e Initial load
duke
parents:
diff changeset
263 public long getNonstaticFieldSize() { return nonstaticFieldSize.getValue(this); }
2376
c7f3d0b4570f 7017732: move static fields into Class to prepare for perm gen removal
never
parents: 2177
diff changeset
264 public long getStaticOopFieldCount() { return staticOopFieldCount.getValue(this); }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
265 public long getNonstaticOopMapSize() { return nonstaticOopMapSize.getValue(this); }
a61af66fc99e Initial load
duke
parents:
diff changeset
266 public boolean getIsMarkedDependent() { return isMarkedDependent.getValue(this) != 0; }
a61af66fc99e Initial load
duke
parents:
diff changeset
267 public long getVtableLen() { return vtableLen.getValue(this); }
a61af66fc99e Initial load
duke
parents:
diff changeset
268 public long getItableLen() { return itableLen.getValue(this); }
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1552
diff changeset
269 public Symbol getGenericSignature() { return getSymbol(genericSignature); }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
270 public long majorVersion() { return majorVersion.getValue(this); }
a61af66fc99e Initial load
duke
parents:
diff changeset
271 public long minorVersion() { return minorVersion.getValue(this); }
a61af66fc99e Initial load
duke
parents:
diff changeset
272
a61af66fc99e Initial load
duke
parents:
diff changeset
273 // "size helper" == instance size in words
a61af66fc99e Initial load
duke
parents:
diff changeset
274 public long getSizeHelper() {
a61af66fc99e Initial load
duke
parents:
diff changeset
275 int lh = getLayoutHelper();
a61af66fc99e Initial load
duke
parents:
diff changeset
276 if (Assert.ASSERTS_ENABLED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
277 Assert.that(lh > 0, "layout helper initialized for instance class");
a61af66fc99e Initial load
duke
parents:
diff changeset
278 }
a61af66fc99e Initial load
duke
parents:
diff changeset
279 return lh / VM.getVM().getAddressSize();
a61af66fc99e Initial load
duke
parents:
diff changeset
280 }
a61af66fc99e Initial load
duke
parents:
diff changeset
281
a61af66fc99e Initial load
duke
parents:
diff changeset
282 // same as enum InnerClassAttributeOffset in VM code.
a61af66fc99e Initial load
duke
parents:
diff changeset
283 public static interface InnerClassAttributeOffset {
a61af66fc99e Initial load
duke
parents:
diff changeset
284 // from JVM spec. "InnerClasses" attribute
a61af66fc99e Initial load
duke
parents:
diff changeset
285 public static final int innerClassInnerClassInfoOffset = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
286 public static final int innerClassOuterClassInfoOffset = 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
287 public static final int innerClassInnerNameOffset = 2;
a61af66fc99e Initial load
duke
parents:
diff changeset
288 public static final int innerClassAccessFlagsOffset = 3;
a61af66fc99e Initial load
duke
parents:
diff changeset
289 public static final int innerClassNextOffset = 4;
a61af66fc99e Initial load
duke
parents:
diff changeset
290 };
a61af66fc99e Initial load
duke
parents:
diff changeset
291
a61af66fc99e Initial load
duke
parents:
diff changeset
292 // refer to compute_modifier_flags in VM code.
a61af66fc99e Initial load
duke
parents:
diff changeset
293 public long computeModifierFlags() {
a61af66fc99e Initial load
duke
parents:
diff changeset
294 long access = getAccessFlags();
a61af66fc99e Initial load
duke
parents:
diff changeset
295 // But check if it happens to be member class.
a61af66fc99e Initial load
duke
parents:
diff changeset
296 TypeArray innerClassList = getInnerClasses();
a61af66fc99e Initial load
duke
parents:
diff changeset
297 int length = ( innerClassList == null)? 0 : (int) innerClassList.getLength();
a61af66fc99e Initial load
duke
parents:
diff changeset
298 if (length > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
299 if (Assert.ASSERTS_ENABLED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
300 Assert.that(length % InnerClassAttributeOffset.innerClassNextOffset == 0, "just checking");
a61af66fc99e Initial load
duke
parents:
diff changeset
301 }
a61af66fc99e Initial load
duke
parents:
diff changeset
302 for (int i = 0; i < length; i += InnerClassAttributeOffset.innerClassNextOffset) {
a61af66fc99e Initial load
duke
parents:
diff changeset
303 int ioff = innerClassList.getShortAt(i +
a61af66fc99e Initial load
duke
parents:
diff changeset
304 InnerClassAttributeOffset.innerClassInnerClassInfoOffset);
a61af66fc99e Initial load
duke
parents:
diff changeset
305 // 'ioff' can be zero.
a61af66fc99e Initial load
duke
parents:
diff changeset
306 // refer to JVM spec. section 4.7.5.
a61af66fc99e Initial load
duke
parents:
diff changeset
307 if (ioff != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
308 // only look at classes that are already loaded
a61af66fc99e Initial load
duke
parents:
diff changeset
309 // since we are looking for the flags for our self.
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1552
diff changeset
310 ConstantPool.CPSlot classInfo = getConstants().getSlotAt(ioff);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
311 Symbol name = null;
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1552
diff changeset
312 if (classInfo.isOop()) {
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1552
diff changeset
313 name = ((Klass) classInfo.getOop()).getName();
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1552
diff changeset
314 } else if (classInfo.isMetaData()) {
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1552
diff changeset
315 name = classInfo.getSymbol();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
316 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
317 throw new RuntimeException("should not reach here");
a61af66fc99e Initial load
duke
parents:
diff changeset
318 }
a61af66fc99e Initial load
duke
parents:
diff changeset
319
a61af66fc99e Initial load
duke
parents:
diff changeset
320 if (name.equals(getName())) {
a61af66fc99e Initial load
duke
parents:
diff changeset
321 // This is really a member class
a61af66fc99e Initial load
duke
parents:
diff changeset
322 access = innerClassList.getShortAt(i +
a61af66fc99e Initial load
duke
parents:
diff changeset
323 InnerClassAttributeOffset.innerClassAccessFlagsOffset);
a61af66fc99e Initial load
duke
parents:
diff changeset
324 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
325 }
a61af66fc99e Initial load
duke
parents:
diff changeset
326 }
a61af66fc99e Initial load
duke
parents:
diff changeset
327 } // for inner classes
a61af66fc99e Initial load
duke
parents:
diff changeset
328 }
a61af66fc99e Initial load
duke
parents:
diff changeset
329
a61af66fc99e Initial load
duke
parents:
diff changeset
330 // Remember to strip ACC_SUPER bit
a61af66fc99e Initial load
duke
parents:
diff changeset
331 return (access & (~JVM_ACC_SUPER)) & JVM_ACC_WRITTEN_FLAGS;
a61af66fc99e Initial load
duke
parents:
diff changeset
332 }
a61af66fc99e Initial load
duke
parents:
diff changeset
333
a61af66fc99e Initial load
duke
parents:
diff changeset
334
a61af66fc99e Initial load
duke
parents:
diff changeset
335 // whether given Symbol is name of an inner/nested Klass of this Klass?
a61af66fc99e Initial load
duke
parents:
diff changeset
336 // anonymous and local classes are excluded.
a61af66fc99e Initial load
duke
parents:
diff changeset
337 public boolean isInnerClassName(Symbol sym) {
a61af66fc99e Initial load
duke
parents:
diff changeset
338 return isInInnerClasses(sym, false);
a61af66fc99e Initial load
duke
parents:
diff changeset
339 }
a61af66fc99e Initial load
duke
parents:
diff changeset
340
a61af66fc99e Initial load
duke
parents:
diff changeset
341 // whether given Symbol is name of an inner/nested Klass of this Klass?
a61af66fc99e Initial load
duke
parents:
diff changeset
342 // anonymous classes excluded, but local classes are included.
a61af66fc99e Initial load
duke
parents:
diff changeset
343 public boolean isInnerOrLocalClassName(Symbol sym) {
a61af66fc99e Initial load
duke
parents:
diff changeset
344 return isInInnerClasses(sym, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
345 }
a61af66fc99e Initial load
duke
parents:
diff changeset
346
a61af66fc99e Initial load
duke
parents:
diff changeset
347 private boolean isInInnerClasses(Symbol sym, boolean includeLocals) {
a61af66fc99e Initial load
duke
parents:
diff changeset
348 TypeArray innerClassList = getInnerClasses();
a61af66fc99e Initial load
duke
parents:
diff changeset
349 int length = ( innerClassList == null)? 0 : (int) innerClassList.getLength();
a61af66fc99e Initial load
duke
parents:
diff changeset
350 if (length > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
351 if (Assert.ASSERTS_ENABLED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
352 Assert.that(length % InnerClassAttributeOffset.innerClassNextOffset == 0, "just checking");
a61af66fc99e Initial load
duke
parents:
diff changeset
353 }
a61af66fc99e Initial load
duke
parents:
diff changeset
354 for (int i = 0; i < length; i += InnerClassAttributeOffset.innerClassNextOffset) {
a61af66fc99e Initial load
duke
parents:
diff changeset
355 int ioff = innerClassList.getShortAt(i +
a61af66fc99e Initial load
duke
parents:
diff changeset
356 InnerClassAttributeOffset.innerClassInnerClassInfoOffset);
a61af66fc99e Initial load
duke
parents:
diff changeset
357 // 'ioff' can be zero.
a61af66fc99e Initial load
duke
parents:
diff changeset
358 // refer to JVM spec. section 4.7.5.
a61af66fc99e Initial load
duke
parents:
diff changeset
359 if (ioff != 0) {
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1552
diff changeset
360 ConstantPool.CPSlot iclassInfo = getConstants().getSlotAt(ioff);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
361 Symbol innerName = null;
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1552
diff changeset
362 if (iclassInfo.isOop()) {
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1552
diff changeset
363 innerName = ((Klass) iclassInfo.getOop()).getName();
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1552
diff changeset
364 } else if (iclassInfo.isMetaData()) {
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1552
diff changeset
365 innerName = iclassInfo.getSymbol();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
366 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
367 throw new RuntimeException("should not reach here");
a61af66fc99e Initial load
duke
parents:
diff changeset
368 }
a61af66fc99e Initial load
duke
parents:
diff changeset
369
a61af66fc99e Initial load
duke
parents:
diff changeset
370 Symbol myname = getName();
a61af66fc99e Initial load
duke
parents:
diff changeset
371 int ooff = innerClassList.getShortAt(i +
a61af66fc99e Initial load
duke
parents:
diff changeset
372 InnerClassAttributeOffset.innerClassOuterClassInfoOffset);
a61af66fc99e Initial load
duke
parents:
diff changeset
373 // for anonymous classes inner_name_index of InnerClasses
a61af66fc99e Initial load
duke
parents:
diff changeset
374 // attribute is zero.
a61af66fc99e Initial load
duke
parents:
diff changeset
375 int innerNameIndex = innerClassList.getShortAt(i +
a61af66fc99e Initial load
duke
parents:
diff changeset
376 InnerClassAttributeOffset.innerClassInnerNameOffset);
a61af66fc99e Initial load
duke
parents:
diff changeset
377 // if this is not a member (anonymous, local etc.), 'ooff' will be zero
a61af66fc99e Initial load
duke
parents:
diff changeset
378 // refer to JVM spec. section 4.7.5.
a61af66fc99e Initial load
duke
parents:
diff changeset
379 if (ooff == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
380 if (includeLocals) {
a61af66fc99e Initial load
duke
parents:
diff changeset
381 // does it looks like my local class?
a61af66fc99e Initial load
duke
parents:
diff changeset
382 if (innerName.equals(sym) &&
a61af66fc99e Initial load
duke
parents:
diff changeset
383 innerName.asString().startsWith(myname.asString())) {
a61af66fc99e Initial load
duke
parents:
diff changeset
384 // exclude anonymous classes.
a61af66fc99e Initial load
duke
parents:
diff changeset
385 return (innerNameIndex != 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
386 }
a61af66fc99e Initial load
duke
parents:
diff changeset
387 }
a61af66fc99e Initial load
duke
parents:
diff changeset
388 } else {
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1552
diff changeset
389 ConstantPool.CPSlot oclassInfo = getConstants().getSlotAt(ooff);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
390 Symbol outerName = null;
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1552
diff changeset
391 if (oclassInfo.isOop()) {
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1552
diff changeset
392 outerName = ((Klass) oclassInfo.getOop()).getName();
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1552
diff changeset
393 } else if (oclassInfo.isMetaData()) {
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1552
diff changeset
394 outerName = oclassInfo.getSymbol();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
395 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
396 throw new RuntimeException("should not reach here");
a61af66fc99e Initial load
duke
parents:
diff changeset
397 }
a61af66fc99e Initial load
duke
parents:
diff changeset
398
a61af66fc99e Initial load
duke
parents:
diff changeset
399 // include only if current class is outer class.
a61af66fc99e Initial load
duke
parents:
diff changeset
400 if (outerName.equals(myname) && innerName.equals(sym)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
401 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
402 }
a61af66fc99e Initial load
duke
parents:
diff changeset
403 }
a61af66fc99e Initial load
duke
parents:
diff changeset
404 }
a61af66fc99e Initial load
duke
parents:
diff changeset
405 } // for inner classes
a61af66fc99e Initial load
duke
parents:
diff changeset
406 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
407 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
408 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
409 }
a61af66fc99e Initial load
duke
parents:
diff changeset
410 }
a61af66fc99e Initial load
duke
parents:
diff changeset
411
a61af66fc99e Initial load
duke
parents:
diff changeset
412 public boolean implementsInterface(Klass k) {
a61af66fc99e Initial load
duke
parents:
diff changeset
413 if (Assert.ASSERTS_ENABLED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
414 Assert.that(k.isInterface(), "should not reach here");
a61af66fc99e Initial load
duke
parents:
diff changeset
415 }
a61af66fc99e Initial load
duke
parents:
diff changeset
416 ObjArray interfaces = getTransitiveInterfaces();
a61af66fc99e Initial load
duke
parents:
diff changeset
417 final int len = (int) interfaces.getLength();
a61af66fc99e Initial load
duke
parents:
diff changeset
418 for (int i = 0; i < len; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
419 if (interfaces.getObjAt(i).equals(k)) return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
420 }
a61af66fc99e Initial load
duke
parents:
diff changeset
421 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
422 }
a61af66fc99e Initial load
duke
parents:
diff changeset
423
a61af66fc99e Initial load
duke
parents:
diff changeset
424 boolean computeSubtypeOf(Klass k) {
a61af66fc99e Initial load
duke
parents:
diff changeset
425 if (k.isInterface()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
426 return implementsInterface(k);
a61af66fc99e Initial load
duke
parents:
diff changeset
427 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
428 return super.computeSubtypeOf(k);
a61af66fc99e Initial load
duke
parents:
diff changeset
429 }
a61af66fc99e Initial load
duke
parents:
diff changeset
430 }
a61af66fc99e Initial load
duke
parents:
diff changeset
431
a61af66fc99e Initial load
duke
parents:
diff changeset
432 public void printValueOn(PrintStream tty) {
a61af66fc99e Initial load
duke
parents:
diff changeset
433 tty.print("InstanceKlass for " + getName().asString());
a61af66fc99e Initial load
duke
parents:
diff changeset
434 }
a61af66fc99e Initial load
duke
parents:
diff changeset
435
a61af66fc99e Initial load
duke
parents:
diff changeset
436 public void iterateFields(OopVisitor visitor, boolean doVMFields) {
a61af66fc99e Initial load
duke
parents:
diff changeset
437 super.iterateFields(visitor, doVMFields);
a61af66fc99e Initial load
duke
parents:
diff changeset
438 if (doVMFields) {
a61af66fc99e Initial load
duke
parents:
diff changeset
439 visitor.doOop(arrayKlasses, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
440 visitor.doOop(methods, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
441 visitor.doOop(methodOrdering, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
442 visitor.doOop(localInterfaces, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
443 visitor.doOop(transitiveInterfaces, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
444 visitor.doCInt(nofImplementors, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
445 for (int i = 0; i < IMPLEMENTORS_LIMIT; i++)
a61af66fc99e Initial load
duke
parents:
diff changeset
446 visitor.doOop(implementors[i], true);
a61af66fc99e Initial load
duke
parents:
diff changeset
447 visitor.doOop(fields, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
448 visitor.doOop(constants, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
449 visitor.doOop(classLoader, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
450 visitor.doOop(protectionDomain, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
451 visitor.doOop(signers, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
452 visitor.doOop(innerClasses, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
453 visitor.doCInt(nonstaticFieldSize, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
454 visitor.doCInt(staticFieldSize, true);
2376
c7f3d0b4570f 7017732: move static fields into Class to prepare for perm gen removal
never
parents: 2177
diff changeset
455 visitor.doCInt(staticOopFieldCount, true);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
456 visitor.doCInt(nonstaticOopMapSize, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
457 visitor.doCInt(isMarkedDependent, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
458 visitor.doCInt(initState, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
459 visitor.doCInt(vtableLen, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
460 visitor.doCInt(itableLen, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
461 }
a61af66fc99e Initial load
duke
parents:
diff changeset
462
a61af66fc99e Initial load
duke
parents:
diff changeset
463 TypeArray fields = getFields();
a61af66fc99e Initial load
duke
parents:
diff changeset
464 int length = (int) fields.getLength();
a61af66fc99e Initial load
duke
parents:
diff changeset
465 for (int index = 0; index < length; index += NEXT_OFFSET) {
a61af66fc99e Initial load
duke
parents:
diff changeset
466 short accessFlags = fields.getShortAt(index + ACCESS_FLAGS_OFFSET);
a61af66fc99e Initial load
duke
parents:
diff changeset
467 short signatureIndex = fields.getShortAt(index + SIGNATURE_INDEX_OFFSET);
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1552
diff changeset
468 FieldType type = new FieldType(getConstants().getSymbolAt(signatureIndex));
0
a61af66fc99e Initial load
duke
parents:
diff changeset
469 AccessFlags access = new AccessFlags(accessFlags);
a61af66fc99e Initial load
duke
parents:
diff changeset
470 if (access.isStatic()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
471 visitField(visitor, type, index);
a61af66fc99e Initial load
duke
parents:
diff changeset
472 }
a61af66fc99e Initial load
duke
parents:
diff changeset
473 }
a61af66fc99e Initial load
duke
parents:
diff changeset
474 }
a61af66fc99e Initial load
duke
parents:
diff changeset
475
a61af66fc99e Initial load
duke
parents:
diff changeset
476 public Klass getJavaSuper() {
a61af66fc99e Initial load
duke
parents:
diff changeset
477 return getSuper();
a61af66fc99e Initial load
duke
parents:
diff changeset
478 }
a61af66fc99e Initial load
duke
parents:
diff changeset
479
a61af66fc99e Initial load
duke
parents:
diff changeset
480 public void iterateNonStaticFields(OopVisitor visitor) {
a61af66fc99e Initial load
duke
parents:
diff changeset
481 if (getSuper() != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
482 ((InstanceKlass) getSuper()).iterateNonStaticFields(visitor);
a61af66fc99e Initial load
duke
parents:
diff changeset
483 }
a61af66fc99e Initial load
duke
parents:
diff changeset
484 TypeArray fields = getFields();
a61af66fc99e Initial load
duke
parents:
diff changeset
485
a61af66fc99e Initial load
duke
parents:
diff changeset
486 int length = (int) fields.getLength();
a61af66fc99e Initial load
duke
parents:
diff changeset
487 for (int index = 0; index < length; index += NEXT_OFFSET) {
a61af66fc99e Initial load
duke
parents:
diff changeset
488 short accessFlags = fields.getShortAt(index + ACCESS_FLAGS_OFFSET);
a61af66fc99e Initial load
duke
parents:
diff changeset
489 short signatureIndex = fields.getShortAt(index + SIGNATURE_INDEX_OFFSET);
a61af66fc99e Initial load
duke
parents:
diff changeset
490
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1552
diff changeset
491 FieldType type = new FieldType(getConstants().getSymbolAt(signatureIndex));
0
a61af66fc99e Initial load
duke
parents:
diff changeset
492 AccessFlags access = new AccessFlags(accessFlags);
a61af66fc99e Initial load
duke
parents:
diff changeset
493 if (!access.isStatic()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
494 visitField(visitor, type, index);
a61af66fc99e Initial load
duke
parents:
diff changeset
495 }
a61af66fc99e Initial load
duke
parents:
diff changeset
496 }
a61af66fc99e Initial load
duke
parents:
diff changeset
497 }
a61af66fc99e Initial load
duke
parents:
diff changeset
498
a61af66fc99e Initial load
duke
parents:
diff changeset
499 /** Field access by name. */
a61af66fc99e Initial load
duke
parents:
diff changeset
500 public Field findLocalField(Symbol name, Symbol sig) {
a61af66fc99e Initial load
duke
parents:
diff changeset
501 TypeArray fields = getFields();
a61af66fc99e Initial load
duke
parents:
diff changeset
502 int n = (int) fields.getLength();
a61af66fc99e Initial load
duke
parents:
diff changeset
503 ConstantPool cp = getConstants();
a61af66fc99e Initial load
duke
parents:
diff changeset
504 for (int i = 0; i < n; i += NEXT_OFFSET) {
a61af66fc99e Initial load
duke
parents:
diff changeset
505 int nameIndex = fields.getShortAt(i + NAME_INDEX_OFFSET);
a61af66fc99e Initial load
duke
parents:
diff changeset
506 int sigIndex = fields.getShortAt(i + SIGNATURE_INDEX_OFFSET);
a61af66fc99e Initial load
duke
parents:
diff changeset
507 Symbol f_name = cp.getSymbolAt(nameIndex);
a61af66fc99e Initial load
duke
parents:
diff changeset
508 Symbol f_sig = cp.getSymbolAt(sigIndex);
a61af66fc99e Initial load
duke
parents:
diff changeset
509 if (name.equals(f_name) && sig.equals(f_sig)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
510 return newField(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
511 }
a61af66fc99e Initial load
duke
parents:
diff changeset
512 }
a61af66fc99e Initial load
duke
parents:
diff changeset
513
a61af66fc99e Initial load
duke
parents:
diff changeset
514 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
515 }
a61af66fc99e Initial load
duke
parents:
diff changeset
516
a61af66fc99e Initial load
duke
parents:
diff changeset
517 /** Find field in direct superinterfaces. */
a61af66fc99e Initial load
duke
parents:
diff changeset
518 public Field findInterfaceField(Symbol name, Symbol sig) {
a61af66fc99e Initial load
duke
parents:
diff changeset
519 ObjArray interfaces = getLocalInterfaces();
a61af66fc99e Initial load
duke
parents:
diff changeset
520 int n = (int) interfaces.getLength();
a61af66fc99e Initial load
duke
parents:
diff changeset
521 for (int i = 0; i < n; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
522 InstanceKlass intf1 = (InstanceKlass) interfaces.getObjAt(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
523 if (Assert.ASSERTS_ENABLED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
524 Assert.that(intf1.isInterface(), "just checking type");
a61af66fc99e Initial load
duke
parents:
diff changeset
525 }
a61af66fc99e Initial load
duke
parents:
diff changeset
526 // search for field in current interface
a61af66fc99e Initial load
duke
parents:
diff changeset
527 Field f = intf1.findLocalField(name, sig);
a61af66fc99e Initial load
duke
parents:
diff changeset
528 if (f != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
529 if (Assert.ASSERTS_ENABLED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
530 Assert.that(f.getAccessFlagsObj().isStatic(), "interface field must be static");
a61af66fc99e Initial load
duke
parents:
diff changeset
531 }
a61af66fc99e Initial load
duke
parents:
diff changeset
532 return f;
a61af66fc99e Initial load
duke
parents:
diff changeset
533 }
a61af66fc99e Initial load
duke
parents:
diff changeset
534 // search for field in direct superinterfaces
a61af66fc99e Initial load
duke
parents:
diff changeset
535 f = intf1.findInterfaceField(name, sig);
a61af66fc99e Initial load
duke
parents:
diff changeset
536 if (f != null) return f;
a61af66fc99e Initial load
duke
parents:
diff changeset
537 }
a61af66fc99e Initial load
duke
parents:
diff changeset
538 // otherwise field lookup fails
a61af66fc99e Initial load
duke
parents:
diff changeset
539 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
540 }
a61af66fc99e Initial load
duke
parents:
diff changeset
541
a61af66fc99e Initial load
duke
parents:
diff changeset
542 /** Find field according to JVM spec 5.4.3.2, returns the klass in
a61af66fc99e Initial load
duke
parents:
diff changeset
543 which the field is defined. */
a61af66fc99e Initial load
duke
parents:
diff changeset
544 public Field findField(Symbol name, Symbol sig) {
a61af66fc99e Initial load
duke
parents:
diff changeset
545 // search order according to newest JVM spec (5.4.3.2, p.167).
a61af66fc99e Initial load
duke
parents:
diff changeset
546 // 1) search for field in current klass
a61af66fc99e Initial load
duke
parents:
diff changeset
547 Field f = findLocalField(name, sig);
a61af66fc99e Initial load
duke
parents:
diff changeset
548 if (f != null) return f;
a61af66fc99e Initial load
duke
parents:
diff changeset
549
a61af66fc99e Initial load
duke
parents:
diff changeset
550 // 2) search for field recursively in direct superinterfaces
a61af66fc99e Initial load
duke
parents:
diff changeset
551 f = findInterfaceField(name, sig);
a61af66fc99e Initial load
duke
parents:
diff changeset
552 if (f != null) return f;
a61af66fc99e Initial load
duke
parents:
diff changeset
553
a61af66fc99e Initial load
duke
parents:
diff changeset
554 // 3) apply field lookup recursively if superclass exists
a61af66fc99e Initial load
duke
parents:
diff changeset
555 InstanceKlass supr = (InstanceKlass) getSuper();
a61af66fc99e Initial load
duke
parents:
diff changeset
556 if (supr != null) return supr.findField(name, sig);
a61af66fc99e Initial load
duke
parents:
diff changeset
557
a61af66fc99e Initial load
duke
parents:
diff changeset
558 // 4) otherwise field lookup fails
a61af66fc99e Initial load
duke
parents:
diff changeset
559 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
560 }
a61af66fc99e Initial load
duke
parents:
diff changeset
561
a61af66fc99e Initial load
duke
parents:
diff changeset
562 /** Find field according to JVM spec 5.4.3.2, returns the klass in
a61af66fc99e Initial load
duke
parents:
diff changeset
563 which the field is defined (convenience routine) */
a61af66fc99e Initial load
duke
parents:
diff changeset
564 public Field findField(String name, String sig) {
a61af66fc99e Initial load
duke
parents:
diff changeset
565 SymbolTable symbols = VM.getVM().getSymbolTable();
a61af66fc99e Initial load
duke
parents:
diff changeset
566 Symbol nameSym = symbols.probe(name);
a61af66fc99e Initial load
duke
parents:
diff changeset
567 Symbol sigSym = symbols.probe(sig);
a61af66fc99e Initial load
duke
parents:
diff changeset
568 if (nameSym == null || sigSym == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
569 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
570 }
a61af66fc99e Initial load
duke
parents:
diff changeset
571 return findField(nameSym, sigSym);
a61af66fc99e Initial load
duke
parents:
diff changeset
572 }
a61af66fc99e Initial load
duke
parents:
diff changeset
573
a61af66fc99e Initial load
duke
parents:
diff changeset
574 /** Find field according to JVM spec 5.4.3.2, returns the klass in
a61af66fc99e Initial load
duke
parents:
diff changeset
575 which the field is defined (retained only for backward
a61af66fc99e Initial load
duke
parents:
diff changeset
576 compatibility with jdbx) */
a61af66fc99e Initial load
duke
parents:
diff changeset
577 public Field findFieldDbg(String name, String sig) {
a61af66fc99e Initial load
duke
parents:
diff changeset
578 return findField(name, sig);
a61af66fc99e Initial load
duke
parents:
diff changeset
579 }
a61af66fc99e Initial load
duke
parents:
diff changeset
580
a61af66fc99e Initial load
duke
parents:
diff changeset
581 /** Get field by its index in the fields array. Only designed for
a61af66fc99e Initial load
duke
parents:
diff changeset
582 use in a debugging system. */
a61af66fc99e Initial load
duke
parents:
diff changeset
583 public Field getFieldByIndex(int fieldArrayIndex) {
a61af66fc99e Initial load
duke
parents:
diff changeset
584 return newField(fieldArrayIndex);
a61af66fc99e Initial load
duke
parents:
diff changeset
585 }
a61af66fc99e Initial load
duke
parents:
diff changeset
586
a61af66fc99e Initial load
duke
parents:
diff changeset
587
a61af66fc99e Initial load
duke
parents:
diff changeset
588 /** Return a List of SA Fields for the fields declared in this class.
a61af66fc99e Initial load
duke
parents:
diff changeset
589 Inherited fields are not included.
a61af66fc99e Initial load
duke
parents:
diff changeset
590 Return an empty list if there are no fields declared in this class.
a61af66fc99e Initial load
duke
parents:
diff changeset
591 Only designed for use in a debugging system. */
a61af66fc99e Initial load
duke
parents:
diff changeset
592 public List getImmediateFields() {
a61af66fc99e Initial load
duke
parents:
diff changeset
593 // A list of Fields for each field declared in this class/interface,
a61af66fc99e Initial load
duke
parents:
diff changeset
594 // not including inherited fields.
a61af66fc99e Initial load
duke
parents:
diff changeset
595 TypeArray fields = getFields();
a61af66fc99e Initial load
duke
parents:
diff changeset
596
a61af66fc99e Initial load
duke
parents:
diff changeset
597 int length = (int) fields.getLength();
a61af66fc99e Initial load
duke
parents:
diff changeset
598 List immediateFields = new ArrayList(length / NEXT_OFFSET);
a61af66fc99e Initial load
duke
parents:
diff changeset
599 for (int index = 0; index < length; index += NEXT_OFFSET) {
a61af66fc99e Initial load
duke
parents:
diff changeset
600 immediateFields.add(getFieldByIndex(index));
a61af66fc99e Initial load
duke
parents:
diff changeset
601 }
a61af66fc99e Initial load
duke
parents:
diff changeset
602
a61af66fc99e Initial load
duke
parents:
diff changeset
603 return immediateFields;
a61af66fc99e Initial load
duke
parents:
diff changeset
604 }
a61af66fc99e Initial load
duke
parents:
diff changeset
605
a61af66fc99e Initial load
duke
parents:
diff changeset
606 /** Return a List of SA Fields for all the java fields in this class,
a61af66fc99e Initial load
duke
parents:
diff changeset
607 including all inherited fields. This includes hidden
a61af66fc99e Initial load
duke
parents:
diff changeset
608 fields. Thus the returned list can contain fields with
a61af66fc99e Initial load
duke
parents:
diff changeset
609 the same name.
a61af66fc99e Initial load
duke
parents:
diff changeset
610 Return an empty list if there are no fields.
a61af66fc99e Initial load
duke
parents:
diff changeset
611 Only designed for use in a debugging system. */
a61af66fc99e Initial load
duke
parents:
diff changeset
612 public List getAllFields() {
a61af66fc99e Initial load
duke
parents:
diff changeset
613 // Contains a Field for each field in this class, including immediate
a61af66fc99e Initial load
duke
parents:
diff changeset
614 // fields and inherited fields.
a61af66fc99e Initial load
duke
parents:
diff changeset
615 List allFields = getImmediateFields();
a61af66fc99e Initial load
duke
parents:
diff changeset
616
a61af66fc99e Initial load
duke
parents:
diff changeset
617 // transitiveInterfaces contains all interfaces implemented
a61af66fc99e Initial load
duke
parents:
diff changeset
618 // by this class and its superclass chain with no duplicates.
a61af66fc99e Initial load
duke
parents:
diff changeset
619
a61af66fc99e Initial load
duke
parents:
diff changeset
620 ObjArray interfaces = getTransitiveInterfaces();
a61af66fc99e Initial load
duke
parents:
diff changeset
621 int n = (int) interfaces.getLength();
a61af66fc99e Initial load
duke
parents:
diff changeset
622 for (int i = 0; i < n; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
623 InstanceKlass intf1 = (InstanceKlass) interfaces.getObjAt(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
624 if (Assert.ASSERTS_ENABLED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
625 Assert.that(intf1.isInterface(), "just checking type");
a61af66fc99e Initial load
duke
parents:
diff changeset
626 }
a61af66fc99e Initial load
duke
parents:
diff changeset
627 allFields.addAll(intf1.getImmediateFields());
a61af66fc99e Initial load
duke
parents:
diff changeset
628 }
a61af66fc99e Initial load
duke
parents:
diff changeset
629
a61af66fc99e Initial load
duke
parents:
diff changeset
630 // Get all fields in the superclass, recursively. But, don't
a61af66fc99e Initial load
duke
parents:
diff changeset
631 // include fields in interfaces implemented by superclasses;
a61af66fc99e Initial load
duke
parents:
diff changeset
632 // we already have all those.
a61af66fc99e Initial load
duke
parents:
diff changeset
633 if (!isInterface()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
634 InstanceKlass supr;
a61af66fc99e Initial load
duke
parents:
diff changeset
635 if ( (supr = (InstanceKlass) getSuper()) != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
636 allFields.addAll(supr.getImmediateFields());
a61af66fc99e Initial load
duke
parents:
diff changeset
637 }
a61af66fc99e Initial load
duke
parents:
diff changeset
638 }
a61af66fc99e Initial load
duke
parents:
diff changeset
639
a61af66fc99e Initial load
duke
parents:
diff changeset
640 return allFields;
a61af66fc99e Initial load
duke
parents:
diff changeset
641 }
a61af66fc99e Initial load
duke
parents:
diff changeset
642
a61af66fc99e Initial load
duke
parents:
diff changeset
643
a61af66fc99e Initial load
duke
parents:
diff changeset
644 /** Return a List of SA Methods declared directly in this class/interface.
a61af66fc99e Initial load
duke
parents:
diff changeset
645 Return an empty list if there are none, or if this isn't a class/
a61af66fc99e Initial load
duke
parents:
diff changeset
646 interface.
a61af66fc99e Initial load
duke
parents:
diff changeset
647 */
a61af66fc99e Initial load
duke
parents:
diff changeset
648 public List getImmediateMethods() {
a61af66fc99e Initial load
duke
parents:
diff changeset
649 // Contains a Method for each method declared in this class/interface
a61af66fc99e Initial load
duke
parents:
diff changeset
650 // not including inherited methods.
a61af66fc99e Initial load
duke
parents:
diff changeset
651
a61af66fc99e Initial load
duke
parents:
diff changeset
652 ObjArray methods = getMethods();
a61af66fc99e Initial load
duke
parents:
diff changeset
653 int length = (int)methods.getLength();
a61af66fc99e Initial load
duke
parents:
diff changeset
654 Object[] tmp = new Object[length];
a61af66fc99e Initial load
duke
parents:
diff changeset
655
a61af66fc99e Initial load
duke
parents:
diff changeset
656 TypeArray methodOrdering = getMethodOrdering();
a61af66fc99e Initial load
duke
parents:
diff changeset
657 if (methodOrdering.getLength() != length) {
a61af66fc99e Initial load
duke
parents:
diff changeset
658 // no ordering info present
a61af66fc99e Initial load
duke
parents:
diff changeset
659 for (int index = 0; index < length; index++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
660 tmp[index] = methods.getObjAt(index);
a61af66fc99e Initial load
duke
parents:
diff changeset
661 }
a61af66fc99e Initial load
duke
parents:
diff changeset
662 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
663 for (int index = 0; index < length; index++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
664 int originalIndex = getMethodOrdering().getIntAt(index);
a61af66fc99e Initial load
duke
parents:
diff changeset
665 tmp[originalIndex] = methods.getObjAt(index);
a61af66fc99e Initial load
duke
parents:
diff changeset
666 }
a61af66fc99e Initial load
duke
parents:
diff changeset
667 }
a61af66fc99e Initial load
duke
parents:
diff changeset
668
a61af66fc99e Initial load
duke
parents:
diff changeset
669 return Arrays.asList(tmp);
a61af66fc99e Initial load
duke
parents:
diff changeset
670 }
a61af66fc99e Initial load
duke
parents:
diff changeset
671
a61af66fc99e Initial load
duke
parents:
diff changeset
672 /** Return a List containing an SA InstanceKlass for each
a61af66fc99e Initial load
duke
parents:
diff changeset
673 interface named in this class's 'implements' clause.
a61af66fc99e Initial load
duke
parents:
diff changeset
674 */
a61af66fc99e Initial load
duke
parents:
diff changeset
675 public List getDirectImplementedInterfaces() {
a61af66fc99e Initial load
duke
parents:
diff changeset
676 // Contains an InstanceKlass for each interface in this classes
a61af66fc99e Initial load
duke
parents:
diff changeset
677 // 'implements' clause.
a61af66fc99e Initial load
duke
parents:
diff changeset
678
a61af66fc99e Initial load
duke
parents:
diff changeset
679 ObjArray interfaces = getLocalInterfaces();
a61af66fc99e Initial load
duke
parents:
diff changeset
680 int length = (int) interfaces.getLength();
a61af66fc99e Initial load
duke
parents:
diff changeset
681 List directImplementedInterfaces = new ArrayList(length);
a61af66fc99e Initial load
duke
parents:
diff changeset
682
a61af66fc99e Initial load
duke
parents:
diff changeset
683 for (int index = 0; index < length; index ++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
684 directImplementedInterfaces.add(interfaces.getObjAt(index));
a61af66fc99e Initial load
duke
parents:
diff changeset
685 }
a61af66fc99e Initial load
duke
parents:
diff changeset
686
a61af66fc99e Initial load
duke
parents:
diff changeset
687 return directImplementedInterfaces;
a61af66fc99e Initial load
duke
parents:
diff changeset
688 }
a61af66fc99e Initial load
duke
parents:
diff changeset
689
a61af66fc99e Initial load
duke
parents:
diff changeset
690
a61af66fc99e Initial load
duke
parents:
diff changeset
691 public long getObjectSize() {
a61af66fc99e Initial load
duke
parents:
diff changeset
692 long bodySize = alignObjectOffset(getVtableLen() * getHeap().getOopSize())
a61af66fc99e Initial load
duke
parents:
diff changeset
693 + alignObjectOffset(getItableLen() * getHeap().getOopSize())
2376
c7f3d0b4570f 7017732: move static fields into Class to prepare for perm gen removal
never
parents: 2177
diff changeset
694 + (getNonstaticOopMapSize()) * getHeap().getOopSize();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
695 return alignObjectSize(headerSize + bodySize);
a61af66fc99e Initial load
duke
parents:
diff changeset
696 }
a61af66fc99e Initial load
duke
parents:
diff changeset
697
a61af66fc99e Initial load
duke
parents:
diff changeset
698 public Klass arrayKlassImpl(boolean orNull, int n) {
a61af66fc99e Initial load
duke
parents:
diff changeset
699 // FIXME: in reflective system this would need to change to
a61af66fc99e Initial load
duke
parents:
diff changeset
700 // actually allocate
a61af66fc99e Initial load
duke
parents:
diff changeset
701 if (getArrayKlasses() == null) { return null; }
a61af66fc99e Initial load
duke
parents:
diff changeset
702 ObjArrayKlass oak = (ObjArrayKlass) getArrayKlasses();
a61af66fc99e Initial load
duke
parents:
diff changeset
703 if (orNull) {
a61af66fc99e Initial load
duke
parents:
diff changeset
704 return oak.arrayKlassOrNull(n);
a61af66fc99e Initial load
duke
parents:
diff changeset
705 }
a61af66fc99e Initial load
duke
parents:
diff changeset
706 return oak.arrayKlass(n);
a61af66fc99e Initial load
duke
parents:
diff changeset
707 }
a61af66fc99e Initial load
duke
parents:
diff changeset
708
a61af66fc99e Initial load
duke
parents:
diff changeset
709 public Klass arrayKlassImpl(boolean orNull) {
a61af66fc99e Initial load
duke
parents:
diff changeset
710 return arrayKlassImpl(orNull, 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
711 }
a61af66fc99e Initial load
duke
parents:
diff changeset
712
a61af66fc99e Initial load
duke
parents:
diff changeset
713 public String signature() {
a61af66fc99e Initial load
duke
parents:
diff changeset
714 return "L" + super.signature() + ";";
a61af66fc99e Initial load
duke
parents:
diff changeset
715 }
a61af66fc99e Initial load
duke
parents:
diff changeset
716
a61af66fc99e Initial load
duke
parents:
diff changeset
717 /** Convenience routine taking Strings; lookup is done in
a61af66fc99e Initial load
duke
parents:
diff changeset
718 SymbolTable. */
a61af66fc99e Initial load
duke
parents:
diff changeset
719 public Method findMethod(String name, String sig) {
a61af66fc99e Initial load
duke
parents:
diff changeset
720 SymbolTable syms = VM.getVM().getSymbolTable();
a61af66fc99e Initial load
duke
parents:
diff changeset
721 Symbol nameSym = syms.probe(name);
a61af66fc99e Initial load
duke
parents:
diff changeset
722 Symbol sigSym = syms.probe(sig);
a61af66fc99e Initial load
duke
parents:
diff changeset
723 if (nameSym == null || sigSym == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
724 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
725 }
a61af66fc99e Initial load
duke
parents:
diff changeset
726 return findMethod(nameSym, sigSym);
a61af66fc99e Initial load
duke
parents:
diff changeset
727 }
a61af66fc99e Initial load
duke
parents:
diff changeset
728
a61af66fc99e Initial load
duke
parents:
diff changeset
729 /** Find method in vtable. */
a61af66fc99e Initial load
duke
parents:
diff changeset
730 public Method findMethod(Symbol name, Symbol sig) {
a61af66fc99e Initial load
duke
parents:
diff changeset
731 return findMethod(getMethods(), name, sig);
a61af66fc99e Initial load
duke
parents:
diff changeset
732 }
a61af66fc99e Initial load
duke
parents:
diff changeset
733
a61af66fc99e Initial load
duke
parents:
diff changeset
734 /** Breakpoint support (see methods on methodOop for details) */
a61af66fc99e Initial load
duke
parents:
diff changeset
735 public BreakpointInfo getBreakpoints() {
a61af66fc99e Initial load
duke
parents:
diff changeset
736 Address addr = getHandle().getAddressAt(Oop.getHeaderSize() + breakpoints.getOffset());
a61af66fc99e Initial load
duke
parents:
diff changeset
737 return (BreakpointInfo) VMObjectFactory.newObject(BreakpointInfo.class, addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
738 }
a61af66fc99e Initial load
duke
parents:
diff changeset
739
a61af66fc99e Initial load
duke
parents:
diff changeset
740 //----------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
741 // Internals only below this point
a61af66fc99e Initial load
duke
parents:
diff changeset
742 //
a61af66fc99e Initial load
duke
parents:
diff changeset
743
a61af66fc99e Initial load
duke
parents:
diff changeset
744 private void visitField(OopVisitor visitor, FieldType type, int index) {
a61af66fc99e Initial load
duke
parents:
diff changeset
745 Field f = newField(index);
a61af66fc99e Initial load
duke
parents:
diff changeset
746 if (type.isOop()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
747 visitor.doOop((OopField) f, false);
a61af66fc99e Initial load
duke
parents:
diff changeset
748 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
749 }
a61af66fc99e Initial load
duke
parents:
diff changeset
750 if (type.isByte()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
751 visitor.doByte((ByteField) f, false);
a61af66fc99e Initial load
duke
parents:
diff changeset
752 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
753 }
a61af66fc99e Initial load
duke
parents:
diff changeset
754 if (type.isChar()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
755 visitor.doChar((CharField) f, false);
a61af66fc99e Initial load
duke
parents:
diff changeset
756 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
757 }
a61af66fc99e Initial load
duke
parents:
diff changeset
758 if (type.isDouble()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
759 visitor.doDouble((DoubleField) f, false);
a61af66fc99e Initial load
duke
parents:
diff changeset
760 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
761 }
a61af66fc99e Initial load
duke
parents:
diff changeset
762 if (type.isFloat()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
763 visitor.doFloat((FloatField) f, false);
a61af66fc99e Initial load
duke
parents:
diff changeset
764 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
765 }
a61af66fc99e Initial load
duke
parents:
diff changeset
766 if (type.isInt()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
767 visitor.doInt((IntField) f, false);
a61af66fc99e Initial load
duke
parents:
diff changeset
768 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
769 }
a61af66fc99e Initial load
duke
parents:
diff changeset
770 if (type.isLong()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
771 visitor.doLong((LongField) f, false);
a61af66fc99e Initial load
duke
parents:
diff changeset
772 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
773 }
a61af66fc99e Initial load
duke
parents:
diff changeset
774 if (type.isShort()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
775 visitor.doShort((ShortField) f, false);
a61af66fc99e Initial load
duke
parents:
diff changeset
776 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
777 }
a61af66fc99e Initial load
duke
parents:
diff changeset
778 if (type.isBoolean()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
779 visitor.doBoolean((BooleanField) f, false);
a61af66fc99e Initial load
duke
parents:
diff changeset
780 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
781 }
a61af66fc99e Initial load
duke
parents:
diff changeset
782 }
a61af66fc99e Initial load
duke
parents:
diff changeset
783
a61af66fc99e Initial load
duke
parents:
diff changeset
784 // Creates new field from index in fields TypeArray
a61af66fc99e Initial load
duke
parents:
diff changeset
785 private Field newField(int index) {
a61af66fc99e Initial load
duke
parents:
diff changeset
786 TypeArray fields = getFields();
a61af66fc99e Initial load
duke
parents:
diff changeset
787 short signatureIndex = fields.getShortAt(index + SIGNATURE_INDEX_OFFSET);
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1552
diff changeset
788 FieldType type = new FieldType(getConstants().getSymbolAt(signatureIndex));
0
a61af66fc99e Initial load
duke
parents:
diff changeset
789 if (type.isOop()) {
113
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
790 if (VM.getVM().isCompressedOopsEnabled()) {
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
791 return new NarrowOopField(this, index);
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
792 } else {
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
793 return new OopField(this, index);
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
794 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
795 }
a61af66fc99e Initial load
duke
parents:
diff changeset
796 if (type.isByte()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
797 return new ByteField(this, index);
a61af66fc99e Initial load
duke
parents:
diff changeset
798 }
a61af66fc99e Initial load
duke
parents:
diff changeset
799 if (type.isChar()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
800 return new CharField(this, index);
a61af66fc99e Initial load
duke
parents:
diff changeset
801 }
a61af66fc99e Initial load
duke
parents:
diff changeset
802 if (type.isDouble()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
803 return new DoubleField(this, index);
a61af66fc99e Initial load
duke
parents:
diff changeset
804 }
a61af66fc99e Initial load
duke
parents:
diff changeset
805 if (type.isFloat()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
806 return new FloatField(this, index);
a61af66fc99e Initial load
duke
parents:
diff changeset
807 }
a61af66fc99e Initial load
duke
parents:
diff changeset
808 if (type.isInt()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
809 return new IntField(this, index);
a61af66fc99e Initial load
duke
parents:
diff changeset
810 }
a61af66fc99e Initial load
duke
parents:
diff changeset
811 if (type.isLong()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
812 return new LongField(this, index);
a61af66fc99e Initial load
duke
parents:
diff changeset
813 }
a61af66fc99e Initial load
duke
parents:
diff changeset
814 if (type.isShort()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
815 return new ShortField(this, index);
a61af66fc99e Initial load
duke
parents:
diff changeset
816 }
a61af66fc99e Initial load
duke
parents:
diff changeset
817 if (type.isBoolean()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
818 return new BooleanField(this, index);
a61af66fc99e Initial load
duke
parents:
diff changeset
819 }
a61af66fc99e Initial load
duke
parents:
diff changeset
820 throw new RuntimeException("Illegal field type at index " + index);
a61af66fc99e Initial load
duke
parents:
diff changeset
821 }
a61af66fc99e Initial load
duke
parents:
diff changeset
822
a61af66fc99e Initial load
duke
parents:
diff changeset
823 private static Method findMethod(ObjArray methods, Symbol name, Symbol signature) {
a61af66fc99e Initial load
duke
parents:
diff changeset
824 int len = (int) methods.getLength();
a61af66fc99e Initial load
duke
parents:
diff changeset
825 // methods are sorted, so do binary search
a61af66fc99e Initial load
duke
parents:
diff changeset
826 int l = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
827 int h = len - 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
828 while (l <= h) {
a61af66fc99e Initial load
duke
parents:
diff changeset
829 int mid = (l + h) >> 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
830 Method m = (Method) methods.getObjAt(mid);
a61af66fc99e Initial load
duke
parents:
diff changeset
831 int res = m.getName().fastCompare(name);
a61af66fc99e Initial load
duke
parents:
diff changeset
832 if (res == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
833 // found matching name; do linear search to find matching signature
a61af66fc99e Initial load
duke
parents:
diff changeset
834 // first, quick check for common case
a61af66fc99e Initial load
duke
parents:
diff changeset
835 if (m.getSignature().equals(signature)) return m;
a61af66fc99e Initial load
duke
parents:
diff changeset
836 // search downwards through overloaded methods
a61af66fc99e Initial load
duke
parents:
diff changeset
837 int i;
a61af66fc99e Initial load
duke
parents:
diff changeset
838 for (i = mid - 1; i >= l; i--) {
a61af66fc99e Initial load
duke
parents:
diff changeset
839 Method m1 = (Method) methods.getObjAt(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
840 if (!m1.getName().equals(name)) break;
a61af66fc99e Initial load
duke
parents:
diff changeset
841 if (m1.getSignature().equals(signature)) return m1;
a61af66fc99e Initial load
duke
parents:
diff changeset
842 }
a61af66fc99e Initial load
duke
parents:
diff changeset
843 // search upwards
a61af66fc99e Initial load
duke
parents:
diff changeset
844 for (i = mid + 1; i <= h; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
845 Method m1 = (Method) methods.getObjAt(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
846 if (!m1.getName().equals(name)) break;
a61af66fc99e Initial load
duke
parents:
diff changeset
847 if (m1.getSignature().equals(signature)) return m1;
a61af66fc99e Initial load
duke
parents:
diff changeset
848 }
a61af66fc99e Initial load
duke
parents:
diff changeset
849 // not found
a61af66fc99e Initial load
duke
parents:
diff changeset
850 if (Assert.ASSERTS_ENABLED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
851 int index = linearSearch(methods, name, signature);
a61af66fc99e Initial load
duke
parents:
diff changeset
852 if (index != -1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
853 throw new DebuggerException("binary search bug: should have found entry " + index);
a61af66fc99e Initial load
duke
parents:
diff changeset
854 }
a61af66fc99e Initial load
duke
parents:
diff changeset
855 }
a61af66fc99e Initial load
duke
parents:
diff changeset
856 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
857 } else if (res < 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
858 l = mid + 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
859 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
860 h = mid - 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
861 }
a61af66fc99e Initial load
duke
parents:
diff changeset
862 }
a61af66fc99e Initial load
duke
parents:
diff changeset
863 if (Assert.ASSERTS_ENABLED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
864 int index = linearSearch(methods, name, signature);
a61af66fc99e Initial load
duke
parents:
diff changeset
865 if (index != -1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
866 throw new DebuggerException("binary search bug: should have found entry " + index);
a61af66fc99e Initial load
duke
parents:
diff changeset
867 }
a61af66fc99e Initial load
duke
parents:
diff changeset
868 }
a61af66fc99e Initial load
duke
parents:
diff changeset
869 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
870 }
a61af66fc99e Initial load
duke
parents:
diff changeset
871
a61af66fc99e Initial load
duke
parents:
diff changeset
872 private static int linearSearch(ObjArray methods, Symbol name, Symbol signature) {
a61af66fc99e Initial load
duke
parents:
diff changeset
873 int len = (int) methods.getLength();
a61af66fc99e Initial load
duke
parents:
diff changeset
874 for (int index = 0; index < len; index++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
875 Method m = (Method) methods.getObjAt(index);
a61af66fc99e Initial load
duke
parents:
diff changeset
876 if (m.getSignature().equals(signature) && m.getName().equals(name)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
877 return index;
a61af66fc99e Initial load
duke
parents:
diff changeset
878 }
a61af66fc99e Initial load
duke
parents:
diff changeset
879 }
a61af66fc99e Initial load
duke
parents:
diff changeset
880 return -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
881 }
a61af66fc99e Initial load
duke
parents:
diff changeset
882 }