src/share/vm/classfile/symbolTable.cpp

changeset 6992
2c6ef90f030a
parent 6680
78bbf4d43a14
child 7074
833b0f92429a
     1.1 --- a/src/share/vm/classfile/symbolTable.cpp	Tue Jul 01 09:03:55 2014 +0200
     1.2 +++ b/src/share/vm/classfile/symbolTable.cpp	Mon Jul 07 10:12:40 2014 +0200
     1.3 @@ -36,6 +36,7 @@
     1.4  #include "runtime/mutexLocker.hpp"
     1.5  #include "utilities/hashtable.inline.hpp"
     1.6  #if INCLUDE_ALL_GCS
     1.7 +#include "gc_implementation/g1/g1SATBCardTableModRefBS.hpp"
     1.8  #include "gc_implementation/g1/g1StringDedup.hpp"
     1.9  #endif
    1.10  
    1.11 @@ -704,11 +705,26 @@
    1.12    return lookup(chars, length);
    1.13  }
    1.14  
    1.15 +// Tell the GC that this string was looked up in the StringTable.
    1.16 +static void ensure_string_alive(oop string) {
    1.17 +  // A lookup in the StringTable could return an object that was previously
    1.18 +  // considered dead. The SATB part of G1 needs to get notified about this
    1.19 +  // potential resurrection, otherwise the marking might not find the object.
    1.20 +#if INCLUDE_ALL_GCS
    1.21 +  if (UseG1GC && string != NULL) {
    1.22 +    G1SATBCardTableModRefBS::enqueue(string);
    1.23 +  }
    1.24 +#endif
    1.25 +}
    1.26  
    1.27  oop StringTable::lookup(jchar* name, int len) {
    1.28    unsigned int hash = hash_string(name, len);
    1.29    int index = the_table()->hash_to_index(hash);
    1.30 -  return the_table()->lookup(index, name, len, hash);
    1.31 +  oop string = the_table()->lookup(index, name, len, hash);
    1.32 +
    1.33 +  ensure_string_alive(string);
    1.34 +
    1.35 +  return string;
    1.36  }
    1.37  
    1.38  
    1.39 @@ -719,7 +735,10 @@
    1.40    oop found_string = the_table()->lookup(index, name, len, hashValue);
    1.41  
    1.42    // Found
    1.43 -  if (found_string != NULL) return found_string;
    1.44 +  if (found_string != NULL) {
    1.45 +    ensure_string_alive(found_string);
    1.46 +    return found_string;
    1.47 +  }
    1.48  
    1.49    debug_only(StableMemoryChecker smc(name, len * sizeof(name[0])));
    1.50    assert(!Universe::heap()->is_in_reserved(name),
    1.51 @@ -744,11 +763,17 @@
    1.52  
    1.53    // Grab the StringTable_lock before getting the_table() because it could
    1.54    // change at safepoint.
    1.55 -  MutexLocker ml(StringTable_lock, THREAD);
    1.56 +  oop added_or_found;
    1.57 +  {
    1.58 +    MutexLocker ml(StringTable_lock, THREAD);
    1.59 +    // Otherwise, add to symbol to table
    1.60 +    added_or_found = the_table()->basic_add(index, string, name, len,
    1.61 +                                  hashValue, CHECK_NULL);
    1.62 +  }
    1.63  
    1.64 -  // Otherwise, add to symbol to table
    1.65 -  return the_table()->basic_add(index, string, name, len,
    1.66 -                                hashValue, CHECK_NULL);
    1.67 +  ensure_string_alive(added_or_found);
    1.68 +
    1.69 +  return added_or_found;
    1.70  }
    1.71  
    1.72  oop StringTable::intern(Symbol* symbol, TRAPS) {

mercurial