void stringTable::add(stringOop s) { assert(s->is_string(), "adding something that's not a string to the string table"); assert(s->is_old(), "all strings should be tenured"); int32 hashValue = hash(s->bytes(), s->length()); basic_add(s, hashValue); }
stringOop stringTable::basic_add(stringOop s, int32 hashValue) { assert(s->is_string(), "adding something that's not a string to the string table"); assert(s->is_old(), "all strings should be tenured"); // Canonical strings must have a hash value (for _IdentityHash) that // is a pure function of the chars in the string. Otherwise, their // hash value would change when they are discarded by a GC and re- // created later. assert(s->mark()->hash() == no_hash, "should not have a hash yet"); s->set_mark(s->mark()->set_hash(hashValue)); assert(s->mark()->hash() != no_hash, "should have a hash now"); stringTableEntry* bucket = bucketFor(hashValue); stringTableLink* old_link; if (bucket->is_string()) { old_link = Memory->string_table->new_link(bucket->get_string()); } else { old_link = bucket->get_link(); } bucket->set_link(Memory->string_table->new_link(s, old_link)); return s; }