JDK-8370512 : C2: Wrong frequency computed for call sites with immature profile
  • Type: Bug
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 21
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • Submitted: 2025-10-23
  • Updated: 2025-10-24
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 26
26Unresolved
Related Reports
Relates :  
Description
Immature profiles report "-1" as a call site count and callers have to handle it as a special case.
If `ciCallProfile::count()` is used as is, it breaks call site frequency computation (makes the result negative) and, hence, negatively affects inlining decisions.

The code below demonstrates the issue:
 
    private static final int SIZE = 1_000_000;

    @Benchmark
    public MyList<Point> erasedIndirect() {
        var result = ListMinMap.<Point>createIndirectErased(SIZE);
        for (int i = 0; i < SIZE; i++) {
            result.set(i, erased.get(i).times(23));
        }
        return result;
    }

    static <T> MyList<T> createIndirectErased(int size) {
        return ErasedList.create(size);
    }


7494   67    b  4       org.bench.ListMinMap::erasedIndirect (48 bytes)
  @ 2   org.bench.ListMinMap::createIndirectErased (5 bytes)   inline (hot)
    @ 1   org.bench.ListMinMap$ErasedList::create (9 bytes)   failed to inline: low call site frequency
... 

Originally reported by [~mcimadamore]
Comments
ILW = Failed inlining due to wrong call site frequency computation, edge case, no workaround but force inlining = MLM = P4
24-10-2025

The following patch fixes the bug: diff --git a/src/hotspot/share/opto/bytecodeInfo.cpp b/src/hotspot/share/opto/bytecodeInfo.cpp index 5b48b33aa46..377631c87e6 100644 --- a/src/hotspot/share/opto/bytecodeInfo.cpp +++ b/src/hotspot/share/opto/bytecodeInfo.cpp @@ -309,7 +309,11 @@ bool InlineTree::should_not_inline(ciMethod* callee_method, ciMethod* caller_met } if (MinInlineFrequencyRatio > 0) { - int call_site_count = caller_method->scale_count(profile.count()); + int count = MAX2(profile.count(), 0); + if (count == 0 && !is_not_reached(callee_method, caller_method, caller_bci, profile)) { + count = 1; + } + int call_site_count = caller_method->scale_count(count); int invoke_count = caller_method->interpreter_invocation_count(); assert(invoke_count != 0, "require invocation count greater than zero"); double freq = (double)call_site_count / (double)invoke_count;
23-10-2025