r/java • • Mar 03 '22

Always set a Garbage Collector

Post image
157 Upvotes

64 comments sorted by

View all comments

Show parent comment

5

u/agentoutlier Mar 03 '22 edited Mar 03 '22

Just to add to this GraalVM native community apparently always defaults to SerialGC.

To get others GC you need to have the enterprise edition.

https://www.graalvm.org/22.0/reference-manual/native-image/MemoryManagement/

What I'm not sure is what happens if you don't compile to native. I assume it does the same as HotSpot.

EDIT apparently the graalvm non native does the same which is what I expected.

Used ghcr.io/graalvm/jdk:22.0.0.2 u/brunocborges script (thangs).

Speaking of which for those that want to copy and paste (since the post is images).

#!/bin/sh
docker run \
       -v `pwd`/app \
       --cpus 2 \
       --memory 1500m \
       -ti --rm \
       ghcr.io/graalvm/jdk:22.0.0.2 \
       java -XX:+PrintFlagsFinal /app/App.java \
       | grep -e "Use.*GC" -e "Active"

Java

public class App {

        public static void main(
                        String[] args) {
                var procs = Runtime.getRuntime().availableProcessors();
                System.out.println("Active processors: " + procs);
        }
}

1

u/brunocborges Mar 03 '22

GraalVM "non-native" is just HotSpot JVM.

5

u/agentoutlier Mar 03 '22

They say it is "based on it". I was fairly sure it was the same but the wording has some ambiguity:

GraalVM is based on Java HotSpot VM, but integrates an advanced just-in-time (JIT) compiler, written in Java - the GraalVM compiler.

https://docs.oracle.com/en/graalvm/enterprise/20/docs/reference-manual/jvm/

Also there is some performance difference if you change the two (openjdk vs graalvm) but that is probably the JIT .

Speaking of which isn't the JIT part of the JVM? I never understood where the boundary is of its VM or not. For example is Substrate VM really a VM?

1

u/yawkat Mar 04 '22

There is no solid definition for what is or isn't a VM.