0%

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

Book Description

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

Who this book is for

This book is for JVM developers looking to optimize their application's performance. You'll also find this book useful if you're a JVM developer looking to explore options to develop polyglot applications using tools from the Python, R, Ruby, or Node.js ecosystem. A solid understanding of software development concepts and prior experience working with programming languages is necessary to get started.

Table of Contents

  1. Supercharge Your Applications with GraalVM
  2. Contributors
  3. About the author
  4. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
    4. Download the example code files
    5. Code in Action
    6. Download the color images
    7. Conventions used
    8. Get in touch
    9. Reviews
  5. Section 1: The Evolution of JVM
  6. Chapter 1: Evolution of Java Virtual Machine
    1. Technical requirements
    2. Introduction to GraalVM
    3. Learning how JVM works
    4. Understanding the JVM architecture
    5. Class loader subsystem
    6. Memory subsystem
    7. JVM execution engine subsystem
    8. Native subsystem
    9. Summary
    10. Questions
    11. Further reading
  7. Chapter 2: JIT, HotSpot, and GraalJIT
    1. Technical requirements
    2. Setup environment
    3. Installing OpenJDK Java
    4. Installing JITWatch
    5. Taking a deep dive into HotSpot and the C2 JIT compiler
    6. Code cache
    7. Compiler threshold
    8. On-stack replacement
    9. Tiered compilation
    10. Understanding the optimizations performed by JIT
    11. Inlining
    12. Monomorphic, bimorphic, and megamorphic dispatch
    13. Dead code elimination
    14. Loop optimization – Loop unrolling
    15. Escape analysis
    16. Deoptimization
    17. Non-entrant code
    18. Zombie code
    19. Graal JIT and the JVM Compiler Interface (JVMCI)
    20. Summary
    21. Questions
    22. Further reading
  8. Section 2: Getting Up and Running with GraalVM – Architecture and Implementation
  9. Chapter 3: GraalVM Architecture
    1. Reviewing modern architectural requirements
    2. Smaller footprint
    3. Quicker bootstrap
    4. Polyglot and interoperability
    5. Learning what the GraalVM architecture is
    6. Reviewing the GraalVM editions (Community and Enterprise)
    7. Understanding the GraalVM architecture
    8. JVM (HotSpot)
    9. Java Virtual Machine Compiler Interface (JVMCI)
    10. Graal compiler and tooling
    11. Truffle
    12. Sulong – LLVM
    13. SubstrateVM (Graal AOT and native image)
    14. An overview of GraalVM microservices architecture
    15. Understanding how GraalVM addresses various non-functional aspects
    16. Performance and scalability
    17. Security
    18. DevOps – continuous integration and delivery
    19. Summary
    20. Questions
    21. Further reading
  10. Chapter 4: Graal Just-In-Time Compiler
    1. Technical requirements
    2. Setting up the environment
    3. Setting up Graal
    4. Understanding the Graal JIT compiler
    5. Graal compiler configuration
    6. Graal JIT compilation pipeline and tiered optimization
    7. Graal intermediate representation
    8. Understanding Graal compiler optimizations
    9. Speculative optimization
    10. Partial escape analysis
    11. Inter-procedural analysis and inlining
    12. Debugging and monitoring applications
    13. Visual Studio Code extension
    14. GraalVM Dashboard
    15. Command-line tools
    16. Chrome debugger
    17. Summary
    18. Questions
    19. Further reading
  11. Chapter 5: Graal Ahead-of-Time Compiler and Native Image
    1. Technical requirements
    2. Building native images
    3. Analyzing the native image with GraalVM Dashboard
    4. Understanding the code size breakdown report
    5. Heap size breakdown
    6. Understanding PGO
    7. Native image configuration
    8. Hosted options and resource configurations
    9. Generating Graal graphs for native images
    10. Understanding how native images manage memory
    11. The Serial garbage collector
    12. The G1 Garbage Collector
    13. Managing the heap size and generating heap dumps
    14. Building static native images and native shared libraries
    15. Debugging native images
    16. Limitations of Graal AOT (Native Image)
    17. GraalVM containers
    18. Summary
    19. Questions
    20. Further reading
  12. Section 3: Polyglot with Graal
  13. Chapter 6: Truffle – An Overview
    1. Exploring the Truffle language implementation framework
    2. Exploring the Truffle interpreter/compiler pipeline
    3. Self-optimization and tree rewriting
    4. Partial Evaluation
    5. Learning Truffle DSL
    6. Polymorphic inline caching
    7. Understanding how Truffle supports interoperability
    8. Frame management and local variables
    9. Dynamic Object Model
    10. Understanding Truffle instrumentation
    11. Ahead-of-time compilation using Truffle
    12. Optimizing Truffle interpreter performance with launcher options
    13. SimpleLanguage and Simple Tool
    14. Summary
    15. Questions
    16. Further reading
  14. Chapter 7: GraalVM Polyglot – JavaScript and Node.js
    1. Technical requirements
    2. Understanding the JavaScript (including Node.js) Truffle interpreter
    3. Verifying JavaScript, Node, and npm installation and versions
    4. JavaScript interoperability
    5. Polyglot native images
    6. Bindings
    7. Multithreading
    8. Asynchronous programming – Promise and await
    9. Summary
    10. Questions
    11. Further reading
  15. Chapter 8: GraalVM Polyglot – Java on Truffle, Python, and R
    1. Technical requirements
    2. Understanding Espresso (Java on Truffle)
    3. Why do we need Java on Java?
    4. Installing and running Espresso
    5. Exploring polyglot interoperability with Espresso
    6. Exploring Espresso interoperability with other Truffle languages
    7. Understanding GraalPython – the Python Truffle interpreter
    8. Installing Graal Python
    9. Understanding the graalpython compilation and interpreter pipeline
    10. Exploring interoperability between Java and Python
    11. Exploring interoperability between Python and other dynamic languages
    12. Understanding FastR – the R Truffle interpreter
    13. Installing and running R
    14. Exploring the interoperability of R
    15. Summary
    16. Questions
    17. Further reading
  16. Chapter 9: GraalVM Polyglot – LLVM, Ruby, and WASM
    1. Technical requirements
    2. Understanding LLVM – the (Sulong) Truffle interface
    3. Installing the LLVM toolchain
    4. Exploring LLVM interoperability
    5. Understanding the LLVM managed environment
    6. Understanding TruffleRuby – the Ruby Truffle interpreter
    7. Installing TruffleRuby
    8. Understanding the TruffleRuby interpreter/compiler pipeline
    9. Exploring Polyglot interoperability with TruffleRuby
    10. Understanding GraalWasm – the WASM Truffle interpreter
    11. Understanding GraalWasm architecture
    12. Installing and running GraalWasm
    13. Installing Emscripten (emcc)
    14. Summary
    15. Questions
    16. Further reading
  17. Section 4: Microservices with Graal
  18. Chapter 10: Microservices Architecture with GraalVM
    1. Technical requirements
    2. Overview of microservices architecture
    3. Building microservices architecture with GraalVM
    4. Understanding GraalVM containers
    5. Case study – online book library
    6. Functional architecture
    7. Deployment architecture
    8. Exploring modern microservices frameworks
    9. Building BookInfoService using Spring without GraalVM
    10. Building BookInfoService with Micronaut
    11. Building BookInfoService with Quarkus
    12. Building a serverless BookInfoService using fn project
    13. Summary
    14. Questions
    15. Further reading
  19. Assessments
    1. Chapter 1 – Evolution of Java Virtual Machine
    2. Chapter 2 – JIT, Hotspot, and GraalJIT
    3. Chapter 3 – Graal VM Architecture
    4. Chapter 4 – Graal Just-In-Time Compiler
    5. Chapter 5 – Graal Ahead-of-Time Compiler and Native Image
    6. Chapter 6 – Truffle – An Overview
    7. Chapter 7 – GraalVM Polyglot – JavaScript and Node.js
    8. Chapter 8 – GraalVM Polyglot – Java on Truffle, Python, and R
    9. Chapter 9 – GraalVM Polyglot – LLVM, Ruby, and WASM
    10. Chapter 10 – Microservices Architecture with GraalVM
    11. Why subscribe?
  20. Other Books You May Enjoy
    1. Packt is searching for authors like you
    2. Leave a review - let other readers know what you think
3.144.17.45