8325600: Better symbol storage

Reviewed-by: coleenp, rhalade, matsaave
This commit is contained in:
David Holmes 2024-02-13 21:15:08 +00:00 committed by Jaikiran Pai
parent aea9a08beb
commit c5a8c8a0b6

@ -345,10 +345,10 @@ Symbol* SymbolTable::lookup_common(const char* name,
}
// Symbols should represent entities from the constant pool that are
// limited to 64K in length, but usage errors creep in allowing Symbols
// limited to <64K in length, but usage errors creep in allowing Symbols
// to be used for arbitrary strings. For debug builds we will assert if
// a string is too long, whereas product builds will truncate it.
Symbol* SymbolTable::new_symbol(const char* name, int len) {
static int check_length(const char* name, int len) {
assert(len <= Symbol::max_length(),
"String length %d exceeds the maximum Symbol length of %d", len, Symbol::max_length());
if (len > Symbol::max_length()) {
@ -356,7 +356,11 @@ Symbol* SymbolTable::new_symbol(const char* name, int len) {
"length of %d and has been truncated", name, (name + len - 80), Symbol::max_length());
len = Symbol::max_length();
}
return len;
}
Symbol* SymbolTable::new_symbol(const char* name, int len) {
len = check_length(name, len);
unsigned int hash = hash_symbol(name, len, _alt_hash);
Symbol* sym = lookup_common(name, len, hash);
if (sym == nullptr) {
@ -555,7 +559,7 @@ Symbol* SymbolTable::do_add_if_needed(const char* name, int len, uintx hash, boo
Symbol* SymbolTable::new_permanent_symbol(const char* name) {
unsigned int hash = 0;
int len = (int)strlen(name);
int len = check_length(name, (int)strlen(name));
Symbol* sym = SymbolTable::lookup_only(name, len, hash);
if (sym == nullptr) {
sym = do_add_if_needed(name, len, hash, /* is_permanent */ true);