src/hotspot/share/classfile/stringTable.cpp
author coleenp
Thu, 25 Apr 2019 10:56:31 -0400
changeset 54623 1126f0607c70
parent 54486 7fd299216e97
child 54764 865ec913f916
permissions -rw-r--r--
8222811: Consolidate MutexLockerEx and MutexLocker Summary: Make MutexLocker be MutexLockerEx implementation, remove MutexLockerEx calls. Reviewed-by: dcubed, dholmes, pliden, rehn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
     1
/*
53536
482109fae02b 8213229: Investigate treating StringTable as weak in young collections
tschatzl
parents: 52931
diff changeset
     2
 * Copyright (c) 1997, 2019, 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"
54347
235883996bc7 8221698: Remove redundant includes from popular header files
iklam
parents: 53785
diff changeset
    55
#include "utilities/utf8.hpp"
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    56
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
    57
// We prefer short chains of avg 2
52931
3b0fe3d6c3d7 8209387: Follow ups to JDK-8195100 Use a low latency hashtable for SymbolTable
gziemski
parents: 52717
diff changeset
    58
const double PREF_AVG_LIST_LEN = 2.0;
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
    59
// 2^24 is max size
52931
3b0fe3d6c3d7 8209387: Follow ups to JDK-8195100 Use a low latency hashtable for SymbolTable
gziemski
parents: 52717
diff changeset
    60
const size_t END_SIZE = 24;
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
    61
// If a chain gets to 32 something might be wrong
52931
3b0fe3d6c3d7 8209387: Follow ups to JDK-8195100 Use a low latency hashtable for SymbolTable
gziemski
parents: 52717
diff changeset
    62
const size_t REHASH_LEN = 32;
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
    63
// If we have as many dead items as 50% of the number of bucket
52931
3b0fe3d6c3d7 8209387: Follow ups to JDK-8195100 Use a low latency hashtable for SymbolTable
gziemski
parents: 52717
diff changeset
    64
const double CLEAN_DEAD_HIGH_WATER_MARK = 0.5;
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    65
51823
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51796
diff changeset
    66
#if INCLUDE_CDS_JAVA_HEAP
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51796
diff changeset
    67
inline oop read_string_from_compact_hashtable(address base_address, u4 offset) {
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51796
diff changeset
    68
  assert(sizeof(narrowOop) == sizeof(offset), "must be");
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51796
diff changeset
    69
  narrowOop v = (narrowOop)offset;
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51796
diff changeset
    70
  return HeapShared::decode_from_archive(v);
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51796
diff changeset
    71
}
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51796
diff changeset
    72
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51796
diff changeset
    73
static CompactHashtable<
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51796
diff changeset
    74
  const jchar*, oop,
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51796
diff changeset
    75
  read_string_from_compact_hashtable,
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51796
diff changeset
    76
  java_lang_String::equals
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51796
diff changeset
    77
> _shared_table;
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51796
diff changeset
    78
#endif
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51796
diff changeset
    79
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    80
// --------------------------------------------------------------------------
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    81
StringTable* StringTable::_the_table = NULL;
51405
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
52717
b22da519f2e3 8213791: StringTable: Use get and insert
rehn
parents: 52516
diff changeset
   210
void StringTable::update_needs_rehash(bool rehash) {
b22da519f2e3 8213791: StringTable: Use get and insert
rehn
parents: 52516
diff changeset
   211
  if (rehash) {
b22da519f2e3 8213791: StringTable: Use get and insert
rehn
parents: 52516
diff changeset
   212
    _needs_rehashing = true;
b22da519f2e3 8213791: StringTable: Use get and insert
rehn
parents: 52516
diff changeset
   213
  }
b22da519f2e3 8213791: StringTable: Use get and insert
rehn
parents: 52516
diff changeset
   214
}
b22da519f2e3 8213791: StringTable: Use get and insert
rehn
parents: 52516
diff changeset
   215
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   216
size_t StringTable::item_added() {
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51334
diff changeset
   217
  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
   218
}
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   219
52931
3b0fe3d6c3d7 8209387: Follow ups to JDK-8195100 Use a low latency hashtable for SymbolTable
gziemski
parents: 52717
diff changeset
   220
size_t StringTable::add_items_to_clean(size_t ndead) {
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51334
diff changeset
   221
  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
   222
  log_trace(stringtable)(
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   223
     "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
   224
     the_table()->_uncleaned_items_count, ndead, total);
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   225
  return total;
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   226
}
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   227
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   228
void StringTable::item_removed() {
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51334
diff changeset
   229
  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
   230
}
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   231
52931
3b0fe3d6c3d7 8209387: Follow ups to JDK-8195100 Use a low latency hashtable for SymbolTable
gziemski
parents: 52717
diff changeset
   232
double StringTable::get_load_factor() const {
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51334
diff changeset
   233
  return (double)_items_count/_current_size;
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   234
}
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   235
52931
3b0fe3d6c3d7 8209387: Follow ups to JDK-8195100 Use a low latency hashtable for SymbolTable
gziemski
parents: 52717
diff changeset
   236
double StringTable::get_dead_factor() const {
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51334
diff changeset
   237
  return (double)_uncleaned_items_count/_current_size;
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   238
}
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   239
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51334
diff changeset
   240
size_t StringTable::table_size() {
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51334
diff changeset
   241
  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
   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
void StringTable::trigger_concurrent_work() {
54623
1126f0607c70 8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents: 54486
diff changeset
   245
  MutexLocker ml(Service_lock, Mutex::_no_safepoint_check_flag);
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   246
  the_table()->_has_work = true;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   247
  Service_lock->notify_all();
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   248
}
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   249
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   250
// Probing
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   251
oop StringTable::lookup(Symbol* symbol) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   252
  ResourceMark rm;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   253
  int length;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   254
  jchar* chars = symbol->as_unicode(length);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   255
  return lookup(chars, length);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   256
}
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   257
51823
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51796
diff changeset
   258
oop StringTable::lookup(const jchar* name, int len) {
44323
1566bea4793a 8176593: Throwable::getStackTrace performance regression
redestad
parents: 42057
diff changeset
   259
  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
   260
  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
   261
  if (string != NULL) {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   262
    return string;
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   263
  }
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   264
  if (StringTable::_alt_hash) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   265
    hash = hash_string(name, len, true);
44323
1566bea4793a 8176593: Throwable::getStackTrace performance regression
redestad
parents: 42057
diff changeset
   266
  }
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   267
  return StringTable::the_table()->do_lookup(name, len, hash);
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   268
}
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   269
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   270
class StringTableGet : public StackObj {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   271
  Thread* _thread;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   272
  Handle  _return;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   273
 public:
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   274
  StringTableGet(Thread* thread) : _thread(thread) {}
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   275
  void operator()(WeakHandle<vm_string_table_data>* val) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   276
    oop result = val->resolve();
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   277
    assert(result != NULL, "Result should be reachable");
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   278
    _return = Handle(_thread, result);
44323
1566bea4793a 8176593: Throwable::getStackTrace performance regression
redestad
parents: 42057
diff changeset
   279
  }
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   280
  oop get_res_oop() {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   281
    return _return();
25492
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   282
  }
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   283
};
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   284
51823
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51796
diff changeset
   285
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
   286
  Thread* thread = Thread::current();
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   287
  StringTableLookupJchar lookup(thread, hash, name, len);
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   288
  StringTableGet stg(thread);
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   289
  bool rehash_warning;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   290
  _local_table->get(thread, lookup, stg, &rehash_warning);
52717
b22da519f2e3 8213791: StringTable: Use get and insert
rehn
parents: 52516
diff changeset
   291
  update_needs_rehash(rehash_warning);
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   292
  return stg.get_res_oop();
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   293
}
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   294
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   295
// Interning
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   296
oop StringTable::intern(Symbol* symbol, TRAPS) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   297
  if (symbol == NULL) return NULL;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   298
  ResourceMark rm(THREAD);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   299
  int length;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   300
  jchar* chars = symbol->as_unicode(length);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   301
  Handle string;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   302
  oop result = intern(string, chars, length, CHECK_NULL);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   303
  return result;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   304
}
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   305
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   306
oop StringTable::intern(oop string, TRAPS) {
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   307
  if (string == NULL) return NULL;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   308
  ResourceMark rm(THREAD);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   309
  int length;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   310
  Handle h_string (THREAD, string);
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   311
  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
   312
                                                     CHECK_NULL);
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   313
  oop result = intern(h_string, chars, length, CHECK_NULL);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   314
  return result;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   315
}
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   316
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   317
oop StringTable::intern(const char* utf8_string, TRAPS) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   318
  if (utf8_string == NULL) return NULL;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   319
  ResourceMark rm(THREAD);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   320
  int length = UTF8::unicode_length(utf8_string);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   321
  jchar* chars = NEW_RESOURCE_ARRAY(jchar, length);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   322
  UTF8::convert_to_unicode(utf8_string, chars, length);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   323
  Handle string;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   324
  oop result = intern(string, chars, length, CHECK_NULL);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   325
  return result;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   326
}
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   327
51823
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51796
diff changeset
   328
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
   329
  // shared table always uses java_lang_String::hash_code
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   330
  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
   331
  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
   332
  if (found_string != NULL) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   333
    return found_string;
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   334
  }
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   335
  if (StringTable::_alt_hash) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   336
    hash = hash_string(name, len, true);
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   337
  }
53785
d230a0406623 8216049: stringTable::intern creates redundant String when looking up existing one
shade
parents: 53587
diff changeset
   338
  found_string = StringTable::the_table()->do_lookup(name, len, hash);
d230a0406623 8216049: stringTable::intern creates redundant String when looking up existing one
shade
parents: 53587
diff changeset
   339
  if (found_string != NULL) {
d230a0406623 8216049: stringTable::intern creates redundant String when looking up existing one
shade
parents: 53587
diff changeset
   340
    return found_string;
d230a0406623 8216049: stringTable::intern creates redundant String when looking up existing one
shade
parents: 53587
diff changeset
   341
  }
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   342
  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
   343
                                             hash, CHECK_NULL);
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   344
}
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   345
51823
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51796
diff changeset
   346
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
   347
                           int len, uintx hash, TRAPS) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   348
  HandleMark hm(THREAD);  // cleanup strings created
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   349
  Handle string_h;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   350
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   351
  if (!string_or_null_h.is_null()) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   352
    string_h = string_or_null_h;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   353
  } else {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   354
    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
   355
  }
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   356
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   357
  // 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
   358
  // 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
   359
  // compiler optimizations done on e.g. interned string literals.
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   360
  Universe::heap()->deduplicate_string(string_h());
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   361
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   362
  assert(java_lang_String::equals(string_h(), name, len),
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   363
         "string must be properly initialized");
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   364
  assert(len == java_lang_String::length(string_h()), "Must be same length");
52717
b22da519f2e3 8213791: StringTable: Use get and insert
rehn
parents: 52516
diff changeset
   365
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   366
  StringTableLookupOop lookup(THREAD, hash, string_h);
52717
b22da519f2e3 8213791: StringTable: Use get and insert
rehn
parents: 52516
diff changeset
   367
  StringTableGet stg(THREAD);
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   368
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   369
  bool rehash_warning;
52717
b22da519f2e3 8213791: StringTable: Use get and insert
rehn
parents: 52516
diff changeset
   370
  do {
b22da519f2e3 8213791: StringTable: Use get and insert
rehn
parents: 52516
diff changeset
   371
    if (_local_table->get(THREAD, lookup, stg, &rehash_warning)) {
b22da519f2e3 8213791: StringTable: Use get and insert
rehn
parents: 52516
diff changeset
   372
      update_needs_rehash(rehash_warning);
b22da519f2e3 8213791: StringTable: Use get and insert
rehn
parents: 52516
diff changeset
   373
      return stg.get_res_oop();
b22da519f2e3 8213791: StringTable: Use get and insert
rehn
parents: 52516
diff changeset
   374
    }
b22da519f2e3 8213791: StringTable: Use get and insert
rehn
parents: 52516
diff changeset
   375
    WeakHandle<vm_string_table_data> wh = WeakHandle<vm_string_table_data>::create(string_h);
b22da519f2e3 8213791: StringTable: Use get and insert
rehn
parents: 52516
diff changeset
   376
    // The hash table takes ownership of the WeakHandle, even if it's not inserted.
b22da519f2e3 8213791: StringTable: Use get and insert
rehn
parents: 52516
diff changeset
   377
    if (_local_table->insert(THREAD, lookup, wh, &rehash_warning)) {
b22da519f2e3 8213791: StringTable: Use get and insert
rehn
parents: 52516
diff changeset
   378
      update_needs_rehash(rehash_warning);
b22da519f2e3 8213791: StringTable: Use get and insert
rehn
parents: 52516
diff changeset
   379
      return wh.resolve();
b22da519f2e3 8213791: StringTable: Use get and insert
rehn
parents: 52516
diff changeset
   380
    }
b22da519f2e3 8213791: StringTable: Use get and insert
rehn
parents: 52516
diff changeset
   381
  } while(true);
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   382
}
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   383
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   384
void StringTable::oops_do(OopClosure* f) {
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   385
  assert(f != NULL, "No closure");
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   386
  StringTable::the_table()->_weak_handles->oops_do(f);
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   387
}
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   388
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   389
void StringTable::possibly_parallel_oops_do(
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   390
   OopStorage::ParState<false /* concurrent */, false /* const */>*
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   391
   _par_state_string, OopClosure* f)
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   392
{
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   393
  assert(f != NULL, "No closure");
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   394
  _par_state_string->oops_do(f);
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   395
}
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   396
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   397
// Concurrent work
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   398
void StringTable::grow(JavaThread* jt) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   399
  StringTableHash::GrowTask gt(_local_table);
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   400
  if (!gt.prepare(jt)) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   401
    return;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   402
  }
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   403
  log_trace(stringtable)("Started to grow");
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
    TraceTime timer("Grow", TRACETIME_LOG(Debug, stringtable, perf));
