1 /*
   2  * Copyright (c) 2014, 2020, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "classfile/altHashing.hpp"
  27 #include "classfile/javaClasses.inline.hpp"
  28 #include "gc/shared/stringdedup/stringDedup.hpp"
  29 #include "gc/shared/stringdedup/stringDedupTable.hpp"
  30 #include "gc/shared/suspendibleThreadSet.hpp"
  31 #include "logging/log.hpp"
  32 #include "memory/padded.inline.hpp"
  33 #include "memory/universe.hpp"
  34 #include "oops/access.inline.hpp"
  35 #include "oops/arrayOop.inline.hpp"
  36 #include "oops/oop.inline.hpp"
  37 #include "oops/typeArrayOop.hpp"
  38 #include "runtime/atomic.hpp"
  39 #include "runtime/mutexLocker.hpp"
  40 #include "runtime/safepointVerifiers.hpp"
  41 
  42 //
  43 // List of deduplication table entries. Links table
  44 // entries together using their _next fields.
  45 //
  46 class StringDedupEntryList : public CHeapObj<mtGC> {
  47 private:
  48   StringDedupEntry*   _list;
  49   size_t              _length;
  50 
  51 public:
  52   StringDedupEntryList() :
  53     _list(NULL),
  54     _length(0) {
  55   }
  56 
  57   void add(StringDedupEntry* entry) {
  58     entry->set_next(_list);
  59     _list = entry;
  60     _length++;
  61   }
  62 
  63   StringDedupEntry* remove() {
  64     StringDedupEntry* entry = _list;
  65     if (entry != NULL) {
  66       _list = entry->next();
  67       _length--;
  68     }
  69     return entry;
  70   }
  71 
  72   StringDedupEntry* remove_all() {
  73     StringDedupEntry* list = _list;
  74     _list = NULL;
  75     return list;
  76   }
  77 
  78   size_t length() {
  79     return _length;
  80   }
  81 };
  82 
  83 //
  84 // Cache of deduplication table entries. This cache provides fast allocation and
  85 // reuse of table entries to lower the pressure on the underlying allocator.
  86 // But more importantly, it provides fast/deferred freeing of table entries. This
  87 // is important because freeing of table entries is done during stop-the-world
  88 // phases and it is not uncommon for large number of entries to be freed at once.
  89 // Tables entries that are freed during these phases are placed onto a freelist in
  90 // the cache. The deduplication thread, which executes in a concurrent phase, will
  91 // later reuse or free the underlying memory for these entries.
  92 //
  93 // The cache allows for single-threaded allocations and multi-threaded frees.
  94 // Allocations are synchronized by StringDedupTable_lock as part of a table
  95 // modification.
  96 //
  97 class StringDedupEntryCache : public CHeapObj<mtGC> {
  98 private:
  99   // One cache/overflow list per GC worker to allow lock less freeing of
 100   // entries while doing a parallel scan of the table. Using PaddedEnd to
 101   // avoid false sharing.
 102   size_t                             _nlists;
 103   size_t                             _max_list_length;
 104   PaddedEnd<StringDedupEntryList>*   _cached;
 105   PaddedEnd<StringDedupEntryList>*   _overflowed;
 106 
 107 public:
 108   StringDedupEntryCache(size_t max_size);
 109   ~StringDedupEntryCache();
 110 
 111   // Set max number of table entries to cache.
 112   void set_max_size(size_t max_size);
 113 
 114   // Get a table entry from the cache, or allocate a new entry if the cache is empty.
 115   StringDedupEntry* alloc();
 116 
 117   // Insert a table entry into the cache.
 118   void free(StringDedupEntry* entry, uint worker_id);
 119 
 120   // Returns current number of entries in the cache.
 121   size_t size();
 122 
 123   // Deletes overflowed entries.
 124   void delete_overflowed();
 125 };
 126 
 127 StringDedupEntryCache::StringDedupEntryCache(size_t max_size) :
 128   _nlists(ParallelGCThreads),
 129   _max_list_length(0),
 130   _cached(PaddedArray<StringDedupEntryList, mtGC>::create_unfreeable((uint)_nlists)),
 131   _overflowed(PaddedArray<StringDedupEntryList, mtGC>::create_unfreeable((uint)_nlists)) {
 132   set_max_size(max_size);
 133 }
 134 
 135 StringDedupEntryCache::~StringDedupEntryCache() {
 136   ShouldNotReachHere();
 137 }
 138 
 139 void StringDedupEntryCache::set_max_size(size_t size) {
 140   _max_list_length = size / _nlists;
 141 }
 142 
 143 StringDedupEntry* StringDedupEntryCache::alloc() {
 144   for (size_t i = 0; i < _nlists; i++) {
 145     StringDedupEntry* entry = _cached[i].remove();
 146     if (entry != NULL) {
 147       return entry;
 148     }
 149   }
 150   return new StringDedupEntry();
 151 }
 152 
 153 void StringDedupEntryCache::free(StringDedupEntry* entry, uint worker_id) {
 154   assert(entry->obj() != NULL, "Double free");
 155   assert(worker_id < _nlists, "Invalid worker id");
 156 
 157   entry->set_obj(NULL);
 158   entry->set_hash(0);
 159 
 160   if (_cached[worker_id].length() < _max_list_length) {
 161     // Cache is not full
 162     _cached[worker_id].add(entry);
 163   } else {
 164     // Cache is full, add to overflow list for later deletion
 165     _overflowed[worker_id].add(entry);
 166   }
 167 }
 168 
 169 size_t StringDedupEntryCache::size() {
 170   size_t size = 0;
 171   for (size_t i = 0; i < _nlists; i++) {
 172     size += _cached[i].length();
 173   }
 174   return size;
 175 }
 176 
 177 void StringDedupEntryCache::delete_overflowed() {
 178   double start = os::elapsedTime();
 179   uintx count = 0;
 180 
 181   for (size_t i = 0; i < _nlists; i++) {
 182     StringDedupEntry* entry;
 183 
 184     {
 185       // The overflow list can be modified during safepoints, therefore
 186       // we temporarily join the suspendible thread set while removing
 187       // all entries from the list.
 188       SuspendibleThreadSetJoiner sts_join;
 189       entry = _overflowed[i].remove_all();
 190     }
 191 
 192     // Delete all entries
 193     while (entry != NULL) {
 194       StringDedupEntry* next = entry->next();
 195       delete entry;
 196       entry = next;
 197       count++;
 198     }
 199   }
 200 
 201   double end = os::elapsedTime();
 202   log_trace(gc, stringdedup)("Deleted " UINTX_FORMAT " entries, " STRDEDUP_TIME_FORMAT_MS,
 203                              count, STRDEDUP_TIME_PARAM_MS(end - start));
 204 }
 205 
 206 StringDedupTable*        StringDedupTable::_table = NULL;
 207 StringDedupEntryCache*   StringDedupTable::_entry_cache = NULL;
 208 
 209 const size_t             StringDedupTable::_min_size = (1 << 10);   // 1024
 210 const size_t             StringDedupTable::_max_size = (1 << 24);   // 16777216
 211 const double             StringDedupTable::_grow_load_factor = 2.0; // Grow table at 200% load
 212 const double             StringDedupTable::_shrink_load_factor = _grow_load_factor / 3.0; // Shrink table at 67% load
 213 const double             StringDedupTable::_max_cache_factor = 0.1; // Cache a maximum of 10% of the table size
 214 const uintx              StringDedupTable::_rehash_multiple = 60;   // Hash bucket has 60 times more collisions than expected
 215 const uintx              StringDedupTable::_rehash_threshold = (uintx)(_rehash_multiple * _grow_load_factor);
 216 
 217 uintx                    StringDedupTable::_entries_added = 0;
 218 volatile uintx           StringDedupTable::_entries_removed = 0;
 219 uintx                    StringDedupTable::_resize_count = 0;
 220 uintx                    StringDedupTable::_rehash_count = 0;
 221 
 222 StringDedupTable*        StringDedupTable::_resized_table = NULL;
 223 StringDedupTable*        StringDedupTable::_rehashed_table = NULL;
 224 volatile size_t          StringDedupTable::_claimed_index = 0;
 225 
 226 StringDedupTable::StringDedupTable(size_t size, jint hash_seed) :
 227   _size(size),
 228   _entries(0),
 229   _shrink_threshold((uintx)(size * _shrink_load_factor)),
 230   _grow_threshold((uintx)(size * _grow_load_factor)),
 231   _rehash_needed(false),
 232   _hash_seed(hash_seed) {
 233   assert(is_power_of_2(size), "Table size must be a power of 2");
 234   _buckets = NEW_C_HEAP_ARRAY(StringDedupEntry*, _size, mtGC);
 235   memset(_buckets, 0, _size * sizeof(StringDedupEntry*));
 236 }
 237 
 238 StringDedupTable::~StringDedupTable() {
 239   FREE_C_HEAP_ARRAY(G1StringDedupEntry*, _buckets);
 240 }
 241 
 242 void StringDedupTable::create() {
 243   assert(_table == NULL, "One string deduplication table allowed");
 244   _entry_cache = new StringDedupEntryCache(_min_size * _max_cache_factor);
 245   _table = new StringDedupTable(_min_size);
 246 }
 247 
 248 void StringDedupTable::add(typeArrayOop value, bool latin1, unsigned int hash, StringDedupEntry** list) {
 249   StringDedupEntry* entry = _entry_cache->alloc();
 250   entry->set_obj(value);
 251   entry->set_hash(hash);
 252   entry->set_latin1(latin1);
 253   entry->set_next(*list);
 254   *list = entry;
 255   _entries++;
 256 }
 257 
 258 void StringDedupTable::remove(StringDedupEntry** pentry, uint worker_id) {
 259   StringDedupEntry* entry = *pentry;
 260   *pentry = entry->next();
 261   _entry_cache->free(entry, worker_id);
 262 }
 263 
 264 void StringDedupTable::transfer(StringDedupEntry** pentry, StringDedupTable* dest) {
 265   StringDedupEntry* entry = *pentry;
 266   *pentry = entry->next();
 267   unsigned int hash = entry->hash();
 268   size_t index = dest->hash_to_index(hash);
 269   StringDedupEntry** list = dest->bucket(index);
 270   entry->set_next(*list);
 271   *list = entry;
 272 }
 273 
 274 typeArrayOop StringDedupTable::lookup(typeArrayOop value, bool latin1, unsigned int hash,
 275                                       StringDedupEntry** list, uintx &count) {
 276   for (StringDedupEntry* entry = *list; entry != NULL; entry = entry->next()) {
 277     if (entry->hash() == hash && entry->latin1() == latin1) {
 278       oop* obj_addr = (oop*)entry->obj_addr();
 279       oop obj = NativeAccess<ON_PHANTOM_OOP_REF | AS_NO_KEEPALIVE>::oop_load(obj_addr);
 280       if (java_lang_String::value_equals(value, static_cast<typeArrayOop>(obj))) {
 281         obj = NativeAccess<ON_PHANTOM_OOP_REF>::oop_load(obj_addr);
 282         return static_cast<typeArrayOop>(obj);
 283       }
 284     }
 285     count++;
 286   }
 287 
 288   // Not found
 289   return NULL;
 290 }
 291 
 292 typeArrayOop StringDedupTable::lookup_or_add_inner(typeArrayOop value, bool latin1, unsigned int hash) {
 293   size_t index = hash_to_index(hash);
 294   StringDedupEntry** list = bucket(index);
 295   uintx count = 0;
 296 
 297   // Lookup in list
 298   typeArrayOop existing_value = lookup(value, latin1, hash, list, count);
 299 
 300   // Check if rehash is needed
 301   if (count > _rehash_threshold) {
 302     _rehash_needed = true;
 303   }
 304 
 305   if (existing_value == NULL) {
 306     // Not found, add new entry
 307     add(value, latin1, hash, list);
 308 
 309     // Update statistics
 310     _entries_added++;
 311   }
 312 
 313   return existing_value;
 314 }
 315 
 316 unsigned int StringDedupTable::hash_code(typeArrayOop value, bool latin1) {
 317   unsigned int hash;
 318   int length = value->length();
 319   if (latin1) {
 320     const jbyte* data = (jbyte*)value->base(T_BYTE);
 321     if (use_java_hash()) {
 322       hash = java_lang_String::hash_code(data, length);
 323     } else {
 324       hash = AltHashing::murmur3_32(_table->_hash_seed, data, length);
 325     }
 326   } else {
 327     length /= sizeof(jchar) / sizeof(jbyte); // Convert number of bytes to number of chars
 328     const jchar* data = (jchar*)value->base(T_CHAR);
 329     if (use_java_hash()) {
 330       hash = java_lang_String::hash_code(data, length);
 331     } else {
 332       hash = AltHashing::murmur3_32(_table->_hash_seed, data, length);
 333     }
 334   }
 335 
 336   return hash;
 337 }
 338 
 339 void StringDedupTable::deduplicate(oop java_string, StringDedupStat* stat) {
 340   assert(java_lang_String::is_instance(java_string), "Must be a string");
 341   NoSafepointVerifier nsv;
 342 
 343   stat->inc_inspected();
 344 
 345   typeArrayOop value = java_lang_String::value(java_string);
 346   if (value == NULL) {
 347     // String has no value
 348     stat->inc_skipped();
 349     return;
 350   }
 351 
 352   bool latin1 = java_lang_String::is_latin1(java_string);
 353   unsigned int hash = 0;
 354 
 355   if (use_java_hash()) {
 356     if (!java_lang_String::hash_is_set(java_string)) {
 357       stat->inc_hashed();
 358     }
 359     hash = java_lang_String::hash_code(java_string);
 360   } else {
 361     // Compute hash
 362     hash = hash_code(value, latin1);
 363     stat->inc_hashed();
 364   }
 365 
 366   typeArrayOop existing_value = lookup_or_add(value, latin1, hash);
 367   if (existing_value == value) {
 368     // Same value, already known
 369     stat->inc_known();
 370     return;
 371   }
 372 
 373   // Get size of value array
 374   uintx size_in_bytes = value->size() * HeapWordSize;
 375   stat->inc_new(size_in_bytes);
 376 
 377   if (existing_value != NULL) {
 378     // Existing value found, deduplicate string
 379     java_lang_String::set_value(java_string, existing_value);
 380     stat->deduped(value, size_in_bytes);
 381   }
 382 }
 383 
 384 bool StringDedupTable::is_resizing() {
 385   return _resized_table != NULL;
 386 }
 387 
 388 bool StringDedupTable::is_rehashing() {
 389   return _rehashed_table != NULL;
 390 }
 391 
 392 StringDedupTable* StringDedupTable::prepare_resize() {
 393   size_t size = _table->_size;
 394 
 395   // Check if the hashtable needs to be resized
 396   if (_table->_entries > _table->_grow_threshold) {
 397     // Grow table, double the size
 398     size *= 2;
 399     if (size > _max_size) {
 400       // Too big, don't resize
 401       return NULL;
 402     }
 403   } else if (_table->_entries < _table->_shrink_threshold) {
 404     // Shrink table, half the size
 405     size /= 2;
 406     if (size < _min_size) {
 407       // Too small, don't resize
 408       return NULL;
 409     }
 410   } else if (StringDeduplicationResizeALot) {
 411     // Force grow
 412     size *= 2;
 413     if (size > _max_size) {
 414       // Too big, force shrink instead
 415       size /= 4;
 416     }
 417   } else {
 418     // Resize not needed
 419     return NULL;
 420   }
 421 
 422   // Update statistics
 423   _resize_count++;
 424 
 425   // Update max cache size
 426   _entry_cache->set_max_size(size * _max_cache_factor);
 427 
 428   // Allocate the new table. The new table will be populated by workers
 429   // calling unlink_or_oops_do() and finally installed by finish_resize().
 430   return new StringDedupTable(size, _table->_hash_seed);
 431 }
 432 
 433 void StringDedupTable::finish_resize(StringDedupTable* resized_table) {
 434   assert(resized_table != NULL, "Invalid table");
 435 
 436   resized_table->_entries = _table->_entries;
 437 
 438   // Free old table
 439   delete _table;
 440 
 441   // Install new table
 442   _table = resized_table;
 443 }
 444 
 445 void StringDedupTable::unlink_or_oops_do(StringDedupUnlinkOrOopsDoClosure* cl, uint worker_id) {
 446   // The table is divided into partitions to allow lock-less parallel processing by
 447   // multiple worker threads. A worker thread first claims a partition, which ensures
 448   // exclusive access to that part of the table, then continues to process it. To allow
 449   // shrinking of the table in parallel we also need to make sure that the same worker
 450   // thread processes all partitions where entries will hash to the same destination
 451   // partition. Since the table size is always a power of two and we always shrink by
 452   // dividing the table in half, we know that for a given partition there is only one
 453   // other partition whoes entries will hash to the same destination partition. That
 454   // other partition is always the sibling partition in the second half of the table.
 455   // For example, if the table is divided into 8 partitions, the sibling of partition 0
 456   // is partition 4, the sibling of partition 1 is partition 5, etc.
 457   size_t table_half = _table->_size / 2;
 458 
 459   // Let each partition be one page worth of buckets
 460   size_t partition_size = MIN2(table_half, os::vm_page_size() / sizeof(StringDedupEntry*));
 461   assert(table_half % partition_size == 0, "Invalid partition size");
 462 
 463   // Number of entries removed during the scan
 464   uintx removed = 0;
 465 
 466   for (;;) {
 467     // Grab next partition to scan
 468     size_t partition_begin = claim_table_partition(partition_size);
 469     size_t partition_end = partition_begin + partition_size;
 470     if (partition_begin >= table_half) {
 471       // End of table
 472       break;
 473     }
 474 
 475     // Scan the partition followed by the sibling partition in the second half of the table
 476     removed += unlink_or_oops_do(cl, partition_begin, partition_end, worker_id);
 477     removed += unlink_or_oops_do(cl, table_half + partition_begin, table_half + partition_end, worker_id);
 478   }
 479 
 480   // Delayed update to avoid contention on the table lock
 481   if (removed > 0) {
 482     assert_locked_or_safepoint_weak(StringDedupTable_lock);
 483     Atomic::sub(&_table->_entries, removed);
 484     Atomic::add(&_entries_removed, removed);
 485   }
 486 }
 487 
 488 uintx StringDedupTable::unlink_or_oops_do(StringDedupUnlinkOrOopsDoClosure* cl,
 489                                           size_t partition_begin,
 490                                           size_t partition_end,
 491                                           uint worker_id) {
 492   uintx removed = 0;
 493   for (size_t bucket = partition_begin; bucket < partition_end; bucket++) {
 494     StringDedupEntry** entry = _table->bucket(bucket);
 495     while (*entry != NULL) {
 496       oop* p = (oop*)(*entry)->obj_addr();
 497       if (cl->is_alive(*p)) {
 498         cl->keep_alive(p);
 499         if (is_resizing()) {
 500           // We are resizing the table, transfer entry to the new table
 501           _table->transfer(entry, _resized_table);
 502         } else {
 503           if (is_rehashing()) {
 504             // We are rehashing the table, rehash the entry but keep it
 505             // in the table. We can't transfer entries into the new table
 506             // at this point since we don't have exclusive access to all
 507             // destination partitions. finish_rehash() will do a single
 508             // threaded transfer of all entries.
 509             typeArrayOop value = (typeArrayOop)*p;
 510             bool latin1 = (*entry)->latin1();
 511             unsigned int hash = hash_code(value, latin1);
 512             (*entry)->set_hash(hash);
 513           }
 514 
 515           // Move to next entry
 516           entry = (*entry)->next_addr();
 517         }
 518       } else {
 519         // Not alive, remove entry from table
 520         _table->remove(entry, worker_id);
 521         removed++;
 522       }
 523     }
 524   }
 525 
 526   return removed;
 527 }
 528 
 529 void StringDedupTable::gc_prologue(bool resize_and_rehash_table) {
 530   assert(!is_resizing() && !is_rehashing(), "Already in progress?");
 531 
 532   _claimed_index = 0;
 533   if (resize_and_rehash_table) {
 534     // If both resize and rehash is needed, only do resize. Rehash of
 535     // the table will eventually happen if the situation persists.
 536     _resized_table = StringDedupTable::prepare_resize();
 537     if (!is_resizing()) {
 538       _rehashed_table = StringDedupTable::prepare_rehash();
 539     }
 540   }
 541 }
 542 
 543 void StringDedupTable::gc_epilogue() {
 544   assert(!is_resizing() || !is_rehashing(), "Can not both resize and rehash");
 545   assert(_claimed_index >= _table->_size / 2 || _claimed_index == 0, "All or nothing");
 546 
 547   if (is_resizing()) {
 548     StringDedupTable::finish_resize(_resized_table);
 549     _resized_table = NULL;
 550   } else if (is_rehashing()) {
 551     StringDedupTable::finish_rehash(_rehashed_table);
 552     _rehashed_table = NULL;
 553   }
 554 }
 555 
 556 StringDedupTable* StringDedupTable::prepare_rehash() {
 557   if (!_table->_rehash_needed && !StringDeduplicationRehashALot) {
 558     // Rehash not needed
 559     return NULL;
 560   }
 561 
 562   // Update statistics
 563   _rehash_count++;
 564 
 565   // Compute new hash seed
 566   _table->_hash_seed = AltHashing::compute_seed();
 567 
 568   // Allocate the new table, same size and hash seed
 569   return new StringDedupTable(_table->_size, _table->_hash_seed);
 570 }
 571 
 572 void StringDedupTable::finish_rehash(StringDedupTable* rehashed_table) {
 573   assert(rehashed_table != NULL, "Invalid table");
 574 
 575   // Move all newly rehashed entries into the correct buckets in the new table
 576   for (size_t bucket = 0; bucket < _table->_size; bucket++) {
 577     StringDedupEntry** entry = _table->bucket(bucket);
 578     while (*entry != NULL) {
 579       _table->transfer(entry, rehashed_table);
 580     }
 581   }
 582 
 583   rehashed_table->_entries = _table->_entries;
 584 
 585   // Free old table
 586   delete _table;
 587 
 588   // Install new table
 589   _table = rehashed_table;
 590 }
 591 
 592 size_t StringDedupTable::claim_table_partition(size_t partition_size) {
 593   return Atomic::add(&_claimed_index, partition_size) - partition_size;
 594 }
 595 
 596 void StringDedupTable::verify() {
 597   for (size_t bucket = 0; bucket < _table->_size; bucket++) {
 598     // Verify entries
 599     StringDedupEntry** entry = _table->bucket(bucket);
 600     while (*entry != NULL) {
 601       typeArrayOop value = (*entry)->obj();
 602       guarantee(value != NULL, "Object must not be NULL");
 603       guarantee(Universe::heap()->is_in(value), "Object must be on the heap");
 604       guarantee(!value->is_forwarded(), "Object must not be forwarded");
 605       guarantee(value->is_typeArray(), "Object must be a typeArrayOop");
 606       bool latin1 = (*entry)->latin1();
 607       unsigned int hash = hash_code(value, latin1);
 608       guarantee((*entry)->hash() == hash, "Table entry has inorrect hash");
 609       guarantee(_table->hash_to_index(hash) == bucket, "Table entry has incorrect index");
 610       entry = (*entry)->next_addr();
 611     }
 612 
 613     // Verify that we do not have entries with identical oops or identical arrays.
 614     // We only need to compare entries in the same bucket. If the same oop or an
 615     // identical array has been inserted more than once into different/incorrect
 616     // buckets the verification step above will catch that.
 617     StringDedupEntry** entry1 = _table->bucket(bucket);
 618     while (*entry1 != NULL) {
 619       typeArrayOop value1 = (*entry1)->obj();
 620       bool latin1_1 = (*entry1)->latin1();
 621       StringDedupEntry** entry2 = (*entry1)->next_addr();
 622       while (*entry2 != NULL) {
 623         typeArrayOop value2 = (*entry2)->obj();
 624         bool latin1_2 = (*entry2)->latin1();
 625         guarantee(latin1_1 != latin1_2 || !java_lang_String::value_equals(value1, value2), "Table entries must not have identical arrays");
 626         entry2 = (*entry2)->next_addr();
 627       }
 628       entry1 = (*entry1)->next_addr();
 629     }
 630   }
 631 }
 632 
 633 void StringDedupTable::clean_entry_cache() {
 634   _entry_cache->delete_overflowed();
 635 }
 636 
 637 void StringDedupTable::print_statistics() {
 638   Log(gc, stringdedup) log;
 639   log.debug("  Table");
 640   log.debug("    Memory Usage: " STRDEDUP_BYTES_FORMAT_NS,
 641             STRDEDUP_BYTES_PARAM(_table->_size * sizeof(StringDedupEntry*) + (_table->_entries + _entry_cache->size()) * sizeof(StringDedupEntry)));
 642   log.debug("    Size: " SIZE_FORMAT ", Min: " SIZE_FORMAT ", Max: " SIZE_FORMAT, _table->_size, _min_size, _max_size);
 643   log.debug("    Entries: " UINTX_FORMAT ", Load: " STRDEDUP_PERCENT_FORMAT_NS ", Cached: " UINTX_FORMAT ", Added: " UINTX_FORMAT ", Removed: " UINTX_FORMAT,
 644             _table->_entries, percent_of((size_t)_table->_entries, _table->_size), _entry_cache->size(), _entries_added, _entries_removed);
 645   log.debug("    Resize Count: " UINTX_FORMAT ", Shrink Threshold: " UINTX_FORMAT "(" STRDEDUP_PERCENT_FORMAT_NS "), Grow Threshold: " UINTX_FORMAT "(" STRDEDUP_PERCENT_FORMAT_NS ")",
 646             _resize_count, _table->_shrink_threshold, _shrink_load_factor * 100.0, _table->_grow_threshold, _grow_load_factor * 100.0);
 647   log.debug("    Rehash Count: " UINTX_FORMAT ", Rehash Threshold: " UINTX_FORMAT ", Hash Seed: 0x%x", _rehash_count, _rehash_threshold, _table->_hash_seed);
 648   log.debug("    Age Threshold: " UINTX_FORMAT, StringDeduplicationAgeThreshold);
 649 }