src/share/vm/utilities/hashtable.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File
*** old/src/share/vm/utilities/hashtable.cpp	Wed Feb 26 07:50:02 2014
--- new/src/share/vm/utilities/hashtable.cpp	Wed Feb 26 07:50:02 2014

*** 23,32 **** --- 23,33 ---- */ #include "precompiled.hpp" #include "classfile/altHashing.hpp" #include "classfile/javaClasses.hpp" + #include "code/dependencies.hpp" #include "memory/allocation.inline.hpp" #include "memory/filemap.hpp" #include "memory/resourceArea.hpp" #include "oops/oop.inline.hpp" #include "runtime/safepoint.hpp"
*** 336,346 **** --- 337,346 ---- } #endif // PRODUCT #ifdef ASSERT template <MEMFLAGS F> void BasicHashtable<F>::verify_lookup_length(double load) { if ((double)_lookup_length / (double)_lookup_count > load * 2.0) { warning("Performance bug: SystemDictionary lookup_count=%d "
*** 349,358 **** --- 349,470 ---- (double) _lookup_length / _lookup_count, load); } } #endif + + + template<class T, class M> GenericHashtable<T, M>::GenericHashtable(int size, bool C_heap, MEMFLAGS memflag) { + assert(size > 0, " Invalid hashtable size"); + _size = size; + _C_heap = C_heap; + _memflag = memflag; + // Perform subtype-specific resource allocation + _items = (C_heap) ? NEW_C_HEAP_ARRAY(T*, size, memflag) : NEW_RESOURCE_ARRAY(T*, size); + memset(_items, 0, sizeof(T*) * size); + + DEBUG_ONLY(_num_items = 0;) + } + + template<class T, class M> GenericHashtable<T, M>::~GenericHashtable() { + if (on_C_heap()) { + // Check backing array + for (int i = 0; i < size(); i++) { + T* item = head(i); + // Delete all items in linked list + while (item != NULL) { + T* next_item = item->next(); + delete item; + DEBUG_ONLY(_num_items--); + item = next_item; + } + } + FREE_C_HEAP_ARRAY(T*, _items, _memflag); + _items = NULL; + assert (_num_items == 0, "Not all memory released"); + } + } + + /** + * Return a pointer to the item 'I' that is stored in the hashtable for + * which match_item->equals(I) == true. If no such item is found, NULL + * is returned. + */ + template<class T, class F> T* GenericHashtable<T, F>::contains(T* match_item) { + if (match_item != NULL) { + int idx = index(match_item); + return contains_impl(match_item, idx); + } + return NULL; + } + + /** + * Add item to the hashtable. Return 'true' if the item was added + * and false otherwise. + */ + template<class T, class F> bool GenericHashtable<T, F>::add(T* item) { + if (item != NULL) { + int idx = index(item); + T* found_item = contains_impl(item, idx); + if (found_item == NULL) { + T* list_head = head(idx); + item->set_next(list_head); + item->set_prev(NULL); + + if (list_head != NULL) { + list_head->set_prev(item); + } + set_head(item, idx); + DEBUG_ONLY(_num_items++); + return true; + } + } + return false; + } + + /** + * Removes an item 'I' from the hashtable, if present. 'I' is removed, if + * match_item->equals(I) == true. Removing an item from the hashtable does + * not free memory. + */ + template<class T, class F> T* GenericHashtable<T, F>::remove(T* match_item) { + if (match_item != NULL) { + int idx = index(match_item); + T* found_item = contains_impl(match_item, idx); + if (found_item != NULL) { + // Remove item from linked list + T* prev = found_item->prev(); + T* next = found_item->next(); + if (prev != NULL) { + prev->set_next(next); + } else { + set_head(next, idx); + } + if (next != NULL) { + next->set_prev(prev); + } + + DEBUG_ONLY(_num_items--); + return found_item; + } + } + return NULL; + } + + + template<class T, class F> T* GenericHashtable<T, F>::contains_impl(T* item, int idx) { + T* current_item = head(idx); + while (current_item != NULL) { + if (current_item->equals(item)) { + return current_item; + } + current_item = current_item->next(); + } + return NULL; + } + + // Explicitly instantiate these types template class Hashtable<ConstantPool*, mtClass>; template class Hashtable<Symbol*, mtSymbol>; template class Hashtable<Klass*, mtClass>; template class Hashtable<oop, mtClass>;
*** 368,372 **** --- 480,486 ---- template class BasicHashtableEntry<mtCode>; template class BasicHashtable<mtClass>; template class BasicHashtable<mtSymbol>; template class BasicHashtable<mtCode>; template class BasicHashtable<mtInternal>; + + template class GenericHashtable<DependencySignature, ResourceObj>;

src/share/vm/utilities/hashtable.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File