< prev index next >

src/hotspot/share/utilities/hashtable.cpp

Print this page


  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "classfile/altHashing.hpp"
  27 #include "classfile/dictionary.hpp"
  28 #include "classfile/javaClasses.inline.hpp"
  29 #include "classfile/moduleEntry.hpp"
  30 #include "classfile/packageEntry.hpp"
  31 #include "classfile/placeholders.hpp"
  32 #include "classfile/protectionDomainCache.hpp"
  33 #include "classfile/stringTable.hpp"
  34 #include "memory/allocation.inline.hpp"
  35 #include "memory/filemap.hpp"
  36 #include "memory/resourceArea.hpp"
  37 #include "oops/oop.inline.hpp"
  38 #include "runtime/safepoint.hpp"
  39 #include "utilities/dtrace.hpp"
  40 #include "utilities/hashtable.hpp"
  41 #include "utilities/hashtable.inline.hpp"
  42 #include "utilities/numberSeq.hpp"
  43 
  44 
  45 // This hashtable is implemented as an open hash table with a fixed number of buckets.
  46 
  47 template <MEMFLAGS F> BasicHashtableEntry<F>* BasicHashtable<F>::new_entry_free_list() {
  48   BasicHashtableEntry<F>* entry = NULL;
  49   if (_free_list != NULL) {
  50     entry = _free_list;
  51     _free_list = _free_list->next();
  52   }
  53   return entry;
  54 }
  55 


 144         p->set_shared();
 145       }
 146       p = next;
 147     }
 148   }
 149   // give the new table the free list as well
 150   new_table->copy_freelist(this);
 151   assert(new_table->number_of_entries() == saved_entry_count, "lost entry on dictionary copy?");
 152 
 153   // Destroy memory used by the buckets in the hashtable.  The memory
 154   // for the elements has been used in a new table and is not
 155   // destroyed.  The memory reuse will benefit resizing the SystemDictionary
 156   // to avoid a memory allocation spike at safepoint.
 157   BasicHashtable<F>::free_buckets();
 158 }
 159 
 160 template <MEMFLAGS F> void BasicHashtable<F>::free_buckets() {
 161   if (NULL != _buckets) {
 162     // Don't delete the buckets in the shared space.  They aren't
 163     // allocated by os::malloc
 164     if (!UseSharedSpaces ||
 165         !FileMapInfo::current_info()->is_in_shared_space(_buckets)) {
 166        FREE_C_HEAP_ARRAY(HashtableBucket, _buckets);
 167     }
 168     _buckets = NULL;
 169   }
 170 }
 171 
 172 template <MEMFLAGS F> void BasicHashtable<F>::BucketUnlinkContext::free_entry(BasicHashtableEntry<F>* entry) {
 173   entry->set_next(_removed_head);
 174   _removed_head = entry;
 175   if (_removed_tail == NULL) {
 176     _removed_tail = entry;
 177   }
 178   _num_removed++;
 179 }
 180 
 181 template <MEMFLAGS F> void BasicHashtable<F>::bulk_free_entries(BucketUnlinkContext* context) {
 182   if (context->_num_removed == 0) {
 183     assert(context->_removed_head == NULL && context->_removed_tail == NULL,
 184            "Zero entries in the unlink context, but elements linked from " PTR_FORMAT " to " PTR_FORMAT,
 185            p2i(context->_removed_head), p2i(context->_removed_tail));




  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "classfile/altHashing.hpp"
  27 #include "classfile/dictionary.hpp"
  28 #include "classfile/javaClasses.inline.hpp"
  29 #include "classfile/moduleEntry.hpp"
  30 #include "classfile/packageEntry.hpp"
  31 #include "classfile/placeholders.hpp"
  32 #include "classfile/protectionDomainCache.hpp"
  33 #include "classfile/stringTable.hpp"
  34 #include "memory/allocation.inline.hpp"
  35 #include "memory/metaspaceShared.hpp"
  36 #include "memory/resourceArea.hpp"
  37 #include "oops/oop.inline.hpp"
  38 #include "runtime/safepoint.hpp"
  39 #include "utilities/dtrace.hpp"
  40 #include "utilities/hashtable.hpp"
  41 #include "utilities/hashtable.inline.hpp"
  42 #include "utilities/numberSeq.hpp"
  43 
  44 
  45 // This hashtable is implemented as an open hash table with a fixed number of buckets.
  46 
  47 template <MEMFLAGS F> BasicHashtableEntry<F>* BasicHashtable<F>::new_entry_free_list() {
  48   BasicHashtableEntry<F>* entry = NULL;
  49   if (_free_list != NULL) {
  50     entry = _free_list;
  51     _free_list = _free_list->next();
  52   }
  53   return entry;
  54 }
  55 


 144         p->set_shared();
 145       }
 146       p = next;
 147     }
 148   }
 149   // give the new table the free list as well
 150   new_table->copy_freelist(this);
 151   assert(new_table->number_of_entries() == saved_entry_count, "lost entry on dictionary copy?");
 152 
 153   // Destroy memory used by the buckets in the hashtable.  The memory
 154   // for the elements has been used in a new table and is not
 155   // destroyed.  The memory reuse will benefit resizing the SystemDictionary
 156   // to avoid a memory allocation spike at safepoint.
 157   BasicHashtable<F>::free_buckets();
 158 }
 159 
 160 template <MEMFLAGS F> void BasicHashtable<F>::free_buckets() {
 161   if (NULL != _buckets) {
 162     // Don't delete the buckets in the shared space.  They aren't
 163     // allocated by os::malloc
 164     if (!MetaspaceShared::is_in_shared_metaspace(_buckets)) {

 165        FREE_C_HEAP_ARRAY(HashtableBucket, _buckets);
 166     }
 167     _buckets = NULL;
 168   }
 169 }
 170 
 171 template <MEMFLAGS F> void BasicHashtable<F>::BucketUnlinkContext::free_entry(BasicHashtableEntry<F>* entry) {
 172   entry->set_next(_removed_head);
 173   _removed_head = entry;
 174   if (_removed_tail == NULL) {
 175     _removed_tail = entry;
 176   }
 177   _num_removed++;
 178 }
 179 
 180 template <MEMFLAGS F> void BasicHashtable<F>::bulk_free_entries(BucketUnlinkContext* context) {
 181   if (context->_num_removed == 0) {
 182     assert(context->_removed_head == NULL && context->_removed_tail == NULL,
 183            "Zero entries in the unlink context, but elements linked from " PTR_FORMAT " to " PTR_FORMAT,
 184            p2i(context->_removed_head), p2i(context->_removed_tail));


< prev index next >