< prev index next >

src/share/vm/classfile/stringTable.cpp

Print this page




  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "classfile/altHashing.hpp"
  27 #include "classfile/compactHashtable.inline.hpp"
  28 #include "classfile/javaClasses.inline.hpp"
  29 #include "classfile/stringTable.hpp"
  30 #include "classfile/systemDictionary.hpp"
  31 #include "gc/shared/collectedHeap.inline.hpp"
  32 #include "gc/shared/gcLocker.inline.hpp"
  33 #include "memory/allocation.inline.hpp"
  34 #include "memory/filemap.hpp"
  35 #include "oops/oop.inline.hpp"
  36 #include "runtime/atomic.inline.hpp"
  37 #include "runtime/mutexLocker.hpp"
  38 #include "utilities/hashtable.inline.hpp"
  39 #include "utilities/macros.hpp"
  40 #if INCLUDE_ALL_GCS
  41 #include "gc/g1/g1CollectedHeap.hpp"
  42 #include "gc/g1/g1SATBCardTableModRefBS.hpp"
  43 #include "gc/g1/g1StringDedup.hpp"

  44 #endif
  45 
  46 // the number of buckets a thread claims
  47 const int ClaimChunkSize = 32;
  48 
  49 #ifdef ASSERT
  50 class StableMemoryChecker : public StackObj {
  51   enum { _bufsize = wordSize*4 };
  52 
  53   address _region;
  54   jint    _size;
  55   u1      _save_buf[_bufsize];
  56 
  57   int sample(u1* save_buf) {
  58     if (_size <= _bufsize) {
  59       memcpy(save_buf, _region, _size);
  60       return _size;
  61     } else {
  62       // copy head and tail
  63       memcpy(&save_buf[0],          _region,                      _bufsize/2);


 163   HashtableEntry<oop, mtSymbol>* entry = new_entry(hashValue, string());
 164   add_entry(index, entry);
 165   return string();
 166 }
 167 
 168 
 169 oop StringTable::lookup(Symbol* symbol) {
 170   ResourceMark rm;
 171   int length;
 172   jchar* chars = symbol->as_unicode(length);
 173   return lookup(chars, length);
 174 }
 175 
 176 // Tell the GC that this string was looked up in the StringTable.
 177 static void ensure_string_alive(oop string) {
 178   // A lookup in the StringTable could return an object that was previously
 179   // considered dead. The SATB part of G1 needs to get notified about this
 180   // potential resurrection, otherwise the marking might not find the object.
 181 #if INCLUDE_ALL_GCS
 182   if (UseG1GC && string != NULL) {
 183     G1SATBCardTableModRefBS::enqueue(string);
 184   }
 185 #endif
 186 }
 187 
 188 oop StringTable::lookup(jchar* name, int len) {
 189   oop string = lookup_shared(name, len);
 190   if (string != NULL) {
 191     return string;
 192   }
 193 
 194   unsigned int hash = hash_string(name, len);
 195   int index = the_table()->hash_to_index(hash);
 196   string = the_table()->lookup_in_main_table(index, name, len, hash);
 197 
 198   ensure_string_alive(string);
 199 
 200   return string;
 201 }
 202 
 203 oop StringTable::intern(Handle string_or_null, jchar* name,




  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "classfile/altHashing.hpp"
  27 #include "classfile/compactHashtable.inline.hpp"
  28 #include "classfile/javaClasses.inline.hpp"
  29 #include "classfile/stringTable.hpp"
  30 #include "classfile/systemDictionary.hpp"
  31 #include "gc/shared/collectedHeap.inline.hpp"
  32 #include "gc/shared/gcLocker.inline.hpp"
  33 #include "memory/allocation.inline.hpp"
  34 #include "memory/filemap.hpp"
  35 #include "oops/oop.inline.hpp"
  36 #include "runtime/atomic.inline.hpp"
  37 #include "runtime/mutexLocker.hpp"
  38 #include "utilities/hashtable.inline.hpp"
  39 #include "utilities/macros.hpp"
  40 #if INCLUDE_ALL_GCS
  41 #include "gc/g1/g1CollectedHeap.hpp"

  42 #include "gc/g1/g1StringDedup.hpp"
  43 #include "gc/shared/satbMarkQueue.hpp"
  44 #endif
  45 
  46 // the number of buckets a thread claims
  47 const int ClaimChunkSize = 32;
  48 
  49 #ifdef ASSERT
  50 class StableMemoryChecker : public StackObj {
  51   enum { _bufsize = wordSize*4 };
  52 
  53   address _region;
  54   jint    _size;
  55   u1      _save_buf[_bufsize];
  56 
  57   int sample(u1* save_buf) {
  58     if (_size <= _bufsize) {
  59       memcpy(save_buf, _region, _size);
  60       return _size;
  61     } else {
  62       // copy head and tail
  63       memcpy(&save_buf[0],          _region,                      _bufsize/2);


 163   HashtableEntry<oop, mtSymbol>* entry = new_entry(hashValue, string());
 164   add_entry(index, entry);
 165   return string();
 166 }
 167 
 168 
 169 oop StringTable::lookup(Symbol* symbol) {
 170   ResourceMark rm;
 171   int length;
 172   jchar* chars = symbol->as_unicode(length);
 173   return lookup(chars, length);
 174 }
 175 
 176 // Tell the GC that this string was looked up in the StringTable.
 177 static void ensure_string_alive(oop string) {
 178   // A lookup in the StringTable could return an object that was previously
 179   // considered dead. The SATB part of G1 needs to get notified about this
 180   // potential resurrection, otherwise the marking might not find the object.
 181 #if INCLUDE_ALL_GCS
 182   if (UseG1GC && string != NULL) {
 183     SATBMarkQueue::enqueue(string);
 184   }
 185 #endif
 186 }
 187 
 188 oop StringTable::lookup(jchar* name, int len) {
 189   oop string = lookup_shared(name, len);
 190   if (string != NULL) {
 191     return string;
 192   }
 193 
 194   unsigned int hash = hash_string(name, len);
 195   int index = the_table()->hash_to_index(hash);
 196   string = the_table()->lookup_in_main_table(index, name, len, hash);
 197 
 198   ensure_string_alive(string);
 199 
 200   return string;
 201 }
 202 
 203 oop StringTable::intern(Handle string_or_null, jchar* name,


< prev index next >