< prev index next >

src/hotspot/share/classfile/stringTable.cpp

Print this page




  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 "logging/log.hpp"
  33 #include "memory/allocation.inline.hpp"
  34 #include "memory/filemap.hpp"
  35 #include "memory/metaspaceShared.hpp"
  36 #include "memory/resourceArea.hpp"
  37 #include "oops/access.inline.hpp"
  38 #include "oops/oop.inline.hpp"
  39 #include "oops/typeArrayOop.inline.hpp"
  40 #include "runtime/atomic.hpp"
  41 #include "runtime/handles.inline.hpp"
  42 #include "runtime/mutexLocker.hpp"
  43 #include "runtime/safepointVerifiers.hpp"
  44 #include "services/diagnosticCommand.hpp"
  45 #include "utilities/hashtable.inline.hpp"
  46 #include "utilities/macros.hpp"
  47 #if INCLUDE_ALL_GCS
  48 #include "gc/g1/g1StringDedup.hpp"
  49 #endif
  50 
  51 // the number of buckets a thread claims
  52 const int ClaimChunkSize = 32;
  53 
  54 #ifdef ASSERT
  55 class StableMemoryChecker : public StackObj {
  56   enum { _bufsize = wordSize*4 };
  57 
  58   address _region;
  59   jint    _size;
  60   u1      _save_buf[_bufsize];
  61 
  62   int sample(u1* save_buf) {
  63     if (_size <= _bufsize) {
  64       memcpy(save_buf, _region, _size);
  65       return _size;
  66     } else {
  67       // copy head and tail


 243   found_string = the_table()->lookup_in_main_table(index, name, len, hashValue);
 244 
 245   // Found
 246   if (found_string != NULL) {
 247     return found_string;
 248   }
 249 
 250   debug_only(StableMemoryChecker smc(name, len * sizeof(name[0])));
 251   assert(!Universe::heap()->is_in_reserved(name),
 252          "proposed name of symbol must be stable");
 253 
 254   HandleMark hm(THREAD);  // cleanup strings created
 255   Handle string;
 256   // try to reuse the string if possible
 257   if (!string_or_null.is_null()) {
 258     string = string_or_null;
 259   } else {
 260     string = java_lang_String::create_from_unicode(name, len, CHECK_NULL);
 261   }
 262 
 263 #if INCLUDE_ALL_GCS
 264   if (G1StringDedup::is_enabled()) {
 265     // Deduplicate the string before it is interned. Note that we should never
 266     // deduplicate a string after it has been interned. Doing so will counteract
 267     // compiler optimizations done on e.g. interned string literals.
 268     G1StringDedup::deduplicate(string());
 269   }
 270 #endif
 271 
 272   // Grab the StringTable_lock before getting the_table() because it could
 273   // change at safepoint.
 274   oop added_or_found;
 275   {
 276     MutexLocker ml(StringTable_lock, THREAD);
 277     // Otherwise, add to symbol to table
 278     added_or_found = the_table()->basic_add(index, string, name, len,
 279                                   hashValue, CHECK_NULL);
 280   }
 281 
 282   return added_or_found;
 283 }




  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 "logging/log.hpp"
  33 #include "memory/allocation.inline.hpp"
  34 #include "memory/filemap.hpp"
  35 #include "memory/metaspaceShared.hpp"
  36 #include "memory/resourceArea.hpp"
  37 #include "oops/access.inline.hpp"
  38 #include "oops/oop.inline.hpp"
  39 #include "oops/typeArrayOop.inline.hpp"
  40 #include "runtime/atomic.hpp"
  41 #include "runtime/handles.inline.hpp"
  42 #include "runtime/mutexLocker.hpp"
  43 #include "runtime/safepointVerifiers.hpp"
  44 #include "services/diagnosticCommand.hpp"
  45 #include "utilities/hashtable.inline.hpp"
  46 #include "utilities/macros.hpp"
  47 #if INCLUDE_G1GC
  48 #include "gc/g1/g1StringDedup.hpp"
  49 #endif
  50 
  51 // the number of buckets a thread claims
  52 const int ClaimChunkSize = 32;
  53 
  54 #ifdef ASSERT
  55 class StableMemoryChecker : public StackObj {
  56   enum { _bufsize = wordSize*4 };
  57 
  58   address _region;
  59   jint    _size;
  60   u1      _save_buf[_bufsize];
  61 
  62   int sample(u1* save_buf) {
  63     if (_size <= _bufsize) {
  64       memcpy(save_buf, _region, _size);
  65       return _size;
  66     } else {
  67       // copy head and tail


 243   found_string = the_table()->lookup_in_main_table(index, name, len, hashValue);
 244 
 245   // Found
 246   if (found_string != NULL) {
 247     return found_string;
 248   }
 249 
 250   debug_only(StableMemoryChecker smc(name, len * sizeof(name[0])));
 251   assert(!Universe::heap()->is_in_reserved(name),
 252          "proposed name of symbol must be stable");
 253 
 254   HandleMark hm(THREAD);  // cleanup strings created
 255   Handle string;
 256   // try to reuse the string if possible
 257   if (!string_or_null.is_null()) {
 258     string = string_or_null;
 259   } else {
 260     string = java_lang_String::create_from_unicode(name, len, CHECK_NULL);
 261   }
 262 
 263 #if INCLUDE_G1GC
 264   if (G1StringDedup::is_enabled()) {
 265     // Deduplicate the string before it is interned. Note that we should never
 266     // deduplicate a string after it has been interned. Doing so will counteract
 267     // compiler optimizations done on e.g. interned string literals.
 268     G1StringDedup::deduplicate(string());
 269   }
 270 #endif
 271 
 272   // Grab the StringTable_lock before getting the_table() because it could
 273   // change at safepoint.
 274   oop added_or_found;
 275   {
 276     MutexLocker ml(StringTable_lock, THREAD);
 277     // Otherwise, add to symbol to table
 278     added_or_found = the_table()->basic_add(index, string, name, len,
 279                                   hashValue, CHECK_NULL);
 280   }
 281 
 282   return added_or_found;
 283 }


< prev index next >