Skip to content

Commit 18b3ca5

Browse files
Aleksei Voitylovgnu-andrew
authored andcommitted
8325600: Better symbol storage
Reviewed-by: mbalao, andrew Backport-of: da06689bf6fde7b6dd8efc2f0c39fc95adcdb69d
1 parent dfbb2cf commit 18b3ca5

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

hotspot/src/share/vm/classfile/symbolTable.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -237,17 +237,22 @@ unsigned int SymbolTable::hash_symbol(const char* s, int len) {
237237
// safepoints).
238238

239239
// Symbols should represent entities from the constant pool that are
240-
// limited to 64K in length, but usage errors creep in allowing Symbols
240+
// limited to <64K in length, but usage errors creep in allowing Symbols
241241
// to be used for arbitrary strings. For debug builds we will assert if
242242
// a string is too long, whereas product builds will truncate it.
243-
Symbol* SymbolTable::lookup(const char* name, int len, TRAPS) {
243+
static int check_length(const char* name, int len) {
244244
assert(len <= Symbol::max_length(),
245245
"String length exceeds the maximum Symbol length");
246246
if (len > Symbol::max_length()) {
247247
warning("A string \"%.80s ... %.80s\" exceeds the maximum Symbol "
248248
"length of %d and has been truncated", name, (name + len - 80), Symbol::max_length());
249249
len = Symbol::max_length();
250250
}
251+
return len;
252+
}
253+
254+
Symbol* SymbolTable::lookup(const char* name, int len, TRAPS) {
255+
len = check_length(name, len);
251256
unsigned int hashValue = hash_symbol(name, len);
252257
int index = the_table()->hash_to_index(hashValue);
253258

@@ -387,7 +392,8 @@ void SymbolTable::add(ClassLoaderData* loader_data, constantPoolHandle cp,
387392

388393
Symbol* SymbolTable::new_permanent_symbol(const char* name, TRAPS) {
389394
unsigned int hash;
390-
Symbol* result = SymbolTable::lookup_only((char*)name, (int)strlen(name), hash);
395+
int len = check_length(name, (int)strlen(name));
396+
Symbol* result = SymbolTable::lookup_only((char*)name, len, hash);
391397
if (result != NULL) {
392398
return result;
393399
}
@@ -396,7 +402,7 @@ Symbol* SymbolTable::new_permanent_symbol(const char* name, TRAPS) {
396402

397403
SymbolTable* table = the_table();
398404
int index = table->hash_to_index(hash);
399-
return table->basic_add(index, (u1*)name, (int)strlen(name), hash, false, THREAD);
405+
return table->basic_add(index, (u1*)name, len, hash, false, THREAD);
400406
}
401407

402408
Symbol* SymbolTable::basic_add(int index_arg, u1 *name, int len,

0 commit comments

Comments
 (0)