src/hotspot/share/classfile/stringTable.cpp
author jiangli
Tue, 09 Oct 2018 15:58:07 -0400
changeset 52062 8dbf1a13af49
parent 52047 7bc8b456e5ac
child 52402 72d4e10305b9
permissions -rw-r--r--
8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp Summary: Restructure and cleanup java heap object archiving code. Reviewed-by: coleenp, iklam
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
     1
/*
49041
44122f767467 8198286: Direct memory accessors in typeArrayOop.hpp should use Access API
eosterlund
parents: 48618
diff changeset
     2
 * Copyright (c) 1997, 2018, 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"
51823
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51796
diff changeset
    27
#include "classfile/compactHashtable.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"
50057
f945444fabc3 8202647: Add deduplicate_string function to CollectedHeap
stefank
parents: 49982
diff changeset
    31
#include "gc/shared/collectedHeap.hpp"
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
    32
#include "gc/shared/oopStorage.inline.hpp"
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
    33
#include "gc/shared/oopStorageParState.inline.hpp"
46522
86b13b03a053 8176132: -XX:+PrintSharedSpaces should be converted to use Unified Logging.
rprotacio
parents: 46488
diff changeset
    34
#include "logging/log.hpp"
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
    35
#include "logging/logStream.hpp"
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    36
#include "memory/allocation.inline.hpp"
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    37
#include "memory/filemap.hpp"
51823
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51796
diff changeset
    38
#include "memory/heapShared.inline.hpp"
37248
11a660dbbb8e 8132524: Missing includes to resourceArea.hpp
jprovino
parents: 37172
diff changeset
    39
#include "memory/resourceArea.hpp"
50057
f945444fabc3 8202647: Add deduplicate_string function to CollectedHeap
stefank
parents: 49982
diff changeset
    40
#include "memory/universe.hpp"
48618
688e5cbd0b91 8192003: Refactor weak references in StringTable to use the Access API
eosterlund
parents: 47216
diff changeset
    41
#include "oops/access.inline.hpp"
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    42
#include "oops/oop.inline.hpp"
49041
44122f767467 8198286: Direct memory accessors in typeArrayOop.hpp should use Access API
eosterlund
parents: 48618
diff changeset
    43
#include "oops/typeArrayOop.inline.hpp"
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
    44
#include "oops/weakHandle.inline.hpp"
40655
9f644073d3a0 8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents: 38647
diff changeset
    45
#include "runtime/atomic.hpp"
49393
93fe2fc5c093 8199472: Fix non-PCH build after JDK-8199319
simonis
parents: 49329
diff changeset
    46
#include "runtime/handles.inline.hpp"
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    47
#include "runtime/mutexLocker.hpp"
49594
898ef81cbc0e 8200106: Move NoSafepointVerifier out from gcLocker.hpp
stefank
parents: 49393
diff changeset
    48
#include "runtime/safepointVerifiers.hpp"
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
    49
#include "runtime/timerTrace.hpp"
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
    50
#include "runtime/interfaceSupport.inline.hpp"
46742
24ec8a039c90 8184994: Add Dictionary size logging and jcmd
coleenp
parents: 46522
diff changeset
    51
#include "services/diagnosticCommand.hpp"
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
    52
#include "utilities/concurrentHashTable.inline.hpp"
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
    53
#include "utilities/concurrentHashTableTasks.inline.hpp"
27684
e0391b2bf625 8064581: Move INCLUDE_ALL_GCS include section to the end of the include list
stefank
parents: 26421
diff changeset
    54
#include "utilities/macros.hpp"
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    55
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
    56
// We prefer short chains of avg 2
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
    57
#define PREF_AVG_LIST_LEN   2
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
    58
// 2^24 is max size
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
    59
#define END_SIZE           24
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
    60
// If a chain gets to 32 something might be wrong
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
    61
#define REHASH_LEN         32
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
    62
// If we have as many dead items as 50% of the number of bucket
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
    63
#define CLEAN_DEAD_HIGH_WATER_MARK 0.5
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    64
51823
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51796
diff changeset
    65
#if INCLUDE_CDS_JAVA_HEAP
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51796
diff changeset
    66
inline oop read_string_from_compact_hashtable(address base_address, u4 offset) {
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51796
diff changeset
    67
  assert(sizeof(narrowOop) == sizeof(offset), "must be");
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51796
diff changeset
    68
  narrowOop v = (narrowOop)offset;
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51796
diff changeset
    69
  return HeapShared::decode_from_archive(v);
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51796
diff changeset
    70
}
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51796
diff changeset
    71
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51796
diff changeset
    72
static CompactHashtable<
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51796
diff changeset
    73
  const jchar*, oop,
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51796
diff changeset
    74
  read_string_from_compact_hashtable,
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51796
diff changeset
    75
  java_lang_String::equals
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51796
diff changeset
    76
> _shared_table;
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51796
diff changeset
    77
#endif
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51796
diff changeset
    78
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    79
// --------------------------------------------------------------------------
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    80
StringTable* StringTable::_the_table = NULL;
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51334
diff changeset
    81
volatile bool StringTable::_shared_string_mapped = false;
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51334
diff changeset
    82
volatile bool StringTable::_alt_hash = false;
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
    83
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
    84
static juint murmur_seed = 0;
44323
1566bea4793a 8176593: Throwable::getStackTrace performance regression
redestad
parents: 42057
diff changeset
    85
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
    86
uintx hash_string(const jchar* s, int len, bool useAlt) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
    87
  return  useAlt ?
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
    88
    AltHashing::murmur3_32(murmur_seed, s, len) :
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
    89
    java_lang_String::hash_code(s, len);
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
    90
}
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
    91
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
    92
class StringTableConfig : public StringTableHash::BaseConfig {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
    93
 private:
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
    94
 public:
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
    95
  static uintx get_hash(WeakHandle<vm_string_table_data> const& value,
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
    96
                        bool* is_dead) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
    97
    EXCEPTION_MARK;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
    98
    oop val_oop = value.peek();
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
    99
    if (val_oop == NULL) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   100
      *is_dead = true;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   101
      return 0;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   102
    }
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   103
    *is_dead = false;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   104
    ResourceMark rm(THREAD);
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   105
    // All String oops are hashed as unicode
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   106
    int length;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   107
    jchar* chars = java_lang_String::as_unicode_string(val_oop, length, THREAD);
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   108
    if (chars != NULL) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   109
      return hash_string(chars, length, StringTable::_alt_hash);
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   110
    }
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   111
    vm_exit_out_of_memory(length, OOM_MALLOC_ERROR, "get hash from oop");
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   112
    return 0;
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   113
  }
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   114
  // We use default allocation/deallocation but counted
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   115
  static void* allocate_node(size_t size,
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   116
                             WeakHandle<vm_string_table_data> const& value) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   117
    StringTable::item_added();
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   118
    return StringTableHash::BaseConfig::allocate_node(size, value);
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   119
  }
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   120
  static void free_node(void* memory,
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   121
                        WeakHandle<vm_string_table_data> const& value) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   122
    value.release();
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   123
    StringTableHash::BaseConfig::free_node(memory, value);
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   124
    StringTable::item_removed();
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   125
  }
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   126
};
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   127
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   128
class StringTableLookupJchar : StackObj {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   129
 private:
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   130
  Thread* _thread;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   131
  uintx _hash;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   132
  int _len;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   133
  const jchar* _str;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   134
  Handle _found;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   135
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   136
 public:
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   137
  StringTableLookupJchar(Thread* thread, uintx hash, const jchar* key, int len)
51334
cc2c79d22508 8208671: Runtime, JFR, Serviceability changes to allow enabling -Wreorder
tschatzl
parents: 50951
diff changeset
   138
    : _thread(thread), _hash(hash), _len(len), _str(key) {
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   139
  }
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   140
  uintx get_hash() const {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   141
    return _hash;
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   142
  }
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   143
  bool equals(WeakHandle<vm_string_table_data>* value, bool* is_dead) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   144
    oop val_oop = value->peek();
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   145
    if (val_oop == NULL) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   146
      // dead oop, mark this hash dead for cleaning
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   147
      *is_dead = true;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   148
      return false;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   149
    }
51823
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51796
diff changeset
   150
    bool equals = java_lang_String::equals(val_oop, _str, _len);
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   151
    if (!equals) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   152
      return false;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   153
    }
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   154
    // Need to resolve weak handle and Handleize through possible safepoint.
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   155
     _found = Handle(_thread, value->resolve());
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   156
    return true;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   157
  }
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   158
};
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   159
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   160
class StringTableLookupOop : public StackObj {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   161
 private:
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   162
  Thread* _thread;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   163
  uintx _hash;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   164
  Handle _find;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   165
  Handle _found;  // Might be a different oop with the same value that's already
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   166
                  // in the table, which is the point.
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   167
 public:
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   168
  StringTableLookupOop(Thread* thread, uintx hash, Handle handle)
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   169
    : _thread(thread), _hash(hash), _find(handle) { }
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   170
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   171
  uintx get_hash() const {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   172
    return _hash;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   173
  }
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   174
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   175
  bool equals(WeakHandle<vm_string_table_data>* value, bool* is_dead) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   176
    oop val_oop = value->peek();
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   177
    if (val_oop == NULL) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   178
      // dead oop, mark this hash dead for cleaning
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   179
      *is_dead = true;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   180
      return false;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   181
    }
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   182
    bool equals = java_lang_String::equals(_find(), val_oop);
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   183
    if (!equals) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   184
      return false;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   185
    }
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   186
    // Need to resolve weak handle and Handleize through possible safepoint.
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   187
    _found = Handle(_thread, value->resolve());
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   188
    return true;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   189
  }
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   190
};
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   191
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51334
diff changeset
   192
static size_t ceil_log2(size_t val) {
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   193
  size_t ret;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   194
  for (ret = 1; ((size_t)1 << ret) < val; ++ret);
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   195
  return ret;
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   196
}
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   197
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   198
StringTable::StringTable() : _local_table(NULL), _current_size(0), _has_work(0),
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51334
diff changeset
   199
  _needs_rehashing(false), _weak_handles(NULL), _items_count(0), _uncleaned_items_count(0) {
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   200
  _weak_handles = new OopStorage("StringTable weak",
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   201
                                 StringTableWeakAlloc_lock,
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   202
                                 StringTableWeakActive_lock);
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51334
diff changeset
   203
  size_t start_size_log_2 = ceil_log2(StringTableSize);
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   204
  _current_size = ((size_t)1) << start_size_log_2;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   205
  log_trace(stringtable)("Start size: " SIZE_FORMAT " (" SIZE_FORMAT ")",
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   206
                         _current_size, start_size_log_2);
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   207
  _local_table = new StringTableHash(start_size_log_2, END_SIZE, REHASH_LEN);
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   208
}
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   209
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   210
size_t StringTable::item_added() {
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51334
diff changeset
   211
  return Atomic::add((size_t)1, &(the_table()->_items_count));
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   212
}
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   213
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51334
diff changeset
   214
size_t StringTable::add_items_count_to_clean(size_t ndead) {
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51334
diff changeset
   215
  size_t total = Atomic::add((size_t)ndead, &(the_table()->_uncleaned_items_count));
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   216
  log_trace(stringtable)(
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   217
     "Uncleaned items:" SIZE_FORMAT " added: " SIZE_FORMAT " total:" SIZE_FORMAT,
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51334
diff changeset
   218
     the_table()->_uncleaned_items_count, ndead, total);
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   219
  return total;
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   220
}
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   221
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   222
void StringTable::item_removed() {
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51334
diff changeset
   223
  Atomic::add((size_t)-1, &(the_table()->_items_count));
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   224
}
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   225
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   226
double StringTable::get_load_factor() {
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51334
diff changeset
   227
  return (double)_items_count/_current_size;
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   228
}
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   229
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   230
double StringTable::get_dead_factor() {
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51334
diff changeset
   231
  return (double)_uncleaned_items_count/_current_size;
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   232
}
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   233
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51334
diff changeset
   234
size_t StringTable::table_size() {
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51334
diff changeset
   235
  return ((size_t)1) << _local_table->get_size_log2(Thread::current());
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   236
}
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   237
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   238
void StringTable::trigger_concurrent_work() {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   239
  MutexLockerEx ml(Service_lock, Mutex::_no_safepoint_check_flag);
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   240
  the_table()->_has_work = true;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   241
  Service_lock->notify_all();
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   242
}
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   243
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   244
// Probing
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   245
oop StringTable::lookup(Symbol* symbol) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   246
  ResourceMark rm;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   247
  int length;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   248
  jchar* chars = symbol->as_unicode(length);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   249
  return lookup(chars, length);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   250
}
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   251
51823
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51796
diff changeset
   252
oop StringTable::lookup(const jchar* name, int len) {
44323
1566bea4793a 8176593: Throwable::getStackTrace performance regression
redestad
parents: 42057
diff changeset
   253
  unsigned int hash = java_lang_String::hash_code(name, len);
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   254
  oop string = StringTable::the_table()->lookup_shared(name, len, hash);
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   255
  if (string != NULL) {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   256
    return string;
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   257
  }
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   258
  if (StringTable::_alt_hash) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   259
    hash = hash_string(name, len, true);
44323
1566bea4793a 8176593: Throwable::getStackTrace performance regression
redestad
parents: 42057
diff changeset
   260
  }
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   261
  return StringTable::the_table()->do_lookup(name, len, hash);
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   262
}
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   263
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   264
class StringTableGet : public StackObj {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   265
  Thread* _thread;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   266
  Handle  _return;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   267
 public:
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   268
  StringTableGet(Thread* thread) : _thread(thread) {}
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   269
  void operator()(WeakHandle<vm_string_table_data>* val) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   270
    oop result = val->resolve();
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   271
    assert(result != NULL, "Result should be reachable");
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   272
    _return = Handle(_thread, result);
44323
1566bea4793a 8176593: Throwable::getStackTrace performance regression
redestad
parents: 42057
diff changeset
   273
  }
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   274
  oop get_res_oop() {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   275
    return _return();
25492
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   276
  }
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   277
};
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   278
51823
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51796
diff changeset
   279
oop StringTable::do_lookup(const jchar* name, int len, uintx hash) {
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   280
  Thread* thread = Thread::current();
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   281
  StringTableLookupJchar lookup(thread, hash, name, len);
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   282
  StringTableGet stg(thread);
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   283
  bool rehash_warning;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   284
  _local_table->get(thread, lookup, stg, &rehash_warning);
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   285
  if (rehash_warning) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   286
    _needs_rehashing = true;
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   287
  }
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   288
  return stg.get_res_oop();
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   289
}
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   290
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   291
// Interning
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   292
oop StringTable::intern(Symbol* symbol, TRAPS) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   293
  if (symbol == NULL) return NULL;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   294
  ResourceMark rm(THREAD);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   295
  int length;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   296
  jchar* chars = symbol->as_unicode(length);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   297
  Handle string;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   298
  oop result = intern(string, chars, length, CHECK_NULL);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   299
  return result;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   300
}
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   301
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   302
oop StringTable::intern(oop string, TRAPS) {
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   303
  if (string == NULL) return NULL;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   304
  ResourceMark rm(THREAD);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   305
  int length;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   306
  Handle h_string (THREAD, string);
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   307
  jchar* chars = java_lang_String::as_unicode_string(string, length,
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   308
                                                     CHECK_NULL);
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   309
  oop result = intern(h_string, chars, length, CHECK_NULL);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   310
  return result;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   311
}
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   312
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   313
oop StringTable::intern(const char* utf8_string, TRAPS) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   314
  if (utf8_string == NULL) return NULL;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   315
  ResourceMark rm(THREAD);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   316
  int length = UTF8::unicode_length(utf8_string);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   317
  jchar* chars = NEW_RESOURCE_ARRAY(jchar, length);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   318
  UTF8::convert_to_unicode(utf8_string, chars, length);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   319
  Handle string;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   320
  oop result = intern(string, chars, length, CHECK_NULL);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   321
  return result;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   322
}
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   323
51823
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51796
diff changeset
   324
oop StringTable::intern(Handle string_or_null_h, const jchar* name, int len, TRAPS) {
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   325
  // shared table always uses java_lang_String::hash_code
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   326
  unsigned int hash = java_lang_String::hash_code(name, len);
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   327
  oop found_string = StringTable::the_table()->lookup_shared(name, len, hash);
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   328
  if (found_string != NULL) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   329
    return found_string;
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   330
  }
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   331
  if (StringTable::_alt_hash) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   332
    hash = hash_string(name, len, true);
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   333
  }
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   334
  return StringTable::the_table()->do_intern(string_or_null_h, name, len,
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   335
                                             hash, CHECK_NULL);
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   336
}
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   337
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   338
class StringTableCreateEntry : public StackObj {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   339
 private:
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   340
   Thread* _thread;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   341
   Handle  _return;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   342
   Handle  _store;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   343
 public:
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   344
  StringTableCreateEntry(Thread* thread, Handle store)
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   345
    : _thread(thread), _store(store) {}
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   346
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   347
  WeakHandle<vm_string_table_data> operator()() { // No dups found
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   348
    WeakHandle<vm_string_table_data> wh =
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   349
      WeakHandle<vm_string_table_data>::create(_store);
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   350
    return wh;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   351
  }
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   352
  void operator()(bool inserted, WeakHandle<vm_string_table_data>* val) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   353
    oop result = val->resolve();
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   354
    assert(result != NULL, "Result should be reachable");
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   355
    _return = Handle(_thread, result);
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   356
  }
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   357
  oop get_return() const {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   358
    return _return();
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   359
  }
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   360
};
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   361
51823
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51796
diff changeset
   362
oop StringTable::do_intern(Handle string_or_null_h, const jchar* name,
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   363
                           int len, uintx hash, TRAPS) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   364
  HandleMark hm(THREAD);  // cleanup strings created
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   365
  Handle string_h;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   366
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   367
  if (!string_or_null_h.is_null()) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   368
    string_h = string_or_null_h;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   369
  } else {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   370
    string_h = java_lang_String::create_from_unicode(name, len, CHECK_NULL);
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   371
  }
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   372
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   373
  // Deduplicate the string before it is interned. Note that we should never
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   374
  // deduplicate a string after it has been interned. Doing so will counteract
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   375
  // compiler optimizations done on e.g. interned string literals.
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   376
  Universe::heap()->deduplicate_string(string_h());
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   377
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   378
  assert(java_lang_String::equals(string_h(), name, len),
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   379
         "string must be properly initialized");
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   380
  assert(len == java_lang_String::length(string_h()), "Must be same length");
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   381
  StringTableLookupOop lookup(THREAD, hash, string_h);
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   382
  StringTableCreateEntry stc(THREAD, string_h);
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   383
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   384
  bool rehash_warning;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   385
  _local_table->get_insert_lazy(THREAD, lookup, stc, stc, &rehash_warning);
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   386
  if (rehash_warning) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   387
    _needs_rehashing = true;
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   388
  }
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   389
  return stc.get_return();
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   390
}
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   391
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   392
// GC support
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   393
class StringTableIsAliveCounter : public BoolObjectClosure {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   394
  BoolObjectClosure* _real_boc;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   395
 public:
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   396
  size_t _count;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   397
  size_t _count_total;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   398
  StringTableIsAliveCounter(BoolObjectClosure* boc) : _real_boc(boc), _count(0),
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   399
                                                      _count_total(0) {}
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   400
  bool do_object_b(oop obj) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   401
    bool ret = _real_boc->do_object_b(obj);
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   402
    if (!ret) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   403
      ++_count;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   404
    }
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   405
    ++_count_total;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   406
    return ret;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   407
  }
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   408
};
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   409
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   410
void StringTable::unlink_or_oops_do(BoolObjectClosure* is_alive, OopClosure* f,
51537
a5d47d1b2a74 8209852: Counters in StringCleaningTask should be type of size_t
zgu
parents: 51405
diff changeset
   411
                                    size_t* processed, size_t* removed) {
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   412
  DoNothingClosure dnc;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   413
  assert(is_alive != NULL, "No closure");
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   414
  StringTableIsAliveCounter stiac(is_alive);
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   415
  OopClosure* tmp = f != NULL ? f : &dnc;
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   416
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   417
  StringTable::the_table()->_weak_handles->weak_oops_do(&stiac, tmp);
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   418
50556
e5a40146791b 8204613: StringTable: Calculates wrong number of uncleaned items.
rehn
parents: 50445
diff changeset
   419
  // This is the serial case without ParState.
e5a40146791b 8204613: StringTable: Calculates wrong number of uncleaned items.
rehn
parents: 50445
diff changeset
   420
  // Just set the correct number and check for a cleaning phase.
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51334
diff changeset
   421
  the_table()->_uncleaned_items_count = stiac._count;
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   422
  StringTable::the_table()->check_concurrent_work();
50556
e5a40146791b 8204613: StringTable: Calculates wrong number of uncleaned items.
rehn
parents: 50445
diff changeset
   423
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   424
  if (processed != NULL) {
51537
a5d47d1b2a74 8209852: Counters in StringCleaningTask should be type of size_t
zgu
parents: 51405
diff changeset
   425
    *processed = stiac._count_total;
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   426
  }
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   427
  if (removed != NULL) {
51537
a5d47d1b2a74 8209852: Counters in StringCleaningTask should be type of size_t
zgu
parents: 51405
diff changeset
   428
    *removed = stiac._count;
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   429
  }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   430
}
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   431
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   432
void StringTable::oops_do(OopClosure* f) {
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   433
  assert(f != NULL, "No closure");
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   434
  StringTable::the_table()->_weak_handles->oops_do(f);
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   435
}
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   436
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   437
void StringTable::possibly_parallel_unlink(
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   438
   OopStorage::ParState<false, false>* _par_state_string, BoolObjectClosure* cl,
51537
a5d47d1b2a74 8209852: Counters in StringCleaningTask should be type of size_t
zgu
parents: 51405
diff changeset
   439
   size_t* processed, size_t* removed)
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   440
{
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   441
  DoNothingClosure dnc;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   442
  assert(cl != NULL, "No closure");
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   443
  StringTableIsAliveCounter stiac(cl);
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   444
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   445
  _par_state_string->weak_oops_do(&stiac, &dnc);
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   446
50556
e5a40146791b 8204613: StringTable: Calculates wrong number of uncleaned items.
rehn
parents: 50445
diff changeset
   447
  // Accumulate the dead strings.
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51334
diff changeset
   448
  the_table()->add_items_count_to_clean(stiac._count);
50556
e5a40146791b 8204613: StringTable: Calculates wrong number of uncleaned items.
rehn
parents: 50445
diff changeset
   449
51537
a5d47d1b2a74 8209852: Counters in StringCleaningTask should be type of size_t
zgu
parents: 51405
diff changeset
   450
  *processed = stiac._count_total;
a5d47d1b2a74 8209852: Counters in StringCleaningTask should be type of size_t
zgu
parents: 51405
diff changeset
   451
  *removed = stiac._count;
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   452
}
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   453
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   454
void StringTable::possibly_parallel_oops_do(
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   455
   OopStorage::ParState<false /* concurrent */, false /* const */>*
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   456
   _par_state_string, OopClosure* f)
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   457
{
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   458
  assert(f != NULL, "No closure");
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   459
  _par_state_string->oops_do(f);
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   460
}
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   461
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   462
// Concurrent work
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   463
void StringTable::grow(JavaThread* jt) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   464
  StringTableHash::GrowTask gt(_local_table);
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   465
  if (!gt.prepare(jt)) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   466
    return;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   467
  }
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   468
  log_trace(stringtable)("Started to grow");
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   469
  {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   470
    TraceTime timer("Grow", TRACETIME_LOG(Debug, stringtable, perf));
50608
1609a43e77ae 8204857: ConcurrentHashTable: Fix parallel processing
rehn
parents: 50556
diff changeset
   471
    while (gt.do_task(jt)) {
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   472
      gt.pause(jt);
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   473
      {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   474
        ThreadBlockInVM tbivm(jt);
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   475
      }
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   476
      gt.cont(jt);
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   477
    }
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   478
  }
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   479
  gt.done(jt);
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51334
diff changeset
   480
  _current_size = table_size();
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   481
  log_debug(stringtable)("Grown to size:" SIZE_FORMAT, _current_size);
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   482
}
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   483
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   484
struct StringTableDoDelete : StackObj {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   485
  void operator()(WeakHandle<vm_string_table_data>* val) {
50556
e5a40146791b 8204613: StringTable: Calculates wrong number of uncleaned items.
rehn
parents: 50445
diff changeset
   486
    /* do nothing */
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   487
  }
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   488
};
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   489
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   490
struct StringTableDeleteCheck : StackObj {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   491
  long _count;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   492
  long _item;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   493
  StringTableDeleteCheck() : _count(0), _item(0) {}
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   494
  bool operator()(WeakHandle<vm_string_table_data>* val) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   495
    ++_item;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   496
    oop tmp = val->peek();
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   497
    if (tmp == NULL) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   498
      ++_count;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   499
      return true;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   500
    } else {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   501
      return false;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   502
    }
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   503
  }
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   504
};
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   505
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   506
void StringTable::clean_dead_entries(JavaThread* jt) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   507
  StringTableHash::BulkDeleteTask bdt(_local_table);
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   508
  if (!bdt.prepare(jt)) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   509
    return;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   510
  }
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   511
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   512
  StringTableDeleteCheck stdc;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   513
  StringTableDoDelete stdd;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   514
  {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   515
    TraceTime timer("Clean", TRACETIME_LOG(Debug, stringtable, perf));
50608
1609a43e77ae 8204857: ConcurrentHashTable: Fix parallel processing
rehn
parents: 50556
diff changeset
   516
    while(bdt.do_task(jt, stdc, stdd)) {
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   517
      bdt.pause(jt);
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   518
      {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   519
        ThreadBlockInVM tbivm(jt);
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   520
      }
50815
54a285a5c6cb 8205583: Crash in ConcurrentHashTable do_bulk_delete_locked_for
rehn
parents: 50608
diff changeset
   521
      bdt.cont(jt);
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   522
    }
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   523
    bdt.done(jt);
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   524
  }
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   525
  log_debug(stringtable)("Cleaned %ld of %ld", stdc._count, stdc._item);
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   526
}
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   527
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   528
void StringTable::check_concurrent_work() {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   529
  if (_has_work) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   530
    return;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   531
  }
