本书一共分为五个部分:走近Java、自动内存管理、虚拟机执行子系统、程序编译与代码优化、高效并发。各个部分之间基本上是互相独立的,没有必然的前后依赖关系,读者可以从任何一个感兴趣的专题开始阅读,但是每个部分各个章节间则有先后顺序。
AI Reading Assistant
Whole-book reading guide from stratified index samples; jump to passages in the text
AI guide
# 深入理解Java虚拟机:JVM高级特性与最佳实践(第3版)
## 【One-Line Pitch】
The definitive Chinese-language guide to JVM internals—covering memory management, garbage collection, class loading, compilation, and concurrency—for senior Java developers, architects, and performance tuners who need to understand what happens beneath their code.
## 【Book Arc】
- **Opening (~0%–9%)**: Introduces the Java technology ecosystem, its history, and the JVM family tree (HotSpot, JRockit, J9, Dalvik, etc.), plus a practical walkthrough of compiling your own JDK. Sets the stage for why JVM knowledge matters for production-grade applications.
- **Early (~9%–25%)**: Dives into automatic memory management—runtime data areas (heap, stack, method area, etc.), object creation and layout, OutOfMemoryError troubleshooting, garbage collection algorithms (mark-sweep, mark-copy, mark-compact), and the classic collectors from Serial to G1, plus low-latency newcomers Shenandoah and ZGC.
- **Early (~25%–34%)**: Explores the virtual machine execution subsystem—Class file structure (updated to JDK 12), the five-phase class loading process (load, verify, prepare, resolve, initialize), classloader mechanics, and the Java module system (Jigsaw) introduced in JDK 9.
- **Middle (~34%–47%)**: Covers program compilation and code optimization—syntax sugar (generics, autoboxing, conditional compilation), the Javac compiler front-end, annotation processors, JIT compilation (HotSpot's C1/C2 compilers), AOT compilation with Jaotc, and optimization techniques like method inlining, escape analysis, and the Graal compiler.
- **Late (~47%–end)**: Tackles high-efficiency concurrency—the Java Memory Model (main memory vs. working memory, volatile semantics, happens-before rules), thread implementation and scheduling, the emerging coroutine support, thread safety classifications, and lock optimization techniques (spin locks, lock elimination, lock coarsening, lightweight locks, biased locks).
## 【Key Takeaways】
- **JVM knowledge is a differentiator for production systems** (Opening): Code that works for 10 users often fails for 10,000—understanding VM internals helps you write code that the JVM can optimize effectively. This is the book's core motivation.
- **Memory management is the first frontier** (Early): The runtime data areas (program counter, VM stack, native method stack, heap, method area, constant pool, direct memory) form the foundation. Knowing where objects live and how they're accessed is prerequisite to diagnosing OutOfMemoryError.
- **GC is a spectrum of trade-offs** (Early): From Serial's simplicity to G1's region-based collection to ZGC/Shenandoah's sub-millisecond pause targets, each collector balances throughput, latency, and footprint. The book explains the algorithms (mark-sweep, mark-copy, mark-compact) and the HotSpot implementation details (safe points, card tables, write barriers).
- **Class files are the contract between language and VM** (Early): The Class file structure (updated through JDK 12) is tedious but unavoidable—it's the foundation for understanding class loading, bytecode execution, and dynamic language support. New attributes for modules (JDK 9) and nest-based access control (JDK 11) reflect evolving language features.
- **Compilation is a two-stage pipeline** (Middle): Java source → bytecode (front-end, Javac) → native code (back-end, JIT/AOT). Understanding syntax sugar like generics (implemented via type erasure) and autoboxing reveals why certain code patterns perform better than they appear.
- **JIT optimization is where performance lives** (Middle): HotSpot's hotspot detection, tiered compilation, and techniques like method inlining and escape analysis can dramatically improve runtime performance. The Graal compiler and JVMCI interface represent the future of JVM compilation.
- **The Java Memory Model defines concurrency semantics** (Late): The happens-before relationship, volatile guarantees, and atomicity/visibility/ordering rules are the backbone of correct concurrent programming. Understanding these prevents subtle race conditions that are nearly impossible to debug empirically.
- **Lock optimization is a VM-level art** (Late): Modern JVMs employ biased locks, lightweight locks, spin locks, and lock coarsening to reduce synchronization overhead—meaning the cost of `synchronized` is far lower than most developers assume.
## 【Reading Tips】
- **Part independence is real**: The five parts (Java overview, memory management, execution subsystem, compilation, concurrency) are designed to be read in any order. If you're a working developer, start with Part 2 (memory) or Part 5 (concurrency)—they have the most immediate practical payoff.
- **Chapter 3 (GC) deserves deep reading**: It's the longest and most technical chapter, covering everything from basic algorithms to cutting-edge collectors. Skim the historical collectors (Serial, ParNew) if you're on modern JDKs, but read G1, ZGC, and Shenandoah carefully—they're what you'll actually encounter.
- **Chapter 6 (Class files) is reference material**: The author admits this chapter reads like a technical manual. Don't read it cover-to-cover; use it as a reference when you need to understand a specific attribute or constant pool entry.
- **Follow the practical exercises**: The book includes hands-on projects—compiling your own JDK, triggering OutOfMemoryError scenarios, building an annotation processor, and analyzing JIT compilation output. These cement the theory and are worth the time investment.
- **Watch for version-specific notes**: The 3rd edition is written from a mid-2019 perspective (JDK 13 era). The author explicitly flags version differences, so pay attention to these callouts—they explain why some features exist only in certain JDK releases.
## 【Coverage Limits】
This guide covers the book's structure, key themes, and practical reading strategies based on the table of contents, preface, and introductory material. Detailed technical content from the middle chapters (GC algorithms, class loading internals, JIT optimization specifics) is summarized at a high level—the excerpts do not include the full depth of those chapters.
##
Excerpt 1
irst 收集器 3.6低延迟垃圾收集器 3.6.1 Shenandoah 收集器 3.6.2 ZGC收集器 3.7选择合适的垃圾收集器 3.7.1 Epsilon 收集器 3.7.2收集器的权衡 3.7.3虚拟机及垃圾收集器日志 3.7.4垃圾收集器参数总结 3.8实战:内存分配与回收策略 3.8.1...
View in text
Excerpt 2
线程安全所涉及的概念和分类、同步实现的方式及虚拟机的底层运作原理,并且 介绍了虚拟机实现高效并发所做的一系列锁优化措施。 ❶第3版更新:本章主体内容并没有过多变化,但对不少细节进行了修饰,对一些读者疑问较多 的地方进行了补充讲解。 参考资料 本书名为“深入理解Java虚拟机”,但要想真的深入理解虚拟机,仅凭一本书...
View in text
Excerpt 3
1997年被Sun公司收购。Hot-Spot虚拟机刚发布时是作为 JDK 1.2的附加程序提供的,后来它成为JDK 1.3及之后所有JDK版本的默认Java虚拟机。 2000年5月8日,工程代号为Kestrel (美洲红隼)的JDK 1.3发布。相对于JDK 1.2,JDK 1.3的改进 主要体现在Java类库上...
View in text
Excerpt 4
//www. infoq. cn/article/2018/02/from-j avaee-to-j akartaee。 [15] Java One大会从2019年起停办,合并入Oracle CodeOne大会中。 [16] 需要使用 +XX: +UnlockCommercialFeatures解锁的特...
View in text
Excerpt 5
开始从硬件转向软件,发布了 自己的Zing虚拟机,可以在通用x86平台上提供接近于\fega系统的性能和一致的功能特性。 随着虚拟机技术的不断发展,Java虚拟机变得越来越强大的同时也越来越复杂,要推动在专有硬 件上的Java虚拟机升级发展,难以直接借助开源社区的力量,往往需要耗费更高昂的成本,在商业上 的缺陷使...
View in text
Excerpt 6
efined)。此内存区域是唯 --个在《Java虚拟机规范》中没有规定任何OutOfMemoryError情况的区域。 2.2.2 Java虚拟机栈 与程序计数器一样,Java虚拟机栈(Java Virtual Machine Stack)也是线程私有的,它的生命周期 与线程相同。虚拟机栈描述的是Java方...
View in text
Excerpt 7
的设置方式。关于对象头的具体内 容,稍后会详细介绍。 在上面工作都完成之后,从虚拟机的视角来看,一个新的对象已经产生了。但是从Java程序的视 角看来,对象创建才刚刚开始——构造函数,艮PClass文件中的<irnt>()方法还没有执行,所有的字段都 为默认的零值,对象需要的其他资源和状态信息也还没有按照预定的意...
View in text
Excerpt 8
及它到GC Roots引用链的信息,一般可以比较准确地定位到这些对象创建的位置,进而找出产生内 存泄漏的代码的具体位置。 图2-5使用Eclipse Memory Analyzer打开的堆转储快照文件 如果不是内存泄漏,换句话说就是内存中的对象确实都是必须存活的,那就应当检查Java虚拟机 的堆参数(-Xmx与-...
View in text
Tags
AI categories
Programming LanguageBackendTechnology
Loading comments...
Reply to Comment
Edit Comment