Understand the internals and architecture of GraalVM with the help of hands-on experiments and gain deep knowledge that you can apply to improve your application’s performance, interoperability, and throughput.
---
Key Features
============
Generate faster and leaner code with minimum computing resources for high performance
Compile Java applications faster than ever to a standalone executable called native images
Create high-performance polyglot applications that are compatible across various JVM and non-JVM languages
GraalVM is a universal virtual machine that allows programmers to compile and run applications written in both JVM and non-
JVM languages. It improves the performance and efficiency of applications, making it an ideal companion for cloud-native or
microservices-based applications.
---
This book is a hands-on guide, with step-by-step instructions on how to work with GraalVM. Starting with a quick introduction to the GraalVM architecture and how things work under the hood, you’ll discover the performance benefits of running your Java applications on GraalVM. You’ll then learn how to create native images and understand how AOT (ahead-of-time) can improve application performance significantly. The book covers examples of building polyglot applications that will help you explore the interoperability between languages running on the same VM. You’ll also see how you can use the Truffle framework to implement any language of your choice to run optimally on GraalVM.
---
By the end of this book, you’ll not only have learned how GraalVM is beneficial in cloud-native and microservices development but also how to leverage its capabilities to create high-performing polyglot applications.
---
What you will learn
===================
Gain a solid understanding of GraalVM and how it works under the hood
Work with GraalVM’s high performance optimizing compiler and see how it can be used in both JIT (just-in-time) and AOT (ahead-of-time) modes
Get to grips with the various optimizations that GraalVM performs at runtime
Use advanced tools to analyze and diagnose performance issues in the code
Compile, embed, run, and interoperate between languages using Truffle on GraalVM
Build optimum microservices using popular frameworks such as Micronaut and Quarkus to create cloud-native applications.
Author(s): A.B Vijay Kumar
Edition: 1
Publisher: Packt
Year: 2021
Language: English
Pages: 356
Tags: java graalVM jdk compiler
Cover
Title Page
Copyright and Credits
Dedicated
Contributors
Table of Contents
Preface
Section 1: The Evolution of JVM
Chapter 1: Evolution of Java Virtual Machine
Technical requirements
Introduction to GraalVM
Learning how JVM works
Understanding the JVM architecture
Class loader subsystem
Memory subsystem
JVM execution engine subsystem
Native subsystem
Summary
Questions
Further reading
Chapter 2: JIT, HotSpot, and Graal JIT
Technical requirements
Setup environment
Installing OpenJDK Java
Installing JITWatch
Taking a deep dive into HotSpot and the C2 JIT compiler
Code cache
Compiler threshold
On-stack replacement
Tiered compilation
Understanding the optimizations performed by JIT
Inlining
Monomorphic, bimorphic, and megamorphic dispatch
Dead code elimination
Loop optimization – Loop unrolling
Escape analysis
Deoptimization
Non-entrant code
Zombie code
Graal JIT and the JVM Compiler Interface (JVMCI)
Summary
Questions
Further reading
Section 2: Getting Up and Running with GraalVM – Architecture, and Implementation
Chapter 3: GraalVM Architecture
Reviewing modern architectural requirements
Smaller footprint
Quicker bootstrap
Polyglot and interoperability
Learning what the GraalVM architecture is
Reviewing the GraalVM editions (Community and Enterprise)
Understanding the GraalVM architecture
JVM (HotSpot)
Java Virtual Machine Compiler Interface (JVMCI)
Graal compiler and tooling
Truffle
Sulong – LLVM
SubstrateVM (Graal AOT and native image)
An overview of GraalVM microservices architecture
Understanding how GraalVM addresses various non-functional aspects
Performance and scalability
Security
DevOps – continuous integration and delivery
Summary
Questions
Further reading
Chapter 4: Graal Just-In-Time Compiler
Technical requirements
Setting up the environment
Setting up Graal
Understanding the Graal JIT compiler
Graal compiler configuration
Graal JIT compilation pipeline and tiered optimization
Graal intermediate representation
Understanding Graal compiler optimizations
Speculative optimization
Partial escape analysis
Inter-procedural analysis and inlining
Debugging and monitoring applications
Visual Studio Code extension
GraalVM Dashboard
Command-line tools
Chrome debugger
Summary
Questions
Further reading
Chapter 5: Graal Ahead-of-Time Compiler and Native Image
Technical requirements
Building native images
Analyzing the native image with GraalVM Dashboard
Understanding the code size breakdown report
Heap size breakdown
Understanding PGO
Native image configuration
Hosted options and resource configurations
Generating Graal graphs for native images
Understanding how native images manage memory
The Serial garbage collector
The G1 Garbage Collector
Managing the heap size and generating heap dumps
Building static native images and native shared libraries
Debugging native images
Limitations of Graal AOT (Native Image)
GraalVM containers
Summary
Questions
Further reading
Section 3: Polyglot with Graal
Chapter 6: Truffle – An Overview
Exploring the Truffle language implementation framework
Exploring the Truffle interpreter/compiler pipeline
Self-optimization and tree rewriting
Partial Evaluation
Learning Truffle DSL
Polymorphic inline caching
Understanding how Truffle supports interoperability
Frame management and local variables
Dynamic Object Model
Understanding Truffle instrumentation
Ahead-of-time compilation using Truffle
Optimizing Truffle interpreter performance with launcher options
SimpleLanguage and Simple Tool
Summary
Questions
Further reading
Chapter 7: GraalVM Polyglot – JavaScript and Node.js
Technical requirements
Understanding the JavaScript (including Node.js) Truffle interpreter
Verifying JavaScript, Node, and npm installation and versions
JavaScript interoperability
Polyglot native images
Bindings
Multithreading
Asynchronous programming – Promise and await
Summary
Questions
Further reading
Chapter 8: GraalVM Polyglot – Java on Truffle, Python, and R
Technical requirements
Understanding Espresso (Java on Truffle)
Why do we need Java on Java?
Installing and running Espresso
Exploring polyglot interoperability with Espresso
Exploring Espresso interoperability with other Truffle languages
Understanding GraalPython – the Python Truffle interpreter
Installing Graal Python
Understanding the graalpython compilation and interpreter pipeline
Exploring interoperability between Java and Python
Exploring interoperability between Python and other dynamic languages
Understanding FastR – the R Truffle interpreter
Installing and running R
Exploring the interoperability of R
Summary
Questions
Further reading
Chapter 9: GraalVM Polyglot – LLVM, Ruby, and WASM
Technical requirements
Understanding LLVM – the (Sulong) Truffle interface
Installing the LLVM toolchain
Exploring LLVM interoperability
Understanding the LLVM managed environment
Understanding TruffleRuby – the Ruby Truffle interpreter
Installing TruffleRuby
Understanding the TruffleRuby interpreter/compiler pipeline
Exploring Polyglot interoperability with TruffleRuby
Understanding GraalWasm – the WASM Truffle interpreter
Understanding GraalWasm architecture
Installing and running GraalWasm
Installing Emscripten (emcc)
Summary
Questions
Further reading
Section 4: Microservices with Graal
Chapter 10: Microservices Architecture with GraalVM
Technical requirements
Overview of microservices architecture
Building microservices architecture with GraalVM
Understanding GraalVM containers
Case study – online book library
Functional architecture
Deployment architecture
Exploring modern microservices frameworks
Building BookInfoService using Spring without GraalVM
Building BookInfoService with Micronaut
Building BookInfoService with Quarkus
Building a serverless BookInfoService using fn project
Summary
Questions
Further reading
Assessments
About Packt
Other Books You May Enjoy
Index