@@ -110,22 +110,18 @@ template <MEMFLAGS F> void BasicHashtable<F>::free_buckets() {
110110 _buckets = NULL ;
111111}
112112
113- // For oops and Strings the size of the literal is interesting. For other types, nobody cares.
114- static int literal_size (ConstantPool*) { return 0 ; }
115- static int literal_size (Klass*) { return 0 ; }
116- static int literal_size (nmethod*) { return 0 ; }
113+ // Default overload, for types that are uninteresting.
114+ template <typename T> static int literal_size (T) { return 0 ; }
117115
118116static int literal_size (Symbol *symbol) {
119117 return symbol->size () * HeapWordSize;
120118}
121119
122120static int literal_size (oop obj) {
123- // NOTE: this would over-count if (pre-JDK8) java_lang_Class::has_offset_field() is true,
124- // and the String.value array is shared by several Strings. However, starting from JDK8,
125- // the String.value array is not shared anymore.
126121 if (obj == NULL ) {
127122 return 0 ;
128123 } else if (obj->klass () == SystemDictionary::String_klass ()) {
124+ // This may overcount if String.value arrays are shared.
129125 return (obj->size () + java_lang_String::value (obj)->size ()) * HeapWordSize;
130126 } else {
131127 return obj->size ();
@@ -235,10 +231,6 @@ template <class T, MEMFLAGS F> TableStatistics Hashtable<T, F>::statistics_calcu
235231}
236232
237233// Dump footprint and bucket length statistics
238- //
239- // Note: if you create a new subclass of Hashtable<MyNewType, F>, you will need to
240- // add a new function static int literal_size(MyNewType lit)
241- // because I can't get template <class T> int literal_size(T) to pick the specializations for Symbol and oop.
242234template <class T , MEMFLAGS F> void Hashtable<T, F>::print_table_statistics(outputStream* st,
243235 const char *table_name,
244236 T (*literal_load_barrier)(HashtableEntry<T, F>*)) {
@@ -318,11 +310,9 @@ template class Hashtable<InstanceKlass*, mtClass>;
318310template class Hashtable <WeakHandle, mtClass>;
319311template class Hashtable <WeakHandle, mtServiceability>;
320312template class Hashtable <Symbol*, mtModule>;
321- template class Hashtable <oop, mtSymbol>;
322313template class Hashtable <Symbol*, mtClass>;
323314template class HashtableEntry <Symbol*, mtSymbol>;
324315template class HashtableEntry <Symbol*, mtClass>;
325- template class HashtableEntry <oop, mtSymbol>;
326316template class HashtableBucket <mtClass>;
327317template class BasicHashtableEntry <mtSymbol>;
328318template class BasicHashtableEntry <mtCode>;
0 commit comments