< prev index next >
src/share/vm/classfile/stringTable.cpp
Print this page
*** 109,126 ****
// use the hash value from StringTable::hash_string() as it might use alternate hashcode.
return _shared_table.lookup((const char*)name,
java_lang_String::hash_code(name, len), len);
}
oop StringTable::lookup_in_main_table(int index, jchar* name,
int len, unsigned int hash) {
int count = 0;
for (HashtableEntry<oop, mtSymbol>* l = bucket(index); l != NULL; l = l->next()) {
count++;
if (l->hash() == hash) {
if (java_lang_String::equals(l->literal(), name, len)) {
! return l->literal();
}
}
}
// If the bucket size is too deep check if this hash code is insufficient.
if (count >= rehash_count && !needs_rehashing()) {
--- 109,141 ----
// use the hash value from StringTable::hash_string() as it might use alternate hashcode.
return _shared_table.lookup((const char*)name,
java_lang_String::hash_code(name, len), len);
}
+ // Tell the GC that this string was looked up in the StringTable.
+ static void ensure_string_alive(oop string) {
+ // A lookup in the StringTable could return an object that was previously
+ // considered dead. The SATB part of G1 needs to get notified about this
+ // potential resurrection, otherwise the marking might not find the object.
+ #if INCLUDE_ALL_GCS
+ assert(string != NULL, "should only be called when string found in table");
+ if (UseG1GC) {
+ G1SATBCardTableModRefBS::enqueue(string);
+ }
+ #endif
+ }
+
oop StringTable::lookup_in_main_table(int index, jchar* name,
int len, unsigned int hash) {
int count = 0;
for (HashtableEntry<oop, mtSymbol>* l = bucket(index); l != NULL; l = l->next()) {
count++;
if (l->hash() == hash) {
if (java_lang_String::equals(l->literal(), name, len)) {
! oop result = l->literal();
! ensure_string_alive(result);
! return result;
}
}
}
// If the bucket size is too deep check if this hash code is insufficient.
if (count >= rehash_count && !needs_rehashing()) {
*** 171,204 ****
int length;
jchar* chars = symbol->as_unicode(length);
return lookup(chars, length);
}
- // Tell the GC that this string was looked up in the StringTable.
- static void ensure_string_alive(oop string) {
- // A lookup in the StringTable could return an object that was previously
- // considered dead. The SATB part of G1 needs to get notified about this
- // potential resurrection, otherwise the marking might not find the object.
- #if INCLUDE_ALL_GCS
- if (UseG1GC && string != NULL) {
- G1SATBCardTableModRefBS::enqueue(string);
- }
- #endif
- }
-
oop StringTable::lookup(jchar* name, int len) {
oop string = lookup_shared(name, len);
if (string != NULL) {
return string;
}
unsigned int hash = hash_string(name, len);
int index = the_table()->hash_to_index(hash);
string = the_table()->lookup_in_main_table(index, name, len, hash);
-
- ensure_string_alive(string);
-
return string;
}
oop StringTable::intern(Handle string_or_null, jchar* name,
--- 186,204 ----
*** 212,222 ****
int index = the_table()->hash_to_index(hashValue);
found_string = the_table()->lookup_in_main_table(index, name, len, hashValue);
// Found
if (found_string != NULL) {
- ensure_string_alive(found_string);
return found_string;
}
debug_only(StableMemoryChecker smc(name, len * sizeof(name[0])));
assert(!Universe::heap()->is_in_reserved(name),
--- 212,221 ----
*** 247,258 ****
// Otherwise, add to symbol to table
added_or_found = the_table()->basic_add(index, string, name, len,
hashValue, CHECK_NULL);
}
- ensure_string_alive(added_or_found);
-
return added_or_found;
}
oop StringTable::intern(Symbol* symbol, TRAPS) {
if (symbol == NULL) return NULL;
--- 246,255 ----
< prev index next >