Mercurial > hg > truffle
annotate src/share/vm/ci/ciObjectFactory.cpp @ 614:3db67f76d308
Merge
author | acorn |
---|---|
date | Thu, 05 Mar 2009 22:07:29 -0500 |
parents | d1605aabd0a1 |
children | b32a809aab08 |
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/_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(); | |
156 ciEnv::_Object = | |
157 get(SystemDictionary::object_klass()) | |
158 ->as_instance_klass(); | |
159 ciEnv::_Throwable = | |
160 get(SystemDictionary::throwable_klass()) | |
161 ->as_instance_klass(); | |
162 ciEnv::_Thread = | |
163 get(SystemDictionary::thread_klass()) | |
164 ->as_instance_klass(); | |
165 ciEnv::_OutOfMemoryError = | |
166 get(SystemDictionary::OutOfMemoryError_klass()) | |
167 ->as_instance_klass(); | |
168 ciEnv::_String = | |
169 get(SystemDictionary::string_klass()) | |
170 ->as_instance_klass(); | |
171 | |
172 for (int len = -1; len != _ci_objects->length(); ) { | |
173 len = _ci_objects->length(); | |
174 for (int i2 = 0; i2 < len; i2++) { | |
175 ciObject* obj = _ci_objects->at(i2); | |
176 if (obj->is_loaded() && obj->is_instance_klass()) { | |
177 obj->as_instance_klass()->compute_nonstatic_fields(); | |
178 } | |
179 } | |
180 } | |
181 | |
182 ciEnv::_unloaded_cisymbol = (ciSymbol*) ciObjectFactory::get(vmSymbols::dummy_symbol_oop()); | |
183 // Create dummy instanceKlass and objArrayKlass object and assign them idents | |
184 ciEnv::_unloaded_ciinstance_klass = new (_arena) ciInstanceKlass(ciEnv::_unloaded_cisymbol, NULL, NULL); | |
185 init_ident_of(ciEnv::_unloaded_ciinstance_klass); | |
186 ciEnv::_unloaded_ciobjarrayklass = new (_arena) ciObjArrayKlass(ciEnv::_unloaded_cisymbol, ciEnv::_unloaded_ciinstance_klass, 1); | |
187 init_ident_of(ciEnv::_unloaded_ciobjarrayklass); | |
188 assert(ciEnv::_unloaded_ciobjarrayklass->is_obj_array_klass(), "just checking"); | |
189 | |
190 get(Universe::boolArrayKlassObj()); | |
191 get(Universe::charArrayKlassObj()); | |
192 get(Universe::singleArrayKlassObj()); | |
193 get(Universe::doubleArrayKlassObj()); | |
194 get(Universe::byteArrayKlassObj()); | |
195 get(Universe::shortArrayKlassObj()); | |
196 get(Universe::intArrayKlassObj()); | |
197 get(Universe::longArrayKlassObj()); | |
198 | |
199 | |
200 | |
201 assert(_non_perm_count == 0, "no shared non-perm objects"); | |
202 | |
203 // The shared_ident_limit is the first ident number that will | |
204 // be used for non-shared objects. That is, numbers less than | |
205 // this limit are permanently assigned to shared CI objects, | |
206 // while the higher numbers are recycled afresh by each new ciEnv. | |
207 | |
208 _shared_ident_limit = _next_ident; | |
209 _shared_ci_objects = _ci_objects; | |
210 } | |
211 | |
212 // ------------------------------------------------------------------ | |
213 // ciObjectFactory::get | |
214 // | |
215 // Get the ciObject corresponding to some oop. If the ciObject has | |
216 // already been created, it is returned. Otherwise, a new ciObject | |
217 // is created. | |
218 ciObject* ciObjectFactory::get(oop key) { | |
219 ASSERT_IN_VM; | |
220 | |
221 #ifdef ASSERT | |
222 oop last = NULL; | |
223 for (int j = 0; j< _ci_objects->length(); j++) { | |
224 oop o = _ci_objects->at(j)->get_oop(); | |
225 assert(last < o, "out of order"); | |
226 last = o; | |
227 } | |
228 #endif // ASSERT | |
229 int len = _ci_objects->length(); | |
230 int index = find(key, _ci_objects); | |
231 #ifdef ASSERT | |
232 for (int i=0; i<_ci_objects->length(); i++) { | |
233 if (_ci_objects->at(i)->get_oop() == key) { | |
234 assert(index == i, " bad lookup"); | |
235 } | |
236 } | |
237 #endif | |
238 if (!is_found_at(index, key, _ci_objects)) { | |
239 | |
240 // Check in the non-perm area before putting it in the list. | |
241 NonPermObject* &bucket = find_non_perm(key); | |
242 if (bucket != NULL) { | |
243 return bucket->object(); | |
244 } | |
245 | |
246 // Check in the shared symbol area before putting it in the list. | |
247 if (key->is_symbol()) { | |
248 vmSymbols::SID sid = vmSymbols::find_sid((symbolOop)key); | |
249 if (sid != vmSymbols::NO_SID) { | |
250 // do not pollute the main cache with it | |
251 return vm_symbol_at(sid); | |
252 } | |
253 } | |
254 | |
255 // The ciObject does not yet exist. Create it and insert it | |
256 // into the cache. | |
257 Handle keyHandle(key); | |
258 ciObject* new_object = create_new_object(keyHandle()); | |
259 assert(keyHandle() == new_object->get_oop(), "must be properly recorded"); | |
260 init_ident_of(new_object); | |
261 if (!keyHandle->is_perm()) { | |
262 // Not a perm-space object. | |
263 insert_non_perm(bucket, keyHandle(), new_object); | |
264 return new_object; | |
265 } | |
266 new_object->set_perm(); | |
267 if (len != _ci_objects->length()) { | |
268 // creating the new object has recursively entered new objects | |
269 // into the table. We need to recompute our index. | |
270 index = find(keyHandle(), _ci_objects); | |
271 } | |
272 assert(!is_found_at(index, keyHandle(), _ci_objects), "no double insert"); | |
273 insert(index, new_object, _ci_objects); | |
274 return new_object; | |
275 } | |
276 return _ci_objects->at(index); | |
277 } | |
278 | |
279 // ------------------------------------------------------------------ | |
280 // ciObjectFactory::create_new_object | |
281 // | |
282 // Create a new ciObject from an oop. | |
283 // | |
284 // Implementation note: this functionality could be virtual behavior | |
285 // of the oop itself. For now, we explicitly marshal the object. | |
286 ciObject* ciObjectFactory::create_new_object(oop o) { | |
287 EXCEPTION_CONTEXT; | |
288 | |
289 if (o->is_symbol()) { | |
290 symbolHandle h_o(THREAD, (symbolOop)o); | |
291 return new (arena()) ciSymbol(h_o); | |
292 } else if (o->is_klass()) { | |
293 KlassHandle h_k(THREAD, (klassOop)o); | |
294 Klass* k = ((klassOop)o)->klass_part(); | |
295 if (k->oop_is_instance()) { | |
296 return new (arena()) ciInstanceKlass(h_k); | |
297 } else if (k->oop_is_objArray()) { | |
298 return new (arena()) ciObjArrayKlass(h_k); | |
299 } else if (k->oop_is_typeArray()) { | |
300 return new (arena()) ciTypeArrayKlass(h_k); | |
301 } else if (k->oop_is_method()) { | |
302 return new (arena()) ciMethodKlass(h_k); | |
303 } else if (k->oop_is_symbol()) { | |
304 return new (arena()) ciSymbolKlass(h_k); | |
305 } else if (k->oop_is_klass()) { | |
306 if (k->oop_is_objArrayKlass()) { | |
307 return new (arena()) ciObjArrayKlassKlass(h_k); | |
308 } else if (k->oop_is_typeArrayKlass()) { | |
309 return new (arena()) ciTypeArrayKlassKlass(h_k); | |
310 } else if (k->oop_is_instanceKlass()) { | |
311 return new (arena()) ciInstanceKlassKlass(h_k); | |
312 } else { | |
313 assert(o == Universe::klassKlassObj(), "bad klassKlass"); | |
314 return new (arena()) ciKlassKlass(h_k); | |
315 } | |
316 } | |
317 } else if (o->is_method()) { | |
318 methodHandle h_m(THREAD, (methodOop)o); | |
319 return new (arena()) ciMethod(h_m); | |
320 } else if (o->is_methodData()) { | |
321 methodDataHandle h_md(THREAD, (methodDataOop)o); | |
322 return new (arena()) ciMethodData(h_md); | |
323 } else if (o->is_instance()) { | |
324 instanceHandle h_i(THREAD, (instanceOop)o); | |
325 return new (arena()) ciInstance(h_i); | |
326 } else if (o->is_objArray()) { | |
327 objArrayHandle h_oa(THREAD, (objArrayOop)o); | |
328 return new (arena()) ciObjArray(h_oa); | |
329 } else if (o->is_typeArray()) { | |
330 typeArrayHandle h_ta(THREAD, (typeArrayOop)o); | |
331 return new (arena()) ciTypeArray(h_ta); | |
332 } | |
333 | |
334 // The oop is of some type not supported by the compiler interface. | |
335 ShouldNotReachHere(); | |
336 return NULL; | |
337 } | |
338 | |
339 //------------------------------------------------------------------ | |
340 // ciObjectFactory::get_unloaded_method | |
341 // | |
342 // Get the ciMethod representing an unloaded/unfound method. | |
343 // | |
344 // Implementation note: unloaded methods are currently stored in | |
345 // an unordered array, requiring a linear-time lookup for each | |
346 // unloaded method. This may need to change. | |
347 ciMethod* ciObjectFactory::get_unloaded_method(ciInstanceKlass* holder, | |
348 ciSymbol* name, | |
349 ciSymbol* signature) { | |
350 for (int i=0; i<_unloaded_methods->length(); i++) { | |
351 ciMethod* entry = _unloaded_methods->at(i); | |
352 if (entry->holder()->equals(holder) && | |
353 entry->name()->equals(name) && | |
354 entry->signature()->as_symbol()->equals(signature)) { | |
355 // We've found a match. | |
356 return entry; | |
357 } | |
358 } | |
359 | |
360 // This is a new unloaded method. Create it and stick it in | |
361 // the cache. | |
362 ciMethod* new_method = new (arena()) ciMethod(holder, name, signature); | |
363 | |
364 init_ident_of(new_method); | |
365 _unloaded_methods->append(new_method); | |
366 | |
367 return new_method; | |
368 } | |
369 | |
370 //------------------------------------------------------------------ | |
371 // ciObjectFactory::get_unloaded_klass | |
372 // | |
373 // Get a ciKlass representing an unloaded klass. | |
374 // | |
375 // Implementation note: unloaded klasses are currently stored in | |
376 // an unordered array, requiring a linear-time lookup for each | |
377 // unloaded klass. This may need to change. | |
378 ciKlass* ciObjectFactory::get_unloaded_klass(ciKlass* accessing_klass, | |
379 ciSymbol* name, | |
380 bool create_if_not_found) { | |
381 EXCEPTION_CONTEXT; | |
382 oop loader = NULL; | |
383 oop domain = NULL; | |
384 if (accessing_klass != NULL) { | |
385 loader = accessing_klass->loader(); | |
386 domain = accessing_klass->protection_domain(); | |
387 } | |
388 for (int i=0; i<_unloaded_klasses->length(); i++) { | |
389 ciKlass* entry = _unloaded_klasses->at(i); | |
390 if (entry->name()->equals(name) && | |
391 entry->loader() == loader && | |
392 entry->protection_domain() == domain) { | |
393 // We've found a match. | |
394 return entry; | |
395 } | |
396 } | |
397 | |
398 if (!create_if_not_found) | |
399 return NULL; | |
400 | |
401 // This is a new unloaded klass. Create it and stick it in | |
402 // the cache. | |
403 ciKlass* new_klass = NULL; | |
404 | |
405 // Two cases: this is an unloaded objArrayKlass or an | |
406 // unloaded instanceKlass. Deal with both. | |
407 if (name->byte_at(0) == '[') { | |
408 // Decompose the name.' | |
409 jint dimension = 0; | |
410 symbolOop element_name = NULL; | |
411 BasicType element_type= FieldType::get_array_info(name->get_symbolOop(), | |
412 &dimension, | |
413 &element_name, | |
414 THREAD); | |
415 if (HAS_PENDING_EXCEPTION) { | |
416 CLEAR_PENDING_EXCEPTION; | |
417 CURRENT_THREAD_ENV->record_out_of_memory_failure(); | |
418 return ciEnv::_unloaded_ciobjarrayklass; | |
419 } | |
420 assert(element_type != T_ARRAY, "unsuccessful decomposition"); | |
421 ciKlass* element_klass = NULL; | |
422 if (element_type == T_OBJECT) { | |
423 ciEnv *env = CURRENT_THREAD_ENV; | |
424 ciSymbol* ci_name = env->get_object(element_name)->as_symbol(); | |
425 element_klass = | |
426 env->get_klass_by_name(accessing_klass, ci_name, false)->as_instance_klass(); | |
427 } else { | |
428 assert(dimension > 1, "one dimensional type arrays are always loaded."); | |
429 | |
430 // The type array itself takes care of one of the dimensions. | |
431 dimension--; | |
432 | |
433 // The element klass is a typeArrayKlass. | |
434 element_klass = ciTypeArrayKlass::make(element_type); | |
435 } | |
436 new_klass = new (arena()) ciObjArrayKlass(name, element_klass, dimension); | |
437 } else { | |
438 jobject loader_handle = NULL; | |
439 jobject domain_handle = NULL; | |
440 if (accessing_klass != NULL) { | |
441 loader_handle = accessing_klass->loader_handle(); | |
442 domain_handle = accessing_klass->protection_domain_handle(); | |
443 } | |
444 new_klass = new (arena()) ciInstanceKlass(name, loader_handle, domain_handle); | |
445 } | |
446 init_ident_of(new_klass); | |
447 _unloaded_klasses->append(new_klass); | |
448 | |
449 return new_klass; | |
450 } | |
451 | |
452 //------------------------------------------------------------------ | |
453 // ciObjectFactory::get_empty_methodData | |
454 // | |
455 // Get the ciMethodData representing the methodData for a method with | |
456 // none. | |
457 ciMethodData* ciObjectFactory::get_empty_methodData() { | |
458 ciMethodData* new_methodData = new (arena()) ciMethodData(); | |
459 init_ident_of(new_methodData); | |
460 return new_methodData; | |
461 } | |
462 | |
463 //------------------------------------------------------------------ | |
464 // ciObjectFactory::get_return_address | |
465 // | |
466 // Get a ciReturnAddress for a specified bci. | |
467 ciReturnAddress* ciObjectFactory::get_return_address(int bci) { | |
468 for (int i=0; i<_return_addresses->length(); i++) { | |
469 ciReturnAddress* entry = _return_addresses->at(i); | |
470 if (entry->bci() == bci) { | |
471 // We've found a match. | |
472 return entry; | |
473 } | |
474 } | |
475 | |
476 ciReturnAddress* new_ret_addr = new (arena()) ciReturnAddress(bci); | |
477 init_ident_of(new_ret_addr); | |
478 _return_addresses->append(new_ret_addr); | |
479 return new_ret_addr; | |
480 } | |
481 | |
482 // ------------------------------------------------------------------ | |
483 // ciObjectFactory::init_ident_of | |
484 void ciObjectFactory::init_ident_of(ciObject* obj) { | |
485 obj->set_ident(_next_ident++); | |
486 } | |
487 | |
488 | |
489 // ------------------------------------------------------------------ | |
490 // ciObjectFactory::find | |
491 // | |
492 // Use binary search to find the position of this oop in the cache. | |
493 // If there is no entry in the cache corresponding to this oop, return | |
494 // the position at which the oop should be inserted. | |
495 int ciObjectFactory::find(oop key, GrowableArray<ciObject*>* objects) { | |
496 int min = 0; | |
497 int max = objects->length()-1; | |
498 | |
499 // print_contents(); | |
500 | |
501 while (max >= min) { | |
502 int mid = (max + min) / 2; | |
503 oop value = objects->at(mid)->get_oop(); | |
504 if (value < key) { | |
505 min = mid + 1; | |
506 } else if (value > key) { | |
507 max = mid - 1; | |
508 } else { | |
509 return mid; | |
510 } | |
511 } | |
512 return min; | |
513 } | |
514 | |
515 // ------------------------------------------------------------------ | |
516 // ciObjectFactory::is_found_at | |
517 // | |
518 // Verify that the binary seach found the given key. | |
519 bool ciObjectFactory::is_found_at(int index, oop key, GrowableArray<ciObject*>* objects) { | |
520 return (index < objects->length() && | |
521 objects->at(index)->get_oop() == key); | |
522 } | |
523 | |
524 | |
525 // ------------------------------------------------------------------ | |
526 // ciObjectFactory::insert | |
527 // | |
528 // Insert a ciObject into the table at some index. | |
529 void ciObjectFactory::insert(int index, ciObject* obj, GrowableArray<ciObject*>* objects) { | |
530 int len = objects->length(); | |
531 if (len == index) { | |
532 objects->append(obj); | |
533 } else { | |
534 objects->append(objects->at(len-1)); | |
535 int pos; | |
536 for (pos = len-2; pos >= index; pos--) { | |
537 objects->at_put(pos+1,objects->at(pos)); | |
538 } | |
539 objects->at_put(index, obj); | |
540 } | |
541 #ifdef ASSERT | |
542 oop last = NULL; | |
543 for (int j = 0; j< objects->length(); j++) { | |
544 oop o = objects->at(j)->get_oop(); | |
545 assert(last < o, "out of order"); | |
546 last = o; | |
547 } | |
548 #endif // ASSERT | |
549 } | |
550 | |
551 static ciObjectFactory::NonPermObject* emptyBucket = NULL; | |
552 | |
553 // ------------------------------------------------------------------ | |
554 // ciObjectFactory::find_non_perm | |
555 // | |
556 // Use a small hash table, hashed on the klass of the key. | |
557 // If there is no entry in the cache corresponding to this oop, return | |
558 // the null tail of the bucket into which the oop should be inserted. | |
559 ciObjectFactory::NonPermObject* &ciObjectFactory::find_non_perm(oop key) { | |
560 // Be careful: is_perm might change from false to true. | |
561 // Thus, there might be a matching perm object in the table. | |
562 // If there is, this probe must find it. | |
563 if (key->is_perm() && _non_perm_count == 0) { | |
564 return emptyBucket; | |
565 } else if (key->is_instance()) { | |
566 if (key->klass() == SystemDictionary::class_klass()) { | |
567 // class mirror instances are always perm | |
568 return emptyBucket; | |
569 } | |
570 // fall through to probe | |
571 } else if (key->is_array()) { | |
572 // fall through to probe | |
573 } else { | |
574 // not an array or instance | |
575 return emptyBucket; | |
576 } | |
577 | |
578 ciObject* klass = get(key->klass()); | |
579 NonPermObject* *bp = &_non_perm_bucket[(unsigned) klass->hash() % NON_PERM_BUCKETS]; | |
580 for (NonPermObject* p; (p = (*bp)) != NULL; bp = &p->next()) { | |
581 if (is_equal(p, key)) break; | |
582 } | |
583 return (*bp); | |
584 } | |
585 | |
586 | |
587 | |
588 // ------------------------------------------------------------------ | |
589 // Code for for NonPermObject | |
590 // | |
591 inline ciObjectFactory::NonPermObject::NonPermObject(ciObjectFactory::NonPermObject* &bucket, oop key, ciObject* object) { | |
592 assert(ciObjectFactory::is_initialized(), ""); | |
593 _object = object; | |
594 _next = bucket; | |
595 bucket = this; | |
596 } | |
597 | |
598 | |
599 | |
600 // ------------------------------------------------------------------ | |
601 // ciObjectFactory::insert_non_perm | |
602 // | |
603 // Insert a ciObject into the non-perm table. | |
604 void ciObjectFactory::insert_non_perm(ciObjectFactory::NonPermObject* &where, oop key, ciObject* obj) { | |
605 assert(&where != &emptyBucket, "must not try to fill empty bucket"); | |
606 NonPermObject* p = new (arena()) NonPermObject(where, key, obj); | |
607 assert(where == p && is_equal(p, key) && p->object() == obj, "entry must match"); | |
608 assert(find_non_perm(key) == p, "must find the same spot"); | |
609 ++_non_perm_count; | |
610 } | |
611 | |
612 // ------------------------------------------------------------------ | |
613 // ciObjectFactory::vm_symbol_at | |
614 // Get the ciSymbol corresponding to some index in vmSymbols. | |
615 ciSymbol* ciObjectFactory::vm_symbol_at(int index) { | |
616 assert(index >= vmSymbols::FIRST_SID && index < vmSymbols::SID_LIMIT, "oob"); | |
617 return _shared_ci_symbols[index]; | |
618 } | |
619 | |
620 // ------------------------------------------------------------------ | |
621 // ciObjectFactory::print_contents_impl | |
622 void ciObjectFactory::print_contents_impl() { | |
623 int len = _ci_objects->length(); | |
624 tty->print_cr("ciObjectFactory (%d) oop contents:", len); | |
625 for (int i=0; i<len; i++) { | |
626 _ci_objects->at(i)->print(); | |
627 tty->cr(); | |
628 } | |
629 } | |
630 | |
631 // ------------------------------------------------------------------ | |
632 // ciObjectFactory::print_contents | |
633 void ciObjectFactory::print_contents() { | |
634 print(); | |
635 tty->cr(); | |
636 GUARDED_VM_ENTRY(print_contents_impl();) | |
637 } | |
638 | |
639 // ------------------------------------------------------------------ | |
640 // ciObjectFactory::print | |
641 // | |
642 // Print debugging information about the object factory | |
643 void ciObjectFactory::print() { | |
644 tty->print("<ciObjectFactory oops=%d unloaded_methods=%d unloaded_klasses=%d>", | |
645 _ci_objects->length(), _unloaded_methods->length(), | |
646 _unloaded_klasses->length()); | |
647 } |