50608
1609a43e77ae 8204857: ConcurrentHashTable: Fix parallel processing
rehn
parents: 50556
diff changeset
   406
    while (gt.do_task(jt)) {
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   407
      gt.pause(jt);
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   408
      {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   409
        ThreadBlockInVM tbivm(jt);
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   410
      }
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   411
      gt.cont(jt);
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   412
    }
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   413
  }
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   414
  gt.done(jt);
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51334
diff changeset
   415
  _current_size = table_size();
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   416
  log_debug(stringtable)("Grown to size:" SIZE_FORMAT, _current_size);
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   417
}
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   418
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   419
struct StringTableDoDelete : StackObj {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   420
  void operator()(WeakHandle<vm_string_table_data>* val) {
50556
e5a40146791b 8204613: StringTable: Calculates wrong number of uncleaned items.
rehn
parents: 50445
diff changeset
   421
    /* do nothing */
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   422
  }
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   423
};
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   424
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   425
struct StringTableDeleteCheck : StackObj {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   426
  long _count;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   427
  long _item;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   428
  StringTableDeleteCheck() : _count(0), _item(0) {}
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   429
  bool operator()(WeakHandle<vm_string_table_data>* val) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   430
    ++_item;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   431
    oop tmp = val->peek();
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   432
    if (tmp == NULL) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   433
      ++_count;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   434
      return true;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   435
    } else {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   436
      return false;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   437
    }
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   438
  }
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   439
};
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   440
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   441
void StringTable::clean_dead_entries(JavaThread* jt) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   442
  StringTableHash::BulkDeleteTask bdt(_local_table);
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   443
  if (!bdt.prepare(jt)) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   444
    return;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   445
  }
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   446
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   447
  StringTableDeleteCheck stdc;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   448
  StringTableDoDelete stdd;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   449
  {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   450
    TraceTime timer("Clean", TRACETIME_LOG(Debug, stringtable, perf));
50608
1609a43e77ae 8204857: ConcurrentHashTable: Fix parallel processing
rehn
parents: 50556
diff changeset
   451
    while(bdt.do_task(jt, stdc, stdd)) {
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   452
      bdt.pause(jt);
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
        ThreadBlockInVM tbivm(jt);
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   455
      }
50815
54a285a5c6cb 8205583: Crash in ConcurrentHashTable do_bulk_delete_locked_for
rehn
parents: 50608
diff changeset
   456
      bdt.cont(jt);
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   457
    }
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   458
    bdt.done(jt);
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   459
  }
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   460
  log_debug(stringtable)("Cleaned %ld of %ld", stdc._count, stdc._item);
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   461
}
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   462
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   463
void StringTable::check_concurrent_work() {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   464
  if (_has_work) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   465
    return;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   466
  }
50556
e5a40146791b 8204613: StringTable: Calculates wrong number of uncleaned items.
rehn
parents: 50445
diff changeset
   467
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   468
  double load_factor = StringTable::get_load_factor();
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   469
  double dead_factor = StringTable::get_dead_factor();
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   470
  // 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
   471
  // more items than preferred load factor or
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   472
  // more dead items than water mark.
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   473
  if ((dead_factor > load_factor) ||
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   474
      (load_factor > PREF_AVG_LIST_LEN) ||
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   475
      (dead_factor > CLEAN_DEAD_HIGH_WATER_MARK)) {
53587
739eaf4ac4ad 8213753: SymbolTable is double walked during class unloading and clean up table timing in do_unloading
coleenp
parents: 53536
diff changeset
   476
    log_debug(stringtable)("Concurrent work triggered, live factor: %g dead factor: %g",
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   477
                           load_factor, dead_factor);
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   478
    trigger_concurrent_work();
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   479
  }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   480
}
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   481
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   482
void StringTable::concurrent_work(JavaThread* jt) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   483
  _has_work = false;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   484
  double load_factor = get_load_factor();
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   485
  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
   486
  // We prefer growing, since that also removes dead items
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   487
  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
   488
    grow(jt);
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   489
  } else {
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   490
    clean_dead_entries(jt);
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   491
  }
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   492
}
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   493
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   494
void StringTable::do_concurrent_work(JavaThread* jt) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   495
  StringTable::the_table()->concurrent_work(jt);
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   496
}
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   497
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   498
// Rehash
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   499
bool StringTable::do_rehash() {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   500
  if (!_local_table->is_safepoint_safe()) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   501
    return false;
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   502
  }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   503
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   504
  // We use max size
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   505
  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
   506
  // Use alt hash from now on
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   507
  _alt_hash = true;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   508
  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
   509
    _alt_hash = false;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   510
    delete new_table;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   511
    return false;
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   512
  }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   513
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   514
  // free old table
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   515
  delete _local_table;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   516
  _local_table = new_table;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   517
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   518
  return true;
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   519
}
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   520
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   521
void StringTable::try_rehash_table() {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   522
  static bool rehashed = false;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   523
  log_debug(stringtable)("Table imbalanced, rehashing called.");
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   524
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   525
  // Grow instead of rehash.
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   526
  if (get_load_factor() > PREF_AVG_LIST_LEN &&
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   527
      !_local_table->is_max_size_reached()) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   528
    log_debug(stringtable)("Choosing growing over rehashing.");
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   529
    trigger_concurrent_work();
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   530
    _needs_rehashing = false;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   531
    return;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   532
  }
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   533
  // Already rehashed.
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   534
  if (rehashed) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   535
    log_warning(stringtable)("Rehashing already done, still long lists.");
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   536
    trigger_concurrent_work();
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   537
    _needs_rehashing = false;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   538
    return;
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   539
  }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   540
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   541
  murmur_seed = AltHashing::compute_seed();
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   542
  {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   543
    if (do_rehash()) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   544
      rehashed = true;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   545
    } else {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   546
      log_info(stringtable)("Resizes in progress rehashing skipped.");
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   547
    }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   548
  }
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   549
  _needs_rehashing = false;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   550
}
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   551
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   552
void StringTable::rehash_table() {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   553
  StringTable::the_table()->try_rehash_table();
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   554
}
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   555
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   556
// Statistics
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   557
static int literal_size(oop obj) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   558
  // NOTE: this would over-count if (pre-JDK8)
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   559
  // 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
   560
  // 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
   561
  // array is not shared anymore.
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   562
  if (obj == NULL) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   563
    return 0;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   564
  } else if (obj->klass() == SystemDictionary::String_klass()) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   565
    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
   566
  } else {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   567
    return obj->size();
24426
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
}
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   570
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   571
struct SizeFunc : StackObj {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   572
  size_t operator()(WeakHandle<vm_string_table_data>* val) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   573
    oop s = val->peek();
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   574
    if (s == NULL) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   575
      // Dead
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   576
      return 0;
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   577
    }
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   578
    return literal_size(s);
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   579
  };
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   580
};
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   581
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   582
void StringTable::print_table_statistics(outputStream* st,
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   583
                                         const char* table_name) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   584
  SizeFunc sz;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   585
  _local_table->statistics_to(Thread::current(), sz, st, table_name);
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   586
}
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   587
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   588
// Verification
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   589
class VerifyStrings : StackObj {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   590
 public:
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   591
  bool operator()(WeakHandle<vm_string_table_data>* val) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   592
    oop s = val->peek();
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   593
    if (s != NULL) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   594
      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
   595
    }
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   596
    return true;
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
};
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   599
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   600
// 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
   601
