When can Hotspot allocate objects on the stack? [duplicate]
问题 This question already has answers here : Eligibility for escape analysis / stack allocation with Java 7 (3 answers) Closed 2 years ago . Since somewhere around Java 6, the Hotspot JVM can do escape analysis and allocate non-escaping objects on the stack instead of on the garbage collected heap. This results in a speedup of the generated code and reduces pressure on the garbage collector. What are the rules for when Hotspot is able to stack allocate objects? In other words when can I rely on