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.

Valhalla Update JJUG CCC Spring 2019

422 views

Published on

Update on Project Valhalla delivered during the Japan Java User's Group Cross Community Conference Spring 2019 Keynote. After a very brief review of Project Valhalla and its goals, we cover nest-based access control (JEP 181, new in JDK 11) and an overview of the currently available value type prototypes (MVT and LW1).

Published in: Software
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (Unlimited) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... Download Full EPUB Ebook here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... ACCESS WEBSITE for All Ebooks ......................................................................................................................... Download Full PDF EBOOK here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... Download EPUB Ebook here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... Download doc Ebook here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (Unlimited) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... Download Full EPUB Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... ACCESS WEBSITE for All Ebooks ......................................................................................................................... Download Full PDF EBOOK here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... Download EPUB Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... Download doc Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (Unlimited) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... Download Full EPUB Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... ACCESS WEBSITE for All Ebooks ......................................................................................................................... Download Full PDF EBOOK here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... Download EPUB Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... Download doc Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (Unlimited) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... Download Full EPUB Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... ACCESS WEBSITE for All Ebooks ......................................................................................................................... Download Full PDF EBOOK here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... Download EPUB Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... Download doc Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (Unlimited) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... Download Full EPUB Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... ACCESS WEBSITE for All Ebooks ......................................................................................................................... Download Full PDF EBOOK here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... Download EPUB Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... Download doc Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Be the first to like this

