javaperformancejit

Probability of getters and setters getting inlined by the compiler


My question is pretty straightforward:

Q: What is the chance that a getter / setter method will get inlined by the compiler in Java?
(Obviously there isn't a definite answer to this, but other information would be appreciated)

Extra: I understand there is always a chance the compiler (Standard and JIT) will decide to make a method inline, and when it comes to getters and setters this is usually what the programmer wants.


Solution

  • The compiler (javac) tend to have negligible impact on optimization, as optimization happens at run time.

    As of the JIT yes,it will probably inline either sooner or later.depending on how heavily the code is used, so a function call overhead may be seen at first, but when the getter/setter has been called sufficiently often then it is inlined.