50556
e5a40146791b 8204613: StringTable: Calculates wrong number of uncleaned items.
rehn
parents: 50445
diff changeset
   532
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   533
  double load_factor = StringTable::get_load_factor();
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   534
  double dead_factor = StringTable::get_dead_factor();
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   535
  // We should clean/resize if we have more dead than alive,
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   536
  // more items than preferred load factor or
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   537
  // more dead items than water mark.
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   538
  if ((dead_factor > load_factor) ||
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   539
      (load_factor > PREF_AVG_LIST_LEN) ||
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   540
      (dead_factor > CLEAN_DEAD_HIGH_WATER_MARK)) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   541
    log_debug(stringtable)("Concurrent work triggered, live factor:%g dead factor:%g",
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   542
                           load_factor, dead_factor);
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   543
    trigger_concurrent_work();
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   544
  }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   545
}
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   546
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   547
void StringTable::concurrent_work(JavaThread* jt) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   548
  _has_work = false;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   549
  double load_factor = get_load_factor();
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   550
  log_debug(stringtable, perf)("Concurrent work, live factor: %g", load_factor);
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   551
  // We prefer growing, since that also removes dead items
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   552
  if (load_factor > PREF_AVG_LIST_LEN && !_local_table->is_max_size_reached()) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   553
    grow(jt);
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   554
  } else {
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   555
    clean_dead_entries(jt);
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   556
  }
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   557
}
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   558
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   559
void StringTable::do_concurrent_work(JavaThread* jt) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   560
  StringTable::the_table()->concurrent_work(jt);
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   561
}
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   562
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   563
// Rehash
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   564
bool StringTable::do_rehash() {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   565
  if (!_local_table->is_safepoint_safe()) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   566
    return false;
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   567
  }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   568
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   569
  // We use max size
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   570
  StringTableHash* new_table = new StringTableHash(END_SIZE, END_SIZE, REHASH_LEN);
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   571
  // Use alt hash from now on
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   572
  _alt_hash = true;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   573
  if (!_local_table->try_move_nodes_to(Thread::current(), new_table)) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   574
    _alt_hash = false;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   575
    delete new_table;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   576
    return false;
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   577
  }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   578
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   579
  // free old table
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   580
  delete _local_table;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   581
  _local_table = new_table;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   582
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   583
  return true;
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   584
}
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   585
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   586
void StringTable::try_rehash_table() {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   587
  static bool rehashed = false;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   588
  log_debug(stringtable)("Table imbalanced, rehashing called.");
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   589
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   590
  // Grow instead of rehash.
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   591
  if (get_load_factor() > PREF_AVG_LIST_LEN &&
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   592
      !_local_table->is_max_size_reached()) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   593
    log_debug(stringtable)("Choosing growing over rehashing.");
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   594
    trigger_concurrent_work();
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   595
    _needs_rehashing = false;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   596
    return;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   597
  }
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   598
  // Already rehashed.
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   599
  if (rehashed) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   600
    log_warning(stringtable)("Rehashing already done, still long lists.");
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   601
    trigger_concurrent_work();
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   602
    _needs_rehashing = false;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   603
    return;
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   604
  }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   605
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   606
  murmur_seed = AltHashing::compute_seed();
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   607
  {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   608
    if (do_rehash()) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   609
      rehashed = true;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   610
    } else {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   611
      log_info(stringtable)("Resizes in progress rehashing skipped.");
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   612
    }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   613
  }
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   614
  _needs_rehashing = false;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   615
}
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   616
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   617
void StringTable::rehash_table() {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   618
  StringTable::the_table()->try_rehash_table();
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   619
}
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   620
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   621
// Statistics
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   622
static int literal_size(oop obj) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   623
  // NOTE: this would over-count if (pre-JDK8)
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   624
  // java_lang_Class::has_offset_field() is true and the String.value array is
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   625
  // shared by several Strings. However, starting from JDK8, the String.value
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   626
  // array is not shared anymore.
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   627
  if (obj == NULL) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   628
    return 0;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   629
  } else if (obj->klass() == SystemDictionary::String_klass()) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   630
    return (obj->size() + java_lang_String::value(obj)->size()) * HeapWordSize;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   631
  } else {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   632
    return obj->size();
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   633
  }
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   634
}
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   635
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   636
struct SizeFunc : StackObj {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   637
  size_t operator()(WeakHandle<vm_string_table_data>* val) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   638
    oop s = val->peek();
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   639
    if (s == NULL) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   640
      // Dead
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   641
      return 0;
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   642
    }
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   643
    return literal_size(s);
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   644
  };
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   645
};
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   646
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   647
void StringTable::print_table_statistics(outputStream* st,
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   648
                                         const char* table_name) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   649
  SizeFunc sz;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   650
  _local_table->statistics_to(Thread::current(), sz, st, table_name);
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   651
}
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   652
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   653
// Verification
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   654
class VerifyStrings : StackObj {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   655
 public:
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   656
  bool operator()(WeakHandle<vm_string_table_data>* val) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   657
    oop s = val->peek();
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   658
    if (s != NULL) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   659
      assert(java_lang_String::length(s) >= 0, "Length on string must work.");
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   660
    }
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   661
    return true;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   662
  };
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   663
};
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   664
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   665
// This verification is part of Universe::verify() and needs to be quick.
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   666
void StringTable::verify() {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   667
  Thread* thr = Thread::current();
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   668
  VerifyStrings vs;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   669
  if (!the_table()->_local_table->try_scan(thr, vs)) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   670
    log_info(stringtable)("verify unavailable at this moment");
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   671
  }
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   672
}
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   673
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   674
// Verification and comp
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   675
class VerifyCompStrings : StackObj {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   676
  GrowableArray<oop>* _oops;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   677
 public:
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   678
  size_t _errors;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   679
  VerifyCompStrings(GrowableArray<oop>* oops) : _oops(oops), _errors(0) {}
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   680
  bool operator()(WeakHandle<vm_string_table_data>* val) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   681
    oop s = val->resolve();
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   682
    if (s == NULL) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   683
      return true;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   684
    }
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   685
    int len = _oops->length();
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   686
    for (int i = 0; i < len; i++) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   687
      bool eq = java_lang_String::equals(s, _oops->at(i));
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   688
      assert(!eq, "Duplicate strings");
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   689
      if (eq) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   690
        _errors++;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   691
      }
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   692
    }
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   693
    _oops->push(s);
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   694
    return true;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   695
  };
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   696
};
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   697
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   698
size_t StringTable::verify_and_compare_entries() {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   699
  Thread* thr = Thread::current();
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   700
  GrowableArray<oop>* oops =
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   701
    new (ResourceObj::C_HEAP, mtInternal)
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   702
      GrowableArray<oop>((int)the_table()->_current_size, true);
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   703
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   704
  VerifyCompStrings vcs(oops);
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   705
  if (!the_table()->_local_table->try_scan(thr, vcs)) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   706
    log_info(stringtable)("verify unavailable at this moment");
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   707
  }
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   708
  delete oops;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   709
  return vcs._errors;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   710
}
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   711
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   712
// Dumping
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   713
class PrintString : StackObj {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   714
  Thread* _thr;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   715
  outputStream* _st;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   716
 public:
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   717
  PrintString(Thread* thr, outputStream* st) : _thr(thr), _st(st) {}
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   718
  bool operator()(WeakHandle<vm_string_table_data>* val) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   719
    oop s = val->peek();
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   720
    if (s == NULL) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   721
      return true;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   722
    }
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   723
    typeArrayOop value     = java_lang_String::value_no_keepalive(s);
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   724
    int          length    = java_lang_String::length(s);
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   725
    bool         is_latin1 = java_lang_String::is_latin1(s);
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   726
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   727
    if (length <= 0) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   728
      _st->print("%d: ", length);
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   729
    } else {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   730
      ResourceMark rm(_thr);
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   731
      int utf8_length = length;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   732
      char* utf8_string;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   733
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   734
      if (!is_latin1) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   735
        jchar* chars = value->char_at_addr(0);
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   736
        utf8_string = UNICODE::as_utf8(chars, utf8_length);
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   737
      } else {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   738
        jbyte* bytes = value->byte_at_addr(0);
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   739
        utf8_string = UNICODE::as_utf8(bytes, utf8_length);
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   740
      }
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   741
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   742
      _st->print("%d: ", utf8_length);
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   743
      HashtableTextDump::put_utf8(_st, utf8_string, utf8_length);
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   744
    }
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   745
    _st->cr();
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   746
    return true;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   747
  };
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   748
};
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   749
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   750
void StringTable::dump(outputStream* st, bool verbose) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   751
  if (!verbose) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   752
    the_table()->print_table_statistics(st, "StringTable");
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   753
  } else {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   754
    Thread* thr = Thread::current();
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   755
    ResourceMark rm(thr);
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   756
    st->print_cr("VERSION: 1.1");
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   757
    PrintString ps(thr, st);
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   758
    if (!the_table()->_local_table->try_scan(thr, ps)) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   759
      st->print_cr("dump unavailable at this moment");
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   760
    }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   761
  }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   762
}
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   763
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   764
// Utility for dumping strings
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   765
StringtableDCmd::StringtableDCmd(outputStream* output, bool heap) :
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   766
                                 DCmdWithParser(output, heap),
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   767
  _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
   768
           "BOOLEAN", false, "false") {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   769
  _dcmdparser.add_dcmd_option(&_verbose);
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   770
}
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   771
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   772
void StringtableDCmd::execute(DCmdSource source, TRAPS) {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   773
  VM_DumpHashtable dumper(output(), VM_DumpHashtable::DumpStrings,
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   774
                         _verbose.value());
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   775
  VMThread::execute(&dumper);
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   776
}
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   777
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   778
int StringtableDCmd::num_arguments() {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   779
  ResourceMark rm;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   780
  StringtableDCmd* dcmd = new StringtableDCmd(NULL, false);
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   781
  if (dcmd != NULL) {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   782
    DCmdMark mark(dcmd);
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   783
    return dcmd->_dcmdparser.num_arguments();
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   784
  } else {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   785
    return 0;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   786
  }
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   787
}
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   788
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   789
// Sharing
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   790
#if INCLUDE_CDS_JAVA_HEAP
51823
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51796
diff changeset
   791
