![Supercharge Your Applications with GraalVM](https://img.perlego.com/books/RM_Books/packt_pub_vpnckweg/9781800566231_300_450.webp)
Supercharge Your Applications with GraalVM
A B Vijay Kumar
- 358 pages
- English
- ePUB (mobile friendly)
- Available on iOS & Android
Supercharge Your Applications with GraalVM
A B Vijay Kumar
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
Information
Section 1: The Evolution of JVM
- Chapter 1, Evolution of Java Virtual Machine
- Chapter 2, JIT, HotSpot, and GraalJIT
Chapter 1: Evolution of Java Virtual Machine
- 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
Technical requirements
Introduction to GraalVM
- 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.
Learning how JVM works
- 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.
![Figure 1.1 ā Java compiler and interpreter](https://book-extracts.perlego.com/2825619/images/B16878_Figure_1.1-plgo-compressed.webp)
- 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.