Slide 1

Slide 1 text

Welcome, Java 15! JJUG Night Seminar #JJUG

Slide 2

Slide 2 text

Who am I? https://logico-jp.io

Slide 3

Slide 3 text

参考資料 blogs.oracle.com/java-platform-group/the-arrival-of-java-15 logico-jp.io/2020/09/16/the-arrival-of-java-15/ logmi.jp/tech/articles/323179 www.slideshare.net/YujiKubota/head-toward-java-14-and-java-15-linedm qiita.com/nowokay/items/2858699bc1cd89222cd8 www.javainthebox.com/2020/09/jepjava-se-15.html

Slide 4

Slide 4 text

Thanks for your watching…

Slide 5

Slide 5 text

Thanks for your watching… It’s too early!

Slide 6

Slide 6 text

Agenda

Slide 7

Slide 7 text

Java 15 (not 1.5)

Slide 8

Slide 8 text

JSR 390 : Java SE 15 cr.openjdk.java.net/~iris/se/15/lat estSpec/apidiffs/overview- summary.html

Slide 9

Slide 9 text

リリースサイクル変更後6回⽬のリリース The 6th release since release cadence was changed Java 8 Java 9 2017/9 2018/3 2018/9 2019/3 2019/9 2020/3 2020/9 2021/3 2021/9 2020/09/15 2021/03/15

Slide 10

Slide 10 text

Contributors blogs.oracle.com/java-platform-group/the-arrival-of-java-15

Slide 11

Slide 11 text

JDK 15までのJEPの個数 – # of JEPs in each release blogs.oracle.com/java-platform-group/the-arrival-of-java-15

Slide 12

Slide 12 text

JDK 15に取り込まれたJEP – JEPs in JDK 15 openjdk.java.net/projects/jdk/15/ 339 Edwards-Curve Digital Signature Algorithm (EdDSA) 360 Sealed Classes (Preview) 371 Hidden Classes 372 Remove the Nashorn JavaScript Engine 373 Reimplement the Legacy DatagramSocket API 374 Disable and Deprecate Biased Locking 375 Pattern Matching for instanceof (Second Preview) 377 ZGC: A Scalable Low-Latency Garbage Collector 378 Text Blocks 379 Shenandoah: A Low-Pause-Time Garbage Collector 381 Remove the Solaris and SPARC Ports 383 Foreign-Memory Access API (Second Incubator) 384 Records (Second Preview) 385 Deprecate RMI Activation for Removal

Slide 13

Slide 13 text

廃⽌や削除 Removed or deprecated 339 Edwards-Curve Digital Signature Algorithm (EdDSA) 360 Sealed Classes (Preview) 371 Hidden Classes 372 Remove the Nashorn JavaScript Engine 373 Reimplement the Legacy DatagramSocket API 374 Disable and Deprecate Biased Locking 375 Pattern Matching for instanceof (Second Preview) 377 ZGC: A Scalable Low-Latency Garbage Collector 378 Text Blocks 379 Shenandoah: A Low-Pause-Time Garbage Collector 381 Remove the Solaris and SPARC Ports 383 Foreign-Memory Access API (Second Incubator) 384 Records (Second Preview) 385 Deprecate RMI Activation for Removal

Slide 14

Slide 14 text

新機能や追加機能 New or additional features 339 Edwards-Curve Digital Signature Algorithm (EdDSA) 360 Sealed Classes (Preview) 371 Hidden Classes 372 Remove the Nashorn JavaScript Engine 373 Reimplement the Legacy DatagramSocket API 374 Disable and Deprecate Biased Locking 375 Pattern Matching for instanceof (Second Preview) 377 ZGC: A Scalable Low-Latency Garbage Collector 378 Text Blocks 379 Shenandoah: A Low-Pause-Time Garbage Collector 381 Remove the Solaris and SPARC Ports 383 Foreign-Memory Access API (Second Incubator) 384 Records (Second Preview) 385 Deprecate RMI Activation for Removal

Slide 15

Slide 15 text

