--- old/src/share/vm/classfile/stringTable.cpp 2016-02-15 12:31:38.100930846 -0500 +++ new/src/share/vm/classfile/stringTable.cpp 2016-02-15 12:31:37.686936021 -0500 @@ -111,6 +111,19 @@ 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; @@ -118,7 +131,9 @@ count++; if (l->hash() == hash) { if (java_lang_String::equals(l->literal(), name, len)) { - return l->literal(); + oop result = l->literal(); + ensure_string_alive(result); + return result; } } } @@ -173,18 +188,6 @@ 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) { @@ -194,9 +197,6 @@ 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; } @@ -214,7 +214,6 @@ // Found if (found_string != NULL) { - ensure_string_alive(found_string); return found_string; } @@ -249,8 +248,6 @@ hashValue, CHECK_NULL); } - ensure_string_alive(added_or_found); - return added_or_found; }