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

CodeHeap::blob_count() overestimates the number of blobs

    Details

    • Subcomponent:
    • Resolved In Build:
      b11

      Backports

        Description

        While working on JDK-8238247, I realized that CodeHeap::blob_count() miscalculates the blob count. If you look at the usages of CodeHeap::_blob_count field, it is only incremented, never decremented. Which is almost fine, but it leads to blob_count miscalculation: when block is freed and put on free list and re-acquired from the free list, it is counted as new blob all over again.

        So, either way should be done:
         a) Decrement _blob_count on addition to the free list, which would make CodeHeap::blob_count() report the number of alive blobs;
         b) Stop incrementing blob_count on removal from the free list, which would make CodeHeap::blob_count() report the number of alive+free blobs.

        Sample patch for option (a):

        diff -r e4e6c1846d31 src/hotspot/share/memory/heap.cpp
        --- a/src/hotspot/share/memory/heap.cpp Fri Jan 31 19:00:14 2020 +0100
        +++ b/src/hotspot/share/memory/heap.cpp Fri Jan 31 19:00:17 2020 +0100
        @@ -609,10 +609,13 @@
         void CodeHeap::add_to_freelist(HeapBlock* a) {
           FreeBlock* b = (FreeBlock*)a;
           size_t bseg = segment_for(b);
           _freelist_length++;
         
        + _blob_count--;
        + assert(_blob_count >= 0, "sanity");
        +
           assert(b != _freelist, "cannot be removed twice");
         
           // Mark as free and update free space count
           _freelist_segments += b->length();
           b->set_free();

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  rraghavan Rahul Raghavan
                  Reporter:
                  shade Aleksey Shipilev
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  4 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved: