hotspot/src/share/vm/classfile/stringTable.cpp
author roland
Thu, 10 Jul 2014 15:12:48 +0200
changeset 25635 d2f8ae0c908b
parent 25351 7c198a690050
child 25490 59f226da8d81
permissions -rw-r--r--
8040237: nsk/jvmti/RetransformClasses/retransform001 crashed the VM on all platforms when run with with -server -Xcomp Summary: class redefinition may cause speculative trap clean up code to dereference dead method Reviewed-by: kvn, coleenp
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
     1
/*
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
     2
 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
     4
 *
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
     7
 * published by the Free Software Foundation.
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
     8
 *
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    13
 * accompanied this code).
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    14
 *
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    18
 *
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    21
 * questions.
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    22
 *
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    23
 */
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    24
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    25
#include "precompiled.hpp"
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    26
#include "classfile/altHashing.hpp"
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    27
#include "classfile/javaClasses.hpp"
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    28
#include "classfile/stringTable.hpp"
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    29
#include "classfile/systemDictionary.hpp"
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    30
#include "gc_interface/collectedHeap.inline.hpp"
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    31
#include "memory/allocation.inline.hpp"
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    32
#include "memory/filemap.hpp"
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    33
#include "memory/gcLocker.inline.hpp"
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    34
#include "oops/oop.inline.hpp"
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    35
#include "oops/oop.inline2.hpp"
25351
7c198a690050 8044775: Improve usage of umbrella header atomic.inline.hpp.
goetz
parents: 24429
diff changeset
    36
#include "runtime/atomic.inline.hpp"
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    37
#include "runtime/mutexLocker.hpp"
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    38
#include "utilities/hashtable.inline.hpp"
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    39
#if INCLUDE_ALL_GCS
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    40
#include "gc_implementation/g1/g1StringDedup.hpp"
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    41
#endif
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    42
24429
coleenp
parents: 24426
diff changeset
    43
PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
coleenp
parents: 24426
diff changeset
    44
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    45
// the number of buckets a thread claims
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    46
const int ClaimChunkSize = 32;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    47
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    48
#ifdef ASSERT
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    49
class StableMemoryChecker : public StackObj {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    50
  enum { _bufsize = wordSize*4 };
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    51
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    52
  address _region;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    53
  jint    _size;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    54
  u1      _save_buf[_bufsize];
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    55
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    56
  int sample(u1* save_buf) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    57
    if (_size <= _bufsize) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    58
      memcpy(save_buf, _region, _size);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    59
      return _size;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    60
    } else {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    61
      // copy head and tail
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    62
      memcpy(&save_buf[0],          _region,                      _bufsize/2);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    63
      memcpy(&save_buf[_bufsize/2], _region + _size - _bufsize/2, _bufsize/2);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    64
      return (_bufsize/2)*2;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    65
    }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    66
  }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    67
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    68
 public:
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    69
  StableMemoryChecker(const void* region, jint size) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    70
    _region = (address) region;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    71
    _size   = size;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    72
    sample(_save_buf);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    73
  }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    74
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    75
  bool verify() {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    76
    u1 check_buf[sizeof(_save_buf)];
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    77
    int check_size = sample(check_buf);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    78
    return (0 == memcmp(_save_buf, check_buf, check_size));
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    79
  }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    80
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    81
  void set_region(const void* region) { _region = (address) region; }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    82
};
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    83
#endif
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    84
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    85
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    86
// --------------------------------------------------------------------------
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    87
StringTable* StringTable::_the_table = NULL;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    88
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    89
bool StringTable::_needs_rehashing = false;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    90
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    91
volatile int StringTable::_parallel_claimed_idx = 0;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    92
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    93
// Pick hashing algorithm
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    94
unsigned int StringTable::hash_string(const jchar* s, int len) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    95
  return use_alternate_hashcode() ? AltHashing::murmur3_32(seed(), s, len) :
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    96
                                    java_lang_String::hash_code(s, len);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    97
}
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    98
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    99
oop StringTable::lookup(int index, jchar* name,
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   100
                        int len, unsigned int hash) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   101
  int count = 0;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   102
  for (HashtableEntry<oop, mtSymbol>* l = bucket(index); l != NULL; l = l->next()) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   103
    count++;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   104
    if (l->hash() == hash) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   105
      if (java_lang_String::equals(l->literal(), name, len)) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   106
        return l->literal();
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   107
      }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   108
    }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   109
  }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   110
  // If the bucket size is too deep check if this hash code is insufficient.
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   111
  if (count >= BasicHashtable<mtSymbol>::rehash_count && !needs_rehashing()) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   112
    _needs_rehashing = check_rehash_table(count);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   113
  }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   114
  return NULL;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   115
}
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   116
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   117
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   118
oop StringTable::basic_add(int index_arg, Handle string, jchar* name,
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   119
                           int len, unsigned int hashValue_arg, TRAPS) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   120
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   121
  assert(java_lang_String::equals(string(), name, len),
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   122
         "string must be properly initialized");
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   123
  // Cannot hit a safepoint in this function because the "this" pointer can move.
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   124
  No_Safepoint_Verifier nsv;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   125
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   126
  // Check if the symbol table has been rehashed, if so, need to recalculate
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   127
  // the hash value and index before second lookup.
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   128
  unsigned int hashValue;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   129
  int index;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   130
  if (use_alternate_hashcode()) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   131
    hashValue = hash_string(name, len);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   132
    index = hash_to_index(hashValue);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   133
  } else {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   134
    hashValue = hashValue_arg;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   135
    index = index_arg;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   136
  }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   137
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   138
  // Since look-up was done lock-free, we need to check if another
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   139
  // thread beat us in the race to insert the symbol.
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   140
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   141
  oop test = lookup(index, name, len, hashValue); // calls lookup(u1*, int)
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   142
  if (test != NULL) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   143
    // Entry already added
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   144
    return test;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   145
  }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   146
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   147
  HashtableEntry<oop, mtSymbol>* entry = new_entry(hashValue, string());
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   148
  add_entry(index, entry);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   149
  return string();
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   150
}
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   151
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   152
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   153
oop StringTable::lookup(Symbol* symbol) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   154
  ResourceMark rm;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   155
  int length;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   156
  jchar* chars = symbol->as_unicode(length);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   157
  return lookup(chars, length);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   158
}
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   159
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   160
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   161
oop StringTable::lookup(jchar* name, int len) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   162
  unsigned int hash = hash_string(name, len);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   163
  int index = the_table()->hash_to_index(hash);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   164
  return the_table()->lookup(index, name, len, hash);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   165
}
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   166
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   167
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   168
oop StringTable::intern(Handle string_or_null, jchar* name,
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   169
                        int len, TRAPS) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   170
  unsigned int hashValue = hash_string(name, len);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   171
  int index = the_table()->hash_to_index(hashValue);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   172
  oop found_string = the_table()->lookup(index, name, len, hashValue);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   173
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   174
  // Found
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   175
  if (found_string != NULL) return found_string;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   176
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   177
  debug_only(StableMemoryChecker smc(name, len * sizeof(name[0])));
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   178
  assert(!Universe::heap()->is_in_reserved(name),
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   179
         "proposed name of symbol must be stable");
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   180
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   181
  Handle string;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   182
  // try to reuse the string if possible
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   183
  if (!string_or_null.is_null()) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   184
    string = string_or_null;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   185
  } else {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   186
    string = java_lang_String::create_from_unicode(name, len, CHECK_NULL);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   187
  }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   188
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   189
#if INCLUDE_ALL_GCS
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   190
  if (G1StringDedup::is_enabled()) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   191
    // Deduplicate the string before it is interned. Note that we should never
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   192
    // deduplicate a string after it has been interned. Doing so will counteract
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   193
    // compiler optimizations done on e.g. interned string literals.
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   194
    G1StringDedup::deduplicate(string());
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   195
  }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   196
