Upgrade to Pro — share decks privately, control downloads, hide ads and more …

To the Moon and Beyond With Java 17 APIs!

Gunnar Morling
September 28, 2021

To the Moon and Beyond With Java 17 APIs!

Since moving to a 6 monthly release cadence, the Java platform is evolving more dynamically than ever before. It can be quite a challenge to stay on top of all the changes and new features.

In this talk we're going to explore the most important developments in the Java API: which classes have been added, what has been removed? Join Duke, the Java mascot for a trip to space and learn which exciting new APIs provided by the Java platform can help him with his journey:

- The Java Vector API for utilizing the SIMD capabilities of modern CPU architectures
- The Foreign Linker API for integrating with native code
- The JFR Event Streaming API for publishing JDK Flight Recorder Events

We'll also take a look at some useful changes to the Java runtime, such as CDS archives for a faster spaceship..., uhm, application launch.

Gunnar Morling

September 28, 2021
Tweet

More Decks by Gunnar Morling

Other Decks in Technology

Transcript

  1. To the Moon and Beyond
    With Java 17 APIs!
    Gunnar Morling
    Software Engineer, Red Hat
    @gunnarmorling

    View Slide

  2. View Slide

  3. View Slide

  4. #Java17APIs @gunnarmorling
    “Commit [ourselves] to
    achieving the goal, before
    this decade talk is out, of
    landing a man Duke on the
    Moon and returning him
    safely to the Earth”
    Today’s Mission
    John F. Kennedy

    View Slide

  5. The Vector API 1
    JFR Event Streaming
    2
    3
    The Foreign Linker API

    View Slide

  6. #Java17APIs @gunnarmorling
    ● Projects
    ○ Debezium
    ○ Quarkus
    ○ Hibernate
    ● MapStruct, JfrUnit, kcctl
    ● Java Champion
    ● @gunnarmorling
    Gunnar Morling
    Open Source Software Engineer at Red Hat

    View Slide

  7. The Vector API
    1

    View Slide

  8. #Java17APIs @gunnarmorling
    The Vector API
    JEPs 338 / 414 / 417
    java.util.Vector?!

    View Slide

  9. #Java17APIs @gunnarmorling
    “Introduce an API to express vector
    computations that reliably compile at runtime
    to optimal vector instructions on supported
    CPU architectures, thus achieving
    performance superior to equivalent scalar
    computations.”
    The Vector API
    JEPs 338 / 414 / 417
    JEP 417

    View Slide

  10. #Java17APIs @gunnarmorling
    The Vector API
    Goals
    Clear and concise API
    1
    Reliable runtime compilation
    and performance on
    x64 (SSE, AVX) and
    AArch64 (NEON, SVE)
    2
    3 4
    Platform agnostic
    Graceful degradation

    View Slide

  11. #Java17APIs @gunnarmorling
    The Vector API
    Use Cases
    ● Image, text, signal
    processing
    ● Encryption
    ● Machine Learning
    ● etc.

    View Slide

  12. #Java17APIs @gunnarmorling
    The Vector API
    Terminology

    View Slide

  13. #Java17APIs @gunnarmorling
    The Vector API
    Example – Scalar
    c = -(a2 + b2)

    View Slide

  14. #Java17APIs @gunnarmorling
    The Vector API
    Example – Vector

    View Slide

  15. #Java17APIs @gunnarmorling
    The Vector API
    Example – Vector

    View Slide

  16. #Java17APIs @gunnarmorling
    The Vector API
    Example – Vector

    View Slide

  17. #Java17APIs @gunnarmorling
    The Vector API
    Example – Vector

    View Slide

  18. #Java17APIs @gunnarmorling
    The Vector API
    Example – Vector

    View Slide

  19. #Java17APIs @gunnarmorling
    The Vector API
    A Very Rich API

    View Slide

  20. #Java17APIs @gunnarmorling
    The Vector API
    Example – FizzBuzz

    View Slide

  21. #Java17APIs @gunnarmorling
    The Vector API
    FizzBuzz – Performance
    Benchmark Mode Cnt Score Error Units
    scalarFizzBuzz thrpt 5 2204774,792 ± 76581,374 ops/s
    simdFizzBuzz thrpt 5 8830433,250 ± 69955,161 ops/s
    MacBook Pro 2019 (2,6 GHz 6-Core Intel Core i7, 32GB RAM)

    View Slide

  22. #Java17APIs @gunnarmorling
    The Vector API
    Examining Assembly Code with Hsdis

    View Slide

  23. #Java17APIs @gunnarmorling
    The Vector API
    Examining Native Assembly
    "conditionally copies
    byte elements from
    the source operand to
    the destination
    operand depending on
    mask bits defined in
    the implicit third
    register argument"
    felixcloutier.com

    View Slide

  24. Detour
    Identifying JDK API
    Changes by Yourself

    View Slide

  25. #Java17APIs @gunnarmorling
    Detour: Identifying API Changes
    javaalmanac.io

    View Slide

  26. #Java17APIs @gunnarmorling
    Detour: Identifying API Changes
    github.com/AdoptOpenJDK/jdk-api-diff

    View Slide

  27. #Java17APIs @gunnarmorling
    Detour: Identifying API Changes
    chriswhocodes.com/jepsearch.html

    View Slide

  28. #Java17APIs @gunnarmorling
    Detour: Identifying API Changes
    JavaDoc ab Version 17

    View Slide

  29. 1
    JFR Event Streaming 3
    2
    The Vector API
    The Foreign Linker API

    View Slide

  30. #Java17APIs @gunnarmorling
    ● Accessing native Memory (JEP 383)
    ● Accessing native APIs (JEP 389)
    ○ Moving specific parts to native code
    ○ Using existing native libraries
    ● Vector API
    Projekt Panama
    Integration of JVM and Native Code

    View Slide

  31. #Java17APIs @gunnarmorling
    Foreign Linker API
    Using Method Handle

    View Slide

  32. #Java17APIs @gunnarmorling
    Foreign Linker API
    Using Method Handle

    View Slide

  33. #Java17APIs @gunnarmorling
    Foreign Linker API
    Using Method Handle

    View Slide

  34. #Java17APIs @gunnarmorling
    ● Provide or create header file
    ● Generate binding (Panama EA build required)
    Foreign Linker API
    jextract

    View Slide

  35. #Java17APIs @gunnarmorling
    Foreign Linker API
    jextract

    View Slide

  36. #Java17APIs @gunnarmorling
    Foreign Linker API
    github.com/sundararajana/panama-jextract-samples

    View Slide

  37. Detour
    Removed APIs

    View Slide

  38. #Java17APIs @gunnarmorling
    ● RMI Activation
    ● Pack 200
    ● Nashorn JavaScript-Engine
    ● Deprecated for Removal in Java 17
    ○ Applet API
    ○ Security Manager
    Detour: Removed APIs
    Tackling the Maintenance Burden
    → 🤷
    → 🤷
    → Standalone Nashorn
    (ab Java 15), GraalJS

    View Slide

  39. 1
    JFR Event Streaming
    2
    3
    The Vector API
    The Foreign Linker API

    View Slide

  40. #Java17APIs @gunnarmorling
    OpenJDK Flight Recorder
    ● “JVM framework for troubleshooting,
    monitoring and profiling”
    ● 150+ built-in event types
    ● Support for custom events
    ● Open source since Java 11
    ● Meant for “Always on” usage in production

    View Slide

  41. #Java17APIs @gunnarmorling
    JFR Event Types
    https://bestsolution-at.github.io/jfr-doc/

    View Slide

  42. #Java17APIs @gunnarmorling
    JFR Event Streaming
    JEP 349
    ● Processing JFR events in “real-time”
    ● Use Cases
    ○ Export to monitoring services
    ○ Performance tests (JfrUnit)
    ○ Predictive analytics

    View Slide

  43. #Java17APIs @gunnarmorling
    JFR Event Streaming
    API

    View Slide

  44. #Java17APIs @gunnarmorling
    JFR Event Streaming
    Out-of-process: github.com/flight-recorder/health-report

    View Slide

  45. #Java17APIs @gunnarmorling
    ● Performance tests based on metrics like latency/throughput
    often unstable
    ● JfrUnit
    ○ Assertions based on proxy metrics
    ○ Plain JUnit-Tests
    ○ Analysis via JDK Mission Control
    JFR Event Streaming
    Use Case: Performance Regression Tests with JfrUnit
    “Unit testing,
    for performance”

    View Slide

  46. #Java17APIs @gunnarmorling
    JFR Event Streaming
    Asserting Socket IO with JfrUnit

    View Slide

  47. #Java17APIs @gunnarmorling
    JFR Event Streaming
    Asserting Socket IO with JfrUnit

    View Slide

  48. #Java17APIs @gunnarmorling
    JFR Event Streaming
    Asserting Socket IO with JfrUnit

    View Slide

  49. #Java17APIs @gunnarmorling
    JFR Event Streaming
    Asserting Socket IO with JfrUnit

    View Slide

  50. #Java17APIs @gunnarmorling
    JFR Event Streaming
    Asserting Socket IO with JfrUnit

    View Slide

  51. #Java17APIs @gunnarmorling
    JFR Event Streaming
    Asserting Socket IO with JfrUnit

    View Slide

  52. Detour
    AppCDS

    View Slide

  53. #Java17APIs @gunnarmorling
    ● Class Data Sharing: Memory mapped class metadata
    ● Default CDS archive for JDK classes since Java 12 (JEP 341)
    ● AppCDS: CDS archive for your own classes
    Detour: Faster Start-up with AppCDS
    No Need to Go Native?

    View Slide

  54. #Java17APIs @gunnarmorling
    Detour: AppCDS
    Quarkus App – Time to First Response
    Hetzner Cloud CX4 (4 vCPUs, 16GB RAM)

    View Slide

  55. #Java17APIs @gunnarmorling
    Detour: AppCDS
    Start-up Time of Apache Kafka

    View Slide

  56. View Slide

  57. #Java17APIs @gunnarmorling
    Java 17 – An Update Well Worth It!
    Many Improvements Across the Board...
    Language
    API
    Runtime

    View Slide

  58. #Java17APIs @gunnarmorling
    ● Shenandoah GC
    ● JFR support for native GraalVM binaries
    ● AArch64/Linux port
    ● Project Lilliput
    Red Hat & OpenJDK
    Multiple Contributions

    View Slide

  59. #Java17APIs @gunnarmorling
    ● JEP Search
    https://chriswhocodes.com/jepsearch.html
    ● Blog (Vector API, JFR Event Streaming,
    AppCDS, etc.)
    https://www.morling.dev/
    ● JfrUnit
    https://github.com/moditect/jfrunit
    Resources

    View Slide

  60. #Java17APIs @gunnarmorling
    Q&A
    [email protected]
    @gunnarmorling
    📧
    Contact

    View Slide

  61. View Slide