author | lfoltan |
Tue, 23 Apr 2019 07:05:38 -0400 | |
changeset 54595 | a61da18408c1 |
parent 54347 | 235883996bc7 |
child 54623 | 1126f0607c70 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
53587
739eaf4ac4ad
8213753: SymbolTable is double walked during class unloading and clean up table timing in do_unloading
coleenp
parents:
52951
diff
changeset
|
2 |
* Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved. |
1 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
2332
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
2332
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
2332
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 25 |
#include "precompiled.hpp" |
13087 | 26 |
#include "classfile/altHashing.hpp" |
51823 | 27 |
#include "classfile/compactHashtable.hpp" |
7397 | 28 |
#include "classfile/javaClasses.hpp" |
29 |
#include "classfile/symbolTable.hpp" |
|
12263
d20640f4f8fe
7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents:
11480
diff
changeset
|
30 |
#include "memory/allocation.inline.hpp" |
46746
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46742
diff
changeset
|
31 |
#include "memory/metaspaceClosure.hpp" |
51823 | 32 |
#include "memory/metaspaceShared.hpp" |
37248 | 33 |
#include "memory/resourceArea.hpp" |
7397 | 34 |
#include "oops/oop.inline.hpp" |
40655
9f644073d3a0
8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents:
39713
diff
changeset
|
35 |
#include "runtime/atomic.hpp" |
51405
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
36 |
#include "runtime/interfaceSupport.inline.hpp" |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
37 |
#include "runtime/timerTrace.hpp" |
46742 | 38 |
#include "services/diagnosticCommand.hpp" |
51405
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
39 |
#include "utilities/concurrentHashTable.inline.hpp" |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
40 |
#include "utilities/concurrentHashTableTasks.inline.hpp" |
54347
235883996bc7
8221698: Remove redundant includes from popular header files
iklam
parents:
54133
diff
changeset
|
41 |
#include "utilities/utf8.hpp" |
51405
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
42 |
|
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
43 |
// We used to not resize at all, so let's be conservative |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
44 |
// and not set it too short before we decide to resize, |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
45 |
// to match previous startup behavior |
52931
3b0fe3d6c3d7
8209387: Follow ups to JDK-8195100 Use a low latency hashtable for SymbolTable
gziemski
parents:
52516
diff
changeset
|
46 |
const double PREF_AVG_LIST_LEN = 8.0; |
51405
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
47 |
// 2^17 (131,072) is max size, which is about 6.5 times as large |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
48 |
// as the previous table size (used to be 20,011), |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
49 |
// which never resized |
52931
3b0fe3d6c3d7
8209387: Follow ups to JDK-8195100 Use a low latency hashtable for SymbolTable
gziemski
parents:
52516
diff
changeset
|
50 |
const size_t END_SIZE = 17; |
51405
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
51 |
// If a chain gets to 100 something might be wrong |
52931
3b0fe3d6c3d7
8209387: Follow ups to JDK-8195100 Use a low latency hashtable for SymbolTable
gziemski
parents:
52516
diff
changeset
|
52 |
const size_t REHASH_LEN = 100; |
51405
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
53 |
|
52931
3b0fe3d6c3d7
8209387: Follow ups to JDK-8195100 Use a low latency hashtable for SymbolTable
gziemski
parents:
52516
diff
changeset
|
54 |
const size_t ON_STACK_BUFFER_LENGTH = 128; |
1 | 55 |
|
56 |
// -------------------------------------------------------------------------- |
|
51823 | 57 |
|
58 |
inline bool symbol_equals_compact_hashtable_entry(Symbol* value, const char* key, int len) { |
|
59 |
if (value->equals(key, len)) { |
|
60 |
assert(value->refcount() == PERM_REFCOUNT, "must be shared"); |
|
61 |
return true; |
|
62 |
} else { |
|
63 |
return false; |
|
64 |
} |
|
65 |
} |
|
66 |
||
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52047
diff
changeset
|
67 |
static OffsetCompactHashtable< |
51823 | 68 |
const char*, Symbol*, |
69 |
symbol_equals_compact_hashtable_entry |
|
70 |
> _shared_table; |
|
71 |
||
72 |
// -------------------------------------------------------------------------- |
|
1 | 73 |
SymbolTable* SymbolTable::_the_table = NULL; |
51405
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
74 |
volatile bool SymbolTable::_alt_hash = false; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
75 |
volatile bool SymbolTable::_lookup_shared_first = false; |
12263
d20640f4f8fe
7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents:
11480
diff
changeset
|
76 |
// Static arena for symbols that are not deallocated |
d20640f4f8fe
7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents:
11480
diff
changeset
|
77 |
Arena* SymbolTable::_arena = NULL; |
51405
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
78 |
|
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
79 |
static juint murmur_seed = 0; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
80 |
|
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
81 |
static inline void log_trace_symboltable_helper(Symbol* sym, const char* msg) { |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
82 |
#ifndef PRODUCT |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
83 |
ResourceMark rm; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
84 |
log_trace(symboltable)("%s [%s]", msg, sym->as_quoted_ascii()); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
85 |
#endif // PRODUCT |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
86 |
} |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
87 |
|
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
88 |
// Pick hashing algorithm. |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
89 |
static uintx hash_symbol(const char* s, int len, bool useAlt) { |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
90 |
return useAlt ? |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
91 |
AltHashing::murmur3_32(murmur_seed, (const jbyte*)s, len) : |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
92 |
java_lang_String::hash_code((const jbyte*)s, len); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
93 |
} |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
94 |
|
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
95 |
static uintx hash_shared_symbol(const char* s, int len) { |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
96 |
return java_lang_String::hash_code((const jbyte*)s, len); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
97 |
} |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
98 |
|
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
99 |
class SymbolTableConfig : public SymbolTableHash::BaseConfig { |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
100 |
private: |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
101 |
public: |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
102 |
static uintx get_hash(Symbol* const& value, bool* is_dead) { |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
103 |
*is_dead = (value->refcount() == 0); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
104 |
if (*is_dead) { |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
105 |
return 0; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
106 |
} else { |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
107 |
return hash_symbol((const char*)value->bytes(), value->utf8_length(), SymbolTable::_alt_hash); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
108 |
} |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
109 |
} |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
110 |
// We use default allocation/deallocation but counted |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
111 |
static void* allocate_node(size_t size, Symbol* const& value) { |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
112 |
SymbolTable::item_added(); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
113 |
return SymbolTableHash::BaseConfig::allocate_node(size, value); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
114 |
} |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
115 |
static void free_node(void* memory, Symbol* const& value) { |
52951 | 116 |
// We get here because #1 some threads lost a race to insert a newly created Symbol |
117 |
// or #2 we're cleaning up unused symbol. |
|
118 |
// If #1, then the symbol can be either permanent (refcount==PERM_REFCOUNT), |
|
119 |
// or regular newly created one (refcount==1) |
|
120 |
// If #2, then the symbol is dead (refcount==0) |
|
121 |
assert((value->refcount() == PERM_REFCOUNT) || (value->refcount() == 1) || (value->refcount() == 0), |
|
51405
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
122 |
"refcount %d", value->refcount()); |
52951 | 123 |
if (value->refcount() == 1) { |
124 |
value->decrement_refcount(); |
|
125 |
assert(value->refcount() == 0, "expected dead symbol"); |
|
126 |
} |
|
51405
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
127 |
SymbolTable::delete_symbol(value); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
128 |
SymbolTableHash::BaseConfig::free_node(memory, value); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
129 |
SymbolTable::item_removed(); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
130 |
} |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
131 |
}; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
132 |
|
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
133 |
static size_t ceil_log2(size_t value) { |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
134 |
size_t ret; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
135 |
for (ret = 1; ((size_t)1 << ret) < value; ++ret); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
136 |
return ret; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
137 |
} |
28363
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
27677
diff
changeset
|
138 |
|
51405
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
139 |
SymbolTable::SymbolTable() : |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
140 |
_symbols_removed(0), _symbols_counted(0), _local_table(NULL), |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
141 |
_current_size(0), _has_work(0), _needs_rehashing(false), |
53587
739eaf4ac4ad
8213753: SymbolTable is double walked during class unloading and clean up table timing in do_unloading
coleenp
parents:
52951
diff
changeset
|
142 |
_items_count(0), _has_items_to_clean(false) { |
51405
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
143 |
|
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
144 |
size_t start_size_log_2 = ceil_log2(SymbolTableSize); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
145 |
_current_size = ((size_t)1) << start_size_log_2; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
146 |
log_trace(symboltable)("Start size: " SIZE_FORMAT " (" SIZE_FORMAT ")", |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
147 |
_current_size, start_size_log_2); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
148 |
_local_table = new SymbolTableHash(start_size_log_2, END_SIZE, REHASH_LEN); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
149 |
} |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
150 |
|
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
151 |
void SymbolTable::delete_symbol(Symbol* sym) { |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
152 |
if (sym->refcount() == PERM_REFCOUNT) { |
51520
ef7852ece52b
8209622: applications/kitchensink/Kitchensink.java failed with Kitchensink failed with exit code = 138
gziemski
parents:
51435
diff
changeset
|
153 |
MutexLockerEx ml(SymbolArena_lock, Mutex::_no_safepoint_check_flag); // Protect arena |
51405
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
154 |
// Deleting permanent symbol should not occur very often (insert race condition), |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
155 |
// so log it. |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
156 |
log_trace_symboltable_helper(sym, "Freeing permanent symbol"); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
157 |
if (!arena()->Afree(sym, sym->size())) { |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
158 |
log_trace_symboltable_helper(sym, "Leaked permanent symbol"); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
159 |
} |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
160 |
} else { |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
161 |
delete sym; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
162 |
} |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
163 |
} |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
164 |
|
52951 | 165 |
void SymbolTable::update_needs_rehash(bool rehash) { |
166 |
if (rehash) { |
|
167 |
_needs_rehashing = true; |
|
168 |
} |
|
169 |
} |
|
170 |
||
53587
739eaf4ac4ad
8213753: SymbolTable is double walked during class unloading and clean up table timing in do_unloading
coleenp
parents:
52951
diff
changeset
|
171 |
void SymbolTable::reset_has_items_to_clean() { Atomic::store(false, &_has_items_to_clean); } |
739eaf4ac4ad
8213753: SymbolTable is double walked during class unloading and clean up table timing in do_unloading
coleenp
parents:
52951
diff
changeset
|
172 |
void SymbolTable::mark_has_items_to_clean() { Atomic::store(true, &_has_items_to_clean); } |
739eaf4ac4ad
8213753: SymbolTable is double walked during class unloading and clean up table timing in do_unloading
coleenp
parents:
52951
diff
changeset
|
173 |
bool SymbolTable::has_items_to_clean() const { return Atomic::load(&_has_items_to_clean); } |
739eaf4ac4ad
8213753: SymbolTable is double walked during class unloading and clean up table timing in do_unloading
coleenp
parents:
52951
diff
changeset
|
174 |
|
51405
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
175 |
void SymbolTable::item_added() { |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
176 |
Atomic::inc(&(SymbolTable::the_table()->_items_count)); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
177 |
} |
1 | 178 |
|
51405
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
179 |
void SymbolTable::item_removed() { |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
180 |
Atomic::inc(&(SymbolTable::the_table()->_symbols_removed)); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
181 |
Atomic::dec(&(SymbolTable::the_table()->_items_count)); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
182 |
} |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
183 |
|
52931
3b0fe3d6c3d7
8209387: Follow ups to JDK-8195100 Use a low latency hashtable for SymbolTable
gziemski
parents:
52516
diff
changeset
|
184 |
double SymbolTable::get_load_factor() const { |
51405
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
185 |
return (double)_items_count/_current_size; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
186 |
} |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
187 |
|
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
188 |
size_t SymbolTable::table_size() { |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
189 |
return ((size_t)1) << _local_table->get_size_log2(Thread::current()); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
190 |
} |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
191 |
|
53587
739eaf4ac4ad
8213753: SymbolTable is double walked during class unloading and clean up table timing in do_unloading
coleenp
parents:
52951
diff
changeset
|
192 |
void SymbolTable::trigger_cleanup() { |
51405
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
193 |
MutexLockerEx ml(Service_lock, Mutex::_no_safepoint_check_flag); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
194 |
SymbolTable::the_table()->_has_work = true; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
195 |
Service_lock->notify_all(); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
196 |
} |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
197 |
|
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
198 |
Symbol* SymbolTable::allocate_symbol(const char* name, int len, bool c_heap, TRAPS) { |
13097
c146b608d91f
7178670: runtime/7158800/BadUtf8.java fails in SymbolTable::rehash_table
coleenp
parents:
13087
diff
changeset
|
199 |
assert (len <= Symbol::max_length(), "should be checked by caller"); |
c146b608d91f
7178670: runtime/7158800/BadUtf8.java fails in SymbolTable::rehash_table
coleenp
parents:
13087
diff
changeset
|
200 |
|
12263
d20640f4f8fe
7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents:
11480
diff
changeset
|
201 |
Symbol* sym; |
15934
104ff83451f1
8009829: CDS: JDK JPRT test fails crash in Symbol::equals()
coleenp
parents:
14742
diff
changeset
|
202 |
if (DumpSharedSpaces) { |
46746
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46742
diff
changeset
|
203 |
c_heap = false; |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46742
diff
changeset
|
204 |
} |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46742
diff
changeset
|
205 |
if (c_heap) { |
12263
d20640f4f8fe
7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents:
11480
diff
changeset
|
206 |
// refcount starts as 1 |
51405
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
207 |
sym = new (len, THREAD) Symbol((const u1*)name, len, 1); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13199
diff
changeset
|
208 |
assert(sym != NULL, "new should call vm_exit_out_of_memory if C_HEAP is exhausted"); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13199
diff
changeset
|
209 |
} else { |
15934
104ff83451f1
8009829: CDS: JDK JPRT test fails crash in Symbol::equals()
coleenp
parents:
14742
diff
changeset
|
210 |
// Allocate to global arena |
51520
ef7852ece52b
8209622: applications/kitchensink/Kitchensink.java failed with Kitchensink failed with exit code = 138
gziemski
parents:
51435
diff
changeset
|
211 |
MutexLockerEx ml(SymbolArena_lock, Mutex::_no_safepoint_check_flag); // Protect arena |
51405
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
212 |
sym = new (len, arena(), THREAD) Symbol((const u1*)name, len, PERM_REFCOUNT); |
12263
d20640f4f8fe
7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents:
11480
diff
changeset
|
213 |
} |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
214 |
return sym; |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
215 |
} |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
216 |
|
12263
d20640f4f8fe
7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents:
11480
diff
changeset
|
217 |
void SymbolTable::initialize_symbols(int arena_alloc_size) { |
d20640f4f8fe
7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents:
11480
diff
changeset
|
218 |
// Initialize the arena for global symbols, size passed in depends on CDS. |
d20640f4f8fe
7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents:
11480
diff
changeset
|
219 |
if (arena_alloc_size == 0) { |
25946 | 220 |
_arena = new (mtSymbol) Arena(mtSymbol); |
12263
d20640f4f8fe
7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents:
11480
diff
changeset
|
221 |
} else { |
25946 | 222 |
_arena = new (mtSymbol) Arena(mtSymbol, arena_alloc_size); |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
223 |
} |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
224 |
} |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
225 |
|
51405
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
226 |
class SymbolsDo : StackObj { |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
227 |
SymbolClosure *_cl; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
228 |
public: |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
229 |
SymbolsDo(SymbolClosure *cl) : _cl(cl) {} |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
230 |
bool operator()(Symbol** value) { |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
231 |
assert(value != NULL, "expected valid value"); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
232 |
assert(*value != NULL, "value should point to a symbol"); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
233 |
_cl->do_symbol(value); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
234 |
return true; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
235 |
}; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
236 |
}; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
237 |
|
51823 | 238 |
class SharedSymbolIterator { |
239 |
SymbolClosure* _symbol_closure; |
|
240 |
public: |
|
241 |
SharedSymbolIterator(SymbolClosure* f) : _symbol_closure(f) {} |
|
242 |
void do_value(Symbol* symbol) { |
|
243 |
_symbol_closure->do_symbol(&symbol); |
|
244 |
} |
|
245 |
}; |
|
246 |
||
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
247 |
// Call function for all symbols in the symbol table. |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
248 |
void SymbolTable::symbols_do(SymbolClosure *cl) { |
28615
1fb960ea5a7e
8067982: Some jcmd /gc/heap_dump tests failed: hprof output contains warning or error.
jiangli
parents:
28363
diff
changeset
|
249 |
// all symbols from shared table |
51823 | 250 |
SharedSymbolIterator iter(cl); |
251 |
_shared_table.iterate(&iter); |
|
28615
1fb960ea5a7e
8067982: Some jcmd /gc/heap_dump tests failed: hprof output contains warning or error.
jiangli
parents:
28363
diff
changeset
|
252 |
|
1fb960ea5a7e
8067982: Some jcmd /gc/heap_dump tests failed: hprof output contains warning or error.
jiangli
parents:
28363
diff
changeset
|
253 |
// all symbols from the dynamic table |
51405
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
254 |
SymbolsDo sd(cl); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
255 |
if (!SymbolTable::the_table()->_local_table->try_scan(Thread::current(), sd)) { |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
256 |
log_info(stringtable)("symbols_do unavailable at this moment"); |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
257 |
} |
22545
b93a7f0e9b9d
8027476: Improve performance of Stringtable unlink
tschatzl
parents:
20283
diff
changeset
|
258 |
} |
b93a7f0e9b9d
8027476: Improve performance of Stringtable unlink
tschatzl
parents:
20283
diff
changeset
|
259 |
|
51405
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
260 |
class MetaspacePointersDo : StackObj { |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
261 |
MetaspaceClosure *_it; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
262 |
public: |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
263 |
MetaspacePointersDo(MetaspaceClosure *it) : _it(it) {} |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
264 |
bool operator()(Symbol** value) { |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
265 |
assert(value != NULL, "expected valid value"); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
266 |
assert(*value != NULL, "value should point to a symbol"); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
267 |
_it->push(value); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
268 |
return true; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
269 |
}; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
270 |
}; |
22545
b93a7f0e9b9d
8027476: Improve performance of Stringtable unlink
tschatzl
parents:
20283
diff
changeset
|
271 |
|
51405
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
272 |
void SymbolTable::metaspace_pointers_do(MetaspaceClosure* it) { |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
273 |
assert(DumpSharedSpaces, "called only during dump time"); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
274 |
MetaspacePointersDo mpd(it); |
52516
d5eebe1e03fe
8213574: Deadlock in string table expansion when dumping lots of CDS classes
rehn
parents:
52514
diff
changeset
|
275 |
SymbolTable::the_table()->_local_table->do_safepoint_scan(mpd); |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
276 |
} |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
277 |
|
51405
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
278 |
Symbol* SymbolTable::lookup_dynamic(const char* name, |
28363
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
27677
diff
changeset
|
279 |
int len, unsigned int hash) { |
51405
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
280 |
Symbol* sym = SymbolTable::the_table()->do_lookup(name, len, hash); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
281 |
assert((sym == NULL) || sym->refcount() != 0, "refcount must not be zero"); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
282 |
return sym; |
1 | 283 |
} |
284 |
||
28363
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
27677
diff
changeset
|
285 |
Symbol* SymbolTable::lookup_shared(const char* name, |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
27677
diff
changeset
|
286 |
int len, unsigned int hash) { |
51405
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
287 |
if (!_shared_table.empty()) { |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
288 |
if (SymbolTable::_alt_hash) { |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
289 |
// hash_code parameter may use alternate hashing algorithm but the shared table |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
290 |
// always uses the same original hash code. |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
291 |
hash = hash_shared_symbol(name, len); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
292 |
} |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
293 |
return _shared_table.lookup(name, hash, len); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
294 |
} else { |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
295 |
return NULL; |
37198
b96542d1afa1
8152380: Shared symbol table should never use alternate hashcode
iklam
parents:
35898
diff
changeset
|
296 |
} |
28363
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
27677
diff
changeset
|
297 |
} |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
27677
diff
changeset
|
298 |
|
51405
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
299 |
Symbol* SymbolTable::lookup_common(const char* name, |
28363
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
27677
diff
changeset
|
300 |
int len, unsigned int hash) { |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
27677
diff
changeset
|
301 |
Symbol* sym; |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
27677
diff
changeset
|
302 |
if (_lookup_shared_first) { |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
27677
diff
changeset
|
303 |
sym = lookup_shared(name, len, hash); |
51405
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
304 |
if (sym == NULL) { |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
305 |
_lookup_shared_first = false; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
306 |
sym = lookup_dynamic(name, len, hash); |
28363
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
27677
diff
changeset
|
307 |
} |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
27677
diff
changeset
|
308 |
} else { |
51405
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
309 |
sym = lookup_dynamic(name, len, hash); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
310 |
if (sym == NULL) { |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
311 |
sym = lookup_shared(name, len, hash); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
312 |
if (sym != NULL) { |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
313 |
_lookup_shared_first = true; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
314 |
} |
28363
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
27677
diff
changeset
|
315 |
} |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
27677
diff
changeset
|
316 |
} |
51405
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
317 |
return sym; |
28363
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
27677
diff
changeset
|
318 |
} |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
27677
diff
changeset
|
319 |
|
51405
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
320 |
Symbol* SymbolTable::lookup(const char* name, int len, TRAPS) { |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
321 |
unsigned int hash = hash_symbol(name, len, SymbolTable::_alt_hash); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
322 |
Symbol* sym = SymbolTable::the_table()->lookup_common(name, len, hash); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
323 |
if (sym == NULL) { |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
324 |
sym = SymbolTable::the_table()->do_add_if_needed(name, len, hash, true, CHECK_NULL); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
325 |
} |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
326 |
assert(sym->refcount() != 0, "lookup should have incremented the count"); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
327 |
assert(sym->equals(name, len), "symbol must be properly initialized"); |
39713 | 328 |
return sym; |
329 |
} |
|
330 |
||
51405
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
331 |
Symbol* SymbolTable::lookup(const Symbol* sym, int begin, int end, TRAPS) { |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
332 |
assert(sym->refcount() != 0, "require a valid symbol"); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
333 |
const char* name = (const char*)sym->base() + begin; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
334 |
int len = end - begin; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
335 |
unsigned int hash = hash_symbol(name, len, SymbolTable::_alt_hash); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
336 |
Symbol* found = SymbolTable::the_table()->lookup_common(name, len, hash); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
337 |
if (found == NULL) { |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
338 |
found = SymbolTable::the_table()->do_add_if_needed(name, len, hash, true, THREAD); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
339 |
} |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
340 |
return found; |
1 | 341 |
} |
342 |
||
51405
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
343 |
class SymbolTableLookup : StackObj { |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
344 |
private: |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
345 |
Thread* _thread; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
346 |
uintx _hash; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
347 |
int _len; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
348 |
const char* _str; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
349 |
public: |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
350 |
SymbolTableLookup(Thread* thread, const char* key, int len, uintx hash) |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
351 |
: _thread(thread), _hash(hash), _len(len), _str(key) {} |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
352 |
uintx get_hash() const { |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
353 |
return _hash; |
1 | 354 |
} |
51405
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
355 |
bool equals(Symbol** value, bool* is_dead) { |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
356 |
assert(value != NULL, "expected valid value"); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
357 |
assert(*value != NULL, "value should point to a symbol"); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
358 |
Symbol *sym = *value; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
359 |
if (sym->equals(_str, _len)) { |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
360 |
if (sym->try_increment_refcount()) { |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
361 |
// something is referencing this symbol now. |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
362 |
return true; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
363 |
} else { |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
364 |
assert(sym->refcount() == 0, "expected dead symbol"); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
365 |
*is_dead = true; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
366 |
return false; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
367 |
} |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
368 |
} else { |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
369 |
*is_dead = (sym->refcount() == 0); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
370 |
return false; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
371 |
} |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
372 |
} |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
373 |
}; |
1 | 374 |
|
51405
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
375 |
class SymbolTableGet : public StackObj { |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
376 |
Symbol* _return; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
377 |
public: |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
378 |
SymbolTableGet() : _return(NULL) {} |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
379 |
void operator()(Symbol** value) { |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
380 |
assert(value != NULL, "expected valid value"); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
381 |
assert(*value != NULL, "value should point to a symbol"); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
382 |
_return = *value; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
383 |
} |
52931
3b0fe3d6c3d7
8209387: Follow ups to JDK-8195100 Use a low latency hashtable for SymbolTable
gziemski
parents:
52516
diff
changeset
|
384 |
Symbol* get_res_sym() const { |
51405
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
385 |
return _return; |
1 | 386 |
} |
51405
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
387 |
}; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
388 |
|
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
389 |
Symbol* SymbolTable::do_lookup(const char* name, int len, uintx hash) { |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
390 |
Thread* thread = Thread::current(); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
391 |
SymbolTableLookup lookup(thread, name, len, hash); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
392 |
SymbolTableGet stg; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
393 |
bool rehash_warning = false; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
394 |
_local_table->get(thread, lookup, stg, &rehash_warning); |
52951 | 395 |
update_needs_rehash(rehash_warning); |
51405
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
396 |
Symbol* sym = stg.get_res_sym(); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
397 |
assert((sym == NULL) || sym->refcount() != 0, "found dead symbol"); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
398 |
return sym; |
1 | 399 |
} |
400 |
||
51405
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
401 |
Symbol* SymbolTable::lookup_only(const char* name, int len, unsigned int& hash) { |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
402 |
hash = hash_symbol(name, len, SymbolTable::_alt_hash); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
403 |
return SymbolTable::the_table()->lookup_common(name, len, hash); |
11480
1bf714e8adb4
7115199: Add event tracing hooks and Java Flight Recorder infrastructure
phh
parents:
8885
diff
changeset
|
404 |
} |
1bf714e8adb4
7115199: Add event tracing hooks and Java Flight Recorder infrastructure
phh
parents:
8885
diff
changeset
|
405 |
|
2332
5c7b6f4ce0a1
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
2131
diff
changeset
|
406 |
// Suggestion: Push unicode-based lookup all the way into the hashing |
5c7b6f4ce0a1
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
2131
diff
changeset
|
407 |
// and probing logic, so there is no need for convert_to_utf8 until |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
408 |
// an actual new Symbol* is created. |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
409 |
Symbol* SymbolTable::lookup_unicode(const jchar* name, int utf16_length, TRAPS) { |
2332
5c7b6f4ce0a1
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
2131
diff
changeset
|
410 |
int utf8_length = UNICODE::utf8_length((jchar*) name, utf16_length); |
51405
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
411 |
char stack_buf[ON_STACK_BUFFER_LENGTH]; |
2332
5c7b6f4ce0a1
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
2131
diff
changeset
|
412 |
if (utf8_length < (int) sizeof(stack_buf)) { |
5c7b6f4ce0a1
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
2131
diff
changeset
|
413 |
char* chars = stack_buf; |
5c7b6f4ce0a1
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
2131
diff
changeset
|
414 |
UNICODE::convert_to_utf8(name, utf16_length, chars); |
5c7b6f4ce0a1
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
2131
diff
changeset
|
415 |
return lookup(chars, utf8_length, THREAD); |
5c7b6f4ce0a1
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
2131
diff
changeset
|
416 |
} else { |
5c7b6f4ce0a1
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
2131
diff
changeset
|
417 |
ResourceMark rm(THREAD); |
51405
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
418 |
char* chars = NEW_RESOURCE_ARRAY(char, utf8_length + 1); |
2332
5c7b6f4ce0a1
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
2131
diff
changeset
|
419 |
UNICODE::convert_to_utf8(name, utf16_length, chars); |
5c7b6f4ce0a1
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
2131
diff
changeset
|
420 |
return lookup(chars, utf8_length, THREAD); |
5c7b6f4ce0a1
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
2131
diff
changeset
|
421 |
} |
5c7b6f4ce0a1
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
2131
diff
changeset
|
422 |
} |
5c7b6f4ce0a1
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
2131
diff
changeset
|
423 |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
424 |
Symbol* SymbolTable::lookup_only_unicode(const jchar* name, int utf16_length, |
2332
5c7b6f4ce0a1
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
2131
diff
changeset
|
425 |
unsigned int& hash) { |
5c7b6f4ce0a1
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
2131
diff
changeset
|
426 |
int utf8_length = UNICODE::utf8_length((jchar*) name, utf16_length); |
51405
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
427 |
char stack_buf[ON_STACK_BUFFER_LENGTH]; |
2332
5c7b6f4ce0a1
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
2131
diff
changeset
|
428 |
if (utf8_length < (int) sizeof(stack_buf)) { |
5c7b6f4ce0a1
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
2131
diff
changeset
|
429 |
char* chars = stack_buf; |
5c7b6f4ce0a1
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
2131
diff
changeset
|
430 |
UNICODE::convert_to_utf8(name, utf16_length, chars); |
5c7b6f4ce0a1
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
2131
diff
changeset
|
431 |
return lookup_only(chars, utf8_length, hash); |
5c7b6f4ce0a1
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
2131
diff
changeset
|
432 |
} else { |
5c7b6f4ce0a1
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
2131
diff
changeset
|
433 |
ResourceMark rm; |
51405
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
434 |
char* chars = NEW_RESOURCE_ARRAY(char, utf8_length + 1); |
2332
5c7b6f4ce0a1
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
2131
diff
changeset
|
435 |
UNICODE::convert_to_utf8(name, utf16_length, chars); |
5c7b6f4ce0a1
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
2131
diff
changeset
|
436 |
return lookup_only(chars, utf8_length, hash); |
5c7b6f4ce0a1
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
2131
diff
changeset
|
437 |
} |
5c7b6f4ce0a1
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
2131
diff
changeset
|
438 |
} |
5c7b6f4ce0a1
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
2131
diff
changeset
|
439 |
|
53898
853b82a25d53
8219554: Redundant lookup_common in SymbolTable::add
redestad
parents:
53587
diff
changeset
|
440 |
void SymbolTable::new_symbols(ClassLoaderData* loader_data, const constantPoolHandle& cp, |
853b82a25d53
8219554: Redundant lookup_common in SymbolTable::add
redestad
parents:
53587
diff
changeset
|
441 |
int names_count, const char** names, int* lengths, |
853b82a25d53
8219554: Redundant lookup_common in SymbolTable::add
redestad
parents:
53587
diff
changeset
|
442 |
int* cp_indices, unsigned int* hashValues, TRAPS) { |
51405
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
443 |
bool c_heap = !loader_data->is_the_null_class_loader_data(); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
444 |
for (int i = 0; i < names_count; i++) { |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
445 |
const char *name = names[i]; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
446 |
int len = lengths[i]; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
447 |
unsigned int hash = hashValues[i]; |
53898
853b82a25d53
8219554: Redundant lookup_common in SymbolTable::add
redestad
parents:
53587
diff
changeset
|
448 |
assert(SymbolTable::the_table()->lookup_shared(name, len, hash) == NULL, "must have checked already"); |
853b82a25d53
8219554: Redundant lookup_common in SymbolTable::add
redestad
parents:
53587
diff
changeset
|
449 |
Symbol* sym = SymbolTable::the_table()->do_add_if_needed(name, len, hash, c_heap, CHECK); |
51405
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
450 |
assert(sym->refcount() != 0, "lookup should have incremented the count"); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
451 |
cp->symbol_at_put(cp_indices[i], sym); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
452 |
} |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
453 |
} |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
454 |
|
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
455 |
Symbol* SymbolTable::do_add_if_needed(const char* name, int len, uintx hash, bool heap, TRAPS) { |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
456 |
SymbolTableLookup lookup(THREAD, name, len, hash); |
52951 | 457 |
SymbolTableGet stg; |
51405
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
458 |
bool clean_hint = false; |
52951 | 459 |
bool rehash_warning = false; |
460 |
Symbol* sym = NULL; |
|
461 |
||
462 |
do { |
|
463 |
if (_local_table->get(THREAD, lookup, stg, &rehash_warning)) { |
|
464 |
sym = stg.get_res_sym(); |
|
465 |
break; |
|
466 |
} |
|
467 |
sym = SymbolTable::the_table()->allocate_symbol(name, len, heap, THREAD); |
|
468 |
if (_local_table->insert(THREAD, lookup, sym, &rehash_warning, &clean_hint)) { |
|
469 |
break; |
|
470 |
} |
|
471 |
} while(true); |
|
472 |
||
473 |
update_needs_rehash(rehash_warning); |
|
474 |
||
51405
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
475 |
if (clean_hint) { |
53587
739eaf4ac4ad
8213753: SymbolTable is double walked during class unloading and clean up table timing in do_unloading
coleenp
parents:
52951
diff
changeset
|
476 |
mark_has_items_to_clean(); |
51405
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
477 |
check_concurrent_work(); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
478 |
} |
52951 | 479 |
|
480 |
assert((sym == NULL) || sym->refcount() != 0, "found dead symbol"); |
|
51405
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
481 |
return sym; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
482 |
} |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
483 |
|
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
484 |
Symbol* SymbolTable::new_permanent_symbol(const char* name, TRAPS) { |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
485 |
unsigned int hash = 0; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
486 |
int len = (int)strlen(name); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
487 |
Symbol* sym = SymbolTable::lookup_only(name, len, hash); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
488 |
if (sym == NULL) { |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
489 |
sym = SymbolTable::the_table()->do_add_if_needed(name, len, hash, false, CHECK_NULL); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
490 |
} |
54133
829bf950287e
8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents:
53898
diff
changeset
|
491 |
if (!sym->is_permanent()) { |
829bf950287e
8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents:
53898
diff
changeset
|
492 |
sym->make_permanent(); |
51405
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
493 |
log_trace_symboltable_helper(sym, "Asked for a permanent symbol, but got a regular one"); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
494 |
} |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
495 |
return sym; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
496 |
} |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
497 |
|
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
498 |
struct SizeFunc : StackObj { |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
499 |
size_t operator()(Symbol** value) { |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
500 |
assert(value != NULL, "expected valid value"); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
501 |
assert(*value != NULL, "value should point to a symbol"); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
502 |
return (*value)->size() * HeapWordSize; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
503 |
}; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
504 |
}; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
505 |
|
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
506 |
void SymbolTable::print_table_statistics(outputStream* st, |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
507 |
const char* table_name) { |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
508 |
SizeFunc sz; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
509 |
_local_table->statistics_to(Thread::current(), sz, st, table_name); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
510 |
} |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
511 |
|
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
512 |
// Verification |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
513 |
class VerifySymbols : StackObj { |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
514 |
public: |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
515 |
bool operator()(Symbol** value) { |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
516 |
guarantee(value != NULL, "expected valid value"); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
517 |
guarantee(*value != NULL, "value should point to a symbol"); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
518 |
Symbol* sym = *value; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
519 |
guarantee(sym->equals((const char*)sym->bytes(), sym->utf8_length()), |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
520 |
"symbol must be internally consistent"); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
521 |
return true; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
522 |
}; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
523 |
}; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
524 |
|
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
525 |
void SymbolTable::verify() { |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
526 |
Thread* thr = Thread::current(); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
527 |
VerifySymbols vs; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
528 |
if (!SymbolTable::the_table()->_local_table->try_scan(thr, vs)) { |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
529 |
log_info(stringtable)("verify unavailable at this moment"); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
530 |
} |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
531 |
} |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
532 |
|
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
533 |
// Dumping |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
534 |
class DumpSymbol : StackObj { |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
535 |
Thread* _thr; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
536 |
outputStream* _st; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
537 |
public: |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
538 |
DumpSymbol(Thread* thr, outputStream* st) : _thr(thr), _st(st) {} |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
539 |
bool operator()(Symbol** value) { |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
540 |
assert(value != NULL, "expected valid value"); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
541 |
assert(*value != NULL, "value should point to a symbol"); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
542 |
Symbol* sym = *value; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
543 |
const char* utf8_string = (const char*)sym->bytes(); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
544 |
int utf8_length = sym->utf8_length(); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
545 |
_st->print("%d %d: ", utf8_length, sym->refcount()); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
546 |
HashtableTextDump::put_utf8(_st, utf8_string, utf8_length); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
547 |
_st->cr(); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
548 |
return true; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
549 |
}; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
550 |
}; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
551 |
|
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
552 |
void SymbolTable::dump(outputStream* st, bool verbose) { |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
553 |
if (!verbose) { |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
554 |
SymbolTable::the_table()->print_table_statistics(st, "SymbolTable"); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
555 |
} else { |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
556 |
Thread* thr = Thread::current(); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
557 |
ResourceMark rm(thr); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
558 |
st->print_cr("VERSION: 1.1"); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
559 |
DumpSymbol ds(thr, st); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
560 |
if (!SymbolTable::the_table()->_local_table->try_scan(thr, ds)) { |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
561 |
log_info(symboltable)("dump unavailable at this moment"); |
1 | 562 |
} |
563 |
} |
|
564 |
} |
|
565 |
||
51405
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
566 |
#if INCLUDE_CDS |
52047
7bc8b456e5ac
8210388: Use hash table to store archived subgraph_info records
iklam
parents:
51997
diff
changeset
|
567 |
struct CopyToArchive : StackObj { |
7bc8b456e5ac
8210388: Use hash table to store archived subgraph_info records
iklam
parents:
51997
diff
changeset
|
568 |
CompactHashtableWriter* _writer; |
7bc8b456e5ac
8210388: Use hash table to store archived subgraph_info records
iklam
parents:
51997
diff
changeset
|
569 |
CopyToArchive(CompactHashtableWriter* writer) : _writer(writer) {} |
7bc8b456e5ac
8210388: Use hash table to store archived subgraph_info records
iklam
parents:
51997
diff
changeset
|
570 |
bool operator()(Symbol** value) { |
7bc8b456e5ac
8210388: Use hash table to store archived subgraph_info records
iklam
parents:
51997
diff
changeset
|
571 |
assert(value != NULL, "expected valid value"); |
7bc8b456e5ac
8210388: Use hash table to store archived subgraph_info records
iklam
parents:
51997
diff
changeset
|
572 |
assert(*value != NULL, "value should point to a symbol"); |
7bc8b456e5ac
8210388: Use hash table to store archived subgraph_info records
iklam
parents:
51997
diff
changeset
|
573 |
Symbol* sym = *value; |
7bc8b456e5ac
8210388: Use hash table to store archived subgraph_info records
iklam
parents:
51997
diff
changeset
|
574 |
unsigned int fixed_hash = hash_shared_symbol((const char*)sym->bytes(), sym->utf8_length()); |
7bc8b456e5ac
8210388: Use hash table to store archived subgraph_info records
iklam
parents:
51997
diff
changeset
|
575 |
assert(fixed_hash == hash_symbol((const char*)sym->bytes(), sym->utf8_length(), false), |
7bc8b456e5ac
8210388: Use hash table to store archived subgraph_info records
iklam
parents:
51997
diff
changeset
|
576 |
"must not rehash during dumping"); |
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52047
diff
changeset
|
577 |
_writer->add(fixed_hash, MetaspaceShared::object_delta_u4(sym)); |
51405
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
578 |
return true; |
1 | 579 |
} |
51405
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
580 |
}; |
1 | 581 |
|
52047
7bc8b456e5ac
8210388: Use hash table to store archived subgraph_info records
iklam
parents:
51997
diff
changeset
|
582 |
void SymbolTable::copy_shared_symbol_table(CompactHashtableWriter* writer) { |
51405
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
583 |
CopyToArchive copy(writer); |
52516
d5eebe1e03fe
8213574: Deadlock in string table expansion when dumping lots of CDS classes
rehn
parents:
52514
diff
changeset
|
584 |
SymbolTable::the_table()->_local_table->do_safepoint_scan(copy); |
13087 | 585 |
} |
586 |
||
46746
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46742
diff
changeset
|
587 |
void SymbolTable::write_to_archive() { |
51405
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
588 |
_shared_table.reset(); |
46746
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46742
diff
changeset
|
589 |
|
52047
7bc8b456e5ac
8210388: Use hash table to store archived subgraph_info records
iklam
parents:
51997
diff
changeset
|
590 |
int num_buckets = CompactHashtableWriter::default_num_buckets( |
7bc8b456e5ac
8210388: Use hash table to store archived subgraph_info records
iklam
parents:
51997
diff
changeset
|
591 |
SymbolTable::the_table()->_items_count); |
7bc8b456e5ac
8210388: Use hash table to store archived subgraph_info records
iklam
parents:
51997
diff
changeset
|
592 |
CompactHashtableWriter writer(num_buckets, |
7bc8b456e5ac
8210388: Use hash table to store archived subgraph_info records
iklam
parents:
51997
diff
changeset
|
593 |
&MetaspaceShared::stats()->symbol); |
51405
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
594 |
copy_shared_symbol_table(&writer); |
51823 | 595 |
writer.dump(&_shared_table, "symbol"); |
37995 | 596 |
|
51405
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
597 |
// Verify table is correct |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
598 |
Symbol* sym = vmSymbols::java_lang_Object(); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
599 |
const char* name = (const char*)sym->bytes(); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
600 |
int len = sym->utf8_length(); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
601 |
unsigned int hash = hash_symbol(name, len, SymbolTable::_alt_hash); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
602 |
assert(sym == _shared_table.lookup(name, hash, len), "sanity"); |
46746
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46742
diff
changeset
|
603 |
} |
28363
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
27677
diff
changeset
|
604 |
|
52047
7bc8b456e5ac
8210388: Use hash table to store archived subgraph_info records
iklam
parents:
51997
diff
changeset
|
605 |
void SymbolTable::serialize_shared_table_header(SerializeClosure* soc) { |
7bc8b456e5ac
8210388: Use hash table to store archived subgraph_info records
iklam
parents:
51997
diff
changeset
|
606 |
_shared_table.serialize_header(soc); |
46746
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46742
diff
changeset
|
607 |
|
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46742
diff
changeset
|
608 |
if (soc->writing()) { |
37995 | 609 |
// Sanity. Make sure we don't use the shared table at dump time |
610 |
_shared_table.reset(); |
|
611 |
} |
|
51405
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
612 |
} |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
613 |
#endif //INCLUDE_CDS |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
614 |
|
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
615 |
// Concurrent work |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
616 |
void SymbolTable::grow(JavaThread* jt) { |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
617 |
SymbolTableHash::GrowTask gt(_local_table); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
618 |
if (!gt.prepare(jt)) { |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
619 |
return; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
620 |
} |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
621 |
log_trace(symboltable)("Started to grow"); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
622 |
{ |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
623 |
TraceTime timer("Grow", TRACETIME_LOG(Debug, symboltable, perf)); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
624 |
while (gt.do_task(jt)) { |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
625 |
gt.pause(jt); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
626 |
{ |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
627 |
ThreadBlockInVM tbivm(jt); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
628 |
} |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
629 |
gt.cont(jt); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
630 |
} |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
631 |
} |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
632 |
gt.done(jt); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
633 |
_current_size = table_size(); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
634 |
log_debug(symboltable)("Grown to size:" SIZE_FORMAT, _current_size); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
635 |
} |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
636 |
|
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
637 |
struct SymbolTableDoDelete : StackObj { |
52931
3b0fe3d6c3d7
8209387: Follow ups to JDK-8195100 Use a low latency hashtable for SymbolTable
gziemski
parents:
52516
diff
changeset
|
638 |
size_t _deleted; |
51405
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
639 |
SymbolTableDoDelete() : _deleted(0) {} |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
640 |
void operator()(Symbol** value) { |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
641 |
assert(value != NULL, "expected valid value"); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
642 |
assert(*value != NULL, "value should point to a symbol"); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
643 |
Symbol *sym = *value; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
644 |
assert(sym->refcount() == 0, "refcount"); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
645 |
_deleted++; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
646 |
} |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
647 |
}; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
648 |
|
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
649 |
struct SymbolTableDeleteCheck : StackObj { |
52931
3b0fe3d6c3d7
8209387: Follow ups to JDK-8195100 Use a low latency hashtable for SymbolTable
gziemski
parents:
52516
diff
changeset
|
650 |
size_t _processed; |
51405
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
651 |
SymbolTableDeleteCheck() : _processed(0) {} |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
652 |
bool operator()(Symbol** value) { |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
653 |
assert(value != NULL, "expected valid value"); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
654 |
assert(*value != NULL, "value should point to a symbol"); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
655 |
_processed++; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
656 |
Symbol *sym = *value; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
657 |
return (sym->refcount() == 0); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
658 |
} |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
659 |
}; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
660 |
|
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
661 |
void SymbolTable::clean_dead_entries(JavaThread* jt) { |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
662 |
SymbolTableHash::BulkDeleteTask bdt(_local_table); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
663 |
if (!bdt.prepare(jt)) { |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
664 |
return; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
665 |
} |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
666 |
|
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
667 |
SymbolTableDeleteCheck stdc; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
668 |
SymbolTableDoDelete stdd; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
669 |
{ |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
670 |
TraceTime timer("Clean", TRACETIME_LOG(Debug, symboltable, perf)); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
671 |
while (bdt.do_task(jt, stdc, stdd)) { |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
672 |
bdt.pause(jt); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
673 |
{ |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
674 |
ThreadBlockInVM tbivm(jt); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
675 |
} |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
676 |
bdt.cont(jt); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
677 |
} |
53587
739eaf4ac4ad
8213753: SymbolTable is double walked during class unloading and clean up table timing in do_unloading
coleenp
parents:
52951
diff
changeset
|
678 |
SymbolTable::the_table()->reset_has_items_to_clean(); |
51405
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
679 |
bdt.done(jt); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
680 |
} |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
681 |
|
52931
3b0fe3d6c3d7
8209387: Follow ups to JDK-8195100 Use a low latency hashtable for SymbolTable
gziemski
parents:
52516
diff
changeset
|
682 |
Atomic::add(stdc._processed, &_symbols_counted); |
51405
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
683 |
|
52931
3b0fe3d6c3d7
8209387: Follow ups to JDK-8195100 Use a low latency hashtable for SymbolTable
gziemski
parents:
52516
diff
changeset
|
684 |
log_debug(symboltable)("Cleaned " SIZE_FORMAT " of " SIZE_FORMAT, |
51405
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
685 |
stdd._deleted, stdc._processed); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
686 |
} |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
687 |
|
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
688 |
void SymbolTable::check_concurrent_work() { |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
689 |
if (_has_work) { |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
690 |
return; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
691 |
} |
53587
739eaf4ac4ad
8213753: SymbolTable is double walked during class unloading and clean up table timing in do_unloading
coleenp
parents:
52951
diff
changeset
|
692 |
// We should clean/resize if we have |
51405
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
693 |
// more items than preferred load factor or |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
694 |
// more dead items than water mark. |
53587
739eaf4ac4ad
8213753: SymbolTable is double walked during class unloading and clean up table timing in do_unloading
coleenp
parents:
52951
diff
changeset
|
695 |
if (has_items_to_clean() || (get_load_factor() > PREF_AVG_LIST_LEN)) { |
739eaf4ac4ad
8213753: SymbolTable is double walked during class unloading and clean up table timing in do_unloading
coleenp
parents:
52951
diff
changeset
|
696 |
log_debug(symboltable)("Concurrent work triggered, load factor: %f, items to clean: %s", |
739eaf4ac4ad
8213753: SymbolTable is double walked during class unloading and clean up table timing in do_unloading
coleenp
parents:
52951
diff
changeset
|
697 |
get_load_factor(), has_items_to_clean() ? "true" : "false"); |
739eaf4ac4ad
8213753: SymbolTable is double walked during class unloading and clean up table timing in do_unloading
coleenp
parents:
52951
diff
changeset
|
698 |
trigger_cleanup(); |
51405
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
699 |
} |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
700 |
} |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
701 |
|
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
702 |
void SymbolTable::concurrent_work(JavaThread* jt) { |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
703 |
double load_factor = get_load_factor(); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
704 |
log_debug(symboltable, perf)("Concurrent work, live factor: %g", load_factor); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
705 |
// We prefer growing, since that also removes dead items |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
706 |
if (load_factor > PREF_AVG_LIST_LEN && !_local_table->is_max_size_reached()) { |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
707 |
grow(jt); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
708 |
} else { |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
709 |
clean_dead_entries(jt); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
710 |
} |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
711 |
_has_work = false; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
712 |
} |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
713 |
|
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
714 |
void SymbolTable::do_concurrent_work(JavaThread* jt) { |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
715 |
SymbolTable::the_table()->concurrent_work(jt); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
716 |
} |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
717 |
|
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
718 |
// Rehash |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
719 |
bool SymbolTable::do_rehash() { |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
720 |
if (!_local_table->is_safepoint_safe()) { |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
721 |
return false; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
722 |
} |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
723 |
|
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
724 |
// We use max size |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
725 |
SymbolTableHash* new_table = new SymbolTableHash(END_SIZE, END_SIZE, REHASH_LEN); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
726 |
// Use alt hash from now on |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
727 |
_alt_hash = true; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
728 |
if (!_local_table->try_move_nodes_to(Thread::current(), new_table)) { |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
729 |
_alt_hash = false; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
730 |
delete new_table; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
731 |
return false; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
732 |
} |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
733 |
|
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
734 |
// free old table |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
735 |
delete _local_table; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
736 |
_local_table = new_table; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
737 |
|
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
738 |
return true; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
739 |
} |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
740 |
|
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
741 |
void SymbolTable::try_rehash_table() { |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
742 |
static bool rehashed = false; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
743 |
log_debug(symboltable)("Table imbalanced, rehashing called."); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
744 |
|
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
745 |
// Grow instead of rehash. |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
746 |
if (get_load_factor() > PREF_AVG_LIST_LEN && |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
747 |
!_local_table->is_max_size_reached()) { |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
748 |
log_debug(symboltable)("Choosing growing over rehashing."); |
53587
739eaf4ac4ad
8213753: SymbolTable is double walked during class unloading and clean up table timing in do_unloading
coleenp
parents:
52951
diff
changeset
|
749 |
trigger_cleanup(); |
51405
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
750 |
_needs_rehashing = false; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
751 |
return; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
752 |
} |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
753 |
|
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
754 |
// Already rehashed. |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
755 |
if (rehashed) { |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
756 |
log_warning(symboltable)("Rehashing already done, still long lists."); |
53587
739eaf4ac4ad
8213753: SymbolTable is double walked during class unloading and clean up table timing in do_unloading
coleenp
parents:
52951
diff
changeset
|
757 |
trigger_cleanup(); |
51405
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
758 |
_needs_rehashing = false; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
759 |
return; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
760 |
} |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
761 |
|
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
762 |
murmur_seed = AltHashing::compute_seed(); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
763 |
|
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
764 |
if (do_rehash()) { |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
765 |
rehashed = true; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
766 |
} else { |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
767 |
log_info(symboltable)("Resizes in progress rehashing skipped."); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
768 |
} |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
769 |
|
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
770 |
_needs_rehashing = false; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
771 |
} |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
772 |
|
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
773 |
void SymbolTable::rehash_table() { |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
774 |
SymbolTable::the_table()->try_rehash_table(); |
28363
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
27677
diff
changeset
|
775 |
} |
1 | 776 |
|
777 |
//--------------------------------------------------------------------------- |
|
778 |
// Non-product code |
|
779 |
||
780 |
#ifndef PRODUCT |
|
781 |
||
51405
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
782 |
class HistogramIterator : StackObj { |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
783 |
public: |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
784 |
static const size_t results_length = 100; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
785 |
size_t counts[results_length]; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
786 |
size_t sizes[results_length]; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
787 |
size_t total_size; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
788 |
size_t total_count; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
789 |
size_t total_length; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
790 |
size_t max_length; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
791 |
size_t out_of_range_count; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
792 |
size_t out_of_range_size; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
793 |
HistogramIterator() : total_size(0), total_count(0), total_length(0), |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
794 |
max_length(0), out_of_range_count(0), out_of_range_size(0) { |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
795 |
// initialize results to zero |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
796 |
for (size_t i = 0; i < results_length; i++) { |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
797 |
counts[i] = 0; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
798 |
sizes[i] = 0; |
1 | 799 |
} |
800 |
} |
|
51405
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
801 |
bool operator()(Symbol** value) { |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
802 |
assert(value != NULL, "expected valid value"); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
803 |
assert(*value != NULL, "value should point to a symbol"); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
804 |
Symbol* sym = *value; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
805 |
size_t size = sym->size(); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
806 |
size_t len = sym->utf8_length(); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
807 |
if (len < results_length) { |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
808 |
counts[len]++; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
809 |
sizes[len] += size; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
810 |
} else { |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
811 |
out_of_range_count++; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
812 |
out_of_range_size += size; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
813 |
} |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
814 |
total_count++; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
815 |
total_size += size; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
816 |
total_length += len; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
817 |
max_length = MAX2(max_length, len); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
818 |
|
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
819 |
return true; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
820 |
}; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
821 |
}; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
822 |
|
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
823 |
void SymbolTable::print_histogram() { |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
824 |
SymbolTable* st = SymbolTable::the_table(); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
825 |
HistogramIterator hi; |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
826 |
st->_local_table->do_scan(Thread::current(), hi); |
26923
60c1555c25c5
8057925: PrintSymbolTableSizeHistogram prints misleading output
shade
parents:
26421
diff
changeset
|
827 |
tty->print_cr("Symbol Table Histogram:"); |
51405
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
828 |
tty->print_cr(" Total number of symbols " SIZE_FORMAT_W(7), hi.total_count); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
829 |
tty->print_cr(" Total size in memory " SIZE_FORMAT_W(7) "K", |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
830 |
(hi.total_size * wordSize) / 1024); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
831 |
tty->print_cr(" Total counted " SIZE_FORMAT_W(7), st->_symbols_counted); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
832 |
tty->print_cr(" Total removed " SIZE_FORMAT_W(7), st->_symbols_removed); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
833 |
if (SymbolTable::the_table()->_symbols_counted > 0) { |
26923
60c1555c25c5
8057925: PrintSymbolTableSizeHistogram prints misleading output
shade
parents:
26421
diff
changeset
|
834 |
tty->print_cr(" Percent removed %3.2f", |
51405
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
835 |
((float)st->_symbols_removed / st->_symbols_counted) * 100); |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
836 |
} |
51405
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
837 |
tty->print_cr(" Reference counts " SIZE_FORMAT_W(7), Symbol::_total_count); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
838 |
tty->print_cr(" Symbol arena used " SIZE_FORMAT_W(7) "K", arena()->used() / 1024); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
839 |
tty->print_cr(" Symbol arena size " SIZE_FORMAT_W(7) "K", arena()->size_in_bytes() / 1024); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
840 |
tty->print_cr(" Total symbol length " SIZE_FORMAT_W(7), hi.total_length); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
841 |
tty->print_cr(" Maximum symbol length " SIZE_FORMAT_W(7), hi.max_length); |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
842 |
tty->print_cr(" Average symbol length %7.2f", ((float)hi.total_length / hi.total_count)); |
26923
60c1555c25c5
8057925: PrintSymbolTableSizeHistogram prints misleading output
shade
parents:
26421
diff
changeset
|
843 |
tty->print_cr(" Symbol length histogram:"); |
60c1555c25c5
8057925: PrintSymbolTableSizeHistogram prints misleading output
shade
parents:
26421
diff
changeset
|
844 |
tty->print_cr(" %6s %10s %10s", "Length", "#Symbols", "Size"); |
51405
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
845 |
for (size_t i = 0; i < hi.results_length; i++) { |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
846 |
if (hi.counts[i] > 0) { |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
847 |
tty->print_cr(" " SIZE_FORMAT_W(6) " " SIZE_FORMAT_W(10) " " SIZE_FORMAT_W(10) "K", |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
848 |
i, hi.counts[i], (hi.sizes[i] * wordSize) / 1024); |
1 | 849 |
} |
850 |
} |
|
51405
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
851 |
tty->print_cr(" >=" SIZE_FORMAT_W(6) " " SIZE_FORMAT_W(10) " " SIZE_FORMAT_W(10) "K\n", |
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
852 |
hi.results_length, hi.out_of_range_count, (hi.out_of_range_size*wordSize) / 1024); |
1 | 853 |
} |
854 |
#endif // PRODUCT |
|
28363
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
27677
diff
changeset
|
855 |
|
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
27677
diff
changeset
|
856 |
// Utility for dumping symbols |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
27677
diff
changeset
|
857 |
SymboltableDCmd::SymboltableDCmd(outputStream* output, bool heap) : |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
27677
diff
changeset
|
858 |
DCmdWithParser(output, heap), |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
27677
diff
changeset
|
859 |
_verbose("-verbose", "Dump the content of each symbol in the table", |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
27677
diff
changeset
|
860 |
"BOOLEAN", false, "false") { |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
27677
diff
changeset
|
861 |
_dcmdparser.add_dcmd_option(&_verbose); |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
27677
diff
changeset
|
862 |
} |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
27677
diff
changeset
|
863 |
|
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
27677
diff
changeset
|
864 |
void SymboltableDCmd::execute(DCmdSource source, TRAPS) { |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
27677
diff
changeset
|
865 |
VM_DumpHashtable dumper(output(), VM_DumpHashtable::DumpSymbols, |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
27677
diff
changeset
|
866 |
_verbose.value()); |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
27677
diff
changeset
|
867 |
VMThread::execute(&dumper); |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
27677
diff
changeset
|
868 |
} |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
27677
diff
changeset
|
869 |
|
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
27677
diff
changeset
|
870 |
int SymboltableDCmd::num_arguments() { |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
27677
diff
changeset
|
871 |
ResourceMark rm; |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
27677
diff
changeset
|
872 |
SymboltableDCmd* dcmd = new SymboltableDCmd(NULL, false); |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
27677
diff
changeset
|
873 |
if (dcmd != NULL) { |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
27677
diff
changeset
|
874 |
DCmdMark mark(dcmd); |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
27677
diff
changeset
|
875 |
return dcmd->_dcmdparser.num_arguments(); |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
27677
diff
changeset
|
876 |
} else { |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
27677
diff
changeset
|
877 |
return 0; |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
27677
diff
changeset
|
878 |
} |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
27677
diff
changeset
|
879 |
} |