JVM入門 -メモリ管理編-

87e6be3b5dcac822e5dfd974ba65045a?s=47 Kinoko
July 18, 2019

JVM入門 -メモリ管理編-

関ジャバ'19 7月度 - connpass https://kanjava.connpass.com/event/134133/
登壇資料

87e6be3b5dcac822e5dfd974ba65045a?s=128

Kinoko

July 18, 2019
Tweet

Transcript

  1. JVMೖ໳
 -ϝϞϦ؅ཧฤ- Abe Asami

  2. ࣗݾ঺հ "CF"TBNJl͖ͷࢠz
 େࡕͷϑϦʔϥϯεϓϩάϥϚ IUUQOPDPOPOFU !BBUI +BWB,PUMJO4DBMBͳͲͳͲ

  3. ࠷ۙ΍͍ͬͯΔ͜ͱ https://www.geekhub.jp/
 ΤϯδχΞಛԽ߹ಉઆ໌ձΠϕϯτɻ࣍ճ 9/14(౔) ։࠵༧ఆ ʮJava11ʹΑΔ
 WebΞϓϦέʔγϣϯ։ൃͰֶͿ
 Javaϓϩάϥϛϯάೖ໳ʯൢചத https://www.udemy.com/java11-springbootweb-java/

  4. ͜ͷςʔϚΛબΜͩཧ༝ • ਖ਼௚JVMͷ͜ͱ͸งғؾͰ͔͠ཧղ͍ͯ͠ͳ ͍ͨΊɺษڧ͔͔ͨͬͨ͠Β • ӡ༻ϑΣʔζʹܞΘΔػձ͕গͳ͘ɺύ ϑΥʔϚϯε΍ϝϞϦपΓͷτϥϒϧૺ۰ ܦݧ͕͋·Γͳ͍ɾɾɾ • ࠓ೔͸ϝϞϦ؅ཧͷ࿩͚ͩͰ͢

  5. ͦ΋ͦ΋JVMͱ͸

  6. Java VM (JavaԾ૝Ϛγϯ) • JavaόΠτίʔυΛ࣮ߦ͢ΔͨΊͷԾ૝؀ڥ • OSґଘΛٵऩͯ͘͠Ε͍ͯΔ

  7. JVMʹ͸छྨ͕͋Δ • HotSpot VM, IBM JVM, JRockit, ͳͲͳͲ

  8. ࠓճ͸HotSpot VMͷ࿩ • Oracle͕ఏڙ͍ͯ͠ΔJVM

  9. ͋ͱࠓճ͸Java8ͷ࿩Ͱ͢ • ͜ͷ͋ͱͷݕূͰ࢖ͬͨͷ͕Java8

  10. JVMͷ࢓૊Έ (ΊͬͪΌͬ͘͟Γ)

  11. ϝϞϦߏ଄

  12. None
  13. None
  14. None
  15. None
  16. None
  17. None
  18. None
  19. None
  20. None
  21. None
  22. None
  23. ࣮ࡍͷϓϩάϥϜͰ GCͷঢ়گΛղੳͯ͠ΈΔ

  24. GCϩά • GCͷॲཧ࣌ؒ΍લޙͷϝϞϦ࢖༻ྔͳͲͷϩ ά

  25. GCViewer • GCϩάͷϏϡʔΞʔ • https://github.com/chewiebug/GCViewer • 2019/07/18 ݱࡏɺJDK11ະରԠ

  26. ͱΓ͋͑ͣɺ ͳΜ͔͠Βಈ͔ͯ͠ GCϩάΛग़ͯ͠ΈΔ

  27. ࢀর͕࢒Βͳ͍ΠϯελϯεΛ
 ͻͨ͢Βੜ੒

  28. ࣮ߦ java -Xloggc:gc.log -XX:+PrintGCDetails -XX:+PrintGCDateStamps Main GCϩάग़ྗͷͨΊͷΦϓγϣϯ (※ඪ४ग़ྗʹग़͚ͩ͢Ͱ͋Ε͹ 
 -verbose:gc

    ͚͚ͩͭΕ͹OK)
  29. ग़ྗ͞Εͨϩά

  30. GCViewerͰ։͍ͯΈΔ

  31. ΦϒδΣΫτ͸·ͣYoungྖҬʹ࡞ΒΕɺ
 ੜ੒͔Β͕࣌ؒܦͭͱOldྖҬʹҠಈ͢Δ

  32. ࠓճ͸OldྖҬ΁ͷҠಈ͕ൃੜ͠ͳ͍ͨΊ
 ώʔϓશମͷ࢖༻ྔ ≒ YoungྖҬͷώʔϓ࢖༻ྔ

  33. GC࣌ʹͪΌΜͱϝϞϦ͕ղ์͞Ε͍ͯΔ

  34. ϚΠφʔGCɾɾɾYoungྖҬͷΈ͕ର৅ YoungྖҬ͕
 ͍ͬͺ͍ʹͳͬͨ
 λΠϛϯάͰ
 ϚΠφʔGC͕
 ࣮ߦ͞Ε͍ͯΔ

  35. ΋͏1ύλʔϯ
 ࢼͯ͠ΈΔ

  36. ࢀর͕࢒ΔΠϯελϯεΛ
 ͻͨ͢Βੜ੒

  37. GCϩά

  38. ͜Ε΋GCViewerͰ։͍ͯΈΔ

  39. None
  40. Full GC (ϝδϟʔGC)ɾɾɾશώʔϓྖҬ͕ର৅

  41. Full GC͸͕͔͔࣌ؒΔ 2019-07-18T07:28:35.759-0900: 53.145: [GC (Allocation Failure) [PSYoungGen: 1153507K->190965K(1768960K)] 1400776K->506242K(2118656K),

    0.3026525 secs] [Times: user=2.55 sys=0.14, real=0.31 secs] 2019-07-18T07:28:36.064-0900: 53.450: [Full GC (Ergonomics) [PSYoungGen: 190965K->190932K(1768960K)] [ParOldGe 315276K->290297K(610816K)] 506242K->481229K(2379776K), [Metaspace: 2676K->2676K(1056768K)], 4.7517463 secs] [Times: user=29.92 sys=0.06, real=4.75 secs] ্ͷϚΠφʔGC ɾɾɾ 0.31 secs
 ԼͷFull GC ɾɾɾ 4.75 secs
  42. GCத͸ΞϓϦέʔγϣϯ
 εϨου͕ࢭ·Δ Stop the World (STW) ͱݺ͹ΕΔ

  43. OutOfMemoryError(OOME) Λൃੜͤͯ͞ΈΔ

  44. ώʔϓͷ࠷େαΠζΛมߋ
 ͯ͠ΈΔ % java -Xms600m -Xmx800m -Xloggc:gc.log -XX:+PrintGCDetails -XX: +PrintGCDateStamps

    Main -Xms ɾɾɾώʔϓͷॳظαΠζ
 -Xmx ɾɾɾώʔϓͷ࠷େαΠζ
  45. ແࣄ(?) OOMEൃੜ

  46. GCϩά

  47. ΋͏ͪΐͬͱৄ͘͠ղੳΛ
 ͯ͠ΈΔ

  48. ώʔϓμϯϓ • ಛఆͷ࣌ࠁʹώʔϓ಺ʹؚ·ΕΔ͢΂ͯͷΦϒ δΣΫτͷεφοϓγϣοτ

  49. OOMEൃੜ࣌ʹώʔϓμϯϓΛ ग़ྗͤͯ͞ΈΔ java -Xms600m -Xmx800m -Xloggc:gc.log -XX:+PrintGCDetails -XX: +PrintGCDateStamps -XX:+HeapDumpOnOutOfMemoryError

    Main -XX:+HeapDumpOnOutOfMemoryError
 ɾɾɾ OOMEൃੜ࣌ʹώʔϓμϯϓΛग़ྗ
  50. The Eclipse Memory Analyzer • Eclipse Memory Analyzer Open Source

    Project | The Eclipse Foundation
 https://www.eclipse.org/mat/ • ώʔϓμϯϓΛ͍͍ײ͡ʹදࣔͯ͘͠ΕΔGUI πʔϧ
  51. ώʔϓμϯϓΛ։͍ͯΈͨ

  52. None
  53. None
  54. ·ͱΊ • ͜͏͍ͬͨJVMͷجຊ΍໰୊ൃੜ࣌ͷղੳํ ๏Λ஌͓ͬͯ͘ͱɺ͍͟ͱ͍͏ͱ͖ʹ߄ͯͳ ͯ͘ศར(ଟ෼)

  55. ͪͳΈʹJava11ͷσʔλ෼ੳʹ͸
 Java Mission ControlΛ࢖͏ͱ͍͍ͦ͏Ͱ͢ • Java Mission Control 
 https://www.oracle.com/technetwork/jp/

    java/javaseproducts/mission-control/ index.html • ༗ঈػೳ͕ͩͬͨɺJava11͔ΒOpenJDKʹ دଃ͞Εͯແঈఏڙͱͳͬͨ
  56. ࢀߟʹͨ͠ϖʔδ • OutOfMemoryError ͷௐ΂ํ - Qiita https://qiita.com/opengl-8080/items/ 64152ee9965441f7667b • Java͸ͲͷΑ͏ʹಈ͘ͷ͔ʙਤղͰΘ͔ΔJVMͷ࢓૊Έɿ࿈ࡌʛgihyo.jp

    … ٕज़ධ࿦ࣾ http://gihyo.jp/dev/serial/01/jvm-arc • ʮϝϞϦʔΛҙࣝͯ͠ΈΑ͏ʯୈ2ճɹGCͷ࢓૊ΈΛཧղ͢Δ | ೔ܦ xTECH ʢΫϩεςοΫʣ https://tech.nikkeibp.co.jp/it/article/COLUMN/ 20060612/240657/?rt=nocnt • ·͡ΊʹJVMνϡʔχϯά: ୈ1ճ ·ͣ͸ݱঢ়֬ೝ https://x1.inkenkun.com/ archives/367
  57. ͝ਗ਼ௌ
 ͋Γ͕ͱ͏͍͟͝·ͨ͠