Skip to Content
Java性能优化实践:JVM调优策略、工具与技巧
book

Java性能优化实践:JVM调优策略、工具与技巧

by Benjamin J. Evans, James Gough, Chris Newland
January 2021
Intermediate to advanced
342 pages
9h 1m
Chinese
Posts & Telecom Press
Content preview from Java性能优化实践:JVM调优策略、工具与技巧
182
10
可能要向调用者返回一个结果。
内联是
JIT
编译器所应用的最重要的优化之一,也叫
网关优化
gateway optimization
),
为它通过消除方法的边界,缩短了相关代码的距离。
考虑如下代码:
int
result = add(a, b);
private
int
add(
int
x,
int
y) {
return
x + y;
}
内联优化会将
add()
的方法体复制到它的调用点中,实际上得到:
int
result = a + b;
HotSpot
的内联编译器优化支持开发人员编写组织清晰、可复用的代码。它代表的理念是,
开发人员不需要手动进行细微的优化。相反,
HotSpot
使用自动化的统计分析来确定相关
代码何时应该放在一起。内联也进而拓宽了其他优化的范围,包括:
逃逸分析(
escape analysis
死代码消除(
dead code elimination
DCE
循环展开(
loop unrolling
锁消除(
lock elision
10.3.1
 内联的限制
有时虚拟机需要对内联子系统施加一些限制。比如,虚拟机可能需要控制:
JIT
编译器优化一个方法所花的时间;
生成的原生代码的大小(这会进而影响代码缓存所占用的内存多少)。
如果没有这些约束,编译器可能就会陷入很深的内联调用链中不能自拔,或是会因巨大
的原生方法而填满代码缓存。
JIT
编译资源非常宝贵,这个一般性原则在这里再次发挥
作用。
HotSpot
在决定是否内联某个方法时会考虑几个因素,包括: ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Java持续交付

Java持续交付

Daniel Bryant, Abraham Marín-Pérez
软件开发实践:项目驱动式的Java开发指南

软件开发实践:项目驱动式的Java开发指南

Raoul-Gabriel Urma, Richard Warburton

Publisher Resources

ISBN: 9787115552334