< prev index next >

src/hotspot/share/utilities/hashtable.inline.hpp

Print this page




  26 #define SHARE_UTILITIES_HASHTABLE_INLINE_HPP
  27 
  28 #include "memory/allocation.inline.hpp"
  29 #include "runtime/orderAccess.hpp"
  30 #include "utilities/hashtable.hpp"
  31 #include "utilities/dtrace.hpp"
  32 
  33 // Inline function definitions for hashtable.hpp.
  34 
  35 // --------------------------------------------------------------------------
  36 
  37 // Initialize a table.
  38 
  39 template <MEMFLAGS F> inline BasicHashtable<F>::BasicHashtable(int table_size, int entry_size) {
  40   // Called on startup, no locking needed
  41   initialize(table_size, entry_size, 0);
  42   _buckets = NEW_C_HEAP_ARRAY2(HashtableBucket<F>, table_size, F, CURRENT_PC);
  43   for (int index = 0; index < _table_size; index++) {
  44     _buckets[index].clear();
  45   }

  46 }
  47 
  48 
  49 template <MEMFLAGS F> inline BasicHashtable<F>::BasicHashtable(int table_size, int entry_size,
  50                                       HashtableBucket<F>* buckets,
  51                                       int number_of_entries) {
  52   // Called on startup, no locking needed
  53   initialize(table_size, entry_size, number_of_entries);
  54   _buckets = buckets;

  55 }
  56 
  57 template <MEMFLAGS F> inline BasicHashtable<F>::~BasicHashtable() {
  58   for (int i = 0; i < _entry_blocks->length(); i++) {
  59     FREE_C_HEAP_ARRAY(char, _entry_blocks->at(i));
  60   }
  61   delete _entry_blocks;
  62   free_buckets();
  63 }
  64 
  65 template <MEMFLAGS F> inline void BasicHashtable<F>::initialize(int table_size, int entry_size,
  66                                        int number_of_entries) {
  67   // Called on startup, no locking needed
  68   _table_size = table_size;
  69   _entry_size = entry_size;
  70   _free_list = NULL;
  71   _first_free_entry = NULL;
  72   _end_block = NULL;
  73   _number_of_entries = number_of_entries;
  74   _entry_blocks = new(ResourceObj::C_HEAP, F) GrowableArray<char*>(4, true, F);


  84 template <MEMFLAGS F> inline void HashtableBucket<F>::set_entry(BasicHashtableEntry<F>* l) {
  85   // Warning: Preserve store ordering.  The PackageEntryTable, ModuleEntryTable and
  86   //          SystemDictionary are read without locks.  The new entry must be
  87   //          complete before other threads can be allowed to see it
  88   //          via a store to _buckets[index].
  89   OrderAccess::release_store(&_entry, l);
  90 }
  91 
  92 
  93 template <MEMFLAGS F> inline BasicHashtableEntry<F>* HashtableBucket<F>::get_entry() const {
  94   // Warning: Preserve load ordering.  The PackageEntryTable, ModuleEntryTable and
  95   //          SystemDictionary are read without locks.  The new entry must be
  96   //          complete before other threads can be allowed to see it
  97   //          via a store to _buckets[index].
  98   return OrderAccess::load_acquire(&_entry);
  99 }
 100 
 101 
 102 template <MEMFLAGS F> inline void BasicHashtable<F>::set_entry(int index, BasicHashtableEntry<F>* entry) {
 103   _buckets[index].set_entry(entry);





 104 }
 105 
 106 
 107 template <MEMFLAGS F> inline void BasicHashtable<F>::add_entry(int index, BasicHashtableEntry<F>* entry) {
 108   entry->set_next(bucket(index));
 109   _buckets[index].set_entry(entry);
 110   ++_number_of_entries;

 111 }
 112 
 113 template <MEMFLAGS F> inline void BasicHashtable<F>::free_entry(BasicHashtableEntry<F>* entry) {
 114   entry->set_next(_free_list);
 115   _free_list = entry;
 116   --_number_of_entries;

 117 }
 118 
 119 #endif // SHARE_UTILITIES_HASHTABLE_INLINE_HPP


  26 #define SHARE_UTILITIES_HASHTABLE_INLINE_HPP
  27 
  28 #include "memory/allocation.inline.hpp"
  29 #include "runtime/orderAccess.hpp"
  30 #include "utilities/hashtable.hpp"
  31 #include "utilities/dtrace.hpp"
  32 
  33 // Inline function definitions for hashtable.hpp.
  34 
  35 // --------------------------------------------------------------------------
  36 
  37 // Initialize a table.
  38 
  39 template <MEMFLAGS F> inline BasicHashtable<F>::BasicHashtable(int table_size, int entry_size) {
  40   // Called on startup, no locking needed
  41   initialize(table_size, entry_size, 0);
  42   _buckets = NEW_C_HEAP_ARRAY2(HashtableBucket<F>, table_size, F, CURRENT_PC);
  43   for (int index = 0; index < _table_size; index++) {
  44     _buckets[index].clear();
  45   }
  46   _stats_rate = TableRateStatistics();
  47 }
  48 
  49 
  50 template <MEMFLAGS F> inline BasicHashtable<F>::BasicHashtable(int table_size, int entry_size,
  51                                       HashtableBucket<F>* buckets,
  52                                       int number_of_entries) {
  53   // Called on startup, no locking needed
  54   initialize(table_size, entry_size, number_of_entries);
  55   _buckets = buckets;
  56   _stats_rate = TableRateStatistics();
  57 }
  58 
  59 template <MEMFLAGS F> inline BasicHashtable<F>::~BasicHashtable() {
  60   for (int i = 0; i < _entry_blocks->length(); i++) {
  61     FREE_C_HEAP_ARRAY(char, _entry_blocks->at(i));
  62   }
  63   delete _entry_blocks;
  64   free_buckets();
  65 }
  66 
  67 template <MEMFLAGS F> inline void BasicHashtable<F>::initialize(int table_size, int entry_size,
  68                                        int number_of_entries) {
  69   // Called on startup, no locking needed
  70   _table_size = table_size;
  71   _entry_size = entry_size;
  72   _free_list = NULL;
  73   _first_free_entry = NULL;
  74   _end_block = NULL;
  75   _number_of_entries = number_of_entries;
  76   _entry_blocks = new(ResourceObj::C_HEAP, F) GrowableArray<char*>(4, true, F);


  86 template <MEMFLAGS F> inline void HashtableBucket<F>::set_entry(BasicHashtableEntry<F>* l) {
  87   // Warning: Preserve store ordering.  The PackageEntryTable, ModuleEntryTable and
  88   //          SystemDictionary are read without locks.  The new entry must be
  89   //          complete before other threads can be allowed to see it
  90   //          via a store to _buckets[index].
  91   OrderAccess::release_store(&_entry, l);
  92 }
  93 
  94 
  95 template <MEMFLAGS F> inline BasicHashtableEntry<F>* HashtableBucket<F>::get_entry() const {
  96   // Warning: Preserve load ordering.  The PackageEntryTable, ModuleEntryTable and
  97   //          SystemDictionary are read without locks.  The new entry must be
  98   //          complete before other threads can be allowed to see it
  99   //          via a store to _buckets[index].
 100   return OrderAccess::load_acquire(&_entry);
 101 }
 102 
 103 
 104 template <MEMFLAGS F> inline void BasicHashtable<F>::set_entry(int index, BasicHashtableEntry<F>* entry) {
 105   _buckets[index].set_entry(entry);
 106   if (entry != NULL) {
 107     JFR_ONLY(_stats_rate.add();)
 108   } else {
 109     JFR_ONLY(_stats_rate.remove();)
 110   }
 111 }
 112 
 113 
 114 template <MEMFLAGS F> inline void BasicHashtable<F>::add_entry(int index, BasicHashtableEntry<F>* entry) {
 115   entry->set_next(bucket(index));
 116   _buckets[index].set_entry(entry);
 117   ++_number_of_entries;
 118   JFR_ONLY(_stats_rate.add();)
 119 }
 120 
 121 template <MEMFLAGS F> inline void BasicHashtable<F>::free_entry(BasicHashtableEntry<F>* entry) {
 122   entry->set_next(_free_list);
 123   _free_list = entry;
 124   --_number_of_entries;
 125   JFR_ONLY(_stats_rate.remove();)
 126 }
 127 
 128 #endif // SHARE_UTILITIES_HASHTABLE_INLINE_HPP
< prev index next >