プレビューもしくはインキュベート機能 Preview or incubator projects 339 Edwards-Curve Digital Signature Algorithm (EdDSA) 360 Sealed Classes (Preview) 371 Hidden Classes 372 Remove the Nashorn JavaScript Engine 373 Reimplement the Legacy DatagramSocket API 374 Disable and Deprecate Biased Locking 375 Pattern Matching for instanceof (Second Preview) 377 ZGC: A Scalable Low-Latency Garbage Collector 378 Text Blocks 379 Shenandoah: A Low-Pause-Time Garbage Collector 381 Remove the Solaris and SPARC Ports 383 Foreign-Memory Access API (Second Incubator) 384 Records (Second Preview) 385 Deprecate RMI Activation for Removal

Slide 16

Slide 16 text

JEPs (Java Enhancement Proposal) in Java 15

Slide 17

Slide 17 text

Removed or deprecated

Slide 18

Slide 18 text

廃⽌や削除 Removed or deprecated 339 Edwards-Curve Digital Signature Algorithm (EdDSA) 360 Sealed Classes (Preview) 371 Hidden Classes 372 Remove the Nashorn JavaScript Engine 373 Reimplement the Legacy DatagramSocket API 374 Disable and Deprecate Biased Locking 375 Pattern Matching for instanceof (Second Preview) 377 ZGC: A Scalable Low-Latency Garbage Collector 378 Text Blocks 379 Shenandoah: A Low-Pause-Time Garbage Collector 381 Remove the Solaris and SPARC Ports 383 Foreign-Memory Access API (Second Incubator) 384 Records (Second Preview) 385 Deprecate RMI Activation for Removal

Slide 19

Slide 19 text

Remove the Nashorn JavaScript Engine medium.com/graalvm/nashorn-removal-graalvm-to-the-rescue-d4da3605b6cb logico-jp.io/2020/03/24/nashorn-removal-graalvm-to-the-rescue/

Slide 20

Slide 20 text

Disable and Deprecate Biased Locking ž Java 15 からは biased locking をデフォルトで無効

Slide 21

Slide 21 text

Biased Locking ž ロック実装は2種類

Slide 22

Slide 22 text

なぜデフォルトのロック実装になった? Why biased locking was chosen at that time?

Slide 23

Slide 23 text

無効化する理由 Why has biased locking been disabled since Java 15?

Slide 24

Slide 24 text

参考資料 blogs.oracle.com/dave/biased-locking-in-hotspot mechanical-sympathy.blogspot.com/2011/11/java-lock-implementations.html

Slide 25

Slide 25 text

Remove the Solaris and SPARC Ports

Slide 26

Slide 26 text

Deprecate RMI Activation for Removal

Slide 27

Slide 27 text

対象 What objects are targeted?

Slide 28

Slide 28 text

New or additional features

Slide 29

Slide 29 text

新機能や追加機能 New or additional features 339 Edwards-Curve Digital Signature Algorithm (EdDSA) 360 Sealed Classes (Preview) 371 Hidden Classes 372 Remove the Nashorn JavaScript Engine 373 Reimplement the Legacy DatagramSocket API 374 Disable and Deprecate Biased Locking 375 Pattern Matching for instanceof (Second Preview) 377 ZGC: A Scalable Low-Latency Garbage Collector 378 Text Blocks 379 Shenandoah: A Low-Pause-Time Garbage Collector 381 Remove the Solaris and SPARC Ports 383 Foreign-Memory Access API (Second Incubator) 384 Records (Second Preview) 385 Deprecate RMI Activation for Removal

Slide 30

Slide 30 text

Edwards-Curve Digital Signature Algorithm (EdDSA)

Slide 31

Slide 31 text

Hidden Classes sun.misc.Unsafe::defineAnonymousClass を

Slide 32

Slide 32 text

Motivation

Slide 33

Slide 33 text

Fooというクラスにbarというメソッドがあるとして... When Class 'Foo' has a method named 'bar'... // Class is stored in byte array byte[] bytes = Files.readAllBytes(Paths.get("Foo.class")); MethodHandles.Lookup lookup = MethodHandles.lookup(); // Look up the hidden class lookup.defineHiddenClass(bytes, false); Class> clazz = lookup.findClass("Foo"); Constructor constuctor = clazz.getDeclaredConstructor(); Object hiddenClassInstance = constuctor.newInstance(); // Get method declared in the hidden class and invoke it Method method = clazz.getDeclaredMethod("bar"); method.invoke(hiddenClassInstance);

