author | iklam |
Wed, 02 Dec 2015 18:14:54 -0800 | |
changeset 34659 | 3a7071043457 |
parent 33628 | 09241459a8b8 |
child 35492 | c8c0273e6b91 |
child 35498 | 392b50de06c6 |
permissions | -rw-r--r-- |
24426 | 1 |
/* |
29081
c61eb4914428
8072911: Remove includes of oop.inline.hpp from .hpp files
stefank
parents:
28363
diff
changeset
|
2 |
* Copyright (c) 1997, 2015, 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" |
|
34659
3a7071043457
8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
33628
diff
changeset
|
27 |
#include "classfile/compactHashtable.inline.hpp" |
24426 | 28 |
#include "classfile/javaClasses.hpp" |
29 |
#include "classfile/stringTable.hpp" |
|
30 |
#include "classfile/systemDictionary.hpp" |
|
30764 | 31 |
#include "gc/shared/collectedHeap.inline.hpp" |
32 |
#include "gc/shared/gcLocker.inline.hpp" |
|
24426 | 33 |
#include "memory/allocation.inline.hpp" |
34 |
#include "memory/filemap.hpp" |
|
35 |
#include "oops/oop.inline.hpp" |
|
25351
7c198a690050
8044775: Improve usage of umbrella header atomic.inline.hpp.
goetz
parents:
24429
diff
changeset
|
36 |
#include "runtime/atomic.inline.hpp" |
24426 | 37 |
#include "runtime/mutexLocker.hpp" |
38 |
#include "utilities/hashtable.inline.hpp" |
|
27684
e0391b2bf625
8064581: Move INCLUDE_ALL_GCS include section to the end of the include list
stefank
parents:
26421
diff
changeset
|
39 |
#include "utilities/macros.hpp" |
24426 | 40 |
#if INCLUDE_ALL_GCS |
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
41 |
#include "gc/g1/g1CollectedHeap.hpp" |
30764 | 42 |
#include "gc/g1/g1SATBCardTableModRefBS.hpp" |
43 |
#include "gc/g1/g1StringDedup.hpp" |
|
24426 | 44 |
#endif |
45 |
||
46 |
// the number of buckets a thread claims |
|
47 |
const int ClaimChunkSize = 32; |
|
48 |
||
49 |
#ifdef ASSERT |
|
50 |
class StableMemoryChecker : public StackObj { |
|
51 |
enum { _bufsize = wordSize*4 }; |
|
52 |
||
53 |
address _region; |
|
54 |
jint _size; |
|
55 |
u1 _save_buf[_bufsize]; |
|
56 |
||
57 |
int sample(u1* save_buf) { |
|
58 |
if (_size <= _bufsize) { |
|
59 |
memcpy(save_buf, _region, _size); |
|
60 |
return _size; |
|
61 |
} else { |
|
62 |
// copy head and tail |
|
63 |
memcpy(&save_buf[0], _region, _bufsize/2); |
|
64 |
memcpy(&save_buf[_bufsize/2], _region + _size - _bufsize/2, _bufsize/2); |
|
65 |
return (_bufsize/2)*2; |
|
66 |
} |
|
67 |
} |
|
68 |
||
69 |
public: |
|
70 |
StableMemoryChecker(const void* region, jint size) { |
|
71 |
_region = (address) region; |
|
72 |
_size = size; |
|
73 |
sample(_save_buf); |
|
74 |
} |
|
75 |
||
76 |
bool verify() { |
|
77 |
u1 check_buf[sizeof(_save_buf)]; |
|
78 |
int check_size = sample(check_buf); |
|
79 |
return (0 == memcmp(_save_buf, check_buf, check_size)); |
|
80 |
} |
|
81 |
||
82 |
void set_region(const void* region) { _region = (address) region; } |
|
83 |
}; |
|
84 |
#endif |
|
85 |
||
86 |
||
87 |
// -------------------------------------------------------------------------- |
|
88 |
StringTable* StringTable::_the_table = NULL; |
|
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
89 |
bool StringTable::_ignore_shared_strings = false; |
24426 | 90 |
bool StringTable::_needs_rehashing = false; |
91 |
||
92 |
volatile int StringTable::_parallel_claimed_idx = 0; |
|
93 |
||
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
94 |
CompactHashtable<oop, char> StringTable::_shared_table; |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
95 |
|
24426 | 96 |
// Pick hashing algorithm |
33628 | 97 |
template<typename T> |
98 |
unsigned int StringTable::hash_string(const T* s, int len) { |
|
24426 | 99 |
return use_alternate_hashcode() ? AltHashing::murmur3_32(seed(), s, len) : |
100 |
java_lang_String::hash_code(s, len); |
|
101 |
} |
|
102 |
||
33628 | 103 |
// Explicit instantiation for all supported types. |
104 |
template unsigned int StringTable::hash_string<jchar>(const jchar* s, int len); |
|
105 |
template unsigned int StringTable::hash_string<jbyte>(const jbyte* s, int len); |
|
106 |
||
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
107 |
oop StringTable::lookup_shared(jchar* name, int len) { |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
108 |
// java_lang_String::hash_code() was used to compute hash values in the shared table. Don't |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
109 |
// use the hash value from StringTable::hash_string() as it might use alternate hashcode. |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
110 |
return _shared_table.lookup((const char*)name, |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
111 |
java_lang_String::hash_code(name, len), len); |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
112 |
} |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
113 |
|
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
114 |
oop StringTable::lookup_in_main_table(int index, jchar* name, |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
115 |
int len, unsigned int hash) { |
24426 | 116 |
int count = 0; |
117 |
for (HashtableEntry<oop, mtSymbol>* l = bucket(index); l != NULL; l = l->next()) { |
|
118 |
count++; |
|
119 |
if (l->hash() == hash) { |
|
120 |
if (java_lang_String::equals(l->literal(), name, len)) { |
|
121 |
return l->literal(); |
|
122 |
} |
|
123 |
} |
|
124 |
} |
|
125 |
// If the bucket size is too deep check if this hash code is insufficient. |
|
26421
37d88e604ad0
8056084: Refactor Hashtable to allow implementations without rehashing support
mgerdin
parents:
25492
diff
changeset
|
126 |
if (count >= rehash_count && !needs_rehashing()) { |
24426 | 127 |
_needs_rehashing = check_rehash_table(count); |
128 |
} |
|
129 |
return NULL; |
|
130 |
} |
|
131 |
||
132 |
||
133 |
oop StringTable::basic_add(int index_arg, Handle string, jchar* name, |
|
134 |
int len, unsigned int hashValue_arg, TRAPS) { |
|
135 |
||
136 |
assert(java_lang_String::equals(string(), name, len), |
|
137 |
"string must be properly initialized"); |
|
138 |
// Cannot hit a safepoint in this function because the "this" pointer can move. |
|
139 |
No_Safepoint_Verifier nsv; |
|
140 |
||
141 |
// Check if the symbol table has been rehashed, if so, need to recalculate |
|
142 |
// the hash value and index before second lookup. |
|
143 |
unsigned int hashValue; |
|
144 |
int index; |
|
145 |
if (use_alternate_hashcode()) { |
|
146 |
hashValue = hash_string(name, len); |
|
147 |
index = hash_to_index(hashValue); |
|
148 |
} else { |
|
149 |
hashValue = hashValue_arg; |
|
150 |
index = index_arg; |
|
151 |
} |
|
152 |
||
153 |
// Since look-up was done lock-free, we need to check if another |
|
154 |
// thread beat us in the race to insert the symbol. |
|
155 |
||
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
156 |
// No need to lookup the shared table from here since the caller (intern()) already did |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
157 |
oop test = lookup_in_main_table(index, name, len, hashValue); // calls lookup(u1*, int) |
24426 | 158 |
if (test != NULL) { |
159 |
// Entry already added |
|
160 |
return test; |
|
161 |
} |
|
162 |
||
163 |
HashtableEntry<oop, mtSymbol>* entry = new_entry(hashValue, string()); |
|
164 |
add_entry(index, entry); |
|
165 |
return string(); |
|
166 |
} |
|
167 |
||
168 |
||
169 |
oop StringTable::lookup(Symbol* symbol) { |
|
170 |
ResourceMark rm; |
|
171 |
int length; |
|
172 |
jchar* chars = symbol->as_unicode(length); |
|
173 |
return lookup(chars, length); |
|
174 |
} |
|
175 |
||
25492
d27050bdfb04
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
25491
diff
changeset
|
176 |
// Tell the GC that this string was looked up in the StringTable. |
d27050bdfb04
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
25491
diff
changeset
|
177 |
static void ensure_string_alive(oop string) { |
d27050bdfb04
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
25491
diff
changeset
|
178 |
// A lookup in the StringTable could return an object that was previously |
d27050bdfb04
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
25491
diff
changeset
|
179 |
// considered dead. The SATB part of G1 needs to get notified about this |
d27050bdfb04
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
25491
diff
changeset
|
180 |
// potential resurrection, otherwise the marking might not find the object. |
d27050bdfb04
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
25491
diff
changeset
|
181 |
#if INCLUDE_ALL_GCS |
d27050bdfb04
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
25491
diff
changeset
|
182 |
if (UseG1GC && string != NULL) { |
d27050bdfb04
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
25491
diff
changeset
|
183 |
G1SATBCardTableModRefBS::enqueue(string); |
d27050bdfb04
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
25491
diff
changeset
|
184 |
} |
d27050bdfb04
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
25491
diff
changeset
|
185 |
#endif |
d27050bdfb04
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
25491
diff
changeset
|
186 |
} |
24426 | 187 |
|
188 |
oop StringTable::lookup(jchar* name, int len) { |
|
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
189 |
oop string = lookup_shared(name, len); |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
190 |
if (string != NULL) { |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
191 |
return string; |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
192 |
} |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
193 |
|
24426 | 194 |
unsigned int hash = hash_string(name, len); |
195 |
int index = the_table()->hash_to_index(hash); |
|
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
196 |
string = the_table()->lookup_in_main_table(index, name, len, hash); |
25492
d27050bdfb04
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
25491
diff
changeset
|
197 |
|
d27050bdfb04
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
25491
diff
changeset
|
198 |
ensure_string_alive(string); |
d27050bdfb04
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
25491
diff
changeset
|
199 |
|
d27050bdfb04
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
25491
diff
changeset
|
200 |
return string; |
24426 | 201 |
} |
202 |
||
203 |
||
204 |
oop StringTable::intern(Handle string_or_null, jchar* name, |
|
205 |
int len, TRAPS) { |
|
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
206 |
oop found_string = lookup_shared(name, len); |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
207 |
if (found_string != NULL) { |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
208 |
return found_string; |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
209 |
} |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
210 |
|
24426 | 211 |
unsigned int hashValue = hash_string(name, len); |
212 |
int index = the_table()->hash_to_index(hashValue); |
|
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
213 |
found_string = the_table()->lookup_in_main_table(index, name, len, hashValue); |
24426 | 214 |
|
215 |
// Found |
|
25492
d27050bdfb04
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
25491
diff
changeset
|
216 |
if (found_string != NULL) { |
d27050bdfb04
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
25491
diff
changeset
|
217 |
ensure_string_alive(found_string); |
d27050bdfb04
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
25491
diff
changeset
|
218 |
return found_string; |
d27050bdfb04
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
25491
diff
changeset
|
219 |
} |
24426 | 220 |
|
221 |
debug_only(StableMemoryChecker smc(name, len * sizeof(name[0]))); |
|
222 |
assert(!Universe::heap()->is_in_reserved(name), |
|
223 |
"proposed name of symbol must be stable"); |
|
224 |
||
225 |
Handle string; |
|
226 |
// try to reuse the string if possible |
|
227 |
if (!string_or_null.is_null()) { |
|
228 |
string = string_or_null; |
|
229 |
} else { |
|
230 |
string = java_lang_String::create_from_unicode(name, len, CHECK_NULL); |
|
231 |
} |
|
232 |
||
233 |
#if INCLUDE_ALL_GCS |
|
234 |
if (G1StringDedup::is_enabled()) { |
|
235 |
// Deduplicate the string before it is interned. Note that we should never |
|
236 |
// deduplicate a string after it has been interned. Doing so will counteract |
|
237 |
// compiler optimizations done on e.g. interned string literals. |
|
238 |
G1StringDedup::deduplicate(string()); |
|
239 |
} |
|
240 |
#endif |
|
241 |
||
242 |
// Grab the StringTable_lock before getting the_table() because it could |
|
243 |
// change at safepoint. |
|
25492
d27050bdfb04
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
25491
diff
changeset
|
244 |
oop added_or_found; |
d27050bdfb04
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
25491
diff
changeset
|
245 |
{ |
d27050bdfb04
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
25491
diff
changeset
|
246 |
MutexLocker ml(StringTable_lock, THREAD); |
d27050bdfb04
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
25491
diff
changeset
|
247 |
// Otherwise, add to symbol to table |
d27050bdfb04
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
25491
diff
changeset
|
248 |
added_or_found = the_table()->basic_add(index, string, name, len, |
d27050bdfb04
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
25491
diff
changeset
|
249 |
hashValue, CHECK_NULL); |
d27050bdfb04
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
25491
diff
changeset
|
250 |
} |
24426 | 251 |
|
25492
d27050bdfb04
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
25491
diff
changeset
|
252 |
ensure_string_alive(added_or_found); |
d27050bdfb04
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
25491
diff
changeset
|
253 |
|
d27050bdfb04
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
25491
diff
changeset
|
254 |
return added_or_found; |
24426 | 255 |
} |
256 |
||
257 |
oop StringTable::intern(Symbol* symbol, TRAPS) { |
|
258 |
if (symbol == NULL) return NULL; |
|
259 |
ResourceMark rm(THREAD); |
|
260 |
int length; |
|
261 |
jchar* chars = symbol->as_unicode(length); |
|
262 |
Handle string; |
|
263 |
oop result = intern(string, chars, length, CHECK_NULL); |
|
264 |
return result; |
|
265 |
} |
|
266 |
||
267 |
||
268 |
oop StringTable::intern(oop string, TRAPS) |
|
269 |
{ |
|
270 |
if (string == NULL) return NULL; |
|
271 |
ResourceMark rm(THREAD); |
|
272 |
int length; |
|
273 |
Handle h_string (THREAD, string); |
|
274 |
jchar* chars = java_lang_String::as_unicode_string(string, length, CHECK_NULL); |
|
275 |
oop result = intern(h_string, chars, length, CHECK_NULL); |
|
276 |
return result; |
|
277 |
} |
|
278 |
||
279 |
||
280 |
oop StringTable::intern(const char* utf8_string, TRAPS) { |
|
281 |
if (utf8_string == NULL) return NULL; |
|
282 |
ResourceMark rm(THREAD); |
|
283 |
int length = UTF8::unicode_length(utf8_string); |
|
284 |
jchar* chars = NEW_RESOURCE_ARRAY(jchar, length); |
|
285 |
UTF8::convert_to_unicode(utf8_string, chars, length); |
|
286 |
Handle string; |
|
287 |
oop result = intern(string, chars, length, CHECK_NULL); |
|
288 |
return result; |
|
289 |
} |
|
290 |
||
291 |
void StringTable::unlink_or_oops_do(BoolObjectClosure* is_alive, OopClosure* f, int* processed, int* removed) { |
|
292 |
buckets_unlink_or_oops_do(is_alive, f, 0, the_table()->table_size(), processed, removed); |
|
293 |
} |
|
294 |
||
295 |
void StringTable::possibly_parallel_unlink_or_oops_do(BoolObjectClosure* is_alive, OopClosure* f, int* processed, int* removed) { |
|
296 |
// Readers of the table are unlocked, so we should only be removing |
|
297 |
// entries at a safepoint. |
|
298 |
assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint"); |
|
299 |
const int limit = the_table()->table_size(); |
|
300 |
||
301 |
for (;;) { |
|
302 |
// Grab next set of buckets to scan |
|
303 |
int start_idx = Atomic::add(ClaimChunkSize, &_parallel_claimed_idx) - ClaimChunkSize; |
|
304 |
if (start_idx >= limit) { |
|
305 |
// End of table |
|
306 |
break; |
|
307 |
} |
|
308 |
||
309 |
int end_idx = MIN2(limit, start_idx + ClaimChunkSize); |
|
310 |
buckets_unlink_or_oops_do(is_alive, f, start_idx, end_idx, processed, removed); |
|
311 |
} |
|
312 |
} |
|
313 |
||
314 |
void StringTable::buckets_oops_do(OopClosure* f, int start_idx, int end_idx) { |
|
315 |
const int limit = the_table()->table_size(); |
|
316 |
||
317 |
assert(0 <= start_idx && start_idx <= limit, |
|
33105
294e48b4f704
8080775: Better argument formatting for assert() and friends
david
parents:
31345
diff
changeset
|
318 |
"start_idx (%d) is out of bounds", start_idx); |
24426 | 319 |
assert(0 <= end_idx && end_idx <= limit, |
33105
294e48b4f704
8080775: Better argument formatting for assert() and friends
david
parents:
31345
diff
changeset
|
320 |
"end_idx (%d) is out of bounds", end_idx); |
24426 | 321 |
assert(start_idx <= end_idx, |
33105
294e48b4f704
8080775: Better argument formatting for assert() and friends
david
parents:
31345
diff
changeset
|
322 |
"Index ordering: start_idx=%d, end_idx=%d", |
294e48b4f704
8080775: Better argument formatting for assert() and friends
david
parents:
31345
diff
changeset
|
323 |
start_idx, end_idx); |
24426 | 324 |
|
325 |
for (int i = start_idx; i < end_idx; i += 1) { |
|
326 |
HashtableEntry<oop, mtSymbol>* entry = the_table()->bucket(i); |
|
327 |
while (entry != NULL) { |
|
328 |
assert(!entry->is_shared(), "CDS not used for the StringTable"); |
|
329 |
||
330 |
f->do_oop((oop*)entry->literal_addr()); |
|
331 |
||
332 |
entry = entry->next(); |
|
333 |
} |
|
334 |
} |
|
335 |
} |
|
336 |
||
337 |
void StringTable::buckets_unlink_or_oops_do(BoolObjectClosure* is_alive, OopClosure* f, int start_idx, int end_idx, int* processed, int* removed) { |
|
338 |
const int limit = the_table()->table_size(); |
|
339 |
||
340 |
assert(0 <= start_idx && start_idx <= limit, |
|
33105
294e48b4f704
8080775: Better argument formatting for assert() and friends
david
parents:
31345
diff
changeset
|
341 |
"start_idx (%d) is out of bounds", start_idx); |
24426 | 342 |
assert(0 <= end_idx && end_idx <= limit, |
33105
294e48b4f704
8080775: Better argument formatting for assert() and friends
david
parents:
31345
diff
changeset
|
343 |
"end_idx (%d) is out of bounds", end_idx); |
24426 | 344 |
assert(start_idx <= end_idx, |
33105
294e48b4f704
8080775: Better argument formatting for assert() and friends
david
parents:
31345
diff
changeset
|
345 |
"Index ordering: start_idx=%d, end_idx=%d", |
294e48b4f704
8080775: Better argument formatting for assert() and friends
david
parents:
31345
diff
changeset
|
346 |
start_idx, end_idx); |
24426 | 347 |
|
348 |
for (int i = start_idx; i < end_idx; ++i) { |
|
349 |
HashtableEntry<oop, mtSymbol>** p = the_table()->bucket_addr(i); |
|
350 |
HashtableEntry<oop, mtSymbol>* entry = the_table()->bucket(i); |
|
351 |
while (entry != NULL) { |
|
352 |
assert(!entry->is_shared(), "CDS not used for the StringTable"); |
|
353 |
||
354 |
if (is_alive->do_object_b(entry->literal())) { |
|
355 |
if (f != NULL) { |
|
356 |
f->do_oop((oop*)entry->literal_addr()); |
|
357 |
} |
|
358 |
p = entry->next_addr(); |
|
359 |
} else { |
|
360 |
*p = entry->next(); |
|
361 |
the_table()->free_entry(entry); |
|
362 |
(*removed)++; |
|
363 |
} |
|
364 |
(*processed)++; |
|
365 |
entry = *p; |
|
366 |
} |
|
367 |
} |
|
368 |
} |
|
369 |
||
370 |
void StringTable::oops_do(OopClosure* f) { |
|
371 |
buckets_oops_do(f, 0, the_table()->table_size()); |
|
372 |
} |
|
373 |
||
374 |
void StringTable::possibly_parallel_oops_do(OopClosure* f) { |
|
375 |
const int limit = the_table()->table_size(); |
|
376 |
||
377 |
for (;;) { |
|
378 |
// Grab next set of buckets to scan |
|
379 |
int start_idx = Atomic::add(ClaimChunkSize, &_parallel_claimed_idx) - ClaimChunkSize; |
|
380 |
if (start_idx >= limit) { |
|
381 |
// End of table |
|
382 |
break; |
|
383 |
} |
|
384 |
||
385 |
int end_idx = MIN2(limit, start_idx + ClaimChunkSize); |
|
386 |
buckets_oops_do(f, start_idx, end_idx); |
|
387 |
} |
|
388 |
} |
|
389 |
||
390 |
// This verification is part of Universe::verify() and needs to be quick. |
|
391 |
// See StringTable::verify_and_compare() below for exhaustive verification. |
|
392 |
void StringTable::verify() { |
|
393 |
for (int i = 0; i < the_table()->table_size(); ++i) { |
|
394 |
HashtableEntry<oop, mtSymbol>* p = the_table()->bucket(i); |
|
395 |
for ( ; p != NULL; p = p->next()) { |
|
396 |
oop s = p->literal(); |
|
397 |
guarantee(s != NULL, "interned string is NULL"); |
|
398 |
unsigned int h = java_lang_String::hash_string(s); |
|
399 |
guarantee(p->hash() == h, "broken hash in string table entry"); |
|
400 |
guarantee(the_table()->hash_to_index(h) == i, |
|
401 |
"wrong index in string table"); |
|
402 |
} |
|
403 |
} |
|
404 |
} |
|
405 |
||
28363
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
27684
diff
changeset
|
406 |
void StringTable::dump(outputStream* st, bool verbose) { |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
27684
diff
changeset
|
407 |
if (!verbose) { |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
27684
diff
changeset
|
408 |
the_table()->dump_table(st, "StringTable"); |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
27684
diff
changeset
|
409 |
} else { |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
27684
diff
changeset
|
410 |
Thread* THREAD = Thread::current(); |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
27684
diff
changeset
|
411 |
st->print_cr("VERSION: 1.1"); |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
27684
diff
changeset
|
412 |
for (int i = 0; i < the_table()->table_size(); ++i) { |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
27684
diff
changeset
|
413 |
HashtableEntry<oop, mtSymbol>* p = the_table()->bucket(i); |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
27684
diff
changeset
|
414 |
for ( ; p != NULL; p = p->next()) { |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
27684
diff
changeset
|
415 |
oop s = p->literal(); |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
27684
diff
changeset
|
416 |
typeArrayOop value = java_lang_String::value(s); |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
27684
diff
changeset
|
417 |
int length = java_lang_String::length(s); |
33628 | 418 |
bool is_latin1 = java_lang_String::is_latin1(s); |
28363
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
27684
diff
changeset
|
419 |
|
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
27684
diff
changeset
|
420 |
if (length <= 0) { |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
27684
diff
changeset
|
421 |
st->print("%d: ", length); |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
27684
diff
changeset
|
422 |
} else { |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
27684
diff
changeset
|
423 |
ResourceMark rm(THREAD); |
33628 | 424 |
int utf8_length; |
425 |
char* utf8_string; |
|
426 |
||
427 |
if (!is_latin1) { |
|
428 |
jchar* chars = value->char_at_addr(0); |
|
429 |
utf8_length = UNICODE::utf8_length(chars, length); |
|
430 |
utf8_string = UNICODE::as_utf8(chars, length); |
|
431 |
} else { |
|
432 |
jbyte* bytes = value->byte_at_addr(0); |
|
433 |
utf8_length = UNICODE::utf8_length(bytes, length); |
|
434 |
utf8_string = UNICODE::as_utf8(bytes, length); |
|
435 |
} |
|
28363
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
27684
diff
changeset
|
436 |
|
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
27684
diff
changeset
|
437 |
st->print("%d: ", utf8_length); |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
27684
diff
changeset
|
438 |
HashtableTextDump::put_utf8(st, utf8_string, utf8_length); |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
27684
diff
changeset
|
439 |
} |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
27684
diff
changeset
|
440 |
st->cr(); |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
27684
diff
changeset
|
441 |
} |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
27684
diff
changeset
|
442 |
} |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
27684
diff
changeset
|
443 |
} |
24426 | 444 |
} |
445 |
||
446 |
StringTable::VerifyRetTypes StringTable::compare_entries( |
|
447 |
int bkt1, int e_cnt1, |
|
448 |
HashtableEntry<oop, mtSymbol>* e_ptr1, |
|
449 |
int bkt2, int e_cnt2, |
|
450 |
HashtableEntry<oop, mtSymbol>* e_ptr2) { |
|
451 |
// These entries are sanity checked by verify_and_compare_entries() |
|
452 |
// before this function is called. |
|
453 |
oop str1 = e_ptr1->literal(); |
|
454 |
oop str2 = e_ptr2->literal(); |
|
455 |
||
456 |
if (str1 == str2) { |
|
457 |
tty->print_cr("ERROR: identical oop values (0x" PTR_FORMAT ") " |
|
458 |
"in entry @ bucket[%d][%d] and entry @ bucket[%d][%d]", |
|
33148
68fa8b6c4340
8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents:
33105
diff
changeset
|
459 |
p2i(str1), bkt1, e_cnt1, bkt2, e_cnt2); |
24426 | 460 |
return _verify_fail_continue; |
461 |
} |
|
462 |
||
463 |
if (java_lang_String::equals(str1, str2)) { |
|
464 |
tty->print_cr("ERROR: identical String values in entry @ " |
|
465 |
"bucket[%d][%d] and entry @ bucket[%d][%d]", |
|
466 |
bkt1, e_cnt1, bkt2, e_cnt2); |
|
467 |
return _verify_fail_continue; |
|
468 |
} |
|
469 |
||
470 |
return _verify_pass; |
|
471 |
} |
|
472 |
||
473 |
StringTable::VerifyRetTypes StringTable::verify_entry(int bkt, int e_cnt, |
|
474 |
HashtableEntry<oop, mtSymbol>* e_ptr, |
|
475 |
StringTable::VerifyMesgModes mesg_mode) { |
|
476 |
||
477 |
VerifyRetTypes ret = _verify_pass; // be optimistic |
|
478 |
||
479 |
oop str = e_ptr->literal(); |
|
480 |
if (str == NULL) { |
|
481 |
if (mesg_mode == _verify_with_mesgs) { |
|
482 |
tty->print_cr("ERROR: NULL oop value in entry @ bucket[%d][%d]", bkt, |
|
483 |
e_cnt); |
|
484 |
} |
|
485 |
// NULL oop means no more verifications are possible |
|
486 |
return _verify_fail_done; |
|
487 |
} |
|
488 |
||
489 |
if (str->klass() != SystemDictionary::String_klass()) { |
|
490 |
if (mesg_mode == _verify_with_mesgs) { |
|
491 |
tty->print_cr("ERROR: oop is not a String in entry @ bucket[%d][%d]", |
|
492 |
bkt, e_cnt); |
|
493 |
} |
|
494 |
// not a String means no more verifications are possible |
|
495 |
return _verify_fail_done; |
|
496 |
} |
|
497 |
||
498 |
unsigned int h = java_lang_String::hash_string(str); |
|
499 |
if (e_ptr->hash() != h) { |
|
500 |
if (mesg_mode == _verify_with_mesgs) { |
|
501 |
tty->print_cr("ERROR: broken hash value in entry @ bucket[%d][%d], " |
|
502 |
"bkt_hash=%d, str_hash=%d", bkt, e_cnt, e_ptr->hash(), h); |
|
503 |
} |
|
504 |
ret = _verify_fail_continue; |
|
505 |
} |
|
506 |
||
507 |
if (the_table()->hash_to_index(h) != bkt) { |
|
508 |
if (mesg_mode == _verify_with_mesgs) { |
|
509 |
tty->print_cr("ERROR: wrong index value for entry @ bucket[%d][%d], " |
|
510 |
"str_hash=%d, hash_to_index=%d", bkt, e_cnt, h, |
|
511 |
the_table()->hash_to_index(h)); |
|
512 |
} |
|
513 |
ret = _verify_fail_continue; |
|
514 |
} |
|
515 |
||
516 |
return ret; |
|
517 |
} |
|
518 |
||
519 |
// See StringTable::verify() above for the quick verification that is |
|
520 |
// part of Universe::verify(). This verification is exhaustive and |
|
521 |
// reports on every issue that is found. StringTable::verify() only |
|
522 |
// reports on the first issue that is found. |
|
523 |
// |
|
524 |
// StringTable::verify_entry() checks: |
|
525 |
// - oop value != NULL (same as verify()) |
|
526 |
// - oop value is a String |
|
527 |
// - hash(String) == hash in entry (same as verify()) |
|
528 |
// - index for hash == index of entry (same as verify()) |
|
529 |
// |
|
530 |
// StringTable::compare_entries() checks: |
|
531 |
// - oops are unique across all entries |
|
532 |
// - String values are unique across all entries |
|
533 |
// |
|
534 |
int StringTable::verify_and_compare_entries() { |
|
535 |
assert(StringTable_lock->is_locked(), "sanity check"); |
|
536 |
||
537 |
int fail_cnt = 0; |
|
538 |
||
539 |
// first, verify all the entries individually: |
|
540 |
for (int bkt = 0; bkt < the_table()->table_size(); bkt++) { |
|
541 |
HashtableEntry<oop, mtSymbol>* e_ptr = the_table()->bucket(bkt); |
|
542 |
for (int e_cnt = 0; e_ptr != NULL; e_ptr = e_ptr->next(), e_cnt++) { |
|
543 |
VerifyRetTypes ret = verify_entry(bkt, e_cnt, e_ptr, _verify_with_mesgs); |
|
544 |
if (ret != _verify_pass) { |
|
545 |
fail_cnt++; |
|
546 |
} |
|
547 |
} |
|
548 |
} |
|
549 |
||
550 |
// Optimization: if the above check did not find any failures, then |
|
551 |
// the comparison loop below does not need to call verify_entry() |
|
552 |
// before calling compare_entries(). If there were failures, then we |
|
553 |
// have to call verify_entry() to see if the entry can be passed to |
|
554 |
// compare_entries() safely. When we call verify_entry() in the loop |
|
555 |
// below, we do so quietly to void duplicate messages and we don't |
|
556 |
// increment fail_cnt because the failures have already been counted. |
|
557 |
bool need_entry_verify = (fail_cnt != 0); |
|
558 |
||
559 |
// second, verify all entries relative to each other: |
|
560 |
for (int bkt1 = 0; bkt1 < the_table()->table_size(); bkt1++) { |
|
561 |
HashtableEntry<oop, mtSymbol>* e_ptr1 = the_table()->bucket(bkt1); |
|
562 |
for (int e_cnt1 = 0; e_ptr1 != NULL; e_ptr1 = e_ptr1->next(), e_cnt1++) { |
|
563 |
if (need_entry_verify) { |
|
564 |
VerifyRetTypes ret = verify_entry(bkt1, e_cnt1, e_ptr1, |
|
565 |
_verify_quietly); |
|
566 |
if (ret == _verify_fail_done) { |
|
567 |
// cannot use the current entry to compare against other entries |
|
568 |
continue; |
|
569 |
} |
|
570 |
} |
|
571 |
||
572 |
for (int bkt2 = bkt1; bkt2 < the_table()->table_size(); bkt2++) { |
|
573 |
HashtableEntry<oop, mtSymbol>* e_ptr2 = the_table()->bucket(bkt2); |
|
574 |
int e_cnt2; |
|
575 |
for (e_cnt2 = 0; e_ptr2 != NULL; e_ptr2 = e_ptr2->next(), e_cnt2++) { |
|
576 |
if (bkt1 == bkt2 && e_cnt2 <= e_cnt1) { |
|
577 |
// skip the entries up to and including the one that |
|
578 |
// we're comparing against |
|
579 |
continue; |
|
580 |
} |
|
581 |
||
582 |
if (need_entry_verify) { |
|
583 |
VerifyRetTypes ret = verify_entry(bkt2, e_cnt2, e_ptr2, |
|
584 |
_verify_quietly); |
|
585 |
if (ret == _verify_fail_done) { |
|
586 |
// cannot compare against this entry |
|
587 |
continue; |
|
588 |
} |
|
589 |
} |
|
590 |
||
591 |
// compare two entries, report and count any failures: |
|
592 |
if (compare_entries(bkt1, e_cnt1, e_ptr1, bkt2, e_cnt2, e_ptr2) |
|
593 |
!= _verify_pass) { |
|
594 |
fail_cnt++; |
|
595 |
} |
|
596 |
} |
|
597 |
} |
|
598 |
} |
|
599 |
} |
|
600 |
return fail_cnt; |
|
601 |
} |
|
602 |
||
603 |
// Create a new table and using alternate hash code, populate the new table |
|
604 |
// with the existing strings. Set flag to use the alternate hash code afterwards. |
|
605 |
void StringTable::rehash_table() { |
|
606 |
assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint"); |
|
607 |
// This should never happen with -Xshare:dump but it might in testing mode. |
|
608 |
if (DumpSharedSpaces) return; |
|
609 |
StringTable* new_table = new StringTable(); |
|
610 |
||
611 |
// Rehash the table |
|
612 |
the_table()->move_to(new_table); |
|
613 |
||
614 |
// Delete the table and buckets (entries are reused in new table). |
|
615 |
delete _the_table; |
|
616 |
// Don't check if we need rehashing until the table gets unbalanced again. |
|
617 |
// Then rehash with a new global seed. |
|
618 |
_needs_rehashing = false; |
|
619 |
_the_table = new_table; |
|
620 |
} |
|
28363
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
27684
diff
changeset
|
621 |
|
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
27684
diff
changeset
|
622 |
// Utility for dumping strings |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
27684
diff
changeset
|
623 |
StringtableDCmd::StringtableDCmd(outputStream* output, bool heap) : |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
27684
diff
changeset
|
624 |
DCmdWithParser(output, heap), |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
27684
diff
changeset
|
625 |
_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
|
626 |
"BOOLEAN", false, "false") { |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
27684
diff
changeset
|
627 |
_dcmdparser.add_dcmd_option(&_verbose); |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
27684
diff
changeset
|
628 |
} |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
27684
diff
changeset
|
629 |
|
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
27684
diff
changeset
|
630 |
void StringtableDCmd::execute(DCmdSource source, TRAPS) { |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
27684
diff
changeset
|
631 |
VM_DumpHashtable dumper(output(), VM_DumpHashtable::DumpStrings, |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
27684
diff
changeset
|
632 |
_verbose.value()); |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
27684
diff
changeset
|
633 |
VMThread::execute(&dumper); |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
27684
diff
changeset
|
634 |
} |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
27684
diff
changeset
|
635 |
|
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
27684
diff
changeset
|
636 |
int StringtableDCmd::num_arguments() { |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
27684
diff
changeset
|
637 |
ResourceMark rm; |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
27684
diff
changeset
|
638 |
StringtableDCmd* dcmd = new StringtableDCmd(NULL, false); |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
27684
diff
changeset
|
639 |
if (dcmd != NULL) { |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
27684
diff
changeset
|
640 |
DCmdMark mark(dcmd); |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
27684
diff
changeset
|
641 |
return dcmd->_dcmdparser.num_arguments(); |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
27684
diff
changeset
|
642 |
} else { |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
27684
diff
changeset
|
643 |
return 0; |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
27684
diff
changeset
|
644 |
} |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
27684
diff
changeset
|
645 |
} |
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
646 |
|
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
647 |
// Sharing |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
648 |
bool StringTable::copy_shared_string(GrowableArray<MemRegion> *string_space, |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
649 |
CompactHashtableWriter* ch_table) { |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
650 |
#if INCLUDE_CDS && INCLUDE_ALL_GCS && defined(_LP64) && !defined(_WINDOWS) |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
651 |
assert(UseG1GC, "Only support G1 GC"); |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
652 |
assert(UseCompressedOops && UseCompressedClassPointers, |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
653 |
"Only support UseCompressedOops and UseCompressedClassPointers enabled"); |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
654 |
|
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
655 |
Thread* THREAD = Thread::current(); |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
656 |
G1CollectedHeap::heap()->begin_archive_alloc_range(); |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
657 |
for (int i = 0; i < the_table()->table_size(); ++i) { |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
658 |
HashtableEntry<oop, mtSymbol>* bucket = the_table()->bucket(i); |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
659 |
for ( ; bucket != NULL; bucket = bucket->next()) { |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
660 |
oop s = bucket->literal(); |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
661 |
unsigned int hash = java_lang_String::hash_code(s); |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
662 |
if (hash == 0) { |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
663 |
continue; |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
664 |
} |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
665 |
|
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
666 |
// allocate the new 'value' array first |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
667 |
typeArrayOop v = java_lang_String::value(s); |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
668 |
int v_len = v->size(); |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
669 |
typeArrayOop new_v; |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
670 |
if (G1CollectedHeap::heap()->is_archive_alloc_too_large(v_len)) { |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
671 |
continue; // skip the current String. The 'value' array is too large to handle |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
672 |
} else { |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
673 |
new_v = (typeArrayOop)G1CollectedHeap::heap()->archive_mem_allocate(v_len); |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
674 |
if (new_v == NULL) { |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
675 |
return false; // allocation failed |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
676 |
} |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
677 |
} |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
678 |
// now allocate the new String object |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
679 |
int s_len = s->size(); |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
680 |
oop new_s = (oop)G1CollectedHeap::heap()->archive_mem_allocate(s_len); |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
681 |
if (new_s == NULL) { |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
682 |
return false; |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
683 |
} |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
684 |
|
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
685 |
s->identity_hash(); |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
686 |
v->identity_hash(); |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
687 |
|
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
688 |
// copy the objects' data |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
689 |
Copy::aligned_disjoint_words((HeapWord*)s, (HeapWord*)new_s, s_len); |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
690 |
Copy::aligned_disjoint_words((HeapWord*)v, (HeapWord*)new_v, v_len); |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
691 |
|
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
692 |
// adjust the pointer to the 'value' field in the new String oop. Also pre-compute and set the |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
693 |
// 'hash' field. That avoids "write" to the shared strings at runtime by the deduplication process. |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
694 |
java_lang_String::set_value_raw(new_s, new_v); |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
695 |
if (java_lang_String::hash(new_s) == 0) { |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
696 |
java_lang_String::set_hash(new_s, hash); |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
697 |
} |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
698 |
|
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
699 |
// add to the compact table |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
700 |
ch_table->add(hash, new_s); |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
701 |
} |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
702 |
} |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
703 |
|
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
704 |
G1CollectedHeap::heap()->end_archive_alloc_range(string_space, os::vm_allocation_granularity()); |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
705 |
assert(string_space->length() <= 2, "sanity"); |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
706 |
#endif |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
707 |
return true; |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
708 |
} |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
709 |
|
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
710 |
bool StringTable::copy_compact_table(char** top, char *end, GrowableArray<MemRegion> *string_space, |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
711 |
size_t* space_size) { |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
712 |
#if INCLUDE_CDS && defined(_LP64) && !defined(_WINDOWS) |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
713 |
if (!(UseG1GC && UseCompressedOops && UseCompressedClassPointers)) { |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
714 |
if (PrintSharedSpaces) { |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
715 |
tty->print_cr("Shared strings are excluded from the archive as UseG1GC, " |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
716 |
"UseCompressedOops and UseCompressedClassPointers are required."); |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
717 |
} |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
718 |
return true; |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
719 |
} |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
720 |
|
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
721 |
CompactHashtableWriter ch_table(CompactHashtable<oop, char>::_string_table, |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
722 |
the_table()->number_of_entries(), |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
723 |
&MetaspaceShared::stats()->string); |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
724 |
|
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
725 |
// Copy the interned strings into the "string space" within the java heap |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
726 |
if (!copy_shared_string(string_space, &ch_table)) { |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
727 |
return false; |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
728 |
} |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
729 |
|
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
730 |
for (int i = 0; i < string_space->length(); i++) { |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
731 |
*space_size += string_space->at(i).byte_size(); |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
732 |
} |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
733 |
|
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
734 |
// Now dump the compact table |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
735 |
if (*top + ch_table.get_required_bytes() > end) { |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
736 |
// not enough space left |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
737 |
return false; |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
738 |
} |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
739 |
ch_table.dump(top, end); |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
740 |
*top = (char*)align_pointer_up(*top, sizeof(void*)); |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
741 |
|
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
742 |
#endif |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
743 |
return true; |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
744 |
} |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
745 |
|
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
746 |
void StringTable::shared_oops_do(OopClosure* f) { |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
747 |
#if INCLUDE_CDS && defined(_LP64) && !defined(_WINDOWS) |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
748 |
_shared_table.oops_do(f); |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
749 |
#endif |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
750 |
} |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
751 |
|
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
752 |
const char* StringTable::init_shared_table(FileMapInfo *mapinfo, char *buffer) { |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
753 |
#if INCLUDE_CDS && defined(_LP64) && !defined(_WINDOWS) |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
754 |
if (mapinfo->space_capacity(MetaspaceShared::first_string) == 0) { |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
755 |
// no shared string data |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
756 |
return buffer; |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
757 |
} |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
758 |
|
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
759 |
// initialize the shared table |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
760 |
juint *p = (juint*)buffer; |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
761 |
const char* end = _shared_table.init( |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
762 |
CompactHashtable<oop, char>::_string_table, (char*)p); |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
763 |
const char* aligned_end = (const char*)align_pointer_up(end, sizeof(void*)); |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
764 |
|
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
765 |
if (_ignore_shared_strings) { |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
766 |
_shared_table.reset(); |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
767 |
} |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
768 |
|
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
769 |
return aligned_end; |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
770 |
#endif |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
771 |
|
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
772 |
return buffer; |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
30764
diff
changeset
|
773 |
} |