On Thu, 5 Nov 2026 15:17:04 GMT, Quan Anh Mai <[email protected]> wrote:

> ## Problem
> 
> When C2 parses a variable, it tries to be smart about the type of that 
> variable. If a method parameter declares that it is of type `A`, and `A` is 
> an abstract class that only has a single concrete subclass `B`, then C2 
> eagerly assumes that the parameter must be of type `B`. This property, in the 
> presence of concurrent class loading/unloading, does not always hold, as the 
> VM can always load another concrete subclass `C` of `A` that is unrelated to 
> `B`. To avoid incorrect execution arised from this issue, C2 relies on 
> `dependencies`, which encodes various kinds of assumptions the compiler made. 
> Among those, we have an assumption called `unique_concrete_subclass`, which 
> will be invalidated when `C` is loaded, triggering the deoptimization and 
> invalidation of the aforementioned compiled method.
> 
> However, this mechanism is both inadequate and not timely. The main issue is 
> that the concurrent load of `C` may not only happen after the compilation has 
> finished, but also during the compilation process. This leads to CHA 
> computation giving contradictory results when called at different time in the 
> compilation process. There are 2 examples which were reported:
> 
> 1.
> 
>     if (b) {
>         A a1 = ...;
>     } else {
>         C a2 = ...;
>     }
>     A a = Phi(a1, a2);
> 
> If `A a = Phi(a1, a2)` is parsed before `C a2 = ...`, and `C` has not been 
> loaded then, the compiler will assume that `a` must be of type `B`. This 
> leads to a `Phi` of type `B` with one of its inputs being a node of type `C` 
> which is unrelated. This graph shape is nonsense, and all kinds of issues can 
> appear from various optimization passes which do not expect such a 
> conflicting graph.
> 
> 2.
> 
>     A a = call();
> 
> If when `a` is parsed, `C` has not been loaded, the compiler will assume `a` 
> is of type `B`. However, if `call` is late-inlined, and it turns out that the 
> returned value is of type `C`. All uses of `a` will suddenly have their input 
> changed from a `B` to a `C`, which may also lead to unexpected failures.
> 
> ## Overview of this PR
> 
> This PR tries to detect CHA inconsistencies, and triggers a compilation 
> failure when such a paradox happens. The core invariant that needs holding is 
> that, given type `X` and `Y`, if `X` is a subtype of `Y`, then the result of 
> narrowing `X` should also be a subtype of the result of narrowing `Y`. This 
> invariant does not need to hold in the VM, it only needs to hold in the local 
> `ciEnv`, which is the local view of the compiler with respect to the class 
> hierarchy.
> 
> In some...

@merykitty please merge PR with latest mainline to resolve merge conflict.

I also don't see GHA testing for it.

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

PR Comment: https://git.openjdk.org/jdk/pull/33753#issuecomment-7053846571

Reply via email to