[Book Reviews] Mastering the Java Virtual Machine

Thanaphoom Babparn
6 min readApr 24, 2024

--

Hello everyone! Thank you for interesting in my article about review book again. Recently I read the book “Mastering the Java Virtual Machine”. I picked because I’m working as Java developer and I want to expand my knowledge. On the late of February, I saw the LinkedIn post about this book and it’s containing something about garbage collection and memory management. So I decided to buy it and it’s worth to read for sure.

Let’s start my opinion about this book. 🙇‍♂️

Mastering the Java Virtual Machine

Mastering the Java Virtual Machine: An in-depth guide to JVM internals and performance optimization is a guide that help you exploring the world of Java programming languages or Java Virtual Machine I would say. Starting from understanding the fundamental of the JVM. Architectural and how it execute on the background. By the end of the book, You can feel that you have improved your skills related to JVM.

The book divided to big 4 parts

  1. Understanding the JVM: Learning on fundamental and how bytecode got executed.
  2. Memory Management and Execution: Understanding on how to manage memory and garbage collection.
  3. Alternative JVMs: Learning more about JVM ecosystem like GraalVM or the Java distro from many vendors.
  4. Advanced Java Topics: The topic relate to something behind Java framework.

Detail in brief

I will put some few informations here but in case you are interested in the rest detail, Please kindly buy your own. Apologize for the inconvenience. 🙇‍♂️

Understanding the JVM

JVM is an abstract computing machine that exists for executing bytecode. The JVM is the magic behind Java’s “Write Once, Run Anywhere” philosophy. It’s a software engine that provides a platform-independent way to execute Java bytecode. While born for executing Java, the JVM now supports various languages like Scala, Kotlin, and Groovy.

Understanding Java Bytecode a bit

Java bytecode is the core of Java’s “Write Once, Run Anywhere” (WORA) capability. It’s an intermediate form of your Java code that the Java Virtual Machine (JVM) understands and executes. When you compile Java code, the compiler (javac) doesn’t produce machine-specific code. Instead, it generates platform-independent bytecode.

Java bytecode is like a set of instructions for the JVM. These instructions control how Java programs work on any system with a compatible JVM. This intermediate layer is the reason a single Java program can run seamlessly on various devices and operating systems.

For example

int x = 5;
int y = 3;
int result = x * y;

On the background, this is how it execute

0: iconst_5  // Push 5 onto the stack 
1: istore_1 // Store the value into local variable x (1st variable)
2: iconst_3 // Push 3 onto the stack
3: istore_2 // Store the value into local variable y (2st variable)
4: iload_1 // Load the value from local variable x (1st variable)
5: iload_2 // Load the value from local variable y (2st variable)
6: imul // Multiply the top two values
7: istore_3 // Store the result into local variable result (3rd variable)

Memory Management and Execution

Before we talk about the execution and memory management. Let’s understand the concept of system operation layers a bit

  • Hardware layer — The lowest level which consist of the physical component of computer system e.g. processors, memory, storage device and input/output (I/O)
  • ISA layer — Defining the interface between software and the hardware which processor can understands. This layer feel like a bridge that allowing software to communicate to hardware resources.
  • Operating system layer — OS is the intermediate between application software and hardware. It manages resources, provide runtime environment for applications and communicate between software and hardware components.
  • Application layer — Programs or tools designed to fulfill user needs.

Why these layers relate to JVM?

  • Interaction with ISA and hardware — JVM indirect interacts ISA layer and hardware through operating system. It relies on ISA layer’s instruction set to execute bytecode
  • Collaboration with the OS — JVM is utilizing for memory management, file operations and etc.
  • Application executions — JVM application is running on this layer. It interpreted and execute Java bytecode and ensure Java program can run across platform.
Source: How many types of memory areas are allocated by JVM?

Memory management in the JVM

  • Method Area: Shared storage for class structures (code, metadata, constant pools).
  • Heap: Where objects live. Also garbage collected.
  • Stack: Per-thread area storing method frames (local variables, partial results).
  • PC Registers: Each thread has a Program Counter (PC) tracking the next instruction.
  • Native Method Stacks:For non-Java code executed by the JVM.

What is garbage collection?

Garbage collection automatically reclaims memory occupied by objects that your Java program no longer needs. This prevents memory leaks and keeps your application running smoothly.

Side joke — Sometime memory leaks make you really annoying even you have garbage collection. 🤪

This is the summarize table from the book to help design the GC options

Alternative JVMs

GraalVM — A high-performance JVM from Oracle supporting Java, but also languages like Python, Ruby, and even native languages like C++. It offers ahead-of-time (AOT) compilation to improve startup time and efficiency.

Please kindly read on further information here

Alternative Java options

  • Amazon Corretto — Amazon’s commitment on open source JVM, LTS and backed by the AWS usage.
  • Azul Zulu — Has C4 GC (Continuously Concurrent Compacting Collector) and has enhanced runtime performance.
  • IBM Semeru — Designed for container-friendly architecture and optimized for cloud deployment.
  • Eclipse TemurinTimely updates and security patches, platform independence and open community collaboration.
  • Microsoft Build of OpenJDK —No-cost distribution of OpenJDK from Microsoft.

If you are using SDKMAN, You can run this command to list the other vendors

sdk list java

Or if you haven’t heard it before, Please check here

My review opinion

Rating: 4.7/5

Regarding to this rating, Don’t get me wrong. This book contains the meaningful informations for someone who work as a Java developer (like me). You have visioned start from head-to-toe actually. Apart from that, on each section you will have questions to make you recall what you have learnt on the section.

The part I like would be the memory management. As a Java developer, memory management, heap, and performance tuning is the problem you need to dealing with a lot of times. Also, the GraalVM and the benefits of each Java vendors are really helpful.

However, On the part relate to JVM arguments on GC tuning, I think it would be great if the book contains example of value format, example of result of each parameter if they’re existing for help engineers have the control over JVM application. And it will really useful if when each parameters need to be add/drop out.

Other resource

Secrets of Performance Tuning Java on Kubernetes by Bruno Borges

This session has mentioned on this book and apparently, I watched it before! This session is gem and you can learn a lot about the world of performance tuning. 👍

I hope you enjoy my review so far. See you in the next book review article. Furthermore, You can reach me at the below links.

Facebook: Thanaphoom Babparn
FB Page: TP Coder
LinkedIn: Thanaphoom Babparn
Linktree: https://linktr.ee/tpbabparn

--

--

Thanaphoom Babparn

Software engineer who wanna improve himself and make an impact on the world.