Share
Embed
Say hello to Java 17!
Presentation deck used in JJUG (Japan Java User Group) Night Seminar on September 29, 2021.
Akihiro Nishikawa
September 29, 2021
Annual Pro sale · Save $30
Have presentations of your own?
Share with private links, password protection, and more control over your work.
Transcript
113 slides
-
Say hello to Java 17! JJUG Night Seminar Nishikawa, Akihiro
September 29, 2021 -
Agenda Java 17の概況 JEPs JEPには現れていない変更 Java
8、Java 11からJava 17への移行 -
すでにまとめてくださってらっしゃいます Java in the Box Annex: JEPでは語れないJava 17 (さくらばさん)
www.javainthebox.com/2021/09/jepjava-17.html 末永さん & 久保田さん WEB+DB PRESS Vol.124 Java17の新機能をざっくり紹介 qiita.com/ReiTsukikazu/items/407d61cb66fa4f562bf9 -
JSR 392: Java SE 17 API Differences Between Java SE
16 (build 36) & Java SE 17 (build 35) -
リリースサイクル変更後8回目のリリース The 8th release since release cadence was changed va
8 Java 9 Java 17 2017/9 2018/3 2018/9 2019/3 2019/9 2020/3 2020/9 2021/3 2021/9 2021/09/14 2022/03 2022/3 -
Java 17に取り込まれたJEP – JEPs in Java 17 openjdk.java.net/projects/jdk/17/ 306 Restore
Always-Strict Floating-Point Semantics 356 Enhanced Pseudo-Random Number Generators 382 New macOS Rendering Pipeline 391 macOS/AArch64 Port 398 Deprecate the Applet API for Removal 403 Strongly Encapsulate JDK Internals 406 Pattern Matching for switch (Preview) 407 Remove RMI Activation 409 Sealed Classes 410 Remove the Experimental AOT and JIT Compiler 411 Deprecate the Security Manager for Removal 412 Foreign Function & Memory API (Incubator) 414 Vector API (Second Incubator) 415 Context-Specific Deserialization Filters -
廃止や削除 Removed or deprecated 306 Restore Always-Strict Floating-Point Semantics 356
Enhanced Pseudo-Random Number Generators 382 New macOS Rendering Pipeline 391 macOS/AArch64 Port 398 Deprecate the Applet API for Removal 403 Strongly Encapsulate JDK Internals 406 Pattern Matching for switch (Preview) 407 Remove RMI Activation 409 Sealed Classes 410 Remove the Experimental AOT and JIT Compiler 411 Deprecate the Security Manager for Removal 412 Foreign Function & Memory API (Incubator) 414 Vector API (Second Incubator) 415 Context-Specific Deserialization Filters -
新機能や追加機能 Newly introduced and added 306 Restore Always-Strict Floating-Point Semantics
356 Enhanced Pseudo-Random Number Generators 382 New macOS Rendering Pipeline 391 macOS/AArch64 Port 398 Deprecate the Applet API for Removal 403 Strongly Encapsulate JDK Internals 406 Pattern Matching for switch (Preview) 407 Remove RMI Activation 409 Sealed Classes 410 Remove the Experimental AOT and JIT Compiler 411 Deprecate the Security Manager for Removal 412 Foreign Function & Memory API (Incubator) 414 Vector API (Second Incubator) 415 Context-Specific Deserialization Filters -
プレビューもしくはインキュベート機能 Preview or incubator projects 306 Restore Always-Strict Floating-Point Semantics
356 Enhanced Pseudo-Random Number Generators 382 New macOS Rendering Pipeline 391 macOS/AArch64 Port 398 Deprecate the Applet API for Removal 403 Strongly Encapsulate JDK Internals 406 Pattern Matching for switch (Preview) 407 Remove RMI Activation 409 Sealed Classes 410 Remove the Experimental AOT and JIT Compiler 411 Deprecate the Security Manager for Removal 412 Foreign Function & Memory API (Incubator) 414 Vector API (Second Incubator) 415 Context-Specific Deserialization Filters -
Java 17の位置づけ Spring Frameworkの次期バージョンでは Java 17がベースラインに A Java 17
and Jakarta EE 9 baseline for Spring Framework 6 Java SE (JDK) Java EE Jakarta EE Spring Framework 5.3.x Spring Boot 2.x Java 8~ Java 17 Java EE 7、8 Spring Framework 6 Spring Boot 3 Java 17+ Jakarta EE 9+ -
サポート期間は提供元次第... Support period depends upon each distributor... 対象のJDK サポート期間 (From)
サポート期間 (To) Oracle Oracle JDK 2021/9 2026/9 (Premier) 2029/9 (Extended) OpenJDK built by Oracle 2021/9 2022/3 Red Hat Red Hat OpenJDK 2021/11 (リリース予定) Eclipse Foundation Adoptium (Temurin) 2021/9 TBD Azul Systems Azul Zulu 2021/9 2029/9 Amazon Web Services Amazon Corretto 2021/9 TBD Bellsoft Bellsoft Liberica JDK 2021/9 2030/3 SAP SapMachine 2021/9 2026/9 Microsoft Microsoft Build of OpenJDK 2021/9 2027/9 (at least) -
[Q] LTS なのになぜ Preview や Incubator があるのか? Why does LTS
version of Java 17 contain preview/incubator projects? OpenJDK開発側は、6ヶ月というリリースサイクルを守っている LTSにするか否か、サポート期間はディストリビューターとしての判断 Moving Java Forward Even Faster | Mark Reinhold (mreinhold.org) そのため、LTS でも Preview / Incubator project が入ってくる -
次のLTSは? OracleがLTSを2年おき(現状は3年おき) にしたいと提案中 まだ本決まりではない 各ディストリビューターからいろいろなコメントが出ている The discuss September
2021 Archive by thread (java.net) -
GraalVM は? GraalVMのリリースサイクルはJavaのリリースサイクルと異なる 現在、JDK 17ベースのCE (Community Edition) がLabリリースとして出ている graalvm/labs-openjdk-17:
Based on JDK 17 with included support for libgraal and GraalVM CE. (github.com) 最新は jvmci-21.3-b03 -
Language feature 306 Restore Always-Strict Floating-Point Semantics 356 Enhanced Pseudo-Random
Number Generators 382 New macOS Rendering Pipeline 391 macOS/AArch64 Port 398 Deprecate the Applet API for Removal 403 Strongly Encapsulate JDK Internals 406 Pattern Matching for switch (Preview) 407 Remove RMI Activation 409 Sealed Classes 410 Remove the Experimental AOT and JIT Compiler 411 Deprecate the Security Manager for Removal 412 Foreign Function & Memory API (Incubator) 414 Vector API (Second Incubator) 415 Context-Specific Deserialization Filters -
409: Sealed Classes Project Amber 由来 Java 15でPreview、Java 16で再度Preview Java
16の内容から変更なし 実装・継承先を同一コンパイル単位内のクラス/インターフェースのみに制限 宣言的に許可するしくみ Pattern matching と組み合わせて使うことも想定 -
409: Sealed Classes public sealed class Shape permits Circle, Rectangle,
Square {...} 制限するクラスもしくはインターフェースを宣言 拡張許可されたサブクラスが続く -
409: Sealed Classes 許可されたサブクラスは sealed クラスや sealed インターフェースと同じモジュールに属すること
無名モジュールで宣言された場合は、 sealedクラスやsealedインターフェースと同じパッケージに属すること 許可されたサブクラスは sealed クラスもしくは sealed インターフェースを直接拡張する(間接はNG) その super クラスや super インターフェースで始まった seal の継続方法の明示が必要 継続方法 final : 全てのサブクラスに対して拡張禁止 sealed : permitsで許可したサブクラスに対してのみ拡張許可 non-sealed : 全てのサブクラスに対して拡張許可(拡張の制限を外す) -
409: Sealed Classes Developer Live Making Use of Sealed
Classes in Java - YouTube -
Updates and Improvements on Core Libraries 306 Restore Always-Strict Floating-Point
Semantics 356 Enhanced Pseudo-Random Number Generators 382 New macOS Rendering Pipeline 391 macOS/AArch64 Port 398 Deprecate the Applet API for Removal 403 Strongly Encapsulate JDK Internals 406 Pattern Matching for switch (Preview) 407 Remove RMI Activation 409 Sealed Classes 410 Remove the Experimental AOT and JIT Compiler 411 Deprecate the Security Manager for Removal 412 Foreign Function & Memory API (Incubator) 414 Vector API (Second Incubator) 415 Context-Specific Deserialization Filters -
306: Restore Always-Strict Floating-Point Semantics Java SE 1.2で導入されたデフォルト浮動小数点モードをなくし、厳密な浮動小 数点セマンティクス (strictfp)
だけにする これにより、strictfp 修飾子は意味がなくなる 厳密な浮動小数点セマンティクス 浮動小数点数をIEEE 754という規格で決められたルールで厳密に処理 デフォルト浮動小数点モード (Java SE 1.2で導入) CPUの機能を使って浮動小数点数を演算 -
306: Restore Always-Strict Floating-Point Semantics デフォルト浮動小数点モードの導入由来 x86アーキテクチャのx87浮動小数点コプロセッサ命令セットと相性が悪かった (厳密な浮動小数点セマンティクスに適合するには大量の追加命令が必要で、オーバーヘッド大)
オーバーフローやアンダーフローがない場合、strictfpの場合と結果を一致させるためのオーバーヘッドは小 SSE2 (Streaming SIMD Extensions 2) Pentium 4以後で搭載された拡張機能 (2001年頃) Intel、AMDともSSE2以後の拡張も含めて長期にわたってサポート 大きなオーバーヘッドを伴わずに厳密なJVM浮動小数点演算をサポートできるようになった -
306: Restore Always-Strict Floating-Point Semantics JDKの実装上の変更点 HotSpot VMで指数部拡張数値集合 (extended
exponent value set) を許可する浮動小数点モード の実行禁止 strictfp 修飾子の不必要な使用に対して新たな lint警告を出すためのjavacのアップデート strictfp public class FloatingPointSample { public FloatingPointSample() { } public static void main(String... args) { FloatingPointSample fp = new FloatingPointSample(); fp.sayHello(); } public strictfp void sayHello() { System.out.println("Hello!"); } } $ javac FloatingPointSample.java FloatingPointSample.java:1: warning: [strictfp] as of release 17, all floating- point expressions are evaluated strictly and 'strictfp' is not required strictfp public class FloatingPointSample { ^ FloatingPointSample.java:11: warning: [strictfp] as of release 17, all floating- point expressions are evaluated strictly and 'strictfp' is not required public strictfp void sayHello() { ^ 2 warnings -
306: Restore Always-Strict Floating-Point Semantics Developer Live Floating-Point Arithmetic
: What Every Java Programmer Should Know! - YouTube -
356: Enhanced Pseudo-Random Number Generators 疑似乱数生成器 (PRNG) の新たなインターフェース型と実装を導入 ジャンプ可能なPRNGアルゴリズムと分割可能なPRNGアルゴリズム
Xoshiro256PlusPlusとXoshiro128PlusPlusの実装 java.util.randomのアップデート Random、ThreadLocalRandom、SplittableRandomのリファクタリング 従来の乱数生成器の動作に影響が出ないように配慮 -
356: Enhanced Pseudo-Random Number Generators java.util.random [Interface] RandomGenerator [Nested]
RandomGenerator.ArbitrarilyJumpableGenerator RandomGenerator.JumpableRandomGenerator RandomGenerator.LeapableRandomGenerator RandomGenerator.SplittableGenerator RandomGenerator.StreamableGenerator [Class] RandomGeneratorFactory<T extends RandomGenerator> -
382: New macOS Rendering Pipeline Project Lanaiの成果を統合 OpenJDK: Lanai
(java.net) 非推奨のApple OpenGL APIへのJDKの依存度を低減するべく、新しいApple Metal APIを使用するmacOS 用のJava 2Dレンダリング・パイプラインを実装 macOS固有のコードに対する変更のみで、他OSへの影響はない 新たなJava APIの追加や既存Java APIの変更もない -
415: Context-Specific Deserialization Filters アプリケーションが、コンテキストに応じて(=ストリームごとに)選択されたデシリア ライズ・フィルターを構成できるようになった デシリアライズ・フィルター Java 9で導入
JEP 290: Filter Incoming Serialization Data (java.net) 入力データストリームをデシリアライズする前に検証できるようになったが、 (起動時に設定する)静的なJVM全体のデシリアライズ・フィルターゆえ、きめ細かな対応が困難 -
415: Context-Specific Deserialization Filters 2種類のフィルター JVM全体:JVM内のすべてのデシリアライズに適用 ストリーム固有:特定のObjectInputStreamからのクラスを検証 フィルターの実装方法
jdk.serialFilterプロパティでJVM全体のパターンベースのフィルターを指定 jdk.serialFilterプロパティでパターンベースのフィルターを指定した場合は、アプリケーションは変更不要 ObjectInputFilter APIを使って、カスタムまたはパターンベースのストリーム専用フィルターを実装 Config.createFilter(String) の利用 -
415: Context-Specific Deserialization Filters 後方互換性 フィルターファクトリーを設定していない場合、 (JVM全体のフィルターが構成済みであれば)組み込みのファ クトリーが静的なJVM全体のフィルターを返す 詳しくは
Serialization Filtering docs.oracle.com/en/java/javase/17/core/serialization-filtering1.html -
New Platform Support 306 Restore Always-Strict Floating-Point Semantics 356 Enhanced
Pseudo-Random Number Generators 382 New macOS Rendering Pipeline 391 macOS/AArch64 Port 398 Deprecate the Applet API for Removal 403 Strongly Encapsulate JDK Internals 406 Pattern Matching for switch (Preview) 407 Remove RMI Activation 409 Sealed Classes 410 Remove the Experimental AOT and JIT Compiler 411 Deprecate the Security Manager for Removal 412 Foreign Function & Memory API (Incubator) 414 Vector API (Second Incubator) 415 Context-Specific Deserialization Filters -
391: macOS/AArch64 Port Appleの新しいArm 64ベースのシステム (M1) 上でネイティブに動作するmacOS 用のJDKバージョン macOSに内蔵されているRosetta
2トランスレーターを使って、AArch64ベースのシステム上でmacOS/x64ビ ルドのJDKを実行することも可能だが、パフォーマンスに難がある 移植にあたり、既存のAArch64コードを再利用 Linux : JEP 237: Linux/AArch64 Port (java.net) Windows: JEP 388: Windows/AArch64 Port (java.net) -
391: macOS/AArch64 Port HotSpot for macOS/AArch64にW^Xサポートを追加 macOS/AArch64にはWrite-xor-execute (W^X) ポリシーがあるため、それに対応するべく、
W^Xサポート を実装・追加(他のOS、CPU向けJDKではW^Xポリシーはサポートしていない) Write-xor-execute (W^X) ポリシーとは? メモリセグメントは実行可能かつ書き込み可能であってはいけない、というポリシー -
Previews and Incubators 306 Restore Always-Strict Floating-Point Semantics 356 Enhanced
Pseudo-Random Number Generators 382 New macOS Rendering Pipeline 391 macOS/AArch64 Port 398 Deprecate the Applet API for Removal 403 Strongly Encapsulate JDK Internals 406 Pattern Matching for switch (Preview) 407 Remove RMI Activation 409 Sealed Classes 410 Remove the Experimental AOT and JIT Compiler 411 Deprecate the Security Manager for Removal 412 Foreign Function & Memory API (Incubator) 414 Vector API (Second Incubator) 415 Context-Specific Deserialization Filters -
406: Pattern Matching for switch (Preview) Project Amber由来 Java 14
JEP 305: Pattern Matching for instanceof (Preview) (java.net) Java 15 JEP 375: Pattern Matching for instanceof (Second Preview) (java.net) Java 16 JEP 394: Pattern Matching for instanceof (java.net) -
406: Pattern Matching for switch (Preview) switchでパターンマッチングが使えるようになった caseラベルを拡張し、定数に加えてパターンも含める
guarded patternとparenthesized patternという2種類の新しいパターンを導入 Sealed class、Recordsとの組み合わせももちろん可能 -
406: Pattern Matching for switch (Preview) 注意 パターンラベルが重複するとコンパイル時エラー
パターン変数を宣言すると、fall-throughは許可されない (breakが必要) -
406: Pattern Matching for switch (Preview) guarded pattern parenthesized pattern
static String formatterPatternSwitch(Object o) { return switch (o) { case null -> String.format("null"); case Integer i -> String.format("int %d", i); case Long l -> String.format("long %d", l); case Double d -> String.format("double %f", d); case String s -> String.format("String %s", s); default -> o.toString(); }; } static void test(Object o) { switch (o) { case Character c -> { if (c.charValue() == 7) { System.out.println("Ding!"); } System.out.println("Character"); } case Integer i -> throw new IllegalStateException( "Invalid Integer argument of value " + i.intValue()); default -> { break; } } } -
406: Pattern Matching for switch (Preview) Developer Live Pattern
Matching in Java 17 and Beyond - YouTube -
412: Foreign Function & Memory API (Incubator) Project Panama由来
OpenJDK: Panama (java.net) 2個のAPI仕様をまとめたもの (FFM API) Foreign Function API JNIを置き換え、ネイティブライブラリをシンプルかつ性能よく呼び出すためのAPI JEP 389: Foreign Linker API (Incubator) (java.net) Foreign Memory Access API ヒープ外の外部メモリへの安全かつ効率的なアクセスをするための API JEP 370: Foreign-Memory Access API (Incubator) (java.net) JEP 383: Foreign-Memory Access API (Second Incubator) (java.net) JEP 393: Foreign-Memory Access API (Third Incubator) (java.net) -
412: Foreign Function & Memory API (Incubator) 外部メモリ割り当て MemorySegment
MemoryAddress SegmentAllocator 構造化済み外部メモリ操作 MemoryLayout MemoryHandles MemoryAccess 外部リソースのライフサイクル管理 ResourceScope 外部関数の呼び出し SymbolLookup CLinker 利用時にはモジュールの明示的な追加が必要 --add-modules jdk.incubator.foreign -
412: Foreign Function & Memory API (Incubator) Foreign Function API
$ java --add-modules jdk.incubator.foreign --enable-native-access=ALL-UNNAMED ForeignFunctionSample.java WARNING: Using incubator modules: jdk.incubator.foreign warning: using incubating module(s): jdk.incubator.foreign 1 warning [Foreign API] 1000 [Java API] 1000 import com.sun.security.auth.module.UnixSystem; import jdk.incubator.foreign.CLinker; import jdk.incubator.foreign.FunctionDescriptor; import java.lang.invoke.MethodType; public class ForeignFunctionSample { public ForeignFunctionSample() {} public static void main(String... args) throws Throwable { var getuidDesc = FunctionDescriptor.of(CLinker.C_INT); var getuidType = MethodType.methodType(int.class); var getuidAddr = CLinker.systemLookup().lookup("getuid").get(); var linker = CLinker.getInstance(); var getuidHandle = linker.downcallHandle(getuidAddr, getuidType, getuidDesc); var uid = (int) getuidHandle.invokeExact(); System.out.println("[Foreign API] " + uid); System.out.println("[Java API] " + new UnixSystem().getUid()); } } -
412: Foreign Function & Memory API (Incubator) Foreign Memory API
ResourceScope MemorySegment などのリソースのライフサイク ルを管理 MemorySegment Javaヒープ上またはJavaヒープ外に位置するメモリ 領域をモデル化するために利用可能な抽象化し たもの Slice セグメント中に指定可能な子セグメント 親セグメントと時間的境界が同じ MemoryLayout バイト数指定も、構造体指定も可 import jdk.incubator.foreign.ResourceScope; import jdk.incubator.foreign.MemoryAccess; import jdk.incubator.foreign.MemoryLayout; import jdk.incubator.foreign.MemoryLayouts; import jdk.incubator.foreign.MemorySegment; import java.lang.invoke.VarHandle; ... // 座標を設定(省略) record Point(int x, int y) {} Point[] values = new Point[10]; ... try (var scope = ResourceScope.newConfinedScope()) { // 構造体としてメモリレイアウトを定義して、領域を確保 MemoryLayout points = MemoryLayout.sequenceLayout( values.length, MemoryLayout.structLayout( MemoryLayouts.JAVA_INT.withName("x"), MemoryLayouts.JAVA_INT.withName("y") ) ); var segment = MemorySegment.allocateNative(points, scope); ... } catch (Exception e) {...} -
412: Foreign Function & Memory API (Incubator) Foreign Memory API
メモリから読み書き VarHandleを使って読み書き ... VarHandle xHandle = points.varHandle( int.class, MemoryLayout.PathElement.sequenceElement(), MemoryLayout.PathElement.groupElement("x") ); VarHandle yHandle = points.varHandle( int.class, MemoryLayout.PathElement.sequenceElement(), MemoryLayout.PathElement.groupElement("y") ); for (int i = 0; i < values.length; i++) { int x = (int) xHandle.get(segment, (long) i); int y = (int) yHandle.get(segment, (long) i); xHandle.set(segment, (long) i, values[i].x() * 2); yHandle.set(segment, (long) i, values[i].y() * 2); } ... // メモリセグメントにPointの値を設定 ... for (int i = 0; i < values.length; i++) { MemoryAccess.setIntAtOffset( segment, points.byteOffset( MemoryLayout.PathElement.sequenceElement(i), MemoryLayout.PathElement.groupElement("x") ), values[i].x() ); MemoryAccess.setIntAtOffset( segment, points.byteOffset( MemoryLayout.PathElement.sequenceElement(i), MemoryLayout.PathElement.groupElement("y") ), values[i].y() ); } ... -
414: Vector API (Second Incubator) Project Panama由来 OpenJDK: Panama
(java.net) サポート対象のCPUアーキテクチャで最適なハードウェアベクトル計算命令に、確 実にランタイムでコンパイルするベクトル計算を表現するためのAPI クロスプラットフォーム SIMD (Single Instruction Multiple Data) モデル Java 16 : JEP 338: Vector API (Incubator) (java.net) Intel x64、ARM Aarch 64 Neon、PPC に対応 -
414: Vector API (Second Incubator) SIMDが使えないときは、 4回の乗算、加算、代入が必要 SIMDが使えると、 1回のSIMD乗算、SIMD加算、代入 a
= b + c * z[i+0] d = e + f * z[i+1] r = s + t * z[i+2] w = x + y * z[i+3] = + * a d r w b e s x c f t y z[i+0] z[i+1] z[i+2] z[i+3] -
414: Vector API (Second Incubator) Intel SVML (Short Vector Math
Library) との統合 jdk.incubator.vectorモジュールがあれば、Intelから寄贈されたSVML共有ライブラリを利用可能 Vector APIが共有ライブラリのスタブに演算をバインド(共有ライブラリがない場合、スカラーコードにフォール バック) APIならびに全体的なパフォーマンスの改善 (とくに文字の演算) UTF-8 decoding shortベクトルとchar配列間の文字コピーのメソッド 整数ベクトルでの符号なし比較演算 byteベクトルとboolean配列間の変換 x64アーキテクチャにおける超越関数ならびに三角関数のlanewise演算のサポート -
414: Vector API (Second Incubator) Java 18 : JEP 417:
Vector API (Third Incubator) (java.net) ARM AArch64用のScalar Vector Extension ハードウェアでマスキングをサポートするアーキテクチャ上でのmasked vector operationの最適化 Foreign Memory APIとの統合 APIの改善 IncubationはProject Valhallaの成果取り込みまで続く(予定) Unified generics Primitive クラス -
414: Vector API (Second Incubator) Developer Live The Vector
API in JDK 17 - YouTube -
Future Proofing Java Programs 306 Restore Always-Strict Floating-Point Semantics 356
Enhanced Pseudo-Random Number Generators 382 New macOS Rendering Pipeline 391 macOS/AArch64 Port 398 Deprecate the Applet API for Removal 403 Strongly Encapsulate JDK Internals 406 Pattern Matching for switch (Preview) 407 Remove RMI Activation 409 Sealed Classes 410 Remove the Experimental AOT and JIT Compiler 411 Deprecate the Security Manager for Removal 412 Foreign Function & Memory API (Incubator) 414 Vector API (Second Incubator) 415 Context-Specific Deserialization Filters -
403: Strongly Encapsulate JDK Internals すべてのJDK内部要素をデフォルトで隠蔽 sun.misc.Unsafeなどのいくつかの重要な内部API (jdk.unsupportedモジュールがexportしているも の)
を除く JEP 396 (JDK 16) の流れを汲む JEP 396: Strongly Encapsulate JDK Internals by Default (java.net) -
403: Strongly Encapsulate JDK Internals Java 9-15 --illegal-access =
warn Java 16 --illegal-access = deny ただし、Java 15以前のように緩和できた Java 17 --illegal-accessオプションは無効化 Publicでないメンバーにアクセスするためには、--add-opens (もしくは JARファイルmanifest属性のAdd- Opens) を使って明示的に指定する必要がある -
403: Strongly Encapsulate JDK Internals 移行・周知期間を終えて厳格化 内部APIがデフォルトで隠蔽されている点に変更はない Java 8からの移行時には、jdepsを使った依存関係の確認が必要
ライブラリや開発フレームワークで使っている場合、バージョンアップで回避できるか? ライブラリや開発フレームワークに依存しない部分で(強引に)内部APIを使っている場合、コードの書き換え が必要になる場合がある(Java 8 → Java 9でもはまった人が続出したところ) -
Deprecations and Removals 306 Restore Always-Strict Floating-Point Semantics 356 Enhanced
Pseudo-Random Number Generators 382 New macOS Rendering Pipeline 391 macOS/AArch64 Port 398 Deprecate the Applet API for Removal 403 Strongly Encapsulate JDK Internals 406 Pattern Matching for switch (Preview) 407 Remove RMI Activation 409 Sealed Classes 410 Remove the Experimental AOT and JIT Compiler 411 Deprecate the Security Manager for Removal 412 Foreign Function & Memory API (Incubator) 414 Vector API (Second Incubator) 415 Context-Specific Deserialization Filters -
398: Deprecate the Applet API for Removal JEP 289 (Java
9) で非推奨になって いたものを、将来リリースで削除するた め非推奨化 java.applet.Applet java.applet.AppletStub java.applet.AppletContext java.applet.AudioClip javax.swing.JApplet java.beans.AppletInitializer 以下のAPIに含まれる、左記クラス/イ ンターフェースを参照するAPI要素も、 将来リリースで削除するために非推奨 化 java.beans.Beans javax.swing.RepaintManager javax.naming.Context -
407: Remove RMI Activation JEP 385 (Deprecate RMI Activation for
Removal, Java 15) で非推奨化 反論がなかったので... -
411: Deprecate the Security Manager for Removal 将来リリースで削除するため、JEP 398とあわせて非推奨化
Java 1.0からある機能、SandboxでAppletを動かすために使われていた ClientサイドのJavaコードを保護するための主要な手段として利用されてこなかった Serverサイドではほぼ使われなかった Appletもなくなるしね... -
For OpenJDK Contributors 306 Restore Always-Strict Floating-Point Semantics 356 Enhanced
Pseudo-Random Number Generators 382 New macOS Rendering Pipeline 391 macOS/AArch64 Port 398 Deprecate the Applet API for Removal 403 Strongly Encapsulate JDK Internals 406 Pattern Matching for switch (Preview) 407 Remove RMI Activation 409 Sealed Classes 410 Remove the Experimental AOT and JIT Compiler 411 Deprecate the Security Manager for Removal 412 Foreign Function & Memory API (Incubator) 414 Vector API (Second Incubator) 415 Context-Specific Deserialization Filters -
410: Remove the Experimental AOT and JIT Compiler 実験的なJavaベースのAOT (Ahead-of-Time)
およびJIT (Just-in-Time) コンパ イラを削除 導入したけどほとんど使われなかった メンテナンスが大変 Oracle JDK 16で既に削除されているが、誰も文句言わなかったので... 削除対象のモジュール jdk.aot (jaotc ツール) jdk.internal.vm.compiler (Graal コンパイラ) jdk.internal.vm.compiler.management (GraalのMBean) -
410: Remove the Experimental AOT and JIT Compiler JVMCIは引き続き残る (利用できる)
JavaベースのJITコンパイラやAOTコンパイラが必要であれば、GraalVMを使う -
すでにまとめてらっしゃいます Java in the Box Annex: JEPでは語れないJava 17 (さくらばさん)
www.javainthebox.com/2021/09/jepjava-17.html 末永さん & 久保田さん WEB+DB PRESS Vol.124 -
Garbage Collection Java 17ではGC関連のJEPはない Java 17におけるGCの改善個数は312個 全体的な改善 異なるメモリ予約に対して異なるサイズのラージページを利用可能
[JDK-8256155] Allow multiple large page sizes to be used on Linux - Java Bug System -
Garbage Collection / ZGC アプリケーションに合わせてconcurrent GCスレッドを動的に調整し、スループット の最適化とアロケーションストールの回避を両立 [JDK-8268372] ZGC:
dynamically select the number of concurrent GC threads used - Java Bug System Mark stackのメモリ使用量を大幅に削減 [JDK-8260267] ZGC: Reduce mark stack usage - Java Bug System -
Garbage Collection / Parallel GC GCポーズ内の直列処理している部分を並列化してGCポーズ時間を短縮 所定の種類の参照(Soft、Weak、Final、Phantom)の処理を必要とする java.lang.ref.Referenceインスタンスの量に基づいて、異なる量のスレッドを開始
観測された java.lang.ref.Reference の数を ReferencesPerThread の値(デフォルト値は 1000)で割り、その値を基にスレッド個数を決定 -XX:ParallelRefProcEnabled はデフォルトで true GCポーズ時間が長くなった場合は、コマンドラインで -XX:-ParallelRefProcEnabled を指定 ReferencesPerThread の値は、オプション -XX:ReferencesPerThread で調整可能 [JDK-8204686] Dynamic parallel reference processing support for Parallel GC - Java Bug System [JDK-8043575] Dynamically parallelize reference processing work - Java Bug System -
Garbage Collection / Parallel GC その他 すべての内部弱参照の処理が自動的に並列実行されるように変更 [JDK-8268443] ParallelGC
Full GC should use parallel WeakProcessor - Java Bug System Parallel GCのFull GCにおけるadjust rootsフェーズの並列化 (work gangの利用) [JDK-8248314] Parallel: Parallelize parallel full gc Adjust Roots phase - Java Bug System -
Garbage Collection / G1 GC 予防的ガベージコレクション (Preventive garbage collection)
退避失敗による典型的な長いポーズを回避するため、特別な種類のyoung generationのGCを導入 [JDK-8257774] G1: Trigger collect when free region count drops below threshold to prevent evacuation failures - Java Bug System デフォルトで有効 診断フラグ G1UsePreventiveGC (以前の G1AllowPreventiveGC) で無効化可能 -
Garbage Collection / G1 GC 想定している状況 短命なhumongousオブジェクトの割り当て率が高く、オブジェクトをコピーするのに十分なスペースがない G1がGCをスケジュールする前に短命なhumongousオブジェクトがヒープを埋め尽くしてしまう可能性がある
そのような場合 上記のような状況が起こるのを待たずに、生き残ったオブジェクトをコピーするのに十分なスペースがあると確信 できる間に、スケジュール外のガベージコレクションを開始 Behavior in Very Tight Heap Situations - Garbage-First Garbage Collector Tuning https://docs.oracle.com/en/java/javase/17/gctuning/garbage-first-g1-garbage- collector1.html#GUID-BE157AF6-29E7-461A-82CF-50C1978785DA -
Garbage Collection / G1 GC GCログには G1 Preventive Collectionとしてタグ付け [...]
[2.574s][info][gc] GC(121) Pause Young (Normal) (G1 Evacuation Pause) 86M->83M(90M) 5.781ms [2.582s][info][gc] GC(122) Pause Young (Normal) (G1 Evacuation Pause) 86M->83M(90M) 4.936ms [2.596s][info][gc] GC(123) Pause Young (Normal) (G1 Preventive Collection) 86M->84M(90M) 9.997ms [...] -
Garbage Collection / G1 GC その他 Windows でのラージ・ページ処理に関する重要なバグの修正 [JDK-8266489]
Enable G1 to use large pages on Windows when region size is larger than 2m - Java Bug System G1 Full GCでのMarkSweepDeadRatioオプションのサポート [JDK-8262068] Improve G1 Full GC by skipping compaction for regions with high survival ratio - Java Bug System コレクションセットの早期刈り込みによるメモリ節減 [JDK-8262185] G1: Prune collection set candidates early - Java Bug System 退避後GCフェーズの一部を並列化してパフォーマンス向上 [JDK-8214237] Join parallel phases post evacuation - Java Bug System -
Garbage Collection / Shenandoah GC GCポーズのスレッドスタック処理の改善 Stack watermarkを使って並列化
Java 14(クラスの同時アンロード)、Java 16(参照の並行処理)に ついでの改善 ミリ秒以下のGCポーズ時間を実現 詳細 Shenandoah in OpenJDK 17: Sub-millisecond GC pauses | Red Hat Developer -
セキュリティ関連 Security Manager以外 Crypto [JDK-8248268] Support KWP in addition
to KW - Java Bug System [JDK-8023980] JCE doesn't provide any class to handle RSA private key in PKCS#1 - Java Bug System [JDK-8255410] Add ChaCha20 and Poly1305 support to SunPKCS11 provider - Java Bug System PKI [JDK-8256895] Add support for RFC 8954: Online Certificate Status Protocol (OCSP) Nonce Extension - Java Bug System [JDK-8179503] Java should support GET OCSP calls - Java Bug System [JDK-8256421] Add 2 HARICA roots to cacerts truststore - Java Bug System -
セキュリティ関連 Security Manager以外 TLS [JDK-8217633] Configurable extensions with system
properties - Java Bug System Kerberos [JDK-8139348] Deprecate 3DES and RC4 in Kerberos - Java Bug System XML Signature [JDK-8259575] Add SignatureMethodParameterSpec subclass for RSASSA-PSS params - Java Bug System [JDK-8259709] Disable SHA-1 XML Signatures - Java Bug System [JDK-8259801] Enable XML Signature secure validation mode by default - Java Bug System -
すでにまとめてらっしゃいます 末永さん & 久保田さん WEB+DB PRESS Vol.124 Java 11から17までのJEP、新しいAPIのまとめ
- CLOVER🍀 (hatenablog.com) yoshioterada/Java-Update-From-JavaSE9-to-Java17: This is all of the list of the Java Update from Java SE 9 to Java 17. (github.com) -
Java 11からJava 17までに統合されたAPIsやJEPs JEPs in JDK 17 integrated since JDK
11 (java.net) New API List (Java SE 17 & JDK 17) (oracle.com) -
サポート期間 Support period Red Hat OpenJDK 8のサポート終了は 2026/5 (予定)
Eclipse Adoptium (Temurin)、Amazon Correttoも同様 Oracle JDKはExtended Supportの終了が 2030/12 Java 17のサポート期間は 2027/9 終了(予定) 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 Java 11 Java 17 参考: Java 8 (Adoptium) -
まず Migration Guide を読む! Java Platform, Standard Edition Oracle JDK
Migration Guide, Release 17 2021/09/29現在、日本語版はない -
ほぼほんとーです Carl MastrangeloのNetflixでの体験 Java 8からJava 11へのアップデートを実施したCarlのコメントによれば... まずJava 11でそのまま動作
エラーが出たら、依存関係をチェックし、必要に応じてアップデート 内部APIや廃止APIを使っていたら書き換えて再ビルド(彼のケースは不使用) その後、Java 16/17へも移行したが、基本の流れは同じ ... When I joined Netflix, no one told me it was impossible to upgrade from Java 8 to 11. I just started using it. When things didn’t work (and they definitely didn’t!) on 11, I went and checked if I needed to update the library. I did this as a back-burner project, on my own machine, separate from the main repo. One by one, all the non-working libraries were updated to the working ones. When a library was not Java 11 compatible, I filed a PR on GitHub to fix it. And, plain as it sounds, when there are no more broken things, only working things are left! ... - The Impossible Java 11 by Carl Mastrangelo https://carlmastrangelo.com/blog/the-impossible-java-11 -
大まかなフロー まずは再コンパイルせずに新しいJavaで実行 エラーが出たら、 依存関係のアップデート JDK 内部APIや廃止APIの利用状況を確認 (必要であれば)再コンパイルして実行
Migration Guide docs.oracle.com/en/java/javase/17/migrate/preparing-migration.html この話って、 Java 9登場時に さんざん出ましたよね... -
依存関係のチェック 内部APIの利用確認 jdeps –jdkinternals 廃止・非推奨APIの利用確認 jdeprscan –-release 17
モジュールのカプセル化解除(最終手段) Java 17以後は明示的に--add-opensが必要 (JEP 403) 基本的に公開APIで代替できるはず -
インストールされたJDK/JREイメージに対する変更(例) 特にJava 8との対比 JRE tools.jar, rt.jar, dt.jar
ディレクトリ構造 拡張機能メカニズム java.ext.dirsシステム・プロパティ $JAVA_HOME/lib/ext 推奨標準優先メカニズム java.endorsed.dirsシステム・プロパティ $JAVA_HOME/lib/endorsed Java EEやCORBA関連のAPI JavaDB (Apache Derby) javah Jhat native2ascii JVM TI hprofエージェント ヒープダンプを出すならjcmdもしくはjmapで VisualVM Nashorn -
ディレクトリ / バージョン System.getProperty("java.home") $JAVA_HOME (Java 8までは $JAVA_HOME/jre )
構成ファイルやライブラリ $JAVA_HOME/conf $JAVA_HOME/lib System.getProperty("java.version") $FEATURE.$INTERIM.$UPDATE.$PATCH (Java 8までは 1.8.0_291 など) Runtime.Version (Java SE 17 & JDK 17) (oracle.com) -
削除された Java EE / CORBA 関連のモジュール Java 9で非推奨、Java 11で削除 (Jakarta
EEのライブラリを使う、という手も) 削除モジュール 影響を受けるパッケージ 移行するなら... Java API for XML Web Services (JAX-WS) java.xml.ws com.sun.xml.ws » jaxws-rt Java Architecture for XML Binding (JAXB) java.xml.bind org.glassfish.jaxb » jaxb-runtime JavaBeans Activation Framework java.activation javax.activation » javax.activation-api Common Annotations java.xml.ws.annotation javax.annotation » javax.annotation-api Common Object Request Broker Architecture (CORBA) java.corba org.glassfish.corba » glassfish-corba-orb Java Transaction API (JTA) java.transaction javax.transaction » javax.transaction-api -
デフォルトGC Java 9 からデフォルトGCはG1 JEP 248: Make G1 the
Default Garbage Collector (java.net) Java 8までのデフォルトGCはParallel GC CMS GCはJava 9で非推奨、Java 14で廃止 JEP 291: Deprecate the Concurrent Mark Sweep (CMS) Garbage Collector (java.net) JEP 363: Remove the Concurrent Mark Sweep (CMS) Garbage Collector (java.net) -
クラスローダー Platform Class Loader 以前のExtension Class Loaderから名称変更 JDKすべてのクラスを参照可
Application / Platform Class loaderは、内部クラスのインスタンス URLClassLoaderのインスタンスではない Cast すると ClassCastException -Xbootclasspath/p は廃止 (--patch-module を使う) JEP 261: Module System (java.net) -Xbootclasspath/a は利用可能 -
VMコマンドラインオプション 廃止済みオプション エラーメッセージが出て、VMが終了 (exit) Unrecognized option: もしくは Unrecognized
VM option のあとに該当のオプションを明示 非推奨オプション 警告メッセージを出す (warning) VM Warning: Option <option> was deprecated : サポートしているが将来削除の可能性あり VM Warning: Ignoring option : サポートしていないので無視 VM Option Explorer Differences between HotSpot VM Versions (chriswhocodes.com) -
java.io.FilePermission Java 9以後、オブジェクト作成時に指定したパスを正規化しなくなった Java 8までは正規化していた 同じものを指しているのに、別のものとして取り扱ってしまう 絶対パスと相対パス
シンボリックリンクとその実体 Windowsで表示されるパスとDOS 形式の 8.3 名を使用したパス Java 8までの挙動に一致するには jdk.io.permissionsUseCanonicalPathシステム・プロパティを true に設定 (デフォルト値はfalse) -
JDWP (Java Debug Wire Protocol) ソケットコネクター リモートデバッグのために接続をリスニングするために利用 Java 9以後、 接続を許可するホストを明示的に指定する必要がある
無指定の場合はlocalhostにバインド VNCなどと同様、アスタリスク (*) で任意のホストからの接続を許可できる Java 8以前は、無指定で任意のホストからの接続が可能だった -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=*:8192 -
Java 11からの移行 考え方はJava 8からの移行と同じ 変更せずに実行 エラーが出たら、変更や廃止されたAPIとその移行先をチェックして必要であれば書き換え 再コンパイル
動作確認 手作業でやらずに自動化してしまいましょう! -
Key takeaways Java 17 OpenJDK 8に比べてサポート期間が長いLTS 多数の開発フレームワークやライブラリがサポート
Java 17はSpring Framework/Spring Boot次期メジャーバージョンのベースライン Java 一桁の世界に滞在するのはリスク はやく Java 二桁の世界へ移行しましょう 移行方針や方法は、2017/9ごろの「Java 9への移行」で話題になっていたことと同じ ちゃんと自動化しましょう