Jvm

Last updated: Apr 3, 2026

JVM FAQ

1) JVM internal storage ?

2) Difference between JVM heap, stack ?

  • JVM stack
    • storage stack frame, local var
    • smaller than heap in general
    • NOT shared by different threads. used by local thread only
  • JVM heap
    • storage class
    • shared by all threads in JVM
  • Ref

3) Explain JVM GC ? GC strategy ? algorithm ?

  • 5W1H

    • Where ?
      • JVM heap
    • Why ?
      • prevent memory leakage. in order to use memory efficiently
    • What ?
      • GC “recycle” object which NOT used anymore
    • When ?
      • Reference counting : remove when “reference count = 0”. But NOT working when “cyclic reference”
      • Tracing : tranverse (“dependence tree”) from GC root, if not in visited list, means not used, then remove them
      • Escape analysis
    • HOW ? (GC remove algorithm)
      • Mark-Sweep

        • mark the to-clean area
        • pros:
          • easy understand, implement
        • cons:
          • low efficiency
          • will cause “space fragments” -> hard to maintain the “continuous storage space”
      • Mark-Compact

        • mark the to-clean area, merge/move them altogether, then clean
        • pros:
          • can keep “continuous storage space”
        • cons:
          • spend extra time/resource on “merge/move” op
      • Mark-Copy

        • split memory space to 50%, 50%. Only use 50% each time, move “to-clean instance” to the other 50% when clean
        • pros:
          • fast, easy to implement, not cause “space fragments”
        • cons:
          • Only 50% of memory space can be used everytime
          • will cause more frequent GC
      • Generation collection

        • implement above algorithm to young, old generation seperately
        • after Java 1.3
        • mechanisms:
          • step 1) new instances storaged in Young Generation, when it’s full, will trigger minor GC
          • step 2) move survived instances to FromSpace (survivor 0).
          • step 3) when FromSpace full, trigger minor GC
          • step 4) move survived instances to ToSpace (survivor 1).
          • step 5) move still-survived instances to Old Generation
        • Young Generation
          • (Eden:FromSpace:ToSpace = 8:1:1 by default)
          • “minor GC”
          • Eden : storage “new” instances
          • Survivor
            • FromSpace (Survivor0)
            • ToSpace (Survivor1) :
              • continuous memory
        • Old Generation
          • Old Space : storage “long life cycle” instances
          • “major GC”
        • permanent generation
          • AKA “method area”. (after Java 8, this space moved to “MetaSpace”, not use JVM memory anymore, but local memory)
          • storage class, string…
          • there is also GC here. “major GC”
  • properties:

    • GC process is a local priority, independent thread
    • JVM GC is an automatic mechanism. we can also manually trigger it : System.gc(); (but NOT recommended)
  • Ref

3’) Explain GC’s ”stop-the-world” ?

3’') Explain type of GC collector ?

  • Serial collector
    • will cause “stop-the-world”
    • only ONE thread
  • Parallel collector
    • will cause “stop-the-world”
    • can have MUTI thread
  • Parallel Old collector
  • Parnew collector
  • CMS collector
  • G1 collector
  • Ref

4) how to get memory in java program, heap usage percentage (%) ?

  • java.lang.Runtime : get remaining memory, all memory, max heap memory
  • Runtime.freeMemory() : get remain memory in binary
  • Runtime.totalMemory(): get total memory in binary
  • Runtime.maxMemory() : get max memory in binary

5) Explain classLoader ?

6) Explain memory leakage ?

7) does memory leakage happen in java ? how ?

8) Difference between Serial and Parallel GC ?

9) Thread, progress, program ?

10) Explain JVM reflection ? dynamic proxy ?

11) Explain JVM instance creation steps ?

12) Explain JVM instance life cycle ?

13) Explain JVM instance structure ?

14) Common JVM command ?

  • jps
    • JVM Process Status Tool, show all system’s hotspot threads in JVM
  • jstat
    • JVM statistics Monitoring. Monitor JVM running status, can show class loading, inner memory GC, JIT
  • jmap
    • JVM Memory Map. For creating heap dump doc
  • jhat
    • JVM Heap Analysis. Use with jmap. analyze jmap’s dump output. there is a HTTP/HTML server in jhat, can view view browser
  • jstack
    • Create current JVM thread shanshot
  • jinfo
    • JVM Configuration Info. Check/modify JVM running parameters in real-time

15) Common JVM tune command ?

  • jconsole
    • Java Monitoring and Management Console
    • java default too, for memory, thread, GC monitoring
  • jvisualvm
    • JDK default too, can record memory/thread/ snapshot, monitor GC
  • MAT
    • Memory Analyzer Tool
    • analyze JVM heap usage, can find memory leakage, usage
  • GChisto
    • analyze GC log tool

16) Common JVM tune parameter ?

  • Xms : min of java heap
  • Xmx : max of java heap
  • -XX:NewSize : new generation size
  • XX:NewRatio : new generation pct VS old generation pct
  • XX:SurvivorRatio : Eden pct VS survivor pct

17) What’s int length in 64 bit JVM ?

  • Not relative to platform. Int length is a fixed value. It's always 34 bit

18) Difference between WeakReference and SoftReference and PhantomReference ?

19) Explain -XX:+UseCompressedOops ?

20) What’s max heap storage in 32 bit JVM and 64 bit JVM ?

  • theoretically
    • 32 bit : 2**32 max heap storage
    • 64 bit : 2**64 max heap storage

21) Difference between JRE, JDK and JIT ?

  • JRE : java run-time
  • JDK : java development kit : java dev tool. JRE is included in it
  • JIT : java in time compilation

Ref