Java default methods is slower than the same code but in an abstract class

后端 未结 1 1355
情歌与酒
情歌与酒 2021-02-05 06:12

I have an interface PackedObject:

public interface PackedObject {
    int get();
    int sum();
    void setIndex(int index);
    default int defaul         


        
1条回答
  •  囚心锁ツ
    2021-02-05 06:51

    Just regurgitating information that i've picked up by cursory reading of the hotspot-compiler-dev mailing list, but this may be the lack of class hierarchy analysis for default methods in interfaces, which prevents devirtualization of interface methods.

    See JDK Bug 8065760 and 6986483


    My guess is that even though the method is inlined it still is by preceded by a type guard that gets eliminated by CHA in the abstract case but not for the interface method.

    Printing optimized assembly (i think JMH has some flag for that) could confirm that.

    0 讨论(0)
提交回复
热议问题