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