hotspot/src/share/vm/utilities/hashtable.cpp
author trims
Thu, 27 May 2010 19:08:38 -0700
changeset 5547 f4b087cbb361
parent 1623 a0dd9009e992
child 7397 5b173b4ca846
permissions -rw-r--r--
6941466: Oracle rebranding changes for Hotspot repositories Summary: Change all the Sun copyrights to Oracle copyright Reviewed-by: ohair
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1623
diff changeset
     2
 * Copyright (c) 2003, 2008, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1623
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1623
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1623
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
# include "incls/_precompiled.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
# include "incls/_hashtable.cpp.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
HS_DTRACE_PROBE_DECL4(hs_private, hashtable__new_entry,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
  void*, unsigned int, oop, void*);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
// This is a generic hashtable, designed to be used for the symbol
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
// and string tables.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
// It is implemented as an open hash table with a fixed number of buckets.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
// %note:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
//  - HashtableEntrys are allocated in blocks to reduce the space overhead.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
BasicHashtableEntry* BasicHashtable::new_entry(unsigned int hashValue) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
  BasicHashtableEntry* entry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  if (_free_list) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
    entry = _free_list;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
    _free_list = _free_list->next();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  } else {
1551
b431de37a22c 6770949: minor tweaks before 6655638
jrose
parents: 1
diff changeset
    46
    if (_first_free_entry + _entry_size >= _end_block) {
b431de37a22c 6770949: minor tweaks before 6655638
jrose
parents: 1
diff changeset
    47
      int block_size = MIN2(512, MAX2((int)_table_size / 2, (int)_number_of_entries));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
      int len = _entry_size * block_size;
1551
b431de37a22c 6770949: minor tweaks before 6655638
jrose
parents: 1
diff changeset
    49
      len = 1 << log2_intptr(len); // round down to power of 2
b431de37a22c 6770949: minor tweaks before 6655638
jrose
parents: 1
diff changeset
    50
      assert(len >= _entry_size, "");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
      _first_free_entry = NEW_C_HEAP_ARRAY(char, len);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
      _end_block = _first_free_entry + len;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
    entry = (BasicHashtableEntry*)_first_free_entry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
    _first_free_entry += _entry_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
1551
b431de37a22c 6770949: minor tweaks before 6655638
jrose
parents: 1
diff changeset
    58
  assert(_entry_size % HeapWordSize == 0, "");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  entry->set_hash(hashValue);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  return entry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
HashtableEntry* Hashtable::new_entry(unsigned int hashValue, oop obj) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  HashtableEntry* entry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  entry = (HashtableEntry*)BasicHashtable::new_entry(hashValue);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  entry->set_literal(obj);   // clears literal string field
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  HS_DTRACE_PROBE4(hs_private, hashtable__new_entry,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
    this, hashValue, obj, entry);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  return entry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
// GC support
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
void Hashtable::unlink(BoolObjectClosure* is_alive) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  // Readers of the table are unlocked, so we should only be removing
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  // entries at a safepoint.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  for (int i = 0; i < table_size(); ++i) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
    for (HashtableEntry** p = bucket_addr(i); *p != NULL; ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
      HashtableEntry* entry = *p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
      if (entry->is_shared()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
      assert(entry->literal() != NULL, "just checking");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
      if (is_alive->do_object_b(entry->literal())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
        p = entry->next_addr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
        *p = entry->next();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
        free_entry(entry);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
void Hashtable::oops_do(OopClosure* f) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  for (int i = 0; i < table_size(); ++i) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
    HashtableEntry** p = bucket_addr(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
    HashtableEntry* entry = bucket(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
    while (entry != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
      f->do_oop(entry->literal_addr());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
      // Did the closure remove the literal from the table?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
      if (entry->literal() == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
        assert(!entry->is_shared(), "immutable hashtable entry?");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
        *p = entry->next();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
        free_entry(entry);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
        p = entry->next_addr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
      entry = (HashtableEntry*)HashtableEntry::make_ptr(*p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
// Reverse the order of elements in the hash buckets.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
void BasicHashtable::reverse() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  for (int i = 0; i < _table_size; ++i) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
    BasicHashtableEntry* new_list = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
    BasicHashtableEntry* p = bucket(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
    while (p != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
      BasicHashtableEntry* next = p->next();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
      p->set_next(new_list);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
      new_list = p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
      p = next;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
    *bucket_addr(i) = new_list;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
// Copy the table to the shared space.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
void BasicHashtable::copy_table(char** top, char* end) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  // Dump the hash table entries.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
  intptr_t *plen = (intptr_t*)(*top);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  *top += sizeof(*plen);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
  int i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  for (i = 0; i < _table_size; ++i) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
    for (BasicHashtableEntry** p = _buckets[i].entry_addr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
                              *p != NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
                               p = (*p)->next_addr()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
      if (*top + entry_size() > end) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
        warning("\nThe shared miscellaneous data space is not large "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
                "enough to \npreload requested classes.  Use "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
                "-XX:SharedMiscDataSize= to increase \nthe initial "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
                "size of the miscellaneous data space.\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
        exit(2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
      *p = (BasicHashtableEntry*)memcpy(*top, *p, entry_size());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
      *top += entry_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
  *plen = (char*)(*top) - (char*)plen - sizeof(*plen);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
  // Set the shared bit.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
  for (i = 0; i < _table_size; ++i) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
    for (BasicHashtableEntry* p = bucket(i); p != NULL; p = p->next()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
      p->set_shared();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
// Reverse the order of elements in the hash buckets.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
void Hashtable::reverse(void* boundary) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
  for (int i = 0; i < table_size(); ++i) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
    HashtableEntry* high_list = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
    HashtableEntry* low_list = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
    HashtableEntry* last_low_entry = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
    HashtableEntry* p = bucket(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
    while (p != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
      HashtableEntry* next = p->next();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
      if ((void*)p->literal() >= boundary) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
        p->set_next(high_list);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
        high_list = p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
        p->set_next(low_list);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
        low_list = p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
        if (last_low_entry == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
          last_low_entry = p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
      p = next;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
    if (low_list != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
      *bucket_addr(i) = low_list;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
      last_low_entry->set_next(high_list);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
      *bucket_addr(i) = high_list;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
// Dump the hash table buckets.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
void BasicHashtable::copy_buckets(char** top, char* end) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
  intptr_t len = _table_size * sizeof(HashtableBucket);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
  *(intptr_t*)(*top) = len;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
  *top += sizeof(intptr_t);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
  *(intptr_t*)(*top) = _number_of_entries;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
  *top += sizeof(intptr_t);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
  if (*top + len > end) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
    warning("\nThe shared miscellaneous data space is not large "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
            "enough to \npreload requested classes.  Use "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
            "-XX:SharedMiscDataSize= to increase \nthe initial "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
            "size of the miscellaneous data space.\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
    exit(2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
  _buckets = (HashtableBucket*)memcpy(*top, _buckets, len);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
  *top += len;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
void Hashtable::print() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
  ResourceMark rm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
  for (int i = 0; i < table_size(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
    HashtableEntry* entry = bucket(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
    while(entry != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
      tty->print("%d : ", i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
      entry->literal()->print();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
      tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
      entry = entry->next();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
void BasicHashtable::verify() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
  int count = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
  for (int i = 0; i < table_size(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
    for (BasicHashtableEntry* p = bucket(i); p != NULL; p = p->next()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
      ++count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
  assert(count == number_of_entries(), "number of hashtable entries incorrect");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
#endif // PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
void BasicHashtable::verify_lookup_length(double load) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
  if ((double)_lookup_length / (double)_lookup_count > load * 2.0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
    warning("Performance bug: SystemDictionary lookup_count=%d "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
            "lookup_length=%d average=%lf load=%f",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
            _lookup_count, _lookup_length,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
            (double) _lookup_length / _lookup_count, load);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
#endif