Skip to content

Commit 67a34da

Browse files
author
Kim Barrett
committed
8260630: Templatize literal_size
8260629: Remove explicit instantiation of Hashtable with oop value Reviewed-by: pliden, tschatzl, coleenp
1 parent 6b24e98 commit 67a34da

File tree

1 file changed

+3
-13
lines changed

1 file changed

+3
-13
lines changed

src/hotspot/share/utilities/hashtable.cpp

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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

118116
static int literal_size(Symbol *symbol) {
119117
return symbol->size() * HeapWordSize;
120118
}
121119

122120
static 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.
242234
template <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>;
318310
template class Hashtable<WeakHandle, mtClass>;
319311
template class Hashtable<WeakHandle, mtServiceability>;
320312
template class Hashtable<Symbol*, mtModule>;
321-
template class Hashtable<oop, mtSymbol>;
322313
template class Hashtable<Symbol*, mtClass>;
323314
template class HashtableEntry<Symbol*, mtSymbol>;
324315
template class HashtableEntry<Symbol*, mtClass>;
325-
template class HashtableEntry<oop, mtSymbol>;
326316
template class HashtableBucket<mtClass>;
327317
template class BasicHashtableEntry<mtSymbol>;
328318
template class BasicHashtableEntry<mtCode>;

0 commit comments

Comments
 (0)