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

Java Module & Ahead Of Time (AOT) Compilation: Battle of Efficiency

Java Module & Ahead Of Time (AOT) Compilation: Battle of Efficiency

After years, the JVM was built for applications that last days, months to years, but with adoption of distributed architectures such as microservices and the native cloud movement this requirement has changed and no longer uses a JVM for long-term applications but of a more effective JVM with no computational resource requirement.

Aiming at this, it was released in Java 9 or supports modularity, but we have other features that enhance the compilation techniques, such as Aheaf Of Time (AOT) Compilation and Just In Time Compilation (JIT).

Therefore, in this talk I will compare the embassies in which providers or the quantities needed to capture more assertive decisions on future projects.

Ef3b48913ea26665c25b2ad78e449d16?s=128

Luram Archanjo

November 27, 2019
Tweet

Transcript

  1. Java Module & Ahead Of Time Compilation Battle of Efficiency

    Luram Archanjo
  2. Who am I? • Software Engineer at Sensedia • MBA

    in Java projects • Java and Microservice enthusiastic
  3. Agenda • Microservices • Java Module • Ahead Of Time

    Compilation (AOT) • Just In Time Compilation (JIT) • Native Image • Questions
  4. Moving to Microservices Feature A Feature B Feature C Monolith

    Microservice Microservice Microservices Microservice
  5. Scalability Feature A Monolith Scalability Microservice Microservice Microservices Scalability Microservice

    Microservice Microservice Microservice Microservice Microservice Microservice Microservice Feature B Feature C Feature A Feature B Feature C Feature A Feature B Feature C Waste Waste Waste Waste Waste
  6. Our resources are finite!

  7. How to use less resources using Java Language?

  8. Java Module

  9. Java Module Source: https://jcp.org/en/jsr/detail?id=376 & https://www.oracle.com/corporate/features/understanding-java-9-modules.html Modularity adds a higher

    level of aggregation above packages. The key new language element is the module - a uniquely named, reusable group of related packages, as well as resources and a module descriptor specifying. According to JSR 376, the key goals of modularizing the Java SE platform are: • Reliable Configuration • Strong Encapsulation • Greater Platform Integrity • Scalable Java Platform • Improved Performance Module Package Class Field Method
  10. Java Module java.se java.sql.rowset java.sql java.logging java.naming java.rmi java.scripting java.xml

    java.base java.datatransfer java.compiler java.desktop JDK Modules java.sql java.logging java.naming java.base java.compiler Application & Custom JRE module-info.java module myApp { exports com.tdc.poa; requires java.base; requires java.sql; requires java.logging; requires java.naming; requires java.compiler; }
  11. What are the results of using Java Modules?

  12. What are the results of using Java Modules? Java 8

  13. What are the results of using Java Modules? Java 9

    Module
  14. Less classes, functions and dependencies are not enough!

  15. The villain of Java’s resources is the Reflection

  16. What are the results of using Reflection? Spring is an

    amazing technical achievement and does so many things, but does them at Runtime. • Reads the byte code of every bean it finds. • Synthesizes new annotations for each annotation on each bean method, constructor, field etc. to support Annotation metadata. • Builds Reflective Metadata for each bean for every method, constructor, field etc.
  17. Is it possible to have the same productivity but without

    Reflection?
  18. Yes, with Ahead Of Time (AOT) Compilation

  19. Ahead Of Time (AOT) Compilation Ahead-of-time compilation (AOT compilation) is

    the act of compiling a higher-level programming language, or an intermediate representation such as Java bytecode, into a native machine code so that the resulting binary file can execute natively. Web Android Java Google Dagger 2
  20. What are the results of using Ahead Of Time (AOT)

    Compilation?
  21. Data from Micronaut website: • Startup time around a second.

    • All Dependency Injection, AOP and Proxy generation happens at compile time. • Can be run with as little as 180mb Max Heap. What are the results of using Ahead Of Time (AOT) Compilation?
  22. Data from Quarkus website: • Startup time around two seconds.

    • All Dependency Injection, AOP and Proxy generation happens at compile time. • Can be run with as little as 145mb Max Heap. What are the results of using Ahead Of Time (AOT) Compilation?
  23. Is it possible to improve more?

  24. Yes, with Just In Time (JIT) Compilation and

  25. GraalVM is a universal virtual machine for running applications written

    in JavaScript, Python, Ruby, R, JVM-based languages like Java, Scala, Groovy, Kotlin, Clojure, and LLVM-based languages such as C and C++ • Native Image • Embeddable For Java Programs For existing Java applications, GraalVM can provide benefits by running them faster, providing a faster Just In Time (JIT) Compilation Source: https://www.graalvm.org/docs/why-graal/ what is?
  26. Just In Time (JIT) compilation is a way of executing

    computer code that involves compilation during execution of a program. It runs complex optimizations to generate high-quality machine code Just In Time (JIT) Compilation System.out.println( "Hello World"); Source code 6a 61 76 61 20 c3 a9 20 66 6f 64 61 Byte code 01101010 01100001 01110110 01100001 00100000 11101001 00100000 01100110 01101111 01100100 01100001 Machine code JIT
  27. What are the results of using Just In Time (JIT)

    Compilation?
  28. What are the results of using Just In Time (JIT)

    Compilation?
  29. What are the results of using Just In Time (JIT)

    Compilation?
  30. Is it possible to improve more?

  31. Yes, with Native Image and

  32. GraalVM Native Image, currently available as an Early Adopter Technology

    Native image works well when: • Little or no runtime reflection is used. • Limited or no dynamic classloading. Source: https://www.graalvm.org/docs/why-graal/ Native Image
  33. What are the results of using Native Image?

  34. What are the results of using Native Image? Source: https://www.graalvm.org/docs/why-graal/

  35. What are the results of using Native Image? Source: https://www.graalvm.org/docs/why-graal/

  36. When to start using Java Module, AOT, JIT or Native

    Image?
  37. When to start using Java Module, JIT or AOT? New

    Application Java Module • Java 9 Just In Time Compilation • GraalVM Ahead Of Time Compilation • Quarkus • Micronaut Native Image • GraalVM ◦ Early Adopter Technology Existent Application Java Module • Java 9 Just In Time Compilation • GraalVM
  38. Java is dying?

  39. Thanks a million! Questions? /larchanjo /luram-archanjo