Skip to content

Commit

Permalink
8260630: Templatize literal_size
Browse files Browse the repository at this point in the history
8260629: Remove explicit instantiation of Hashtable with oop value

Reviewed-by: pliden, tschatzl, coleenp
  • Loading branch information
Kim Barrett committed Jan 30, 2021
1 parent 6b24e98 commit 67a34da
Showing 1 changed file with 3 additions and 13 deletions.
16 changes: 3 additions & 13 deletions src/hotspot/share/utilities/hashtable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,22 +110,18 @@ template <MEMFLAGS F> void BasicHashtable<F>::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<typename T> 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();
Expand Down Expand Up @@ -235,10 +231,6 @@ template <class T, MEMFLAGS F> TableStatistics Hashtable<T, F>::statistics_calcu
}

// Dump footprint and bucket length statistics
//
// Note: if you create a new subclass of Hashtable<MyNewType, F>, you will need to
// add a new function static int literal_size(MyNewType lit)
// because I can't get template <class T> int literal_size(T) to pick the specializations for Symbol and oop.
template <class T, MEMFLAGS F> void Hashtable<T, F>::print_table_statistics(outputStream* st,
const char *table_name,
T (*literal_load_barrier)(HashtableEntry<T, F>*)) {
Expand Down Expand Up @@ -318,11 +310,9 @@ template class Hashtable<InstanceKlass*, mtClass>;
template class Hashtable<WeakHandle, mtClass>;
template class Hashtable<WeakHandle, mtServiceability>;
template class Hashtable<Symbol*, mtModule>;
template class Hashtable<oop, mtSymbol>;
template class Hashtable<Symbol*, mtClass>;
template class HashtableEntry<Symbol*, mtSymbol>;
template class HashtableEntry<Symbol*, mtClass>;
template class HashtableEntry<oop, mtSymbol>;
template class HashtableBucket<mtClass>;
template class BasicHashtableEntry<mtSymbol>;
template class BasicHashtableEntry<mtCode>;
Expand Down

1 comment on commit 67a34da

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.