RFR: 8350097: Make Compilation::current() and Compile::current() safer
Aleksey Shipilev
shade at openjdk.org
Fri Feb 14 15:58:14 UTC 2025
On Fri, 14 Feb 2025 15:18:03 GMT, Aleksey Shipilev <shade at openjdk.org> wrote:
>> Somewhat trivial.
>>
>> I recently hunted a bug for an hour until I realized that I had accessed ciEnv::compiler_data() as C2 `Compile` when, in fact, it was C1 `Compilation`. Stupid mistake, but an assert is easy to do and saves time.
>
> src/hotspot/share/c1/c1_Compilation.hpp line 134:
>
>> 132:
>> 133: static Compilation* current() {
>> 134: DEBUG_ONLY(ciEnv::current()->check_compiler_data_c1_or_null();)
>
> So, can it be just some sort of:
>
>
> assert(CompilerThread::current()->compiler()->is_c1(), "sanity");
>
>
> ...without any other changes in `ciEnv`?
Context: I think `ciEnv` is pretty compiler-agnostic, and it would be better to avoid exposing the fact C1/C2 exist to that interface, even if only for asserts. Seems cleaner to check that we are calling `Compilation::current()` from C1 and `Compile::current()` from C2.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/23635#discussion_r1956372247
More information about the hotspot-compiler-dev
mailing list