Native Image is a technology to ahead-of-time compile Java code to a standalone executable, called a native image. This executable includes the application classes, classes from its dependencies, runtime library classes, and statically linked native code from JDK. It does not run on the Java VM, but includes necessary components like memory management, thread scheduling, and so on from a different runtime system, called “Substrate VM”. Substrate VM is the name for the runtime components (like the deoptimizer, garbage collector, thread scheduling etc.). The resulting program has faster startup time and lower runtime memory overhead compared to a JVM. — Oracle
GraalVM is a Java Development Kit (JDK) written in Java. The open-source distribution of GraalVM is based on OpenJDK, and the enterprise distribution is based on Oracle JDK. As well as just-in-time (JIT) compilation, GraalVM can compile a Java application ahead of time. This allows for faster initialization, greater runtime performance, and decreased resource consumption, but the resulting executable can only run on the platform it was compiled for.
With just-in-time compilation, portions of the program are dynamically compiled into machine code by the Java Virtual Machine (JVM) while it is executing and analyzing the application's bytecode. JIT compilation enhances performance by optimizing code segments that are often run.
In contrast, the process of converting source code into machine code prior to the program being executed is known as "ahead-of-time compilation." AOT compilation involves compiling the program in advance, usually during the build step, or at least all of its major components. There is no need for further compilation during runtime because the generated binary is platform-specific.
Since the difference between the two types are clear, the following sections will be focused on the use of AOT and its cons.
Any class that has to be known at executable construction time in order to be accessible by name at executable runtime. For instance, myClass has to be in a configuration file in order to be called using Class.forName("myClass"). A ClassNotFoundException will be issued at runtime, as if the class was not found on the class path or was inaccessible, if a configuration file is provided but does not contain a class that is necessary for dynamic class loading.
The native-image tool has to be aware of all the classes, methods, and fields that should be available through reflection at build time. In an attempt to resolve these software pieces, Native Image looks for calls to the Reflection API using static analysis. The program parts that are reflectively accessible at runtime must be defined at build time in a configuration file or by using RuntimeReflection from a Feature in the event that the analysis is unsuccessful.
In the same manner that Java code uses the reflection API, native code may access Java objects, classes, methods, and fields by name. Java assets that may be accessed by name using JNI need to be listed in a configuration file provided to the native-image tool during build time.
Similar to JNI, class metadata information is needed for Java serialization, and it has to be supplied in a configuration file to the native-image tool during build time. Still, security flaws in Java serialization have been around for a while. The current serialization system will soon be replaced with a new one that avoids these issues, according to an announcement made by the Java architects.
More limitations and differences are discussed here.
Blossoming Intelligence: How to Run Spring AI Locally with Ollama
In this short article, we'll look at how easy it is to create a chat bot backend powered by Spring and Olama using the llama 3 model.
Sat, 11th May 2024
Read MoreLeveraging Spring Reactive, Functional Endpoints, Docker, and MongoDB
Blocking is a feature of classic servlet-based web frameworks like Spring MVC. Introduced in Spring 5, Spring WebFlux is a reactive framework that operates on servers like Netty and is completely non-blocking. Two programming paradigms are supported by Spring WebFlux. Annotations (Aspect Oriented Programming) and WebFlux.fn (Functional Programming).
Thu, 29th February 2024
Read MoreNextJs meets Redux: A simple user PoC
Redux is a powerful state management library primarily used in JavaScript applications, particularly those built with frameworks like React. At its core, Redux provides a predictable state container for managing the state of an application in a more organised and centralised manner. It operates on a unidirectional data flow model, which helps in maintaining the consistency of application state and facilitates easier debugging and testing.
Thu, 15th February 2024
Read MoreMonitor Spring reactive microservices with Prometheus and Grafana: a how-to guide
Micro-services monitoring is a crucial aspect of managing modern, complex software architectures. Unlike traditional monolithic applications, micro-services break down functionality into smaller, independent services that can be developed, deployed, and scaled independently.
Fri, 27th October 2023
Read MoreHands on Reactive Spring with Redis Cache and Docker support
The concept of reactive programming enables more responsive and scalable programmes by handling asynchronous data streams.
Mon, 28th August 2023
Read More