src/hotspot/share/classfile/compactHashtable.hpp
changeset 54927 1512d88b24c6
parent 53244 9807daeb47c4
equal deleted inserted replaced
54926:d4e7ccaf1445 54927:1512d88b24c6
    98       return (_value == other._value && _hash == other._hash);
    98       return (_value == other._value && _hash == other._hash);
    99     }
    99     }
   100   }; // class CompactHashtableWriter::Entry
   100   }; // class CompactHashtableWriter::Entry
   101 
   101 
   102 private:
   102 private:
   103   int _num_entries;
   103   int _num_entries_written;
   104   int _num_buckets;
   104   int _num_buckets;
   105   int _num_empty_buckets;
   105   int _num_empty_buckets;
   106   int _num_value_only_buckets;
   106   int _num_value_only_buckets;
   107   int _num_other_buckets;
   107   int _num_other_buckets;
   108   GrowableArray<Entry>** _buckets;
   108   GrowableArray<Entry>** _buckets;
   110   Array<u4>* _compact_buckets;
   110   Array<u4>* _compact_buckets;
   111   Array<u4>* _compact_entries;
   111   Array<u4>* _compact_entries;
   112 
   112 
   113 public:
   113 public:
   114   // This is called at dump-time only
   114   // This is called at dump-time only
   115   CompactHashtableWriter(int num_buckets, CompactHashtableStats* stats);
   115   CompactHashtableWriter(int num_entries, CompactHashtableStats* stats);
   116   ~CompactHashtableWriter();
   116   ~CompactHashtableWriter();
   117 
   117 
   118   void add(unsigned int hash, u4 value);
   118   void add(unsigned int hash, u4 value);
   119 
   119 
   120 private:
   120 private:
   121   void allocate_table();
   121   void allocate_table();
   122   void dump_table(NumberSeq* summary);
   122   void dump_table(NumberSeq* summary);
   123 
   123   static int calculate_num_buckets(int num_entries) {
   124 public:
       
   125   void dump(SimpleCompactHashtable *cht, const char* table_name);
       
   126 
       
   127   static int default_num_buckets(size_t num_entries) {
       
   128     return default_num_buckets((int)num_entries);
       
   129   }
       
   130   static int default_num_buckets(int num_entries) {
       
   131     int num_buckets = num_entries / SharedSymbolTableBucketSize;
   124     int num_buckets = num_entries / SharedSymbolTableBucketSize;
   132     // calculation of num_buckets can result in zero buckets, we need at least one
   125     // calculation of num_buckets can result in zero buckets, we need at least one
   133     return (num_buckets < 1) ? 1 : num_buckets;
   126     return (num_buckets < 1) ? 1 : num_buckets;
   134   }
   127   }
       
   128 
       
   129 public:
       
   130   void dump(SimpleCompactHashtable *cht, const char* table_name);
       
   131 
       
   132   static size_t estimate_size(int num_entries);
   135 };
   133 };
   136 #endif // INCLUDE_CDS
   134 #endif // INCLUDE_CDS
   137 
   135 
   138 #define REGULAR_BUCKET_TYPE       0
   136 #define REGULAR_BUCKET_TYPE       0
   139 #define VALUE_ONLY_BUCKET_TYPE    1
   137 #define VALUE_ONLY_BUCKET_TYPE    1
   212     _entry_count = 0;
   210     _entry_count = 0;
   213     _buckets = 0;
   211     _buckets = 0;
   214     _entries = 0;
   212     _entries = 0;
   215   }
   213   }
   216 
   214 
   217   void init(address base_address, u4 entry_count, u4 bucket_count, u4* buckets, u4* entries) {
   215   void init(address base_address, u4 entry_count, u4 bucket_count, u4* buckets, u4* entries);
   218     _base_address = base_address;
       
   219     _bucket_count = bucket_count;
       
   220     _entry_count = entry_count;
       
   221     _buckets = buckets;
       
   222     _entries = entries;
       
   223   }
       
   224 
   216 
   225   // Read/Write the table's header from/to the CDS archive
   217   // Read/Write the table's header from/to the CDS archive
   226   void serialize_header(SerializeClosure* soc) NOT_CDS_RETURN;
   218   void serialize_header(SerializeClosure* soc) NOT_CDS_RETURN;
   227 
   219 
   228   inline bool empty() {
   220   inline bool empty() {
   229     return (_entry_count == 0);
   221     return (_entry_count == 0);
   230   }
   222   }
       
   223 
       
   224   static size_t calculate_header_size();
   231 };
   225 };
   232 
   226 
   233 template <
   227 template <
   234   typename K,
   228   typename K,
   235   typename V,
   229   typename V,