Book Summary: Mastering the Java Virtual Machine An in-depth guide to JVM internals and performance optimization

Amr Hesham
4 min readApr 19, 2024

Hello everyone, I am Amr and i am a Software engineer who is interested in Compiler and Tools development and in this article i will try to write a summary for Mastering the Java Virtual Machine book so you can get an idea about what is the content and what to expect from it.

The book contains four parts which are.

  • Understanding the JVM
  • Memory Management and Execution
  • Alternative JVMs
  • Advanced Java Topics

Part 1: Understanding the JVM

The author starts this part by taking you in the journey to why the JVM exists what are the advantages, and how it represents your code as bytecodes, it’s teaching you how to map your code to bytecode and how to read and understand the JVM class file structure,

Then it explains the most common bytecode instructions such as bytecode for Arithmetic and comparisons operations, Shifts, bitwise, conditions such as equal, and not equals for primitives and references, different method calls and how value is converted from type to other (Casting) and how JVM manipulate object (Set and Get), in my opinion the advantage here is that the author provide many practical examples and code snippets so after this part you can read and understand bytecodes for basics cases

Part 2: Memory Management and Execution

This part is very important for a developer who cares about optimizing your application, it takes you on a journey to the internals of JVM and how it deals with your code as a VM such as variables, operators, stack, heap, methods and native methods, also how JVM can give you more performance using the JIT (Just in time compilation), those information's are very important for example when you face a StackOverflow exception with your recursive methods now you know what this exactly means and why it overflow!

Next it explains the different types of Garbage Collections algorithms how they are works and what are the different between, how to config the GC for your application and what are the recommended configuration, also how to select the right algorithm for your application.

Part 3: Alternative JVMs

This part introduces the Graal VM and explains the use case for it, comparing it with JVM to make it clear what are the advantages and disadvantages with real use cases and how you can create a native image for your application without the need to have VM installed on machine to be able to launch it

Next, it takes you on a journey to see different alternative JVMs implementations exists, and as we know from the previous part that changing Garbage Collector algorithm can led to different performance and pause time, you will learn that using a different JVM implementation will give you different trade off, so you will learn what are the different between the most six popular JVMs implementation (Eclipse J9, Amazon Corretto, Azul Zulu and Zin, IBM Semeru and Eclipse Temurin).

Part 4: Advanced Java Topics

This part is related to advanced topics in Java starting from Metadata and trade offs in frameworks then going to the most interesting topics for me (As a tools Developer)

Staring by the reflection and Dynamic Proxy topics, why they are important and what are the trade-offs of using them with interesting practical examples for both of them.

Next, it takes you to the Annotation Processor topic and how to take advantages of compile-time annotations to validate and generate code, why it’s different from runtime reflection and recreate the previous example in the Annotation processor.

For me I was interested in building tools using Annotation processor such as EasyAdapter library to help you to build UI Adapters easily using only Annotations, but it was the first time for me to learn about Dynamic Proxy and after some search i found that many Android libraries are built using it.

Summary

The book is very interesting to me and learned much good information about GC and how the JVM works in very low-level details, I recommend searching for examples for each concept trying to install the ASM library with the new java project and playing around with Bytecodes while reading the first two parts.

I hope you enjoyed my article, and you can find me on

You can find me on: GitHub, LinkedIn, and Twitter.

You can sponsor my work using GitHub Sponsor ❤️ from here.

Thanks for reading and enjoy Programming 😋.

--

--