RFR: 8373495: C2: Aggressively fold loads from objects that have not escaped [v5]

Vladimir Ivanov vlivanov at openjdk.org
Fri Dec 12 03:06:59 UTC 2025


On Fri, 12 Dec 2025 02:30:22 GMT, Quan Anh Mai <qamai at openjdk.org> wrote:

>> Hi,
>> 
>> The current escape analysis mechanism is all-or-nothing: either the object does not escape, or it does. If the object escapes, we lose the ability to analyse the values of its fields completely, even if the object only escapes at return.
>> 
>> This PR tries to find the escape status of an object at a load, and if it is decided that the object has not escaped there, we can try folding the load aggressively, ignoring calls and memory barriers to find a corresponding store that the load observes.
>> 
>> For the runtime cost, this phase runs very fast, around 5 - 7% the runtime of EA, and about 0.5% the total runtime of C2.
>> 
>> Please take a look and leave your thoughts, thanks a lot.
>
> Quan Anh Mai has updated the pull request incrementally with one additional commit since the last revision:
> 
>   more detailed explanations

Yes, I got it, but my understanding of the core idea of the optimization is that you can skip over membars when base object is not escaped yet. So, if `MemNode::can_see_stored_value()` encounters a node with a wide memory effect (a membar or a call) while traversing the memory graph upwards, it can step over it if it can prove that the freshly allocated instance hasn't escaped yet. And the traversal of memory graph from there up to corresponding Initialize node should reveal whether the instance escaped or not.  Do I get it right?

-------------

PR Comment: https://git.openjdk.org/jdk/pull/28764#issuecomment-3644703975


More information about the hotspot-compiler-dev mailing list