Slide 34

Slide 34 text

注意点 java.lang.Error: thrown from hidden class com.example.Foo/0x0000000800b7a470 at m1/com.example.Foo/0x0000000800b7a470.toString(Foo.java:16) at m1/com.example.Foo_0x0000000800b7a470$$Lambda$29/0x0000000800b7c040.apply(:1000001) at m1/com.example.Foo/0x0000000800b7a470.test(Foo.java:11)

Slide 35

Slide 35 text

参考資料 blogs.oracle.com/javamagazine/the-unsafe-class-unsafe-at-any-speed blogs.oracle.com/jrose/anonymous-classes-in-the-vm

Slide 36

Slide 36 text

Reimplement the Legacy DatagramSocket API

Slide 37

Slide 37 text

どのあたりが変わった? openjdk.java.net/jeps/373

Slide 38

Slide 38 text

どれぐらいパフォーマンスに差が出るのか Performance gain : JGroupsの例 0 10000 20000 30000 40000 50000 60000 70000 80000 90000 100000 UDP TCP Throughput (req/sec) JGroups 5.0.0 July 16 2020, UPerf (warmup: 1m, run: 3m) JDK 11(-28) 物理スレッド JDK 16-ea5 物理スレッド JDK 16 Loom+2-14 仮想スレッド 測定条件 Unicast 通信におけるスループット (req/sec) 構成 物理ノード8個によるクラスタ構成 利⽤JDKと 利⽤スレッ ドの形態 JDK 11 物理スレッド JDK 16-ea5 物理スレッド JDK 16 Loom+2-14 仮想スレッド belaban.blogspot.com/2020/07/double-your-performance- virtual-threads.html logico-jp.io/2020/07/27/double-your-performance-virtual- threads-fibers-and-jdk-15-16/

Slide 39

Slide 39 text

TCP socketのAPIはすでにJava 13で対応済み TCP Socket API was already reimplemented in Java 13

Slide 40

Slide 40 text

ZGC: A Scalable Low-Latency Garbage Collector

Slide 41

Slide 41 text

Java 15での機能強化 What’s new and enhancement in Java 15

Slide 42

Slide 42 text

参考資料 malloc.se/blog/zgc-jdk15 logico-jp.io/2020/09/25/zgc-whats-new-in-jdk-15/

Slide 43

Slide 43 text

Text Blocks

Slide 44

Slide 44 text

参考資料 cr.openjdk.java.net/~jlaskey/Strings/TextBlocksGuide_v11.html logico-jp.io/2020/09/09/programmers-guide-to-text-blocks/

Slide 45

Slide 45 text

Shenandoah: A Low-Pause-Time Garbage Collector

Slide 46

Slide 46 text

Preview or incubator

Slide 47

Slide 47 text

プレビューもしくはインキュベート機能 Preview or incubator projects 339 Edwards-Curve Digital Signature Algorithm (EdDSA) 360 Sealed Classes (Preview) 371 Hidden Classes 372 Remove the Nashorn JavaScript Engine 373 Reimplement the Legacy DatagramSocket API 374 Disable and Deprecate Biased Locking 375 Pattern Matching for instanceof (Second Preview) 377 ZGC: A Scalable Low-Latency Garbage Collector 378 Text Blocks 379 Shenandoah: A Low-Pause-Time Garbage Collector 381 Remove the Solaris and SPARC Ports 383 Foreign-Memory Access API (Second Incubator) 384 Records (Second Preview) 385 Deprecate RMI Activation for Removal

Slide 48

Slide 48 text

Pattern Matching for instanceof (Second Preview)

Slide 49

Slide 49 text

2種類の instanceof The operator of “instanceof” works in two ways.

Slide 50

Slide 50 text

