Mercurial > hg > truffle
annotate src/share/vm/ci/ciObjectFactory.cpp @ 1137:97125851f396
6829187: compiler optimizations required for JSR 292
Summary: C2 implementation for invokedynamic support.
Reviewed-by: kvn, never
author | twisti |
---|---|
date | Tue, 05 Jan 2010 13:05:58 +0100 |
parents | 7c57aead6d3e |
children | dd57230ba8fe |
rev | line source |
---|---|
0 | 1 /* |
948 | 2 * Copyright 1999-2009 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/_ciObjectFactory.cpp.incl" | |
27 | |
28 // ciObjectFactory | |
29 // | |
30 // This class handles requests for the creation of new instances | |
31 // of ciObject and its subclasses. It contains a caching mechanism | |
32 // which ensures that for each oop, at most one ciObject is created. | |
33 // This invariant allows more efficient implementation of ciObject. | |
34 // | |
35 // Implementation note: the oop->ciObject mapping is represented as | |
36 // a table stored in an array. Even though objects are moved | |
37 // by the garbage collector, the compactor preserves their relative | |
38 // order; address comparison of oops (in perm space) is safe so long | |
39 // as we prohibit GC during our comparisons. We currently use binary | |
40 // search to find the oop in the table, and inserting a new oop | |
41 // into the table may be costly. If this cost ends up being | |
42 // problematic the underlying data structure can be switched to some | |
43 // sort of balanced binary tree. | |
44 | |
45 GrowableArray<ciObject*>* ciObjectFactory::_shared_ci_objects = NULL; | |
46 ciSymbol* ciObjectFactory::_shared_ci_symbols[vmSymbols::SID_LIMIT]; | |
47 int ciObjectFactory::_shared_ident_limit = 0; | |
48 volatile bool ciObjectFactory::_initialized = false; | |
49 | |
50 | |
51 // ------------------------------------------------------------------ | |
52 // ciObjectFactory::ciObjectFactory | |
53 ciObjectFactory::ciObjectFactory(Arena* arena, | |
54 int expected_size) { | |
55 | |
56 for (int i = 0; i < NON_PERM_BUCKETS; i++) { | |
57 _non_perm_bucket[i] = NULL; | |
58 } | |
59 _non_perm_count = 0; | |
60 | |
61 _next_ident = _shared_ident_limit; | |
62 _arena = arena; | |
63 _ci_objects = new (arena) GrowableArray<ciObject*>(arena, expected_size, 0, NULL); | |
64 | |
65 // If the shared ci objects exist append them to this factory's objects | |
66 | |
67 if (_shared_ci_objects != NULL) { | |
68 _ci_objects->appendAll(_shared_ci_objects); | |
69 } | |
70 | |
71 _unloaded_methods = new (arena) GrowableArray<ciMethod*>(arena, 4, 0, NULL); | |
72 _unloaded_klasses = new (arena) GrowableArray<ciKlass*>(arena, 8, 0, NULL); | |
73 _return_addresses = | |
74 new (arena) GrowableArray<ciReturnAddress*>(arena, 8, 0, NULL); | |
75 } | |
76 | |
77 // ------------------------------------------------------------------ | |
78 // ciObjectFactory::ciObjectFactory | |
79 void ciObjectFactory::initialize() { | |
80 ASSERT_IN_VM; | |
81 JavaThread* thread = JavaThread::current(); | |
82 HandleMark handle_mark(thread); | |
83 | |
84 // This Arena is long lived and exists in the resource mark of the | |
85 // compiler thread that initializes the initial ciObjectFactory which | |
86 // creates the shared ciObjects that all later ciObjectFactories use. | |
87 Arena* arena = new Arena(); | |
88 ciEnv initial(arena); | |
89 ciEnv* env = ciEnv::current(); | |
90 env->_factory->init_shared_objects(); | |
91 | |
92 _initialized = true; | |
93 | |
94 } | |
95 | |
96 void ciObjectFactory::init_shared_objects() { | |
97 | |
98 _next_ident = 1; // start numbering CI objects at 1 | |
99 | |
100 { | |
101 // Create the shared symbols, but not in _shared_ci_objects. | |
102 int i; | |
103 for (i = vmSymbols::FIRST_SID; i < vmSymbols::SID_LIMIT; i++) { | |
104 symbolHandle sym_handle = vmSymbolHandles::symbol_handle_at((vmSymbols::SID) i); | |
105 assert(vmSymbols::find_sid(sym_handle()) == i, "1-1 mapping"); | |
106 ciSymbol* sym = new (_arena) ciSymbol(sym_handle); | |
107 init_ident_of(sym); | |
108 _shared_ci_symbols[i] = sym; | |
109 } | |
110 #ifdef ASSERT | |
111 for (i = vmSymbols::FIRST_SID; i < vmSymbols::SID_LIMIT; i++) { | |
112 symbolHandle sym_handle = vmSymbolHandles::symbol_handle_at((vmSymbols::SID) i); | |
113 ciSymbol* sym = vm_symbol_at((vmSymbols::SID) i); | |
114 assert(sym->get_oop() == sym_handle(), "oop must match"); | |
115 } | |
116 assert(ciSymbol::void_class_signature()->get_oop() == vmSymbols::void_class_signature(), "spot check"); | |
117 #endif | |
118 } | |
119 | |
120 _ci_objects = new (_arena) GrowableArray<ciObject*>(_arena, 64, 0, NULL); | |
121 | |
122 for (int i = T_BOOLEAN; i <= T_CONFLICT; i++) { | |
123 BasicType t = (BasicType)i; | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
124 if (type2name(t) != NULL && t != T_OBJECT && t != T_ARRAY && t != T_NARROWOOP) { |
0 | 125 ciType::_basic_types[t] = new (_arena) ciType(t); |
126 init_ident_of(ciType::_basic_types[t]); | |
127 } | |
128 } | |
129 | |
130 ciEnv::_null_object_instance = new (_arena) ciNullObject(); | |
131 init_ident_of(ciEnv::_null_object_instance); | |
132 ciEnv::_method_klass_instance = | |
133 get(Universe::methodKlassObj())->as_method_klass(); | |
134 ciEnv::_symbol_klass_instance = | |
135 get(Universe::symbolKlassObj())->as_symbol_klass(); | |
136 ciEnv::_klass_klass_instance = | |
137 get(Universe::klassKlassObj())->as_klass_klass(); | |
138 ciEnv::_instance_klass_klass_instance = | |
139 get(Universe::instanceKlassKlassObj()) | |
140 ->as_instance_klass_klass(); | |
141 ciEnv::_type_array_klass_klass_instance = | |
142 get(Universe::typeArrayKlassKlassObj()) | |
143 ->as_type_array_klass_klass(); | |
144 ciEnv::_obj_array_klass_klass_instance = | |
145 get(Universe::objArrayKlassKlassObj()) | |
146 ->as_obj_array_klass_klass(); | |
147 ciEnv::_ArrayStoreException = | |
148 get(SystemDictionary::ArrayStoreException_klass()) | |
149 ->as_instance_klass(); | |
150 ciEnv::_Class = | |
151 get(SystemDictionary::class_klass()) | |
152 ->as_instance_klass(); | |
153 ciEnv::_ClassCastException = | |
154 get(SystemDictionary::ClassCastException_klass()) | |
155 ->as_instance_klass(); | |
1137
97125851f396
6829187: compiler optimizations required for JSR 292
twisti
parents:
1080
diff
changeset
|
156 if (EnableInvokeDynamic) { |
97125851f396
6829187: compiler optimizations required for JSR 292
twisti
parents:
1080
diff
changeset
|
157 ciEnv::_InvokeDynamic = |
97125851f396
6829187: compiler optimizations required for JSR 292
twisti
parents:
1080
diff
changeset
|
158 get(SystemDictionary::InvokeDynamic_klass())->as_instance_klass(); |
97125851f396
6829187: compiler optimizations required for JSR 292
twisti
parents:
1080
diff
changeset
|
159 } |
0 | 160 ciEnv::_Object = |
161 get(SystemDictionary::object_klass()) | |
162 ->as_instance_klass(); | |
163 ciEnv::_Throwable = | |
164 get(SystemDictionary::throwable_klass()) | |
165 ->as_instance_klass(); | |
166 ciEnv::_Thread = | |
167 get(SystemDictionary::thread_klass()) | |
168 ->as_instance_klass(); | |
169 ciEnv::_OutOfMemoryError = | |
170 get(SystemDictionary::OutOfMemoryError_klass()) | |
171 ->as_instance_klass(); | |
172 ciEnv::_String = | |
173 get(SystemDictionary::string_klass()) | |
174 ->as_instance_klass(); | |
1080
7c57aead6d3e
6892658: C2 should optimize some stringbuilder patterns
never
parents:
1000
diff
changeset
|
175 ciEnv::_StringBuffer = |
7c57aead6d3e
6892658: C2 should optimize some stringbuilder patterns
never
parents:
1000
diff
changeset
|
176 get(SystemDictionary::stringBuffer_klass()) |
7c57aead6d3e
6892658: C2 should optimize some stringbuilder patterns
never
parents:
1000
diff
changeset
|
177 ->as_instance_klass(); |
7c57aead6d3e
6892658: C2 should optimize some stringbuilder patterns
never
parents:
1000
diff
changeset
|
178 ciEnv::_StringBuilder = |
7c57aead6d3e
6892658: C2 should optimize some stringbuilder patterns
never
parents:
1000
diff
changeset
|
179 get(SystemDictionary::StringBuilder_klass()) |
7c57aead6d3e
6892658: C2 should optimize some stringbuilder patterns
never
parents:
1000
diff
changeset
|
180 ->as_instance_klass(); |
7c57aead6d3e
6892658: C2 should optimize some stringbuilder patterns
never
parents:
1000
diff
changeset
|
181 ciEnv::_Integer = |
7c57aead6d3e
6892658: C2 should optimize some stringbuilder patterns
never
parents:
1000
diff
changeset
|
182 get(SystemDictionary::int_klass()) |
7c57aead6d3e
6892658: C2 should optimize some stringbuilder patterns
never
parents:
1000
diff
changeset
|
183 ->as_instance_klass(); |
0 | 184 |
185 for (int len = -1; len != _ci_objects->length(); ) { | |
186 len = _ci_objects->length(); | |
187 for (int i2 = 0; i2 < len; i2++) { | |
188 ciObject* obj = _ci_objects->at(i2); | |
189 if (obj->is_loaded() && obj->is_instance_klass()) { | |
190 obj->as_instance_klass()->compute_nonstatic_fields(); | |
191 } | |
192 } | |
193 } | |
194 | |
195 ciEnv::_unloaded_cisymbol = (ciSymbol*) ciObjectFactory::get(vmSymbols::dummy_symbol_oop()); | |
196 // Create dummy instanceKlass and objArrayKlass object and assign them idents | |
197 ciEnv::_unloaded_ciinstance_klass = new (_arena) ciInstanceKlass(ciEnv::_unloaded_cisymbol, NULL, NULL); | |
198 init_ident_of(ciEnv::_unloaded_ciinstance_klass); | |
199 ciEnv::_unloaded_ciobjarrayklass = new (_arena) ciObjArrayKlass(ciEnv::_unloaded_cisymbol, ciEnv::_unloaded_ciinstance_klass, 1); | |
200 init_ident_of(ciEnv::_unloaded_ciobjarrayklass); | |
201 assert(ciEnv::_unloaded_ciobjarrayklass->is_obj_array_klass(), "just checking"); | |
202 | |
203 get(Universe::boolArrayKlassObj()); | |
204 get(Universe::charArrayKlassObj()); | |
205 get(Universe::singleArrayKlassObj()); | |
206 get(Universe::doubleArrayKlassObj()); | |
207 get(Universe::byteArrayKlassObj()); | |
208 get(Universe::shortArrayKlassObj()); | |
209 get(Universe::intArrayKlassObj()); | |
210 get(Universe::longArrayKlassObj()); | |
211 | |
212 | |
213 | |
214 assert(_non_perm_count == 0, "no shared non-perm objects"); | |
215 | |
216 // The shared_ident_limit is the first ident number that will | |
217 // be used for non-shared objects. That is, numbers less than | |
218 // this limit are permanently assigned to shared CI objects, | |
219 // while the higher numbers are recycled afresh by each new ciEnv. | |
220 | |
221 _shared_ident_limit = _next_ident; | |
222 _shared_ci_objects = _ci_objects; | |
223 } | |
224 | |
225 // ------------------------------------------------------------------ | |
226 // ciObjectFactory::get | |
227 // | |
228 // Get the ciObject corresponding to some oop. If the ciObject has | |
229 // already been created, it is returned. Otherwise, a new ciObject | |
230 // is created. | |
231 ciObject* ciObjectFactory::get(oop key) { | |
232 ASSERT_IN_VM; | |
233 | |
234 #ifdef ASSERT | |
909
b32a809aab08
6866585: debug code in ciObjectFactory too slow for large objects
jcoomes
parents:
196
diff
changeset
|
235 if (CIObjectFactoryVerify) { |
b32a809aab08
6866585: debug code in ciObjectFactory too slow for large objects
jcoomes
parents:
196
diff
changeset
|
236 oop last = NULL; |
b32a809aab08
6866585: debug code in ciObjectFactory too slow for large objects
jcoomes
parents:
196
diff
changeset
|
237 for (int j = 0; j< _ci_objects->length(); j++) { |
b32a809aab08
6866585: debug code in ciObjectFactory too slow for large objects
jcoomes
parents:
196
diff
changeset
|
238 oop o = _ci_objects->at(j)->get_oop(); |
b32a809aab08
6866585: debug code in ciObjectFactory too slow for large objects
jcoomes
parents:
196
diff
changeset
|
239 assert(last < o, "out of order"); |
b32a809aab08
6866585: debug code in ciObjectFactory too slow for large objects
jcoomes
parents:
196
diff
changeset
|
240 last = o; |
b32a809aab08
6866585: debug code in ciObjectFactory too slow for large objects
jcoomes
parents:
196
diff
changeset
|
241 } |
0 | 242 } |
243 #endif // ASSERT | |
244 int len = _ci_objects->length(); | |
245 int index = find(key, _ci_objects); | |
246 #ifdef ASSERT | |
909
b32a809aab08
6866585: debug code in ciObjectFactory too slow for large objects
jcoomes
parents:
196
diff
changeset
|
247 if (CIObjectFactoryVerify) { |
b32a809aab08
6866585: debug code in ciObjectFactory too slow for large objects
jcoomes
parents:
196
diff
changeset
|
248 for (int i=0; i<_ci_objects->length(); i++) { |
b32a809aab08
6866585: debug code in ciObjectFactory too slow for large objects
jcoomes
parents:
196
diff
changeset
|
249 if (_ci_objects->at(i)->get_oop() == key) { |
b32a809aab08
6866585: debug code in ciObjectFactory too slow for large objects
jcoomes
parents:
196
diff
changeset
|
250 assert(index == i, " bad lookup"); |
b32a809aab08
6866585: debug code in ciObjectFactory too slow for large objects
jcoomes
parents:
196
diff
changeset
|
251 } |
0 | 252 } |
253 } | |
254 #endif | |
255 if (!is_found_at(index, key, _ci_objects)) { | |
256 // Check in the non-perm area before putting it in the list. | |
257 NonPermObject* &bucket = find_non_perm(key); | |
258 if (bucket != NULL) { | |
259 return bucket->object(); | |
260 } | |
261 | |
262 // Check in the shared symbol area before putting it in the list. | |
263 if (key->is_symbol()) { | |
264 vmSymbols::SID sid = vmSymbols::find_sid((symbolOop)key); | |
265 if (sid != vmSymbols::NO_SID) { | |
266 // do not pollute the main cache with it | |
267 return vm_symbol_at(sid); | |
268 } | |
269 } | |
270 | |
271 // The ciObject does not yet exist. Create it and insert it | |
272 // into the cache. | |
273 Handle keyHandle(key); | |
274 ciObject* new_object = create_new_object(keyHandle()); | |
275 assert(keyHandle() == new_object->get_oop(), "must be properly recorded"); | |
276 init_ident_of(new_object); | |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
909
diff
changeset
|
277 if (!new_object->is_perm()) { |
0 | 278 // Not a perm-space object. |
279 insert_non_perm(bucket, keyHandle(), new_object); | |
280 return new_object; | |
281 } | |
282 if (len != _ci_objects->length()) { | |
283 // creating the new object has recursively entered new objects | |
284 // into the table. We need to recompute our index. | |
285 index = find(keyHandle(), _ci_objects); | |
286 } | |
287 assert(!is_found_at(index, keyHandle(), _ci_objects), "no double insert"); | |
288 insert(index, new_object, _ci_objects); | |
289 return new_object; | |
290 } | |
291 return _ci_objects->at(index); | |
292 } | |
293 | |
294 // ------------------------------------------------------------------ | |
295 // ciObjectFactory::create_new_object | |
296 // | |
297 // Create a new ciObject from an oop. | |
298 // | |
299 // Implementation note: this functionality could be virtual behavior | |
300 // of the oop itself. For now, we explicitly marshal the object. | |
301 ciObject* ciObjectFactory::create_new_object(oop o) { | |
302 EXCEPTION_CONTEXT; | |
303 | |
304 if (o->is_symbol()) { | |
305 symbolHandle h_o(THREAD, (symbolOop)o); | |
306 return new (arena()) ciSymbol(h_o); | |
307 } else if (o->is_klass()) { | |
308 KlassHandle h_k(THREAD, (klassOop)o); | |
309 Klass* k = ((klassOop)o)->klass_part(); | |
310 if (k->oop_is_instance()) { | |
311 return new (arena()) ciInstanceKlass(h_k); | |
312 } else if (k->oop_is_objArray()) { | |
313 return new (arena()) ciObjArrayKlass(h_k); | |
314 } else if (k->oop_is_typeArray()) { | |
315 return new (arena()) ciTypeArrayKlass(h_k); | |
316 } else if (k->oop_is_method()) { | |
317 return new (arena()) ciMethodKlass(h_k); | |
318 } else if (k->oop_is_symbol()) { | |
319 return new (arena()) ciSymbolKlass(h_k); | |
320 } else if (k->oop_is_klass()) { | |
321 if (k->oop_is_objArrayKlass()) { | |
322 return new (arena()) ciObjArrayKlassKlass(h_k); | |
323 } else if (k->oop_is_typeArrayKlass()) { | |
324 return new (arena()) ciTypeArrayKlassKlass(h_k); | |
325 } else if (k->oop_is_instanceKlass()) { | |
326 return new (arena()) ciInstanceKlassKlass(h_k); | |
327 } else { | |
328 assert(o == Universe::klassKlassObj(), "bad klassKlass"); | |
329 return new (arena()) ciKlassKlass(h_k); | |
330 } | |
331 } | |
332 } else if (o->is_method()) { | |
333 methodHandle h_m(THREAD, (methodOop)o); | |
334 return new (arena()) ciMethod(h_m); | |
335 } else if (o->is_methodData()) { | |
336 methodDataHandle h_md(THREAD, (methodDataOop)o); | |
337 return new (arena()) ciMethodData(h_md); | |
338 } else if (o->is_instance()) { | |
339 instanceHandle h_i(THREAD, (instanceOop)o); | |
340 return new (arena()) ciInstance(h_i); | |
341 } else if (o->is_objArray()) { | |
342 objArrayHandle h_oa(THREAD, (objArrayOop)o); | |
343 return new (arena()) ciObjArray(h_oa); | |
344 } else if (o->is_typeArray()) { | |
345 typeArrayHandle h_ta(THREAD, (typeArrayOop)o); | |
346 return new (arena()) ciTypeArray(h_ta); | |
1137
97125851f396
6829187: compiler optimizations required for JSR 292
twisti
parents:
1080
diff
changeset
|
347 } else if (o->is_constantPoolCache()) { |
97125851f396
6829187: compiler optimizations required for JSR 292
twisti
parents:
1080
diff
changeset
|
348 constantPoolCacheHandle h_cpc(THREAD, (constantPoolCacheOop) o); |
97125851f396
6829187: compiler optimizations required for JSR 292
twisti
parents:
1080
diff
changeset
|
349 return new (arena()) ciCPCache(h_cpc); |
0 | 350 } |
351 | |
352 // The oop is of some type not supported by the compiler interface. | |
353 ShouldNotReachHere(); | |
354 return NULL; | |
355 } | |
356 | |
357 //------------------------------------------------------------------ | |
358 // ciObjectFactory::get_unloaded_method | |
359 // | |
360 // Get the ciMethod representing an unloaded/unfound method. | |
361 // | |
362 // Implementation note: unloaded methods are currently stored in | |
363 // an unordered array, requiring a linear-time lookup for each | |
364 // unloaded method. This may need to change. | |
365 ciMethod* ciObjectFactory::get_unloaded_method(ciInstanceKlass* holder, | |
366 ciSymbol* name, | |
367 ciSymbol* signature) { | |
368 for (int i=0; i<_unloaded_methods->length(); i++) { | |
369 ciMethod* entry = _unloaded_methods->at(i); | |
370 if (entry->holder()->equals(holder) && | |
371 entry->name()->equals(name) && | |
372 entry->signature()->as_symbol()->equals(signature)) { | |
373 // We've found a match. | |
374 return entry; | |
375 } | |
376 } | |
377 | |
378 // This is a new unloaded method. Create it and stick it in | |
379 // the cache. | |
380 ciMethod* new_method = new (arena()) ciMethod(holder, name, signature); | |
381 | |
382 init_ident_of(new_method); | |
383 _unloaded_methods->append(new_method); | |
384 | |
385 return new_method; | |
386 } | |
387 | |
388 //------------------------------------------------------------------ | |
389 // ciObjectFactory::get_unloaded_klass | |
390 // | |
391 // Get a ciKlass representing an unloaded klass. | |
392 // | |
393 // Implementation note: unloaded klasses are currently stored in | |
394 // an unordered array, requiring a linear-time lookup for each | |
395 // unloaded klass. This may need to change. | |
396 ciKlass* ciObjectFactory::get_unloaded_klass(ciKlass* accessing_klass, | |
397 ciSymbol* name, | |
398 bool create_if_not_found) { | |
399 EXCEPTION_CONTEXT; | |
400 oop loader = NULL; | |
401 oop domain = NULL; | |
402 if (accessing_klass != NULL) { | |
403 loader = accessing_klass->loader(); | |
404 domain = accessing_klass->protection_domain(); | |
405 } | |
406 for (int i=0; i<_unloaded_klasses->length(); i++) { | |
407 ciKlass* entry = _unloaded_klasses->at(i); | |
408 if (entry->name()->equals(name) && | |
409 entry->loader() == loader && | |
410 entry->protection_domain() == domain) { | |
411 // We've found a match. | |
412 return entry; | |
413 } | |
414 } | |
415 | |
416 if (!create_if_not_found) | |
417 return NULL; | |
418 | |
419 // This is a new unloaded klass. Create it and stick it in | |
420 // the cache. | |
421 ciKlass* new_klass = NULL; | |
422 | |
423 // Two cases: this is an unloaded objArrayKlass or an | |
424 // unloaded instanceKlass. Deal with both. | |
425 if (name->byte_at(0) == '[') { | |
426 // Decompose the name.' | |
427 jint dimension = 0; | |
428 symbolOop element_name = NULL; | |
429 BasicType element_type= FieldType::get_array_info(name->get_symbolOop(), | |
430 &dimension, | |
431 &element_name, | |
432 THREAD); | |
433 if (HAS_PENDING_EXCEPTION) { | |
434 CLEAR_PENDING_EXCEPTION; | |
435 CURRENT_THREAD_ENV->record_out_of_memory_failure(); | |
436 return ciEnv::_unloaded_ciobjarrayklass; | |
437 } | |
438 assert(element_type != T_ARRAY, "unsuccessful decomposition"); | |
439 ciKlass* element_klass = NULL; | |
440 if (element_type == T_OBJECT) { | |
441 ciEnv *env = CURRENT_THREAD_ENV; | |
442 ciSymbol* ci_name = env->get_object(element_name)->as_symbol(); | |
443 element_klass = | |
444 env->get_klass_by_name(accessing_klass, ci_name, false)->as_instance_klass(); | |
445 } else { | |
446 assert(dimension > 1, "one dimensional type arrays are always loaded."); | |
447 | |
448 // The type array itself takes care of one of the dimensions. | |
449 dimension--; | |
450 | |
451 // The element klass is a typeArrayKlass. | |
452 element_klass = ciTypeArrayKlass::make(element_type); | |
453 } | |
454 new_klass = new (arena()) ciObjArrayKlass(name, element_klass, dimension); | |
455 } else { | |
456 jobject loader_handle = NULL; | |
457 jobject domain_handle = NULL; | |
458 if (accessing_klass != NULL) { | |
459 loader_handle = accessing_klass->loader_handle(); | |
460 domain_handle = accessing_klass->protection_domain_handle(); | |
461 } | |
462 new_klass = new (arena()) ciInstanceKlass(name, loader_handle, domain_handle); | |
463 } | |
464 init_ident_of(new_klass); | |
465 _unloaded_klasses->append(new_klass); | |
466 | |
467 return new_klass; | |
468 } | |
469 | |
470 //------------------------------------------------------------------ | |
471 // ciObjectFactory::get_empty_methodData | |
472 // | |
473 // Get the ciMethodData representing the methodData for a method with | |
474 // none. | |
475 ciMethodData* ciObjectFactory::get_empty_methodData() { | |
476 ciMethodData* new_methodData = new (arena()) ciMethodData(); | |
477 init_ident_of(new_methodData); | |
478 return new_methodData; | |
479 } | |
480 | |
481 //------------------------------------------------------------------ | |
482 // ciObjectFactory::get_return_address | |
483 // | |
484 // Get a ciReturnAddress for a specified bci. | |
485 ciReturnAddress* ciObjectFactory::get_return_address(int bci) { | |
486 for (int i=0; i<_return_addresses->length(); i++) { | |
487 ciReturnAddress* entry = _return_addresses->at(i); | |
488 if (entry->bci() == bci) { | |
489 // We've found a match. | |
490 return entry; | |
491 } | |
492 } | |
493 | |
494 ciReturnAddress* new_ret_addr = new (arena()) ciReturnAddress(bci); | |
495 init_ident_of(new_ret_addr); | |
496 _return_addresses->append(new_ret_addr); | |
497 return new_ret_addr; | |
498 } | |
499 | |
500 // ------------------------------------------------------------------ | |
501 // ciObjectFactory::init_ident_of | |
502 void ciObjectFactory::init_ident_of(ciObject* obj) { | |
503 obj->set_ident(_next_ident++); | |
504 } | |
505 | |
506 | |
507 // ------------------------------------------------------------------ | |
508 // ciObjectFactory::find | |
509 // | |
510 // Use binary search to find the position of this oop in the cache. | |
511 // If there is no entry in the cache corresponding to this oop, return | |
512 // the position at which the oop should be inserted. | |
513 int ciObjectFactory::find(oop key, GrowableArray<ciObject*>* objects) { | |
514 int min = 0; | |
515 int max = objects->length()-1; | |
516 | |
517 // print_contents(); | |
518 | |
519 while (max >= min) { | |
520 int mid = (max + min) / 2; | |
521 oop value = objects->at(mid)->get_oop(); | |
522 if (value < key) { | |
523 min = mid + 1; | |
524 } else if (value > key) { | |
525 max = mid - 1; | |
526 } else { | |
527 return mid; | |
528 } | |
529 } | |
530 return min; | |
531 } | |
532 | |
533 // ------------------------------------------------------------------ | |
534 // ciObjectFactory::is_found_at | |
535 // | |
536 // Verify that the binary seach found the given key. | |
537 bool ciObjectFactory::is_found_at(int index, oop key, GrowableArray<ciObject*>* objects) { | |
538 return (index < objects->length() && | |
539 objects->at(index)->get_oop() == key); | |
540 } | |
541 | |
542 | |
543 // ------------------------------------------------------------------ | |
544 // ciObjectFactory::insert | |
545 // | |
546 // Insert a ciObject into the table at some index. | |
547 void ciObjectFactory::insert(int index, ciObject* obj, GrowableArray<ciObject*>* objects) { | |
548 int len = objects->length(); | |
549 if (len == index) { | |
550 objects->append(obj); | |
551 } else { | |
552 objects->append(objects->at(len-1)); | |
553 int pos; | |
554 for (pos = len-2; pos >= index; pos--) { | |
555 objects->at_put(pos+1,objects->at(pos)); | |
556 } | |
557 objects->at_put(index, obj); | |
558 } | |
559 #ifdef ASSERT | |
909
b32a809aab08
6866585: debug code in ciObjectFactory too slow for large objects
jcoomes
parents:
196
diff
changeset
|
560 if (CIObjectFactoryVerify) { |
b32a809aab08
6866585: debug code in ciObjectFactory too slow for large objects
jcoomes
parents:
196
diff
changeset
|
561 oop last = NULL; |
b32a809aab08
6866585: debug code in ciObjectFactory too slow for large objects
jcoomes
parents:
196
diff
changeset
|
562 for (int j = 0; j< objects->length(); j++) { |
b32a809aab08
6866585: debug code in ciObjectFactory too slow for large objects
jcoomes
parents:
196
diff
changeset
|
563 oop o = objects->at(j)->get_oop(); |
b32a809aab08
6866585: debug code in ciObjectFactory too slow for large objects
jcoomes
parents:
196
diff
changeset
|
564 assert(last < o, "out of order"); |
b32a809aab08
6866585: debug code in ciObjectFactory too slow for large objects
jcoomes
parents:
196
diff
changeset
|
565 last = o; |
b32a809aab08
6866585: debug code in ciObjectFactory too slow for large objects
jcoomes
parents:
196
diff
changeset
|
566 } |
0 | 567 } |
568 #endif // ASSERT | |
569 } | |
570 | |
571 static ciObjectFactory::NonPermObject* emptyBucket = NULL; | |
572 | |
573 // ------------------------------------------------------------------ | |
574 // ciObjectFactory::find_non_perm | |
575 // | |
576 // Use a small hash table, hashed on the klass of the key. | |
577 // If there is no entry in the cache corresponding to this oop, return | |
578 // the null tail of the bucket into which the oop should be inserted. | |
579 ciObjectFactory::NonPermObject* &ciObjectFactory::find_non_perm(oop key) { | |
580 // Be careful: is_perm might change from false to true. | |
581 // Thus, there might be a matching perm object in the table. | |
582 // If there is, this probe must find it. | |
583 if (key->is_perm() && _non_perm_count == 0) { | |
584 return emptyBucket; | |
585 } else if (key->is_instance()) { | |
586 if (key->klass() == SystemDictionary::class_klass()) { | |
587 // class mirror instances are always perm | |
588 return emptyBucket; | |
589 } | |
590 // fall through to probe | |
591 } else if (key->is_array()) { | |
592 // fall through to probe | |
593 } else { | |
594 // not an array or instance | |
595 return emptyBucket; | |
596 } | |
597 | |
598 ciObject* klass = get(key->klass()); | |
599 NonPermObject* *bp = &_non_perm_bucket[(unsigned) klass->hash() % NON_PERM_BUCKETS]; | |
600 for (NonPermObject* p; (p = (*bp)) != NULL; bp = &p->next()) { | |
601 if (is_equal(p, key)) break; | |
602 } | |
603 return (*bp); | |
604 } | |
605 | |
606 | |
607 | |
608 // ------------------------------------------------------------------ | |
609 // Code for for NonPermObject | |
610 // | |
611 inline ciObjectFactory::NonPermObject::NonPermObject(ciObjectFactory::NonPermObject* &bucket, oop key, ciObject* object) { | |
612 assert(ciObjectFactory::is_initialized(), ""); | |
613 _object = object; | |
614 _next = bucket; | |
615 bucket = this; | |
616 } | |
617 | |
618 | |
619 | |
620 // ------------------------------------------------------------------ | |
621 // ciObjectFactory::insert_non_perm | |
622 // | |
623 // Insert a ciObject into the non-perm table. | |
624 void ciObjectFactory::insert_non_perm(ciObjectFactory::NonPermObject* &where, oop key, ciObject* obj) { | |
625 assert(&where != &emptyBucket, "must not try to fill empty bucket"); | |
626 NonPermObject* p = new (arena()) NonPermObject(where, key, obj); | |
627 assert(where == p && is_equal(p, key) && p->object() == obj, "entry must match"); | |
628 assert(find_non_perm(key) == p, "must find the same spot"); | |
629 ++_non_perm_count; | |
630 } | |
631 | |
632 // ------------------------------------------------------------------ | |
633 // ciObjectFactory::vm_symbol_at | |
634 // Get the ciSymbol corresponding to some index in vmSymbols. | |
635 ciSymbol* ciObjectFactory::vm_symbol_at(int index) { | |
636 assert(index >= vmSymbols::FIRST_SID && index < vmSymbols::SID_LIMIT, "oob"); | |
637 return _shared_ci_symbols[index]; | |
638 } | |
639 | |
640 // ------------------------------------------------------------------ | |
641 // ciObjectFactory::print_contents_impl | |
642 void ciObjectFactory::print_contents_impl() { | |
643 int len = _ci_objects->length(); | |
644 tty->print_cr("ciObjectFactory (%d) oop contents:", len); | |
645 for (int i=0; i<len; i++) { | |
646 _ci_objects->at(i)->print(); | |
647 tty->cr(); | |
648 } | |
649 } | |
650 | |
651 // ------------------------------------------------------------------ | |
652 // ciObjectFactory::print_contents | |
653 void ciObjectFactory::print_contents() { | |
654 print(); | |
655 tty->cr(); | |
656 GUARDED_VM_ENTRY(print_contents_impl();) | |
657 } | |
658 | |
659 // ------------------------------------------------------------------ | |
660 // ciObjectFactory::print | |
661 // | |
662 // Print debugging information about the object factory | |
663 void ciObjectFactory::print() { | |
664 tty->print("<ciObjectFactory oops=%d unloaded_methods=%d unloaded_klasses=%d>", | |
665 _ci_objects->length(), _unloaded_methods->length(), | |
666 _unloaded_klasses->length()); | |
667 } |