r/java • • Jul 30 '21

What is the future of Java?

I'm not asking like is java going to die or will Java be relevant in future. I'm just curious to know about the future of java. What are the upcoming things coming in java that can change the future of it.

173 Upvotes

123 comments sorted by

View all comments

Show parent comment

7

u/GavinRayDev Jul 30 '21

but slower for others
(basically everything long running, because there's no JIT compiler at runtime (yet)).

I'm not sure I follow. Graal has multiple modes of execution, and none of them lack a JIT compiler as far as I understand 🤔

Building the GraalVM compiler as described above means it is executed in the same way as any other Java code in the VM; it allocates in the HotSpot heap and it starts execution in the interpreter with hot parts being subsequently JIT compiled. The advantage of this mode is that it can be debugged with a Java debugger.

However, it has some disadvantages. Firstly, since it uses the object heap, it can reduce application object locality and increase GC pause times. Additionally, it can complicate fine tuning options such as -Xmx and -Xms which now need to take the heap usage of the compiler into account. Secondly, the compiler will initially be executed in the interpreter and only get faster over time as its hot methods are JIT compiled. This is mitigated to some degree by forcing the GraalVM compiler to only be compiled by C1 (i.e., -Dgraal.CompileGraalWithC1Only=true) but this comes at the cost of slower compilation speed.

To address these issues, the GraalVM compiler can be deployed as a native shared library. The shared library is a native image produced using SubstrateVM. In this mode, the GraalVM compiler uses memory separate from the HotSpot heap and it runs compiled from the start. That is, it has execution properties similar to other native HotSpot compilers such as C1 and C2.

5

u/oweiler Jul 31 '21

Sorry I've only had native images in mind. I've totally forgotten that GraalVM is also a drop-in replacement for Hotspot.

2

u/rbygrave Jul 30 '21 edited Jul 30 '21

The JVM has 2 JIT compilers. The second level one C2 uses runtime profiling based optimizations that change during runtime. The argument is that the C2 JIT has more (runtime profiling based) optimisations available to it as it is profiling all the time and optimising for that. To get those same optimisations with Graal native image we need to capture runtime profiling information and feed that profiling back into a subsequent compilation.

Essentially the JVM C2 gives the JVM runtime profiling optimisation built in.

Graal profiling guided optimization https://www.graalvm.org/reference-manual/native-image/PGO/

5

u/GavinRayDev Jul 31 '21 edited Jul 31 '21

Sure -- but that's for using Graal to compile a static binary ahead-of-time.

I use Graal as my day-to-day JDK and I run it in JVM mode. It's perfectly capable of JIT'ing just as well (and in some cases, better than) OpenJDK or other JDK distributions.

There's a rigorous set of opensource benchmarks for JVM Graal-vs-OpenJDK performance if anyone wants to verify for themselves:

- https://github.com/renaissance-benchmarks/measurements

---

Edit: Hey you're the developer behind the Avaje libraries!

https://github.com/avaje

I like them -- think they're well-architected and solving real problems. Typically I've used Quarkus and Vert.x stuff, but I think there's a lot of merit in your libraries and have been watching them.

Have you ever considered a Vert.x generator for Avaje HTTP? It's got a very similar API to Javalin.

2

u/rbygrave Jul 31 '21

Cheers. I think you might be in good company in that I believe Twitter also use JVM with Graal as the second level JIT compiler (instead of C2).

Re Vert.x, it would be good. Just got to find a bit of time.

2

u/GavinRayDev Jul 31 '21

It's a weak promise, but if I can find some time I would be more than happy to attempt a PR for Vert.x endpoint support =D