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