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