Hacker News new | ask | show | jobs
by squeaky-clean 1128 days ago
There's no JVM when using GraalVM Native Images, it relies on a JVM during the compile step (well, specifically GraalVM), but produces native code similar to compiling C. There's no virtual machine running bytecode, just entirely native code. So the size of the executable will depend on how many features of the JVM you need compiled into your executable.

A pure java bytecode (bring-your-own-JVM) Hello World can be under 2KB pretty easily. Smaller than the equivalent C program. But of course, that's not including the size of your system JVM.

2 comments

> but produces native code similar to compiling C.

That's very misleading. For one, Java running native still needs a Garbage Collector, maintains Object headers which increase memory usage, can do things like reflection for configured classes, can load services via the ServiceLoader, schedule Threads and manage executors, and many other things that are "expected" to any Java application... in summary: native executables still have a Java runtime embedded into them (called Substrate VM, by the way), making them very different from C (much more like Go).

Also,notice that native Java executables still tend to have a lower "peak performance" (i.e. once a "normal" JVM has warmed up, it will almost certainly be faster than a native executable because the latter cannot do JIT compilation to take advantage of runtime profiling, like a normal JVM does).

It also misleading to think C doesn't have a runtime.

https://learn.microsoft.com/en-us/cpp/c-runtime-library/c-ru...

https://gcc.gnu.org/onlinedocs/gccint/Libgcc.html

https://software-dl.ti.com/codegen/docs/tiarmclang/compiler_...

And many more, not feeling like linking documentation from all C compilers.

In fact this is so relevant even for C, that ISO C has a special section for deployments without runtime support, named freestanding C.

"In a freestanding environment (in which C program execution may take place without any benefit of an operating system), the name and type of the function called at program startup are implementation-defined. There are otherwise no reserved external identitiers. Any library facilities available to a freestanding propram are implementation-defined."

That's not at all comparable.

From your link:

"Most of the routines in libgcc handle arithmetic operations that the target processor cannot perform directly."

You're trying to imply the Java native runtime is comparable to liggcc?? That's silly.

A runtime is a runtime, regardless of the size and features checkbook.
I think the point was that it's a matter of degree and not of substance
The hello world .class file is 413 bytes, just as an info.
Thanks, smaller than I remembered. Been a while since I've done any Java so I aimed a little high.