< prev index next >

src/hotspot/share/ci/ciObjectFactory.cpp

Print this page




 222 
 223 // Decrement the refcount when done on symbols referenced by this compilation.
 224 void ciObjectFactory::remove_symbols() {
 225   for (int i = 0; i < _symbols->length(); i++) {
 226     ciSymbol* s = _symbols->at(i);
 227     s->get_symbol()->decrement_refcount();
 228   }
 229   // Since _symbols is resource allocated we're not allowed to delete it
 230   // but it'll go away just the same.
 231 }
 232 
 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(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(Thread::current(), 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(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 int ciObjectFactory::metadata_compare(Metadata* const& key, ciMetadata* const& elt) {
 263   Metadata* value = elt->constant_encoding();
 264   if (key < value)      return -1;
 265   else if (key > value) return 1;
 266   else                  return 0;
 267 }
 268 
 269 // ------------------------------------------------------------------
 270 // ciObjectFactory::cached_metadata
 271 //
 272 // Get the ciMetadata corresponding to some Metadata. If the ciMetadata has
 273 // already been created, it is returned. Otherwise, null is returned.
 274 ciMetadata* ciObjectFactory::cached_metadata(Metadata* key) {
 275   ASSERT_IN_VM;


 627   init_ident_of(new_ret_addr);
 628   _return_addresses->append(new_ret_addr);
 629   return new_ret_addr;
 630 }
 631 
 632 // ------------------------------------------------------------------
 633 // ciObjectFactory::init_ident_of
 634 void ciObjectFactory::init_ident_of(ciBaseObject* obj) {
 635   obj->set_ident(_next_ident++);
 636 }
 637 
 638 static ciObjectFactory::NonPermObject* emptyBucket = NULL;
 639 
 640 // ------------------------------------------------------------------
 641 // ciObjectFactory::find_non_perm
 642 //
 643 // Use a small hash table, hashed on the klass of the key.
 644 // If there is no entry in the cache corresponding to this oop, return
 645 // the null tail of the bucket into which the oop should be inserted.
 646 ciObjectFactory::NonPermObject* &ciObjectFactory::find_non_perm(oop key) {
 647   assert(Universe::heap()->is_in(key), "must be");
 648   ciMetadata* klass = get_metadata(key->klass());
 649   NonPermObject* *bp = &_non_perm_bucket[(unsigned) klass->hash() % NON_PERM_BUCKETS];
 650   for (NonPermObject* p; (p = (*bp)) != NULL; bp = &p->next()) {
 651     if (is_equal(p, key))  break;
 652   }
 653   return (*bp);
 654 }
 655 
 656 
 657 
 658 // ------------------------------------------------------------------
 659 // Code for for NonPermObject
 660 //
 661 inline ciObjectFactory::NonPermObject::NonPermObject(ciObjectFactory::NonPermObject* &bucket, oop key, ciObject* object) {
 662   assert(ciObjectFactory::is_initialized(), "");
 663   _object = object;
 664   _next = bucket;
 665   bucket = this;
 666 }
 667 
 668 
 669 
 670 // ------------------------------------------------------------------
 671 // ciObjectFactory::insert_non_perm
 672 //
 673 // Insert a ciObject into the non-perm table.
 674 void ciObjectFactory::insert_non_perm(ciObjectFactory::NonPermObject* &where, oop key, ciObject* obj) {
 675   assert(Universe::heap()->is_in_or_null(key), "must be");
 676   assert(&where != &emptyBucket, "must not try to fill empty bucket");
 677   NonPermObject* p = new (arena()) NonPermObject(where, key, obj);
 678   assert(where == p && is_equal(p, key) && p->object() == obj, "entry must match");
 679   assert(find_non_perm(key) == p, "must find the same spot");
 680   ++_non_perm_count;
 681 }
 682 
 683 // ------------------------------------------------------------------
 684 // ciObjectFactory::vm_symbol_at
 685 // Get the ciSymbol corresponding to some index in vmSymbols.
 686 ciSymbol* ciObjectFactory::vm_symbol_at(int index) {
 687   assert(index >= vmSymbols::FIRST_SID && index < vmSymbols::SID_LIMIT, "oob");
 688   return _shared_ci_symbols[index];
 689 }
 690 
 691 // ------------------------------------------------------------------
 692 // ciObjectFactory::metadata_do
 693 void ciObjectFactory::metadata_do(MetadataClosure* f) {
 694   if (_ci_metadata == NULL) return;
 695   for (int j = 0; j< _ci_metadata->length(); j++) {




 222 
 223 // Decrement the refcount when done on symbols referenced by this compilation.
 224 void ciObjectFactory::remove_symbols() {
 225   for (int i = 0; i < _symbols->length(); i++) {
 226     ciSymbol* s = _symbols->at(i);
 227     s->get_symbol()->decrement_refcount();
 228   }
 229   // Since _symbols is resource allocated we're not allowed to delete it
 230   // but it'll go away just the same.
 231 }
 232 
 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(Thread::current(), 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 int ciObjectFactory::metadata_compare(Metadata* const& key, ciMetadata* const& elt) {
 263   Metadata* value = elt->constant_encoding();
 264   if (key < value)      return -1;
 265   else if (key > value) return 1;
 266   else                  return 0;
 267 }
 268 
 269 // ------------------------------------------------------------------
 270 // ciObjectFactory::cached_metadata
 271 //
 272 // Get the ciMetadata corresponding to some Metadata. If the ciMetadata has
 273 // already been created, it is returned. Otherwise, null is returned.
 274 ciMetadata* ciObjectFactory::cached_metadata(Metadata* key) {
 275   ASSERT_IN_VM;


 627   init_ident_of(new_ret_addr);
 628   _return_addresses->append(new_ret_addr);
 629   return new_ret_addr;
 630 }
 631 
 632 // ------------------------------------------------------------------
 633 // ciObjectFactory::init_ident_of
 634 void ciObjectFactory::init_ident_of(ciBaseObject* obj) {
 635   obj->set_ident(_next_ident++);
 636 }
 637 
 638 static ciObjectFactory::NonPermObject* emptyBucket = NULL;
 639 
 640 // ------------------------------------------------------------------
 641 // ciObjectFactory::find_non_perm
 642 //
 643 // Use a small hash table, hashed on the klass of the key.
 644 // If there is no entry in the cache corresponding to this oop, return
 645 // the null tail of the bucket into which the oop should be inserted.
 646 ciObjectFactory::NonPermObject* &ciObjectFactory::find_non_perm(oop key) {
 647   assert(Universe::heap()->is_in_reserved(key), "must be");
 648   ciMetadata* klass = get_metadata(key->klass());
 649   NonPermObject* *bp = &_non_perm_bucket[(unsigned) klass->hash() % NON_PERM_BUCKETS];
 650   for (NonPermObject* p; (p = (*bp)) != NULL; bp = &p->next()) {
 651     if (is_equal(p, key))  break;
 652   }
 653   return (*bp);
 654 }
 655 
 656 
 657 
 658 // ------------------------------------------------------------------
 659 // Code for for NonPermObject
 660 //
 661 inline ciObjectFactory::NonPermObject::NonPermObject(ciObjectFactory::NonPermObject* &bucket, oop key, ciObject* object) {
 662   assert(ciObjectFactory::is_initialized(), "");
 663   _object = object;
 664   _next = bucket;
 665   bucket = this;
 666 }
 667 
 668 
 669 
 670 // ------------------------------------------------------------------
 671 // ciObjectFactory::insert_non_perm
 672 //
 673 // Insert a ciObject into the non-perm table.
 674 void ciObjectFactory::insert_non_perm(ciObjectFactory::NonPermObject* &where, oop key, ciObject* obj) {
 675   assert(Universe::heap()->is_in_reserved_or_null(key), "must be");
 676   assert(&where != &emptyBucket, "must not try to fill empty bucket");
 677   NonPermObject* p = new (arena()) NonPermObject(where, key, obj);
 678   assert(where == p && is_equal(p, key) && p->object() == obj, "entry must match");
 679   assert(find_non_perm(key) == p, "must find the same spot");
 680   ++_non_perm_count;
 681 }
 682 
 683 // ------------------------------------------------------------------
 684 // ciObjectFactory::vm_symbol_at
 685 // Get the ciSymbol corresponding to some index in vmSymbols.
 686 ciSymbol* ciObjectFactory::vm_symbol_at(int index) {
 687   assert(index >= vmSymbols::FIRST_SID && index < vmSymbols::SID_LIMIT, "oob");
 688   return _shared_ci_symbols[index];
 689 }
 690 
 691 // ------------------------------------------------------------------
 692 // ciObjectFactory::metadata_do
 693 void ciObjectFactory::metadata_do(MetadataClosure* f) {
 694   if (_ci_metadata == NULL) return;
 695   for (int j = 0; j< _ci_metadata->length(); j++) {


< prev index next >