< prev index next >

src/hotspot/share/classfile/stringTable.cpp

Print this page




  41 #include "oops/compressedOops.hpp"
  42 #include "oops/oop.inline.hpp"
  43 #include "oops/typeArrayOop.inline.hpp"
  44 #include "oops/weakHandle.inline.hpp"
  45 #include "runtime/atomic.hpp"
  46 #include "runtime/handles.inline.hpp"
  47 #include "runtime/mutexLocker.hpp"
  48 #include "runtime/safepointVerifiers.hpp"
  49 #include "runtime/timerTrace.hpp"
  50 #include "runtime/interfaceSupport.inline.hpp"
  51 #include "services/diagnosticCommand.hpp"
  52 #include "utilities/concurrentHashTable.inline.hpp"
  53 #include "utilities/concurrentHashTableTasks.inline.hpp"
  54 #include "utilities/macros.hpp"
  55 #include "utilities/utf8.hpp"
  56 
  57 // We prefer short chains of avg 2
  58 const double PREF_AVG_LIST_LEN = 2.0;
  59 // 2^24 is max size
  60 const size_t END_SIZE = 24;
  61 // If a chain gets to 100 something might be wrong
  62 const size_t REHASH_LEN = 100;
  63 // If we have as many dead items as 50% of the number of bucket
  64 const double CLEAN_DEAD_HIGH_WATER_MARK = 0.5;
  65 
  66 #if INCLUDE_CDS_JAVA_HEAP
  67 inline oop read_string_from_compact_hashtable(address base_address, u4 offset) {
  68   assert(sizeof(narrowOop) == sizeof(offset), "must be");
  69   narrowOop v = (narrowOop)offset;
  70   return HeapShared::decode_from_archive(v);
  71 }
  72 
  73 static CompactHashtable<
  74   const jchar*, oop,
  75   read_string_from_compact_hashtable,
  76   java_lang_String::equals
  77 > _shared_table;
  78 #endif
  79 
  80 // --------------------------------------------------------------------------
  81 
  82 typedef ConcurrentHashTable<WeakHandle<vm_string_table_data>,


 479 }
 480 
 481 void StringTable::do_concurrent_work(JavaThread* jt) {
 482   _has_work = false;
 483   double load_factor = get_load_factor();
 484   log_debug(stringtable, perf)("Concurrent work, live factor: %g", load_factor);
 485   // We prefer growing, since that also removes dead items
 486   if (load_factor > PREF_AVG_LIST_LEN && !_local_table->is_max_size_reached()) {
 487     grow(jt);
 488   } else {
 489     clean_dead_entries(jt);
 490   }
 491 }
 492 
 493 // Rehash
 494 bool StringTable::do_rehash() {
 495   if (!_local_table->is_safepoint_safe()) {
 496     return false;
 497   }
 498 
 499   // We use current size, not max size.
 500   size_t new_size = _local_table->get_size_log2(Thread::current());
 501   StringTableHash* new_table = new StringTableHash(new_size, END_SIZE, REHASH_LEN);
 502   // Use alt hash from now on
 503   _alt_hash = true;
 504   if (!_local_table->try_move_nodes_to(Thread::current(), new_table)) {
 505     _alt_hash = false;
 506     delete new_table;
 507     return false;
 508   }
 509 
 510   // free old table
 511   delete _local_table;
 512   _local_table = new_table;
 513 
 514   return true;
 515 }
 516 
 517 void StringTable::rehash_table() {
 518   static bool rehashed = false;
 519   log_debug(stringtable)("Table imbalanced, rehashing called.");
 520 
 521   // Grow instead of rehash.




  41 #include "oops/compressedOops.hpp"
  42 #include "oops/oop.inline.hpp"
  43 #include "oops/typeArrayOop.inline.hpp"
  44 #include "oops/weakHandle.inline.hpp"
  45 #include "runtime/atomic.hpp"
  46 #include "runtime/handles.inline.hpp"
  47 #include "runtime/mutexLocker.hpp"
  48 #include "runtime/safepointVerifiers.hpp"
  49 #include "runtime/timerTrace.hpp"
  50 #include "runtime/interfaceSupport.inline.hpp"
  51 #include "services/diagnosticCommand.hpp"
  52 #include "utilities/concurrentHashTable.inline.hpp"
  53 #include "utilities/concurrentHashTableTasks.inline.hpp"
  54 #include "utilities/macros.hpp"
  55 #include "utilities/utf8.hpp"
  56 
  57 // We prefer short chains of avg 2
  58 const double PREF_AVG_LIST_LEN = 2.0;
  59 // 2^24 is max size
  60 const size_t END_SIZE = 24;
  61 // If a chain gets to 32 something might be wrong
  62 const size_t REHASH_LEN = 32;
  63 // If we have as many dead items as 50% of the number of bucket
  64 const double CLEAN_DEAD_HIGH_WATER_MARK = 0.5;
  65 
  66 #if INCLUDE_CDS_JAVA_HEAP
  67 inline oop read_string_from_compact_hashtable(address base_address, u4 offset) {
  68   assert(sizeof(narrowOop) == sizeof(offset), "must be");
  69   narrowOop v = (narrowOop)offset;
  70   return HeapShared::decode_from_archive(v);
  71 }
  72 
  73 static CompactHashtable<
  74   const jchar*, oop,
  75   read_string_from_compact_hashtable,
  76   java_lang_String::equals
  77 > _shared_table;
  78 #endif
  79 
  80 // --------------------------------------------------------------------------
  81 
  82 typedef ConcurrentHashTable<WeakHandle<vm_string_table_data>,


 479 }
 480 
 481 void StringTable::do_concurrent_work(JavaThread* jt) {
 482   _has_work = false;
 483   double load_factor = get_load_factor();
 484   log_debug(stringtable, perf)("Concurrent work, live factor: %g", load_factor);
 485   // We prefer growing, since that also removes dead items
 486   if (load_factor > PREF_AVG_LIST_LEN && !_local_table->is_max_size_reached()) {
 487     grow(jt);
 488   } else {
 489     clean_dead_entries(jt);
 490   }
 491 }
 492 
 493 // Rehash
 494 bool StringTable::do_rehash() {
 495   if (!_local_table->is_safepoint_safe()) {
 496     return false;
 497   }
 498 
 499   // We use max size
 500   StringTableHash* new_table = new StringTableHash(END_SIZE, END_SIZE, REHASH_LEN);

 501   // Use alt hash from now on
 502   _alt_hash = true;
 503   if (!_local_table->try_move_nodes_to(Thread::current(), new_table)) {
 504     _alt_hash = false;
 505     delete new_table;
 506     return false;
 507   }
 508 
 509   // free old table
 510   delete _local_table;
 511   _local_table = new_table;
 512 
 513   return true;
 514 }
 515 
 516 void StringTable::rehash_table() {
 517   static bool rehashed = false;
 518   log_debug(stringtable)("Table imbalanced, rehashing called.");
 519 
 520   // Grow instead of rehash.


< prev index next >