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