author | lana |
Wed, 28 Dec 2011 10:51:24 -0800 | |
changeset 11360 | cfa173720adb |
parent 10546 | e79347eebbc5 |
child 11407 | 5399831730cd |
permissions | -rw-r--r-- |
1 | 1 |
/* |
8725
8c1e3dd5fe1b
7017732: move static fields into Class to prepare for perm gen removal
never
parents:
8314
diff
changeset
|
2 |
* Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved. |
1 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
4571
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
4571
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
4571
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 25 |
#include "precompiled.hpp" |
26 |
#include "ci/ciField.hpp" |
|
27 |
#include "ci/ciInstance.hpp" |
|
28 |
#include "ci/ciInstanceKlass.hpp" |
|
29 |
#include "ci/ciUtilities.hpp" |
|
30 |
#include "classfile/systemDictionary.hpp" |
|
31 |
#include "memory/allocation.hpp" |
|
32 |
#include "memory/allocation.inline.hpp" |
|
33 |
#include "oops/oop.inline.hpp" |
|
10546 | 34 |
#include "oops/fieldStreams.hpp" |
7397 | 35 |
#include "runtime/fieldDescriptor.hpp" |
1 | 36 |
|
37 |
// ciInstanceKlass |
|
38 |
// |
|
39 |
// This class represents a klassOop in the HotSpot virtual machine |
|
40 |
// whose Klass part in an instanceKlass. |
|
41 |
||
42 |
// ------------------------------------------------------------------ |
|
43 |
// ciInstanceKlass::ciInstanceKlass |
|
44 |
// |
|
45 |
// Loaded instance klass. |
|
217
c646ef2f5d58
6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents:
1
diff
changeset
|
46 |
ciInstanceKlass::ciInstanceKlass(KlassHandle h_k) : |
c646ef2f5d58
6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents:
1
diff
changeset
|
47 |
ciKlass(h_k), _non_static_fields(NULL) |
c646ef2f5d58
6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents:
1
diff
changeset
|
48 |
{ |
1 | 49 |
assert(get_Klass()->oop_is_instance(), "wrong type"); |
8314
057b1c20fd7e
6354181: nsk.logging.stress.threads.scmhml001 fails assertion in "src/share/vm/oops/instanceKlass.cpp, 111"
never
parents:
8076
diff
changeset
|
50 |
assert(get_instanceKlass()->is_loaded(), "must be at least loaded"); |
1 | 51 |
instanceKlass* ik = get_instanceKlass(); |
52 |
||
53 |
AccessFlags access_flags = ik->access_flags(); |
|
54 |
_flags = ciFlags(access_flags); |
|
55 |
_has_finalizer = access_flags.has_finalizer(); |
|
56 |
_has_subklass = ik->subklass() != NULL; |
|
5925
a30fef61d0b7
6958668: repeated uncommon trapping for new of klass which is being initialized
never
parents:
5884
diff
changeset
|
57 |
_init_state = (instanceKlass::ClassState)ik->get_init_state(); |
1 | 58 |
_nonstatic_field_size = ik->nonstatic_field_size(); |
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
217
diff
changeset
|
59 |
_has_nonstatic_fields = ik->has_nonstatic_fields(); |
1 | 60 |
_nonstatic_fields = NULL; // initialized lazily by compute_nonstatic_fields: |
61 |
||
62 |
_nof_implementors = ik->nof_implementors(); |
|
63 |
for (int i = 0; i < implementors_limit; i++) { |
|
64 |
_implementors[i] = NULL; // we will fill these lazily |
|
65 |
} |
|
66 |
||
67 |
Thread *thread = Thread::current(); |
|
68 |
if (ciObjectFactory::is_initialized()) { |
|
69 |
_loader = JNIHandles::make_local(thread, ik->class_loader()); |
|
70 |
_protection_domain = JNIHandles::make_local(thread, |
|
71 |
ik->protection_domain()); |
|
72 |
_is_shared = false; |
|
73 |
} else { |
|
74 |
Handle h_loader(thread, ik->class_loader()); |
|
75 |
Handle h_protection_domain(thread, ik->protection_domain()); |
|
76 |
_loader = JNIHandles::make_global(h_loader); |
|
77 |
_protection_domain = JNIHandles::make_global(h_protection_domain); |
|
78 |
_is_shared = true; |
|
79 |
} |
|
80 |
||
81 |
// Lazy fields get filled in only upon request. |
|
82 |
_super = NULL; |
|
83 |
_java_mirror = NULL; |
|
84 |
||
85 |
if (is_shared()) { |
|
4571 | 86 |
if (h_k() != SystemDictionary::Object_klass()) { |
1 | 87 |
super(); |
88 |
} |
|
89 |
//compute_nonstatic_fields(); // done outside of constructor |
|
90 |
} |
|
91 |
||
92 |
_field_cache = NULL; |
|
93 |
} |
|
94 |
||
95 |
// Version for unloaded classes: |
|
96 |
ciInstanceKlass::ciInstanceKlass(ciSymbol* name, |
|
97 |
jobject loader, jobject protection_domain) |
|
98 |
: ciKlass(name, ciInstanceKlassKlass::make()) |
|
99 |
{ |
|
100 |
assert(name->byte_at(0) != '[', "not an instance klass"); |
|
5925
a30fef61d0b7
6958668: repeated uncommon trapping for new of klass which is being initialized
never
parents:
5884
diff
changeset
|
101 |
_init_state = (instanceKlass::ClassState)0; |
1 | 102 |
_nonstatic_field_size = -1; |
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
217
diff
changeset
|
103 |
_has_nonstatic_fields = false; |
1 | 104 |
_nonstatic_fields = NULL; |
105 |
_nof_implementors = -1; |
|
106 |
_loader = loader; |
|
107 |
_protection_domain = protection_domain; |
|
108 |
_is_shared = false; |
|
109 |
_super = NULL; |
|
110 |
_java_mirror = NULL; |
|
111 |
_field_cache = NULL; |
|
112 |
} |
|
113 |
||
114 |
||
115 |
||
116 |
// ------------------------------------------------------------------ |
|
117 |
// ciInstanceKlass::compute_shared_is_initialized |
|
5925
a30fef61d0b7
6958668: repeated uncommon trapping for new of klass which is being initialized
never
parents:
5884
diff
changeset
|
118 |
void ciInstanceKlass::compute_shared_init_state() { |
1 | 119 |
GUARDED_VM_ENTRY( |
120 |
instanceKlass* ik = get_instanceKlass(); |
|
5925
a30fef61d0b7
6958668: repeated uncommon trapping for new of klass which is being initialized
never
parents:
5884
diff
changeset
|
121 |
_init_state = (instanceKlass::ClassState)ik->get_init_state(); |
1 | 122 |
) |
123 |
} |
|
124 |
||
125 |
// ------------------------------------------------------------------ |
|
126 |
// ciInstanceKlass::compute_shared_has_subklass |
|
127 |
bool ciInstanceKlass::compute_shared_has_subklass() { |
|
128 |
GUARDED_VM_ENTRY( |
|
129 |
instanceKlass* ik = get_instanceKlass(); |
|
130 |
_has_subklass = ik->subklass() != NULL; |
|
131 |
return _has_subklass; |
|
132 |
) |
|
133 |
} |
|
134 |
||
135 |
// ------------------------------------------------------------------ |
|
136 |
// ciInstanceKlass::compute_shared_nof_implementors |
|
137 |
int ciInstanceKlass::compute_shared_nof_implementors() { |
|
138 |
// We requery this property, since it is a very old ciObject. |
|
139 |
GUARDED_VM_ENTRY( |
|
140 |
instanceKlass* ik = get_instanceKlass(); |
|
141 |
_nof_implementors = ik->nof_implementors(); |
|
142 |
return _nof_implementors; |
|
143 |
) |
|
144 |
} |
|
145 |
||
146 |
// ------------------------------------------------------------------ |
|
147 |
// ciInstanceKlass::loader |
|
148 |
oop ciInstanceKlass::loader() { |
|
149 |
ASSERT_IN_VM; |
|
150 |
return JNIHandles::resolve(_loader); |
|
151 |
} |
|
152 |
||
153 |
// ------------------------------------------------------------------ |
|
154 |
// ciInstanceKlass::loader_handle |
|
155 |
jobject ciInstanceKlass::loader_handle() { |
|
156 |
return _loader; |
|
157 |
} |
|
158 |
||
159 |
// ------------------------------------------------------------------ |
|
160 |
// ciInstanceKlass::protection_domain |
|
161 |
oop ciInstanceKlass::protection_domain() { |
|
162 |
ASSERT_IN_VM; |
|
163 |
return JNIHandles::resolve(_protection_domain); |
|
164 |
} |
|
165 |
||
166 |
// ------------------------------------------------------------------ |
|
167 |
// ciInstanceKlass::protection_domain_handle |
|
168 |
jobject ciInstanceKlass::protection_domain_handle() { |
|
169 |
return _protection_domain; |
|
170 |
} |
|
171 |
||
172 |
// ------------------------------------------------------------------ |
|
173 |
// ciInstanceKlass::field_cache |
|
174 |
// |
|
175 |
// Get the field cache associated with this klass. |
|
176 |
ciConstantPoolCache* ciInstanceKlass::field_cache() { |
|
177 |
if (is_shared()) { |
|
178 |
return NULL; |
|
179 |
} |
|
180 |
if (_field_cache == NULL) { |
|
181 |
assert(!is_java_lang_Object(), "Object has no fields"); |
|
182 |
Arena* arena = CURRENT_ENV->arena(); |
|
183 |
_field_cache = new (arena) ciConstantPoolCache(arena, 5); |
|
184 |
} |
|
185 |
return _field_cache; |
|
186 |
} |
|
187 |
||
188 |
// ------------------------------------------------------------------ |
|
189 |
// ciInstanceKlass::get_canonical_holder |
|
190 |
// |
|
191 |
ciInstanceKlass* ciInstanceKlass::get_canonical_holder(int offset) { |
|
192 |
#ifdef ASSERT |
|
193 |
if (!(offset >= 0 && offset < layout_helper())) { |
|
194 |
tty->print("*** get_canonical_holder(%d) on ", offset); |
|
195 |
this->print(); |
|
196 |
tty->print_cr(" ***"); |
|
197 |
}; |
|
198 |
assert(offset >= 0 && offset < layout_helper(), "offset must be tame"); |
|
199 |
#endif |
|
200 |
||
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
217
diff
changeset
|
201 |
if (offset < instanceOopDesc::base_offset_in_bytes()) { |
1 | 202 |
// All header offsets belong properly to java/lang/Object. |
203 |
return CURRENT_ENV->Object_klass(); |
|
204 |
} |
|
205 |
||
206 |
ciInstanceKlass* self = this; |
|
207 |
for (;;) { |
|
208 |
assert(self->is_loaded(), "must be loaded to have size"); |
|
209 |
ciInstanceKlass* super = self->super(); |
|
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
217
diff
changeset
|
210 |
if (super == NULL || super->nof_nonstatic_fields() == 0 || |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
217
diff
changeset
|
211 |
!super->contains_field_offset(offset)) { |
1 | 212 |
return self; |
213 |
} else { |
|
214 |
self = super; // return super->get_canonical_holder(offset) |
|
215 |
} |
|
216 |
} |
|
217 |
} |
|
218 |
||
219 |
// ------------------------------------------------------------------ |
|
220 |
// ciInstanceKlass::is_java_lang_Object |
|
221 |
// |
|
222 |
// Is this klass java.lang.Object? |
|
223 |
bool ciInstanceKlass::is_java_lang_Object() { |
|
224 |
return equals(CURRENT_ENV->Object_klass()); |
|
225 |
} |
|
226 |
||
227 |
// ------------------------------------------------------------------ |
|
228 |
// ciInstanceKlass::uses_default_loader |
|
229 |
bool ciInstanceKlass::uses_default_loader() { |
|
4567
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
4450
diff
changeset
|
230 |
// Note: We do not need to resolve the handle or enter the VM |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
4450
diff
changeset
|
231 |
// in order to test null-ness. |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
4450
diff
changeset
|
232 |
return _loader == NULL; |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
4450
diff
changeset
|
233 |
} |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
4450
diff
changeset
|
234 |
|
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
4450
diff
changeset
|
235 |
// ------------------------------------------------------------------ |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
4450
diff
changeset
|
236 |
// ciInstanceKlass::is_in_package |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
4450
diff
changeset
|
237 |
// |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
4450
diff
changeset
|
238 |
// Is this klass in the given package? |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
4450
diff
changeset
|
239 |
bool ciInstanceKlass::is_in_package(const char* packagename, int len) { |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
4450
diff
changeset
|
240 |
// To avoid class loader mischief, this test always rejects application classes. |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
4450
diff
changeset
|
241 |
if (!uses_default_loader()) |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
4450
diff
changeset
|
242 |
return false; |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
4450
diff
changeset
|
243 |
GUARDED_VM_ENTRY( |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
4450
diff
changeset
|
244 |
return is_in_package_impl(packagename, len); |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
4450
diff
changeset
|
245 |
) |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
4450
diff
changeset
|
246 |
} |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
4450
diff
changeset
|
247 |
|
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
4450
diff
changeset
|
248 |
bool ciInstanceKlass::is_in_package_impl(const char* packagename, int len) { |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
4450
diff
changeset
|
249 |
ASSERT_IN_VM; |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
4450
diff
changeset
|
250 |
|
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
4450
diff
changeset
|
251 |
// If packagename contains trailing '/' exclude it from the |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
4450
diff
changeset
|
252 |
// prefix-test since we test for it explicitly. |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
4450
diff
changeset
|
253 |
if (packagename[len - 1] == '/') |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
4450
diff
changeset
|
254 |
len--; |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
4450
diff
changeset
|
255 |
|
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
4450
diff
changeset
|
256 |
if (!name()->starts_with(packagename, len)) |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
4450
diff
changeset
|
257 |
return false; |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
4450
diff
changeset
|
258 |
|
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
4450
diff
changeset
|
259 |
// Test if the class name is something like "java/lang". |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
4450
diff
changeset
|
260 |
if ((len + 1) > name()->utf8_length()) |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
4450
diff
changeset
|
261 |
return false; |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
4450
diff
changeset
|
262 |
|
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
4450
diff
changeset
|
263 |
// Test for trailing '/' |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
4450
diff
changeset
|
264 |
if ((char) name()->byte_at(len) != '/') |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
4450
diff
changeset
|
265 |
return false; |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
4450
diff
changeset
|
266 |
|
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
4450
diff
changeset
|
267 |
// Make sure it's not actually in a subpackage: |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
4450
diff
changeset
|
268 |
if (name()->index_of_at(len+1, "/", 1) >= 0) |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
4450
diff
changeset
|
269 |
return false; |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
4450
diff
changeset
|
270 |
|
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
4450
diff
changeset
|
271 |
return true; |
1 | 272 |
} |
273 |
||
274 |
// ------------------------------------------------------------------ |
|
275 |
// ciInstanceKlass::print_impl |
|
276 |
// |
|
277 |
// Implementation of the print method. |
|
278 |
void ciInstanceKlass::print_impl(outputStream* st) { |
|
279 |
ciKlass::print_impl(st); |
|
280 |
GUARDED_VM_ENTRY(st->print(" loader=0x%x", (address)loader());) |
|
281 |
if (is_loaded()) { |
|
282 |
st->print(" loaded=true initialized=%s finalized=%s subklass=%s size=%d flags=", |
|
283 |
bool_to_str(is_initialized()), |
|
284 |
bool_to_str(has_finalizer()), |
|
285 |
bool_to_str(has_subklass()), |
|
286 |
layout_helper()); |
|
287 |
||
288 |
_flags.print_klass_flags(); |
|
289 |
||
290 |
if (_super) { |
|
291 |
st->print(" super="); |
|
292 |
_super->print_name(); |
|
293 |
} |
|
294 |
if (_java_mirror) { |
|
295 |
st->print(" mirror=PRESENT"); |
|
296 |
} |
|
297 |
} else { |
|
298 |
st->print(" loaded=false"); |
|
299 |
} |
|
300 |
} |
|
301 |
||
302 |
// ------------------------------------------------------------------ |
|
303 |
// ciInstanceKlass::super |
|
304 |
// |
|
305 |
// Get the superklass of this klass. |
|
306 |
ciInstanceKlass* ciInstanceKlass::super() { |
|
307 |
assert(is_loaded(), "must be loaded"); |
|
308 |
if (_super == NULL && !is_java_lang_Object()) { |
|
309 |
GUARDED_VM_ENTRY( |
|
310 |
klassOop super_klass = get_instanceKlass()->super(); |
|
311 |
_super = CURRENT_ENV->get_object(super_klass)->as_instance_klass(); |
|
312 |
) |
|
313 |
} |
|
314 |
return _super; |
|
315 |
} |
|
316 |
||
317 |
// ------------------------------------------------------------------ |
|
318 |
// ciInstanceKlass::java_mirror |
|
319 |
// |
|
320 |
// Get the instance of java.lang.Class corresponding to this klass. |
|
5884
3963019e3782
6960865: ldc of unloaded class throws an assert in ciTypeFlow
jrose
parents:
5882
diff
changeset
|
321 |
// Cache it on this->_java_mirror. |
1 | 322 |
ciInstance* ciInstanceKlass::java_mirror() { |
8725
8c1e3dd5fe1b
7017732: move static fields into Class to prepare for perm gen removal
never
parents:
8314
diff
changeset
|
323 |
if (is_shared()) { |
8c1e3dd5fe1b
7017732: move static fields into Class to prepare for perm gen removal
never
parents:
8314
diff
changeset
|
324 |
return ciKlass::java_mirror(); |
8c1e3dd5fe1b
7017732: move static fields into Class to prepare for perm gen removal
never
parents:
8314
diff
changeset
|
325 |
} |
1 | 326 |
if (_java_mirror == NULL) { |
5884
3963019e3782
6960865: ldc of unloaded class throws an assert in ciTypeFlow
jrose
parents:
5882
diff
changeset
|
327 |
_java_mirror = ciKlass::java_mirror(); |
1 | 328 |
} |
329 |
return _java_mirror; |
|
330 |
} |
|
331 |
||
332 |
// ------------------------------------------------------------------ |
|
333 |
// ciInstanceKlass::unique_concrete_subklass |
|
334 |
ciInstanceKlass* ciInstanceKlass::unique_concrete_subklass() { |
|
335 |
if (!is_loaded()) return NULL; // No change if class is not loaded |
|
336 |
if (!is_abstract()) return NULL; // Only applies to abstract classes. |
|
337 |
if (!has_subklass()) return NULL; // Must have at least one subklass. |
|
338 |
VM_ENTRY_MARK; |
|
339 |
instanceKlass* ik = get_instanceKlass(); |
|
340 |
Klass* up = ik->up_cast_abstract(); |
|
341 |
assert(up->oop_is_instance(), "must be instanceKlass"); |
|
342 |
if (ik == up) { |
|
343 |
return NULL; |
|
344 |
} |
|
345 |
return CURRENT_THREAD_ENV->get_object(up->as_klassOop())->as_instance_klass(); |
|
346 |
} |
|
347 |
||
348 |
// ------------------------------------------------------------------ |
|
349 |
// ciInstanceKlass::has_finalizable_subclass |
|
350 |
bool ciInstanceKlass::has_finalizable_subclass() { |
|
351 |
if (!is_loaded()) return true; |
|
352 |
VM_ENTRY_MARK; |
|
353 |
return Dependencies::find_finalizable_subclass(get_instanceKlass()) != NULL; |
|
354 |
} |
|
355 |
||
356 |
// ------------------------------------------------------------------ |
|
357 |
// ciInstanceKlass::get_field_by_offset |
|
358 |
ciField* ciInstanceKlass::get_field_by_offset(int field_offset, bool is_static) { |
|
359 |
if (!is_static) { |
|
360 |
for (int i = 0, len = nof_nonstatic_fields(); i < len; i++) { |
|
361 |
ciField* field = _nonstatic_fields->at(i); |
|
362 |
int field_off = field->offset_in_bytes(); |
|
363 |
if (field_off == field_offset) |
|
364 |
return field; |
|
365 |
if (field_off > field_offset) |
|
366 |
break; |
|
367 |
// could do binary search or check bins, but probably not worth it |
|
368 |
} |
|
369 |
return NULL; |
|
370 |
} |
|
371 |
VM_ENTRY_MARK; |
|
372 |
instanceKlass* k = get_instanceKlass(); |
|
373 |
fieldDescriptor fd; |
|
374 |
if (!k->find_field_from_offset(field_offset, is_static, &fd)) { |
|
375 |
return NULL; |
|
376 |
} |
|
377 |
ciField* field = new (CURRENT_THREAD_ENV->arena()) ciField(&fd); |
|
378 |
return field; |
|
379 |
} |
|
380 |
||
217
c646ef2f5d58
6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents:
1
diff
changeset
|
381 |
// ------------------------------------------------------------------ |
4450
6d700b859b3e
6892658: C2 should optimize some stringbuilder patterns
never
parents:
670
diff
changeset
|
382 |
// ciInstanceKlass::get_field_by_name |
6d700b859b3e
6892658: C2 should optimize some stringbuilder patterns
never
parents:
670
diff
changeset
|
383 |
ciField* ciInstanceKlass::get_field_by_name(ciSymbol* name, ciSymbol* signature, bool is_static) { |
6d700b859b3e
6892658: C2 should optimize some stringbuilder patterns
never
parents:
670
diff
changeset
|
384 |
VM_ENTRY_MARK; |
6d700b859b3e
6892658: C2 should optimize some stringbuilder patterns
never
parents:
670
diff
changeset
|
385 |
instanceKlass* k = get_instanceKlass(); |
6d700b859b3e
6892658: C2 should optimize some stringbuilder patterns
never
parents:
670
diff
changeset
|
386 |
fieldDescriptor fd; |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
387 |
klassOop def = k->find_field(name->get_symbol(), signature->get_symbol(), is_static, &fd); |
4450
6d700b859b3e
6892658: C2 should optimize some stringbuilder patterns
never
parents:
670
diff
changeset
|
388 |
if (def == NULL) { |
6d700b859b3e
6892658: C2 should optimize some stringbuilder patterns
never
parents:
670
diff
changeset
|
389 |
return NULL; |
6d700b859b3e
6892658: C2 should optimize some stringbuilder patterns
never
parents:
670
diff
changeset
|
390 |
} |
6d700b859b3e
6892658: C2 should optimize some stringbuilder patterns
never
parents:
670
diff
changeset
|
391 |
ciField* field = new (CURRENT_THREAD_ENV->arena()) ciField(&fd); |
6d700b859b3e
6892658: C2 should optimize some stringbuilder patterns
never
parents:
670
diff
changeset
|
392 |
return field; |
6d700b859b3e
6892658: C2 should optimize some stringbuilder patterns
never
parents:
670
diff
changeset
|
393 |
} |
6d700b859b3e
6892658: C2 should optimize some stringbuilder patterns
never
parents:
670
diff
changeset
|
394 |
|
6d700b859b3e
6892658: C2 should optimize some stringbuilder patterns
never
parents:
670
diff
changeset
|
395 |
// ------------------------------------------------------------------ |
217
c646ef2f5d58
6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents:
1
diff
changeset
|
396 |
// ciInstanceKlass::non_static_fields. |
c646ef2f5d58
6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents:
1
diff
changeset
|
397 |
|
c646ef2f5d58
6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents:
1
diff
changeset
|
398 |
class NonStaticFieldFiller: public FieldClosure { |
c646ef2f5d58
6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents:
1
diff
changeset
|
399 |
GrowableArray<ciField*>* _arr; |
c646ef2f5d58
6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents:
1
diff
changeset
|
400 |
ciEnv* _curEnv; |
c646ef2f5d58
6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents:
1
diff
changeset
|
401 |
public: |
c646ef2f5d58
6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents:
1
diff
changeset
|
402 |
NonStaticFieldFiller(ciEnv* curEnv, GrowableArray<ciField*>* arr) : |
c646ef2f5d58
6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents:
1
diff
changeset
|
403 |
_curEnv(curEnv), _arr(arr) |
c646ef2f5d58
6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents:
1
diff
changeset
|
404 |
{} |
c646ef2f5d58
6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents:
1
diff
changeset
|
405 |
void do_field(fieldDescriptor* fd) { |
c646ef2f5d58
6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents:
1
diff
changeset
|
406 |
ciField* field = new (_curEnv->arena()) ciField(fd); |
c646ef2f5d58
6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents:
1
diff
changeset
|
407 |
_arr->append(field); |
c646ef2f5d58
6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents:
1
diff
changeset
|
408 |
} |
c646ef2f5d58
6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents:
1
diff
changeset
|
409 |
}; |
c646ef2f5d58
6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents:
1
diff
changeset
|
410 |
|
c646ef2f5d58
6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents:
1
diff
changeset
|
411 |
GrowableArray<ciField*>* ciInstanceKlass::non_static_fields() { |
c646ef2f5d58
6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents:
1
diff
changeset
|
412 |
if (_non_static_fields == NULL) { |
c646ef2f5d58
6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents:
1
diff
changeset
|
413 |
VM_ENTRY_MARK; |
c646ef2f5d58
6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents:
1
diff
changeset
|
414 |
ciEnv* curEnv = ciEnv::current(); |
c646ef2f5d58
6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents:
1
diff
changeset
|
415 |
instanceKlass* ik = get_instanceKlass(); |
10546 | 416 |
int max_n_fields = ik->java_fields_count(); |
217
c646ef2f5d58
6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents:
1
diff
changeset
|
417 |
|
6180 | 418 |
Arena* arena = curEnv->arena(); |
217
c646ef2f5d58
6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents:
1
diff
changeset
|
419 |
_non_static_fields = |
6180 | 420 |
new (arena) GrowableArray<ciField*>(arena, max_n_fields, 0, NULL); |
217
c646ef2f5d58
6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents:
1
diff
changeset
|
421 |
NonStaticFieldFiller filler(curEnv, _non_static_fields); |
c646ef2f5d58
6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents:
1
diff
changeset
|
422 |
ik->do_nonstatic_fields(&filler); |
c646ef2f5d58
6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents:
1
diff
changeset
|
423 |
} |
c646ef2f5d58
6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents:
1
diff
changeset
|
424 |
return _non_static_fields; |
c646ef2f5d58
6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents:
1
diff
changeset
|
425 |
} |
c646ef2f5d58
6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents:
1
diff
changeset
|
426 |
|
1 | 427 |
static int sort_field_by_offset(ciField** a, ciField** b) { |
428 |
return (*a)->offset_in_bytes() - (*b)->offset_in_bytes(); |
|
429 |
// (no worries about 32-bit overflow...) |
|
430 |
} |
|
431 |
||
432 |
// ------------------------------------------------------------------ |
|
433 |
// ciInstanceKlass::compute_nonstatic_fields |
|
434 |
int ciInstanceKlass::compute_nonstatic_fields() { |
|
435 |
assert(is_loaded(), "must be loaded"); |
|
436 |
||
437 |
if (_nonstatic_fields != NULL) |
|
438 |
return _nonstatic_fields->length(); |
|
439 |
||
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
217
diff
changeset
|
440 |
if (!has_nonstatic_fields()) { |
1 | 441 |
Arena* arena = CURRENT_ENV->arena(); |
442 |
_nonstatic_fields = new (arena) GrowableArray<ciField*>(arena, 0, 0, NULL); |
|
443 |
return 0; |
|
444 |
} |
|
445 |
assert(!is_java_lang_Object(), "bootstrap OK"); |
|
446 |
||
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
217
diff
changeset
|
447 |
// Size in bytes of my fields, including inherited fields. |
591
04d2e26e6d69
6703888: Compressed Oops: use the 32-bits gap after klass in a object
kvn
parents:
360
diff
changeset
|
448 |
int fsize = nonstatic_field_size() * heapOopSize; |
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
217
diff
changeset
|
449 |
|
1 | 450 |
ciInstanceKlass* super = this->super(); |
451 |
GrowableArray<ciField*>* super_fields = NULL; |
|
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
217
diff
changeset
|
452 |
if (super != NULL && super->has_nonstatic_fields()) { |
591
04d2e26e6d69
6703888: Compressed Oops: use the 32-bits gap after klass in a object
kvn
parents:
360
diff
changeset
|
453 |
int super_fsize = super->nonstatic_field_size() * heapOopSize; |
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
217
diff
changeset
|
454 |
int super_flen = super->nof_nonstatic_fields(); |
1 | 455 |
super_fields = super->_nonstatic_fields; |
456 |
assert(super_flen == 0 || super_fields != NULL, "first get nof_fields"); |
|
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
217
diff
changeset
|
457 |
// See if I am no larger than my super; if so, I can use his fields. |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
217
diff
changeset
|
458 |
if (fsize == super_fsize) { |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
217
diff
changeset
|
459 |
_nonstatic_fields = super_fields; |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
217
diff
changeset
|
460 |
return super_fields->length(); |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
217
diff
changeset
|
461 |
} |
1 | 462 |
} |
463 |
||
464 |
GrowableArray<ciField*>* fields = NULL; |
|
465 |
GUARDED_VM_ENTRY({ |
|
466 |
fields = compute_nonstatic_fields_impl(super_fields); |
|
467 |
}); |
|
468 |
||
469 |
if (fields == NULL) { |
|
470 |
// This can happen if this class (java.lang.Class) has invisible fields. |
|
471 |
_nonstatic_fields = super_fields; |
|
472 |
return super_fields->length(); |
|
473 |
} |
|
474 |
||
475 |
int flen = fields->length(); |
|
476 |
||
477 |
// Now sort them by offset, ascending. |
|
478 |
// (In principle, they could mix with superclass fields.) |
|
479 |
fields->sort(sort_field_by_offset); |
|
480 |
_nonstatic_fields = fields; |
|
481 |
return flen; |
|
482 |
} |
|
483 |
||
484 |
GrowableArray<ciField*>* |
|
485 |
ciInstanceKlass::compute_nonstatic_fields_impl(GrowableArray<ciField*>* |
|
486 |
super_fields) { |
|
487 |
ASSERT_IN_VM; |
|
488 |
Arena* arena = CURRENT_ENV->arena(); |
|
489 |
int flen = 0; |
|
490 |
GrowableArray<ciField*>* fields = NULL; |
|
491 |
instanceKlass* k = get_instanceKlass(); |
|
10546 | 492 |
for (JavaFieldStream fs(k); !fs.done(); fs.next()) { |
493 |
if (fs.access_flags().is_static()) continue; |
|
494 |
flen += 1; |
|
495 |
} |
|
1 | 496 |
|
10546 | 497 |
// allocate the array: |
498 |
if (flen == 0) { |
|
499 |
return NULL; // return nothing if none are locally declared |
|
500 |
} |
|
501 |
if (super_fields != NULL) { |
|
502 |
flen += super_fields->length(); |
|
503 |
} |
|
504 |
fields = new (arena) GrowableArray<ciField*>(arena, flen, 0, NULL); |
|
505 |
if (super_fields != NULL) { |
|
506 |
fields->appendAll(super_fields); |
|
507 |
} |
|
508 |
||
509 |
for (JavaFieldStream fs(k); !fs.done(); fs.next()) { |
|
510 |
if (fs.access_flags().is_static()) continue; |
|
511 |
fieldDescriptor fd; |
|
512 |
fd.initialize(k->as_klassOop(), fs.index()); |
|
513 |
ciField* field = new (arena) ciField(&fd); |
|
514 |
fields->append(field); |
|
1 | 515 |
} |
516 |
assert(fields->length() == flen, "sanity"); |
|
517 |
return fields; |
|
518 |
} |
|
519 |
||
520 |
// ------------------------------------------------------------------ |
|
521 |
// ciInstanceKlass::find_method |
|
522 |
// |
|
523 |
// Find a method in this klass. |
|
524 |
ciMethod* ciInstanceKlass::find_method(ciSymbol* name, ciSymbol* signature) { |
|
525 |
VM_ENTRY_MARK; |
|
526 |
instanceKlass* k = get_instanceKlass(); |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
527 |
Symbol* name_sym = name->get_symbol(); |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
528 |
Symbol* sig_sym= signature->get_symbol(); |
1 | 529 |
|
530 |
methodOop m = k->find_method(name_sym, sig_sym); |
|
531 |
if (m == NULL) return NULL; |
|
532 |
||
533 |
return CURRENT_THREAD_ENV->get_object(m)->as_method(); |
|
534 |
} |
|
535 |
||
536 |
// ------------------------------------------------------------------ |
|
537 |
// ciInstanceKlass::is_leaf_type |
|
538 |
bool ciInstanceKlass::is_leaf_type() { |
|
539 |
assert(is_loaded(), "must be loaded"); |
|
540 |
if (is_shared()) { |
|
541 |
return is_final(); // approximately correct |
|
542 |
} else { |
|
543 |
return !_has_subklass && (_nof_implementors == 0); |
|
544 |
} |
|
545 |
} |
|
546 |
||
547 |
// ------------------------------------------------------------------ |
|
548 |
// ciInstanceKlass::implementor |
|
549 |
// |
|
550 |
// Report an implementor of this interface. |
|
551 |
// Returns NULL if exact information is not available. |
|
552 |
// Note that there are various races here, since my copy |
|
553 |
// of _nof_implementors might be out of date with respect |
|
554 |
// to results returned by instanceKlass::implementor. |
|
555 |
// This is OK, since any dependencies we decide to assert |
|
556 |
// will be checked later under the Compile_lock. |
|
557 |
ciInstanceKlass* ciInstanceKlass::implementor(int n) { |
|
7125 | 558 |
if (n >= implementors_limit) { |
1 | 559 |
return NULL; |
560 |
} |
|
561 |
ciInstanceKlass* impl = _implementors[n]; |
|
562 |
if (impl == NULL) { |
|
563 |
if (_nof_implementors > implementors_limit) { |
|
564 |
return NULL; |
|
565 |
} |
|
566 |
// Go into the VM to fetch the implementor. |
|
567 |
{ |
|
568 |
VM_ENTRY_MARK; |
|
569 |
klassOop k = get_instanceKlass()->implementor(n); |
|
570 |
if (k != NULL) { |
|
571 |
impl = CURRENT_THREAD_ENV->get_object(k)->as_instance_klass(); |
|
572 |
} |
|
573 |
} |
|
574 |
// Memoize this result. |
|
575 |
if (!is_shared()) { |
|
576 |
_implementors[n] = (impl == NULL)? this: impl; |
|
577 |
} |
|
578 |
} else if (impl == this) { |
|
579 |
impl = NULL; // memoized null result from a VM query |
|
580 |
} |
|
581 |
return impl; |
|
582 |
} |