#endif
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   197
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   198
  // Grab the StringTable_lock before getting the_table() because it could
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   199
  // change at safepoint.
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   200
  MutexLocker ml(StringTable_lock, THREAD);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   201
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   202
  // Otherwise, add to symbol to table
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   203
  return the_table()->basic_add(index, string, name, len,
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   204
                                hashValue, CHECK_NULL);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   205
}
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   206
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   207
oop StringTable::intern(Symbol* symbol, TRAPS) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   208
  if (symbol == NULL) return NULL;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   209
  ResourceMark rm(THREAD);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   210
  int length;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   211
  jchar* chars = symbol->as_unicode(length);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   212
  Handle string;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   213
  oop result = intern(string, chars, length, CHECK_NULL);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   214
  return result;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   215
}
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   216
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   217
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   218
oop StringTable::intern(oop string, TRAPS)
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   219
{
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   220
  if (string == NULL) return NULL;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   221
  ResourceMark rm(THREAD);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   222
  int length;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   223
  Handle h_string (THREAD, string);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   224
  jchar* chars = java_lang_String::as_unicode_string(string, length, CHECK_NULL);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   225
  oop result = intern(h_string, chars, length, CHECK_NULL);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   226
  return result;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   227
}
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   228
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   229
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   230
oop StringTable::intern(const char* utf8_string, TRAPS) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   231
  if (utf8_string == NULL) return NULL;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   232
  ResourceMark rm(THREAD);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   233
  int length = UTF8::unicode_length(utf8_string);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   234
  jchar* chars = NEW_RESOURCE_ARRAY(jchar, length);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   235
  UTF8::convert_to_unicode(utf8_string, chars, length);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   236
  Handle string;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   237
  oop result = intern(string, chars, length, CHECK_NULL);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   238
  return result;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   239
}
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   240
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   241
void StringTable::unlink_or_oops_do(BoolObjectClosure* is_alive, OopClosure* f, int* processed, int* removed) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   242
  buckets_unlink_or_oops_do(is_alive, f, 0, the_table()->table_size(), processed, removed);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   243
}
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   244
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   245
void StringTable::possibly_parallel_unlink_or_oops_do(BoolObjectClosure* is_alive, OopClosure* f, int* processed, int* removed) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   246
  // Readers of the table are unlocked, so we should only be removing
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   247
  // entries at a safepoint.
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   248
  assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   249
  const int limit = the_table()->table_size();
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   250
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   251
  for (;;) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   252
    // Grab next set of buckets to scan
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   253
    int start_idx = Atomic::add(ClaimChunkSize, &_parallel_claimed_idx) - ClaimChunkSize;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   254
    if (start_idx >= limit) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   255
      // End of table
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   256
      break;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   257
    }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   258
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   259
    int end_idx = MIN2(limit, start_idx + ClaimChunkSize);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   260
    buckets_unlink_or_oops_do(is_alive, f, start_idx, end_idx, processed, removed);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   261
  }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   262
}
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   263
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   264
void StringTable::buckets_oops_do(OopClosure* f, int start_idx, int end_idx) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   265
  const int limit = the_table()->table_size();
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   266
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   267
  assert(0 <= start_idx && start_idx <= limit,
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   268
         err_msg("start_idx (%d) is out of bounds", start_idx));
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   269
  assert(0 <= end_idx && end_idx <= limit,
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   270
         err_msg("end_idx (%d) is out of bounds", end_idx));
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   271
  assert(start_idx <= end_idx,
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   272
         err_msg("Index ordering: start_idx=%d, end_idx=%d",
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   273
                 start_idx, end_idx));
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   274
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   275
  for (int i = start_idx; i < end_idx; i += 1) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   276
    HashtableEntry<oop, mtSymbol>* entry = the_table()->bucket(i);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   277
    while (entry != NULL) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   278
      assert(!entry->is_shared(), "CDS not used for the StringTable");
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   279
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   280
      f->do_oop((oop*)entry->literal_addr());
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   281
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   282
      entry = entry->next();
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   283
    }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   284
  }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   285
}
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   286
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   287
void StringTable::buckets_unlink_or_oops_do(BoolObjectClosure* is_alive, OopClosure* f, int start_idx, int end_idx, int* processed, int* removed) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   288
  const int limit = the_table()->table_size();
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   289
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   290
  assert(0 <= start_idx && start_idx <= limit,
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   291
         err_msg("start_idx (%d) is out of bounds", start_idx));
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   292
  assert(0 <= end_idx && end_idx <= limit,
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   293
         err_msg("end_idx (%d) is out of bounds", end_idx));
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   294
  assert(start_idx <= end_idx,
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   295
         err_msg("Index ordering: start_idx=%d, end_idx=%d",
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   296
                 start_idx, end_idx));
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   297
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   298
  for (int i = start_idx; i < end_idx; ++i) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   299
    HashtableEntry<oop, mtSymbol>** p = the_table()->bucket_addr(i);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   300
    HashtableEntry<oop, mtSymbol>* entry = the_table()->bucket(i);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   301
    while (entry != NULL) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   302
      assert(!entry->is_shared(), "CDS not used for the StringTable");
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   303
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   304
      if (is_alive->do_object_b(entry->literal())) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   305
        if (f != NULL) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   306
          f->do_oop((oop*)entry->literal_addr());
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   307
        }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   308
        p = entry->next_addr();
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   309
      } else {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   310
        *p = entry->next();
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   311
        the_table()->free_entry(entry);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   312
        (*removed)++;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   313
      }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   314
      (*processed)++;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   315
      entry = *p;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   316
    }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   317
  }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   318
}
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   319
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   320
void StringTable::oops_do(OopClosure* f) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   321
  buckets_oops_do(f, 0, the_table()->table_size());
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   322
}
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   323
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   324
void StringTable::possibly_parallel_oops_do(OopClosure* f) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   325
  const int limit = the_table()->table_size();
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   326
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   327
  for (;;) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   328
    // Grab next set of buckets to scan
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   329
    int start_idx = Atomic::add(ClaimChunkSize, &_parallel_claimed_idx) - ClaimChunkSize;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   330
    if (start_idx >= limit) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   331
      // End of table
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   332
      break;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   333
    }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   334
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   335
    int end_idx = MIN2(limit, start_idx + ClaimChunkSize);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   336
    buckets_oops_do(f, start_idx, end_idx);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   337
  }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   338
}
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   339
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   340
// This verification is part of Universe::verify() and needs to be quick.
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   341
// See StringTable::verify_and_compare() below for exhaustive verification.
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   342
void StringTable::verify() {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   343
  for (int i = 0; i < the_table()->table_size(); ++i) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   344
    HashtableEntry<oop, mtSymbol>* p = the_table()->bucket(i);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   345
    for ( ; p != NULL; p = p->next()) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   346
      oop s = p->literal();
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   347
      guarantee(s != NULL, "interned string is NULL");
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   348
      unsigned int h = java_lang_String::hash_string(s);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   349
      guarantee(p->hash() == h, "broken hash in string table entry");
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   350
      guarantee(the_table()->hash_to_index(h) == i,
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   351
                "wrong index in string table");
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   352
    }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   353
  }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   354
}
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   355
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   356
void StringTable::dump(outputStream* st) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   357
  the_table()->dump_table(st, "StringTable");
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   358
}
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   359
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   360
StringTable::VerifyRetTypes StringTable::compare_entries(
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   361
                                      int bkt1, int e_cnt1,
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   362
                                      HashtableEntry<oop, mtSymbol>* e_ptr1,
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   363
                                      int bkt2, int e_cnt2,
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   364
                                      HashtableEntry<oop, mtSymbol>* e_ptr2) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   365
  // These entries are sanity checked by verify_and_compare_entries()
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   366
  // before this function is called.
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   367
  oop str1 = e_ptr1->literal();
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   368
  oop str2 = e_ptr2->literal();
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   369
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   370
  if (str1 == str2) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   371
    tty->print_cr("ERROR: identical oop values (0x" PTR_FORMAT ") "
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   372
                  "in entry @ bucket[%d][%d] and entry @ bucket[%d][%d]",
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   373
                  (void *)str1, bkt1, e_cnt1, bkt2, e_cnt2);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   374
    return _verify_fail_continue;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   375
  }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   376
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   377
  if (java_lang_String::equals(str1, str2)) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   378
    tty->print_cr("ERROR: identical String values in entry @ "
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   379
                  "bucket[%d][%d] and entry @ bucket[%d][%d]",
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   380
                  bkt1, e_cnt1, bkt2, e_cnt2);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   381
    return _verify_fail_continue;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   382
  }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   383
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   384
  return _verify_pass;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   385
}
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   386
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   387
StringTable::VerifyRetTypes StringTable::verify_entry(int bkt, int e_cnt,
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   388
                                      HashtableEntry<oop, mtSymbol>* e_ptr,
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   389
                                      StringTable::VerifyMesgModes mesg_mode) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   390
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   391
  VerifyRetTypes ret = _verify_pass;  // be optimistic
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   392
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   393
  oop str = e_ptr->literal();
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   394
  if (str == NULL) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   395
    if (mesg_mode == _verify_with_mesgs) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   396
      tty->print_cr("ERROR: NULL oop value in entry @ bucket[%d][%d]", bkt,
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   397
                    e_cnt);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   398
    }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   399
    // NULL oop means no more verifications are possible
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   400
    return _verify_fail_done;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   401
  }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   402
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   403
  if (str->klass() != SystemDictionary::String_klass()) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   404
    if (mesg_mode == _verify_with_mesgs) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   405
      tty->print_cr("ERROR: oop is not a String in entry @ bucket[%d][%d]",
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   406
                    bkt, e_cnt);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   407
    }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   408
    // not a String means no more verifications are possible
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   409
    return _verify_fail_done;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   410
  }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   411
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   412
  unsigned int h = java_lang_String::hash_string(str);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   413
  if (e_ptr->hash() != h) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   414
    if (mesg_mode == _verify_with_mesgs) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   415
      tty->print_cr("ERROR: broken hash value in entry @ bucket[%d][%d], "
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   416
                    "bkt_hash=%d, str_hash=%d", bkt, e_cnt, e_ptr->hash(), h);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   417
    }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   418
    ret = _verify_fail_continue;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   419
  }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   420
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   421
  if (the_table()->hash_to_index(h) != bkt) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   422
    if (mesg_mode == _verify_with_mesgs) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   423
      tty->print_cr("ERROR: wrong index value for entry @ bucket[%d][%d], "
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   424
                    "str_hash=%d, hash_to_index=%d", bkt, e_cnt, h,
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   425
                    the_table()->hash_to_index(h));
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   426
    }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   427
    ret = _verify_fail_continue;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   428
  }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   429
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   430
  return ret;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   431
}
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   432
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   433
// See StringTable::verify() above for the quick verification that is
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   434
// part of Universe::verify(). This verification is exhaustive and
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   435
// reports on every issue that is found. StringTable::verify() only
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   436
// reports on the first issue that is found.
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   437
//
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   438
// StringTable::verify_entry() checks:
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   439
// - oop value != NULL (same as verify())
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   440
// - oop value is a String
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   441
// - hash(String) == hash in entry (same as verify())
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   442
// - index for hash == index of entry (same as verify())
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   443
//
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   444
// StringTable::compare_entries() checks:
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   445
// - oops are unique across all entries
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   446
// - String values are unique across all entries
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   447
//
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   448
int StringTable::verify_and_compare_entries() {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   449
  assert(StringTable_lock->is_locked(), "sanity check");
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   450
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   451
  int  fail_cnt = 0;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   452
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   453
  // first, verify all the entries individually:
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   454
  for (int bkt = 0; bkt < the_table()->table_size(); bkt++) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   455
    HashtableEntry<oop, mtSymbol>* e_ptr = the_table()->bucket(bkt);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   456
    for (int e_cnt = 0; e_ptr != NULL; e_ptr = e_ptr->next(), e_cnt++) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   457
      VerifyRetTypes ret = verify_entry(bkt, e_cnt, e_ptr, _verify_with_mesgs);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   458
      if (ret != _verify_pass) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   459
        fail_cnt++;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   460
      }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   461
    }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   462
  }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   463
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   464
  // Optimization: if the above check did not find any failures, then
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   465
  // the comparison loop below does not need to call verify_entry()
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   466
  // before calling compare_entries(). If there were failures, then we
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   467
  // have to call verify_entry() to see if the entry can be passed to
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   468
  // compare_entries() safely. When we call verify_entry() in the loop
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   469
  // below, we do so quietly to void duplicate messages and we don't
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   470
  // increment fail_cnt because the failures have already been counted.
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   471
  bool need_entry_verify = (fail_cnt != 0);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   472
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   473
  // second, verify all entries relative to each other:
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   474
  for (int bkt1 = 0; bkt1 < the_table()->table_size(); bkt1++) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   475
    HashtableEntry<oop, mtSymbol>* e_ptr1 = the_table()->bucket(bkt1);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   476
    for (int e_cnt1 = 0; e_ptr1 != NULL; e_ptr1 = e_ptr1->next(), e_cnt1++) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   477
      if (need_entry_verify) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   478
        VerifyRetTypes ret = verify_entry(bkt1, e_cnt1, e_ptr1,
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   479
                                          _verify_quietly);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   480
        if (ret == _verify_fail_done) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   481
          // cannot use the current entry to compare against other entries
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   482
          continue;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   483
        }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   484
      }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   485
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   486
      for (int bkt2 = bkt1; bkt2 < the_table()->table_size(); bkt2++) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   487
        HashtableEntry<oop, mtSymbol>* e_ptr2 = the_table()->bucket(bkt2);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   488
        int e_cnt2;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   489
        for (e_cnt2 = 0; e_ptr2 != NULL; e_ptr2 = e_ptr2->next(), e_cnt2++) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   490
          if (bkt1 == bkt2 && e_cnt2 <= e_cnt1) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   491
            // skip the entries up to and including the one that
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   492
            // we're comparing against
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   493
            continue;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   494
          }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   495
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   496
          if (need_entry_verify) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   497
            VerifyRetTypes ret = verify_entry(bkt2, e_cnt2, e_ptr2,
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   498
                                              _verify_quietly);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   499
            if (ret == _verify_fail_done) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   500
              // cannot compare against this entry
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   501
              continue;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   502
            }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   503
          }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   504
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   505
          // compare two entries, report and count any failures:
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   506
          if (compare_entries(bkt1, e_cnt1, e_ptr1, bkt2, e_cnt2, e_ptr2)
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   507
              != _verify_pass) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   508
            fail_cnt++;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   509
          }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   510
        }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   511
      }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   512
    }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   513
  }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   514
  return fail_cnt;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   515
}
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   516
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   517
// Create a new table and using alternate hash code, populate the new table
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   518
// with the existing strings.   Set flag to use the alternate hash code afterwards.
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   519
void StringTable::rehash_table() {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   520
  assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   521
  // This should never happen with -Xshare:dump but it might in testing mode.
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   522
  if (DumpSharedSpaces) return;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   523
  StringTable* new_table = new StringTable();
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   524
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   525
  // Rehash the table
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   526
  the_table()->move_to(new_table);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   527
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   528
  // Delete the table and buckets (entries are reused in new table).
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   529
  delete _the_table;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   530
  // Don't check if we need rehashing until the table gets unbalanced again.
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   531
  // Then rehash with a new global seed.
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   532
  _needs_rehashing = false;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   533
  _the_table = new_table;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   534
}