--- old/src/share/vm/utilities/hashtable.hpp 2014-02-21 09:04:02.794118568 +0100 +++ new/src/share/vm/utilities/hashtable.hpp 2014-02-21 09:04:02.682118572 +0100 @@ -300,7 +300,7 @@ }; -// Verions of hashtable where two handles are used to compute the index. +// Versions of hashtable where two handles are used to compute the index. template class TwoOopHashtable : public Hashtable { friend class VMStructs; @@ -327,4 +327,65 @@ } }; + +/* + * Usage of GenericHashtable: + * + * class X : public GenericHashtableEntry { + * + * // Implement virtual functions in class X + * bool equals(X* sig) const; + * uintptr_t hash() const; + * }; + * + * void foo() { + * GenericHashtable* table = new GenericHashtable(11027, false); + * + * X* elem = new X(); + * table->add(elem); + * table->contains(elem); + * } + * + * You can choose other allocation types as well. For example, to store the hashtable to a + * particular region (CHeapObj) simply replace ResourceObj with the desired type: + * + * class X : public GenericHashtableEntry > { ... }; + * + * If you use this templates do not forget to add an explicit initialization + * (at the end of hashtable.cpp). + * + * template class GenericHashtable; + */ +template class GenericHashtableEntry : public M { + private: + T* _next; + public: + // Must be implemented by subclass + virtual uintptr_t hash() const = 0; + virtual bool equals(T* other) const = 0; + + T* next() { return _next; } + void set_next(T* next) { _next = next; } + + // Constructor and destructor + GenericHashtableEntry() : _next(NULL) { }; + virtual ~GenericHashtableEntry() {}; +}; + +template class GenericHashtable : public M { + private: + T** _elements; + int _size; + T* element_at(int idx) { return _elements[idx]; } + void set_element_at(T* element, int idx) { _elements[idx] = element; } + + public: + GenericHashtable(int size, bool resource_mark, MEMFLAGS memflag = mtNone); + ~GenericHashtable() { Unimplemented(); } // Can be added later, if needed + bool add(T* element); + bool contains(T* element); + bool remove(T* element) { Unimplemented(); return false; } + int size() { return _size; } +}; + #endif // SHARE_VM_UTILITIES_HASHTABLE_HPP