oop StringTable::lookup_shared(const jchar* name, int len, unsigned int hash) {
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   792
  assert(hash == java_lang_String::hash_code(name, len),
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   793
         "hash must be computed using java_lang_String::hash_code");
51823
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51796
diff changeset
   794
  return _shared_table.lookup(name, hash, len);
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   795
}
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   796
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   797
oop StringTable::create_archived_string(oop s, Thread* THREAD) {
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   798
  assert(DumpSharedSpaces, "this function is only used with -Xshare:dump");
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   799
52062
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   800
  if (HeapShared::is_archived_object(s)) {
50951
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents: 50815
diff changeset
   801
    return s;
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents: 50815
diff changeset
   802
  }
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents: 50815
diff changeset
   803
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   804
  oop new_s = NULL;
48618
688e5cbd0b91 8192003: Refactor weak references in StringTable to use the Access API
eosterlund
parents: 47216
diff changeset
   805
  typeArrayOop v = java_lang_String::value_no_keepalive(s);
52062
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   806
  typeArrayOop new_v = (typeArrayOop)HeapShared::archive_heap_object(v, THREAD);
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   807
  if (new_v == NULL) {
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   808
    return NULL;
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   809
  }
52062
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   810
  new_s = HeapShared::archive_heap_object(s, THREAD);
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   811
  if (new_s == NULL) {
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   812
    return NULL;
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   813
  }
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   814
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   815
  // adjust the pointer to the 'value' field in the new String oop
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   816
  java_lang_String::set_value_raw(new_s, new_v);
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   817
  return new_s;
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   818
}
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   819
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   820
struct CopyToArchive : StackObj {
52047
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51823
diff changeset
   821
  CompactHashtableWriter* _writer;
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51823
diff changeset
   822
  CopyToArchive(CompactHashtableWriter* writer) : _writer(writer) {}
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   823
  bool operator()(WeakHandle<vm_string_table_data>* val) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   824
    oop s = val->peek();
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   825
    if (s == NULL) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   826
      return true;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   827
    }
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   828
    unsigned int hash = java_lang_String::hash_code(s);
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   829
    if (hash == 0) {
52047
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51823
diff changeset
   830
      // We do not archive Strings with a 0 hashcode because ......
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   831
      return true;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   832
    }
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   833
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   834
    java_lang_String::set_hash(s, hash);
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   835
    oop new_s = StringTable::create_archived_string(s, Thread::current());
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   836
    if (new_s == NULL) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   837
      return true;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   838
    }
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   839
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   840
    val->replace(new_s);
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   841
    // add to the compact table
