hotspot/src/share/vm/classfile/stringTable.cpp
author alanb
Thu, 17 Mar 2016 19:04:01 +0000
changeset 36508 5f9eee6b383b
parent 36187 1d61b06a3ae1
child 37172 ff4d69314a4c
permissions -rw-r--r--
8142968: Module System implementation Summary: Initial integration of JEP 200, JEP 260, JEP 261, and JEP 282 Reviewed-by: acorn, ccheung, coleenp, ctornqvi, dholmes, dsimms, gtriantafill, iklam, jiangli, mgronlun, mseledtsov, cjplummer, sspitsyn, stefank, twisti, hseigel, lfoltan, alanb, mchung, dfazunen Contributed-by: alan.bateman@oracle.com, alex.buckley@oracle.com, jonathan.gibbons@oracle.com, karen.kinnear@oracle.com, mandy.chung@oracle.com, mark.reinhold@oracle.com, harold.seigel@oracle.com, lois.foltan@oracle.com, calvin.cheung@oracle.com, christian.tornqvist@oracle.com, erik.joelsson@oracle.com, george.triantafillou@oracle.com, igor.ignatyev@oracle.com, ioi.lam@oracle.com, james.laskey@oracle.com, jean-francois.denise@oracle.com, jiangli.zhou@oracle.com, markus.gronlund@oracle.com, serguei.spitsyn@oracle.com, staffan.larsen@oracle.com, sundararajan.athijegannathan@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
     1
/*
35498
392b50de06c6 8146401: Clean up oop.hpp: add inline directives and fix header files
goetz
parents: 34659
diff changeset
     2
 * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
24426
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"
34659
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents: 33628
diff changeset
    27
#include "classfile/compactHashtable.inline.hpp"
35498
392b50de06c6 8146401: Clean up oop.hpp: add inline directives and fix header files
goetz
parents: 34659
diff changeset
    28
#include "classfile/javaClasses.inline.hpp"
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    29
#include "classfile/stringTable.hpp"
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    30
#include "classfile/systemDictionary.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 29081
diff changeset
    31
#include "gc/shared/collectedHeap.inline.hpp"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 29081
diff changeset
    32
#include "gc/shared/gcLocker.inline.hpp"
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    33
#include "memory/allocation.inline.hpp"
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    34
#include "memory/filemap.hpp"
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    35
#include "oops/oop.inline.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"
27684
e0391b2bf625 8064581: Move INCLUDE_ALL_GCS include section to the end of the include list
stefank
parents: 26421
diff changeset
    39
#include "utilities/macros.hpp"
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    40
#if INCLUDE_ALL_GCS
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
    41
#include "gc/g1/g1CollectedHeap.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 29081
diff changeset
    42
#include "gc/g1/g1SATBCardTableModRefBS.hpp"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 29081
diff changeset
    43
#include "gc/g1/g1StringDedup.hpp"
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    44
#endif
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    45
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    46
// the number of buckets a thread claims
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    47
const int ClaimChunkSize = 32;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    48
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    49
#ifdef ASSERT
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    50
class StableMemoryChecker : public StackObj {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    51
  enum { _bufsize = wordSize*4 };
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    52
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    53
  address _region;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    54
  jint    _size;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    55
  u1      _save_buf[_bufsize];
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    56
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    57
  int sample(u1* save_buf) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    58
    if (_size <= _bufsize) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    59
      memcpy(save_buf, _region, _size);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    60
      return _size;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    61
    } else {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    62
      // copy head and tail
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    63
      memcpy(&save_buf[0],          _region,                      _bufsize/2);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    64
      memcpy(&save_buf[_bufsize/2], _region + _size - _bufsize/2, _bufsize/2);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    65
      return (_bufsize/2)*2;
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
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    69
 public:
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    70
  StableMemoryChecker(const void* region, jint size) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    71
    _region = (address) region;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    72
    _size   = size;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    73
    sample(_save_buf);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    74
  }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    75
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    76
  bool verify() {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    77
    u1 check_buf[sizeof(_save_buf)];
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    78
    int check_size = sample(check_buf);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    79
    return (0 == memcmp(_save_buf, check_buf, check_size));
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    80
  }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    81
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    82
  void set_region(const void* region) { _region = (address) region; }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    83
};
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    84
#endif
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
// --------------------------------------------------------------------------
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    88
StringTable* StringTable::_the_table = NULL;
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
    89
bool StringTable::_ignore_shared_strings = false;
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    90
bool StringTable::_needs_rehashing = false;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    91
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    92
volatile int StringTable::_parallel_claimed_idx = 0;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    93
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
    94
CompactHashtable<oop, char> StringTable::_shared_table;
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
    95
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    96
// Pick hashing algorithm
33628
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 33148
diff changeset
    97
template<typename T>
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 33148
diff changeset
    98
unsigned int StringTable::hash_string(const T* s, int len) {
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    99
  return use_alternate_hashcode() ? AltHashing::murmur3_32(seed(), s, len) :
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   100
                                    java_lang_String::hash_code(s, len);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   101
}
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   102
33628
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 33148
diff changeset
   103
// Explicit instantiation for all supported types.
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 33148
diff changeset
   104
template unsigned int StringTable::hash_string<jchar>(const jchar* s, int len);
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 33148
diff changeset
   105
template unsigned int StringTable::hash_string<jbyte>(const jbyte* s, int len);
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 33148
diff changeset
   106
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   107
oop StringTable::lookup_shared(jchar* name, int len) {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   108
  // java_lang_String::hash_code() was used to compute hash values in the shared table. Don't
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   109
  // use the hash value from StringTable::hash_string() as it might use alternate hashcode.
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   110
  return _shared_table.lookup((const char*)name,
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   111
                              java_lang_String::hash_code(name, len), len);
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   112
}
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   113
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   114
oop StringTable::lookup_in_main_table(int index, jchar* name,
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   115
                                int len, unsigned int hash) {
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   116
  int count = 0;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   117
  for (HashtableEntry<oop, mtSymbol>* l = bucket(index); l != NULL; l = l->next()) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   118
    count++;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   119
    if (l->hash() == hash) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   120
      if (java_lang_String::equals(l->literal(), name, len)) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   121
        return l->literal();
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   122
      }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   123
    }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   124
  }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   125
  // If the bucket size is too deep check if this hash code is insufficient.
26421
37d88e604ad0 8056084: Refactor Hashtable to allow implementations without rehashing support
mgerdin
parents: 25492
diff changeset
   126
  if (count >= rehash_count && !needs_rehashing()) {
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   127
    _needs_rehashing = check_rehash_table(count);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   128
  }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   129
  return NULL;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   130
}
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   131
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   132
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   133
oop StringTable::basic_add(int index_arg, Handle string, jchar* name,
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   134
                           int len, unsigned int hashValue_arg, TRAPS) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   135
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   136
  assert(java_lang_String::equals(string(), name, len),
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   137
         "string must be properly initialized");
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   138
  // Cannot hit a safepoint in this function because the "this" pointer can move.
35492
c8c0273e6b91 8146690: Make all classes in GC follow the naming convention.
david
parents: 34659
diff changeset
   139
  NoSafepointVerifier nsv;
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   140
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   141
  // Check if the symbol table has been rehashed, if so, need to recalculate
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   142
  // the hash value and index before second lookup.
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   143
  unsigned int hashValue;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   144
  int index;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   145
  if (use_alternate_hashcode()) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   146
    hashValue = hash_string(name, len);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   147
    index = hash_to_index(hashValue);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   148
  } else {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   149
    hashValue = hashValue_arg;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   150
    index = index_arg;
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
  // Since look-up was done lock-free, we need to check if another
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   154
  // thread beat us in the race to insert the symbol.
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   155
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   156
  // No need to lookup the shared table from here since the caller (intern()) already did
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   157
  oop test = lookup_in_main_table(index, name, len, hashValue); // calls lookup(u1*, int)
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   158
  if (test != NULL) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   159
    // Entry already added
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   160
    return test;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   161
  }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   162
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   163
  HashtableEntry<oop, mtSymbol>* entry = new_entry(hashValue, string());
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   164
  add_entry(index, entry);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   165
  return string();
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
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   169
oop StringTable::lookup(Symbol* symbol) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   170
  ResourceMark rm;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   171
  int length;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   172
  jchar* chars = symbol->as_unicode(length);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   173
  return lookup(chars, length);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   174
}
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   175
25492
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   176
// Tell the GC that this string was looked up in the StringTable.
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   177
static void ensure_string_alive(oop string) {
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   178
  // A lookup in the StringTable could return an object that was previously
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   179
  // considered dead. The SATB part of G1 needs to get notified about this
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   180
  // potential resurrection, otherwise the marking might not find the object.
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   181
#if INCLUDE_ALL_GCS
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   182
  if (UseG1GC && string != NULL) {
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   183
    G1SATBCardTableModRefBS::enqueue(string);
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   184
  }
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   185
#endif
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   186
}
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   187
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   188
oop StringTable::lookup(jchar* name, int len) {
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   189
  oop string = lookup_shared(name, len);
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   190
  if (string != NULL) {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   191
    return string;
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   192
  }
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   193
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   194
  unsigned int hash = hash_string(name, len);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   195
  int index = the_table()->hash_to_index(hash);
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   196
  string = the_table()->lookup_in_main_table(index, name, len, hash);
25492
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   197
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   198
  ensure_string_alive(string);
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   199
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   200
  return string;
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   201
}
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   202
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   203
oop StringTable::intern(Handle string_or_null, jchar* name,
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   204
                        int len, TRAPS) {
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   205
  oop found_string = lookup_shared(name, len);
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   206
  if (found_string != NULL) {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   207
    return found_string;
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   208
  }
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   209
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   210
  unsigned int hashValue = hash_string(name, len);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   211
  int index = the_table()->hash_to_index(hashValue);
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   212
  found_string = the_table()->lookup_in_main_table(index, name, len, hashValue);
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   213
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   214
  // Found
25492
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   215
  if (found_string != NULL) {
36187
1d61b06a3ae1 8149837: String.intern creates morre work than necessary for G1
drwhite
parents: 35898
diff changeset
   216
    if (found_string != string_or_null()) {
1d61b06a3ae1 8149837: String.intern creates morre work than necessary for G1
drwhite
parents: 35898
diff changeset
   217
      ensure_string_alive(found_string);
1d61b06a3ae1 8149837: String.intern creates morre work than necessary for G1
drwhite
parents: 35898
diff changeset
   218
    }
25492
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   219
    return found_string;
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   220
  }
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   221
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   222
  debug_only(StableMemoryChecker smc(name, len * sizeof(name[0])));
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   223
  assert(!Universe::heap()->is_in_reserved(name),
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   224
         "proposed name of symbol must be stable");
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   225
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   226
  Handle string;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   227
  // try to reuse the string if possible
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   228
  if (!string_or_null.is_null()) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   229
    string = string_or_null;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   230
  } else {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   231
    string = java_lang_String::create_from_unicode(name, len, CHECK_NULL);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   232
  }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   233
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   234
#if INCLUDE_ALL_GCS
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   235
  if (G1StringDedup::is_enabled()) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   236
    // Deduplicate the string before it is interned. Note that we should never
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   237
    // deduplicate a string after it has been interned. Doing so will counteract
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   238
    // compiler optimizations done on e.g. interned string literals.
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   239
    G1StringDedup::deduplicate(string());
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   240
  }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   241
#endif
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   242
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   243
  // Grab the StringTable_lock before getting the_table() because it could
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   244
  // change at safepoint.
25492
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   245
  oop added_or_found;
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   246
  {
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   247
    MutexLocker ml(StringTable_lock, THREAD);
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   248
    // Otherwise, add to symbol to table
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   249
    added_or_found = the_table()->basic_add(index, string, name, len,
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   250
                                  hashValue, CHECK_NULL);
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   251
  }
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   252
36187
1d61b06a3ae1 8149837: String.intern creates morre work than necessary for G1
drwhite
parents: 35898
diff changeset
   253
  if (added_or_found != string()) {
1d61b06a3ae1 8149837: String.intern creates morre work than necessary for G1
drwhite
parents: 35898
diff changeset
   254
    ensure_string_alive(added_or_found);
1d61b06a3ae1 8149837: String.intern creates morre work than necessary for G1
drwhite
parents: 35898
diff changeset
   255
  }
25492
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   256
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   257
  return added_or_found;
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   258
}
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   259
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   260
oop StringTable::intern(Symbol* symbol, TRAPS) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   261
  if (symbol == NULL) return NULL;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   262
  ResourceMark rm(THREAD);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   263
  int length;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   264
  jchar* chars = symbol->as_unicode(length);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   265
  Handle string;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   266
  oop result = intern(string, chars, length, CHECK_NULL);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   267
  return result;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   268
}
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   269
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   270
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   271
oop StringTable::intern(oop string, TRAPS)
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   272
{
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   273
  if (string == NULL) return NULL;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   274
  ResourceMark rm(THREAD);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   275
  int length;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   276
  Handle h_string (THREAD, string);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   277
  jchar* chars = java_lang_String::as_unicode_string(string, length, CHECK_NULL);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   278
  oop result = intern(h_string, chars, length, CHECK_NULL);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   279
  return result;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   280
}
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   281
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   282
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   283
oop StringTable::intern(const char* utf8_string, TRAPS) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   284
  if (utf8_string == NULL) return NULL;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   285
  ResourceMark rm(THREAD);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   286
  int length = UTF8::unicode_length(utf8_string);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   287
  jchar* chars = NEW_RESOURCE_ARRAY(jchar, length);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   288
  UTF8::convert_to_unicode(utf8_string, chars, length);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   289
  Handle string;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   290
  oop result = intern(string, chars, length, CHECK_NULL);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   291
  return result;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   292
}
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   293
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   294
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
   295
  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
   296
}
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   297
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   298
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
   299
  // Readers of the table are unlocked, so we should only be removing
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   300
  // entries at a safepoint.
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   301
  assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   302
  const int limit = the_table()->table_size();
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   303
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   304
  for (;;) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   305
    // Grab next set of buckets to scan
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   306
    int start_idx = Atomic::add(ClaimChunkSize, &_parallel_claimed_idx) - ClaimChunkSize;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   307
    if (start_idx >= limit) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   308
      // End of table
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   309
      break;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   310
    }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   311
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   312
    int end_idx = MIN2(limit, start_idx + ClaimChunkSize);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   313
    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
   314
  }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   315
}
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   316
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   317
void StringTable::buckets_oops_do(OopClosure* f, int start_idx, int end_idx) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   318
  const int limit = the_table()->table_size();
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   319
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   320
  assert(0 <= start_idx && start_idx <= limit,
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31345
diff changeset
   321
         "start_idx (%d) is out of bounds", start_idx);
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   322
  assert(0 <= end_idx && end_idx <= limit,
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31345
diff changeset
   323
         "end_idx (%d) is out of bounds", end_idx);
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   324
  assert(start_idx <= end_idx,
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31345
diff changeset
   325
         "Index ordering: start_idx=%d, end_idx=%d",
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31345
diff changeset
   326
         start_idx, end_idx);
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   327
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   328
  for (int i = start_idx; i < end_idx; i += 1) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   329
    HashtableEntry<oop, mtSymbol>* entry = the_table()->bucket(i);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   330
    while (entry != NULL) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   331
      assert(!entry->is_shared(), "CDS not used for the StringTable");
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   332
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   333
      f->do_oop((oop*)entry->literal_addr());
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   334
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   335
      entry = entry->next();
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   336
    }
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
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
   341
  const int limit = the_table()->table_size();
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   342
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   343
  assert(0 <= start_idx && start_idx <= limit,
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31345
diff changeset
   344
         "start_idx (%d) is out of bounds", start_idx);
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   345
  assert(0 <= end_idx && end_idx <= limit,
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31345
diff changeset
   346
         "end_idx (%d) is out of bounds", end_idx);
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   347
  assert(start_idx <= end_idx,
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31345
diff changeset
   348
         "Index ordering: start_idx=%d, end_idx=%d",
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31345
diff changeset
   349
         start_idx, end_idx);
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   350
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   351
  for (int i = start_idx; i < end_idx; ++i) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   352
    HashtableEntry<oop, mtSymbol>** p = the_table()->bucket_addr(i);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   353
    HashtableEntry<oop, mtSymbol>* entry = the_table()->bucket(i);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   354
    while (entry != NULL) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   355
      assert(!entry->is_shared(), "CDS not used for the StringTable");
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   356
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   357
      if (is_alive->do_object_b(entry->literal())) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   358
        if (f != NULL) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   359
          f->do_oop((oop*)entry->literal_addr());
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   360
        }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   361
        p = entry->next_addr();
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   362
      } else {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   363
        *p = entry->next();
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   364
        the_table()->free_entry(entry);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   365
        (*removed)++;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   366
      }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   367
      (*processed)++;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   368
      entry = *p;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   369
    }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   370
  }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   371
}
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   372
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   373
void StringTable::oops_do(OopClosure* f) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   374
  buckets_oops_do(f, 0, the_table()->table_size());
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
void StringTable::possibly_parallel_oops_do(OopClosure* f) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   378
  const int limit = the_table()->table_size();
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   379
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   380
  for (;;) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   381
    // Grab next set of buckets to scan
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   382
    int start_idx = Atomic::add(ClaimChunkSize, &_parallel_claimed_idx) - ClaimChunkSize;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   383
    if (start_idx >= limit) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   384
      // End of table
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   385
      break;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   386
    }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   387
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   388
    int end_idx = MIN2(limit, start_idx + ClaimChunkSize);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   389
    buckets_oops_do(f, start_idx, end_idx);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   390
  }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   391
}
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   392
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   393
// This verification is part of Universe::verify() and needs to be quick.
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   394
// See StringTable::verify_and_compare() below for exhaustive verification.
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   395
void StringTable::verify() {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   396
  for (int i = 0; i < the_table()->table_size(); ++i) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   397
    HashtableEntry<oop, mtSymbol>* p = the_table()->bucket(i);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   398
    for ( ; p != NULL; p = p->next()) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   399
      oop s = p->literal();
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   400
      guarantee(s != NULL, "interned string is NULL");
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   401
      unsigned int h = java_lang_String::hash_string(s);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   402
      guarantee(p->hash() == h, "broken hash in string table entry");
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   403
      guarantee(the_table()->hash_to_index(h) == i,
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   404
                "wrong index in string table");
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   405
    }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   406
  }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   407
}
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   408
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   409
void StringTable::dump(outputStream* st, bool verbose) {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   410
  if (!verbose) {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   411
    the_table()->dump_table(st, "StringTable");
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   412
  } else {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   413
    Thread* THREAD = Thread::current();
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   414
    st->print_cr("VERSION: 1.1");
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   415
    for (int i = 0; i < the_table()->table_size(); ++i) {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   416
      HashtableEntry<oop, mtSymbol>* p = the_table()->bucket(i);
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   417
      for ( ; p != NULL; p = p->next()) {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   418
        oop s = p->literal();
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   419
        typeArrayOop value  = java_lang_String::value(s);
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   420
        int          length = java_lang_String::length(s);
33628
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 33148
diff changeset
   421
        bool      is_latin1 = java_lang_String::is_latin1(s);
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   422
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   423
        if (length <= 0) {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   424
          st->print("%d: ", length);
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   425
        } else {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   426
          ResourceMark rm(THREAD);
33628
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 33148
diff changeset
   427
          int utf8_length;
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 33148
diff changeset
   428
          char* utf8_string;
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 33148
diff changeset
   429
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 33148
diff changeset
   430
          if (!is_latin1) {
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 33148
diff changeset
   431
            jchar* chars = value->char_at_addr(0);
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 33148
diff changeset
   432
            utf8_length = UNICODE::utf8_length(chars, length);
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 33148
diff changeset
   433
            utf8_string = UNICODE::as_utf8(chars, length);
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 33148
diff changeset
   434
          } else {
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 33148
diff changeset
   435
            jbyte* bytes = value->byte_at_addr(0);
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 33148
diff changeset
   436
            utf8_length = UNICODE::utf8_length(bytes, length);
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 33148
diff changeset
   437
            utf8_string = UNICODE::as_utf8(bytes, length);
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 33148
diff changeset
   438
          }
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   439
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   440
          st->print("%d: ", utf8_length);
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   441
          HashtableTextDump::put_utf8(st, utf8_string, utf8_length);
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   442
        }
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   443
        st->cr();
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   444
      }
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   445
    }
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   446
  }
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   447
}
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   448
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   449
StringTable::VerifyRetTypes StringTable::compare_entries(
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   450
                                      int bkt1, int e_cnt1,
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   451
                                      HashtableEntry<oop, mtSymbol>* e_ptr1,
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   452
                                      int bkt2, int e_cnt2,
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   453
                                      HashtableEntry<oop, mtSymbol>* e_ptr2) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   454
  // These entries are sanity checked by verify_and_compare_entries()
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   455
  // before this function is called.
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   456
  oop str1 = e_ptr1->literal();
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   457
  oop str2 = e_ptr2->literal();
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   458
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   459
  if (str1 == str2) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   460
    tty->print_cr("ERROR: identical oop values (0x" PTR_FORMAT ") "
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   461
                  "in entry @ bucket[%d][%d] and entry @ bucket[%d][%d]",
33148
68fa8b6c4340 8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 33105
diff changeset
   462
                  p2i(str1), bkt1, e_cnt1, bkt2, e_cnt2);
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   463
    return _verify_fail_continue;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   464
  }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   465
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   466
  if (java_lang_String::equals(str1, str2)) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   467
    tty->print_cr("ERROR: identical String values in entry @ "
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   468
                  "bucket[%d][%d] and entry @ bucket[%d][%d]",
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   469
                  bkt1, e_cnt1, bkt2, e_cnt2);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   470
    return _verify_fail_continue;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   471
  }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   472
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   473
  return _verify_pass;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   474
}
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   475
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   476
StringTable::VerifyRetTypes StringTable::verify_entry(int bkt, int e_cnt,
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   477
                                      HashtableEntry<oop, mtSymbol>* e_ptr,
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   478
                                      StringTable::VerifyMesgModes mesg_mode) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   479
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   480
  VerifyRetTypes ret = _verify_pass;  // be optimistic
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   481
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   482
  oop str = e_ptr->literal();
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   483
  if (str == NULL) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   484
    if (mesg_mode == _verify_with_mesgs) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   485
      tty->print_cr("ERROR: NULL oop value in entry @ bucket[%d][%d]", bkt,
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   486
                    e_cnt);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   487
    }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   488
    // NULL oop means no more verifications are possible
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   489
    return _verify_fail_done;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   490
  }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   491
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   492
  if (str->klass() != SystemDictionary::String_klass()) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   493
    if (mesg_mode == _verify_with_mesgs) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   494
      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
   495
                    bkt, e_cnt);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   496
    }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   497
    // not a String means no more verifications are possible
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   498
    return _verify_fail_done;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   499
  }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   500
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   501
  unsigned int h = java_lang_String::hash_string(str);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   502
  if (e_ptr->hash() != h) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   503
    if (mesg_mode == _verify_with_mesgs) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   504
      tty->print_cr("ERROR: broken hash value in entry @ bucket[%d][%d], "
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   505
                    "bkt_hash=%d, str_hash=%d", bkt, e_cnt, e_ptr->hash(), h);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   506
    }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   507
    ret = _verify_fail_continue;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   508
  }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   509
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   510
  if (the_table()->hash_to_index(h) != bkt) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   511
    if (mesg_mode == _verify_with_mesgs) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   512
      tty->print_cr("ERROR: wrong index value for entry @ bucket[%d][%d], "
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   513
                    "str_hash=%d, hash_to_index=%d", bkt, e_cnt, h,
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   514
                    the_table()->hash_to_index(h));
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   515
    }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   516
    ret = _verify_fail_continue;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   517
  }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   518
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   519
  return ret;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   520
}
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   521
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   522
// See StringTable::verify() above for the quick verification that is
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   523
// part of Universe::verify(). This verification is exhaustive and
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   524
// reports on every issue that is found. StringTable::verify() only
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   525
// reports on the first issue that is found.
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   526
//
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   527
// StringTable::verify_entry() checks:
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   528
// - oop value != NULL (same as verify())
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   529
// - oop value is a String
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   530
// - hash(String) == hash in entry (same as verify())
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   531
// - index for hash == index of entry (same as verify())
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   532
//
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   533
// StringTable::compare_entries() checks:
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   534
// - oops are unique across all entries
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   535
// - String values are unique across all entries
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   536
//
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   537
int StringTable::verify_and_compare_entries() {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   538
  assert(StringTable_lock->is_locked(), "sanity check");
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   539
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   540
  int  fail_cnt = 0;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   541
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   542
  // first, verify all the entries individually:
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   543
  for (int bkt = 0; bkt < the_table()->table_size(); bkt++) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   544
    HashtableEntry<oop, mtSymbol>* e_ptr = the_table()->bucket(bkt);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   545
    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
   546
      VerifyRetTypes ret = verify_entry(bkt, e_cnt, e_ptr, _verify_with_mesgs);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   547
      if (ret != _verify_pass) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   548
        fail_cnt++;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   549
      }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   550
    }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   551
  }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   552
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   553
  // Optimization: if the above check did not find any failures, then
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   554
  // the comparison loop below does not need to call verify_entry()
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   555
  // before calling compare_entries(). If there were failures, then we
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   556
  // 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
   557
  // compare_entries() safely. When we call verify_entry() in the loop
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   558
  // below, we do so quietly to void duplicate messages and we don't
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   559
  // increment fail_cnt because the failures have already been counted.
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   560
  bool need_entry_verify = (fail_cnt != 0);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   561
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   562
  // second, verify all entries relative to each other:
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   563
  for (int bkt1 = 0; bkt1 < the_table()->table_size(); bkt1++) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   564
    HashtableEntry<oop, mtSymbol>* e_ptr1 = the_table()->bucket(bkt1);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   565
    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
   566
      if (need_entry_verify) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   567
        VerifyRetTypes ret = verify_entry(bkt1, e_cnt1, e_ptr1,
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   568
                                          _verify_quietly);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   569
        if (ret == _verify_fail_done) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   570
          // cannot use the current entry to compare against other entries
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   571
          continue;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   572
        }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   573
      }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   574
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   575
      for (int bkt2 = bkt1; bkt2 < the_table()->table_size(); bkt2++) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   576
        HashtableEntry<oop, mtSymbol>* e_ptr2 = the_table()->bucket(bkt2);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   577
        int e_cnt2;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   578
        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
   579
          if (bkt1 == bkt2 && e_cnt2 <= e_cnt1) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   580
            // skip the entries up to and including the one that
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   581
            // we're comparing against
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   582
            continue;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   583
          }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   584
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   585
          if (need_entry_verify) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   586
            VerifyRetTypes ret = verify_entry(bkt2, e_cnt2, e_ptr2,
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   587
                                              _verify_quietly);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   588
            if (ret == _verify_fail_done) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   589
              // cannot compare against this entry
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   590
              continue;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   591
            }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   592
          }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   593
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   594
          // compare two entries, report and count any failures:
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   595
          if (compare_entries(bkt1, e_cnt1, e_ptr1, bkt2, e_cnt2, e_ptr2)
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   596
              != _verify_pass) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   597
            fail_cnt++;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   598
          }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   599
        }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   600
      }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   601
    }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   602
  }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   603
  return fail_cnt;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   604
}
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   605
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   606
// Create a new table and using alternate hash code, populate the new table
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   607
// with the existing strings.   Set flag to use the alternate hash code afterwards.
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   608
void StringTable::rehash_table() {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   609
  assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   610
  // This should never happen with -Xshare:dump but it might in testing mode.
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   611
  if (DumpSharedSpaces) return;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   612
  StringTable* new_table = new StringTable();
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   613
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   614
  // Rehash the table
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   615
  the_table()->move_to(new_table);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   616
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   617
  // Delete the table and buckets (entries are reused in new table).
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   618
  delete _the_table;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   619
  // Don't check if we need rehashing until the table gets unbalanced again.
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   620
  // Then rehash with a new global seed.
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   621
  _needs_rehashing = false;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   622
  _the_table = new_table;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   623
}
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   624
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   625
// Utility for dumping strings
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   626
StringtableDCmd::StringtableDCmd(outputStream* output, bool heap) :
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   627
                                 DCmdWithParser(output, heap),
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   628
  _verbose("-verbose", "Dump the content of each string in the table",
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   629
           "BOOLEAN", false, "false") {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   630
  _dcmdparser.add_dcmd_option(&_verbose);
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   631
}
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   632
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   633
void StringtableDCmd::execute(DCmdSource source, TRAPS) {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   634
  VM_DumpHashtable dumper(output(), VM_DumpHashtable::DumpStrings,
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   635
                         _verbose.value());
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   636
  VMThread::execute(&dumper);
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   637
}
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   638
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   639
int StringtableDCmd::num_arguments() {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   640
  ResourceMark rm;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   641
  StringtableDCmd* dcmd = new StringtableDCmd(NULL, false);
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   642
  if (dcmd != NULL) {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   643
    DCmdMark mark(dcmd);
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   644
    return dcmd->_dcmdparser.num_arguments();
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   645
  } else {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   646
    return 0;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   647
  }
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   648
}
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   649
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   650
// Sharing
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   651
bool StringTable::copy_shared_string(GrowableArray<MemRegion> *string_space,
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   652
                                     CompactHashtableWriter* ch_table) {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   653
#if INCLUDE_CDS && INCLUDE_ALL_GCS && defined(_LP64) && !defined(_WINDOWS)
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   654
  assert(UseG1GC, "Only support G1 GC");
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   655
  assert(UseCompressedOops && UseCompressedClassPointers,
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   656
         "Only support UseCompressedOops and UseCompressedClassPointers enabled");
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   657
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   658
  Thread* THREAD = Thread::current();
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   659
  G1CollectedHeap::heap()->begin_archive_alloc_range();
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   660
  for (int i = 0; i < the_table()->table_size(); ++i) {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   661
    HashtableEntry<oop, mtSymbol>* bucket = the_table()->bucket(i);
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   662
    for ( ; bucket != NULL; bucket = bucket->next()) {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   663
      oop s = bucket->literal();
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   664
      unsigned int hash = java_lang_String::hash_code(s);
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   665
      if (hash == 0) {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   666
        continue;
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   667
      }
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   668
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   669
      // allocate the new 'value' array first
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   670
      typeArrayOop v = java_lang_String::value(s);
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   671
      int v_len = v->size();
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   672
      typeArrayOop new_v;
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   673
      if (G1CollectedHeap::heap()->is_archive_alloc_too_large(v_len)) {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   674
        continue; // skip the current String. The 'value' array is too large to handle
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   675
      } else {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   676
        new_v = (typeArrayOop)G1CollectedHeap::heap()->archive_mem_allocate(v_len);
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   677
        if (new_v == NULL) {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   678
          return false; // allocation failed
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   679
        }
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   680
      }
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   681
      // now allocate the new String object
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   682
      int s_len = s->size();
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   683
      oop new_s = (oop)G1CollectedHeap::heap()->archive_mem_allocate(s_len);
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   684
      if (new_s == NULL) {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   685
        return false;
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   686
      }
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   687
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   688
      s->identity_hash();
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   689
      v->identity_hash();
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   690
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   691
      // copy the objects' data
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   692
      Copy::aligned_disjoint_words((HeapWord*)s, (HeapWord*)new_s, s_len);
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   693
      Copy::aligned_disjoint_words((HeapWord*)v, (HeapWord*)new_v, v_len);
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   694
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   695
      // adjust the pointer to the 'value' field in the new String oop. Also pre-compute and set the
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   696
      // 'hash' field. That avoids "write" to the shared strings at runtime by the deduplication process.
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   697
      java_lang_String::set_value_raw(new_s, new_v);
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   698
      if (java_lang_String::hash(new_s) == 0) {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   699
        java_lang_String::set_hash(new_s, hash);
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   700
      }
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   701
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   702
      // add to the compact table
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   703
      ch_table->add(hash, new_s);
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   704
    }
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   705
  }
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   706
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   707
  G1CollectedHeap::heap()->end_archive_alloc_range(string_space, os::vm_allocation_granularity());
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   708
  assert(string_space->length() <= 2, "sanity");
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   709
#endif
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   710
  return true;
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   711
}
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   712
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   713
bool StringTable::copy_compact_table(char** top, char *end, GrowableArray<MemRegion> *string_space,
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   714
                                     size_t* space_size) {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   715
#if INCLUDE_CDS && defined(_LP64) && !defined(_WINDOWS)
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   716
  if (!(UseG1GC && UseCompressedOops && UseCompressedClassPointers)) {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   717
    if (PrintSharedSpaces) {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   718
      tty->print_cr("Shared strings are excluded from the archive as UseG1GC, "
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   719
                    "UseCompressedOops and UseCompressedClassPointers are required.");
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   720
    }
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   721
    return true;
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   722
  }
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   723
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   724
  CompactHashtableWriter ch_table(CompactHashtable<oop, char>::_string_table,
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   725
                                  the_table()->number_of_entries(),
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   726
                                  &MetaspaceShared::stats()->string);
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   727
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   728
  // Copy the interned strings into the "string space" within the java heap
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   729
  if (!copy_shared_string(string_space, &ch_table)) {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   730
    return false;
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   731
  }
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   732
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   733
  for (int i = 0; i < string_space->length(); i++) {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   734
    *space_size += string_space->at(i).byte_size();
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   735
  }
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   736
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   737
  // Now dump the compact table
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   738
  if (*top + ch_table.get_required_bytes() > end) {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   739
    // not enough space left
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   740
    return false;
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   741
  }
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   742
  ch_table.dump(top, end);
35898
ddc274f0052f 8145628: hotspot metadata classes shouldn't use HeapWordSize or heap related macros like align_object_size
coleenp
parents: 35499
diff changeset
   743
  *top = (char*)align_ptr_up(*top, sizeof(void*));
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   744
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   745
#endif
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   746
  return true;
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   747
}
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   748
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   749
void StringTable::shared_oops_do(OopClosure* f) {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   750
#if INCLUDE_CDS && defined(_LP64) && !defined(_WINDOWS)
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   751
  _shared_table.oops_do(f);
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   752
#endif
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   753
}
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   754
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   755
const char* StringTable::init_shared_table(FileMapInfo *mapinfo, char *buffer) {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   756
#if INCLUDE_CDS && defined(_LP64) && !defined(_WINDOWS)
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   757
  if (mapinfo->space_capacity(MetaspaceShared::first_string) == 0) {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   758
    // no shared string data
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   759
    return buffer;
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   760
  }
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   761
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   762
  // initialize the shared table
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   763
  juint *p = (juint*)buffer;
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   764
  const char* end = _shared_table.init(
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   765
          CompactHashtable<oop, char>::_string_table, (char*)p);
35898
ddc274f0052f 8145628: hotspot metadata classes shouldn't use HeapWordSize or heap related macros like align_object_size
coleenp
parents: 35499
diff changeset
   766
  const char* aligned_end = (const char*)align_ptr_up(end, sizeof(void*));
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   767
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   768
  if (_ignore_shared_strings) {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   769
    _shared_table.reset();
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   770
  }
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   771
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   772
  return aligned_end;
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   773
#endif
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   774
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   775
  return buffer;
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   776
}