Supercharge Your Applications with GraalVM
eBook - ePub

Supercharge Your Applications with GraalVM

A B Vijay Kumar

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

Supercharge Your Applications with GraalVM

A B Vijay Kumar

Book details
Book preview
Table of contents
Citations

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

How do I cancel my subscription?
Simply head over to the account section in settings and click on ā€œCancel Subscriptionā€ - itā€™s as simple as that. After you cancel, your membership will stay active for the remainder of the time youā€™ve paid for. Learn more here.
Can/how do I download books?
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.
What is the difference between the pricing plans?
Both plans give you full access to the library and all of Perlegoā€™s features. The only differences are the price and subscription period: With the annual plan youā€™ll save around 30% compared to 12 months on the monthly plan.
What is Perlego?
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.
Do you support text-to-speech?
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.
Is Supercharge Your Applications with GraalVM an online PDF/ePUB?
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 & Software Development. We have over one million books available in our catalogue for you to explore.

Information

Year
2021
ISBN
9781800566231
Edition
1

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

Citation styles for Supercharge Your Applications with GraalVM

APA 6 Citation

Kumar, V. (2021). Supercharge Your Applications with GraalVM (1st ed.). Packt Publishing. Retrieved from https://www.perlego.com/book/2825619/supercharge-your-applications-with-graalvm-pdf (Original work published 2021)

Chicago Citation

Kumar, Vijay. (2021) 2021. Supercharge Your Applications with GraalVM. 1st ed. Packt Publishing. https://www.perlego.com/book/2825619/supercharge-your-applications-with-graalvm-pdf.

Harvard Citation

Kumar, V. (2021) Supercharge Your Applications with GraalVM. 1st edn. Packt Publishing. Available at: https://www.perlego.com/book/2825619/supercharge-your-applications-with-graalvm-pdf (Accessed: 15 October 2022).

MLA 7 Citation

Kumar, Vijay. Supercharge Your Applications with GraalVM. 1st ed. Packt Publishing, 2021. Web. 15 Oct. 2022.