Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Oracle Code One 2018 Debrief Session - New (J)VMs and New GC Algorithms

343 views

Published on

2018/11/24 Oracle Code One 2018 Debrief Session - New (J)VMs and New GC Algorithms at KanJava JUG Event

JVMは今まで以上の速さで進化しています。今後は、Javaのライセンスモデル変更によるベンダの選択だけでなく、より多くなったGCアルゴリズムの選択に加え、JVM自体の選択まで考える必要があります。

このセッションでは、新GCアルゴリズムとしてShenandoahとZGCの概要と、一般的なHotSpot VMとは別のJVMとしてGraalVMを紹介します。GraalVMでは、Polyglotの説明やデモ、GraalVMをリレーショナルデータベースに組み込み、SQLで他言語を呼び出すデモを実施します。

Published in: Technology
  • Be the first to comment

Oracle Code One 2018 Debrief Session - New (J)VMs and New GC Algorithms

  1. 1. New (J)VMs and New GC Algorithms Oracle Code One 2018 Debrief Session KanJava JUG Leader Koichi Sakata #kanjava
  2. 2. About Me • Koichi Sakata (阪田 浩一) • KanJava JUG Leader/Founder • • Twitter: @jyukutyo • Sever Side Engineer at PONOS –Mobile Game Backend
  3. 3. JVM is still progressing, even faster than before
  4. 4. Agenda • Garbage Collector – Shenandoah GC – ZGC • (J)VM – GraalVM
  5. 5. Garbage Collector
  6. 6. Technical Words In GC • Parallel • Concurrent GC Thread GC Thread Application Thread Application Thread
  7. 7. Technical Words In GC • STW: Stop the World – Stop the application while garbage collection
  8. 8. Shenandoah GC: The Next Generation [DEV5561]
  9. 9. Shenandoah GC
  10. 10. Shenandoah GC • Pronunciation: シェナンドー(ア) • Regionalized GC –Not generational (No young/old separation) • Led by Red Hat • Now developing ver. 2.0 • Available on RHEL/Fedora
  11. 11. 10 Shenandoah! ● Aims to reduce GC pause times ● Goal: <10ms pauses for >100GB heaps ● More precisely: ● Make GC pauses independent of heap size ● Long-term goal: pauseless GC https://archive.fosdem.org/2016/schedule/event/shenandoah2016/attachments/slides/126 8/export/events/attachments/shenandoah2016/slides/1268/Shenandoah2016.pdf
  12. 12. 23 Mixed Concurrent Mark G1 Young Young Shenandoah 2.0: Now That We’ve Gotten the GC Pause Times Under Control, What’s Next?
  13. 13. 76 Init Mark Final Mark Concurrent Partial Shenandoah 2.0 Concurrent Evacuation Concurrent Mark Init Partial Final Partial Shenandoah 2.0: Now That We’ve Gotten the GC Pause Times Under Control, What’s Next?
  14. 14. Shenandoah GC: The Next Generation [DEV5561]
  15. 15. Concurrent Update is hard
  16. 16. Shenandoah GC: The Next Generation [DEV5561]
  17. 17. Shenandoah GC: The Next Generation [DEV5561]
  18. 18. Shenandoah GC: The Next Generation [DEV5561]
  19. 19. Shenandoah GC: The Next Generation [DEV5561]
  20. 20. Shenandoah GC: The Next Generation [DEV5561]
  21. 21. Shenandoah GC: The Next Generation [DEV5561]
  22. 22. Needs Barriers • When objects are in target region – Write Barriers • Creates copy – Read Barriers • Dereferences via the forwarding pointer
  23. 23. Cost • Extra cost for forwarding pointer? – Yes, but... • In return, no need for Card Table and Remembered Set • Can optimize reading forwarding pointer with JIT compile – Cost is moderate
  24. 24. ZGC
  25. 25. ZGC • Pronunciation: ズィージーシー • Regionalized GC –Not generational (No young/old separation) • Led by Oracle • Experimental in Java 11 • Linux/x86_64 only
  26. 26. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | Goals Multi-terabyte heaps Max GC pause time Easy to tune Max application throughput reduction 10msTB 15% 7 ZGC: A Scalable Low-Latency Garbage Collector [DEV6028]
  27. 27. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | ZGC pause times do not increase with the heap or live-set size 9 ZGC: A Scalable Low-Latency Garbage Collector [DEV6028]
  28. 28. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | Heap Regions • Dynamically created/destroyed • Dynamically sized – Multiple of 2MB on x86_64 • Size groups – Small (2MB) – Medium (32MB) – Large (N x 2MB) Also known as ZPages 27 ZGC - Low Latency GC for OpenJDK
  29. 29. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | ZGC Phases Concurrent Mark Pause Mark End Pause Relocate StartPause Mark Start Concurrent Prepare for Reloc. Concurrent Relocate Concurrent Remap 22 GC Cycle ZGC - Low Latency GC for OpenJDK
  30. 30. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | ZGC Phases Concurrent Mark Pause Mark End Pause Relocate StartPause Mark Start Concurrent Prepare for Reloc. Concurrent Relocate Concurrent Remap GC Cycle 23 Walks object graph ZGC - Low Latency GC for OpenJDK
  31. 31. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | ZGC Phases Concurrent Remap Concurrent Mark Mark End Relocate StartMark Start Prepare for Reloc Concurrent Reloc Concurrent Remap Concurrent Mark Concurrent Mark Mark End Relocate StartMark Start Prepare for Reloc Concurrent Reloc Mark End Relocate StartMark Start Prepare for Reloc Concurrent Reloc Concurrent Remap GC Cycle 1 GC Cycle 2 GC Cycle 3 25 ZGC - Low Latency GC for OpenJDK
  32. 32. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | GC Cycle Example Roots ..... 1 2 4 85 3 6 7 55 ZGC - Low Latency GC for OpenJDK
  33. 33. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | Pause Mark Start Roots ..... 1 2 4 85 3 6 7 Marked 56 ZGC - Low Latency GC for OpenJDK
  34. 34. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | Pause Mark Start Roots ..... 1 2 4 85 3 6 7 Marked 57 ZGC - Low Latency GC for OpenJDK
  35. 35. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | Pause Mark Start Roots ..... 1 2 4 85 3 6 7 Marked 58 ZGC - Low Latency GC for OpenJDK
  36. 36. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | Pause Mark Start Roots ..... 1 2 4 85 3 6 7 Marked 59 ZGC - Low Latency GC for OpenJDK
  37. 37. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | Concurrent Mark Roots ..... 1 2 4 85 3 6 7 Marked 61 ZGC - Low Latency GC for OpenJDK
  38. 38. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | Concurrent Mark Roots ..... 1 2 4 85 3 6 7 Marked 62 ZGC - Low Latency GC for OpenJDK
  39. 39. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | Pause Mark End Roots ..... 1 2 4 85 3 6 7 Marked 64 ZGC - Low Latency GC for OpenJDK
  40. 40. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | Concurrent Prepare for Relocate Roots ..... 1 2 4 85 3 6 7 Relocation Set Marked 65 ZGC - Low Latency GC for OpenJDK
  41. 41. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | Concurrent Prepare for Relocate Roots ..... 1 2 4 85 3 6 7 Marked 66 Forwarding Tables ZGC - Low Latency GC for OpenJDK
  42. 42. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | Pause Relocate Start Roots ..... 1 2 4 85 3 6 7 Marked Remapped + Relocated 67 ZGC - Low Latency GC for OpenJDK
  43. 43. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | Pause Relocate Start Roots ..... 1 2 4 85 3 6 7 Marked Remapped + Relocated 68 ZGC - Low Latency GC for OpenJDK
  44. 44. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | Pause Relocate Start Roots ..... 1 2 4 85 3 6 7 Marked Remapped + Relocated 69 ZGC - Low Latency GC for OpenJDK
  45. 45. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | Pause Relocate Start Roots ..... 1 2 4 85 3 6 7 4 4 -> 4’ Marked Remapped + Relocated 70 ZGC - Low Latency GC for OpenJDK
  46. 46. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | Concurrent Relocate Roots ..... 1 2 4 85 3 6 7 4 4 -> 4’ 5 -> 5’ 5 Marked Remapped + Relocated 72 ZGC - Low Latency GC for OpenJDK
  47. 47. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | Concurrent Relocate Roots ..... 1 2 8 6 7 4 4 -> 4’ 5 -> 5’ 5 Marked Remapped + Relocated 73 Heap Region Becomes Reusable ZGC - Low Latency GC for OpenJDK
  48. 48. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | Concurrent Relocate Roots ..... 1 2 8 6 7 4 4 -> 4’ 5 -> 5’ 5 Marked Remapped + Relocated 74 8 -> 8’ 8 ZGC - Low Latency GC for OpenJDK
  49. 49. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | Concurrent Relocate Roots ..... 1 2 4 4 -> 4’ 5 -> 5’ 8 -> 8’ 5 8 Marked Remapped + Relocated 75 Heap Region Becomes Reusable ZGC - Low Latency GC for OpenJDK
  50. 50. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | GC Cycle Completed Roots ..... 1 2 4 4 -> 4’ 5 -> 5’ 8 -> 8’ 5 8 Marked Remapped + Relocated 76 ZGC - Low Latency GC for OpenJDK
  51. 51. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | GC Cycle Completed Roots ..... 1 2 4 4 -> 4’ 5 -> 5’ 8 -> 8’ 5 8 Marked Remapped + Relocated 77 Java Thread Loads Pointer ZGC - Low Latency GC for OpenJDK
  52. 52. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | GC Cycle Completed Roots ..... 1 2 4 4 -> 4’ 5 -> 5’ 8 -> 8’ 5 8 Marked Remapped + Relocated 78 Java Thread Loads Pointer ZGC - Low Latency GC for OpenJDK
  53. 53. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | Pause Mark Start (Second Cycle) Roots ..... 1 2 4 4 -> 4’ 5 -> 5’ 8 -> 8’ 5 8 Marked Remapped + Relocated Remapped + Marked 79 ZGC - Low Latency GC for OpenJDK
  54. 54. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | Pause Mark Start (Second Cycle) Roots ..... 1 2 4 4 -> 4’ 5 -> 5’ 8 -> 8’ 5 8 Marked Remapped + Relocated Remapped + Marked 80 ZGC - Low Latency GC for OpenJDK
  55. 55. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | Pause Mark Start (Second Cycle) Roots ..... 1 2 4 4 -> 4’ 5 -> 5’ 8 -> 8’ 5 8 Marked Remapped + Relocated Remapped + Marked 81 ZGC - Low Latency GC for OpenJDK
  56. 56. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | Pause Mark Start (Second Cycle) Roots ..... 1 2 4 4 -> 4’ 5 -> 5’ 8 -> 8’ 5 8 Marked Remapped + Relocated Remapped + Marked 82 ZGC - Low Latency GC for OpenJDK
  57. 57. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | Concurrent Mark (Second Cycle) Roots ..... 1 2 4 4 -> 4’ 5 -> 5’ 8 -> 8’ 5 8 Marked Remapped + Relocated Remapped + Marked 84 ZGC - Low Latency GC for OpenJDK
  58. 58. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | Concurrent Mark (Second Cycle) Roots ..... 1 2 4 4 -> 4’ 5 -> 5’ 8 -> 8’ 5 8 Marked Remapped + Relocated Remapped + Marked 85 ZGC - Low Latency GC for OpenJDK
  59. 59. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | Concurrent Mark (Second Cycle) Roots ..... 1 2 4 4 -> 4’ 5 -> 5’ 8 -> 8’ 5 8 Marked Remapped + Relocated Remapped + Marked 86 ZGC - Low Latency GC for OpenJDK
  60. 60. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | Concurrent Prepare for Relocate (Second Cycle) Roots ..... 1 2 4 5 8 Marked Remapped + Relocated Remapped + Marked Forwarding Tables Freed 88 ZGC - Low Latency GC for OpenJDK
  61. 61. How to manage the state?
  62. 62. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | Colored Pointers • Core design concept in ZGC • Metadata stored in unused bits in 64-bit pointers – No support for 32-bit platforms – No support for CompressedOops 25 Object Address (42 bits, 4TB address space) 64-bit Object Pointer Unused (18 bits) Colors ZGC: A Scalable Low-Latency Garbage Collector [DEV6028]
  63. 63. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | Colored Pointers Layout on x86_64 30 Object Address (42 bits, 4TB address space) 64-bit Object Pointer Unused (18 bits) Marked0 Marked1Remapped Finalizable Known to be marked? ZGC - Low Latency GC for OpenJDK
  64. 64. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | Colored Pointers Layout on x86_64 31 Object Address (42 bits, 4TB address space) 64-bit Object Pointer Unused (18 bits) Marked0 Marked1Remapped Finalizable Known to not point into the relocation set? ZGC - Low Latency GC for OpenJDK
  65. 65. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | Colored Pointers Layout on x86_64 32 Object Address (42 bits, 4TB address space) 64-bit Object Pointer Unused (18 bits) Marked0 Marked1Remapped Finalizable Only reachable through a Finalizer? ZGC - Low Latency GC for OpenJDK
  66. 66. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | Relocation • Concurrent & Parallel • Load barrier – Detects loads of object pointers pointing into the relocation set – Java threads help out with relocation if needed • Off-heap forwarding tables – No forwarding information stored in old copies of objects – Important for immediate reuse of heap memory 54 ZGC - Low Latency GC for OpenJDK
  67. 67. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | Load Barrier • A small piece of code injected by the JIT in strategic places – When loading an object reference from the heap • Checks if the loaded object reference has a bad color – If so, take action and correct it 26 ZGC: A Scalable Low-Latency Garbage Collector [DEV6028]
  68. 68. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | Load Barrier String n = person.name; // Loading an object reference from heap <load barrier needed here> String p = n; // No barrier, not a load from heap n.isEmpty(); // No barrier, not a load from heap int age = person.age; // No barrier, not an object reference 29 String name; int age; double height; ... Person String ZGC: A Scalable Low-Latency Garbage Collector [DEV6028]
  69. 69. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | Load Barrier String n = person.name; // Loading an object reference from heap if (n & bad_bit_mask) { slow_path(register_for(n), address_of(person.name)); } 31 String name; int age; double height; ... Person String ZGC: A Scalable Low-Latency Garbage Collector [DEV6028] Bad Color?
  70. 70. Shenandoah GC: The Next Generation [DEV5561]
  71. 71. Shenandoah GC: The Next Generation [DEV5561]
  72. 72. http://www.graalvm.org/
  73. 73. GraalVM = HotSpot VM + α
  74. 74. Custom Part in GraalVM • Graal – JIT Compiler • Truffle – Language Implementation Framework – AST Interpreter • Substrate VM – Runtime Library and Tools for Java AOT Compiled Code
  75. 75. Now working for Windows
  76. 76. Top 10 Things To Do With GraalVM 1. High-performance modern Java 2. Low-footprint, fast- startup Java 3. Combine JavaScript, Java, Ruby, and R 4. Run native languages on the JVM 5. Tools that work across all languages 6. Extend a JVM-based application 7. Extend a native application 8. Java code as a native library 9. Polyglot in the database 10.Create your own language
  77. 77. Top 10 Things To Do With GraalVM 1. High-performance modern Java 2. Low-footprint, fast- startup Java 3. Combine JavaScript, Java, Ruby, and R 4. Run native languages on the JVM 5. Tools that work across all languages 6. Extend a JVM-based application 7. Extend a native application 8. Java code as a native library 9. Polyglot in the database 10.Create your own language Polyglot
  78. 78. Polyglot HotSpot VM JVMCI Graal JVM Lang Truffle LLVMJS R Ruby C C++ Fortran Interpreter
  79. 79. Polyglot on the JVM with Graal
  80. 80. Not only provide high performance for single language
  81. 81. Interoperability
  82. 82. e.g.) Call Ruby code from JavaScript at lower cost
  83. 83. Execute Ruby Code in JavaScript js> var array = Polyglot.eval("ruby", "[1,2,42,4]") js> array[2] 42 [GRAALVM_HOME]/bin/polyglot --shell --jvm https://www.sakatakoichi.com/entry/graalvmpolyglot
  84. 84. Debug on Chrome
  85. 85. 9. Polyglot in the database Top 10 Things To Do With GraalVM
  86. 86. RDBMS embed GraalVM
  87. 87. GraalVM-Embedded Database • Oracle Database – Oracle Multilingual Engine (Oracle MLE) • MySQL – MySQL MLE Plugin •Available shortly from MySQL Labs
  88. 88. GraalVM supports Node.js v10.9.0
  89. 89. e.g.) Call a JavaScript function in a SQL statement
  90. 90. Execute JavaScript Function in SQL SQL> select validator.isEmail('alice@example.com’) from dual; VALIDATOR.ISEMAIL('ALICE@EXAMPLE.COM’) -------------------------------------- 1 SQL> select validator.isEmail('bob@example') from dual; VALIDATOR.ISEMAIL('BOB@EXAMPLE’) -------------------------------- 0 https://www.sakatakoichi.com/entry/graalvmembeddeddb
  91. 91. Call isEmail() function in validator module of Node.js from SQL statement
  92. 92. Deploy Node.js module to RDBMS
  93. 93. Deploy With dbjs Command $ dbjs deploy -uscott -p tiger -c localhost:1521/ORCLCDB validator +validator.js ... ├─┬isEmail │ └──SCALAR FUNCTION VALIDATOR.ISEMAIL("p0" IN VARCHAR2) RETURN NUMBER ...
  94. 94. Ad Hoc Function Is Executable $ echo "export function helloworld() : string { return 'HelloWorld'; }" > helloworld.ts $ dbjs deploy -u scott -p tiger -c localhost:1521/ORCLCDB helloworld.ts + helloworld.js └─┬ helloworld └── SCALAR FUNCTION HELLOWORLD.HELLOWORLD RETURN VARCHAR2
  95. 95. Ad Hoc Function is Executable $sqlplus scott/tiger@localhost:1521/ORCLCDB SQL>select helloworld() fromdual; HELLOWORLD() ---------------------------------------------------- HelloWorld
  96. 96. In RDBMS, only JavaScript is allowed now. Python will be next.
  97. 97. Wrap Up GraalVM is AWESOME!

×