News for hackers. Stuff that matters.
Re:GraalVM by greatjack613 on Sunday August 09, 2020 @11:11PM (#24105099)
As an engineer who lives and breathes java, both in the context of high performance servers and android apps, can someone explain what this does for me besides for quick startup times through the native image feature? what are the benefits of this?
Re:GraalVM by hedora on Sunday August 09, 2020 @11:18PM (#24105144)
Java’s linker is based on an open world assumption, where you can add arbitrary stuff to the classpath and dynamically link it at runtime. This defeats most compiler optimizations, so you’re left with the JIT.

GraalVM makes a closed world assumption, so it can do things like dead code elimination (for library functions that don’t get called), and apply static analysis to inline virtual method calls, perform constant propagation, and so on.

This lets it greatly outperform the JVM, at the expense of some rarely used functionality.

Basically, it’s like switching from the JIT to a C compiler’s -O3.

Re:GraalVM by bdibs on Sunday August 09, 2020 @11:28PM (#24105201)
And is that with their javac or is it reserved only for their native image generation?
Re:GraalVM by smabie on Monday August 10, 2020 @12:24AM (#24105547)
In my experience, native image is noticeably slower than regular openjdk, at least for Scala. The start up speed is nice, though.
Re:GraalVM by asymptotically2 on Monday August 10, 2020 @12:53AM (#24105675)
You need to pay Oracle $lots for a GraalVM enterprise licence to get profile guided optimisations, if you want some of your peak performance back.
Re:GraalVM by pjmlp on Monday August 10, 2020 @02:09AM (#24106092)
Twitter thinks otherwise, as they are the major consumer of GraalVM in production.
Re:GraalVM by didibus on Monday August 10, 2020 @02:16AM (#24106132)
GraalVM is a JIT compiler for the most part. That's the one Twitter uses I believe. SubstrateVM is what lets you perform a closed world assumption ahead of time build. And that does indeed run left performant most of the time, but it uses less memory and starts faster.
Re:GraalVM by pjmlp on Monday August 10, 2020 @03:03AM (#24106408)
Unless one feeds it with PGO data, just like it happens in most AOT workflows for optimizations like devirtualization.
Re:GraalVM by secondcoming on Monday August 10, 2020 @04:36AM (#24106913)
What part of production, do you know? Because mobile.twitter.com links are slow as hell to load
Re:GraalVM by pjmlp on Monday August 10, 2020 @04:47AM (#24106982)
Re:GraalVM by marta_morena_25 on Monday August 10, 2020 @01:42AM (#24105944)
> This lets it greatly outperform the JVM, at the expense of some rarely used functionality.

Outperform in what metric? Startup time? Granted. Anything else? Not so much.

>Basically, it’s like switching from the JIT to a C compiler’s -O3.

Yeah and that would be pretty bad (it's not a good analogy to begin with). "-O3" doesn't have anything that a JIT couldn't have. The only advantage is again, startup time. JIT compilation has otherwise only advantages over static compilcation, especially in highly polymorphic code, such as java. Static compilation for polymorphic code is a joke in terms of performance... And every C++ programmer should know that.

I didn't look at the spec, but I would assume that AOT is only the bootup and then the JIT will take over anyway. This means, they'd do some basic precompilation for fat bootup and then use JIT again to optimize the code further based on runtime analysis. Everything else would be a ridicolous step backwards in time and make AOT completely useless, except for some niche scenarios.

Re:GraalVM by TimTheTinker on Monday August 10, 2020 @02:28AM (#24106214)
As far as I know, Truffle is able to do some absolutely incredible compile-time optimizations —- reaching deeply into what we would normally regard as strictly semantic territory.

(For an example, see some of the optimizations done by TruffleRuby for things like `myArray.sort.first` - which it apparently optimizes by terminating the sort as soon as the first element is sorted to the front of the array... and all that without any special hints in the standard library. Please correct me if I’m wrong... it’s been a few years since I’ve read in depth about TruffleRuby. And granted this example isn’t Java, but I imagine there are great parallels there.)

Re:GraalVM by tosh on Monday August 10, 2020 @06:35AM (#24107633)
I'm not sure how it would terminate sort early, my initial assumption was that for small arrays there might be special-casing?

this seems to be a related thread on twitter:

https://twitter.com/ChrisGSeaton/status/1001582169578524672

Re:GraalVM by monadic2 on Monday August 10, 2020 @07:36AM (#24108133)
Are you unsure about the runtime considerations or how the compiler would infer the necessary optimizations?
Re:GraalVM by innagadadavida on Monday August 10, 2020 @10:50AM (#24109853)
Can the storage of generic containers change as well? For example, store the objects in the container instead of reference?
Re:GraalVM by galaxyLogic on Monday August 10, 2020 @02:34AM (#24106244)
> Startup time? Granted. Anything else? Not so much.

Startup time matters a lot especially for Java applications. The reason Java never got to the desktop (including browser) I believe was the startup time.

Startup time matters a lot also for micro-services.

A 2nd great benefit of GraalVM I think is it makes it easy to integrate programs written in different languages, say Node.js and Java for instance.

Re:GraalVM by Erlich_Bachman on Monday August 10, 2020 @04:59AM (#24107053)
> Java never got to the desktop (including browser)

What do you mean by this? There are a lot of desktop Java applications...

Re:GraalVM by outadoc on Monday August 10, 2020 @09:31AM (#24109007)
I'd like to hear about them, because apart from enterprise applications, there aren't that many left. Electron is the new desktop Java.
Re:GraalVM by hoistbypetard on Monday August 10, 2020 @05:19PM (#24114113)
I wouldn't call them dominant by any stretch, but I wouldn't call them uncommon. Ones I use somewhere between daily and semi-regularly:

* Pycharm * Datagrip * Charles * JDiskReport * TexturePacker * Android Studio and associated tools * Apache Directory Studio * Zed attack proxy

That's just stuff that I've used recently and on an ongoing basis... I feel like I see quite a bit more of it.

Re:GraalVM by galaxyLogic on Tuesday August 11, 2020 @02:35AM (#24117725)
I used to use a thing called JMeter. But its GUI felt inferior in my view compared to typical Windows applications.
Re:GraalVM by mikkom on Monday August 10, 2020 @05:16AM (#24107159)
> The reason Java never got to the desktop (including browser) I believe was the startup time.

I think it's mainly the fact that it has always been very difficult to create executable files.

Running java requires you to install the given version of JRE instead of just downloading an application and starting it.

Re:GraalVM by pjmlp on Monday August 10, 2020 @07:50AM (#24108252)
It was always very easy, just package the JRE with the application, use an installer like any other desktop application, or buy one of those commercial AOT compilers available since the start of century.
Re:GraalVM by benibela on Monday August 10, 2020 @04:54PM (#24113861)
But that takes a lot of space

You could not fit it on a floppy

Re:GraalVM by pjmlp on Monday August 10, 2020 @04:57PM (#24113907)
The 8 and 16 bit home computer scene are way past us.
Re:GraalVM by sriku on Monday August 10, 2020 @03:36AM (#24106585)
There's also an expectation that memory footprint will be lower and that can contribute to speed by reducing GC time. The "JIT can do it too" arguments generally don't consider bounded memory.
Re:GraalVM by avasthe on Monday August 10, 2020 @11:52PM (#24117016)
Hehehe the old AOT vs JIT debate.

JITs can do great optimizations in theory. But in practice they have only so much time to do optimizations.

And startup time, binary distribution size, memory footprint matter too.

Re:GraalVM by pjmlp on Monday August 10, 2020 @02:08AM (#24106083)
It is a meta-circular VM, where all layers except for a small glue layer is implemented in Java, already that is quite cool.

It grew out of the MaximeVM project at Sun labs.

Other well known meta-circular JVM,were Squawk for Sun SPOT and Jikes RVM.

Then on top of that, it provides a LLVM like infrastructure to build compilers and language runtimes, all in memory safe language like Java.

Additionally there is a long term roadmap to increasingly replace C++ parts of OpenJDK with GraalVM code.

Re:GraalVM by marvy on Tuesday August 11, 2020 @11:00AM (#24120983)
> It grew out of the MaximeVM project at Sun labs.

I think you mean MaxineVM :)

Re:GraalVM by de6u99er on Sunday August 09, 2020 @11:35PM (#24105241)
You can compile your Java code into an executable which doesn't require Java to be present. Advantages would be reduced memory footprint and quicker startup times, which could be ideal for microservices started on demand instead of constantly running.

That being said, the people at Spring don't recommend it for production use yet. Here's what they have to say about it:

"While GraalVM is now GA, GraalVM native image feature which allows ahead-of-time compilation of Java applications into executable images is only available as an early adopter plugin, so we don't consider it production ready yet."

https://github.com/spring-projects/spring-framework/wiki/Gra...

Re:GraalVM by gunnarmorling on Monday August 10, 2020 @03:15AM (#24106482)
As a counter-point, Quarkus [1] has mature support for building Java apps as native binaries via GraalVM, with a large number of extensions that enable 3rd party libraries to be used in native binaries, and people use this successfully in production. Issues from the past, like lack of debug symbol support with GraalVM CE, have also been resolved by now.

Shameless plug for one real-world usage: the search feature of my personal blog is built as a GraalVM native binary, running as a serverless app on AWS Lambda [3].

Disclaimer: I work for Red Hat, who sponsor the development of Quarkus

[1] https://quarkus.io/

[2] https://quarkus.io/guides/

[3] https://www.morling.dev/blog/how-i-built-a-serverless-search...

Re:GraalVM by nobleach on Monday August 10, 2020 @11:27AM (#24110317)
While what Quarkus promises sounds delightful, the actual dev experience is still not something I'd recommend. The amount of libraries one can use is still very limited. The compiler errors when one chooses to step outside of the approved list of supported libraries, are very cryptic (or non-existent). In my case, I tried to use Apache Freemarker for templating. I could've tried Quarkus' own templating library, but it didn't exist at that time. What was worse, I had to shut down nearly every app on my 16 Gigabyte, 6-core machine to compile the image! If I didn't do that, compilation would fail with no useful info. The Quarkus team does a wonderful job of demoing a Hello World example. I was just unable to achieve the same success. I love what they're trying to build, so I'll check back with regularity. Our one Quarkus app is using OpenJDK 1.8 for the time being.
Re:GraalVM by gunnarmorling on Monday August 10, 2020 @02:15PM (#24112268)
Agreed that the experience when trying to native-enable existing libs isn't the greatest. Altough those things are rather reported by the GraalVM compiler rather than Quarkus. The working model and assumption is that somebody goes through this once and then either contributes changes to the library in question back upstream or provides a Quarkus extension for that library, sparing others from that hassle.

That RAM consumption sounds definitely over the top; if you still have the context, logging an issue would be very welcomed. That said, there's many libraries enabled by Quarkus (see quarkus.io/guides/), so every essential functionality should be covered by now. Still a question of course whether your specific library in a given space (like FreeMarker vs. Quarkus Qute) already is supported. In any case, thanks for checking back in regularly, things might look better next time already, as the framework evolves rapidly.

Re:GraalVM by vips7L on Tuesday August 11, 2020 @10:58AM (#24120955)
Isn't native-image memory consumption and compile time basically a known issue by the graal team?
Re:GraalVM by thu2111 on Monday August 10, 2020 @03:20PM (#24112982)
Note that Quarkus starts very fast on Java 14 too. With JDK 14 their hello world app starts in about 600msec on my laptop. HotSpot got optimised a lot over the years and Quarkus gets some of its speed boost by just doing less dynamic stuff at startup.
Re:GraalVM by erik_seaberg on Monday August 10, 2020 @01:10AM (#24105763)
Static linking is back in fashion, but it means many stale copies of the guts of Java are present, where before we had just one complete and managed copy. It's very similar to bundling your own libc when pretty much every system already has one.
Re:GraalVM by brabel on Monday August 10, 2020 @02:56AM (#24106372)
You're not wrong, but with Java evolving rapidly, we're in a situation where there are dozens of commonly used JVM versions in the wild... being able to ship the most recent JVM (which can be as little as 25MB depending on which JDK modules you depend on) with your application not only allows you to benefit from using modern language features, but it also makes your application safer by using the latest runtime with the most up-to-date security fixes, not to mention performance and testing becomes a lot easier when you only have one JVM version to worry about. Also, you can have both options. I have a somewhat popular Java app that I distribute as a tiny jar (300KB, requires Java 9+) and as a stand-alone app (packaged with jlink, around 35MB including JDK 11) - and users can choose which one they want.
Re:GraalVM by bmc7505 on Monday August 10, 2020 @12:03AM (#24105419)
> You can compile your Java code into an executable which doesn't require Java to be present.

Wasn't this feature already supported in JDK 14 with the jpackage tool?

https://openjdk.java.net/jeps/343

Re:GraalVM by vbsteven on Monday August 10, 2020 @12:55AM (#24105683)
If I understand correctly, the difference between jpackage and GraalVM is this:

Jpackage bundles a small Java VM (with only the features you use) together with your compiled bytecode into a single executable. When it runs it starts up the VM and executes bytecode on that VM exactly the same as it would be if you were to run a jar on a preexisting JDK/JRE installation.

Graal compiles your full app ahead of time into a native code binary. There is no bytecode/translation happening at runtime. That is why GraalVM advertises faster startup and lower memory footprint.

So there are essentially 3 ways to run JVM (Java/Scala/Kotlin/...) code:

* compile into bytecode jar -> requires existing VM runtime

* compile into bytecode jar + bundle VM runtime -> no dependencies required, runs as the previous option

* compile into native binary -> no dependencies required, runs native, starts and runs faster

Re:GraalVM by vips7L on Monday August 10, 2020 @08:53AM (#24108706)
> Jpackage bundles a small Java VM (with only the features you use) together with your compiled bytecode into a single executable. When it runs it starts up the VM and executes bytecode on that VM exactly the same as it would be if you were to run a jar on a preexisting JDK/JRE installation.

This is incorrect. Jpackage creates an installer which will unpack the VM image and any other resources.

I've tried it with a small CLI tool and it actually doesn't work that well (at least on Windows).

Re:GraalVM by bmc7505 on Monday August 10, 2020 @12:58AM (#24105701)
Makes sense, thanks for clarifying!
Re:GraalVM by brabel on Monday August 10, 2020 @02:48AM (#24106326)
It's actually jlink that is already available and creates a minimal JVM with your application code that you can distribute as OS-specific bundles... jpackage, which is still in beta (and doesn't work very well, I've tried it recently), will take the output of jlink and turn that into some common OS-specific packages, like RPM, Debian and dmg.
Re:GraalVM by vips7L on Monday August 10, 2020 @08:55AM (#24108721)
> and doesn't work very well, I've tried it recently)

This is my experience as well. After installation, my installed app just didn't do anything.

Re:GraalVM by nsonha on Monday August 10, 2020 @12:29AM (#24105575)
I believe because dead code elimination isn't currently possible with JVM, "package to binary" would mean including the whole (or most of) JVM with your program.
Re:GraalVM by jariel on Monday August 10, 2020 @12:12AM (#24105479)
It's amazing how badly certain companies consistently put their foot in their mouths and cannot even give a basic explanation of what their products to.

To compound the inanity - Graal is also the name of a new compiler used in the newer JVMs, in addition to the name of a completely different kind of 'JRE/SDK'.

GraalVM allows for polygot execution of a number of languages: Java, Javascript, Python, and anything compiled to LLVM bitcode.

It runs them all 'side by side' so there's no translation barrier when interacting between languages.

GraalVM also comes with a native compiler that allows you to have much faster startup time, though it comes at the cost of not getting more advanced runtime optimisations.

As far as 'performance' I don't think there is anything fundamentally different form the newer JVMs.

Re:GraalVM by darksaints on Sunday August 09, 2020 @11:25PM (#24105185)
Even in JIT mode there is performance improvement due to reduced heap allocation.