       1 /*
       2  * Copyright (c) 2003, 2014, 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.hpp"
      28 #include "memory/allocation.inline.hpp"
      29 #include "memory/filemap.hpp"
      30 #include "memory/resourceArea.hpp"
      31 #include "oops/oop.inline.hpp"
      32 #include "runtime/safepoint.hpp"
      33 #include "utilities/dtrace.hpp"
      34 #include "utilities/hashtable.hpp"
      35 #include "utilities/hashtable.inline.hpp"
      36 #include "utilities/numberSeq.hpp"
      37
      38 // ------------------------------------------------------------------------------------------
      39 //
      40 // start of next_prime
      41 //
      42 // http://stackoverflow.com/questions/4475996/given-prime-number-n-compute-the-next-prime
      43 //
      44 bool is_prime(int x)
      45 {
      46     int o = 4;
      47     for (int i = 5; true; i += o)
      48       {
      49           int q = x / i;
      50           if (q < i)
      51               return true;
      52           if (x == q * i)
      53               return false;
      54           o ^= 6;
      55         }
      56     return true;
      57   }
      58 int next_prime(int x)
      59 {
      60     switch (x)
      61     {
      62           case 0:
      63           case 1:
      64           case 2:
      65             return 2;
      66           case 3:
      67             return 3;
      68           case 4:
      69           case 5:
      70             return 5;
      71       }
      72     int k = x / 6;
      73     int i = x - 6 * k;
      74     int o = i < 2 ? 1 : 5;
      75     x = 6 * k + o;
      76     for (i = (3 + o) / 2; !is_prime(x); x += i)
      77         i ^= 6;
      78       return x;
      79   }
      80 // end of next_prime
      81 // ------------------------------------------------------------------------------------------
      82
      83 // This hashtable is implemented as an open hash table with a fixed number of buckets.
      84
      85 template <MEMFLAGS F> BasicHashtableEntry<F>* BasicHashtable<F>::new_entry_free_list() {
      86   BasicHashtableEntry<F>* entry = NULL;
      87   if (_free_list != NULL) {
      88     entry = _free_list;
      89     _free_list = _free_list->next();
      90   }
      91   return entry;
      92 }
      93
      94 // HashtableEntrys are allocated in blocks to reduce the space overhead.
      95 template <MEMFLAGS F> BasicHashtableEntry<F>* BasicHashtable<F>::new_entry(unsigned int hashValue) {
      96   BasicHashtableEntry<F>* entry = new_entry_free_list();
      97
      98   if (entry == NULL) {
      99     if (_first_free_entry + _entry_size >= _end_block) {
     100       int block_size = MIN2(512, MAX2((int)_table_size / 2, (int)_number_of_entries));
     101       int len = _entry_size * block_size;
     102       len = 1 << log2_intptr(len); // round down to power of 2
     103       assert(len >= _entry_size, "");
     104       _first_free_entry = NEW_C_HEAP_ARRAY2(char, len, F, CURRENT_PC);
     105       _end_block = _first_free_entry + len;
     106     }
     107     entry = (BasicHashtableEntry<F>*)_first_free_entry;
     108     _first_free_entry += _entry_size;
     109   }
     110
     111   assert(_entry_size % HeapWordSize == 0, "");
     112   entry->set_hash(hashValue);
     113   return entry;
     114 }
     115
     116
     117 template <class T, MEMFLAGS F> HashtableEntry<T, F>* Hashtable<T, F>::new_entry(unsigned int hashValue, T obj) {
     118   HashtableEntry<T, F>* entry;
     119
     120   entry = (HashtableEntry<T, F>*)BasicHashtable<F>::new_entry(hashValue);
     121   entry->set_literal(obj);
     122   entry->_debug_lookups = 0;
     123   return entry;
     124 }
     125
     126 // Check to see if the hashtable is unbalanced.  The caller set a flag to
     127 // rehash at the next safepoint.  If this bucket is 60 times greater than the
     128 // expected average bucket length, it's an unbalanced hashtable.
     129 // This is somewhat an arbitrary heuristic but if one bucket gets to
     130 // rehash_count which is currently 100, there's probably something wrong.
     131
     132 template <class T, MEMFLAGS F> bool RehashableHashtable<T, F>::check_rehash_table(int count) {
     133   assert(this->table_size() != 0, "underflow");
     134   if (count > (((double)this->number_of_entries()/(double)this->table_size())*rehash_multiple)) {
     135     // Set a flag for the next safepoint, which should be at some guaranteed
     136     // safepoint interval.
     137     return true;
     138   }
     139   return false;
     140 }
     141
     142 template <class T, MEMFLAGS F> juint RehashableHashtable<T, F>::_seed = 0;
     143
     144 // Create a new table and using alternate hash code, populate the new table
     145 // with the existing elements.   This can be used to change the hash code
     146 // and could in the future change the size of the table.
     147
     148 template <class T, MEMFLAGS F> void RehashableHashtable<T, F>::move_to(RehashableHashtable<T, F>* new_table) {
     149
     150   // Initialize the global seed for hashing.
     151   _seed = AltHashing::compute_seed();
     152   assert(seed() != 0, "shouldn't be zero");
     153
     154   int saved_entry_count = this->number_of_entries();
     155
     156   // Iterate through the table and create a new entry for the new table
     157   for (int i = 0; i < new_table->table_size(); ++i) {
     158     for (HashtableEntry<T, F>* p = this->bucket(i); p != NULL; ) {
     159       HashtableEntry<T, F>* next = p->next();
     160       T string = p->literal();
     161       // Use alternate hashing algorithm on the symbol in the first table
     162       unsigned int hashValue = string->new_hash(seed());
     163       // Get a new index relative to the new table (can also change size)
     164       int index = new_table->hash_to_index(hashValue);
     165       p->set_hash(hashValue);
     166       // Keep the shared bit in the Hashtable entry to indicate that this entry
     167       // can't be deleted.   The shared bit is the LSB in the _next field so
     168       // walking the hashtable past these entries requires
     169       // BasicHashtableEntry::make_ptr() call.
     170       bool keep_shared = p->is_shared();
     171       this->unlink_entry(p);
     172       new_table->add_entry(index, p);
     173       if (keep_shared) {
     174         p->set_shared();
     175       }
     176       p = next;
     177     }
     178   }
     179   // give the new table the free list as well
     180   new_table->copy_freelist(this);
     181   assert(new_table->number_of_entries() == saved_entry_count, "lost entry on dictionary copy?");
     182
     183   // Destroy memory used by the buckets in the hashtable.  The memory
     184   // for the elements has been used in a new table and is not
     185   // destroyed.  The memory reuse will benefit resizing the SystemDictionary
     186   // to avoid a memory allocation spike at safepoint.
     187   BasicHashtable<F>::free_buckets();
     188 }
     189
     190 template <MEMFLAGS F> void BasicHashtable<F>::free_buckets() {
     191   if (NULL != _buckets) {
     192     // Don't delete the buckets in the shared space.  They aren't
     193     // allocated by os::malloc
     194     if (!UseSharedSpaces ||
     195         !FileMapInfo::current_info()->is_in_shared_space(_buckets)) {
     196        FREE_C_HEAP_ARRAY(HashtableBucket, _buckets, F);
     197     }
     198     _buckets = NULL;
     199   }
     200 }
     201
     202 // Resize the internal bucket table if the current one reaches its maximum allowed chain length (LoadFactor)
     203 template <MEMFLAGS F> ResizeHashtableStats BasicHashtable<F>::resize_table(Monitor* lock, float trigger, float desired) {
     204   assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
     205   assert(lock->is_locked()==false, "table lock must not be held");
     206
     207   ResizeHashtableStats stats = {false, 0, 0};
     208
     209 //#define FORCE_RESIZE
     210 #ifdef FORCE_RESIZE
     211   int force_mod = 3;
     212   if (((_debug_resize_fire++) % force_mod) != 0) {
     213     return stats;
     214   }
     215 #else // FORCE_RESIZE
     216   // Check if there is anything to be done here
     217   float load_factor = (float)_number_of_entries/(float)_table_size;
     218   if (load_factor < trigger) {
     219     return stats;
     220   }
     221 #endif // FORCE_RESIZE
     222
     223 #ifndef PRODUCT
     224 //#ifdef PRODUCT_TEST
     225   julong time = (julong)os::javaTimeNanos();
     226 #endif // PRODUCT
     227
     228   MutexLocker mu(lock);
     229
     230   if (HashtablesVerifyBeforeResize == true) {
     231     verify();
     232   }
     233
     234   // Find the next best size for the hashtable.
     235   int table_size_old = _table_size;
     236 #ifdef FORCE_RESIZE
     237   int table_size_new = next_prime(table_size_old+1);
     238 #else
     239   int table_size_new = next_prime((int)(((float)_number_of_entries/(float)desired)+0.5f));
     240 #endif // FORCE_RESIZE
     241
     242   // Allocate new buckets and clear them
     243   HashtableBucket<F>* buckets_new = NEW_C_HEAP_ARRAY2(HashtableBucket<F>, table_size_new, F, CURRENT_PC);
     244   if (buckets_new == NULL) {
     245     return stats;
     246   }
     247
     248   for (int i = 0; i < table_size_new; i++) {
     249     buckets_new[i].clear();
     250   }
     251
     252   // hash_to_index() uses _table_size, so switch the sizes now
     253   _table_size = table_size_new;
     254
     255   // Do not bother sorting if new size is bigger than the number of entries
     256   bool sort = HashtablesResizeSort && (table_size_new > _number_of_entries);
     257
     258   // Move entries from the old table to a new table
     259   for (int index_old = 0; index_old < table_size_old; index_old++) {
     260     for (BasicHashtableEntry<F>* p = _buckets[index_old].get_entry(); p != NULL; ) {
     261       BasicHashtableEntry<F>* next = p->next();
     262       bool keep_shared = p->is_shared();
     263
     264       int index_new = hash_to_index(p->hash());
     265
     266       if (sort == true) {
     267         // Insert according to the lookup counter value, higher scored entries go to the front
     268         BasicHashtableEntry<F>* p_new_bigger = NULL;
     269         for (BasicHashtableEntry<F>* p_new = buckets_new[index_new].get_entry(); p_new != NULL; p_new = p_new->next()) {
     270           if (p_new != NULL) {
     271             if (p_new->_debug_lookups > p->_debug_lookups) {
     272               p_new_bigger = p_new;
     273             } else {
     274               break;
     275             }
     276           }
     277         }
     278         BasicHashtableEntry<F>* p_new_bigger_next = NULL;
     279         if (p_new_bigger == NULL) {
     280           p_new_bigger_next = buckets_new[index_new].get_entry();
     281           buckets_new[index_new].set_entry(p);
     282         } else {
     283           p_new_bigger_next = p_new_bigger->next();
     284           p_new_bigger->set_next(p);
     285         }
     286         p->set_next(p_new_bigger_next);
     287       } else {
     288 //#define ADD_TO_END
     289 #ifdef ADD_TO_END
     290         BasicHashtableEntry<F>* p_new_last = NULL;
     291         for (BasicHashtableEntry<F>* p_new = buckets_new[index_new].get_entry(); p_new != NULL; p_new = p_new->next()) {
     292           p_new_last = p_new;
     293         }
     294         if (p_new_last == NULL) {
     295           buckets_new[index_new].set_entry(p);
     296         } else {
     297           p_new_last->set_next(p);
     298         }
     299         p->set_next(NULL);
     300 #else // ADD_TO_END
     301         p->set_next(buckets_new[index_new].get_entry());
     302         buckets_new[index_new].set_entry(p);
     303 #endif // ADD_TO_END
     304       }
     305
     306       if (keep_shared) {
     307         p->set_shared();
     308       }
     309       p = next;
     310     }
     311   }
     312
     313   // The old backets now can be released
     314   BasicHashtable<F>::free_buckets();
     315
     316   // Switch to the new storage
     317   _buckets = buckets_new;
     318
     319   if (HashtablesVerifyAfterResize == true) {
     320     verify();
     321   }
     322
     323 #ifndef PRODUCT
     324 //#ifdef PRODUCT_TEST
     325   julong duration = (julong)os::javaTimeNanos() - time;
     326
     327   // Reset new table's statistics
     328   _debug_lookup_count = 0;
     329   _debug_insertion_count = 0;
     330   _debug_lookup_found_count = 0;
     331   _debug_lookup_found_max_duration = 0;
     332   _debug_lookup_found_total_duration = 0;
     333   _debug_chain_found_maximum_length = 0;
     334   _debug_chain_found_total_length = 0;
     335   _debug_lookup_failed_count = 0;
     336   _debug_lookup_failed_max_duration = 0;
     337   _debug_lookup_failed_total_duration = 0;
     338   _debug_chain_failed_maximum_length = 0;
     339   _debug_chain_failed_total_length = 0;
     340   _debug_resize_max_duration = (duration > _debug_resize_max_duration) ? duration : _debug_resize_max_duration;
     341   _debug_resize_total_duration += duration;
     342   _debug_resize_total_count++;
     343 #endif // PRODUCT
     344
     345   stats.resized = true;
     346   stats.old_size = table_size_old;
     347   stats.new_size = table_size_new;
     348   return stats;
     349 }
     350
     351 // Reverse the order of elements in the hash buckets.
     352
     353 template <MEMFLAGS F> void BasicHashtable<F>::reverse() {
     354
     355   for (int i = 0; i < _table_size; ++i) {
     356     BasicHashtableEntry<F>* new_list = NULL;
     357     BasicHashtableEntry<F>* p = bucket(i);
     358     while (p != NULL) {
     359       BasicHashtableEntry<F>* next = p->next();
     360       p->set_next(new_list);
     361       new_list = p;
     362       p = next;
     363     }
     364     *bucket_addr(i) = new_list;
     365   }
     366 }
     367
     368
     369 // Copy the table to the shared space.
     370
     371 template <MEMFLAGS F> void BasicHashtable<F>::copy_table(char** top, char* end) {
     372
     373   // Dump the hash table entries.
     374
     375   intptr_t *plen = (intptr_t*)(*top);
     376   *top += sizeof(*plen);
     377
     378   int i;
     379   for (i = 0; i < _table_size; ++i) {
     380     for (BasicHashtableEntry<F>** p = _buckets[i].entry_addr();
     381                               *p != NULL;
     382                                p = (*p)->next_addr()) {
     383       if (*top + entry_size() > end) {
     384         report_out_of_shared_space(SharedMiscData);
     385       }
     386       *p = (BasicHashtableEntry<F>*)memcpy(*top, *p, entry_size());
     387       *top += entry_size();
     388     }
     389   }
     390   *plen = (char*)(*top) - (char*)plen - sizeof(*plen);
     391
     392   // Set the shared bit.
     393
     394   for (i = 0; i < _table_size; ++i) {
     395     for (BasicHashtableEntry<F>* p = bucket(i); p != NULL; p = p->next()) {
     396       p->set_shared();
     397     }
     398   }
     399 }
     400

     401 // Reverse the order of elements in the hash buckets.
     402
     403 template <class T, MEMFLAGS F> void Hashtable<T, F>::reverse(void* boundary) {
     404
     405   for (int i = 0; i < this->table_size(); ++i) {
     406     HashtableEntry<T, F>* high_list = NULL;
     407     HashtableEntry<T, F>* low_list = NULL;
     408     HashtableEntry<T, F>* last_low_entry = NULL;
     409     HashtableEntry<T, F>* p = bucket(i);
     410     while (p != NULL) {
     411       HashtableEntry<T, F>* next = p->next();
     412       if ((void*)p->literal() >= boundary) {
     413         p->set_next(high_list);
     414         high_list = p;
     415       } else {
     416         p->set_next(low_list);
     417         low_list = p;
     418         if (last_low_entry == NULL) {
     419           last_low_entry = p;
     420         }
     421       }
     422       p = next;
     423     }
     424     if (low_list != NULL) {
     425       *bucket_addr(i) = low_list;
     426       last_low_entry->set_next(high_list);
     427     } else {
     428       *bucket_addr(i) = high_list;
     429     }
     430   }
     431 }
     432
     433 // Dump the hash table buckets.
     434
     435 template <MEMFLAGS F> void BasicHashtable<F>::copy_buckets(char** top, char* end) {
     436   intptr_t len = _table_size * sizeof(HashtableBucket<F>);
     437   *(intptr_t*)(*top) = len;
     438   *top += sizeof(intptr_t);
     439
     440   *(intptr_t*)(*top) = _number_of_entries;
     441   *top += sizeof(intptr_t);
     442
     443   if (*top + len > end) {
     444     report_out_of_shared_space(SharedMiscData);
     445   }
     446   _buckets = (HashtableBucket<F>*)memcpy(*top, _buckets, len);
     447   *top += len;
     448 }
     449
     450 template <class T, MEMFLAGS F> int Hashtable<T, F>::literal_size(Symbol *symbol) {
     451   return symbol->size() * HeapWordSize;
     452 }
     453
     454 template <class T, MEMFLAGS F> int Hashtable<T, F>::literal_size(oop oop) {
     455   // NOTE: this would over-count if (pre-JDK8) java_lang_Class::has_offset_field() is true,
     456   // and the String.value array is shared by several Strings. However, starting from JDK8,
     457   // the String.value array is not shared anymore.
     458   assert(oop != NULL && oop->klass() == SystemDictionary::String_klass(), "only strings are supported");
     459   return (oop->size() + java_lang_String::value(oop)->size()) * HeapWordSize;
     460 }
     461
     462 template <class T, MEMFLAGS F> int Hashtable<T, F>::literal_size(Klass *klass) {
     463   return klass->size() * HeapWordSize;
     464 }
     465
     466 // Dump footprint and bucket length statistics
     467 //
     468 // Note: if you create a new subclass of Hashtable<MyNewType, F>, you will need to
     469 // add a new function Hashtable<T, F>::literal_size(MyNewType lit)
     470
     471 template <class T, MEMFLAGS F> void Hashtable<T, F>::dump_table(outputStream* st, const char *table_name) {
     472   NumberSeq summary;
     473   int literal_bytes = 0;
     474   for (int i = 0; i < this->table_size(); ++i) {
     475     int count = 0;
     476     for (HashtableEntry<T, F>* e = this->bucket(i);
     477        e != NULL; e = e->next()) {
     478       count++;
     479       literal_bytes += literal_size(e->literal());
     480     }
     481     summary.add((double)count);
     482   }
     483   double num_buckets = summary.num();
     484   double num_entries = summary.sum();
     485
     486   int bucket_bytes = (int)num_buckets * sizeof(HashtableBucket<F>);
     487   int entry_bytes  = (int)num_entries * sizeof(HashtableEntry<T, F>);
     488   int total_bytes = literal_bytes +  bucket_bytes + entry_bytes;
     489
     490   double bucket_avg  = (num_buckets <= 0) ? 0 : (bucket_bytes  / num_buckets);
     491   double entry_avg   = (num_entries <= 0) ? 0 : (entry_bytes   / num_entries);
     492   double literal_avg = (num_entries <= 0) ? 0 : (literal_bytes / num_entries);
     493
     494   st->print_cr("%s statistics:", table_name);
     495   st->print_cr("Number of buckets       : %9d = %9d bytes, avg %7.3f", (int)num_buckets, bucket_bytes,  bucket_avg);
     496   st->print_cr("Number of entries       : %9d = %9d bytes, avg %7.3f", (int)num_entries, entry_bytes,   entry_avg);
     497   st->print_cr("Number of literals      : %9d = %9d bytes, avg %7.3f", (int)num_entries, literal_bytes, literal_avg);
     498   st->print_cr("Total footprint         : %9s = %9d bytes", "", total_bytes);
     499   st->print_cr("Average bucket size     : %9.3f (load factor)", summary.avg());
     500   st->print_cr("Variance of bucket size : %9.3f", summary.variance());
     501   st->print_cr("Std. dev. of bucket size: %9.3f", summary.sd());
     502   st->print_cr("Maximum bucket size     : %9d", (int)summary.maximum());
     503 }
     504
     505 template <class T, MEMFLAGS F> void Hashtable<T, F>::dump(outputStream* st, const char* table_name) {
     506 #ifndef PRODUCT
     507 //#ifdef PRODUCT_TEST
     508   st->print("\n-------------------------------------------------------------------------------\n");
     509   dump_table(st, table_name);
     510   st->print("-------------------------\n");
     511   {
     512     int count = 0;
     513     for (int i=0; i<1024; i++) {
     514       if (this->_debug_table_threads[i] != 0) {
     515         count++;
     516       } else {
     517         break;
     518       }
     519     }
     520     st->print_cr("Number of threads       : %9d", count);
     521   }
     522   st->print("-------------------------\n");
     523   {
     524     st->print_cr("All Lookups             : %9llu", this->_debug_all_lookup_count);
     525     st->print_cr("All Insertions          : %9llu", this->_debug_all_insertion_count);
     526     double ratio = 0.0;
     527     if (this->_debug_all_lookup_count > 0.0) {
     528       ratio = (double)(this->_debug_all_lookup_count-this->_debug_all_insertion_count) / (double)this->_debug_all_lookup_count;
     529     }
     530     st->print_cr("All Lookups ratio       : %9.3f", 100.0*ratio);
     531   }
     532   st->print("-------------------------\n");
     533   {
     534     st->print_cr("Lookups                 : %9llu", this->_debug_lookup_count);
     535     st->print_cr("Insertions              : %9llu", this->_debug_insertion_count);
     536     double ratio = 0.0;
     537     if (this->_debug_lookup_count > 0.0) {
     538       ratio = (double)(this->_debug_lookup_count-this->_debug_insertion_count) / (double)this->_debug_lookup_count;
     539     }
     540     st->print_cr("Lookups ratio           : %9.3f", 100.0*ratio);
     541   }
     542   {
     543     st->print_cr("Found Lookups           : %9llu", this->_debug_lookup_found_count);
     544     st->print_cr("Failed Lookups          : %9llu", this->_debug_lookup_failed_count);
     545     double ratio = 0.0;
     546     if (this->_debug_lookup_found_count > 0) {
     547       ratio = (double)this->_debug_lookup_found_count / (double)(this->_debug_lookup_found_count+this->_debug_lookup_failed_count);
     548     }
     549     st->print_cr("Found ratio             : %9.3f", 100.0*ratio);
     550   }
     551   st->print("-------------------------\n");
     552   {
     553     double average = 0.0;
     554     if (this->_debug_lookup_found_count > 0) {
     555       average = (((double)this->_debug_lookup_found_total_duration / (double)this->_debug_lookup_found_count) + 0.5);
     556     }
     557     st->print_cr("Total found lookup time : %9llu ns", this->_debug_lookup_found_total_duration);
     558     st->print_cr("Max found lookup time   : %9llu ns", this->_debug_lookup_found_max_duration);
     559     st->print_cr("Avg found lookup time   : %9d ns", (int)average);
     560   }
     561   {
     562     double average = 0.0;
     563     if (this->_debug_lookup_failed_count > 0) {
     564       average = (((double)this->_debug_lookup_failed_total_duration / (double)this->_debug_lookup_failed_count) + 0.5);
     565     }
     566     st->print_cr("Total failed lookup time: %9llu ns", this->_debug_lookup_failed_total_duration);
     567     st->print_cr("Max failed lookup time  : %9llu ns", this->_debug_lookup_failed_max_duration);
     568     st->print_cr("Avg failed lookup time  : %9d ns", (int)average);
     569   }
     570   st->print("-------------------------\n");
     571   {
     572     double average = 0.0;
     573     if (this->_debug_lookup_found_count > 0) {
     574       average = (double)this->_debug_chain_found_total_length / (double)this->_debug_lookup_found_count;
     575     }
     576     st->print_cr("Max found chain length  : %9llu", this->_debug_chain_found_maximum_length);
     577     st->print_cr("Avg found chain length  : %9.3f", average);
     578   }
     579   {
     580     double average = 0.0;
     581     if (this->_debug_lookup_failed_count > 0) {
     582       average = (double)this->_debug_chain_failed_total_length / (double)this->_debug_lookup_failed_count;
     583     }
     584     st->print_cr("Max failed chain length : %9llu", this->_debug_chain_failed_maximum_length);
     585     st->print_cr("Avg failed chain length : %9.3f", average);
     586   }
     587   st->print("-------------------------\n");
     588   {
     589     st->print_cr("Times table was resized : %9llu", this->_debug_resize_total_count);
     590     double average = 0.0;
     591     if (this->_debug_resize_total_count > 0) {
     592       average = (((double)this->_debug_resize_total_duration / (double)this->_debug_resize_total_count) + 0.5);
     593     }
     594     st->print_cr("Maximum resize time     : %9d ns (%.5f s)", (int)this->_debug_resize_max_duration, (double)this->_debug_resize_max_duration/1000000000.0);
     595     st->print_cr("Average resize time     : %9d ns (%.5f s)", (int)average, (double)average/1000000000.0);
     596     st->print_cr("Total resize time       : %9.5f s", (double)this->_debug_resize_total_duration/1000000000.0);
     597   }
     598 #endif
     599 }
     600

     601 #ifndef PRODUCT
     602
     603 template <class T, MEMFLAGS F> void Hashtable<T, F>::print() {
     604   ResourceMark rm;
     605
     606   for (int i = 0; i < BasicHashtable<F>::table_size(); i++) {
     607     HashtableEntry<T, F>* entry = bucket(i);
     608     while(entry != NULL) {
     609       tty->print("%d : ", i);
     610       entry->literal()->print();
     611       tty->cr();
     612       entry = entry->next();
     613     }
     614   }
     615 }
     616

     617 template <MEMFLAGS F> void BasicHashtable<F>::verify() {
     618   int count = 0;
     619   for (int i = 0; i < table_size(); i++) {
     620     for (BasicHashtableEntry<F>* p = bucket(i); p != NULL; p = p->next()) {
     621       ++count;
     622     }
     623   }
     624   assert(count == number_of_entries(), "number of hashtable entries incorrect");
     625 }
     626

     627 #endif // PRODUCT
     628

     629 #ifdef ASSERT
     630
     631 template <MEMFLAGS F> void BasicHashtable<F>::verify_lookup_length(double load) {
     632   if ((double)_lookup_length / (double)_lookup_count > load * 2.0) {
     633     warning("Performance bug: SystemDictionary lookup_count=%d "
     634             "lookup_length=%d average=%lf load=%f",
     635             _lookup_count, _lookup_length,
     636             (double) _lookup_length / _lookup_count, load);
     637   }
     638 }
     639
     640 #endif // ASSERT
     641
     642 // Explicitly instantiate these types
     643 #if INCLUDE_ALL_GCS
     644 template class Hashtable<nmethod*, mtGC>;
     645 template class HashtableEntry<nmethod*, mtGC>;
     646 template class BasicHashtable<mtGC>;
     647 #endif
     648 template class Hashtable<ConstantPool*, mtClass>;
     649 template class RehashableHashtable<Symbol*, mtSymbol>;
     650 template class RehashableHashtable<oopDesc*, mtSymbol>;
     651 template class Hashtable<Symbol*, mtSymbol>;
     652 template class Hashtable<Klass*, mtClass>;
     653 template class Hashtable<oop, mtClass>;
     654 #if defined(SOLARIS) || defined(CHECK_UNHANDLED_OOPS)
     655 template class Hashtable<oop, mtSymbol>;
     656 template class RehashableHashtable<oop, mtSymbol>;
     657 #endif // SOLARIS || CHECK_UNHANDLED_OOPS
     658 template class Hashtable<oopDesc*, mtSymbol>;
     659 template class Hashtable<Symbol*, mtClass>;
     660 template class HashtableEntry<Symbol*, mtSymbol>;
     661 template class HashtableEntry<Symbol*, mtClass>;
     662 template class HashtableEntry<oop, mtSymbol>;
     663 template class BasicHashtableEntry<mtSymbol>;
     664 template class BasicHashtableEntry<mtCode>;
     665 template class BasicHashtable<mtClass>;
     666 template class BasicHashtable<mtSymbol>;
     667 template class BasicHashtable<mtCode>;
     668 template class BasicHashtable<mtInternal>;
    --- EOF ---