16 Kasım 2020 Pazartesi

GraalVM - Oracle Tarafından Geliştiriliyor

Giriş
GraalVM Oracle tarafından geliştiriliyor. 2018 yılının Nisan ayında duyuruldu. Ancak tarihçesi şöyle
The history of Graal dates back to the research works on MaxineVM, also known as a meta-circular virtual machine. If this sounds complicated then all you really have to understand is that MaxineVM is a Java virtual machine written in… Java (hence it is meta-circular).
Mayıs 2019'dan beri de ticari kullanıma hazır. Açıklaması şöyle
GraalVM is an Oracle project and has been in production-ready status since May 2019. This means that it has been extensively tested and is considered stable enough for use in production environments.
Graal Ne Demek?
Açıklaması şöyle
The word “Graal” comes from old French for “Grail.” The “VM” in “GraalVM” comes from the fact that it runs inside the JVM.
GraalVM Kurulum
Açıklaması şöyle
You can install GraalVM on your machine in several ways.

- You can download the official releases from their GitHub page. They support several platforms (including Apple Silicon!) and two versions of Java. After that, you can follow this guide for your respective platform.

- Another option if you have a UNIX-like system, like Linux or MacOS, is to use SDKMan to manage your installed SKDs. It’s a great tool to manage multiple java installations and switch between them with ease. Think of this tool as NVM for Java. Follow this link to learn more about SDKMan and about how to install it.
Örnek - MacOS
Şöyle yaparız
sdk install java 22.3.r17-grl
Kurulumu test etmek için şöyle yaparız
$ java -version
openjdk version "17.0.5" 2022-10-18
OpenJDK Runtime Environment GraalVM CE 22.3.0 (build 17.0.5+8-jvmci-22.3-b08)
OpenJDK 64-Bit Server VM GraalVM CE 22.3.0 (build 17.0.5+8-jvmci-22.3-b08, 
mixed mode, sharing)
JAVA_HOME ve PATH değişkenleri için şöyle yaparız
# Linux
export JAVA_HOME=<graalvm>

# macOS
export JAVA_HOME=/Library/Java/JavaVirtualMachines/<graalvm>/Contents/Home

# Windows
setx /M JAVA_HOME "C:\Progra~1\Java\<graalvm>"

# Linux
export PATH=<graalvm>/bin:$PATH

# macOS
export PATH=/Library/Java/JavaVirtualMachines/<graalvm>/Contents/Home/bin:$PATH

# Windows
setx /M PATH "C:\Progra~1\Java\<graalvm>\bin;%PATH%"
Sürümleri
İki sürüm var. Bunlar şöyle 
1. Community Edition 
2. Enterprise Edition

Not : Yeni paket kurmak için GraalVM gu komutu yazısına bakabilirsiniz.

1. Internal JDK
Açıklaması şöyle. Yani GraalVM'i aynen JDK gibi kullanmak mümkün, çünkü GraalVM kendi içerisinde bir HotSpot  JVM barındırıyor. 
Foremost, it’s good to remember that the GraalVM distributions contain a JDK with all the usual JDK tools, meaning you can use GraalVM as your JDK. 
...
When running Java applications just-in-time with GraalVM, the underlying JVM is the usual Java Hotspot (tm) VM, which means that most of the configuration options are equivalent,...
Bu kullanımda HotSpot VM'deki C2 derleyici yani JIT yerine Graal derleyici kullanılıyor.. Şeklen şöyle

Açıklaması şöyle
GraalVM includes two compilers — the GraalVM compiler and the GraalVM Native Image. The GraalVM compiler is an advanced JIT optimizing compiler that replaces the old C++ written HotSpot Java Virtual Machine. It is written in Java itself and designed to be modular, maintainable, and extendable. The GraalVM compiler generates faster and leaner code that requires fewer compute resources.
Truffle
Truffle ile GraalVM de kendi içinde barındırdığı Java HotSpot VM'e başka alternatifler de sunmaya başlamış. GraalVM Truffle yazısına bakabilirsiniz. 

2. Compile To Native Executable
Açıklaması şöyle. Böylece artık JVM'e gerek kalmadan uygulama çalıştırılabiliyor Buna aynı zamanda ahead-of-time compilation da deniliyor.
What excites people so much about GraalVM is a sub-project called SubstrateVM (SVM), and that compiles JVM applications to native executables. This is also called a ahead-of-time compiler.

Once you compile a JVM application into a native executable, it can run without a JVM. In fact, what you get is a self-contained executable just like you would get with Go.
Native Executable Dezavantajları
1. Çok büyük bellek kullanan uygulamalar için iyi değil.
2. Artık Java Agents, Java Management Extensions (JMX), and JDK Flight Recorder (JFR) gibi bir çok araç olmuyor
3. GC olarak SerialGC var. Açıklaması şöyle
Additionally, it has a much simpler garbage collection (SerialGC) to start with and generates Image Heap during the native-image build, resulting in lower memory footprint. But we got to select a GC as we prefer. However, it’s worth noting that some GC options, like G1GC, are only available in the Enterprise version of GraalVM at the time of writing.
Substrate VM
Native Image olarak derlenen uygulamalar halen bir runtime katmanına ihtiyaç duyuyor. Bunu da  SubstrateVM sağlıyor.  Açıklaması şöyle
The GraalVM native image compiler compiles Java applications into standalone native executable that include the application classes, classes from its dependencies, runtime library classes, and statically linked native code from JDK. These executable do not run on the JVM; instead, they use a different runtime system called the “Substrate VM.”

This runtime system includes all necessary components like memory management, thread scheduling, and more. As a result, the resulting program has a faster startup time and lower runtime memory overhead compared to a JVM, making it ideal for container and serverless applications.
Şeklen şöyle


Debugging
Açıklaması şöyle
However, the minimalist VM, SubstrateVM, used in the native executable does not support JVM-TI, and thus Java debuggers cannot be used for native executable debugging.

To debug the native executable, developers need to use an OS-level system debugger such as GDB.


Pluginler
Bir başka açıklama şöyle. Yani Maven veya Gradle için pluginler var. Ayrıca gereksiz kodları native executable dosyasına dahil etmiyor.
  • Compiles Java code ahead-of-time into a native executable file.
  • Only the code that is required at run time by the application (a fraction of the resources required by the JVM) is included in the executable file.
  • While the AOT compiler compiles Java code into a native executable, it will analyze its dependencies, dependent JDK libraries and VM components and removes all unused classes, method, and fields from your application and libraries.
  • This process makes reverse engineering difficult by converting Java bytecode into native machine code. Potential attack surfaces are also minimized.
  • Supported by many microservice frameworks: Micronaut, Spring, Helidon, Quarkus, etc.
  • Maven and Gradle plugins for Native Image so you can easily build, test (there is also JUnit testing support), and run Java applications as executable files.
  • Costs less to run
  • Fast startup, no warmup
  • Ideal for containers (can be packaged into a lightweight container image for faster and more efficient deployment)
Detayları native-image komutu yazısına taşıdım.

3. Build a Shared Library
Açıklaması şöyle
If instead of the executable you would like to build a shared library, you can do that passing the --shared option. You need to mark the methods to be exposed with the @CEntryPoint annotation,..
4. Build Statically Linked Binaries
Açıklaması şöyle
Another very useful possibility is to build statically linked binaries where the OS libraries like libc are linked into the executable. It’s even possible to pick which libc implementation to use. glibc is used by default, ...

Hiç yorum yok:

Yorum Gönder