Java optimizations: (Hotspot/Dalvik) Optimization of final method returning a constant?

后端 未结 3 568
野趣味
野趣味 2021-01-18 14:16

Can anyone tell me if either Hotspot or Dalvik is smart enough to inline calls to a final method returning a constant (static final) int value? Ideally the method call would

3条回答
  •  没有蜡笔的小新
    2021-01-18 14:36

    Inlining is something the JIT compiler might do if it detects a hot spot, a method in the byte code that has been called that often that it probably worth spending some CPU time on compiling the byte code into machine code.

    There's a very good chance that the JIT compiler will inline a final method (as it can't be overwritten). And chances will be even better if that method just returns a constant value.

    But it's my understanding - if the calling method is not a hot spot, then it will not be compiled and there'll be no inlining of the final methods.

    (Information source in german language)

提交回复
热议问题