> ## 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...
Quan Anh Mai has updated the pull request with a new target base due to a merge
or a rebase. The pull request now contains six commits:
- Merge branch 'master' into chaconsistency
- Fix Coninuation/Fuzz, revert PhaseCCP temporary fix
- Fix keep_alive mechanism, remove old Phi input workaround, fix test
failures, change paradoxical_hierarchy not to fail ciEnv
- has_subklass may be called from VM
- Fix keep_alive
- Ensure the hierarchy view is consistent
-------------
Changes: https://git.openjdk.org/jdk/pull/33753/files
Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=33753&range=01
Stats: 1006 lines in 20 files changed: 459 ins; 260 del; 287 mod
Patch: https://git.openjdk.org/jdk/pull/33753.diff
Fetch: git fetch https://git.openjdk.org/jdk.git pull/33753/head:pull/33753
PR: https://git.openjdk.org/jdk/pull/33753