29 #include "ci/ciMemberName.hpp" 30 #include "ci/ciMethod.hpp" 31 #include "ci/ciMethodData.hpp" 32 #include "ci/ciMethodHandle.hpp" 33 #include "ci/ciMethodType.hpp" 34 #include "ci/ciNullObject.hpp" 35 #include "ci/ciObjArray.hpp" 36 #include "ci/ciObjArrayKlass.hpp" 37 #include "ci/ciObject.hpp" 38 #include "ci/ciObjectFactory.hpp" 39 #include "ci/ciSymbol.hpp" 40 #include "ci/ciTypeArray.hpp" 41 #include "ci/ciTypeArrayKlass.hpp" 42 #include "ci/ciUtilities.hpp" 43 #include "classfile/systemDictionary.hpp" 44 #include "gc_interface/collectedHeap.inline.hpp" 45 #include "memory/allocation.inline.hpp" 46 #include "oops/oop.inline.hpp" 47 #include "oops/oop.inline2.hpp" 48 #include "runtime/fieldType.hpp" 49 50 // ciObjectFactory 51 // 52 // This class handles requests for the creation of new instances 53 // of ciObject and its subclasses. It contains a caching mechanism 54 // which ensures that for each oop, at most one ciObject is created. 55 // This invariant allows more efficient implementation of ciObject. 56 // 57 // Implementation note: the oop->ciObject mapping is represented as 58 // a table stored in an array. Even though objects are moved 59 // by the garbage collector, the compactor preserves their relative 60 // order; address comparison of oops (in perm space) is safe so long 61 // as we prohibit GC during our comparisons. We currently use binary 62 // search to find the oop in the table, and inserting a new oop 63 // into the table may be costly. If this cost ends up being 64 // problematic the underlying data structure can be switched to some 65 // sort of balanced binary tree. 66 67 GrowableArray<ciMetadata*>* ciObjectFactory::_shared_ci_metadata = NULL; 68 ciSymbol* ciObjectFactory::_shared_ci_symbols[vmSymbols::SID_LIMIT]; 355 Klass* k = (Klass*)o; 356 if (k->oop_is_instance()) { 357 return new (arena()) ciInstanceKlass(h_k); 358 } else if (k->oop_is_objArray()) { 359 return new (arena()) ciObjArrayKlass(h_k); 360 } else if (k->oop_is_typeArray()) { 361 return new (arena()) ciTypeArrayKlass(h_k); 362 } 363 } else if (o->is_method()) { 364 methodHandle h_m(THREAD, (Method*)o); 365 return new (arena()) ciMethod(h_m); 366 } else if (o->is_methodData()) { 367 // Hold methodHandle alive - might not be necessary ??? 368 methodHandle h_m(THREAD, ((MethodData*)o)->method()); 369 return new (arena()) ciMethodData((MethodData*)o); 370 } 371 372 // The oop is of some type not supported by the compiler interface. 373 ShouldNotReachHere(); 374 return NULL; 375 } 376 377 //------------------------------------------------------------------ 378 // ciObjectFactory::get_unloaded_method 379 // 380 // Get the ciMethod representing an unloaded/unfound method. 381 // 382 // Implementation note: unloaded methods are currently stored in 383 // an unordered array, requiring a linear-time lookup for each 384 // unloaded method. This may need to change. 385 ciMethod* ciObjectFactory::get_unloaded_method(ciInstanceKlass* holder, 386 ciSymbol* name, 387 ciSymbol* signature, 388 ciInstanceKlass* accessor) { 389 ciSignature* that = NULL; 390 for (int i = 0; i < _unloaded_methods->length(); i++) { 391 ciMethod* entry = _unloaded_methods->at(i); 392 if (entry->holder()->equals(holder) && 393 entry->name()->equals(name) && 394 entry->signature()->as_symbol()->equals(signature)) { | 29 #include "ci/ciMemberName.hpp" 30 #include "ci/ciMethod.hpp" 31 #include "ci/ciMethodData.hpp" 32 #include "ci/ciMethodHandle.hpp" 33 #include "ci/ciMethodType.hpp" 34 #include "ci/ciNullObject.hpp" 35 #include "ci/ciObjArray.hpp" 36 #include "ci/ciObjArrayKlass.hpp" 37 #include "ci/ciObject.hpp" 38 #include "ci/ciObjectFactory.hpp" 39 #include "ci/ciSymbol.hpp" 40 #include "ci/ciTypeArray.hpp" 41 #include "ci/ciTypeArrayKlass.hpp" 42 #include "ci/ciUtilities.hpp" 43 #include "classfile/systemDictionary.hpp" 44 #include "gc_interface/collectedHeap.inline.hpp" 45 #include "memory/allocation.inline.hpp" 46 #include "oops/oop.inline.hpp" 47 #include "oops/oop.inline2.hpp" 48 #include "runtime/fieldType.hpp" 49 #if INCLUDE_ALL_GCS 50 # include "gc_implementation/g1/g1SATBCardTableModRefBS.hpp" 51 #endif 52 53 // ciObjectFactory 54 // 55 // This class handles requests for the creation of new instances 56 // of ciObject and its subclasses. It contains a caching mechanism 57 // which ensures that for each oop, at most one ciObject is created. 58 // This invariant allows more efficient implementation of ciObject. 59 // 60 // Implementation note: the oop->ciObject mapping is represented as 61 // a table stored in an array. Even though objects are moved 62 // by the garbage collector, the compactor preserves their relative 63 // order; address comparison of oops (in perm space) is safe so long 64 // as we prohibit GC during our comparisons. We currently use binary 65 // search to find the oop in the table, and inserting a new oop 66 // into the table may be costly. If this cost ends up being 67 // problematic the underlying data structure can be switched to some 68 // sort of balanced binary tree. 69 70 GrowableArray<ciMetadata*>* ciObjectFactory::_shared_ci_metadata = NULL; 71 ciSymbol* ciObjectFactory::_shared_ci_symbols[vmSymbols::SID_LIMIT]; 358 Klass* k = (Klass*)o; 359 if (k->oop_is_instance()) { 360 return new (arena()) ciInstanceKlass(h_k); 361 } else if (k->oop_is_objArray()) { 362 return new (arena()) ciObjArrayKlass(h_k); 363 } else if (k->oop_is_typeArray()) { 364 return new (arena()) ciTypeArrayKlass(h_k); 365 } 366 } else if (o->is_method()) { 367 methodHandle h_m(THREAD, (Method*)o); 368 return new (arena()) ciMethod(h_m); 369 } else if (o->is_methodData()) { 370 // Hold methodHandle alive - might not be necessary ??? 371 methodHandle h_m(THREAD, ((MethodData*)o)->method()); 372 return new (arena()) ciMethodData((MethodData*)o); 373 } 374 375 // The oop is of some type not supported by the compiler interface. 376 ShouldNotReachHere(); 377 return NULL; 378 } 379 380 // ------------------------------------------------------------------ 381 // ciObjectFactory::ensure_metadata_alive 382 // 383 // Ensure that the metadata wrapped by the ciMetadata is kept alive by GC. 384 // This is primarily useful for metadata which is considered as weak roots 385 // by the GC but need to be strong roots if reachable from a current compilation. 386 // 387 void ciObjectFactory::ensure_metadata_alive(ciMetadata* m) { 388 ASSERT_IN_VM; // We're handling raw oops here. 389 390 #if INCLUDE_ALL_GCS 391 if (!UseG1GC) { 392 return; 393 } 394 Klass* metadata_owner_klass; 395 if (m->is_klass()) { 396 metadata_owner_klass = m->as_klass()->get_Klass(); 397 } else if (m->is_method()) { 398 metadata_owner_klass = m->as_method()->get_Method()->constants()->pool_holder(); 399 } else { 400 fatal("Not implemented for other types of metadata"); 401 } 402 403 oop metadata_holder = metadata_owner_klass->klass_holder(); 404 if (metadata_holder != NULL) { 405 G1SATBCardTableModRefBS::enqueue(metadata_holder); 406 } 407 408 #endif 409 } 410 411 //------------------------------------------------------------------ 412 // ciObjectFactory::get_unloaded_method 413 // 414 // Get the ciMethod representing an unloaded/unfound method. 415 // 416 // Implementation note: unloaded methods are currently stored in 417 // an unordered array, requiring a linear-time lookup for each 418 // unloaded method. This may need to change. 419 ciMethod* ciObjectFactory::get_unloaded_method(ciInstanceKlass* holder, 420 ciSymbol* name, 421 ciSymbol* signature, 422 ciInstanceKlass* accessor) { 423 ciSignature* that = NULL; 424 for (int i = 0; i < _unloaded_methods->length(); i++) { 425 ciMethod* entry = _unloaded_methods->at(i); 426 if (entry->holder()->equals(holder) && 427 entry->name()->equals(name) && 428 entry->signature()->as_symbol()->equals(signature)) { |