Is it faster to access final local variables than class variables in Java?

前端 未结 5 1787
闹比i
闹比i 2020-12-06 01:07

I\'ve been looking at at some of the java primitive collections (trove, fastutil, hppc) and I\'ve noticed a pattern that class variables are sometimes declared as fina

5条回答
  •  甜味超标
    2020-12-06 01:44

    In the generated VM opcodes local variables are entries on the operand stack while field references must be moved to the stack via an instruction that retrieves the value through the object reference. I imagine the JIT can make the stack references register references more easily.

提交回复
热议问题