< prev index next >

src/share/vm/classfile/stringTable.cpp

Print this page
rev 12906 : [mq]: gc_interface

@@ -32,17 +32,18 @@
 #include "gc/shared/gcLocker.inline.hpp"
 #include "memory/allocation.inline.hpp"
 #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
 
 // the number of buckets a thread claims
 const int ClaimChunkSize = 32;

@@ -131,12 +132,20 @@
                                 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();
+      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<GC_ACCESS_ON_PHANTOM | ACCESS_WEAK>::oop_load(string_addr);
+      typeArrayOop value = HeapAccess<GC_ACCESS_ON_STRONG | ACCESS_WEAK>::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<GC_ACCESS_ON_PHANTOM>::oop_load(string_addr);
       }
     }
   }
   // If the bucket size is too deep check if this hash code is insufficient.
   if (count >= rehash_count && !needs_rehashing()) {

@@ -187,22 +196,10 @@
   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) {
   // shared table always uses java_lang_String::hash_code
   unsigned int hash = java_lang_String::hash_code(name, len);
   oop string = lookup_shared(name, len, hash);
   if (string != NULL) {

@@ -212,12 +209,10 @@
     hash = alt_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,
                         int len, TRAPS) {

@@ -233,13 +228,10 @@
   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) {
-    if (found_string != string_or_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),

@@ -271,14 +263,10 @@
     // Otherwise, add to symbol to table
     added_or_found = the_table()->basic_add(index, string, name, len,
                                   hashValue, CHECK_NULL);
   }
 
-  if (added_or_found != string()) {
-    ensure_string_alive(added_or_found);
-  }
-
   return added_or_found;
 }
 
 oop StringTable::intern(Symbol* symbol, TRAPS) {
   if (symbol == NULL) return NULL;

@@ -776,6 +764,5 @@
 void StringTable::shared_oops_do(OopClosure* f) {
 #if INCLUDE_CDS && defined(_LP64) && !defined(_WINDOWS)
   _shared_table.oops_do(f);
 #endif
 }
-
< prev index next >