JDK-8337015 : Revisit resource arena allocations in C2
  • Type: Enhancement
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 21,24
  • Priority: P2
  • Status: Open
  • Resolution: Unresolved
  • Submitted: 2024-07-23
  • Updated: 2025-06-04
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.
Other
tbdUnresolved
Related Reports
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Description
Recent changes like JDK-8325672, JDK-8302670, JDK-8336999 and JDK-8336095 increased the amount of allocations in the 'comp_arena' which might have a negative impact on footprint because memory is only released once the compilation finished. We should revisit this. See discussion here:
https://github.com/openjdk/jdk/pull/20297#pullrequestreview-2193709471

"We should probably create a dedicated arena for each Phase, so that the memory can be released after each phase, and re-used properly with the next phase. That could reduce memory footprint."
Comments
We also did a few changes like JDK-8328085 where we had to remove ResourceMarks. This leads to memory being freed only later and could therefore increase peak memory consumption.
20-11-2024

Right, allocating everything in '_comp_arena' will ensure safety but increase footprint significantly because memory is only released after the compilation, and we allocate *a lot* of temporary data structures with limited lifetime during compilations. On the other hand, allocating in the resource area (and in the scope of ResourceMarks) will make sure that memory is released early but has a high risk of use-after-free bugs like JDK-8336095 and will affect all resource arena allocations in the scope (i.e., no fine grained control over what is released and what not).
25-07-2024

"We should probably create a dedicated arena for each Phase". Be very careful about that - it may introduce issues similar to JDK-8336095. I would suggest to use thread local ResourceArea so we can add corresponding check as Tobias did in vector.cpp in JDK-8336999 changes. The good thing about _comp_arena is that we don't release its memory until the end of compilation so it avoids such issue.
24-07-2024