52047
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51823
diff changeset
   842
    _writer->add(hash, CompressedOops::encode(new_s));
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   843
    return true;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   844
  }
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   845
};
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   846
52047
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51823
diff changeset
   847
void StringTable::copy_shared_string_table(CompactHashtableWriter* writer) {
52062
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   848
  assert(HeapShared::is_heap_object_archiving_allowed(), "must be");
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   849
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   850
  CopyToArchive copy(writer);
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   851
  StringTable::the_table()->_local_table->do_scan(Thread::current(), copy);
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   852
}
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   853
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   854
void StringTable::write_to_archive() {
52062
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   855
  assert(HeapShared::is_heap_object_archiving_allowed(), "must be");
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   856
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37248
diff changeset
   857
  _shared_table.reset();
52047
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51823
diff changeset
   858
  int num_buckets = CompactHashtableWriter::default_num_buckets(
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51823
diff changeset
   859
      StringTable::the_table()->_items_count);
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51823
diff changeset
   860
  CompactHashtableWriter writer(num_buckets,
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51823
diff changeset
   861
                                &MetaspaceShared::stats()->string);
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37248
diff changeset
   862
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   863
  // Copy the interned strings into the "string space" within the java heap
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   864
  copy_shared_string_table(&writer);
51823
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51796
diff changeset
   865
  writer.dump(&_shared_table, "string");
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   866
}
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   867
52047
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51823
diff changeset
   868
void StringTable::serialize_shared_table_header(SerializeClosure* soc) {
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51823
diff changeset
   869
  _shared_table.serialize_header(soc);
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   870
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37248
diff changeset
   871
  if (soc->writing()) {
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   872
    // Sanity. Make sure we don't use the shared table at dump time
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   873
    _shared_table.reset();
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   874
  } else if (!_shared_string_mapped) {
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37248
diff changeset
   875
    _shared_table.reset();
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   876
  }
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   877
}
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   878
51823
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51796
diff changeset
   879
class SharedStringIterator {
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51796
diff changeset
   880
  OopClosure* _oop_closure;
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51796
diff changeset
   881
public:
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51796
diff changeset
   882
  SharedStringIterator(OopClosure* f) : _oop_closure(f) {}
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51796
diff changeset
   883
  void do_value(oop string) {
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51796
diff changeset
   884
    _oop_closure->do_oop(&string);
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51796
diff changeset
   885
  }
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51796
diff changeset
   886
};
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51796
diff changeset
   887
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   888
void StringTable::shared_oops_do(OopClosure* f) {
51823
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51796
diff changeset
   889
  SharedStringIterator iter(f);
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51796
diff changeset
   890
  _shared_table.iterate(&iter);
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   891
}
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   892
#endif //INCLUDE_CDS_JAVA_HEAP