-
Enhancement
-
Resolution: Fixed
-
P3
-
9, 10, 11, 12, 13
-
b09
See http://www.scala-lang.org/blog/2016/07/08/trait-method-performance.html#back-to-default-methods for the motivating example. This bug follows up why non-CHA inlining produces suboptimal loop.
While the same can be demonstrated with default methods that do not enjoy CHA inlining due toJDK-8036580, we can also show the same on virtual methods with -XX:-UseCHA. While we can argue that CHA *should* be faster because it uses static information for inlining, it is very weird to see the impact on loop optimizer.
Running this test:
interface I {
int getV();
}
abstract class A implements I {
public int accessVirtual() { return getV(); }
}
class C extends A {
public int v = 0;
public int getV() { return v; }
}
final int NB = 1000;
public C c;
@Setup
public void setup() {
c = new C();
}
@Benchmark
@CompilerControl(CompilerControl.Mode.DONT_INLINE)
public int test() {
int value = 0;
for (int i = 0; i < NB; i++) {
c.v = i;
value += c.accessVirtual();
}
return value;
}
(full test: http://cr.openjdk.java.net/~shade/8161334/CHAnoCHA.java, http://cr.openjdk.java.net/~shade/8161334/benchmarks.jar)
...will yield different performance with -XX:+UseCHA and -XX:-UseCHA. The performance difference seems to be explained with the suboptimal loop generation in non-CHA case, and at least here reaches 20%.
Disassemblies:
http://cr.openjdk.java.net/~shade/8161334/cha.perfasm
http://cr.openjdk.java.net/~shade/8161334/no-cha.perfasm
It seems to start with a subtly different IRs generated for CHA and non-CHA inlining:
http://cr.openjdk.java.net/~shade/8161334/cha-after-parsing.png
http://cr.openjdk.java.net/~shade/8161334/no-cha-after-parsing.png
While the same can be demonstrated with default methods that do not enjoy CHA inlining due to
Running this test:
interface I {
int getV();
}
abstract class A implements I {
public int accessVirtual() { return getV(); }
}
class C extends A {
public int v = 0;
public int getV() { return v; }
}
final int NB = 1000;
public C c;
@Setup
public void setup() {
c = new C();
}
@Benchmark
@CompilerControl(CompilerControl.Mode.DONT_INLINE)
public int test() {
int value = 0;
for (int i = 0; i < NB; i++) {
c.v = i;
value += c.accessVirtual();
}
return value;
}
(full test: http://cr.openjdk.java.net/~shade/8161334/CHAnoCHA.java, http://cr.openjdk.java.net/~shade/8161334/benchmarks.jar)
...will yield different performance with -XX:+UseCHA and -XX:-UseCHA. The performance difference seems to be explained with the suboptimal loop generation in non-CHA case, and at least here reaches 20%.
Disassemblies:
http://cr.openjdk.java.net/~shade/8161334/cha.perfasm
http://cr.openjdk.java.net/~shade/8161334/no-cha.perfasm
It seems to start with a subtly different IRs generated for CHA and non-CHA inlining:
http://cr.openjdk.java.net/~shade/8161334/cha-after-parsing.png
http://cr.openjdk.java.net/~shade/8161334/no-cha-after-parsing.png
- relates to
-
JDK-8219902 C2: MemNode::can_see_stored_value() ignores casts which carry control dependency
-
- Closed
-