void StringTable::verify() {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   602
  Thread* thr = Thread::current();
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   603
  VerifyStrings vs;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   604
  if (!the_table()->_local_table->try_scan(thr, vs)) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   605
    log_info(stringtable)("verify unavailable at this moment");
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   606
  }
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
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   609
// Verification and comp
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   610
class VerifyCompStrings : StackObj {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   611
  GrowableArray<oop>* _oops;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   612
 public:
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   613
  size_t _errors;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   614
  VerifyCompStrings(GrowableArray<oop>* oops) : _oops(oops), _errors(0) {}
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   615
  bool operator()(WeakHandle<vm_string_table_data>* val) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   616
    oop s = val->resolve();
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   617
    if (s == NULL) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   618
      return true;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   619
    }
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   620
    int len = _oops->length();
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   621
    for (int i = 0; i < len; i++) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   622
      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
   623
      assert(!eq, "Duplicate strings");
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   624
      if (eq) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   625
        _errors++;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   626
      }
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   627
    }
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   628
    _oops->push(s);
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   629
    return true;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   630
  };
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   631
};
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   632
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   633
size_t StringTable::verify_and_compare_entries() {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   634
  Thread* thr = Thread::current();
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   635
  GrowableArray<oop>* oops =
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   636
    new (ResourceObj::C_HEAP, mtInternal)
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   637
      GrowableArray<oop>((int)the_table()->_current_size, true);
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   638
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   639
  VerifyCompStrings vcs(oops);
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   640
  if (!the_table()->_local_table->try_scan(thr, vcs)) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   641
    log_info(stringtable)("verify unavailable at this moment");
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   642
  }
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   643
  delete oops;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   644
  return vcs._errors;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   645
}
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   646
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   647
// Dumping
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   648
class PrintString : StackObj {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   649
  Thread* _thr;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   650
  outputStream* _st;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   651
 public:
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   652
  PrintString(Thread* thr, outputStream* st) : _thr(thr), _st(st) {}
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   653
  bool operator()(WeakHandle<vm_string_table_data>* val) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   654
    oop s = val->peek();
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   655
    if (s == NULL) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   656
      return true;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   657
    }
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   658
    typeArrayOop value     = java_lang_String::value_no_keepalive(s);
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   659
    int          length    = java_lang_String::length(s);
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   660
    bool         is_latin1 = java_lang_String::is_latin1(s);
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   661
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   662
    if (length <= 0) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   663
      _st->print("%d: ", length);
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   664
    } else {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   665
      ResourceMark rm(_thr);
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   666
      int utf8_length = length;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   667
      char* utf8_string;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   668
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   669
      if (!is_latin1) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   670
        jchar* chars = value->char_at_addr(0);
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   671
        utf8_string = UNICODE::as_utf8(chars, utf8_length);
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   672
      } else {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   673
        jbyte* bytes = value->byte_at_addr(0);
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   674
        utf8_string = UNICODE::as_utf8(bytes, utf8_length);
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   675
      }
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   676
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   677
      _st->print("%d: ", utf8_length);
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   678
      HashtableTextDump::put_utf8(_st, utf8_string, utf8_length);
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   679
    }
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   680
    _st->cr();
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   681
    return true;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   682
  };
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   683
};
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
void StringTable::dump(outputStream* st, bool verbose) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   686
  if (!verbose) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   687
    the_table()->print_table_statistics(st, "StringTable");
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   688
  } else {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   689
    Thread* thr = Thread::current();
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   690
    ResourceMark rm(thr);
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   691
    st->print_cr("VERSION: 1.1");
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   692
    PrintString ps(thr, st);
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   693
    if (!the_table()->_local_table->try_scan(thr, ps)) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   694
      st->print_cr("dump unavailable at this moment");
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   695
    }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   696
  }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   697
}
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   698
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   699
// Utility for dumping strings
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   700
StringtableDCmd::StringtableDCmd(outputStream* output, bool heap) :
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   701
                                 DCmdWithParser(output, heap),
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   702
  _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
   703
           "BOOLEAN", false, "false") {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   704
  _dcmdparser.add_dcmd_option(&_verbose);
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   705
}
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   706
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   707
void StringtableDCmd::execute(DCmdSource source, TRAPS) {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   708
  VM_DumpHashtable dumper(output(), VM_DumpHashtable::DumpStrings,
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   709
                         _verbose.value());
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   710
  VMThread::execute(&dumper);
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   711
}
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   712
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   713
int StringtableDCmd::num_arguments() {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   714
  ResourceMark rm;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   715
  StringtableDCmd* dcmd = new StringtableDCmd(NULL, false);
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   716
  if (dcmd != NULL) {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   717
    DCmdMark mark(dcmd);
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   718
    return dcmd->_dcmdparser.num_arguments();
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   719
  } else {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   720
    return 0;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   721
  }
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   722
}
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   723
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   724
// Sharing
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   725
#if INCLUDE_CDS_JAVA_HEAP
51823
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51796
diff changeset
   726
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
   727
  assert(hash == java_lang_String::hash_code(name, len),
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   728
         "hash must be computed using java_lang_String::hash_code");
