Are there inline functions in java?

inline-code, java

Solution

In Java, the optimizations are usually done at the JVM level. At runtime, the JVM perform some "complicated" analysis to determine which methods to inline. It can be aggressive in inlining, and the Hotspot JVM actually can inline non-final methods.

The java compilers almost never inline any method call (the JVM does all of that at runtime). They do inline compile time constants (e.g. final static primitive values). But not methods.

For more resources:

Article: The Java HotSpot Performance Engine: Method Inlining Example

Wiki: Inlining in OpenJDK, not fully populated but contains links to useful discussions.

Problem

Is there a concept of inline functions in java, or its replaced something else? If there is, how is it used? I've heard that `public`, `static` and `final` methods are the inline functions. Can we create our own inline function?

Original source

Related problems