RFR: 8267532: C2: Profile and prune untaken exception handlers [v5]

Vladimir Ivanov vlivanov at openjdk.org
Wed Nov 15 03:40:30 UTC 2023


On Tue, 14 Nov 2023 17:00:56 GMT, Jorn Vernee <jvernee at openjdk.org> wrote:

> My sense when working on this was that C2 relies on dead branches being pruned to eliminate unreached calls (and other code) within those branches. That potentially allows multiple unreached calls to be eliminated using a single uncommon trap for the whole branch.

Irrespective of where it is placed (beginning of a block, invoke bytecode, or any other bytecode instruction), an uncommon trap effectively prunes everything it dominates. So, the earlier it is placed, the better. 

In that respect, having an uncommon trap placed right at the entry of the block is preferred. But pruning unreached calls would achieve the same result (and without any additional profiling logic) when it comes to try-with-resource construct.

I'd like to point out that proposed solution doesn't completely eliminate the problem reported in the bug. (And it also suffers from profile pollution - a single exception thrown defeats the whole optimization.) The original problem boils down to EA failure in presence of escape points in cold regions. A proper fix would be to teach EA to move such allocations closer to escape point, but it would require much more complex code changes. There's already work happening to improve C2 EA in that respect.

Still, IMO enhancing profiling machinery to track unreached exception handlers is a good thing.

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

PR Comment: https://git.openjdk.org/jdk/pull/16416#issuecomment-1811758433


More information about the hotspot-dev mailing list