< prev index next >

src/share/vm/ci/ciObjectFactory.cpp

Print this page
rev 12854 : [mq]: gcinterface.patch


 223 
 224 // Decrement the refcount when done on symbols referenced by this compilation.
 225 void ciObjectFactory::remove_symbols() {
 226   for (int i = 0; i < _symbols->length(); i++) {
 227     ciSymbol* s = _symbols->at(i);
 228     s->get_symbol()->decrement_refcount();
 229   }
 230   // Since _symbols is resource allocated we're not allowed to delete it
 231   // but it'll go away just the same.
 232 }
 233 
 234 // ------------------------------------------------------------------
 235 // ciObjectFactory::get
 236 //
 237 // Get the ciObject corresponding to some oop.  If the ciObject has
 238 // already been created, it is returned.  Otherwise, a new ciObject
 239 // is created.
 240 ciObject* ciObjectFactory::get(oop key) {
 241   ASSERT_IN_VM;
 242 
 243   assert(Universe::heap()->is_in_reserved(key), "must be");
 244 
 245   NonPermObject* &bucket = find_non_perm(key);
 246   if (bucket != NULL) {
 247     return bucket->object();
 248   }
 249 
 250   // The ciObject does not yet exist.  Create it and insert it
 251   // into the cache.
 252   Handle keyHandle(Thread::current(), key);
 253   ciObject* new_object = create_new_object(keyHandle());
 254   assert(keyHandle() == new_object->get_oop(), "must be properly recorded");
 255   init_ident_of(new_object);
 256   assert(Universe::heap()->is_in_reserved(new_object->get_oop()), "must be");
 257 
 258   // Not a perm-space object.
 259   insert_non_perm(bucket, keyHandle(), new_object);
 260   return new_object;
 261 }
 262 
 263 int ciObjectFactory::metadata_compare(Metadata* const& key, ciMetadata* const& elt) {
 264   Metadata* value = elt->constant_encoding();
 265   if (key < value)      return -1;
 266   else if (key > value) return 1;
 267   else                  return 0;
 268 }
 269 
 270 // ------------------------------------------------------------------
 271 // ciObjectFactory::get_metadata
 272 //
 273 // Get the ciMetadata corresponding to some Metadata. If the ciMetadata has
 274 // already been created, it is returned. Otherwise, a new ciMetadata
 275 // is created.
 276 ciMetadata* ciObjectFactory::get_metadata(Metadata* key) {


 655   init_ident_of(new_ret_addr);
 656   _return_addresses->append(new_ret_addr);
 657   return new_ret_addr;
 658 }
 659 
 660 // ------------------------------------------------------------------
 661 // ciObjectFactory::init_ident_of
 662 void ciObjectFactory::init_ident_of(ciBaseObject* obj) {
 663   obj->set_ident(_next_ident++);
 664 }
 665 
 666 static ciObjectFactory::NonPermObject* emptyBucket = NULL;
 667 
 668 // ------------------------------------------------------------------
 669 // ciObjectFactory::find_non_perm
 670 //
 671 // Use a small hash table, hashed on the klass of the key.
 672 // If there is no entry in the cache corresponding to this oop, return
 673 // the null tail of the bucket into which the oop should be inserted.
 674 ciObjectFactory::NonPermObject* &ciObjectFactory::find_non_perm(oop key) {
 675   assert(Universe::heap()->is_in_reserved(key), "must be");
 676   ciMetadata* klass = get_metadata(key->klass());
 677   NonPermObject* *bp = &_non_perm_bucket[(unsigned) klass->hash() % NON_PERM_BUCKETS];
 678   for (NonPermObject* p; (p = (*bp)) != NULL; bp = &p->next()) {
 679     if (is_equal(p, key))  break;
 680   }
 681   return (*bp);
 682 }
 683 
 684 
 685 
 686 // ------------------------------------------------------------------
 687 // Code for for NonPermObject
 688 //
 689 inline ciObjectFactory::NonPermObject::NonPermObject(ciObjectFactory::NonPermObject* &bucket, oop key, ciObject* object) {
 690   assert(ciObjectFactory::is_initialized(), "");
 691   _object = object;
 692   _next = bucket;
 693   bucket = this;
 694 }
 695 
 696 
 697 
 698 // ------------------------------------------------------------------
 699 // ciObjectFactory::insert_non_perm
 700 //
 701 // Insert a ciObject into the non-perm table.
 702 void ciObjectFactory::insert_non_perm(ciObjectFactory::NonPermObject* &where, oop key, ciObject* obj) {
 703   assert(Universe::heap()->is_in_reserved_or_null(key), "must be");
 704   assert(&where != &emptyBucket, "must not try to fill empty bucket");
 705   NonPermObject* p = new (arena()) NonPermObject(where, key, obj);
 706   assert(where == p && is_equal(p, key) && p->object() == obj, "entry must match");
 707   assert(find_non_perm(key) == p, "must find the same spot");
 708   ++_non_perm_count;
 709 }
 710 
 711 // ------------------------------------------------------------------
 712 // ciObjectFactory::vm_symbol_at
 713 // Get the ciSymbol corresponding to some index in vmSymbols.
 714 ciSymbol* ciObjectFactory::vm_symbol_at(int index) {
 715   assert(index >= vmSymbols::FIRST_SID && index < vmSymbols::SID_LIMIT, "oob");
 716   return _shared_ci_symbols[index];
 717 }
 718 
 719 // ------------------------------------------------------------------
 720 // ciObjectFactory::metadata_do
 721 void ciObjectFactory::metadata_do(void f(Metadata*)) {
 722   if (_ci_metadata == NULL) return;
 723   for (int j = 0; j< _ci_metadata->length(); j++) {




 223 
 224 // Decrement the refcount when done on symbols referenced by this compilation.
 225 void ciObjectFactory::remove_symbols() {
 226   for (int i = 0; i < _symbols->length(); i++) {
 227     ciSymbol* s = _symbols->at(i);
 228     s->get_symbol()->decrement_refcount();
 229   }
 230   // Since _symbols is resource allocated we're not allowed to delete it
 231   // but it'll go away just the same.
 232 }
 233 
 234 // ------------------------------------------------------------------
 235 // ciObjectFactory::get
 236 //
 237 // Get the ciObject corresponding to some oop.  If the ciObject has
 238 // already been created, it is returned.  Otherwise, a new ciObject
 239 // is created.
 240 ciObject* ciObjectFactory::get(oop key) {
 241   ASSERT_IN_VM;
 242 
 243   assert(GC::gc()->heap()->is_in_reserved(key), "must be");
 244 
 245   NonPermObject* &bucket = find_non_perm(key);
 246   if (bucket != NULL) {
 247     return bucket->object();
 248   }
 249 
 250   // The ciObject does not yet exist.  Create it and insert it
 251   // into the cache.
 252   Handle keyHandle(Thread::current(), key);
 253   ciObject* new_object = create_new_object(keyHandle());
 254   assert(keyHandle() == new_object->get_oop(), "must be properly recorded");
 255   init_ident_of(new_object);
 256   assert(GC::gc()->heap()->is_in_reserved(new_object->get_oop()), "must be");
 257 
 258   // Not a perm-space object.
 259   insert_non_perm(bucket, keyHandle(), new_object);
 260   return new_object;
 261 }
 262 
 263 int ciObjectFactory::metadata_compare(Metadata* const& key, ciMetadata* const& elt) {
 264   Metadata* value = elt->constant_encoding();
 265   if (key < value)      return -1;
 266   else if (key > value) return 1;
 267   else                  return 0;
 268 }
 269 
 270 // ------------------------------------------------------------------
 271 // ciObjectFactory::get_metadata
 272 //
 273 // Get the ciMetadata corresponding to some Metadata. If the ciMetadata has
 274 // already been created, it is returned. Otherwise, a new ciMetadata
 275 // is created.
 276 ciMetadata* ciObjectFactory::get_metadata(Metadata* key) {


 655   init_ident_of(new_ret_addr);
 656   _return_addresses->append(new_ret_addr);
 657   return new_ret_addr;
 658 }
 659 
 660 // ------------------------------------------------------------------
 661 // ciObjectFactory::init_ident_of
 662 void ciObjectFactory::init_ident_of(ciBaseObject* obj) {
 663   obj->set_ident(_next_ident++);
 664 }
 665 
 666 static ciObjectFactory::NonPermObject* emptyBucket = NULL;
 667 
 668 // ------------------------------------------------------------------
 669 // ciObjectFactory::find_non_perm
 670 //
 671 // Use a small hash table, hashed on the klass of the key.
 672 // If there is no entry in the cache corresponding to this oop, return
 673 // the null tail of the bucket into which the oop should be inserted.
 674 ciObjectFactory::NonPermObject* &ciObjectFactory::find_non_perm(oop key) {
 675   assert(GC::gc()->heap()->is_in_reserved(key), "must be");
 676   ciMetadata* klass = get_metadata(key->klass());
 677   NonPermObject* *bp = &_non_perm_bucket[(unsigned) klass->hash() % NON_PERM_BUCKETS];
 678   for (NonPermObject* p; (p = (*bp)) != NULL; bp = &p->next()) {
 679     if (is_equal(p, key))  break;
 680   }
 681   return (*bp);
 682 }
 683 
 684 
 685 
 686 // ------------------------------------------------------------------
 687 // Code for for NonPermObject
 688 //
 689 inline ciObjectFactory::NonPermObject::NonPermObject(ciObjectFactory::NonPermObject* &bucket, oop key, ciObject* object) {
 690   assert(ciObjectFactory::is_initialized(), "");
 691   _object = object;
 692   _next = bucket;
 693   bucket = this;
 694 }
 695 
 696 
 697 
 698 // ------------------------------------------------------------------
 699 // ciObjectFactory::insert_non_perm
 700 //
 701 // Insert a ciObject into the non-perm table.
 702 void ciObjectFactory::insert_non_perm(ciObjectFactory::NonPermObject* &where, oop key, ciObject* obj) {
 703   assert(GC::gc()->heap()->is_in_reserved_or_null(key), "must be");
 704   assert(&where != &emptyBucket, "must not try to fill empty bucket");
 705   NonPermObject* p = new (arena()) NonPermObject(where, key, obj);
 706   assert(where == p && is_equal(p, key) && p->object() == obj, "entry must match");
 707   assert(find_non_perm(key) == p, "must find the same spot");
 708   ++_non_perm_count;
 709 }
 710 
 711 // ------------------------------------------------------------------
 712 // ciObjectFactory::vm_symbol_at
 713 // Get the ciSymbol corresponding to some index in vmSymbols.
 714 ciSymbol* ciObjectFactory::vm_symbol_at(int index) {
 715   assert(index >= vmSymbols::FIRST_SID && index < vmSymbols::SID_LIMIT, "oob");
 716   return _shared_ci_symbols[index];
 717 }
 718 
 719 // ------------------------------------------------------------------
 720 // ciObjectFactory::metadata_do
 721 void ciObjectFactory::metadata_do(void f(Metadata*)) {
 722   if (_ci_metadata == NULL) return;
 723   for (int j = 0; j< _ci_metadata->length(); j++) {


< prev index next >