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

## src/share/vm/utilities/hashtable.inline.hpp

Print this page

      20  * or visit www.oracle.com if you need additional information or have any
      21  * questions.
      22  *
      23  */
      24
      25 #ifndef SHARE_VM_UTILITIES_HASHTABLE_INLINE_HPP
      26 #define SHARE_VM_UTILITIES_HASHTABLE_INLINE_HPP
      27
      28 #include "memory/allocation.inline.hpp"
      29 #include "runtime/orderAccess.inline.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
      58 template <MEMFLAGS F> inline void BasicHashtable<F>::initialize(int table_size, int entry_size,
      59                                        int number_of_entries) {

      60   // Called on startup, no locking needed
      61   _table_size = table_size;
      62   _entry_size = entry_size;
      63   _free_list = NULL;
      64   _first_free_entry = NULL;
      65   _end_block = NULL;
      66   _number_of_entries = number_of_entries;

      67 #ifdef ASSERT
      68   _lookup_count = 0;
      69   _lookup_length = 0;
      70 #endif
      71 }
      72
      73
      74 // The following method is MT-safe and may be used with caution.
      75 template <MEMFLAGS F> inline BasicHashtableEntry<F>* BasicHashtable<F>::bucket(int i) {
      76   return _buckets[i].get_entry();
      77 }
      78
      79
      80 template <MEMFLAGS F> inline void HashtableBucket<F>::set_entry(BasicHashtableEntry<F>* l) {
      81   // Warning: Preserve store ordering.  The SystemDictionary is read
      82   //          without locks.  The new SystemDictionaryEntry must be
      83   //          complete before other threads can be allowed to see it
      84   //          via a store to _buckets[index].
      85   OrderAccess::release_store_ptr(&_entry, l);
      86 }
      20  * or visit www.oracle.com if you need additional information or have any
      21  * questions.
      22  *
      23  */
      24
      25 #ifndef SHARE_VM_UTILITIES_HASHTABLE_INLINE_HPP
      26 #define SHARE_VM_UTILITIES_HASHTABLE_INLINE_HPP
      27
      28 #include "memory/allocation.inline.hpp"
      29 #include "runtime/orderAccess.inline.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   if (HashtablesUseEvenSize == true) {
      41     table_size += (table_size%2);
      42   }
      43   // Called on startup, no locking needed
      44   initialize(table_size, entry_size, 0);
      45   _buckets = NEW_C_HEAP_ARRAY2(HashtableBucket<F>, table_size, F, CURRENT_PC);
      46   for (int index = 0; index < _table_size; index++) {
      47     _buckets[index].clear();
      48   }
      49 }
      50
      51
      52 template <MEMFLAGS F> inline BasicHashtable<F>::BasicHashtable(int table_size, int entry_size,
      53                                       HashtableBucket<F>* buckets,
      54                                       int number_of_entries) {
      55   // Called on startup, no locking needed
      56   initialize(table_size, entry_size, number_of_entries);
      57   _buckets = buckets;
      58 }
      59
      60
      61 template <MEMFLAGS F> inline void BasicHashtable<F>::initialize(int table_size, int entry_size,
      62                                        int number_of_entries) {
      63 #ifdef PRINT_HASHTABLES_CREATION
      64   fprintf(stderr, "BasicHashtable %p with size %d\n", this, (int)table_size);
      65 #endif
      66   // Called on startup, no locking needed
      67   _table_size = table_size;
      68   _entry_size = entry_size;
      69   _free_list = NULL;
      70   _first_free_entry = NULL;
      71   _end_block = NULL;
      72   _number_of_entries = number_of_entries;
      73
      74 #ifndef PRODUCT
      75 //#ifdef PRODUCT_TEST
      76   for (int i=0; i<1024; i++) {
      77     _debug_table_threads[i] = 0;
      78   }
      79   _debug_resize_fire = 0;
      80   _debug_all_lookup_count = 0;
      81   _debug_all_insertion_count = 0;
      82   _debug_lookup_count = 0;
      83   _debug_insertion_count = 0;
      84   _debug_lookup_found_count = 0;
      85   _debug_lookup_found_max_duration = 0;
      86   _debug_lookup_found_total_duration = 0;
      87   _debug_chain_found_maximum_length = 0;
      88   _debug_chain_found_total_length = 0;
      89   _debug_lookup_failed_count = 0;
      90   _debug_lookup_failed_max_duration = 0;
      91   _debug_lookup_failed_total_duration = 0;
      92   _debug_chain_failed_maximum_length = 0;
      93   _debug_chain_failed_total_length = 0;
      94   _debug_resize_max_duration = 0;
      95   _debug_resize_total_duration = 0;
      96   _debug_resize_total_count = 0;
      97 #endif
      98
      99 #ifdef ASSERT
     100   _lookup_count = 0;
     101   _lookup_length = 0;
     102 #endif
     103 }
     104
     105
     106 // The following method is MT-safe and may be used with caution.
     107 template <MEMFLAGS F> inline BasicHashtableEntry<F>* BasicHashtable<F>::bucket(int i) {
     108   return _buckets[i].get_entry();
     109 }
     110
     111
     112 template <MEMFLAGS F> inline void HashtableBucket<F>::set_entry(BasicHashtableEntry<F>* l) {
     113   // Warning: Preserve store ordering.  The SystemDictionary is read
     114   //          without locks.  The new SystemDictionaryEntry must be
     115   //          complete before other threads can be allowed to see it
     116   //          via a store to _buckets[index].
     117   OrderAccess::release_store_ptr(&_entry, l);
     118 }

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