C2 misses inlining opportunity and issues a method call for an unreachable call site.
It occurs only for direct calls. It may lead to missed optimization opportunities and suboptimal performance.
Test case:
public class Test {
private static final int ARRAY_LENGTH = 100000;
public int value;
void inc() { value++; }
public static Test[] testFieldCall(int incCount) {
Test[] a = new Test[ARRAY_LENGTH];
for (int i = 0; i < ARRAY_LENGTH; i++) {
a[i] = new Test();
}
while (incCount-- > 0) {
for (int i = 0; i < ARRAY_LENGTH; i++) {
a[i].inc();
}
}
return a;
}
public static void main(String[] args) {
Test[] result = new Test[0];
while (true) {
result = testFieldCall(1000);
}
}
}
Compilation log is the following:
100 4 % Test::testFieldCall @ 8 (62 bytes)
@ 20 Test::<init> (5 bytes) inline (hot)
@ 1 java.lang.Object::<init> (1 bytes) inline (hot)
@ 48 Test::inc (11 bytes) never executed
108 5 Test::inc (11 bytes)
507 6 Test::testFieldCall (62 bytes)
@ 20 Test::<init> (5 bytes) inline (hot)
@ 1 java.lang.Object::<init> (1 bytes) inline (hot)
@ 48 Test::inc (11 bytes) call site not reached
LogCompilation says the following:
<task_queued compile_id='4' compile_kind='osr' method='Test testFieldCall (I)[LTest;' bytes='62' count='1' backedge_count='14563' iicount='1' osr_bci='8' stamp='0.100' comment='backedge_count' hot_count='14563'/>
<task_queued compile_id='5' method='Test inc ()V' bytes='11' count='5000' backedge_count='1' iicount='10000' stamp='0.108' comment='count' hot_count='10000'/>
<task_queued compile_id='6' method='Test testFieldCall (I)[LTest;' bytes='62' count='5000' backedge_count='5000' iicount='2' stamp='0.508' comment='count' hot_count='10001'/>
and for the call site at Test::testFieldCall @ 48:
<bc code='182' bci='48'/>
<method id='753' holder='749' name='inc' return='655' flags='0' bytes='11' compile_id='5' compiler='C2' iicount='15377'/>
<dependency type='unique_concrete_method' ctxk='749' x='753'/>
<call method='753' count='0' prof_factor='1' inline='1'/>
<inline_fail reason='call site not reached'/>
<direct_call bci='48'/>
However all invocations of Test::inc went throught Test::testFieldCall @ 48.
It occurs only for direct calls. It may lead to missed optimization opportunities and suboptimal performance.
Test case:
public class Test {
private static final int ARRAY_LENGTH = 100000;
public int value;
void inc() { value++; }
public static Test[] testFieldCall(int incCount) {
Test[] a = new Test[ARRAY_LENGTH];
for (int i = 0; i < ARRAY_LENGTH; i++) {
a[i] = new Test();
}
while (incCount-- > 0) {
for (int i = 0; i < ARRAY_LENGTH; i++) {
a[i].inc();
}
}
return a;
}
public static void main(String[] args) {
Test[] result = new Test[0];
while (true) {
result = testFieldCall(1000);
}
}
}
Compilation log is the following:
100 4 % Test::testFieldCall @ 8 (62 bytes)
@ 20 Test::<init> (5 bytes) inline (hot)
@ 1 java.lang.Object::<init> (1 bytes) inline (hot)
@ 48 Test::inc (11 bytes) never executed
108 5 Test::inc (11 bytes)
507 6 Test::testFieldCall (62 bytes)
@ 20 Test::<init> (5 bytes) inline (hot)
@ 1 java.lang.Object::<init> (1 bytes) inline (hot)
@ 48 Test::inc (11 bytes) call site not reached
LogCompilation says the following:
<task_queued compile_id='4' compile_kind='osr' method='Test testFieldCall (I)[LTest;' bytes='62' count='1' backedge_count='14563' iicount='1' osr_bci='8' stamp='0.100' comment='backedge_count' hot_count='14563'/>
<task_queued compile_id='5' method='Test inc ()V' bytes='11' count='5000' backedge_count='1' iicount='10000' stamp='0.108' comment='count' hot_count='10000'/>
<task_queued compile_id='6' method='Test testFieldCall (I)[LTest;' bytes='62' count='5000' backedge_count='5000' iicount='2' stamp='0.508' comment='count' hot_count='10001'/>
and for the call site at Test::testFieldCall @ 48:
<bc code='182' bci='48'/>
<method id='753' holder='749' name='inc' return='655' flags='0' bytes='11' compile_id='5' compiler='C2' iicount='15377'/>
<dependency type='unique_concrete_method' ctxk='749' x='753'/>
<call method='753' count='0' prof_factor='1' inline='1'/>
<inline_fail reason='call site not reached'/>
<direct_call bci='48'/>
However all invocations of Test::inc went throught Test::testFieldCall @ 48.