src/share/vm/utilities/hashtable.cpp

changeset 3901
24b9c7f4cae6
parent 3900
d2a62e0f25eb
child 3904
ace99a6ffc83
     1.1 --- a/src/share/vm/utilities/hashtable.cpp	Fri Jun 29 17:12:15 2012 -0700
     1.2 +++ b/src/share/vm/utilities/hashtable.cpp	Mon Jul 02 13:11:28 2012 -0400
     1.3 @@ -33,11 +33,6 @@
     1.4  #include "utilities/hashtable.inline.hpp"
     1.5  
     1.6  
     1.7 -#ifndef USDT2
     1.8 -HS_DTRACE_PROBE_DECL4(hs_private, hashtable__new_entry,
     1.9 -  void*, unsigned int, void*, void*);
    1.10 -#endif /* !USDT2 */
    1.11 -
    1.12  // This is a generic hashtable, designed to be used for the symbol
    1.13  // and string tables.
    1.14  //
    1.15 @@ -46,8 +41,8 @@
    1.16  // %note:
    1.17  //  - HashtableEntrys are allocated in blocks to reduce the space overhead.
    1.18  
    1.19 -BasicHashtableEntry* BasicHashtable::new_entry(unsigned int hashValue) {
    1.20 -  BasicHashtableEntry* entry;
    1.21 +template <MEMFLAGS F> BasicHashtableEntry<F>* BasicHashtable<F>::new_entry(unsigned int hashValue) {
    1.22 +  BasicHashtableEntry<F>* entry;
    1.23  
    1.24    if (_free_list) {
    1.25      entry = _free_list;
    1.26 @@ -58,10 +53,10 @@
    1.27        int len = _entry_size * block_size;
    1.28        len = 1 << log2_intptr(len); // round down to power of 2
    1.29        assert(len >= _entry_size, "");
    1.30 -      _first_free_entry = NEW_C_HEAP_ARRAY(char, len);
    1.31 +      _first_free_entry = NEW_C_HEAP_ARRAY2(char, len, F, CURRENT_PC);
    1.32        _end_block = _first_free_entry + len;
    1.33      }
    1.34 -    entry = (BasicHashtableEntry*)_first_free_entry;
    1.35 +    entry = (BasicHashtableEntry<F>*)_first_free_entry;
    1.36      _first_free_entry += _entry_size;
    1.37    }
    1.38  
    1.39 @@ -71,29 +66,21 @@
    1.40  }
    1.41  
    1.42  
    1.43 -template <class T> HashtableEntry<T>* Hashtable<T>::new_entry(unsigned int hashValue, T obj) {
    1.44 -  HashtableEntry<T>* entry;
    1.45 +template <class T, MEMFLAGS F> HashtableEntry<T, F>* Hashtable<T, F>::new_entry(unsigned int hashValue, T obj) {
    1.46 +  HashtableEntry<T, F>* entry;
    1.47  
    1.48 -  entry = (HashtableEntry<T>*)BasicHashtable::new_entry(hashValue);
    1.49 +  entry = (HashtableEntry<T, F>*)BasicHashtable<F>::new_entry(hashValue);
    1.50    entry->set_literal(obj);
    1.51 -#ifndef USDT2
    1.52 -  HS_DTRACE_PROBE4(hs_private, hashtable__new_entry,
    1.53 -    this, hashValue, obj, entry);
    1.54 -#else /* USDT2 */
    1.55 -  HS_PRIVATE_HASHTABLE_NEW_ENTRY(
    1.56 -    this, hashValue, (uintptr_t) obj, entry);
    1.57 -#endif /* USDT2 */
    1.58    return entry;
    1.59  }
    1.60  
    1.61 -
    1.62  // Check to see if the hashtable is unbalanced.  The caller set a flag to
    1.63  // rehash at the next safepoint.  If this bucket is 60 times greater than the
    1.64  // expected average bucket length, it's an unbalanced hashtable.
    1.65  // This is somewhat an arbitrary heuristic but if one bucket gets to
    1.66  // rehash_count which is currently 100, there's probably something wrong.
    1.67  
    1.68 -bool BasicHashtable::check_rehash_table(int count) {
    1.69 +template <MEMFLAGS F> bool BasicHashtable<F>::check_rehash_table(int count) {
    1.70    assert(table_size() != 0, "underflow");
    1.71    if (count > (((double)number_of_entries()/(double)table_size())*rehash_multiple)) {
    1.72      // Set a flag for the next safepoint, which should be at some guaranteed
    1.73 @@ -107,13 +94,13 @@
    1.74  // with the existing elements.   This can be used to change the hash code
    1.75  // and could in the future change the size of the table.
    1.76  
    1.77 -template <class T> void Hashtable<T>::move_to(Hashtable<T>* new_table) {
    1.78 -  int saved_entry_count = number_of_entries();
    1.79 +template <class T, MEMFLAGS F> void Hashtable<T, F>::move_to(Hashtable<T, F>* new_table) {
    1.80 +  int saved_entry_count = BasicHashtable<F>::number_of_entries();
    1.81  
    1.82    // Iterate through the table and create a new entry for the new table
    1.83    for (int i = 0; i < new_table->table_size(); ++i) {
    1.84 -    for (HashtableEntry<T>* p = bucket(i); p != NULL; ) {
    1.85 -      HashtableEntry<T>* next = p->next();
    1.86 +    for (HashtableEntry<T, F>* p = bucket(i); p != NULL; ) {
    1.87 +      HashtableEntry<T, F>* next = p->next();
    1.88        T string = p->literal();
    1.89        // Use alternate hashing algorithm on the symbol in the first table
    1.90        unsigned int hashValue = new_hash(string);
    1.91 @@ -141,16 +128,16 @@
    1.92    // for the elements has been used in a new table and is not
    1.93    // destroyed.  The memory reuse will benefit resizing the SystemDictionary
    1.94    // to avoid a memory allocation spike at safepoint.
    1.95 -  free_buckets();
    1.96 +  BasicHashtable<F>::free_buckets();
    1.97  }
    1.98  
    1.99 -void BasicHashtable::free_buckets() {
   1.100 +template <MEMFLAGS F> void BasicHashtable<F>::free_buckets() {
   1.101    if (NULL != _buckets) {
   1.102      // Don't delete the buckets in the shared space.  They aren't
   1.103      // allocated by os::malloc
   1.104      if (!UseSharedSpaces ||
   1.105          !FileMapInfo::current_info()->is_in_shared_space(_buckets)) {
   1.106 -       FREE_C_HEAP_ARRAY(HashtableBucket, _buckets);
   1.107 +       FREE_C_HEAP_ARRAY(HashtableBucket, _buckets, F);
   1.108      }
   1.109      _buckets = NULL;
   1.110    }
   1.111 @@ -159,13 +146,13 @@
   1.112  
   1.113  // Reverse the order of elements in the hash buckets.
   1.114  
   1.115 -void BasicHashtable::reverse() {
   1.116 +template <MEMFLAGS F> void BasicHashtable<F>::reverse() {
   1.117  
   1.118    for (int i = 0; i < _table_size; ++i) {
   1.119 -    BasicHashtableEntry* new_list = NULL;
   1.120 -    BasicHashtableEntry* p = bucket(i);
   1.121 +    BasicHashtableEntry<F>* new_list = NULL;
   1.122 +    BasicHashtableEntry<F>* p = bucket(i);
   1.123      while (p != NULL) {
   1.124 -      BasicHashtableEntry* next = p->next();
   1.125 +      BasicHashtableEntry<F>* next = p->next();
   1.126        p->set_next(new_list);
   1.127        new_list = p;
   1.128        p = next;
   1.129 @@ -177,7 +164,7 @@
   1.130  
   1.131  // Copy the table to the shared space.
   1.132  
   1.133 -void BasicHashtable::copy_table(char** top, char* end) {
   1.134 +template <MEMFLAGS F> void BasicHashtable<F>::copy_table(char** top, char* end) {
   1.135  
   1.136    // Dump the hash table entries.
   1.137  
   1.138 @@ -186,13 +173,13 @@
   1.139  
   1.140    int i;
   1.141    for (i = 0; i < _table_size; ++i) {
   1.142 -    for (BasicHashtableEntry** p = _buckets[i].entry_addr();
   1.143 +    for (BasicHashtableEntry<F>** p = _buckets[i].entry_addr();
   1.144                                *p != NULL;
   1.145                                 p = (*p)->next_addr()) {
   1.146        if (*top + entry_size() > end) {
   1.147          report_out_of_shared_space(SharedMiscData);
   1.148        }
   1.149 -      *p = (BasicHashtableEntry*)memcpy(*top, *p, entry_size());
   1.150 +      *p = (BasicHashtableEntry<F>*)memcpy(*top, *p, entry_size());
   1.151        *top += entry_size();
   1.152      }
   1.153    }
   1.154 @@ -201,7 +188,7 @@
   1.155    // Set the shared bit.
   1.156  
   1.157    for (i = 0; i < _table_size; ++i) {
   1.158 -    for (BasicHashtableEntry* p = bucket(i); p != NULL; p = p->next()) {
   1.159 +    for (BasicHashtableEntry<F>* p = bucket(i); p != NULL; p = p->next()) {
   1.160        p->set_shared();
   1.161      }
   1.162    }
   1.163 @@ -211,15 +198,15 @@
   1.164  
   1.165  // Reverse the order of elements in the hash buckets.
   1.166  
   1.167 -template <class T> void Hashtable<T>::reverse(void* boundary) {
   1.168 +template <class T, MEMFLAGS F> void Hashtable<T, F>::reverse(void* boundary) {
   1.169  
   1.170 -  for (int i = 0; i < table_size(); ++i) {
   1.171 -    HashtableEntry<T>* high_list = NULL;
   1.172 -    HashtableEntry<T>* low_list = NULL;
   1.173 -    HashtableEntry<T>* last_low_entry = NULL;
   1.174 -    HashtableEntry<T>* p = bucket(i);
   1.175 +  for (int i = 0; i < this->table_size(); ++i) {
   1.176 +    HashtableEntry<T, F>* high_list = NULL;
   1.177 +    HashtableEntry<T, F>* low_list = NULL;
   1.178 +    HashtableEntry<T, F>* last_low_entry = NULL;
   1.179 +    HashtableEntry<T, F>* p = bucket(i);
   1.180      while (p != NULL) {
   1.181 -      HashtableEntry<T>* next = p->next();
   1.182 +      HashtableEntry<T, F>* next = p->next();
   1.183        if ((void*)p->literal() >= boundary) {
   1.184          p->set_next(high_list);
   1.185          high_list = p;
   1.186 @@ -244,8 +231,8 @@
   1.187  
   1.188  // Dump the hash table buckets.
   1.189  
   1.190 -void BasicHashtable::copy_buckets(char** top, char* end) {
   1.191 -  intptr_t len = _table_size * sizeof(HashtableBucket);
   1.192 +template <MEMFLAGS F> void BasicHashtable<F>::copy_buckets(char** top, char* end) {
   1.193 +  intptr_t len = _table_size * sizeof(HashtableBucket<F>);
   1.194    *(intptr_t*)(*top) = len;
   1.195    *top += sizeof(intptr_t);
   1.196  
   1.197 @@ -255,18 +242,18 @@
   1.198    if (*top + len > end) {
   1.199      report_out_of_shared_space(SharedMiscData);
   1.200    }
   1.201 -  _buckets = (HashtableBucket*)memcpy(*top, _buckets, len);
   1.202 +  _buckets = (HashtableBucket<F>*)memcpy(*top, _buckets, len);
   1.203    *top += len;
   1.204  }
   1.205  
   1.206  
   1.207  #ifndef PRODUCT
   1.208  
   1.209 -template <class T> void Hashtable<T>::print() {
   1.210 +template <class T, MEMFLAGS F> void Hashtable<T, F>::print() {
   1.211    ResourceMark rm;
   1.212  
   1.213 -  for (int i = 0; i < table_size(); i++) {
   1.214 -    HashtableEntry<T>* entry = bucket(i);
   1.215 +  for (int i = 0; i < BasicHashtable<F>::table_size(); i++) {
   1.216 +    HashtableEntry<T, F>* entry = bucket(i);
   1.217      while(entry != NULL) {
   1.218        tty->print("%d : ", i);
   1.219        entry->literal()->print();
   1.220 @@ -277,10 +264,10 @@
   1.221  }
   1.222  
   1.223  
   1.224 -void BasicHashtable::verify() {
   1.225 +template <MEMFLAGS F> void BasicHashtable<F>::verify() {
   1.226    int count = 0;
   1.227    for (int i = 0; i < table_size(); i++) {
   1.228 -    for (BasicHashtableEntry* p = bucket(i); p != NULL; p = p->next()) {
   1.229 +    for (BasicHashtableEntry<F>* p = bucket(i); p != NULL; p = p->next()) {
   1.230        ++count;
   1.231      }
   1.232    }
   1.233 @@ -293,7 +280,7 @@
   1.234  
   1.235  #ifdef ASSERT
   1.236  
   1.237 -void BasicHashtable::verify_lookup_length(double load) {
   1.238 +template <MEMFLAGS F> void BasicHashtable<F>::verify_lookup_length(double load) {
   1.239    if ((double)_lookup_length / (double)_lookup_count > load * 2.0) {
   1.240      warning("Performance bug: SystemDictionary lookup_count=%d "
   1.241              "lookup_length=%d average=%lf load=%f",
   1.242 @@ -303,10 +290,22 @@
   1.243  }
   1.244  
   1.245  #endif
   1.246 -
   1.247  // Explicitly instantiate these types
   1.248 -template class Hashtable<constantPoolOop>;
   1.249 -template class Hashtable<Symbol*>;
   1.250 -template class Hashtable<klassOop>;
   1.251 -template class Hashtable<oop>;
   1.252 -
   1.253 +template class Hashtable<constantPoolOop, mtClass>;
   1.254 +template class Hashtable<Symbol*, mtSymbol>;
   1.255 +template class Hashtable<klassOop, mtClass>;
   1.256 +template class Hashtable<oop, mtClass>;
   1.257 +#ifdef SOLARIS
   1.258 +template class Hashtable<oop, mtSymbol>;
   1.259 +#endif
   1.260 +template class Hashtable<oopDesc*, mtSymbol>;
   1.261 +template class Hashtable<Symbol*, mtClass>;
   1.262 +template class HashtableEntry<Symbol*, mtSymbol>;
   1.263 +template class HashtableEntry<Symbol*, mtClass>;
   1.264 +template class HashtableEntry<oop, mtSymbol>;
   1.265 +template class BasicHashtableEntry<mtSymbol>;
   1.266 +template class BasicHashtableEntry<mtCode>;
   1.267 +template class BasicHashtable<mtClass>;
   1.268 +template class BasicHashtable<mtSymbol>;
   1.269 +template class BasicHashtable<mtCode>;
   1.270 +template class BasicHashtable<mtInternal>;

mercurial