From 18b3ca58d72881d3b6a89c6f299e26635fd149c4 Mon Sep 17 00:00:00 2001 From: Aleksei Voitylov Date: Wed, 19 Jun 2024 15:03:52 +0000 Subject: [PATCH] 8325600: Better symbol storage Reviewed-by: mbalao, andrew Backport-of: da06689bf6fde7b6dd8efc2f0c39fc95adcdb69d --- hotspot/src/share/vm/classfile/symbolTable.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/hotspot/src/share/vm/classfile/symbolTable.cpp b/hotspot/src/share/vm/classfile/symbolTable.cpp index bc706a5bc1..810945d2b4 100644 --- a/hotspot/src/share/vm/classfile/symbolTable.cpp +++ b/hotspot/src/share/vm/classfile/symbolTable.cpp @@ -237,10 +237,10 @@ unsigned int SymbolTable::hash_symbol(const char* s, int len) { // safepoints). // 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::lookup(const char* name, int len, TRAPS) { +static int check_length(const char* name, int len) { assert(len <= Symbol::max_length(), "String length exceeds the maximum Symbol length"); if (len > Symbol::max_length()) { @@ -248,6 +248,11 @@ Symbol* SymbolTable::lookup(const char* name, int len, TRAPS) { "length of %d and has been truncated", name, (name + len - 80), Symbol::max_length()); len = Symbol::max_length(); } + return len; +} + +Symbol* SymbolTable::lookup(const char* name, int len, TRAPS) { + len = check_length(name, len); unsigned int hashValue = hash_symbol(name, len); int index = the_table()->hash_to_index(hashValue); @@ -387,7 +392,8 @@ void SymbolTable::add(ClassLoaderData* loader_data, constantPoolHandle cp, Symbol* SymbolTable::new_permanent_symbol(const char* name, TRAPS) { unsigned int hash; - Symbol* result = SymbolTable::lookup_only((char*)name, (int)strlen(name), hash); + int len = check_length(name, (int)strlen(name)); + Symbol* result = SymbolTable::lookup_only((char*)name, len, hash); if (result != NULL) { return result; } @@ -396,7 +402,7 @@ Symbol* SymbolTable::new_permanent_symbol(const char* name, TRAPS) { SymbolTable* table = the_table(); int index = table->hash_to_index(hash); - return table->basic_add(index, (u1*)name, (int)strlen(name), hash, false, THREAD); + return table->basic_add(index, (u1*)name, len, hash, false, THREAD); } Symbol* SymbolTable::basic_add(int index_arg, u1 *name, int len,