changeset 53213:0e5c83bf4ff7

8215228: Use a constant hash table size in order to enable compiler optimization Summary: Remove a field from KlassInfoTable to allow compiler optimizations Reviewed-by: phh, aph Contributed-by: zanglin5@jd.com
author jcbeyler
date Tue, 11 Dec 2018 10:23:15 -0800
parents de99beff5c0e
children d5a2a29ca589
files src/hotspot/share/memory/heapInspection.cpp src/hotspot/share/memory/heapInspection.hpp
diffstat 2 files changed, 6 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/src/hotspot/share/memory/heapInspection.cpp	Mon Dec 17 11:37:40 2018 +0100
+++ b/src/hotspot/share/memory/heapInspection.cpp	Tue Dec 11 10:23:15 2018 -0800
@@ -168,14 +168,12 @@
 
 KlassInfoTable::KlassInfoTable(bool add_all_classes) {
   _size_of_instances_in_words = 0;
-  _size = 0;
   _ref = (HeapWord*) Universe::boolArrayKlassObj();
   _buckets =
     (KlassInfoBucket*)  AllocateHeap(sizeof(KlassInfoBucket) * _num_buckets,
        mtInternal, CURRENT_PC, AllocFailStrategy::RETURN_NULL);
   if (_buckets != NULL) {
-    _size = _num_buckets;
-    for (int index = 0; index < _size; index++) {
+    for (int index = 0; index < _num_buckets; index++) {
       _buckets[index].initialize();
     }
     if (add_all_classes) {
@@ -187,11 +185,11 @@
 
 KlassInfoTable::~KlassInfoTable() {
   if (_buckets != NULL) {
-    for (int index = 0; index < _size; index++) {
+    for (int index = 0; index < _num_buckets; index++) {
       _buckets[index].empty();
     }
     FREE_C_HEAP_ARRAY(KlassInfoBucket, _buckets);
-    _size = 0;
+    _buckets = NULL;
   }
 }
 
@@ -200,7 +198,7 @@
 }
 
 KlassInfoEntry* KlassInfoTable::lookup(Klass* k) {
-  uint         idx = hash(k) % _size;
+  uint         idx = hash(k) % _num_buckets;
   assert(_buckets != NULL, "Allocation failure should have been caught");
   KlassInfoEntry*  e   = _buckets[idx].lookup(k);
   // Lookup may fail if this is a new klass for which we
@@ -227,8 +225,8 @@
 }
 
 void KlassInfoTable::iterate(KlassInfoClosure* cic) {
-  assert(_size == 0 || _buckets != NULL, "Allocation failure should have been caught");
-  for (int index = 0; index < _size; index++) {
+  assert(_buckets != NULL, "Allocation failure should have been caught");
+  for (int index = 0; index < _num_buckets; index++) {
     _buckets[index].iterate(cic);
   }
 }
--- a/src/hotspot/share/memory/heapInspection.hpp	Mon Dec 17 11:37:40 2018 +0100
+++ b/src/hotspot/share/memory/heapInspection.hpp	Tue Dec 11 10:23:15 2018 -0800
@@ -234,7 +234,6 @@
 
 class KlassInfoTable: public StackObj {
  private:
-  int _size;
   static const int _num_buckets = 20011;
   size_t _size_of_instances_in_words;