51823
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51796
diff changeset
   729
  return _shared_table.lookup(name, hash, len);
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   730
}
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   731
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   732
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
   733
  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
   734
52062
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   735
  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
   736
    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
   737
  }
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents: 50815
diff changeset
   738
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   739
  oop new_s = NULL;
48618
688e5cbd0b91 8192003: Refactor weak references in StringTable to use the Access API
eosterlund
parents: 47216
diff changeset
   740
  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
   741
  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
   742
  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
   743
    return NULL;
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   744
  }
52062
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   745
  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
   746
  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
   747
    return NULL;
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   748
  }
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   749
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   750
  // 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
   751
  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
   752
  return new_s;
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   753
}
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   754
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   755
struct CopyToArchive : StackObj {
52047
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51823
diff changeset
   756
  CompactHashtableWriter* _writer;
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51823
diff changeset
   757
  CopyToArchive(CompactHashtableWriter* writer) : _writer(writer) {}
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   758
  bool operator()(WeakHandle<vm_string_table_data>* val) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   759
    oop s = val->peek();
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   760
    if (s == NULL) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   761
      return true;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   762
    }
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   763
    unsigned int hash = java_lang_String::hash_code(s);
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   764
    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
   765
    if (new_s == NULL) {
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   766
      return true;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   767
    }
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   768
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   769
    val->replace(new_s);
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   770
    // add to the compact table
