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

Dangling pointer warning for MetadataAllocationRequest

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 21
    • 21
    • hotspot
    • b22

      When compiling with gcc13.1 for
       When compiling with gcc13.1 for release we get some -Wdangling-pointer warnings like this (earlier versions of gcc don't warn):

      In static member function 'static void MetaspaceCriticalAllocation::add(MetadataAllocationRequest*)',
          inlined from 'MetadataAllocationRequest::MetadataAllocationRequest(ClassLoaderData*, size_t, Metaspace::MetadataType)' at ../../src/hotspot/share/memory/metaspaceCriticalAllocation.cpp:53:37,
          inlined from 'static MetaWordImpl** MetaspaceCriticalAllocation::allocate(ClassLoaderData*, size_t, Metaspace::MetadataType)' at ../../src/hotspot/share/memory/metaspaceCriticalAllocation.cpp:208:65:
      ../../src/hotspot/share/memory/metaspaceCriticalAllocation.cpp:83:20: warning: storing the address of local variable 'request' in 'MetaspaceCriticalAllocation::_requests_head' [-Wdangling-pointer=]
         83 | _requests_head = _requests_tail = request;
            | ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
      ../../src/hotspot/share/memory/metaspaceCriticalAllocation.cpp: In static member function 'static MetaWordImpl** MetaspaceCriticalAllocation::allocate(ClassLoaderData*, size_t, Metaspace::MetadataType)':
      ../../src/hotspot/share/memory/metaspaceCriticalAllocation.cpp:208:29: note: 'request' declared here
        208 | MetadataAllocationRequest request(loader_data, word_size, type);
            | ^~~~~~~
      ../../src/hotspot/share/memory/metaspaceCriticalAllocation.cpp:75:28: note: 'MetaspaceCriticalAllocation::_requests_head' declared here
         75 | MetadataAllocationRequest* MetaspaceCriticalAllocation::_requests_head = nullptr;
            | ^~~~~~~~~~~~~~~~~~~~~~~~~~~

      Allocating a request (on the stack) adds the request to a global list, and the destructor removes the request from that list. The warning is a false positive, as the compiler is failing to relate those add/remove pairs.

            kbarrett Kim Barrett
            kbarrett Kim Barrett
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: