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