2516 CPSlot entry = slot_at(i); 2517 guarantee(entry.get_symbol()->refcount() != 0, "should have nonzero reference count"); 2518 } else if (tag.is_string()) { 2519 CPSlot entry = slot_at(i); 2520 guarantee(entry.get_symbol()->refcount() != 0, "should have nonzero reference count"); 2521 } 2522 } 2523 if (cache() != NULL) { 2524 // Note: cache() can be NULL before a class is completely setup or 2525 // in temporary constant pools used during constant pool merging 2526 guarantee(cache()->is_constantPoolCache(), "should be constant pool cache"); 2527 } 2528 if (pool_holder() != NULL) { 2529 // Note: pool_holder() can be NULL in temporary constant pools 2530 // used during constant pool merging 2531 guarantee(pool_holder()->is_klass(), "should be klass"); 2532 } 2533 } 2534 2535 2536 void SymbolHashMap::add_entry(Symbol* sym, u2 value) { 2537 char *str = sym->as_utf8(); 2538 unsigned int hash = compute_hash(str, sym->utf8_length()); 2539 unsigned int index = hash % table_size(); 2540 2541 // check if already in map 2542 // we prefer the first entry since it is more likely to be what was used in 2543 // the class file 2544 for (SymbolHashMapEntry *en = bucket(index); en != NULL; en = en->next()) { 2545 assert(en->symbol() != NULL, "SymbolHashMapEntry symbol is NULL"); 2546 if (en->hash() == hash && en->symbol() == sym) { 2547 return; // already there 2548 } 2549 } 2550 2551 SymbolHashMapEntry* entry = new SymbolHashMapEntry(hash, sym, value); 2552 entry->set_next(bucket(index)); 2553 _buckets[index].set_entry(entry); 2554 assert(entry->symbol() != NULL, "SymbolHashMapEntry symbol is NULL"); 2555 } | 2516 CPSlot entry = slot_at(i); 2517 guarantee(entry.get_symbol()->refcount() != 0, "should have nonzero reference count"); 2518 } else if (tag.is_string()) { 2519 CPSlot entry = slot_at(i); 2520 guarantee(entry.get_symbol()->refcount() != 0, "should have nonzero reference count"); 2521 } 2522 } 2523 if (cache() != NULL) { 2524 // Note: cache() can be NULL before a class is completely setup or 2525 // in temporary constant pools used during constant pool merging 2526 guarantee(cache()->is_constantPoolCache(), "should be constant pool cache"); 2527 } 2528 if (pool_holder() != NULL) { 2529 // Note: pool_holder() can be NULL in temporary constant pools 2530 // used during constant pool merging 2531 guarantee(pool_holder()->is_klass(), "should be klass"); 2532 } 2533 } 2534 2535 2536 SymbolHashMap::~SymbolHashMap() { 2537 SymbolHashMapEntry* next; 2538 for (int i = 0; i < _table_size; i++) { 2539 for (SymbolHashMapEntry* cur = bucket(i); cur != NULL; cur = next) { 2540 next = cur->next(); 2541 delete(cur); 2542 } 2543 } 2544 FREE_C_HEAP_ARRAY(SymbolHashMapBucket, _buckets); 2545 } 2546 2547 void SymbolHashMap::add_entry(Symbol* sym, u2 value) { 2548 char *str = sym->as_utf8(); 2549 unsigned int hash = compute_hash(str, sym->utf8_length()); 2550 unsigned int index = hash % table_size(); 2551 2552 // check if already in map 2553 // we prefer the first entry since it is more likely to be what was used in 2554 // the class file 2555 for (SymbolHashMapEntry *en = bucket(index); en != NULL; en = en->next()) { 2556 assert(en->symbol() != NULL, "SymbolHashMapEntry symbol is NULL"); 2557 if (en->hash() == hash && en->symbol() == sym) { 2558 return; // already there 2559 } 2560 } 2561 2562 SymbolHashMapEntry* entry = new SymbolHashMapEntry(hash, sym, value); 2563 entry->set_next(bucket(index)); 2564 _buckets[index].set_entry(entry); 2565 assert(entry->symbol() != NULL, "SymbolHashMapEntry symbol is NULL"); 2566 } |