JIT优化方式

1.方法内连

public interface Animal {
  void eat();
}

public class Cat implements Animal {
  @Override
  public void eat() {
    System.out.println("Cat eat !");
  }
}

public class Demo {
  public void execute(Animal animal){
    animal.eat();
  }
}
public void execute() {
  System.out.println("Cat eat !");
}

2.逃逸分析

逃逸分析指的是根据运行状况来判断方法中变量是否会被方法外部读取,如果被外部读取,则认为是逃逸的。

2.1 栈上分配

Point point = new Point(1, 2);

System.out.println("point.x = " + point.x + "; point.y" + point.y);

如果point没有逃逸,那么C2会选择在栈上直接创建point对象,而非堆上。

2.2 锁消除

Point point = new Point(1, 2);

synchronized(point) {

        System.out.println("point.x = " + point.x);

}

经过分析如果发现point未逃逸,则代码会在编译后变成如下结构

Point point = new Point(1, 2);

System.out.println("point.x = " + point.x);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值