JDK-8307196 : Dangling pointer warning for MetadataAllocationRequest
  • Type: Bug
  • Component: hotspot
  • Sub-Component: runtime
  • Affected Version: 21
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2023-05-01
  • Updated: 2023-05-11
  • Resolved: 2023-05-05
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 21
21 b22Fixed
Related Reports
Relates :  
Relates :  
Description
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.

Comments
Changeset: e19cf26d Author: Kim Barrett <kbarrett@openjdk.org> Date: 2023-05-05 06:20:32 +0000 URL: https://git.openjdk.org/jdk/commit/e19cf26d656bc2de947aa42c418bdbbf549f8865
05-05-2023

A pull request was submitted for review. URL: https://git.openjdk.org/jdk/pull/13789 Date: 2023-05-04 05:14:28 +0000
04-05-2023