JDK-8223004 : Avoid using a hard-coded number in SimpleCompactHashtable::calculate_header_size()
  • Type: Enhancement
  • Component: hotspot
  • Sub-Component: runtime
  • Affected Version: 13
  • Priority: P4
  • Status: Closed
  • Resolution: Won't Fix
  • Submitted: 2019-04-26
  • Updated: 2019-07-03
  • Resolved: 2019-04-30
Related Reports
Relates :  
Description
Below is the calculate_header_size() implementation for JDK-8207812:
size_t SimpleCompactHashtable::calculate_header_size() {
  // We have 5 fields. Each takes up sizeof(intptr_t). See WriteClosure::do_u4
  size_t bytes = sizeof(intptr_t) * 5;
  return bytes;
}

The 5 could be defined as a enum in SimpleCompactHashTable.hpp.

Ioi has the following addition suggestions:

For this one, I think we can modify the SerializeClosure class to return the number of bytes written/read, for all the do_xxx() functions. Something like

class SerializeClosure : public Closure {
  // Read/write the void pointer pointed to by p.
  virtual size_t do_ptr(void** p) = 0;
  virtual size_t do_u4(u4* p) = 0;
...
};

Then we can have:

void SimpleCompactHashtable::serialize_header(SerializeClosure* soc) {
  // NOTE: if you change this function, you MUST change the number 5 in
  // calculate_header_size() accordingly.
  size_t written_bytes = 0;
  written_bytes += soc->do_ptr((void**)&_base_address);
  written_bytes += soc->do_u4(&_entry_count);
  written_bytes += soc->do_u4(&_bucket_count);
  written_bytes += soc->do_ptr((void**)&_buckets);
  written_bytes += soc->do_ptr((void**)&_entries);
  assert(written_bytes <= calculate_header_size(), "must be");
}
Comments
We will revisit this next time this code is touched.
03-07-2019

Runtime Triage: This is not on our current list of priorities. We will consider this feature if we receive additional customer requirements.
30-04-2019