Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8223004

Avoid using a hard-coded number in SimpleCompactHashtable::calculate_header_size()

    Details

    • Type: Enhancement
    • Status: Closed
    • Priority: P4
    • Resolution: Won't Fix
    • Affects Version/s: 13
    • Fix Version/s: tbd
    • Component/s: hotspot
    • Labels:
      None

      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");
      }

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                ccheung Calvin Cheung
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: