On Fri, 8 May 2026 17:19:59 GMT, Vladimir Kozlov <[email protected]> wrote:

>> src/hotspot/share/ci/ciEnv.cpp line 1124:
>> 
>>> 1122:     // No safepoints are allowed. Otherwise, class redefinition can 
>>> occur in between.
>>> 1123:     MutexLocker ml(Compile_lock);
>>> 1124:     NoSafepointVerifier nsv;
>> 
>> OK, so here is an interesting lifecycle oddity. We are here arming `NSV` for 
>> class redefinition reasons. Looks fine until we go to 
>> `ciEnv::make_code_usable`, which builds `MCS` for preloaded methods. But 
>> `MCS` allocation is _Metaspace_ allocation, so it can trigger GC allocation 
>> failure and GC safepoint. So this `NSV` may fail.
>
> In CompileBroker we generate MC unconditionally before creating compilation 
> task:
> 
>   // Tiered policy requires MethodCounters to exist before adding a method to
>   // the queue. Create if we don't have them yet.
>   method->get_method_counters(thread);
> 
> 
> Also in `ciEnv::is_compilation_valid()` we have:
> 
>   // We require method counters to store some method state (max compilation 
> levels) required by the compilation policy.
>   if (method->get_method_counters(thread) == nullptr) {
>     record_failure("can't create method counters");
>     return false;
>   }
> 
> 
> May be we should do the same check in CompileBroker.

I added check to CompileBroker code.  And I moved `get_method_counters` from 
`ciEnv::is_compilation_valid()` to callers before  `NoSafepointVerifier nsv;`.

>> src/hotspot/share/code/aotCodeCache.cpp line 737:
>> 
>>> 735: 
>>> 736:   size_t codeCacheSize = pointer_delta(CodeCache::high_bound(), 
>>> CodeCache::low_bound(), 1);
>>> 737:   if (codeCacheSize > _codeCacheSize) { // Only allow smaller or equal 
>>> CodeCache size in production run
>> 
>> It is not very clear to me why do we have this limit. What breaks if we have 
>> a larger code cache in production run? Some branches become not easily 
>> reachable, or something else? Let's polish the error message too: we need to 
>> say "larger" or "smaller" explicitly, so users can figure out what to adjust.
>
> We will not be able to patch some branch/call instructions in AOT code if 
> CodeCache become bigger in production. 
> Remember that we have short branches and far branches. So distance to stubs, 
> for example, could change with bigger CodeCache and it would not fit into 
> short branch encoding.

New message: `it was created with smaller CodeCache size = %dKb vs current %dKb`

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

PR Review Comment: https://git.openjdk.org/jdk/pull/30778#discussion_r3210323187
PR Review Comment: https://git.openjdk.org/jdk/pull/30778#discussion_r3210170451

Reply via email to