JDK1.8 HotSpot虚拟机逃逸分析

本文介绍了JDK1.8 HotSpot虚拟机的逃逸分析,这是一种优化代码的技术,用于决定对象是否在堆上分配。逃逸分析默认在6u23及以后版本开启。如果对象未逃逸,可能会进行标量替换,消除对象分配和锁。通过实验测试展示了不同设置下对象分配和GC的情况,强调了HotSpot的栈上分配实际是通过标量替换实现,所有对象仍分配在堆上。
摘要由CSDN通过智能技术生成

逃逸分析是JIT编译器的用来优化代码的一种手段,下面粘贴一下官方的Hot Spot说明。

链接打不开的话可能要扶个梯子往上爬
https://docs.oracle.com/javase/8/docs/technotes/guides/vm/performance-enhancements-7.html

Escape analysis is a technique by which the Java Hotspot Server Compiler can analyze the scope of a new object’s uses and decide whether to allocate it on the Java heap.

Escape analysis is supported and enabled by default in Java SE 6u23 and later.

The Java Hotspot Server Compiler implements the flow-insensitive escape analysis algorithm described in:

[Choi99] Jong-Deok Choi, Manish Gupta, Mauricio Seffano,
Vugranam C. Sreedhar, Sam Midkiff,
“Escape Analysis for Java”, Procedings of ACM SIGPLAN
OOPSLA Conference, November 1, 1999
Based on escape analysis, an object’s escape state might be one of the following:

  • GlobalEscape – An object escapes the method and thread. For example, an object stored in a static field, or, stored in a field of an escaped object, or, returned as the result of the current method.

  • ArgEscape – An object passed as an argument or referenced by an argument but does not globally escape during a call. This state is determined by analyzing the bytecode of called method.

  • NoEscape – A scalar replaceable object, meaning its allocation could be removed from generated code.

After escape analysis, the server compiler eliminates scalar replaceable object allocations and associated locks from generated code. The server compiler also eliminates locks for all non-globally escaping objects. It does not replace a heap allocation with a stack allocation for non-globally escaping objects.

Some scenarios for escape analysis are described next.

The server compiler might eliminate certain object allocations. Consider the example where a method makes a defensive copy of an object and returns the copy to the caller.

public class Person {
private String name;
private int age;
public Person(String personName, int personAge) {

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值