annotate src/share/vm/ci/ciInstanceKlass.cpp @ 0:a61af66fc99e jdk7-b24

Initial load
author duke
date Sat, 01 Dec 2007 00:00:00 +0000
parents
children 52fed2ec0afb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
2 * Copyright 1999-2007 Sun Microsystems, Inc. All Rights Reserved.
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 *
a61af66fc99e Initial load
duke
parents:
diff changeset
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
a61af66fc99e Initial load
duke
parents:
diff changeset
20 * CA 95054 USA or visit www.sun.com if you need additional information or
a61af66fc99e Initial load
duke
parents:
diff changeset
21 * have any questions.
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 #include "incls/_precompiled.incl"
a61af66fc99e Initial load
duke
parents:
diff changeset
26 #include "incls/_ciInstanceKlass.cpp.incl"
a61af66fc99e Initial load
duke
parents:
diff changeset
27
a61af66fc99e Initial load
duke
parents:
diff changeset
28 // ciInstanceKlass
a61af66fc99e Initial load
duke
parents:
diff changeset
29 //
a61af66fc99e Initial load
duke
parents:
diff changeset
30 // This class represents a klassOop in the HotSpot virtual machine
a61af66fc99e Initial load
duke
parents:
diff changeset
31 // whose Klass part in an instanceKlass.
a61af66fc99e Initial load
duke
parents:
diff changeset
32
a61af66fc99e Initial load
duke
parents:
diff changeset
33 // ------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
34 // ciInstanceKlass::ciInstanceKlass
a61af66fc99e Initial load
duke
parents:
diff changeset
35 //
a61af66fc99e Initial load
duke
parents:
diff changeset
36 // Loaded instance klass.
a61af66fc99e Initial load
duke
parents:
diff changeset
37 ciInstanceKlass::ciInstanceKlass(KlassHandle h_k) : ciKlass(h_k) {
a61af66fc99e Initial load
duke
parents:
diff changeset
38 assert(get_Klass()->oop_is_instance(), "wrong type");
a61af66fc99e Initial load
duke
parents:
diff changeset
39 instanceKlass* ik = get_instanceKlass();
a61af66fc99e Initial load
duke
parents:
diff changeset
40
a61af66fc99e Initial load
duke
parents:
diff changeset
41 AccessFlags access_flags = ik->access_flags();
a61af66fc99e Initial load
duke
parents:
diff changeset
42 _flags = ciFlags(access_flags);
a61af66fc99e Initial load
duke
parents:
diff changeset
43 _has_finalizer = access_flags.has_finalizer();
a61af66fc99e Initial load
duke
parents:
diff changeset
44 _has_subklass = ik->subklass() != NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
45 _is_initialized = ik->is_initialized();
a61af66fc99e Initial load
duke
parents:
diff changeset
46 // Next line must follow and use the result of the previous line:
a61af66fc99e Initial load
duke
parents:
diff changeset
47 _is_linked = _is_initialized || ik->is_linked();
a61af66fc99e Initial load
duke
parents:
diff changeset
48 _nonstatic_field_size = ik->nonstatic_field_size();
a61af66fc99e Initial load
duke
parents:
diff changeset
49 _nonstatic_fields = NULL; // initialized lazily by compute_nonstatic_fields:
a61af66fc99e Initial load
duke
parents:
diff changeset
50
a61af66fc99e Initial load
duke
parents:
diff changeset
51 _nof_implementors = ik->nof_implementors();
a61af66fc99e Initial load
duke
parents:
diff changeset
52 for (int i = 0; i < implementors_limit; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
53 _implementors[i] = NULL; // we will fill these lazily
a61af66fc99e Initial load
duke
parents:
diff changeset
54 }
a61af66fc99e Initial load
duke
parents:
diff changeset
55
a61af66fc99e Initial load
duke
parents:
diff changeset
56 Thread *thread = Thread::current();
a61af66fc99e Initial load
duke
parents:
diff changeset
57 if (ciObjectFactory::is_initialized()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
58 _loader = JNIHandles::make_local(thread, ik->class_loader());
a61af66fc99e Initial load
duke
parents:
diff changeset
59 _protection_domain = JNIHandles::make_local(thread,
a61af66fc99e Initial load
duke
parents:
diff changeset
60 ik->protection_domain());
a61af66fc99e Initial load
duke
parents:
diff changeset
61 _is_shared = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
62 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
63 Handle h_loader(thread, ik->class_loader());
a61af66fc99e Initial load
duke
parents:
diff changeset
64 Handle h_protection_domain(thread, ik->protection_domain());
a61af66fc99e Initial load
duke
parents:
diff changeset
65 _loader = JNIHandles::make_global(h_loader);
a61af66fc99e Initial load
duke
parents:
diff changeset
66 _protection_domain = JNIHandles::make_global(h_protection_domain);
a61af66fc99e Initial load
duke
parents:
diff changeset
67 _is_shared = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
68 }
a61af66fc99e Initial load
duke
parents:
diff changeset
69
a61af66fc99e Initial load
duke
parents:
diff changeset
70 // Lazy fields get filled in only upon request.
a61af66fc99e Initial load
duke
parents:
diff changeset
71 _super = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
72 _java_mirror = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
73
a61af66fc99e Initial load
duke
parents:
diff changeset
74 if (is_shared()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
75 if (h_k() != SystemDictionary::object_klass()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
76 super();
a61af66fc99e Initial load
duke
parents:
diff changeset
77 }
a61af66fc99e Initial load
duke
parents:
diff changeset
78 java_mirror();
a61af66fc99e Initial load
duke
parents:
diff changeset
79 //compute_nonstatic_fields(); // done outside of constructor
a61af66fc99e Initial load
duke
parents:
diff changeset
80 }
a61af66fc99e Initial load
duke
parents:
diff changeset
81
a61af66fc99e Initial load
duke
parents:
diff changeset
82 _field_cache = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
83 }
a61af66fc99e Initial load
duke
parents:
diff changeset
84
a61af66fc99e Initial load
duke
parents:
diff changeset
85 // Version for unloaded classes:
a61af66fc99e Initial load
duke
parents:
diff changeset
86 ciInstanceKlass::ciInstanceKlass(ciSymbol* name,
a61af66fc99e Initial load
duke
parents:
diff changeset
87 jobject loader, jobject protection_domain)
a61af66fc99e Initial load
duke
parents:
diff changeset
88 : ciKlass(name, ciInstanceKlassKlass::make())
a61af66fc99e Initial load
duke
parents:
diff changeset
89 {
a61af66fc99e Initial load
duke
parents:
diff changeset
90 assert(name->byte_at(0) != '[', "not an instance klass");
a61af66fc99e Initial load
duke
parents:
diff changeset
91 _is_initialized = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
92 _is_linked = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
93 _nonstatic_field_size = -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
94 _nonstatic_fields = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
95 _nof_implementors = -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
96 _loader = loader;
a61af66fc99e Initial load
duke
parents:
diff changeset
97 _protection_domain = protection_domain;
a61af66fc99e Initial load
duke
parents:
diff changeset
98 _is_shared = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
99 _super = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
100 _java_mirror = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
101 _field_cache = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
102 }
a61af66fc99e Initial load
duke
parents:
diff changeset
103
a61af66fc99e Initial load
duke
parents:
diff changeset
104
a61af66fc99e Initial load
duke
parents:
diff changeset
105
a61af66fc99e Initial load
duke
parents:
diff changeset
106 // ------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
107 // ciInstanceKlass::compute_shared_is_initialized
a61af66fc99e Initial load
duke
parents:
diff changeset
108 bool ciInstanceKlass::compute_shared_is_initialized() {
a61af66fc99e Initial load
duke
parents:
diff changeset
109 GUARDED_VM_ENTRY(
a61af66fc99e Initial load
duke
parents:
diff changeset
110 instanceKlass* ik = get_instanceKlass();
a61af66fc99e Initial load
duke
parents:
diff changeset
111 _is_initialized = ik->is_initialized();
a61af66fc99e Initial load
duke
parents:
diff changeset
112 return _is_initialized;
a61af66fc99e Initial load
duke
parents:
diff changeset
113 )
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 // ciInstanceKlass::compute_shared_is_linked
a61af66fc99e Initial load
duke
parents:
diff changeset
118 bool ciInstanceKlass::compute_shared_is_linked() {
a61af66fc99e Initial load
duke
parents:
diff changeset
119 GUARDED_VM_ENTRY(
a61af66fc99e Initial load
duke
parents:
diff changeset
120 instanceKlass* ik = get_instanceKlass();
a61af66fc99e Initial load
duke
parents:
diff changeset
121 _is_linked = ik->is_linked();
a61af66fc99e Initial load
duke
parents:
diff changeset
122 return _is_linked;
a61af66fc99e Initial load
duke
parents:
diff changeset
123 )
a61af66fc99e Initial load
duke
parents:
diff changeset
124 }
a61af66fc99e Initial load
duke
parents:
diff changeset
125
a61af66fc99e Initial load
duke
parents:
diff changeset
126 // ------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
127 // ciInstanceKlass::compute_shared_has_subklass
a61af66fc99e Initial load
duke
parents:
diff changeset
128 bool ciInstanceKlass::compute_shared_has_subklass() {
a61af66fc99e Initial load
duke
parents:
diff changeset
129 GUARDED_VM_ENTRY(
a61af66fc99e Initial load
duke
parents:
diff changeset
130 instanceKlass* ik = get_instanceKlass();
a61af66fc99e Initial load
duke
parents:
diff changeset
131 _has_subklass = ik->subklass() != NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
132 return _has_subklass;
a61af66fc99e Initial load
duke
parents:
diff changeset
133 )
a61af66fc99e Initial load
duke
parents:
diff changeset
134 }
a61af66fc99e Initial load
duke
parents:
diff changeset
135
a61af66fc99e Initial load
duke
parents:
diff changeset
136 // ------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
137 // ciInstanceKlass::compute_shared_nof_implementors
a61af66fc99e Initial load
duke
parents:
diff changeset
138 int ciInstanceKlass::compute_shared_nof_implementors() {
a61af66fc99e Initial load
duke
parents:
diff changeset
139 // We requery this property, since it is a very old ciObject.
a61af66fc99e Initial load
duke
parents:
diff changeset
140 GUARDED_VM_ENTRY(
a61af66fc99e Initial load
duke
parents:
diff changeset
141 instanceKlass* ik = get_instanceKlass();
a61af66fc99e Initial load
duke
parents:
diff changeset
142 _nof_implementors = ik->nof_implementors();
a61af66fc99e Initial load
duke
parents:
diff changeset
143 return _nof_implementors;
a61af66fc99e Initial load
duke
parents:
diff changeset
144 )
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 // ciInstanceKlass::loader
a61af66fc99e Initial load
duke
parents:
diff changeset
149 oop ciInstanceKlass::loader() {
a61af66fc99e Initial load
duke
parents:
diff changeset
150 ASSERT_IN_VM;
a61af66fc99e Initial load
duke
parents:
diff changeset
151 return JNIHandles::resolve(_loader);
a61af66fc99e Initial load
duke
parents:
diff changeset
152 }
a61af66fc99e Initial load
duke
parents:
diff changeset
153
a61af66fc99e Initial load
duke
parents:
diff changeset
154 // ------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
155 // ciInstanceKlass::loader_handle
a61af66fc99e Initial load
duke
parents:
diff changeset
156 jobject ciInstanceKlass::loader_handle() {
a61af66fc99e Initial load
duke
parents:
diff changeset
157 return _loader;
a61af66fc99e Initial load
duke
parents:
diff changeset
158 }
a61af66fc99e Initial load
duke
parents:
diff changeset
159
a61af66fc99e Initial load
duke
parents:
diff changeset
160 // ------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
161 // ciInstanceKlass::protection_domain
a61af66fc99e Initial load
duke
parents:
diff changeset
162 oop ciInstanceKlass::protection_domain() {
a61af66fc99e Initial load
duke
parents:
diff changeset
163 ASSERT_IN_VM;
a61af66fc99e Initial load
duke
parents:
diff changeset
164 return JNIHandles::resolve(_protection_domain);
a61af66fc99e Initial load
duke
parents:
diff changeset
165 }
a61af66fc99e Initial load
duke
parents:
diff changeset
166
a61af66fc99e Initial load
duke
parents:
diff changeset
167 // ------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
168 // ciInstanceKlass::protection_domain_handle
a61af66fc99e Initial load
duke
parents:
diff changeset
169 jobject ciInstanceKlass::protection_domain_handle() {
a61af66fc99e Initial load
duke
parents:
diff changeset
170 return _protection_domain;
a61af66fc99e Initial load
duke
parents:
diff changeset
171 }
a61af66fc99e Initial load
duke
parents:
diff changeset
172
a61af66fc99e Initial load
duke
parents:
diff changeset
173 // ------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
174 // ciInstanceKlass::field_cache
a61af66fc99e Initial load
duke
parents:
diff changeset
175 //
a61af66fc99e Initial load
duke
parents:
diff changeset
176 // Get the field cache associated with this klass.
a61af66fc99e Initial load
duke
parents:
diff changeset
177 ciConstantPoolCache* ciInstanceKlass::field_cache() {
a61af66fc99e Initial load
duke
parents:
diff changeset
178 if (is_shared()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
179 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
180 }
a61af66fc99e Initial load
duke
parents:
diff changeset
181 if (_field_cache == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
182 assert(!is_java_lang_Object(), "Object has no fields");
a61af66fc99e Initial load
duke
parents:
diff changeset
183 Arena* arena = CURRENT_ENV->arena();
a61af66fc99e Initial load
duke
parents:
diff changeset
184 _field_cache = new (arena) ciConstantPoolCache(arena, 5);
a61af66fc99e Initial load
duke
parents:
diff changeset
185 }
a61af66fc99e Initial load
duke
parents:
diff changeset
186 return _field_cache;
a61af66fc99e Initial load
duke
parents:
diff changeset
187 }
a61af66fc99e Initial load
duke
parents:
diff changeset
188
a61af66fc99e Initial load
duke
parents:
diff changeset
189 // ------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
190 // ciInstanceKlass::get_canonical_holder
a61af66fc99e Initial load
duke
parents:
diff changeset
191 //
a61af66fc99e Initial load
duke
parents:
diff changeset
192 ciInstanceKlass* ciInstanceKlass::get_canonical_holder(int offset) {
a61af66fc99e Initial load
duke
parents:
diff changeset
193 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
194 if (!(offset >= 0 && offset < layout_helper())) {
a61af66fc99e Initial load
duke
parents:
diff changeset
195 tty->print("*** get_canonical_holder(%d) on ", offset);
a61af66fc99e Initial load
duke
parents:
diff changeset
196 this->print();
a61af66fc99e Initial load
duke
parents:
diff changeset
197 tty->print_cr(" ***");
a61af66fc99e Initial load
duke
parents:
diff changeset
198 };
a61af66fc99e Initial load
duke
parents:
diff changeset
199 assert(offset >= 0 && offset < layout_helper(), "offset must be tame");
a61af66fc99e Initial load
duke
parents:
diff changeset
200 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
201
a61af66fc99e Initial load
duke
parents:
diff changeset
202 if (offset < (instanceOopDesc::header_size() * wordSize)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
203 // All header offsets belong properly to java/lang/Object.
a61af66fc99e Initial load
duke
parents:
diff changeset
204 return CURRENT_ENV->Object_klass();
a61af66fc99e Initial load
duke
parents:
diff changeset
205 }
a61af66fc99e Initial load
duke
parents:
diff changeset
206
a61af66fc99e Initial load
duke
parents:
diff changeset
207 ciInstanceKlass* self = this;
a61af66fc99e Initial load
duke
parents:
diff changeset
208 for (;;) {
a61af66fc99e Initial load
duke
parents:
diff changeset
209 assert(self->is_loaded(), "must be loaded to have size");
a61af66fc99e Initial load
duke
parents:
diff changeset
210 ciInstanceKlass* super = self->super();
a61af66fc99e Initial load
duke
parents:
diff changeset
211 if (super == NULL || !super->contains_field_offset(offset)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
212 return self;
a61af66fc99e Initial load
duke
parents:
diff changeset
213 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
214 self = super; // return super->get_canonical_holder(offset)
a61af66fc99e Initial load
duke
parents:
diff changeset
215 }
a61af66fc99e Initial load
duke
parents:
diff changeset
216 }
a61af66fc99e Initial load
duke
parents:
diff changeset
217 }
a61af66fc99e Initial load
duke
parents:
diff changeset
218
a61af66fc99e Initial load
duke
parents:
diff changeset
219 // ------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
220 // ciInstanceKlass::is_java_lang_Object
a61af66fc99e Initial load
duke
parents:
diff changeset
221 //
a61af66fc99e Initial load
duke
parents:
diff changeset
222 // Is this klass java.lang.Object?
a61af66fc99e Initial load
duke
parents:
diff changeset
223 bool ciInstanceKlass::is_java_lang_Object() {
a61af66fc99e Initial load
duke
parents:
diff changeset
224 return equals(CURRENT_ENV->Object_klass());
a61af66fc99e Initial load
duke
parents:
diff changeset
225 }
a61af66fc99e Initial load
duke
parents:
diff changeset
226
a61af66fc99e Initial load
duke
parents:
diff changeset
227 // ------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
228 // ciInstanceKlass::uses_default_loader
a61af66fc99e Initial load
duke
parents:
diff changeset
229 bool ciInstanceKlass::uses_default_loader() {
a61af66fc99e Initial load
duke
parents:
diff changeset
230 VM_ENTRY_MARK;
a61af66fc99e Initial load
duke
parents:
diff changeset
231 return loader() == NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
232 }
a61af66fc99e Initial load
duke
parents:
diff changeset
233
a61af66fc99e Initial load
duke
parents:
diff changeset
234 // ------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
235 // ciInstanceKlass::print_impl
a61af66fc99e Initial load
duke
parents:
diff changeset
236 //
a61af66fc99e Initial load
duke
parents:
diff changeset
237 // Implementation of the print method.
a61af66fc99e Initial load
duke
parents:
diff changeset
238 void ciInstanceKlass::print_impl(outputStream* st) {
a61af66fc99e Initial load
duke
parents:
diff changeset
239 ciKlass::print_impl(st);
a61af66fc99e Initial load
duke
parents:
diff changeset
240 GUARDED_VM_ENTRY(st->print(" loader=0x%x", (address)loader());)
a61af66fc99e Initial load
duke
parents:
diff changeset
241 if (is_loaded()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
242 st->print(" loaded=true initialized=%s finalized=%s subklass=%s size=%d flags=",
a61af66fc99e Initial load
duke
parents:
diff changeset
243 bool_to_str(is_initialized()),
a61af66fc99e Initial load
duke
parents:
diff changeset
244 bool_to_str(has_finalizer()),
a61af66fc99e Initial load
duke
parents:
diff changeset
245 bool_to_str(has_subklass()),
a61af66fc99e Initial load
duke
parents:
diff changeset
246 layout_helper());
a61af66fc99e Initial load
duke
parents:
diff changeset
247
a61af66fc99e Initial load
duke
parents:
diff changeset
248 _flags.print_klass_flags();
a61af66fc99e Initial load
duke
parents:
diff changeset
249
a61af66fc99e Initial load
duke
parents:
diff changeset
250 if (_super) {
a61af66fc99e Initial load
duke
parents:
diff changeset
251 st->print(" super=");
a61af66fc99e Initial load
duke
parents:
diff changeset
252 _super->print_name();
a61af66fc99e Initial load
duke
parents:
diff changeset
253 }
a61af66fc99e Initial load
duke
parents:
diff changeset
254 if (_java_mirror) {
a61af66fc99e Initial load
duke
parents:
diff changeset
255 st->print(" mirror=PRESENT");
a61af66fc99e Initial load
duke
parents:
diff changeset
256 }
a61af66fc99e Initial load
duke
parents:
diff changeset
257 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
258 st->print(" loaded=false");
a61af66fc99e Initial load
duke
parents:
diff changeset
259 }
a61af66fc99e Initial load
duke
parents:
diff changeset
260 }
a61af66fc99e Initial load
duke
parents:
diff changeset
261
a61af66fc99e Initial load
duke
parents:
diff changeset
262 // ------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
263 // ciInstanceKlass::super
a61af66fc99e Initial load
duke
parents:
diff changeset
264 //
a61af66fc99e Initial load
duke
parents:
diff changeset
265 // Get the superklass of this klass.
a61af66fc99e Initial load
duke
parents:
diff changeset
266 ciInstanceKlass* ciInstanceKlass::super() {
a61af66fc99e Initial load
duke
parents:
diff changeset
267 assert(is_loaded(), "must be loaded");
a61af66fc99e Initial load
duke
parents:
diff changeset
268 if (_super == NULL && !is_java_lang_Object()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
269 GUARDED_VM_ENTRY(
a61af66fc99e Initial load
duke
parents:
diff changeset
270 klassOop super_klass = get_instanceKlass()->super();
a61af66fc99e Initial load
duke
parents:
diff changeset
271 _super = CURRENT_ENV->get_object(super_klass)->as_instance_klass();
a61af66fc99e Initial load
duke
parents:
diff changeset
272 )
a61af66fc99e Initial load
duke
parents:
diff changeset
273 }
a61af66fc99e Initial load
duke
parents:
diff changeset
274 return _super;
a61af66fc99e Initial load
duke
parents:
diff changeset
275 }
a61af66fc99e Initial load
duke
parents:
diff changeset
276
a61af66fc99e Initial load
duke
parents:
diff changeset
277 // ------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
278 // ciInstanceKlass::java_mirror
a61af66fc99e Initial load
duke
parents:
diff changeset
279 //
a61af66fc99e Initial load
duke
parents:
diff changeset
280 // Get the instance of java.lang.Class corresponding to this klass.
a61af66fc99e Initial load
duke
parents:
diff changeset
281 ciInstance* ciInstanceKlass::java_mirror() {
a61af66fc99e Initial load
duke
parents:
diff changeset
282 assert(is_loaded(), "must be loaded");
a61af66fc99e Initial load
duke
parents:
diff changeset
283 if (_java_mirror == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
284 _java_mirror = ciKlass::java_mirror();
a61af66fc99e Initial load
duke
parents:
diff changeset
285 }
a61af66fc99e Initial load
duke
parents:
diff changeset
286 return _java_mirror;
a61af66fc99e Initial load
duke
parents:
diff changeset
287 }
a61af66fc99e Initial load
duke
parents:
diff changeset
288
a61af66fc99e Initial load
duke
parents:
diff changeset
289 // ------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
290 // ciInstanceKlass::unique_concrete_subklass
a61af66fc99e Initial load
duke
parents:
diff changeset
291 ciInstanceKlass* ciInstanceKlass::unique_concrete_subklass() {
a61af66fc99e Initial load
duke
parents:
diff changeset
292 if (!is_loaded()) return NULL; // No change if class is not loaded
a61af66fc99e Initial load
duke
parents:
diff changeset
293 if (!is_abstract()) return NULL; // Only applies to abstract classes.
a61af66fc99e Initial load
duke
parents:
diff changeset
294 if (!has_subklass()) return NULL; // Must have at least one subklass.
a61af66fc99e Initial load
duke
parents:
diff changeset
295 VM_ENTRY_MARK;
a61af66fc99e Initial load
duke
parents:
diff changeset
296 instanceKlass* ik = get_instanceKlass();
a61af66fc99e Initial load
duke
parents:
diff changeset
297 Klass* up = ik->up_cast_abstract();
a61af66fc99e Initial load
duke
parents:
diff changeset
298 assert(up->oop_is_instance(), "must be instanceKlass");
a61af66fc99e Initial load
duke
parents:
diff changeset
299 if (ik == up) {
a61af66fc99e Initial load
duke
parents:
diff changeset
300 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
301 }
a61af66fc99e Initial load
duke
parents:
diff changeset
302 return CURRENT_THREAD_ENV->get_object(up->as_klassOop())->as_instance_klass();
a61af66fc99e Initial load
duke
parents:
diff changeset
303 }
a61af66fc99e Initial load
duke
parents:
diff changeset
304
a61af66fc99e Initial load
duke
parents:
diff changeset
305 // ------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
306 // ciInstanceKlass::has_finalizable_subclass
a61af66fc99e Initial load
duke
parents:
diff changeset
307 bool ciInstanceKlass::has_finalizable_subclass() {
a61af66fc99e Initial load
duke
parents:
diff changeset
308 if (!is_loaded()) return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
309 VM_ENTRY_MARK;
a61af66fc99e Initial load
duke
parents:
diff changeset
310 return Dependencies::find_finalizable_subclass(get_instanceKlass()) != NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
311 }
a61af66fc99e Initial load
duke
parents:
diff changeset
312
a61af66fc99e Initial load
duke
parents:
diff changeset
313 // ------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
314 // ciInstanceKlass::get_field_by_offset
a61af66fc99e Initial load
duke
parents:
diff changeset
315 ciField* ciInstanceKlass::get_field_by_offset(int field_offset, bool is_static) {
a61af66fc99e Initial load
duke
parents:
diff changeset
316 if (!is_static) {
a61af66fc99e Initial load
duke
parents:
diff changeset
317 for (int i = 0, len = nof_nonstatic_fields(); i < len; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
318 ciField* field = _nonstatic_fields->at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
319 int field_off = field->offset_in_bytes();
a61af66fc99e Initial load
duke
parents:
diff changeset
320 if (field_off == field_offset)
a61af66fc99e Initial load
duke
parents:
diff changeset
321 return field;
a61af66fc99e Initial load
duke
parents:
diff changeset
322 if (field_off > field_offset)
a61af66fc99e Initial load
duke
parents:
diff changeset
323 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
324 // could do binary search or check bins, but probably not worth it
a61af66fc99e Initial load
duke
parents:
diff changeset
325 }
a61af66fc99e Initial load
duke
parents:
diff changeset
326 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
327 }
a61af66fc99e Initial load
duke
parents:
diff changeset
328 VM_ENTRY_MARK;
a61af66fc99e Initial load
duke
parents:
diff changeset
329 instanceKlass* k = get_instanceKlass();
a61af66fc99e Initial load
duke
parents:
diff changeset
330 fieldDescriptor fd;
a61af66fc99e Initial load
duke
parents:
diff changeset
331 if (!k->find_field_from_offset(field_offset, is_static, &fd)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
332 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
333 }
a61af66fc99e Initial load
duke
parents:
diff changeset
334 ciField* field = new (CURRENT_THREAD_ENV->arena()) ciField(&fd);
a61af66fc99e Initial load
duke
parents:
diff changeset
335 return field;
a61af66fc99e Initial load
duke
parents:
diff changeset
336 }
a61af66fc99e Initial load
duke
parents:
diff changeset
337
a61af66fc99e Initial load
duke
parents:
diff changeset
338 static int sort_field_by_offset(ciField** a, ciField** b) {
a61af66fc99e Initial load
duke
parents:
diff changeset
339 return (*a)->offset_in_bytes() - (*b)->offset_in_bytes();
a61af66fc99e Initial load
duke
parents:
diff changeset
340 // (no worries about 32-bit overflow...)
a61af66fc99e Initial load
duke
parents:
diff changeset
341 }
a61af66fc99e Initial load
duke
parents:
diff changeset
342
a61af66fc99e Initial load
duke
parents:
diff changeset
343 // ------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
344 // ciInstanceKlass::compute_nonstatic_fields
a61af66fc99e Initial load
duke
parents:
diff changeset
345 int ciInstanceKlass::compute_nonstatic_fields() {
a61af66fc99e Initial load
duke
parents:
diff changeset
346 assert(is_loaded(), "must be loaded");
a61af66fc99e Initial load
duke
parents:
diff changeset
347
a61af66fc99e Initial load
duke
parents:
diff changeset
348 if (_nonstatic_fields != NULL)
a61af66fc99e Initial load
duke
parents:
diff changeset
349 return _nonstatic_fields->length();
a61af66fc99e Initial load
duke
parents:
diff changeset
350
a61af66fc99e Initial load
duke
parents:
diff changeset
351 // Size in bytes of my fields, including inherited fields.
a61af66fc99e Initial load
duke
parents:
diff changeset
352 // About equal to size_helper() - sizeof(oopDesc).
a61af66fc99e Initial load
duke
parents:
diff changeset
353 int fsize = nonstatic_field_size() * wordSize;
a61af66fc99e Initial load
duke
parents:
diff changeset
354 if (fsize == 0) { // easy shortcut
a61af66fc99e Initial load
duke
parents:
diff changeset
355 Arena* arena = CURRENT_ENV->arena();
a61af66fc99e Initial load
duke
parents:
diff changeset
356 _nonstatic_fields = new (arena) GrowableArray<ciField*>(arena, 0, 0, NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
357 return 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
358 }
a61af66fc99e Initial load
duke
parents:
diff changeset
359 assert(!is_java_lang_Object(), "bootstrap OK");
a61af66fc99e Initial load
duke
parents:
diff changeset
360
a61af66fc99e Initial load
duke
parents:
diff changeset
361 ciInstanceKlass* super = this->super();
a61af66fc99e Initial load
duke
parents:
diff changeset
362 int super_fsize = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
363 int super_flen = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
364 GrowableArray<ciField*>* super_fields = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
365 if (super != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
366 super_fsize = super->nonstatic_field_size() * wordSize;
a61af66fc99e Initial load
duke
parents:
diff changeset
367 super_flen = super->nof_nonstatic_fields();
a61af66fc99e Initial load
duke
parents:
diff changeset
368 super_fields = super->_nonstatic_fields;
a61af66fc99e Initial load
duke
parents:
diff changeset
369 assert(super_flen == 0 || super_fields != NULL, "first get nof_fields");
a61af66fc99e Initial load
duke
parents:
diff changeset
370 }
a61af66fc99e Initial load
duke
parents:
diff changeset
371
a61af66fc99e Initial load
duke
parents:
diff changeset
372 // See if I am no larger than my super; if so, I can use his fields.
a61af66fc99e Initial load
duke
parents:
diff changeset
373 if (fsize == super_fsize) {
a61af66fc99e Initial load
duke
parents:
diff changeset
374 _nonstatic_fields = super_fields;
a61af66fc99e Initial load
duke
parents:
diff changeset
375 return super_fields->length();
a61af66fc99e Initial load
duke
parents:
diff changeset
376 }
a61af66fc99e Initial load
duke
parents:
diff changeset
377
a61af66fc99e Initial load
duke
parents:
diff changeset
378 GrowableArray<ciField*>* fields = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
379 GUARDED_VM_ENTRY({
a61af66fc99e Initial load
duke
parents:
diff changeset
380 fields = compute_nonstatic_fields_impl(super_fields);
a61af66fc99e Initial load
duke
parents:
diff changeset
381 });
a61af66fc99e Initial load
duke
parents:
diff changeset
382
a61af66fc99e Initial load
duke
parents:
diff changeset
383 if (fields == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
384 // This can happen if this class (java.lang.Class) has invisible fields.
a61af66fc99e Initial load
duke
parents:
diff changeset
385 _nonstatic_fields = super_fields;
a61af66fc99e Initial load
duke
parents:
diff changeset
386 return super_fields->length();
a61af66fc99e Initial load
duke
parents:
diff changeset
387 }
a61af66fc99e Initial load
duke
parents:
diff changeset
388
a61af66fc99e Initial load
duke
parents:
diff changeset
389 int flen = fields->length();
a61af66fc99e Initial load
duke
parents:
diff changeset
390
a61af66fc99e Initial load
duke
parents:
diff changeset
391 // Now sort them by offset, ascending.
a61af66fc99e Initial load
duke
parents:
diff changeset
392 // (In principle, they could mix with superclass fields.)
a61af66fc99e Initial load
duke
parents:
diff changeset
393 fields->sort(sort_field_by_offset);
a61af66fc99e Initial load
duke
parents:
diff changeset
394 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
395 int last_offset = sizeof(oopDesc);
a61af66fc99e Initial load
duke
parents:
diff changeset
396 for (int i = 0; i < fields->length(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
397 ciField* field = fields->at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
398 int offset = field->offset_in_bytes();
a61af66fc99e Initial load
duke
parents:
diff changeset
399 int size = (field->_type == NULL) ? oopSize : field->size_in_bytes();
a61af66fc99e Initial load
duke
parents:
diff changeset
400 assert(last_offset <= offset, "no field overlap");
a61af66fc99e Initial load
duke
parents:
diff changeset
401 if (last_offset > (int)sizeof(oopDesc))
a61af66fc99e Initial load
duke
parents:
diff changeset
402 assert((offset - last_offset) < BytesPerLong, "no big holes");
a61af66fc99e Initial load
duke
parents:
diff changeset
403 // Note: Two consecutive T_BYTE fields will be separated by wordSize-1
a61af66fc99e Initial load
duke
parents:
diff changeset
404 // padding bytes if one of them is declared by a superclass.
a61af66fc99e Initial load
duke
parents:
diff changeset
405 // This is a minor inefficiency classFileParser.cpp.
a61af66fc99e Initial load
duke
parents:
diff changeset
406 last_offset = offset + size;
a61af66fc99e Initial load
duke
parents:
diff changeset
407 }
a61af66fc99e Initial load
duke
parents:
diff changeset
408 assert(last_offset <= (int)sizeof(oopDesc) + fsize, "no overflow");
a61af66fc99e Initial load
duke
parents:
diff changeset
409 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
410
a61af66fc99e Initial load
duke
parents:
diff changeset
411 _nonstatic_fields = fields;
a61af66fc99e Initial load
duke
parents:
diff changeset
412 return flen;
a61af66fc99e Initial load
duke
parents:
diff changeset
413 }
a61af66fc99e Initial load
duke
parents:
diff changeset
414
a61af66fc99e Initial load
duke
parents:
diff changeset
415 GrowableArray<ciField*>*
a61af66fc99e Initial load
duke
parents:
diff changeset
416 ciInstanceKlass::compute_nonstatic_fields_impl(GrowableArray<ciField*>*
a61af66fc99e Initial load
duke
parents:
diff changeset
417 super_fields) {
a61af66fc99e Initial load
duke
parents:
diff changeset
418 ASSERT_IN_VM;
a61af66fc99e Initial load
duke
parents:
diff changeset
419 Arena* arena = CURRENT_ENV->arena();
a61af66fc99e Initial load
duke
parents:
diff changeset
420 int flen = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
421 GrowableArray<ciField*>* fields = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
422 instanceKlass* k = get_instanceKlass();
a61af66fc99e Initial load
duke
parents:
diff changeset
423 typeArrayOop fields_array = k->fields();
a61af66fc99e Initial load
duke
parents:
diff changeset
424 for (int pass = 0; pass <= 1; pass++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
425 for (int i = 0, alen = fields_array->length(); i < alen; i += instanceKlass::next_offset) {
a61af66fc99e Initial load
duke
parents:
diff changeset
426 fieldDescriptor fd;
a61af66fc99e Initial load
duke
parents:
diff changeset
427 fd.initialize(k->as_klassOop(), i);
a61af66fc99e Initial load
duke
parents:
diff changeset
428 if (fd.is_static()) continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
429 if (pass == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
430 flen += 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
431 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
432 ciField* field = new (arena) ciField(&fd);
a61af66fc99e Initial load
duke
parents:
diff changeset
433 fields->append(field);
a61af66fc99e Initial load
duke
parents:
diff changeset
434 }
a61af66fc99e Initial load
duke
parents:
diff changeset
435 }
a61af66fc99e Initial load
duke
parents:
diff changeset
436
a61af66fc99e Initial load
duke
parents:
diff changeset
437 // Between passes, allocate the array:
a61af66fc99e Initial load
duke
parents:
diff changeset
438 if (pass == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
439 if (flen == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
440 return NULL; // return nothing if none are locally declared
a61af66fc99e Initial load
duke
parents:
diff changeset
441 }
a61af66fc99e Initial load
duke
parents:
diff changeset
442 if (super_fields != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
443 flen += super_fields->length();
a61af66fc99e Initial load
duke
parents:
diff changeset
444 }
a61af66fc99e Initial load
duke
parents:
diff changeset
445 fields = new (arena) GrowableArray<ciField*>(arena, flen, 0, NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
446 if (super_fields != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
447 fields->appendAll(super_fields);
a61af66fc99e Initial load
duke
parents:
diff changeset
448 }
a61af66fc99e Initial load
duke
parents:
diff changeset
449 }
a61af66fc99e Initial load
duke
parents:
diff changeset
450 }
a61af66fc99e Initial load
duke
parents:
diff changeset
451 assert(fields->length() == flen, "sanity");
a61af66fc99e Initial load
duke
parents:
diff changeset
452 return fields;
a61af66fc99e Initial load
duke
parents:
diff changeset
453 }
a61af66fc99e Initial load
duke
parents:
diff changeset
454
a61af66fc99e Initial load
duke
parents:
diff changeset
455 // ------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
456 // ciInstanceKlass::find_method
a61af66fc99e Initial load
duke
parents:
diff changeset
457 //
a61af66fc99e Initial load
duke
parents:
diff changeset
458 // Find a method in this klass.
a61af66fc99e Initial load
duke
parents:
diff changeset
459 ciMethod* ciInstanceKlass::find_method(ciSymbol* name, ciSymbol* signature) {
a61af66fc99e Initial load
duke
parents:
diff changeset
460 VM_ENTRY_MARK;
a61af66fc99e Initial load
duke
parents:
diff changeset
461 instanceKlass* k = get_instanceKlass();
a61af66fc99e Initial load
duke
parents:
diff changeset
462 symbolOop name_sym = name->get_symbolOop();
a61af66fc99e Initial load
duke
parents:
diff changeset
463 symbolOop sig_sym= signature->get_symbolOop();
a61af66fc99e Initial load
duke
parents:
diff changeset
464
a61af66fc99e Initial load
duke
parents:
diff changeset
465 methodOop m = k->find_method(name_sym, sig_sym);
a61af66fc99e Initial load
duke
parents:
diff changeset
466 if (m == NULL) return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
467
a61af66fc99e Initial load
duke
parents:
diff changeset
468 return CURRENT_THREAD_ENV->get_object(m)->as_method();
a61af66fc99e Initial load
duke
parents:
diff changeset
469 }
a61af66fc99e Initial load
duke
parents:
diff changeset
470
a61af66fc99e Initial load
duke
parents:
diff changeset
471 // ------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
472 // ciInstanceKlass::is_leaf_type
a61af66fc99e Initial load
duke
parents:
diff changeset
473 bool ciInstanceKlass::is_leaf_type() {
a61af66fc99e Initial load
duke
parents:
diff changeset
474 assert(is_loaded(), "must be loaded");
a61af66fc99e Initial load
duke
parents:
diff changeset
475 if (is_shared()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
476 return is_final(); // approximately correct
a61af66fc99e Initial load
duke
parents:
diff changeset
477 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
478 return !_has_subklass && (_nof_implementors == 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
479 }
a61af66fc99e Initial load
duke
parents:
diff changeset
480 }
a61af66fc99e Initial load
duke
parents:
diff changeset
481
a61af66fc99e Initial load
duke
parents:
diff changeset
482 // ------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
483 // ciInstanceKlass::implementor
a61af66fc99e Initial load
duke
parents:
diff changeset
484 //
a61af66fc99e Initial load
duke
parents:
diff changeset
485 // Report an implementor of this interface.
a61af66fc99e Initial load
duke
parents:
diff changeset
486 // Returns NULL if exact information is not available.
a61af66fc99e Initial load
duke
parents:
diff changeset
487 // Note that there are various races here, since my copy
a61af66fc99e Initial load
duke
parents:
diff changeset
488 // of _nof_implementors might be out of date with respect
a61af66fc99e Initial load
duke
parents:
diff changeset
489 // to results returned by instanceKlass::implementor.
a61af66fc99e Initial load
duke
parents:
diff changeset
490 // This is OK, since any dependencies we decide to assert
a61af66fc99e Initial load
duke
parents:
diff changeset
491 // will be checked later under the Compile_lock.
a61af66fc99e Initial load
duke
parents:
diff changeset
492 ciInstanceKlass* ciInstanceKlass::implementor(int n) {
a61af66fc99e Initial load
duke
parents:
diff changeset
493 if (n > implementors_limit) {
a61af66fc99e Initial load
duke
parents:
diff changeset
494 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
495 }
a61af66fc99e Initial load
duke
parents:
diff changeset
496 ciInstanceKlass* impl = _implementors[n];
a61af66fc99e Initial load
duke
parents:
diff changeset
497 if (impl == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
498 if (_nof_implementors > implementors_limit) {
a61af66fc99e Initial load
duke
parents:
diff changeset
499 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
500 }
a61af66fc99e Initial load
duke
parents:
diff changeset
501 // Go into the VM to fetch the implementor.
a61af66fc99e Initial load
duke
parents:
diff changeset
502 {
a61af66fc99e Initial load
duke
parents:
diff changeset
503 VM_ENTRY_MARK;
a61af66fc99e Initial load
duke
parents:
diff changeset
504 klassOop k = get_instanceKlass()->implementor(n);
a61af66fc99e Initial load
duke
parents:
diff changeset
505 if (k != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
506 impl = CURRENT_THREAD_ENV->get_object(k)->as_instance_klass();
a61af66fc99e Initial load
duke
parents:
diff changeset
507 }
a61af66fc99e Initial load
duke
parents:
diff changeset
508 }
a61af66fc99e Initial load
duke
parents:
diff changeset
509 // Memoize this result.
a61af66fc99e Initial load
duke
parents:
diff changeset
510 if (!is_shared()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
511 _implementors[n] = (impl == NULL)? this: impl;
a61af66fc99e Initial load
duke
parents:
diff changeset
512 }
a61af66fc99e Initial load
duke
parents:
diff changeset
513 } else if (impl == this) {
a61af66fc99e Initial load
duke
parents:
diff changeset
514 impl = NULL; // memoized null result from a VM query
a61af66fc99e Initial load
duke
parents:
diff changeset
515 }
a61af66fc99e Initial load
duke
parents:
diff changeset
516 return impl;
a61af66fc99e Initial load
duke
parents:
diff changeset
517 }