comparison src/share/vm/ci/ciObjectFactory.cpp @ 2181:d25d4ca69222

Merge.
author Thomas Wuerthinger <wuerthinger@ssw.jku.at>
date Wed, 16 Feb 2011 13:47:20 +0100
parents 06f017f7daa7 3582bf76420e
children 0654ee04b214
comparison
equal deleted inserted replaced
2108:50b45e2d9725 2181:d25d4ca69222
36 #include "ci/ciObjArray.hpp" 36 #include "ci/ciObjArray.hpp"
37 #include "ci/ciObjArrayKlass.hpp" 37 #include "ci/ciObjArrayKlass.hpp"
38 #include "ci/ciObjArrayKlassKlass.hpp" 38 #include "ci/ciObjArrayKlassKlass.hpp"
39 #include "ci/ciObjectFactory.hpp" 39 #include "ci/ciObjectFactory.hpp"
40 #include "ci/ciSymbol.hpp" 40 #include "ci/ciSymbol.hpp"
41 #include "ci/ciSymbolKlass.hpp"
42 #include "ci/ciTypeArray.hpp" 41 #include "ci/ciTypeArray.hpp"
43 #include "ci/ciTypeArrayKlass.hpp" 42 #include "ci/ciTypeArrayKlass.hpp"
44 #include "ci/ciTypeArrayKlassKlass.hpp" 43 #include "ci/ciTypeArrayKlassKlass.hpp"
45 #include "ci/ciUtilities.hpp" 44 #include "ci/ciUtilities.hpp"
46 #include "classfile/systemDictionary.hpp" 45 #include "classfile/systemDictionary.hpp"
96 _unloaded_methods = new (arena) GrowableArray<ciMethod*>(arena, 4, 0, NULL); 95 _unloaded_methods = new (arena) GrowableArray<ciMethod*>(arena, 4, 0, NULL);
97 _unloaded_klasses = new (arena) GrowableArray<ciKlass*>(arena, 8, 0, NULL); 96 _unloaded_klasses = new (arena) GrowableArray<ciKlass*>(arena, 8, 0, NULL);
98 _unloaded_instances = new (arena) GrowableArray<ciInstance*>(arena, 4, 0, NULL); 97 _unloaded_instances = new (arena) GrowableArray<ciInstance*>(arena, 4, 0, NULL);
99 _return_addresses = 98 _return_addresses =
100 new (arena) GrowableArray<ciReturnAddress*>(arena, 8, 0, NULL); 99 new (arena) GrowableArray<ciReturnAddress*>(arena, 8, 0, NULL);
100
101 _symbols = new (arena) GrowableArray<ciSymbol*>(arena, 100, 0, NULL);
101 } 102 }
102 103
103 void ciObjectFactory::cleanup() { 104 void ciObjectFactory::cleanup() {
104 int start = 0; 105 int start = 0;
105 if (_shared_ci_objects != NULL) start = _shared_ci_objects->length(); 106 if (_shared_ci_objects != NULL) start = _shared_ci_objects->length();
133 134
134 { 135 {
135 // Create the shared symbols, but not in _shared_ci_objects. 136 // Create the shared symbols, but not in _shared_ci_objects.
136 int i; 137 int i;
137 for (i = vmSymbols::FIRST_SID; i < vmSymbols::SID_LIMIT; i++) { 138 for (i = vmSymbols::FIRST_SID; i < vmSymbols::SID_LIMIT; i++) {
138 symbolHandle sym_handle = vmSymbolHandles::symbol_handle_at((vmSymbols::SID) i); 139 Symbol* vmsym = vmSymbols::symbol_at((vmSymbols::SID) i);
139 assert(vmSymbols::find_sid(sym_handle()) == i, "1-1 mapping"); 140 assert(vmSymbols::find_sid(vmsym) == i, "1-1 mapping");
140 ciSymbol* sym = new (_arena) ciSymbol(sym_handle, (vmSymbols::SID) i); 141 ciSymbol* sym = new (_arena) ciSymbol(vmsym, (vmSymbols::SID) i);
141 init_ident_of(sym); 142 init_ident_of(sym);
142 _shared_ci_symbols[i] = sym; 143 _shared_ci_symbols[i] = sym;
143 } 144 }
144 #ifdef ASSERT 145 #ifdef ASSERT
145 for (i = vmSymbols::FIRST_SID; i < vmSymbols::SID_LIMIT; i++) { 146 for (i = vmSymbols::FIRST_SID; i < vmSymbols::SID_LIMIT; i++) {
146 symbolHandle sym_handle = vmSymbolHandles::symbol_handle_at((vmSymbols::SID) i); 147 Symbol* vmsym = vmSymbols::symbol_at((vmSymbols::SID) i);
147 ciSymbol* sym = vm_symbol_at((vmSymbols::SID) i); 148 ciSymbol* sym = vm_symbol_at((vmSymbols::SID) i);
148 assert(sym->get_oop() == sym_handle(), "oop must match"); 149 assert(sym->get_symbol() == vmsym, "oop must match");
149 } 150 }
150 assert(ciSymbol::void_class_signature()->get_oop() == vmSymbols::void_class_signature(), "spot check"); 151 assert(ciSymbol::void_class_signature()->get_symbol() == vmSymbols::void_class_signature(), "spot check");
151 #endif 152 #endif
152 } 153 }
153 154
154 _ci_objects = new (_arena) GrowableArray<ciObject*>(_arena, 64, 0, NULL); 155 _ci_objects = new (_arena) GrowableArray<ciObject*>(_arena, 64, 0, NULL);
155 156
163 164
164 ciEnv::_null_object_instance = new (_arena) ciNullObject(); 165 ciEnv::_null_object_instance = new (_arena) ciNullObject();
165 init_ident_of(ciEnv::_null_object_instance); 166 init_ident_of(ciEnv::_null_object_instance);
166 ciEnv::_method_klass_instance = 167 ciEnv::_method_klass_instance =
167 get(Universe::methodKlassObj())->as_method_klass(); 168 get(Universe::methodKlassObj())->as_method_klass();
168 ciEnv::_symbol_klass_instance =
169 get(Universe::symbolKlassObj())->as_symbol_klass();
170 ciEnv::_klass_klass_instance = 169 ciEnv::_klass_klass_instance =
171 get(Universe::klassKlassObj())->as_klass_klass(); 170 get(Universe::klassKlassObj())->as_klass_klass();
172 ciEnv::_instance_klass_klass_instance = 171 ciEnv::_instance_klass_klass_instance =
173 get(Universe::instanceKlassKlassObj()) 172 get(Universe::instanceKlassKlassObj())
174 ->as_instance_klass_klass(); 173 ->as_instance_klass_klass();
194 obj->as_instance_klass()->compute_nonstatic_fields(); 193 obj->as_instance_klass()->compute_nonstatic_fields();
195 } 194 }
196 } 195 }
197 } 196 }
198 197
199 ciEnv::_unloaded_cisymbol = (ciSymbol*) ciObjectFactory::get(vmSymbols::dummy_symbol_oop()); 198 ciEnv::_unloaded_cisymbol = ciObjectFactory::get_symbol(vmSymbols::dummy_symbol());
200 // Create dummy instanceKlass and objArrayKlass object and assign them idents 199 // Create dummy instanceKlass and objArrayKlass object and assign them idents
201 ciEnv::_unloaded_ciinstance_klass = new (_arena) ciInstanceKlass(ciEnv::_unloaded_cisymbol, NULL, NULL); 200 ciEnv::_unloaded_ciinstance_klass = new (_arena) ciInstanceKlass(ciEnv::_unloaded_cisymbol, NULL, NULL);
202 init_ident_of(ciEnv::_unloaded_ciinstance_klass); 201 init_ident_of(ciEnv::_unloaded_ciinstance_klass);
203 ciEnv::_unloaded_ciobjarrayklass = new (_arena) ciObjArrayKlass(ciEnv::_unloaded_cisymbol, ciEnv::_unloaded_ciinstance_klass, 1); 202 ciEnv::_unloaded_ciobjarrayklass = new (_arena) ciObjArrayKlass(ciEnv::_unloaded_cisymbol, ciEnv::_unloaded_ciinstance_klass, 1);
204 init_ident_of(ciEnv::_unloaded_ciobjarrayklass); 203 init_ident_of(ciEnv::_unloaded_ciobjarrayklass);
222 // this limit are permanently assigned to shared CI objects, 221 // this limit are permanently assigned to shared CI objects,
223 // while the higher numbers are recycled afresh by each new ciEnv. 222 // while the higher numbers are recycled afresh by each new ciEnv.
224 223
225 _shared_ident_limit = _next_ident; 224 _shared_ident_limit = _next_ident;
226 _shared_ci_objects = _ci_objects; 225 _shared_ci_objects = _ci_objects;
226 }
227
228
229 ciSymbol* ciObjectFactory::get_symbol(Symbol* key) {
230 vmSymbols::SID sid = vmSymbols::find_sid(key);
231 if (sid != vmSymbols::NO_SID) {
232 // do not pollute the main cache with it
233 return vm_symbol_at(sid);
234 }
235
236 assert(vmSymbols::find_sid(key) == vmSymbols::NO_SID, "");
237 ciSymbol* s = new (arena()) ciSymbol(key, vmSymbols::NO_SID);
238 _symbols->push(s);
239 return s;
240 }
241
242 // Decrement the refcount when done on symbols referenced by this compilation.
243 void ciObjectFactory::remove_symbols() {
244 for (int i = 0; i < _symbols->length(); i++) {
245 ciSymbol* s = _symbols->at(i);
246 s->get_symbol()->decrement_refcount();
247 }
248 // Since _symbols is resource allocated we're not allowed to delete it
249 // but it'll go away just the same.
227 } 250 }
228 251
229 // ------------------------------------------------------------------ 252 // ------------------------------------------------------------------
230 // ciObjectFactory::get 253 // ciObjectFactory::get
231 // 254 //
259 if (!is_found_at(index, key, _ci_objects)) { 282 if (!is_found_at(index, key, _ci_objects)) {
260 // Check in the non-perm area before putting it in the list. 283 // Check in the non-perm area before putting it in the list.
261 NonPermObject* &bucket = find_non_perm(key); 284 NonPermObject* &bucket = find_non_perm(key);
262 if (bucket != NULL) { 285 if (bucket != NULL) {
263 return bucket->object(); 286 return bucket->object();
264 }
265
266 // Check in the shared symbol area before putting it in the list.
267 if (key->is_symbol()) {
268 vmSymbols::SID sid = vmSymbols::find_sid((symbolOop)key);
269 if (sid != vmSymbols::NO_SID) {
270 // do not pollute the main cache with it
271 return vm_symbol_at(sid);
272 }
273 } 287 }
274 288
275 // The ciObject does not yet exist. Create it and insert it 289 // The ciObject does not yet exist. Create it and insert it
276 // into the cache. 290 // into the cache.
277 Handle keyHandle(key); 291 Handle keyHandle(key);
303 // Implementation note: this functionality could be virtual behavior 317 // Implementation note: this functionality could be virtual behavior
304 // of the oop itself. For now, we explicitly marshal the object. 318 // of the oop itself. For now, we explicitly marshal the object.
305 ciObject* ciObjectFactory::create_new_object(oop o) { 319 ciObject* ciObjectFactory::create_new_object(oop o) {
306 EXCEPTION_CONTEXT; 320 EXCEPTION_CONTEXT;
307 321
308 if (o->is_symbol()) { 322 if (o->is_klass()) {
309 symbolHandle h_o(THREAD, (symbolOop)o);
310 assert(vmSymbols::find_sid(h_o()) == vmSymbols::NO_SID, "");
311 return new (arena()) ciSymbol(h_o, vmSymbols::NO_SID);
312 } else if (o->is_klass()) {
313 KlassHandle h_k(THREAD, (klassOop)o); 323 KlassHandle h_k(THREAD, (klassOop)o);
314 Klass* k = ((klassOop)o)->klass_part(); 324 Klass* k = ((klassOop)o)->klass_part();
315 if (k->oop_is_instance()) { 325 if (k->oop_is_instance()) {
316 return new (arena()) ciInstanceKlass(h_k); 326 return new (arena()) ciInstanceKlass(h_k);
317 } else if (k->oop_is_objArray()) { 327 } else if (k->oop_is_objArray()) {
318 return new (arena()) ciObjArrayKlass(h_k); 328 return new (arena()) ciObjArrayKlass(h_k);
319 } else if (k->oop_is_typeArray()) { 329 } else if (k->oop_is_typeArray()) {
320 return new (arena()) ciTypeArrayKlass(h_k); 330 return new (arena()) ciTypeArrayKlass(h_k);
321 } else if (k->oop_is_method()) { 331 } else if (k->oop_is_method()) {
322 return new (arena()) ciMethodKlass(h_k); 332 return new (arena()) ciMethodKlass(h_k);
323 } else if (k->oop_is_symbol()) {
324 return new (arena()) ciSymbolKlass(h_k);
325 } else if (k->oop_is_klass()) { 333 } else if (k->oop_is_klass()) {
326 if (k->oop_is_objArrayKlass()) { 334 if (k->oop_is_objArrayKlass()) {
327 return new (arena()) ciObjArrayKlassKlass(h_k); 335 return new (arena()) ciObjArrayKlassKlass(h_k);
328 } else if (k->oop_is_typeArrayKlass()) { 336 } else if (k->oop_is_typeArrayKlass()) {
329 return new (arena()) ciTypeArrayKlassKlass(h_k); 337 return new (arena()) ciTypeArrayKlassKlass(h_k);
432 440
433 // Two cases: this is an unloaded objArrayKlass or an 441 // Two cases: this is an unloaded objArrayKlass or an
434 // unloaded instanceKlass. Deal with both. 442 // unloaded instanceKlass. Deal with both.
435 if (name->byte_at(0) == '[') { 443 if (name->byte_at(0) == '[') {
436 // Decompose the name.' 444 // Decompose the name.'
437 jint dimension = 0; 445 FieldArrayInfo fd;
438 symbolOop element_name = NULL; 446 BasicType element_type = FieldType::get_array_info(name->get_symbol(),
439 BasicType element_type= FieldType::get_array_info(name->get_symbolOop(), 447 fd, THREAD);
440 &dimension,
441 &element_name,
442 THREAD);
443 if (HAS_PENDING_EXCEPTION) { 448 if (HAS_PENDING_EXCEPTION) {
444 CLEAR_PENDING_EXCEPTION; 449 CLEAR_PENDING_EXCEPTION;
445 CURRENT_THREAD_ENV->record_out_of_memory_failure(); 450 CURRENT_THREAD_ENV->record_out_of_memory_failure();
446 return ciEnv::_unloaded_ciobjarrayklass; 451 return ciEnv::_unloaded_ciobjarrayklass;
447 } 452 }
453 int dimension = fd.dimension();
448 assert(element_type != T_ARRAY, "unsuccessful decomposition"); 454 assert(element_type != T_ARRAY, "unsuccessful decomposition");
449 ciKlass* element_klass = NULL; 455 ciKlass* element_klass = NULL;
450 if (element_type == T_OBJECT) { 456 if (element_type == T_OBJECT) {
451 ciEnv *env = CURRENT_THREAD_ENV; 457 ciEnv *env = CURRENT_THREAD_ENV;
452 ciSymbol* ci_name = env->get_object(element_name)->as_symbol(); 458 ciSymbol* ci_name = env->get_symbol(fd.object_key());
453 element_klass = 459 element_klass =
454 env->get_klass_by_name(accessing_klass, ci_name, false)->as_instance_klass(); 460 env->get_klass_by_name(accessing_klass, ci_name, false)->as_instance_klass();
455 } else { 461 } else {
456 assert(dimension > 1, "one dimensional type arrays are always loaded."); 462 assert(dimension > 1, "one dimensional type arrays are always loaded.");
457 463
576 } 582 }
577 583
578 // ------------------------------------------------------------------ 584 // ------------------------------------------------------------------
579 // ciObjectFactory::init_ident_of 585 // ciObjectFactory::init_ident_of
580 void ciObjectFactory::init_ident_of(ciObject* obj) { 586 void ciObjectFactory::init_ident_of(ciObject* obj) {
587 obj->set_ident(_next_ident++);
588 }
589
590 void ciObjectFactory::init_ident_of(ciSymbol* obj) {
581 obj->set_ident(_next_ident++); 591 obj->set_ident(_next_ident++);
582 } 592 }
583 593
584 594
585 // ------------------------------------------------------------------ 595 // ------------------------------------------------------------------