0

How Spring native can run an application coded in java without JVM, from https://spring.io/blog/2021/03/11/announcing-spring-native-beta:

In practice, that means that in addition to the regular Java Virtual Machine supported by Spring since its inception, we are adding beta support for compiling Spring applications to native images with GraalVM in order to provide a new way to deploy Spring applications. Java and Kotlin are supported.

Those native Spring applications can be deployed as a standalone executable (no JVM installation required) and offer interesting characteristics including almost instant startup (typically < 100ms), instant peak performance and lower memory consumption at the cost of longer build times and fewer runtime optimizations than the JVM.

What means by "at the cost of longer build times and fewer runtime optimizations than the JVM"

Ram Sharan Mittal
  • 526
  • 2
  • 7
  • 16
  • GraalVM *is* a VM; the announcement is using imprecise language. – chrylis -cautiouslyoptimistic- Mar 21 '21 at 01:33
  • 1
    As the text says, all [Spring](https://spring.io/) did was ensuring compatibility with [GraalVM](https://www.graalvm.org/). It is then GraalVM that provides the ability to generate a *native image*, so if you want to learn more about native image support, go read the [**GraalVM documentation**](https://www.graalvm.org/reference-manual/native-image/). – Andreas Mar 21 '21 at 01:36

1 Answers1

1

What means by "at the cost of longer build times and fewer runtime optimizations than the JVM"[?]

Two things

  1. Creating a native image takes considerably longer than compiling into class files. I didn't measure it exactly, but I'd say something that needs a few seconds to compile into a class files takes ~5 min to compile into a native image.

  2. Optimisations happen at compile time. They therefore cannot take into account dynamic behaviour. A normal JVM looks at the actual execution of code, tries optimisations and actually measures if they are effective. This can't be done at compile time and isn't done at run time.

Jens Schauder
  • 77,657
  • 34
  • 181
  • 348