๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

๋ชฉ๋ก์ด ์—†์Šต๋‹ˆ๋‹ค.

[Java] jmap ์‚ฌ์šฉํ•˜์—ฌ JVM ์ƒํƒœ ํ™•์ธ

๐Ÿ—ฃ Language/JAVA

    Java ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ๋ฐฐํฌํ•˜๊ณ  ์„œ๋ฒ„ ์œ ์ง€๋ฅผ ํ•˜๋Š” ๊ฒฝ์šฐ์— JVM์˜ ์ƒํƒœ๋ฅผ ํ™•์ธํ•ด์•ผํ•˜๋Š” ์ƒํ™ฉ์ด ์ข…์ข… ๋ฐœ์ƒํ•œ๋‹ค. ์ด ๋•Œ ๋‹ค๋ฅธ ํ”„๋กœ๊ทธ๋žจ์ด๋‚˜ ํŒจํ‚ค์ง€ ์„ค์น˜ ์—†์ด ๋ฐ”๋กœ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ๊ฐ„๋‹จํ•œ ๋ฐฉ๋ฒ•์ด ๋ฐ”๋กœ jmap์„ ํ™œ์šฉํ•˜์—ฌ ํ™•์ธํ•˜๋Š” ๋ฐฉ๋ฒ•์ด๋‹ค.

    ๋ฐฉ๋ฒ•์€ ์•„๋ž˜์™€ ๊ฐ™์ด ๊ฐ„๋‹จํ•˜๋‹ค. (Java ๋ฒ„์ „๋ณ„๋กœ ์กฐ๊ธˆ ๋‹ค๋ฅผ ์ˆ˜ ์žˆ๋‹ค)

    java 11 ์ด์ „ ๋ฒ„์ „

    $ jmap --heap <pid>

     

    java 11 ํฌํ•จ ์ดํ›„ ๋ฒ„์ „

    $ jhsdb jmap --heap --pid <pid>

    * jhsdb ๊ด€๋ จ ๋ฌธ์„œ๋Š” ์˜ค๋ผํด ๋ฌธ์„œ ์ฐธ์กฐ: https://docs.oracle.com/javase/9/tools/jhsdb.htm#JSWOR-GUID-0345CAEB-71CE-4D71-97FE-AA53A4AB028E

     

    ์‹คํ–‰ ๊ฒฐ๊ณผ (jdk 11 ๋ฒ„์ „ ๊ธฐ์ค€)

    $ jhsdb jmap --heap --pid 37141
    Attaching to process ID 37141, please wait...
    Debugger attached successfully.
    Server compiler detected.
    JVM version is 11.0.17+8-post-Ubuntu-1ubuntu218.04
    
    using thread-local object allocation.
    Garbage-First (G1) GC with 28 thread(s)
    
    Heap Configuration:
       MinHeapFreeRatio         = 40
       MaxHeapFreeRatio         = 70
       MaxHeapSize              = 34359738368 (32768.0MB)
       NewSize                  = 1363144 (1.2999954223632812MB)
       MaxNewSize               = 20602421248 (19648.0MB)
       OldSize                  = 5452592 (5.1999969482421875MB)
       NewRatio                 = 2
       SurvivorRatio            = 8
       MetaspaceSize            = 21807104 (20.796875MB)
       CompressedClassSpaceSize = 1073741824 (1024.0MB)
       MaxMetaspaceSize         = 6442450944 (6144.0MB)
       G1HeapRegionSize         = 16777216 (16.0MB)
    
    Heap Usage:
    G1 Heap:
       regions  = 2048
       capacity = 34359738368 (32768.0MB)
       used     = 13018090760 (12415.01880645752MB)
       free     = 21341647608 (20352.98119354248MB)
       37.88763063494116% used
    G1 Young Generation:
    Eden Space:
       regions  = 758
       capacity = 21424504832 (20432.0MB)
       used     = 12717129728 (12128.0MB)
       free     = 8707375104 (8304.0MB)
       59.357870007830854% used
    Survivor Space:
       regions  = 13
       capacity = 218103808 (208.0MB)
       used     = 218103808 (208.0MB)
       free     = 0 (0.0MB)
       100.0% used
    G1 Old Generation:
       regions  = 6
       capacity = 12717129728 (12128.0MB)
       used     = 82857224 (79.01880645751953MB)
       free     = 12634272504 (12048.98119354248MB)
       0.6515402907117376% used

     

    ์‹คํ–‰ ์‹œ ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•˜๋Š” ๊ฒฝ์šฐ 

    sun.jvm.hotspot.types.WrongTypeException: No suitable match for type of address 0x0000000...

    openjdk ์‚ฌ์šฉ ์‹œ ์œ„์™€ ๊ฐ™์€ ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•˜๋Š” ๊ฒฝ์šฐ openjdk-debuginfo ํŒจํ‚ค์ง€๋ฅผ ์„ค์น˜ํ•ด์ฃผ์–ด์•ผ ํ•œ๋‹ค.

    openjdk-11-jdk ๊ธฐ์ค€ ๋””๋ฒ„๊ทธ ํŒจํ‚ค์ง€๋ช…์€ openjdk-11-dbg ์ด๋‹ค

     

    jdk ๋””๋ฒ„๊ทธ ํŒจํ‚ค์ง€ ์„ค์น˜ ๋ช…๋ น์–ด

    $ sudo apt install openjdk-11-dbg -y

     

    ์ฃผ๊ธฐ์ ์œผ๋กœ ํ™•์ธํ•ด์„œ Old generation์˜ ์‚ฌ์šฉ๋Ÿ‰์ด ์ฆ๊ฐ€ํ•˜๋Š”์ง€ ํ™•์ธ๋„ ํ•ด๋ณด๊ณ 

    Tomcat ๊ฐ™์ด ๋Œ€ํ‘œ์ ์ธ Java ์•ฑ์—์„œ ์‹คํ–‰ํ–ˆ์„ ๋•Œ ์˜ต์…˜์ด ์ •์ƒ์ ์œผ๋กœ ์ ์šฉ๋˜๋Š”์ง€ ํ™•์ธ๋„ ํ•ด๋ณผ ์ˆ˜ ์žˆ๋‹ค.

    ๋งŒ์•ฝ Old generation์„ ์ฃผ๊ธฐ์ ์œผ๋กœ ํ™•์ธํ–ˆ์„ ๋•Œ ๊ณ„์† ์ฆ๊ฐ€ํ•˜๋Š” ํ˜„์ƒ์„ ๋ณด์ธ๋‹ค๋ฉด ๋ฉ”๋ชจ๋ฆฌ ๋ˆ„์ˆ˜๋ฅผ ์˜์‹ฌํ•ด๋ณด๊ณ  heap dump๋ฅผ ํŒŒ์ผ๋กœ ๋–จ๊ถˆ ๋ถ„์„ํ•ด์„œ ์กฐ์น˜ํ•  ์ˆ˜๋„ ์žˆ๋‹ค.

    ๋‚˜์ค‘์— heap dump๋ฅผ ์–ด๋–ป๊ฒŒ ๋ถ„์„ํ•  ์ˆ˜ ์žˆ๋Š”์ง€๋„ ์ •๋ฆฌํ•ด์•ผ๊ฒ ๋‹ค.

     

     

    ์ฐธ๊ณ 

    https://ktko.tistory.com/entry/JAVA-%EB%98%90%EB%8A%94-Tomcat-JVM-Heap-%EC%83%81%ED%83%9C-%ED%99%95%EC%9D%B8%ED%95%98%EA%B8%B0

    https://lilo.tistory.com/88

    https://stackoverflow.com/questions/55525449/how-to-read-heap-status-with-jdk-11

    https://tonaconsulting.wordpress.com/2013/10/21/jmap-jstack-not-working-properly-with-openjdk/

    https://hbase.tistory.com/180

    https://soft.plusblog.co.kr/51