src/share/vm/utilities/hashtable.hpp
Index
Unified diffs
Context diffs
Sdiffs
Patch
New
Old
Previous File
Next File
JDK-8034839 Cdiff src/share/vm/utilities/hashtable.hpp
src/share/vm/utilities/hashtable.hpp
Print this page
*** 298,308 ****
private:
static juint _seed;
};
! // Verions of hashtable where two handles are used to compute the index.
template <class T, MEMFLAGS F> class TwoOopHashtable : public Hashtable<T, F> {
friend class VMStructs;
protected:
TwoOopHashtable(int table_size, int entry_size)
--- 298,308 ----
private:
static juint _seed;
};
! // Versions of hashtable where two handles are used to compute the index.
template <class T, MEMFLAGS F> class TwoOopHashtable : public Hashtable<T, F> {
friend class VMStructs;
protected:
TwoOopHashtable(int table_size, int entry_size)
*** 325,330 ****
--- 325,391 ----
int index_for(Symbol* name, ClassLoaderData* loader_data) {
return this->hash_to_index(compute_hash(name, loader_data));
}
};
+
+ /*
+ * Usage of GenericHashtable:
+ *
+ * class X : public GenericHashtableEntry<X, ResourceObj> {
+ *
+ * // Implement virtual functions in class X
+ * bool equals(X* sig) const;
+ * uintptr_t hash() const;
+ * };
+ *
+ * void foo() {
+ * GenericHashtable<X, ResourceObj>* table = new GenericHashtable<X, ResourceObj>(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<type>) simply replace ResourceObj with the desired type:
+ *
+ * class X : public GenericHashtableEntry<X, CHeapObj<mtCode> > { ... };
+ *
+ * If you use this templates do not forget to add an explicit initialization
+ * (at the end of hashtable.cpp).
+ *
+ * template class GenericHashtable<X, ResourceObj>;
+ */
+ template <class T, class M> 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 T, class M> 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
src/share/vm/utilities/hashtable.hpp
Index
Unified diffs
Context diffs
Sdiffs
Patch
New
Old
Previous File
Next File