Supercharge Your Applications with GraalVM
eBook - ePub

Supercharge Your Applications with GraalVM

  1. 358 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

Supercharge Your Applications with GraalVM

About this book

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 languagesBook DescriptionGraalVM 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 applicationsWho this book is forThis 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.

Frequently asked questions

Yes, you can cancel anytime from the Subscription tab in your account settings on the Perlego website. Your subscription will stay active until the end of your current billing period. Learn how to cancel your subscription.
At the moment all of our mobile-responsive ePub books are available to download via the app. Most of our PDFs are also available to download and we're working on making the final remaining ones downloadable now. Learn more here.
Perlego offers two plans: Essential and Complete
  • Essential is ideal for learners and professionals who enjoy exploring a wide range of subjects. Access the Essential Library with 800,000+ trusted titles and best-sellers across business, personal growth, and the humanities. Includes unlimited reading time and Standard Read Aloud voice.
  • Complete: Perfect for advanced learners and researchers needing full, unrestricted access. Unlock 1.4M+ books across hundreds of subjects, including academic and specialized titles. The Complete Plan also includes advanced features like Premium Read Aloud and Research Assistant.
Both plans are available with monthly, semester, or annual billing cycles.
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, we’ve got you covered! Learn more here.
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Yes! You can use the Perlego app on both iOS or Android devices to read anytime, anywhere β€” even offline. Perfect for commutes or when you’re on the go.
Please note we cannot support devices running on iOS 13 and Android 7 or earlier. Learn more about using the app.
Yes, you can access Supercharge Your Applications with GraalVM by A B Vijay Kumar in PDF and/or ePUB format, as well as other popular books in Computer Science & Entreprise Applications. We have over one million books available in our catalogue for you to explore.

Section 1: The Evolution of JVM

This section will walk through the evolution of JVM, and how it optimized the interpreter and compiler. It will walk through C1 and C2 compilers, and the kind of code optimizations that JVM performs to run Java programs faster.
This section comprises the following chapters:
  • Chapter 1, Evolution of Java Virtual Machine
  • Chapter 2, JIT, HotSpot, and GraalJIT

Chapter 1: Evolution of Java Virtual Machine

This chapter will walk you through the evolution of Java Virtual Machine (JVM), and how it optimized the interpreter and compiler. We will learn about C1 and C2 compilers and various types of code optimizations that the JVM performs to run Java programs faster.
In this chapter, we will cover the following topics:
  • Introduction to GraalVM
  • Learning how JVM works
  • Understanding the JVM architecture
  • Understanding the kind of optimizations JVM performs with Just-In-Time (JIT) compilers
  • Learning the pros and cons of the JVM approach
By the end of this chapter, you will have a clear understanding of the JVM architecture. This is critical in understanding the GraalVM architecture and how GraalVM further optimizes and builds on top of JVM best practices.

Technical requirements

This chapter does not require any specific software/hardware.

Introduction to GraalVM

GraalVM is a high-performance VM that provides the runtime for modern cloud-native applications. Cloud-native applications are built based on the service architecture. The microservice architecture changes the paradigm of building micro applications, which challenges the fundamental way we build and run applications. The microservices runtimes demand a different set of requirements.
Here are some of the key requirements of a cloud-native application built on the microservice architecture:
  • Smaller footprint: Cloud-native applications run on the "pay for what we use" model. This means that the cloud-native runtimes need to have a smaller memory footprint and should run with the optimum CPU cycles. This will help run more workloads with fewer cloud resources.
  • Quicker bootstrap: Scalability is one of the most important aspects of container-based microservices architecture. The faster the application's bootup, the faster it can scale the clusters. This is even more important for serverless architectures, where the code is initialized and run and then shut down on request.
  • Polyglot and interoperability: Polyglot is the reality; each language has its strengths and will continue to. Cloud-native microservices are being built with different languages. It's very important to have an architecture that embraces the polyglot requirements and provides interoperability across languages. As we move to modern architectures, it's important to reuse as much code and logic as possible, that is time-tested and critical for business.
GraalVM provides a solution to all these requirements and provides a common platform to embed and run polyglot cloud-native applications. It is built on JVM and brings in further optimizations. Before understanding how GraalVM works, it's important to understand the internal workings of JVM.
Traditional JVM (before GraalVM) has evolved into the most mature runtime implementation. While it has some of the previously listed requirements, it is not built for cloud-native applications, and it comes with its baggage of monolith design principles. It is not an ideal runtime for cloud-native applications.
This chapter will walk you through in detail how JVM works and the key components of the JVM architecture.

Learning how JVM works

Java is one of the most successful and widely used languages. Java has been very successful because of its write once, run anywhere design principle. JVM realizes this design principle by sitting between the application code and the machine code and interpreting the application code to machine code.
Traditionally, there two ways of running application code:
  • Compilers: Application code is directly compiled to machine code (in C, C++). Compilers go through a build process of converting the application code to machine code. Compilers generate the most optimized code for a specific target architecture. The application code has to be compiled to target architectures. In general, the compiled code always runs faster than interpreted code, and issues with code semantics can be identified during compilation time rather than runtime.
  • Interpreters: Application code is interpreted to machine code line by line (JavaScript and so on). Since interpreters run line by line, the code may not be optimized to the target architecture, and run slowly, compared to the compiled code. Interpreters have the flexibility of writing once and running anywhere. A good example is the JavaScript code that is predominantly used for web applications. This runs pretty much on different target browsers with minimal or no changes in the application code. Interpreters are generally slow and are good for running small applications.
JVM has taken the best of both interpreters and compilers. The following diagram illustrates how JVM runs the Java code using both the interpreter and compiler approaches:
Figure 1.1 – Java compiler and interpreter
Figure 1.1 – Java compiler and interpreter
Let's see how this works:
  • Java Compiler (javac) compiles the Java application source code to bytecode (intermediate format).
  • JVM interprets the bytecode to machine code line by line at runtime. This helps in translating the optimized bytecode to target machine code, helping in running the same application code on different target machines, without re-programming or re-compiling.
  • JVM also has a Just-In-Time (JIT) compiler to further optimize the code at runtime by profiling the code.
In this section, we looked at how Java Compiler and JIT work together to run Java code on JVM at a higher level. In the next section, we will learn about the architecture of JVM.

Understanding the JVM architecture

Over the years, JVM has evolved into the most mature VM runtime. It has ...

Table of contents

  1. Supercharge Your Applications with GraalVM
  2. Contributors
  3. Preface
  4. Section 1: The Evolution of JVM
  5. Chapter 1: Evolution of Java Virtual Machine
  6. Chapter 2: JIT, HotSpot, and GraalJIT
  7. Section 2: Getting Up and Running with GraalVM – Architecture and Implementation
  8. Chapter 3: GraalVM Architecture
  9. Chapter 4: Graal Just-In-Time Compiler
  10. Chapter 5: Graal Ahead-of-Time Compiler and Native Image
  11. Section 3: Polyglot with Graal
  12. Chapter 6: Truffle for Multi-language (Polyglot) support
  13. Chapter 7: GraalVM Polyglot – JavaScript and Node.js
  14. Chapter 8: GraalVM Polyglot – Java on Truffle, Python, and R
  15. Chapter 9: GraalVM Polyglot – LLVM, Ruby, and WASM
  16. Section 4: Microservices with Graal
  17. Chapter 10: Microservices Architecture with GraalVM
  18. Assessments
  19. Other Books You May Enjoy