[lworld] Integrated: 8282616: [lworld] C2 does not properly handle circular .ref or value class fields

Tobias Hartmann thartmann at openjdk.org
Mon Feb 13 11:22:54 UTC 2023


On Mon, 13 Feb 2023 09:58:08 GMT, Tobias Hartmann <thartmann at openjdk.org> wrote:

> The current C2 implementation recurses infinitely when scalarizing circular .ref or value class fields, leading to a segmentation fault (stack overflow) during compilation. I added code to detect such circularity and limit the scalarization depth accordingly. Unfortunately, we can now observe nodes of the same type but with different scalarization depth during GVN and IGVN. Here's an example:
> 
> 
> value class V1 {
>     V2 v2 = V2.default;
> }
> 
> value class V2 {
>     V1 v1 = V1.default;
> }
> 
> V1 a = new V1(); // Scalarized as InlineTypeNodeV1(InlineTypeNodeV2(oop))
> V2 b = new V2(); // Scalarized as InlineTypeNodeV2(InlineTypeNodeV1(oop))
> V1 c = __ withfield(a, v2, b); // Scalarized as InlineTypeNodeV1(InlineTypeNodeV2(InlineTypeNodeV1(oop)))
> 
> 
> Nodes for `a` and `c` are of the same type but scalarized with different depth. That's a problem for `InlineTypeNode::merge_with` which relies on Phi nodes to merge field values at the exact same depth. I added code to adjust the scalarization depth during parsing/GVN and limited the creation of Phi nodes during IGVN. All of that is dependent on the detection of circularity. I filed [JDK-8302308](https://bugs.openjdk.org/browse/JDK-8302308) to address some limitations of the current implementation in a low-priority, follow-up enhancement.
> 
> Thanks,
> Tobias

This pull request has now been integrated.

Changeset: 46bfac49
Author:    Tobias Hartmann <thartmann at openjdk.org>
URL:       https://git.openjdk.org/valhalla/commit/46bfac49bcd5eeb898519b253939b5d8f97e9d83
Stats:     364 lines in 14 files changed: 288 ins; 15 del; 61 mod

8282616: [lworld] C2 does not properly handle circular .ref or value class fields

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

PR: https://git.openjdk.org/valhalla/pull/824



More information about the valhalla-dev mailing list