52047
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51823
diff changeset
   771
    _writer->add(hash, CompressedOops::encode(new_s));
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   772
    return true;
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   773
  }
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   774
};
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   775
52047
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51823
diff changeset
   776
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
   777
  assert(HeapShared::is_heap_object_archiving_allowed(), "must be");
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   778
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   779
  CopyToArchive copy(writer);
52516
d5eebe1e03fe 8213574: Deadlock in string table expansion when dumping lots of CDS classes
rehn
parents: 52402
diff changeset
   780
  StringTable::the_table()->_local_table->do_safepoint_scan(copy);
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   781
}
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   782
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   783
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
   784
  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
   785
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37248
diff changeset
   786
  _shared_table.reset();
52047
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51823
diff changeset
   787
  int num_buckets = CompactHashtableWriter::default_num_buckets(
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51823
diff changeset
   788
      StringTable::the_table()->_items_count);
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51823
diff changeset
   789
  CompactHashtableWriter writer(num_buckets,
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51823
diff changeset
   790
                                &MetaspaceShared::stats()->string);
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37248
diff changeset
   791
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   792
  // 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
   793
  copy_shared_string_table(&writer);
51823
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51796
diff changeset
   794
  writer.dump(&_shared_table, "string");
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   795
}
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   796
52047
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51823
diff changeset
   797
