find which type of garbage collector is running

后端 未结 10 951
旧巷少年郎
旧巷少年郎 2020-12-04 08:58

Post JSE 5 ergonomics is intended to automatically select the appropriate type of garbage collector for you (among other things).

I would like to know if there is an

10条回答
  •  悲哀的现实
    2020-12-04 09:32

    (For Java <= 8)

    This command print the GC type of a running JVM:

    jmap -heap | grep GC

    For modern computer (multiple cpus, big memory), JVM will detect it as server machine, and use Parallel GC by default, unless you specify which gc to use via JVM flags explicitly.

    e.g

    jmap -heap 26806 | grep GC

    Output:

    Parallel GC with 8 thread(s)


    @Update - for Java 9+

    (Thanks to @JakeRobb's comment.)

    Since Java 9, there are 2 changes relevant to this question:

    • Need to use jhsdb to attach to a java process or launch a debugger.
      Refer: jhsdb
    • The default gc is changed to G1.

    Command format:

    jhsdb jmap --heap --pid | grep GC

    e.g

    jhsdb jmap --heap --pid 17573 | grep GC

    Output:

    Garbage-First (G1) GC with 8 thread(s)

提交回复
热议问题