diff --git a/src/hotspot/share/utilities/hashtable.cpp b/src/hotspot/share/utilities/hashtable.cpp index b7fa6481adf..f456047c0f9 100644 --- a/src/hotspot/share/utilities/hashtable.cpp +++ b/src/hotspot/share/utilities/hashtable.cpp @@ -110,22 +110,18 @@ template void BasicHashtable::free_buckets() { _buckets = NULL; } -// For oops and Strings the size of the literal is interesting. For other types, nobody cares. -static int literal_size(ConstantPool*) { return 0; } -static int literal_size(Klass*) { return 0; } -static int literal_size(nmethod*) { return 0; } +// Default overload, for types that are uninteresting. +template static int literal_size(T) { return 0; } static int literal_size(Symbol *symbol) { return symbol->size() * HeapWordSize; } static int literal_size(oop obj) { - // NOTE: this would over-count if (pre-JDK8) java_lang_Class::has_offset_field() is true, - // and the String.value array is shared by several Strings. However, starting from JDK8, - // the String.value array is not shared anymore. if (obj == NULL) { return 0; } else if (obj->klass() == SystemDictionary::String_klass()) { + // This may overcount if String.value arrays are shared. return (obj->size() + java_lang_String::value(obj)->size()) * HeapWordSize; } else { return obj->size(); @@ -235,10 +231,6 @@ template TableStatistics Hashtable::statistics_calcu } // Dump footprint and bucket length statistics -// -// Note: if you create a new subclass of Hashtable, you will need to -// add a new function static int literal_size(MyNewType lit) -// because I can't get template int literal_size(T) to pick the specializations for Symbol and oop. template void Hashtable::print_table_statistics(outputStream* st, const char *table_name, T (*literal_load_barrier)(HashtableEntry*)) { @@ -318,11 +310,9 @@ template class Hashtable; template class Hashtable; template class Hashtable; template class Hashtable; -template class Hashtable; template class Hashtable; template class HashtableEntry; template class HashtableEntry; -template class HashtableEntry; template class HashtableBucket; template class BasicHashtableEntry; template class BasicHashtableEntry;