Mercurial > hg > graal-compiler
annotate src/share/vm/ci/ciInstanceKlass.cpp @ 1422:3483ec571caf
* using reflected objects instead of oops
* removed scratch from allocatable registers
* instanceof xir snippet
* arraylength xir snippet
* exceptionobject xir snippet
* VMEntries and VMExits as interfaces
* calls to VMEntries and VMExits are routet through logging proxies
author | Lukas Stadler <lukas.stadler@oracle.com> |
---|---|
date | Mon, 02 Aug 2010 15:44:38 -0700 |
parents | 4ce7240d622c |
children | 5571b97fc1ec |
rev | line source |
---|---|
0 | 1 /* |
196 | 2 * Copyright 1999-2008 Sun Microsystems, Inc. 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 * | |
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, | |
20 * CA 95054 USA or visit www.sun.com if you need additional information or | |
21 * have any questions. | |
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; | |
47 _is_initialized = ik->is_initialized(); | |
48 // Next line must follow and use the result of the previous line: | |
49 _is_linked = _is_initialized || ik->is_linked(); | |
50 _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
|
51 _has_nonstatic_fields = ik->has_nonstatic_fields(); |
0 | 52 _nonstatic_fields = NULL; // initialized lazily by compute_nonstatic_fields: |
53 | |
54 _nof_implementors = ik->nof_implementors(); | |
55 for (int i = 0; i < implementors_limit; i++) { | |
56 _implementors[i] = NULL; // we will fill these lazily | |
57 } | |
58 | |
59 Thread *thread = Thread::current(); | |
1422
3483ec571caf
* using reflected objects instead of oops
Lukas Stadler <lukas.stadler@oracle.com>
parents:
1142
diff
changeset
|
60 if (ciObjectFactory::is_initialized() && !UseC1X) { |
0 | 61 _loader = JNIHandles::make_local(thread, ik->class_loader()); |
1422
3483ec571caf
* using reflected objects instead of oops
Lukas Stadler <lukas.stadler@oracle.com>
parents:
1142
diff
changeset
|
62 _protection_domain = JNIHandles::make_local(thread, ik->protection_domain()); |
0 | 63 _is_shared = false; |
64 } else { | |
65 Handle h_loader(thread, ik->class_loader()); | |
66 Handle h_protection_domain(thread, ik->protection_domain()); | |
67 _loader = JNIHandles::make_global(h_loader); | |
68 _protection_domain = JNIHandles::make_global(h_protection_domain); | |
69 _is_shared = true; | |
70 } | |
71 | |
72 // Lazy fields get filled in only upon request. | |
73 _super = NULL; | |
74 _java_mirror = NULL; | |
75 | |
76 if (is_shared()) { | |
1142 | 77 if (h_k() != SystemDictionary::Object_klass()) { |
0 | 78 super(); |
79 } | |
80 java_mirror(); | |
81 //compute_nonstatic_fields(); // done outside of constructor | |
82 } | |
83 | |
84 _field_cache = NULL; | |
85 } | |
86 | |
87 // Version for unloaded classes: | |
88 ciInstanceKlass::ciInstanceKlass(ciSymbol* name, | |
89 jobject loader, jobject protection_domain) | |
90 : ciKlass(name, ciInstanceKlassKlass::make()) | |
91 { | |
92 assert(name->byte_at(0) != '[', "not an instance klass"); | |
93 _is_initialized = false; | |
94 _is_linked = false; | |
95 _nonstatic_field_size = -1; | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
44
diff
changeset
|
96 _has_nonstatic_fields = false; |
0 | 97 _nonstatic_fields = NULL; |
98 _nof_implementors = -1; | |
99 _loader = loader; | |
100 _protection_domain = protection_domain; | |
101 _is_shared = false; | |
102 _super = NULL; | |
103 _java_mirror = NULL; | |
104 _field_cache = NULL; | |
105 } | |
106 | |
107 | |
108 | |
109 // ------------------------------------------------------------------ | |
110 // ciInstanceKlass::compute_shared_is_initialized | |
111 bool ciInstanceKlass::compute_shared_is_initialized() { | |
112 GUARDED_VM_ENTRY( | |
113 instanceKlass* ik = get_instanceKlass(); | |
114 _is_initialized = ik->is_initialized(); | |
115 return _is_initialized; | |
116 ) | |
117 } | |
118 | |
119 // ------------------------------------------------------------------ | |
120 // ciInstanceKlass::compute_shared_is_linked | |
121 bool ciInstanceKlass::compute_shared_is_linked() { | |
122 GUARDED_VM_ENTRY( | |
123 instanceKlass* ik = get_instanceKlass(); | |
124 _is_linked = ik->is_linked(); | |
125 return _is_linked; | |
126 ) | |
127 } | |
128 | |
129 // ------------------------------------------------------------------ | |
130 // ciInstanceKlass::compute_shared_has_subklass | |
131 bool ciInstanceKlass::compute_shared_has_subklass() { | |
132 GUARDED_VM_ENTRY( | |
133 instanceKlass* ik = get_instanceKlass(); | |
134 _has_subklass = ik->subklass() != NULL; | |
135 return _has_subklass; | |
136 ) | |
137 } | |
138 | |
139 // ------------------------------------------------------------------ | |
140 // ciInstanceKlass::compute_shared_nof_implementors | |
141 int ciInstanceKlass::compute_shared_nof_implementors() { | |
142 // We requery this property, since it is a very old ciObject. | |
143 GUARDED_VM_ENTRY( | |
144 instanceKlass* ik = get_instanceKlass(); | |
145 _nof_implementors = ik->nof_implementors(); | |
146 return _nof_implementors; | |
147 ) | |
148 } | |
149 | |
150 // ------------------------------------------------------------------ | |
151 // ciInstanceKlass::loader | |
152 oop ciInstanceKlass::loader() { | |
153 ASSERT_IN_VM; | |
154 return JNIHandles::resolve(_loader); | |
155 } | |
156 | |
157 // ------------------------------------------------------------------ | |
158 // ciInstanceKlass::loader_handle | |
159 jobject ciInstanceKlass::loader_handle() { | |
160 return _loader; | |
161 } | |
162 | |
163 // ------------------------------------------------------------------ | |
164 // ciInstanceKlass::protection_domain | |
165 oop ciInstanceKlass::protection_domain() { | |
166 ASSERT_IN_VM; | |
167 return JNIHandles::resolve(_protection_domain); | |
168 } | |
169 | |
170 // ------------------------------------------------------------------ | |
171 // ciInstanceKlass::protection_domain_handle | |
172 jobject ciInstanceKlass::protection_domain_handle() { | |
173 return _protection_domain; | |
174 } | |
175 | |
176 // ------------------------------------------------------------------ | |
177 // ciInstanceKlass::field_cache | |
178 // | |
179 // Get the field cache associated with this klass. | |
180 ciConstantPoolCache* ciInstanceKlass::field_cache() { | |
181 if (is_shared()) { | |
182 return NULL; | |
183 } | |
184 if (_field_cache == NULL) { | |
185 assert(!is_java_lang_Object(), "Object has no fields"); | |
186 Arena* arena = CURRENT_ENV->arena(); | |
187 _field_cache = new (arena) ciConstantPoolCache(arena, 5); | |
188 } | |
189 return _field_cache; | |
190 } | |
191 | |
192 // ------------------------------------------------------------------ | |
193 // ciInstanceKlass::get_canonical_holder | |
194 // | |
195 ciInstanceKlass* ciInstanceKlass::get_canonical_holder(int offset) { | |
196 #ifdef ASSERT | |
197 if (!(offset >= 0 && offset < layout_helper())) { | |
198 tty->print("*** get_canonical_holder(%d) on ", offset); | |
199 this->print(); | |
200 tty->print_cr(" ***"); | |
201 }; | |
202 assert(offset >= 0 && offset < layout_helper(), "offset must be tame"); | |
203 #endif | |
204 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
44
diff
changeset
|
205 if (offset < instanceOopDesc::base_offset_in_bytes()) { |
0 | 206 // All header offsets belong properly to java/lang/Object. |
207 return CURRENT_ENV->Object_klass(); | |
208 } | |
209 | |
210 ciInstanceKlass* self = this; | |
211 for (;;) { | |
212 assert(self->is_loaded(), "must be loaded to have size"); | |
213 ciInstanceKlass* super = self->super(); | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
44
diff
changeset
|
214 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
|
215 !super->contains_field_offset(offset)) { |
0 | 216 return self; |
217 } else { | |
218 self = super; // return super->get_canonical_holder(offset) | |
219 } | |
220 } | |
221 } | |
222 | |
223 // ------------------------------------------------------------------ | |
224 // ciInstanceKlass::is_java_lang_Object | |
225 // | |
226 // Is this klass java.lang.Object? | |
227 bool ciInstanceKlass::is_java_lang_Object() { | |
228 return equals(CURRENT_ENV->Object_klass()); | |
229 } | |
230 | |
231 // ------------------------------------------------------------------ | |
232 // ciInstanceKlass::uses_default_loader | |
233 bool ciInstanceKlass::uses_default_loader() { | |
1138
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1080
diff
changeset
|
234 // 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
|
235 // in order to test null-ness. |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1080
diff
changeset
|
236 return _loader == NULL; |
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 // ------------------------------------------------------------------ |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1080
diff
changeset
|
240 // ciInstanceKlass::is_in_package |
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 // Is this klass in the given package? |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1080
diff
changeset
|
243 bool ciInstanceKlass::is_in_package(const char* packagename, int len) { |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1080
diff
changeset
|
244 // 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
|
245 if (!uses_default_loader()) |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1080
diff
changeset
|
246 return false; |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1080
diff
changeset
|
247 GUARDED_VM_ENTRY( |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1080
diff
changeset
|
248 return is_in_package_impl(packagename, len); |
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 } |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1080
diff
changeset
|
251 |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1080
diff
changeset
|
252 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
|
253 ASSERT_IN_VM; |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1080
diff
changeset
|
254 |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1080
diff
changeset
|
255 // If packagename contains trailing '/' exclude it from the |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1080
diff
changeset
|
256 // prefix-test since we test for it explicitly. |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1080
diff
changeset
|
257 if (packagename[len - 1] == '/') |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1080
diff
changeset
|
258 len--; |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1080
diff
changeset
|
259 |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1080
diff
changeset
|
260 if (!name()->starts_with(packagename, len)) |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1080
diff
changeset
|
261 return false; |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1080
diff
changeset
|
262 |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1080
diff
changeset
|
263 // Test if the class name is something like "java/lang". |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1080
diff
changeset
|
264 if ((len + 1) > name()->utf8_length()) |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1080
diff
changeset
|
265 return false; |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1080
diff
changeset
|
266 |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1080
diff
changeset
|
267 // Test for trailing '/' |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1080
diff
changeset
|
268 if ((char) name()->byte_at(len) != '/') |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1080
diff
changeset
|
269 return false; |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1080
diff
changeset
|
270 |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1080
diff
changeset
|
271 // Make sure it's not actually in a subpackage: |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1080
diff
changeset
|
272 if (name()->index_of_at(len+1, "/", 1) >= 0) |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1080
diff
changeset
|
273 return false; |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1080
diff
changeset
|
274 |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1080
diff
changeset
|
275 return true; |
0 | 276 } |
277 | |
278 // ------------------------------------------------------------------ | |
279 // ciInstanceKlass::print_impl | |
280 // | |
281 // Implementation of the print method. | |
282 void ciInstanceKlass::print_impl(outputStream* st) { | |
283 ciKlass::print_impl(st); | |
284 GUARDED_VM_ENTRY(st->print(" loader=0x%x", (address)loader());) | |
285 if (is_loaded()) { | |
286 st->print(" loaded=true initialized=%s finalized=%s subklass=%s size=%d flags=", | |
287 bool_to_str(is_initialized()), | |
288 bool_to_str(has_finalizer()), | |
289 bool_to_str(has_subklass()), | |
290 layout_helper()); | |
291 | |
292 _flags.print_klass_flags(); | |
293 | |
294 if (_super) { | |
295 st->print(" super="); | |
296 _super->print_name(); | |
297 } | |
298 if (_java_mirror) { | |
299 st->print(" mirror=PRESENT"); | |
300 } | |
301 } else { | |
302 st->print(" loaded=false"); | |
303 } | |
304 } | |
305 | |
306 // ------------------------------------------------------------------ | |
307 // ciInstanceKlass::super | |
308 // | |
309 // Get the superklass of this klass. | |
310 ciInstanceKlass* ciInstanceKlass::super() { | |
311 assert(is_loaded(), "must be loaded"); | |
312 if (_super == NULL && !is_java_lang_Object()) { | |
313 GUARDED_VM_ENTRY( | |
314 klassOop super_klass = get_instanceKlass()->super(); | |
315 _super = CURRENT_ENV->get_object(super_klass)->as_instance_klass(); | |
316 ) | |
317 } | |
318 return _super; | |
319 } | |
320 | |
321 // ------------------------------------------------------------------ | |
322 // ciInstanceKlass::java_mirror | |
323 // | |
324 // Get the instance of java.lang.Class corresponding to this klass. | |
325 ciInstance* ciInstanceKlass::java_mirror() { | |
326 assert(is_loaded(), "must be loaded"); | |
327 if (_java_mirror == NULL) { | |
328 _java_mirror = ciKlass::java_mirror(); | |
329 } | |
330 return _java_mirror; | |
331 } | |
332 | |
333 // ------------------------------------------------------------------ | |
334 // ciInstanceKlass::unique_concrete_subklass | |
335 ciInstanceKlass* ciInstanceKlass::unique_concrete_subklass() { | |
336 if (!is_loaded()) return NULL; // No change if class is not loaded | |
337 if (!is_abstract()) return NULL; // Only applies to abstract classes. | |
338 if (!has_subklass()) return NULL; // Must have at least one subklass. | |
339 VM_ENTRY_MARK; | |
340 instanceKlass* ik = get_instanceKlass(); | |
341 Klass* up = ik->up_cast_abstract(); | |
342 assert(up->oop_is_instance(), "must be instanceKlass"); | |
343 if (ik == up) { | |
344 return NULL; | |
345 } | |
346 return CURRENT_THREAD_ENV->get_object(up->as_klassOop())->as_instance_klass(); | |
347 } | |
348 | |
349 // ------------------------------------------------------------------ | |
350 // ciInstanceKlass::has_finalizable_subclass | |
351 bool ciInstanceKlass::has_finalizable_subclass() { | |
352 if (!is_loaded()) return true; | |
353 VM_ENTRY_MARK; | |
354 return Dependencies::find_finalizable_subclass(get_instanceKlass()) != NULL; | |
355 } | |
356 | |
357 // ------------------------------------------------------------------ | |
358 // ciInstanceKlass::get_field_by_offset | |
359 ciField* ciInstanceKlass::get_field_by_offset(int field_offset, bool is_static) { | |
360 if (!is_static) { | |
361 for (int i = 0, len = nof_nonstatic_fields(); i < len; i++) { | |
362 ciField* field = _nonstatic_fields->at(i); | |
363 int field_off = field->offset_in_bytes(); | |
364 if (field_off == field_offset) | |
365 return field; | |
366 if (field_off > field_offset) | |
367 break; | |
368 // could do binary search or check bins, but probably not worth it | |
369 } | |
370 return NULL; | |
371 } | |
372 VM_ENTRY_MARK; | |
373 instanceKlass* k = get_instanceKlass(); | |
374 fieldDescriptor fd; | |
375 if (!k->find_field_from_offset(field_offset, is_static, &fd)) { | |
376 return NULL; | |
377 } | |
378 ciField* field = new (CURRENT_THREAD_ENV->arena()) ciField(&fd); | |
379 return field; | |
380 } | |
381 | |
44
52fed2ec0afb
6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents:
0
diff
changeset
|
382 // ------------------------------------------------------------------ |
1080
7c57aead6d3e
6892658: C2 should optimize some stringbuilder patterns
never
parents:
196
diff
changeset
|
383 // ciInstanceKlass::get_field_by_name |
7c57aead6d3e
6892658: C2 should optimize some stringbuilder patterns
never
parents:
196
diff
changeset
|
384 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
|
385 VM_ENTRY_MARK; |
7c57aead6d3e
6892658: C2 should optimize some stringbuilder patterns
never
parents:
196
diff
changeset
|
386 instanceKlass* k = get_instanceKlass(); |
7c57aead6d3e
6892658: C2 should optimize some stringbuilder patterns
never
parents:
196
diff
changeset
|
387 fieldDescriptor fd; |
7c57aead6d3e
6892658: C2 should optimize some stringbuilder patterns
never
parents:
196
diff
changeset
|
388 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
|
389 if (def == NULL) { |
7c57aead6d3e
6892658: C2 should optimize some stringbuilder patterns
never
parents:
196
diff
changeset
|
390 return NULL; |
7c57aead6d3e
6892658: C2 should optimize some stringbuilder patterns
never
parents:
196
diff
changeset
|
391 } |
7c57aead6d3e
6892658: C2 should optimize some stringbuilder patterns
never
parents:
196
diff
changeset
|
392 ciField* field = new (CURRENT_THREAD_ENV->arena()) ciField(&fd); |
7c57aead6d3e
6892658: C2 should optimize some stringbuilder patterns
never
parents:
196
diff
changeset
|
393 return field; |
7c57aead6d3e
6892658: C2 should optimize some stringbuilder patterns
never
parents:
196
diff
changeset
|
394 } |
7c57aead6d3e
6892658: C2 should optimize some stringbuilder patterns
never
parents:
196
diff
changeset
|
395 |
7c57aead6d3e
6892658: C2 should optimize some stringbuilder patterns
never
parents:
196
diff
changeset
|
396 // ------------------------------------------------------------------ |
44
52fed2ec0afb
6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents:
0
diff
changeset
|
397 // ciInstanceKlass::non_static_fields. |
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 class NonStaticFieldFiller: public FieldClosure { |
52fed2ec0afb
6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents:
0
diff
changeset
|
400 GrowableArray<ciField*>* _arr; |
52fed2ec0afb
6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents:
0
diff
changeset
|
401 ciEnv* _curEnv; |
52fed2ec0afb
6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents:
0
diff
changeset
|
402 public: |
52fed2ec0afb
6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents:
0
diff
changeset
|
403 NonStaticFieldFiller(ciEnv* curEnv, GrowableArray<ciField*>* arr) : |
52fed2ec0afb
6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents:
0
diff
changeset
|
404 _curEnv(curEnv), _arr(arr) |
52fed2ec0afb
6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents:
0
diff
changeset
|
405 {} |
52fed2ec0afb
6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents:
0
diff
changeset
|
406 void do_field(fieldDescriptor* fd) { |
52fed2ec0afb
6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents:
0
diff
changeset
|
407 ciField* field = new (_curEnv->arena()) ciField(fd); |
52fed2ec0afb
6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents:
0
diff
changeset
|
408 _arr->append(field); |
52fed2ec0afb
6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents:
0
diff
changeset
|
409 } |
52fed2ec0afb
6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents:
0
diff
changeset
|
410 }; |
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 GrowableArray<ciField*>* ciInstanceKlass::non_static_fields() { |
52fed2ec0afb
6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents:
0
diff
changeset
|
413 if (_non_static_fields == NULL) { |
52fed2ec0afb
6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents:
0
diff
changeset
|
414 VM_ENTRY_MARK; |
52fed2ec0afb
6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents:
0
diff
changeset
|
415 ciEnv* curEnv = ciEnv::current(); |
52fed2ec0afb
6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents:
0
diff
changeset
|
416 instanceKlass* ik = get_instanceKlass(); |
52fed2ec0afb
6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents:
0
diff
changeset
|
417 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
|
418 |
52fed2ec0afb
6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents:
0
diff
changeset
|
419 _non_static_fields = |
52fed2ec0afb
6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents:
0
diff
changeset
|
420 new (curEnv->arena()) GrowableArray<ciField*>(max_n_fields); |
52fed2ec0afb
6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents:
0
diff
changeset
|
421 NonStaticFieldFiller filler(curEnv, _non_static_fields); |
52fed2ec0afb
6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents:
0
diff
changeset
|
422 ik->do_nonstatic_fields(&filler); |
52fed2ec0afb
6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents:
0
diff
changeset
|
423 } |
52fed2ec0afb
6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents:
0
diff
changeset
|
424 return _non_static_fields; |
52fed2ec0afb
6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents:
0
diff
changeset
|
425 } |
52fed2ec0afb
6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents:
0
diff
changeset
|
426 |
0 | 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 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
44
diff
changeset
|
440 if (!has_nonstatic_fields()) { |
0 | 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 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
44
diff
changeset
|
447 // 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
|
448 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
|
449 |
0 | 450 ciInstanceKlass* super = this->super(); |
451 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
|
452 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
|
453 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
|
454 int super_flen = super->nof_nonstatic_fields(); |
0 | 455 super_fields = super->_nonstatic_fields; |
456 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
|
457 // 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
|
458 if (fsize == super_fsize) { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
44
diff
changeset
|
459 _nonstatic_fields = super_fields; |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
44
diff
changeset
|
460 return super_fields->length(); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
44
diff
changeset
|
461 } |
0 | 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 #ifdef ASSERT | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
44
diff
changeset
|
481 int last_offset = instanceOopDesc::base_offset_in_bytes(); |
0 | 482 for (int i = 0; i < fields->length(); i++) { |
483 ciField* field = fields->at(i); | |
484 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
|
485 int size = (field->_type == NULL) ? heapOopSize : field->size_in_bytes(); |
0 | 486 assert(last_offset <= offset, "no field overlap"); |
487 if (last_offset > (int)sizeof(oopDesc)) | |
488 assert((offset - last_offset) < BytesPerLong, "no big holes"); | |
489 // Note: Two consecutive T_BYTE fields will be separated by wordSize-1 | |
490 // padding bytes if one of them is declared by a superclass. | |
491 // This is a minor inefficiency classFileParser.cpp. | |
492 last_offset = offset + size; | |
493 } | |
165
437d03ea40b1
6703888: Compressed Oops: use the 32-bits gap after klass in a object
kvn
parents:
113
diff
changeset
|
494 assert(last_offset <= (int)instanceOopDesc::base_offset_in_bytes() + fsize, "no overflow"); |
0 | 495 #endif |
496 | |
497 _nonstatic_fields = fields; | |
498 return flen; | |
499 } | |
500 | |
501 GrowableArray<ciField*>* | |
502 ciInstanceKlass::compute_nonstatic_fields_impl(GrowableArray<ciField*>* | |
503 super_fields) { | |
504 ASSERT_IN_VM; | |
505 Arena* arena = CURRENT_ENV->arena(); | |
506 int flen = 0; | |
507 GrowableArray<ciField*>* fields = NULL; | |
508 instanceKlass* k = get_instanceKlass(); | |
509 typeArrayOop fields_array = k->fields(); | |
510 for (int pass = 0; pass <= 1; pass++) { | |
511 for (int i = 0, alen = fields_array->length(); i < alen; i += instanceKlass::next_offset) { | |
512 fieldDescriptor fd; | |
513 fd.initialize(k->as_klassOop(), i); | |
514 if (fd.is_static()) continue; | |
515 if (pass == 0) { | |
516 flen += 1; | |
517 } else { | |
518 ciField* field = new (arena) ciField(&fd); | |
519 fields->append(field); | |
520 } | |
521 } | |
522 | |
523 // Between passes, allocate the array: | |
524 if (pass == 0) { | |
525 if (flen == 0) { | |
526 return NULL; // return nothing if none are locally declared | |
527 } | |
528 if (super_fields != NULL) { | |
529 flen += super_fields->length(); | |
530 } | |
531 fields = new (arena) GrowableArray<ciField*>(arena, flen, 0, NULL); | |
532 if (super_fields != NULL) { | |
533 fields->appendAll(super_fields); | |
534 } | |
535 } | |
536 } | |
537 assert(fields->length() == flen, "sanity"); | |
538 return fields; | |
539 } | |
540 | |
541 // ------------------------------------------------------------------ | |
542 // ciInstanceKlass::find_method | |
543 // | |
544 // Find a method in this klass. | |
545 ciMethod* ciInstanceKlass::find_method(ciSymbol* name, ciSymbol* signature) { | |
546 VM_ENTRY_MARK; | |
547 instanceKlass* k = get_instanceKlass(); | |
548 symbolOop name_sym = name->get_symbolOop(); | |
549 symbolOop sig_sym= signature->get_symbolOop(); | |
550 | |
551 methodOop m = k->find_method(name_sym, sig_sym); | |
552 if (m == NULL) return NULL; | |
553 | |
554 return CURRENT_THREAD_ENV->get_object(m)->as_method(); | |
555 } | |
556 | |
557 // ------------------------------------------------------------------ | |
558 // ciInstanceKlass::is_leaf_type | |
559 bool ciInstanceKlass::is_leaf_type() { | |
560 assert(is_loaded(), "must be loaded"); | |
561 if (is_shared()) { | |
562 return is_final(); // approximately correct | |
563 } else { | |
564 return !_has_subklass && (_nof_implementors == 0); | |
565 } | |
566 } | |
567 | |
568 // ------------------------------------------------------------------ | |
569 // ciInstanceKlass::implementor | |
570 // | |
571 // Report an implementor of this interface. | |
572 // Returns NULL if exact information is not available. | |
573 // Note that there are various races here, since my copy | |
574 // of _nof_implementors might be out of date with respect | |
575 // to results returned by instanceKlass::implementor. | |
576 // This is OK, since any dependencies we decide to assert | |
577 // will be checked later under the Compile_lock. | |
578 ciInstanceKlass* ciInstanceKlass::implementor(int n) { | |
579 if (n > implementors_limit) { | |
580 return NULL; | |
581 } | |
582 ciInstanceKlass* impl = _implementors[n]; | |
583 if (impl == NULL) { | |
584 if (_nof_implementors > implementors_limit) { | |
585 return NULL; | |
586 } | |
587 // Go into the VM to fetch the implementor. | |
588 { | |
589 VM_ENTRY_MARK; | |
590 klassOop k = get_instanceKlass()->implementor(n); | |
591 if (k != NULL) { | |
592 impl = CURRENT_THREAD_ENV->get_object(k)->as_instance_klass(); | |
593 } | |
594 } | |
595 // Memoize this result. | |
596 if (!is_shared()) { | |
597 _implementors[n] = (impl == NULL)? this: impl; | |
598 } | |
599 } else if (impl == this) { | |
600 impl = NULL; // memoized null result from a VM query | |
601 } | |
602 return impl; | |
603 } |