void StringTable::serialize_shared_table_header(SerializeClosure* soc) {
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51823
diff changeset
   798
  _shared_table.serialize_header(soc);
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   799
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37248
diff changeset
   800
  if (soc->writing()) {
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50233
diff changeset
   801
    // 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
   802
    _shared_table.reset();
52402
72d4e10305b9 8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents: 52062
diff changeset
   803
  } else if (!HeapShared::closed_archive_heap_region_mapped()) {
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37248
diff changeset
   804
    _shared_table.reset();
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   805
  }
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   806
}
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   807
51823
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51796
diff changeset
   808
class SharedStringIterator {
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51796
diff changeset
   809
  OopClosure* _oop_closure;
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51796
diff changeset
   810
public:
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51796
diff changeset
   811
  SharedStringIterator(OopClosure* f) : _oop_closure(f) {}
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51796
diff changeset
   812
  void do_value(oop string) {
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51796
diff changeset
   813
    _oop_closure->do_oop(&string);
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51796
diff changeset
   814
  }
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51796
diff changeset
   815
};
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51796
diff changeset
   816
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   817
void StringTable::shared_oops_do(OopClosure* f) {
51823
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51796
diff changeset
   818
  SharedStringIterator iter(f);
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51796
diff changeset
   819
  _shared_table.iterate(&iter);
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   820
}
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   821
#endif //INCLUDE_CDS_JAVA_HEAP