< prev index next >

src/share/vm/ci/ciObjectFactory.cpp

Print this page




 233 // ------------------------------------------------------------------
 234 // ciObjectFactory::get
 235 //
 236 // Get the ciObject corresponding to some oop.  If the ciObject has
 237 // already been created, it is returned.  Otherwise, a new ciObject
 238 // is created.
 239 ciObject* ciObjectFactory::get(oop key) {
 240   ASSERT_IN_VM;
 241 
 242   assert(Universe::heap()->is_in_reserved(key), "must be");
 243 
 244   NonPermObject* &bucket = find_non_perm(key);
 245   if (bucket != NULL) {
 246     return bucket->object();
 247   }
 248 
 249   // The ciObject does not yet exist.  Create it and insert it
 250   // into the cache.
 251   Handle keyHandle(key);
 252   ciObject* new_object = create_new_object(keyHandle());
 253   assert(keyHandle() == new_object->get_oop(), "must be properly recorded");
 254   init_ident_of(new_object);
 255   assert(Universe::heap()->is_in_reserved(new_object->get_oop()), "must be");
 256 
 257   // Not a perm-space object.
 258   insert_non_perm(bucket, keyHandle(), new_object);
 259   return new_object;
 260 }
 261 
 262 // ------------------------------------------------------------------
 263 // ciObjectFactory::get_metadata
 264 //
 265 // Get the ciMetadata corresponding to some Metadata. If the ciMetadata has
 266 // already been created, it is returned. Otherwise, a new ciMetadata
 267 // is created.
 268 ciMetadata* ciObjectFactory::get_metadata(Metadata* key) {
 269   ASSERT_IN_VM;
 270 
 271 #ifdef ASSERT
 272   if (CIObjectFactoryVerify) {
 273     Metadata* last = NULL;


 386     methodHandle h_m(THREAD, ((MethodData*)o)->method());
 387     return new (arena()) ciMethodData((MethodData*)o);
 388   }
 389 
 390   // The Metadata* is of some type not supported by the compiler interface.
 391   ShouldNotReachHere();
 392   return NULL;
 393 }
 394 
 395 // ------------------------------------------------------------------
 396 // ciObjectFactory::ensure_metadata_alive
 397 //
 398 // Ensure that the metadata wrapped by the ciMetadata is kept alive by GC.
 399 // This is primarily useful for metadata which is considered as weak roots
 400 // by the GC but need to be strong roots if reachable from a current compilation.
 401 //
 402 void ciObjectFactory::ensure_metadata_alive(ciMetadata* m) {
 403   ASSERT_IN_VM; // We're handling raw oops here.
 404 
 405 #if INCLUDE_ALL_GCS
 406   if (!UseG1GC) {
 407     return;
 408   }
 409   Klass* metadata_owner_klass;
 410   if (m->is_klass()) {
 411     metadata_owner_klass = m->as_klass()->get_Klass();
 412   } else if (m->is_method()) {
 413     metadata_owner_klass = m->as_method()->get_Method()->constants()->pool_holder();
 414   } else {
 415     fatal("Not implemented for other types of metadata");
 416     return;
 417   }
 418 
 419   oop metadata_holder = metadata_owner_klass->klass_holder();
 420   if (metadata_holder != NULL) {
 421     G1SATBCardTableModRefBS::enqueue(metadata_holder);
 422   }
 423 
 424 #endif
 425 }
 426 


 471 // ciObjectFactory::get_unloaded_klass
 472 //
 473 // Get a ciKlass representing an unloaded klass.
 474 //
 475 // Implementation note: unloaded klasses are currently stored in
 476 // an unordered array, requiring a linear-time lookup for each
 477 // unloaded klass.  This may need to change.
 478 ciKlass* ciObjectFactory::get_unloaded_klass(ciKlass* accessing_klass,
 479                                              ciSymbol* name,
 480                                              bool create_if_not_found) {
 481   EXCEPTION_CONTEXT;
 482   oop loader = NULL;
 483   oop domain = NULL;
 484   if (accessing_klass != NULL) {
 485     loader = accessing_klass->loader();
 486     domain = accessing_klass->protection_domain();
 487   }
 488   for (int i=0; i<_unloaded_klasses->length(); i++) {
 489     ciKlass* entry = _unloaded_klasses->at(i);
 490     if (entry->name()->equals(name) &&
 491         entry->loader() == loader &&
 492         entry->protection_domain() == domain) {
 493       // We've found a match.
 494       return entry;
 495     }
 496   }
 497 
 498   if (!create_if_not_found)
 499     return NULL;
 500 
 501   // This is a new unloaded klass.  Create it and stick it in
 502   // the cache.
 503   ciKlass* new_klass = NULL;
 504 
 505   // Two cases: this is an unloaded ObjArrayKlass or an
 506   // unloaded InstanceKlass.  Deal with both.
 507   if (name->byte_at(0) == '[') {
 508     // Decompose the name.'
 509     FieldArrayInfo fd;
 510     BasicType element_type = FieldType::get_array_info(name->get_symbol(),
 511                                                        fd, THREAD);
 512     if (HAS_PENDING_EXCEPTION) {




 233 // ------------------------------------------------------------------
 234 // ciObjectFactory::get
 235 //
 236 // Get the ciObject corresponding to some oop.  If the ciObject has
 237 // already been created, it is returned.  Otherwise, a new ciObject
 238 // is created.
 239 ciObject* ciObjectFactory::get(oop key) {
 240   ASSERT_IN_VM;
 241 
 242   assert(Universe::heap()->is_in_reserved(key), "must be");
 243 
 244   NonPermObject* &bucket = find_non_perm(key);
 245   if (bucket != NULL) {
 246     return bucket->object();
 247   }
 248 
 249   // The ciObject does not yet exist.  Create it and insert it
 250   // into the cache.
 251   Handle keyHandle(key);
 252   ciObject* new_object = create_new_object(keyHandle());
 253   assert(oopDesc::equals(keyHandle(), new_object->get_oop()), "must be properly recorded");
 254   init_ident_of(new_object);
 255   assert(Universe::heap()->is_in_reserved(new_object->get_oop()), "must be");
 256 
 257   // Not a perm-space object.
 258   insert_non_perm(bucket, keyHandle(), new_object);
 259   return new_object;
 260 }
 261 
 262 // ------------------------------------------------------------------
 263 // ciObjectFactory::get_metadata
 264 //
 265 // Get the ciMetadata corresponding to some Metadata. If the ciMetadata has
 266 // already been created, it is returned. Otherwise, a new ciMetadata
 267 // is created.
 268 ciMetadata* ciObjectFactory::get_metadata(Metadata* key) {
 269   ASSERT_IN_VM;
 270 
 271 #ifdef ASSERT
 272   if (CIObjectFactoryVerify) {
 273     Metadata* last = NULL;


 386     methodHandle h_m(THREAD, ((MethodData*)o)->method());
 387     return new (arena()) ciMethodData((MethodData*)o);
 388   }
 389 
 390   // The Metadata* is of some type not supported by the compiler interface.
 391   ShouldNotReachHere();
 392   return NULL;
 393 }
 394 
 395 // ------------------------------------------------------------------
 396 // ciObjectFactory::ensure_metadata_alive
 397 //
 398 // Ensure that the metadata wrapped by the ciMetadata is kept alive by GC.
 399 // This is primarily useful for metadata which is considered as weak roots
 400 // by the GC but need to be strong roots if reachable from a current compilation.
 401 //
 402 void ciObjectFactory::ensure_metadata_alive(ciMetadata* m) {
 403   ASSERT_IN_VM; // We're handling raw oops here.
 404 
 405 #if INCLUDE_ALL_GCS
 406   if (!(UseG1GC || (UseShenandoahGC && ShenandoahSATBBarrier))) {
 407     return;
 408   }
 409   Klass* metadata_owner_klass;
 410   if (m->is_klass()) {
 411     metadata_owner_klass = m->as_klass()->get_Klass();
 412   } else if (m->is_method()) {
 413     metadata_owner_klass = m->as_method()->get_Method()->constants()->pool_holder();
 414   } else {
 415     fatal("Not implemented for other types of metadata");
 416     return;
 417   }
 418 
 419   oop metadata_holder = metadata_owner_klass->klass_holder();
 420   if (metadata_holder != NULL) {
 421     G1SATBCardTableModRefBS::enqueue(metadata_holder);
 422   }
 423 
 424 #endif
 425 }
 426 


 471 // ciObjectFactory::get_unloaded_klass
 472 //
 473 // Get a ciKlass representing an unloaded klass.
 474 //
 475 // Implementation note: unloaded klasses are currently stored in
 476 // an unordered array, requiring a linear-time lookup for each
 477 // unloaded klass.  This may need to change.
 478 ciKlass* ciObjectFactory::get_unloaded_klass(ciKlass* accessing_klass,
 479                                              ciSymbol* name,
 480                                              bool create_if_not_found) {
 481   EXCEPTION_CONTEXT;
 482   oop loader = NULL;
 483   oop domain = NULL;
 484   if (accessing_klass != NULL) {
 485     loader = accessing_klass->loader();
 486     domain = accessing_klass->protection_domain();
 487   }
 488   for (int i=0; i<_unloaded_klasses->length(); i++) {
 489     ciKlass* entry = _unloaded_klasses->at(i);
 490     if (entry->name()->equals(name) &&
 491         oopDesc::equals(entry->loader(), loader) &&
 492         oopDesc::equals(entry->protection_domain(), domain)) {
 493       // We've found a match.
 494       return entry;
 495     }
 496   }
 497 
 498   if (!create_if_not_found)
 499     return NULL;
 500 
 501   // This is a new unloaded klass.  Create it and stick it in
 502   // the cache.
 503   ciKlass* new_klass = NULL;
 504 
 505   // Two cases: this is an unloaded ObjArrayKlass or an
 506   // unloaded InstanceKlass.  Deal with both.
 507   if (name->byte_at(0) == '[') {
 508     // Decompose the name.'
 509     FieldArrayInfo fd;
 510     BasicType element_type = FieldType::get_array_info(name->get_symbol(),
 511                                                        fd, THREAD);
 512     if (HAS_PENDING_EXCEPTION) {


< prev index next >