--- old/src/share/vm/classfile/stringTable.cpp 2017-04-25 16:44:18.295175775 +0200 +++ new/src/share/vm/classfile/stringTable.cpp 2017-04-25 16:44:18.147175780 +0200 @@ -34,13 +34,14 @@ #include "memory/filemap.hpp" #include "memory/resourceArea.hpp" #include "oops/oop.inline.hpp" +#include "runtime/access.inline.hpp" #include "runtime/atomic.hpp" #include "runtime/mutexLocker.hpp" #include "utilities/hashtable.inline.hpp" #include "utilities/macros.hpp" #if INCLUDE_ALL_GCS +#include "gc/g1/g1BarrierSet.hpp" #include "gc/g1/g1CollectedHeap.hpp" -#include "gc/g1/g1SATBCardTableModRefBS.hpp" #include "gc/g1/g1StringDedup.hpp" #endif @@ -128,13 +129,21 @@ } oop StringTable::lookup_in_main_table(int index, jchar* name, - int len, unsigned int hash) { + int len, unsigned int hash) { int count = 0; for (HashtableEntry* 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(); + oop* string_addr = l->literal_addr(); + // The ACCESS_WEAK peeks at the oop without keeping it alive. + // This is *very dangerous* in general but is okay in this specific + // case. The subsequent oop_load keeps the oop alive if it it matched + // the jchar* string. + oop string = RootAccess::oop_load(string_addr); + typeArrayOop value = HeapAccess::oop_load_at(string, java_lang_String::value_offset_in_bytes()); + int length = java_lang_String::length(string, value); + if (java_lang_String::equals(value, length, string, name, len)) { + return RootAccess::oop_load(string_addr); } } } @@ -189,18 +198,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) { // shared table always uses java_lang_String::hash_code unsigned int hash = java_lang_String::hash_code(name, len); @@ -214,8 +211,6 @@ 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; } @@ -235,9 +230,6 @@ // Found if (found_string != NULL) { - if (found_string != string_or_null()) { - ensure_string_alive(found_string); - } return found_string; } @@ -273,10 +265,6 @@ hashValue, CHECK_NULL); } - if (added_or_found != string()) { - ensure_string_alive(added_or_found); - } - return added_or_found; } @@ -778,4 +766,3 @@ _shared_table.oops_do(f); #endif } -