Skip to content

Instantly share code, notes, and snippets.

@navyxliu
Created February 10, 2024 06:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save navyxliu/2421f3e206a8afc00789d003cb426b6a to your computer and use it in GitHub Desktop.
Save navyxliu/2421f3e206a8afc00789d003cb426b6a to your computer and use it in GitHub Desktop.
C2 inliner rejects a callee because of under-profiled subprocedure.
// java -XX:CompileOnly='UnderProfiledSubprocedure.foo' -XX:+PrintInlining -XX:+PrintCompilation -XX:CompileCommand=quiet -Xbatch UnderProfiledSubprocedure
import java.util.ArrayList;
class UnderProfiledSubprocedure {
private static int ODD = 100;
public void foo(boolean cond) {
var x = new ArrayList<Integer>();
if (cond) { // the branch is only taken by ODD
x.add(0); // ArrayList::add(E) is the subprocedure. it will call ArrayList::add(E, Object[], int)
// when C2 compile method(), the methoddata of ArrayList::add(E) has not been mature yet.
// refer to
}
return;
}
public static void main(String[] args) {
var kase = new UnderProfiledSubprocedure();
for (int iterations = 0; iterations <= 1_000_000; ++iterations) {
boolean cond = (iterations % ODD) == 0;
kase.foo(cond);
}
}
}
@navyxliu
Copy link
Author

here is inline tree.

368   25    b  4       UnderProfiledSubprocedure::foo (22 bytes)
                              @ 4   java.util.ArrayList::<init> (12 bytes)   inline (hot)
                                @ 1   java.util.AbstractList::<init> (10 bytes)   inline (hot)
                                  @ 1   java.util.AbstractCollection::<init> (5 bytes)   inline (hot)
                                    @ 1   java.lang.Object::<init> (1 bytes)   inline (hot)
                              @ 14   java.lang.Integer::valueOf (32 bytes)   inline (hot)
                              @ 17   java.util.ArrayList::add (25 bytes)   inline (hot)
                                @ 20   java.util.ArrayList::add (23 bytes)   failed to inline: low call site frequency

C2 refuses to inline ArrayList::add(23 bytes) because the methoddata of ArrayList::add(25 bytes) has not mature when C2 compiles 'UnderProfiledSubprocedure::foo'.

<method id='1417' holder='1331' name='add' return='1223' arguments='1228 1405 1221' flags='2' bytes='23' iicount='256'/>
<call method='1417' count='-1' prof_factor='0.210938' inline='1'/>
<inline_fail reason='low call site frequency'/>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment