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