Pattern openjdk.java.net/jeps/375 ž A pattern is a combination of (1) a predicate that can be applied to a target, and (2) a set of binding variables that are extracted from the target only if the predicate successfully applies to it. ž A type test pattern consists of a predicate that specifies a type, along with a single binding variable. obj instanceof String s (1) (2) 型テストパターン (type test pattern)

Slide 51

Slide 51 text

これまでは if (obj instanceof String) { String s = (String) obj; // use s }

Slide 52

Slide 52 text

このJEP (305, 375) により if (obj instanceof String s) { // can use s here } else { // can't use s here }

Slide 53

Slide 53 text

詳しくはきしださんパートで

Slide 54

Slide 54 text

Records (Second Preview)

Slide 55

Slide 55 text

簡単な例 public record Point(int x, int y) {}

Slide 56

Slide 56 text

public final class Point extends Record { private final int x; private final int y; public Point(int x, int y) { this.x = x; this.y = y; } public int x() { return x; } public int y() { return y; } public int hashCode() { ... } public boolean equals() { ... } public String toString() { ... } } フィールドの名前がそのままAPI (getXXXではない) メンバーはfinal setter (setXXX) は存在しない

Slide 57

Slide 57 text

Recordの特徴 ž extends できない

Slide 58

Slide 58 text

public record Point(int x, int y) {} ... Point p1 = new Point(1, 2); Point p2 = new Point(1, 2); Point p3 = new Point(p1.x(), p1.y()); Point p4 = new Point(p1.x(), p2.y()); boolean b1_2 = p1.equals(p2); // true boolean b1_3 = p1.equals(p3); // true boolean b3_4 = p3.equals(p4); // true ...

Slide 59

Slide 59 text

詳しくはきしださんパートで

Slide 60

Slide 60 text

Sealed Classes (Preview)

Slide 61

Slide 61 text

public sealed class Shape permits Circle, Rectangle, Square {...} 例 制限するクラスもしくはインターフェースを宣⾔ 拡張許可されたサブクラスが続く

Slide 62

Slide 62 text

拡張許可されたサブクラスの制約 Limitation of permitted subclasses

Slide 63

Slide 63 text

Recordと組み合わせることもできる Able to use Sealed type along with Records Public sealed interface Expr permits ConstantExpr, PlusExpr, TimesExpr, NegExpr {...} public record ConstantExpr(int i) implements Expr {...} public record PlusExpr(Expr a, Expr b) implements Expr {...} public record TimesExpr(Expr a, Expr b) implements Expr {...} public record NegExpr(Expr e) implements Expr {...}

Slide 64

Slide 64 text

instanceof を使ったパターンマッチング Pattern matching with instanceof public sealed class Shape permits Circle, Rectangle, Square {...} final class Circle extends Shape {...} final class Rectangle extends Shape {...} final class Square extends Shape {...} Shape rotate(Shape shape, double angle) { return switch (shape) { case Circle c -> c; // no-op case Rectangle r -> r.rotate(angle); case Square s -> s.rotate(angle); } }

Slide 65

Slide 65 text

詳しくはきしださんパートで

Slide 66

Slide 66 text

Foreign-Memory Access API (Second Incubator) ž --add-modules jdk.incubator.foreign

Slide 67

Slide 67 text

Java 15での強化点

Slide 68

Slide 68 text

これまで… Each way to access foreign memory outside of Java heap has pros and cons. ByteBufferの direct bufferを使う 直接オフヒープメモリを操作できるが、 • 2GBを超えるdirect bufferは作成できない • direct bufferに関連付けられたメモリの解放は、ガベージコレ クタに任されている Unsafe APIを使う 効率よくアクセスできるが、 • ⽂字通り安全ではない • Unsafe APIはサポート対象のAPIではない JNIを使う 理論上は可能だが、 • 偏に⾯倒、⾼コスト • Javaからネイティブへの移⾏が発⽣するために低速

Slide 69

Slide 69 text

セグメントとスライス Segment and Slice

Slide 70

Slide 70 text

境界と制限 (1) 空間的境界 Spatial boundaries

Slide 71

Slide 71 text

境界と制限 (2) 時間的境界 Temporal boundaries

Slide 72

Slide 72 text

境界と制限 (3) スレッド制限 Thread confinements Thread A Thread B

Slide 73

Slide 73 text

VarHandle を使ってセグメント内のメモリにアクセス Dereference memory segment using VarHandle // Get a VarHandle for int type VarHandle intHandle = MemoryHandles.varHandle( int.class, ByteOrder.nativeOrder()); // Allocate a memory segment (100 bytes), and access it try (MemorySegment segment = MemorySegment.allocateNative(100)) { MemoryAddress base = segment.baseAddress(); for (int i = 0; i < 25; i++) { // Access foreign memory with int type VarHandle intHandle.set(base.addOffset(i * 4), i); } }

Slide 74

Slide 74 text

セグメントのオーナーシップ – Serial confinement Segment ownership – Serial confinement // If segmentA is created in threadA, the segment is confined by threadA MemorySegment segmentA = ...; ... // confined by thread B var segmentB = segmentA.withOwnerThread(threadB); // shared segment – any threads can access this memory segment. var segmentB = segmentA.withOwnerThread(null);

Slide 75

Slide 75 text

セグメントのオーナーシップ - Parallel confinement Segment ownership - Parallel confinement // create a memory segment whose size is 1,000,000 × JAVA_INT SequenceLayout seq = MemoryLayout.ofSequence(1_000_000, MemoryLayouts.JAVA_INT); SequenceLayout seq_bulk = seq.reshape(-1, 100); VarHandle intHandle = seq.varHandle(int.class, PathElement.sequenceElement()); // Using spliterator to process memory contents in parallel int sum = StreamSupport.stream(MemorySegment.spliterator(segment, seq_bulk), true) .mapToInt(slice -> { int res = 0; MemoryAddress base = slice.baseAddress(); for (int i = 0; i < 100 ; i++) { res += (int)intHandle.get(base, (long)i); } return res; }).sum();

Slide 76

Slide 76 text

参考資料 cr.openjdk.java.net/~mcimadamore/panama/foreign-memaccess.html logico-jp.io/2020/08/08/state-of-foreign-memory-support/

Slide 77

Slide 77 text

Compatibility

Slide 78

Slide 78 text

Compatibility & Specification Review (CSR) wiki.openjdk.java.net/display/csr/Main bugs.openjdk.java.net/issues/?filter=37957

Slide 79

Slide 79 text

Parallel GC https://bugs.openjdk.java.net/browse/JDK-8246718 bugs.openjdk.java.net/browse/JDK-8240440 bugs.openjdk.java.net/browse/JDK-8242164

Slide 80

Slide 80 text

G1 GC www.phoronix.com/scan.php?page=article&item=openjdk-14-benchmark

Slide 81

Slide 81 text

SPECjbb 2015でJava 14の性能がJava 8に劣っている... Why is SPECjbb 2015 result on Java 14 worse than on Java 8?

Slide 82

Slide 82 text

-XX:MaxRAM=16g だけでHeapを指定しないと... If only “-XX:MaxRAM=16g” is specified and heap size is not specified... kstefanj.github.io/2020/04/16/g1-ootb-performance.html

Slide 83

Slide 83 text

理由

Slide 84

Slide 84 text

対策 bugs.openjdk.java.net/browse/JDK-8241670

Slide 85

Slide 85 text

その結果 As a result, ... kstefanj.github.io/2020/04/16/g1-ootb-performance.html

Slide 86

Slide 86 text

参考資料 ž JDK 15 G1/Parallel GC changes tschatzl.github.io/2020/09/01/jdk15-g1-parallel-gc-changes.html logico-jp.io/2020/09/10/jdk-15-g1-parallel-gc-changes/ kstefanj.github.io/2020/04/16/g1-ootb-performance.html logico-jp.io/2020/06/18/improving-g1-out-of-the-box-performance/ ž OpenJDK Startup - Late 2019 Edition cl4es.github.io/2019/11/20/OpenJDK-Startup-Update.html

Slide 87

Slide 87 text

Takeaways

Slide 88

Slide 88 text

Java 15

Slide 89

Slide 89 text

No content