Valhalla Update JJUG CCC Spring 2019

  1. 1. Valhalla Update JJUG CCC 2019/05/18 David Buck Principal Member of Technical Staff Java Platform Group Oracle
  2. 2. • JVM Sustaining Engineer • OpenJDK Update Project Maintainer • JavaOne Rock Star • Co-author of Oracle WebLogic Server 11g 構築・運用ガイド • @DavidBuckJP • https://blogs.oracle.com/buc k/ Who am I? バック デイビッド(左)
  3. 3. Safe Harbor Statement The following is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, and timing of any features or functionality described for Oracle’s products remains at the sole discretion of Oracle.
  4. 4. アジェンダ • Valhalla プロジェクトの概要 • Nestmates • Value Types のプロトタイプ • MVT • L-World
  5. 5. Valhalla プロジェクトの概要
  6. 6. Project Valhalla Emil Doepler - Doepler, Emil. ca. 1905. Walhall, die Götterwelt der Germanen. Martin Oldenbourg, Berlin. Photographed by Haukurth cropped by Bloodofox, Public Domain
  7. 7. Project Valhalla Valhalla == VALue types
  8. 8. Project Valhalla • Value Types (値型) • Generic Specialization (ジェネリックの特殊化) • VarHandles (JDK 9 でリリースされた)
  9. 9. Value Types (値型) オブジェクト プリミティブ String Integer int float
  10. 10. 従来のレイアウト final class Point { final int x; final int y; } headerPoint[] pts = header x y header x y header x y header x y header x y
  11. 11. 望ましいレイアウト headerheader x y x y x y x y Point[] pts = value class Point { int x; int y; }
  12. 12. Value Types (値型) オブジェクト プリミティブ String Integer int float
  13. 13. Value Types (値型) オブジェクト プリミティブ String Integer int float Value Types
  14. 14. Nestmates
  15. 15. Project Valhalla • Value Types (値型) • Generic Specialization (ジェネリックの特殊化) • VarHandles (JDK 9 でリリースされた) • Nestmates (JDK 11 でリリースされた)
  16. 16. Nested とは
  17. 17. Nested とは
  18. 18. Nested とは Class A
  19. 19. Nested とは Class A Class B
  20. 20. class A { class B {} }
  21. 21. $ javac A.java $ ls A$B.class A.class A.java
  22. 22. $ javac A.java $ ls A$B.class A.class A.java
  23. 23. Java ソースの観点 Class A Class B
  24. 24. JVM の観点 Class A Class A$B
  25. 25. 二仕様物語
  26. 26. private int num; num = 42;
  27. 27. private int num; num = 42;
  28. 28. class A { private int num; class B { void doIt() { num = 42; } } }
  29. 29. num = 42; private int num;
  30. 30. Access Modifiers • public • protected • (default) • private
  31. 31. Access Modifiers • public • protected • (default) • private
  32. 32. Access Modifiers • public • protected • (default) • private
  33. 33. Access Modifiers • public • protected • (default) package • private
  34. 34. Access Modifiers • public • protected • (default) package • private
  35. 35. Access Modifiers Modifier クラス パッケージ サブクラス その他 public ○ ○ ○ ○ protected ○ ○ ○ × (default) ○ ○ × × private ○ × × ×
  36. 36. Access Modifiers • public • protected • (default) • private
  37. 37. Access Modifiers • public • protected • (default) • private
  38. 38. Access Modifiers • public • protected • (default) • private
  39. 39. Access Modifiers • public • protected • (default) • private
  40. 40. public class Outer { private void outerMethod() { System.out.println("Outer.outerMethod() called!"); } class Inner { void innerMethod() { new Outer().outerMethod(); } } public static void main(String[] args) { Outer o = new Outer(); Inner i = o.new Inner(); i.innerMethod(); } }
  41. 41. outerMethod() {…} innerMethod() { … obouterMethod(); }
  42. 42. public static void main(String[] args) { Outer o = new Outer(); Inner i = o.new Inner(); i.innerMethod(); }
  43. 43. public static void main(String[] args) { Outer o = new Outer(); Inner i = o.new Inner(); i.innerMethod(); }
  44. 44. public class Outer { private void outerMethod() { System.out.println("Outer.outerMethod() called!"); } class Inner { void innerMethod() { new Outer().outerMethod(); } } public static void main(String[] args) { Outer o = new Outer(); Inner i = o.new Inner(); i.innerMethod(); } }
  45. 45. javap • Class ファイルをテキスト形式でダンプする • 逆汗 • Java の objdump のようなもの。。。
  46. 46. javap • -p private のメンバーも出力 • -v verbose (逆汗も含む)
  47. 47. static void access$000(nestdemo.Outer); descriptor: (Lnestdemo/Outer;)V flags: ACC_STATIC, ACC_SYNTHETIC Code: stack=1, locals=1, args_size=1 0: aload_0 1: invokespecial #1 // Method outerMethod:()V 4: return LineNumberTable: line 3: 0
  48. 48. static void access$000(nestdemo.Outer); descriptor: (Lnestdemo/Outer;)V flags: ACC_STATIC, ACC_SYNTHETIC Code: stack=1, locals=1, args_size=1 0: aload_0 1: invokespecial #1 // Method outerMethod:()V 4: return LineNumberTable: line 3: 0
  49. 49. static void access$000(nestdemo.Outer); descriptor: (Lnestdemo/Outer;)V flags: ACC_STATIC, ACC_SYNTHETIC Code: stack=1, locals=1, args_size=1 0: aload_0 1: invokespecial #1 // Method outerMethod:()V 4: return LineNumberTable: line 3: 0
  50. 50. Bridge Methods Rich Niewiroski Jr. [CC BY 2.5 (https://creativecommons.org/licenses/by/2.5)]
  51. 51. Bridge Methods • 内部クラスの private メンバのアクセス • 共変戻り • ジェネリクスの型消去 (type erasure)
  52. 52. private outerMethod() {…} access$000(nestdemo.Outer o) { o.outerMethod(); } innerMethod() { access$000(this); }
  53. 53. 問題は?
  54. 54. private void outerMethod() { System.out.println("Outer.outerMethod() called!"); Thread.dumpStack(); }
  55. 55. private void outerMethod() { System.out.println("Outer.outerMethod() called!"); Thread.dumpStack(); }
  56. 56. $ java nestdemo.Outer Outer.outerMethod() called! java.lang.Exception: Stack trace at java.lang.Thread.dumpStack(Thread.java:1336) at nestdemo.Outer.outerMethod(Outer.java:7) at nestdemo.Outer.access$000(Outer.java:3) at nestdemo.Outer$Inner.innerMethod(Outer.java:13) at nestdemo.Outer.main(Outer.java:20)
  57. 57. $ java nestdemo.Outer Outer.outerMethod() called! java.lang.Exception: Stack trace at java.lang.Thread.dumpStack(Thread.java:1336) at nestdemo.Outer.outerMethod(Outer.java:7) at nestdemo.Outer.access$000(Outer.java:3) at nestdemo.Outer$Inner.innerMethod(Outer.java:13) at nestdemo.Outer.main(Outer.java:20)
  58. 58. $ cat -n nestdemo/Outer.java 1 package nestdemo; 2 3 public class Outer { 4 5 private void outerMethod() { 6 System.out.println("Outer.outerMethod() called!"); 7 Thread.dumpStack(); 8 }
  59. 59. (default) != private
  60. 60. static void access$000(nestdemo.Outer); descriptor: (Lnestdemo/Outer;)V flags: ACC_STATIC, ACC_SYNTHETIC Code: stack=1, locals=1, args_size=1 0: aload_0 1: invokespecial #1 // Method outerMethod:()V 4: return LineNumberTable: line 3: 0
  61. 61. static void access$000(nestdemo.Outer); descriptor: (Lnestdemo/Outer;)V flags: ACC_STATIC, ACC_SYNTHETIC Code: stack=1, locals=1, args_size=1 0: aload_0 1: invokespecial #1 // Method outerMethod:()V 4: return LineNumberTable: line 3: 0
  62. 62. Asmtools の jasm super public class AClassFile version 100:10 { public Method "<init>":"()V" stack 1 locals 1 { aload_0; invokespecial Method java/lang/Object."<init>":"()V"; return; } } 001000110111010011100100011010101 111101110100100001011010010100110 011011100010100001110100000100010 110000011100100101101011000111100 101101001000001010101110111110010 100011110100010010000011011101001 100100010010011010010000101001000 100101000001000010110101100110100 100001101100111110110111101001101 011100001001000010100111000100111 110101110111101001111000101010100 101101001010110101110001110011010 011001101011001100010010010100101 AClassFile.jasm AClassFile.class
  63. 63. BadBoy.jasm package nestdemo; public class BadBoy { public static Method main:"([Ljava/lang/String;)V" stack 99 locals 1 { getstatic Field java/lang/System.out:"Ljava/io/PrintStream;"; ldc String "Hi!"; invokevirtual Method java/io/PrintStream.println:"(Ljava/lang/String;)V"; new class nestdemo/Outer; dup; invokenonvirtual Method nestdemo/Outer.<init>:"()V"; invokestatic Method nestdemo/Outer.access$000:"(Lnestdemo/Outer;)V"; return; }
  64. 64. BadBoy.jasm package nestdemo; public class BadBoy { public static Method main:"([Ljava/lang/String;)V" stack 99 locals 1 { getstatic Field java/lang/System.out:"Ljava/io/PrintStream;"; ldc String "Hi!"; invokevirtual Method java/io/PrintStream.println:"(Ljava/lang/String;)V"; new class nestdemo/Outer; dup; invokenonvirtual Method nestdemo/Outer.<init>:"()V"; invokestatic Method nestdemo/Outer.access$000:"(Lnestdemo/Outer;)V"; return; }
  65. 65. $ java -jar asmtools.jar jasm nestdemo/BadBoy.jsm $ java nestdemo.BadBoy Hi! Outer.outerMethod() called! java.lang.Exception: Stack trace at java.lang.Thread.dumpStack(Thread.java:1336) at nestdemo.Outer.outerMethod(Outer.java:7) at nestdemo.Outer.access$000(Outer.java:3) at nestdemo.BadBoy.main(BadBoy.jsm)
  66. 66. Bridge Methods の弱点 • バイトコードとソースは合致しない • アクセス権限が異なる • メモリやディスク領域を消費する
  67. 67. 二仕様物語
  68. 68. Nestmates • JEP 181: Align JVM Checks with Java Language Rules for Nested Classes
  69. 69. Nestmates • JEP 181: Align JVM Checks with Java Language Rules for Nested Classes • JEP 181: Nest-Based Access Control
  70. 70. Nestmates • 新しいクラスの属性 • NestHost • NestMembers • ネスト内のクラスはお互いに private メンバをアクセス出来る
  71. 71. Nestmates • 新しいクラスの属性 • NestHost “Top Level Class” • NestMembers 内部クラス • ネスト内のクラスはお互いに private メンバをアクセス出来る
  72. 72. Nestmates • 新しいクラスの属性 • NestHost “Top Level Class” ★ • NestMembers 内部クラス • ネスト内のクラスはお互いに private メンバをアクセス出来る ★ ソースレベルで他のクラスに含まれていない
  73. 73. public class Three { class Two { class One {} } } Three Two One
  74. 74. NestMembers: Three$Two Three$Two$One Three Two One
  75. 75. NestHost: class Three Three Two One
  76. 76. Three Two One NestHost: class Three
  77. 77. Three Three$Two Three$Two$One
  78. 78. $ jdk-11.0.3/bin/javac nestdemo/Outer.java $ jdk-11.0.3/bin/java nestdemo.Outer Outer.outerMethod() called! java.lang.Exception: Stack trace at java.base/java.lang.Thread.dumpStack(Thread.java:1387) at nestdemo.Outer.outerMethod(Outer.java:7) at nestdemo.Outer$Inner.innerMethod(Outer.java:13) at nestdemo.Outer.main(Outer.java:20)
  79. 79. $ jdk-11.0.3/bin/java nestdemo.BadBoy Hi! Exception in thread "main" java.lang.NoSuchMethodError: nestdemo.Outer.access$000(Lnestdemo/Outer;)V at nestdemo.BadBoy.main(BadBoy.jsm)
  80. 80. Nestmates • クラスファイル形式と JVM の変更だけ • かなり複雑な変更 • 内部クラスの private アクセス以外の利用は検討中 • ジェネリクスの特殊化 • Java 以外の JVM 言語の利用 • クローズド タイプ • Unsafe::defineAnonymoiusClass() の代用 • 興味ある方は是非 JVMLS のセッションを見てください
  81. 81. Value Types のプロトタイプ MVT
  82. 82. Minimal Value Types プロジェクト • 実験 • JVM 側の実装だけ • 普通のユーザに向いていない • Java 言語のサポートなし • メソッドハンドルで操作するしか無かった
  83. 83. Value Capable Class VCC ソース VCC クラス VCC Runtime @jvm.internal.value.ValueCapableClass final class Point { final int x; final int y; }
  84. 84. Value Capable Class の条件 • final (クラス自体) • スーパークラス(直接)が java.lang.Object • すべてのフィルドは final
  85. 85. Derived Value Class VCC ソース VCC クラス VCC Runtime @jvm.internal.value.ValueCapableClass class Point { int x; int y; } DVC Runtime
  86. 86. Derived Value Class • Classfile バージョンは xx.1 • Field のみ • ACC_VALUE フラグ • Q タイプ • メソッドを呼ぶには boxing が必要 (Q -> R) • Boxing しない限りQ タイプと L タイプの互換性はなかった
  87. 87. MVT の新しいバイトコード • vload • vstore • vreturn • vlaload • vastore • vbox • vunbox • vdefault • vwithfield
  88. 88. MVT 実験は終了
  89. 89. MVT から習ったこと • Value Type のパフォーマンス向上 • メモリ使用量の節約
  90. 90. Value Types のプロトタイプ L-World
  91. 91. タイプの種類(構造体) • L-Types: 従来の参照タイプ • Q-Types: 値のみ (Value Type) • R-Types: 新しい参照タイプ • U-Types: R と Q の共用体 (Union)
  92. 92. 検討されたモデルその1 R-World U-Type R-Type Q-Type
  93. 93. 検討されたモデルその2 U-World U-Type L-Type Q-Type
  94. 94. 検討されたモデルその3 L-World L-types 参照 Value Type
  95. 95. L-World へようこそ!
  96. 96. L-World の魅力 • Boxing は不要 • インタフェース対応(デフォルトメソッドも!) • java.lang.Object のメソッド(一部)も使える • equals() • hashCode() • toString()
  97. 97. L-World の Value Type • ACC_VALUE_TYPE クラスフラグ • クラスと field は final • <init> なし • Monitor 系のメソッドは利用不可 • j.l.O is direct super class • Clonable は利用不可 • Enum は対象外 • ValueTypes 属性
  98. 98. ACC_FLATTENABLE • タイプではなくて、フィールドのフラグ • Value を格納する field • Null の値は禁止 • 再起参照も禁止 • Value Type の配列はデフォルトで Flattenable
  99. 99. L-World の新しいバイトコード • defaultvalue • 新規の値を作成 • withfield • 既存の値をコピーし、一つの field を変更する
  100. 100. 調査中: Null の問題 Point2D pointArray[] = new Point2D[10] Object[] refArray = (Object[]) pointArray; refArray[0].toString(); refArray[0] = null; /ダメ!!!!!!!!!!
  101. 101. Milestones • LW1 • 最低限の Value Types • 既存のコードを使う時はメリットなし • ジェネリクスの特殊化もなし • LW10 • ジェネリクスと Value Type の互換性 (Type Erasure) • メインラインのリリースに含まれる可能性はあり • LW100 • ジェネリクスの特殊化(プリミティブ対応も)
  102. 102. LW1 EA ビルド • 少し古い • 未完成の JDK 11 ベース • 複数の既知問題 • -XX:+EnableValhalla • __ByValue キーワード
  103. 103. L-World の例 __ByValue class Point { int x; int y; }
  104. 104. まとめ • プロジェクト Valhalla は Value Types だけではない • いくつかの(比較的に)小規模サブプロジェクトもある • 進捗はあるけど、Value Types を普通に使えるようになるまで 時間かかりそう
  105. 105. ありがとうございます!

×