RFR: 8350097: Make Compilation::current() and Compile::current() safer

Vladimir Kozlov kvn at openjdk.org
Fri Feb 14 18:00:10 UTC 2025


On Fri, 14 Feb 2025 15:55:43 GMT, Aleksey Shipilev <shade at openjdk.org> wrote:

>> 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.

I agree with Aleksey here.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/23635#discussion_r1956531575


More information about the hotspot-compiler-dev mailing list