SlideShare a Scribd company logo
Java
And the Java Virtual Machine
What is Java?
• Language
• Platform
What’s a Java Platform?
• Enables you to develop and run code on varied hardware and OSes
• API specification
• Runtime environment (JRE)
• Libraries (which implement the platform API)
• Execution engine (VM)
• Development kit (JDK)
• Includes JRE (above)
• Compiler, debugger, profiler, disassembler…
Show me some Java Platforms
• Java SE (Standard Edition)
• Jakarta EE (Enterprise Edition)
• Open-sourced to the Eclipse Foundation
• Oracle is keeping the Java EE trademark
• Java ME (Micro Edition)
• Mobile devices
• Java Card
• Embedded devices, IoT
• Security-sensitive applications
Diagram of the Java SE Platform
• (Next slide)
A tour of Java and the JVM
What’s Jakarta EE?
• Java SE + specs and APIs for “enterprise” features
• Servlet (handle a client request, frequently HTTP)
• JPA (map JVM classes to database tables)
• JTA (transactions)
• JAX-RS (describe a RESTful web service)
• JAXB (un)marshalling of JSON, XML
• A Jakarta EE application server provides libraries fulfilling these APIs
• Only a handful of servers are certified as complete implementations
• There’s a (smaller) “Web Profile” with the bits people actually use
Do I need Jakarta EE?
• You could try your luck with a server that’s not certified as compatible
• TomCat remains popular, and was once certified
• You can cherry-pick the bits you want
• If you like JPA, you can have it (e.g. via Hibernate)
• You can disagree on some design points (see Spring)
• Building to a standard may protect you from vendor lock-in
• Beware drama: Oracle has restricted Eclipse’s use of trademarks
• Jakarta EE will be forced to make a big breaking change to rename packages
What’s the deal with Spring?
• Application framework
• Frequently served via an application server (e.g. TomCat)
• Spring integrates with some Jakarta EE specs
• Servlet, Bean Validation, JPA
• Differs philosophically in some places
• Spring MVC instead of JAX-RS for describing REST APIs
• “Controllers” rather than “Resources”
• You can still use JAX-RS if you want
• Jackson/Gson for (un)marshalling
• You can still use JAX-B if desired
Concerning .NET
Breaking news (May 2019)
• .NET Core now has most capabilities of .NET Framework 4.8
• .NET Framework is now deprecated
• .NET Core is rebranded as .NET
• Skips version 4
• So now we’re on .NET 5
• The upcoming slides were once correct
In case any of this sounds familiar…
Java SE .NET
Bytecode format Java bytecode CIL (e.g. MSIL)
Execution engine JVM VES (e.g. CLR)
Standard library Java SE APIs .NET Standard
Extended library Java EE APIs Additional APIs within .NET Core / .NET
Framework
Differences between .NET and Java Platform
• Bytecode-compatibility
• Old Java bytecode will run on new JVMs
• .NET bytecode breaks forward-compatibility to enable new features
• Linking
• Java “links” via an execution engine option (classpath)
• .NET libraries are dynamically linked, and can also load assemblies at runtime
• Execution
• Java has no executable; main class is an argument to execution engine
• .NET executables are libraries plus metadata
Differences between .NET and Java Platform
• Generics
• Java bytecode has no concept of generics (compilers “erase” them)
• Generics exist at runtime in .NET bytecode, and can be reified
• Special features supported in .NET bytecode
• Value types, stackalloc, pointers
• Move program counter / time-travel debugging
• JIT
• JVM JIT implementations use ambitious and complex optimizations
• .NET JIT is simpler. Performance through language features instead
Aside: .NET Framework vs .NET Core
• Original .NET specification was coupled to Windows and IIS
• Same GC and JIT (RyuJIT), same base class libraries (.NET Standard)
• Core is refactored to be modular and with fewer dependencies
• Core provides .NET Native; ahead-of-time compile CIL to native code
• Core Lacks features like Application Domains, Code Access Security
• Both implement Microsoft’s Common Language Infrastructure
• Program structure
• CIL bytecode format (e.g. MSIL)
• Virtual Execution System (e.g. CLR)
Aside: Mono
• An open-source implementation of .NET Framework
• Cross-platform
• Microsoft-sponsored non-Microsoft project
• Supported by Xamarin… who were bought by Microsoft
• Implements Microsoft’s specifications for C# and the CIL
(standardized by ECMA and ISO)
• Pretty cool until .NET Core was announced
Java is a poor man’s Docker
• Application servers (e.g. Tomcat) are basically k8s worker nodes
• JRE is basically a Container OS
• JVM is basically runc
• Java SE APIs are basically system libraries
• EAR/WAR artefacts are basically Container Images
• Compile your application once, deploy anywhere
Method signatures
• These impossible classes are possible in JVM bytecode, but not Java
• Overload method on return type
• Two fields with same name (but different types)
class C {
void a(String s) {}
int a(String s) { return 0; }
}
class C {
int a;
String a;
}
JVM for ultra low-latency computing
• Industry will pay $150k/month for a 3ms edge on the competition
• JVM GC pauses are frequently bigger than this
• Consider a Direct Market Access application
• Parse, validate, serialize message, check risk, read market data, serialize, send
• JVM can do this in ~10 microsecs, just as fast as C/C++
• Admittedly you have to write very non-idiomatic code, and complete warmup
• FPGA ~1 microsec
• ASIC ~400 nanosecs
• Python 50x slower
Should I run Java on the JVM?
1. Should I run Java on the JVM?
2. Should I run Java on the JVM?
Sun/Oracle Hotspot JVM JIT
• Method inlining, loop unrolling
• On-stack replacement
• Jump from interpreted code to JIT’d equivalent whenever code becomes hot
• Escape analysis
• Object fields are replaced with scalar values, avoiding heap allocation
• Monomorphic dispatch (avoid vtable lookup)
• Intrinsics (replace method with something more native)
• Dynamic deoptimization
• As access patterns change or new classes loaded: undo and try again
Sun/Oracle Hotspot JVM JIT
• Two compilers, tiered compilation (as of Java 7)
• C1 (Client)
• Fast startup
• Emits simple native code
• Still faster than executing bytecode in an interpreter
• C2 (Server)
• Generates better native code
• Decides how best to optimize based on execution profiles
• May frequently de-optimize
• Old, complex C++ codebase (needs replacing – more on this later)
Sun/Oracle Hotspot JVM JIT
• Tiered compilation
• Level 0 – interpreted code
• Level 1 – simple C1 compiled code (with no profiling)
• Level 2 – limited C1 compiled code (with light profiling)
• Level 3 – full C1 compiled code (with full profiling)
• Level 4 – C2 compiled code (uses profiling data from previous steps)
• Usually 0 -> 3 -> 4
• More complex code warrants more profiling, compilation
Sun/Oracle Hotspot JVM GC
• G1 (Java 8)
• Specify your latency requirements (“20 ms is the longest I’d wait for GC”)
• ZGC (Java 11)
• Low (<10ms) pause times even on multi-terabyte heaps
• Future support: multi-tiered heaps (hot objects in DRAM, cold in NVMe flash)
• Heap compression
• Pointer colouring (sell more SPARC machines)
• Shenandoah (Java 12)
• Low, constant pause time
• Most work done concurrently
Dalvik
• Google’s implementation of JVM for Android
• Caused Oracle to sue Google for 9 years (so far)
• Uses registers as primarily unit of data-storage instead of stack
• Avoid instruction dispatch, unnecessary memory access
• Higher semantic density per instruction
• 30% fewer instructions, 35% fewer code units
• 35% more bytes in instruction stream (but we consume two at a time)
• Combines .class files into .dex (Dalvik Executables)
• De-dupes any repeated information, saving 50% space
OpenJDK vs Oracle JDK
• Around Java SE 7, various JVMs converged.
• Oracle provided some extra ”commercial features”
• Incident analysis
• Font rendering
• Class sharing (for faster startup, smaller footprint)
• ZGC garbage collector
• For Java 11, Oracle upstreamed these. Basically the same now.
• Oracle JDK is (now) commercial
• OpenJDK is (now) provided by Red Hat (previously Oracle)
Hipster JVMs
• Amazon Corretto
• Zero-cost LTS
• Azul Zing
• Faster startup (saves previously-used JIT profile for re-use)
• Falcon JIT (high-performance server JIT based on LLVM)
• C4 garbage collector (concurrent, compacting, no GC pause)
• TeaVM
• AoT compiles JVM bytecode to JS or WebAssembly
• GraalVM (more on this later)
Hipster JVMs
• Or use the CLR
• Not standards-compliant
• Due to native interface
Should I run Java on the JVM?
1. Should I run Java on the JVM?
2. Should I run Java on the JVM?
JavaScript on the JVM
• Rhino; Java 1.4/1997 – part of an all-Java Netscape Navigator
• JVM JIT outperformed C++, but memory leaky and slow startup
• Interpreted mode was
• Nashorn; Java 8/2011
• “Several orders of magnitude” faster
• Deprecated in Java 11 because JavaScript was changing too fast to keep up
• GraalVM
• Suggested as a way to replace Nashorn
• More on this later
Other JVM languages
• Scala
• Has a “criticism” section on Wikipedia
• Kotlin
• Made by JetBrains (i.e. IntelliJ, Resharper)
• Coroutines, generators, safe navigation, elvis ?:, reification, data classes, FP
• Fast compilation (aiming to be as fast as Java, and not slow like Scala)
• Compiles to JS and native code
• Clojure
• Lisp, REPL
• Compiles to JS too
Other JVM languages
• Groovy
• Used for DSLs (for example data engineering)
• Used for Gradle config (now being replaced by Kotlin)
• JRuby
• Contributed invokedynamic instruction to JVM (not used by Java!)
• Dynamically changes classes and methods at runtime
• Outperforms real Ruby, especially in concurrent code (thanks to JVM threads)
• Jython
• Sounds like it’s for people who concede JVM has good libraries, but hate Java
GraalVM
• Oracle Labs research project based on JDK 8
• Universal Virtual Machine
• JVM-based languages
• LLVM-based languages
• Node.js, Python, Ruby, R
• JIT and AoT compiler (Graal)
• Language AST interpreter (Truffle)
• Enables language-agnostic debugger, profiler, heap viewer
• Compilation to native images, with minimal runtime (SubstrateVM)
GraalVM – JIT Compiler (Graal)
• Written in Java
• Compile Java using Java, rather than C++ (“Java-on-Java”)
• Generates native code (like LLVM/Clang does)
• Integrates into any JDK that supports JVM CI (Compiler Interface)
• JVM CI lets a JVM use as its dynamic compiler: any compiler written in Java
• Oracle Labs has backported JVM CI to JDK 8
• JVM CI ships with JDK 11 proper
• Replace Hotspot JIT’s C2 compiler
• Optimized performance for Truffle-based languages running on JVM
GraalVM – Ahead-of-time compilation
• Uses Graal compiler too
• Includes minimal runtime, SubstrateVM
• Smaller memory footprint
• Zero-dependency native image
• Tiny filesize (Spring web application + runtime in 36MB)
• Instant startup (deploy Spring web application in about 50ms)
• Produce native libraries (for your other native code to link to)
• Optionally include Graal compiler to complement AoT with JIT
• Build image with profile-guided optimizations from previous runs
GraalVM – Truffle
• Library for building programming language implementations
• Describe language as an interpreter for a self-modifying Abstract Syntax Tree
• Low-overhead language interop
• Performance matches or exceeds other language runtimes
• General instrumentation framework
• Multi-language debugging (via Chrome DevTools!)
• Profiling
• Heap view
GraalVM – Truffle
GraalVM – LLVM
• GraalVM implements LLVM’s LLI tool
• Directly execute programs from LLVM bitcode
• First you must compile any program (e.g. C, C++, Rust) to LLVM IR
• Note: platform-dependent
• LLI interprets the IR, then dynamically compiles hot parts using Graal
• Enables seamless interop with other dynamic languages in GraalVM
GraalVM – Database embed
• Oracle Database, MySQL
• Use GraalVM languages and modules… inside a SQL statement
• Write SELECT statements that:
• Classify whether a string is an email address
• Detect credit card brand
GraalVM – Performance
• Twitter cut their CPU usage by 13% by switching to GraalVM
• Across thousands of machines running thousands of JVMs
• See “Twitter’s Quest for a Wholly Graal Runtime”
• Better inlining, and across language boundaries
• Partial escape analysis
• Remove costly object allocations in more scenarios
• More aggressive speculative optimizations
• Full set of optimizations only available with Enterprise license!
Advantages compared to standard runtime
• Run Node.js with large-heap configuration and JVM’s GC
• V8 is tuned for browsers and small-heap scenarios
• Re-use libraries from Java, R, or Python… in Node.js
• Use Python for data science
• Use R for plotting graphs
• Use Java for Spark or Flink
That’s all
• Alex Birch

More Related Content

What's hot (19)

PDF
OSGi Community Event 2010 - OSGi Technical Update
mfrancis
 
PDF
Java Application Servers Are Dead!
Eberhard Wolff
 
PDF
Testing Automaton - CFSummit 2016
Ortus Solutions, Corp
 
PPTX
Java byte code presentation
Mahnoor Hashmi
 
PPTX
Peeling back the Lambda layers
Patrick McCaffrey
 
PDF
Ruby for devops
Adam Klein
 
PDF
Handling 1 Billion Requests/hr with Minimal Latency Using Docker
Matomy
 
PDF
Ekon21 Microservices - Event Driven Design
Arnaud Bouchez
 
PDF
Adding Real-time Features to PHP Applications
Ronny López
 
PDF
MariaDB - The Future of MySQL?
Bokowsky + Laymann GmbH
 
PPTX
Lesson1 intro
attiqrocket
 
PPT
Java Persistence API (JPA) - A Brief Overview
Craig Dickson
 
PPTX
Multi-threading in the modern era: Vertx Akka and Quasar
Gal Marder
 
PDF
OSGi In Anger - Tara Simpson
mfrancis
 
PDF
Deep Dive: Alfresco Core Repository (... embedded in a micro-services style a...
J V
 
PDF
Aws Lambda for Java Architects - Illinois VJug -2016-05-03
Derek Ashmore
 
PPTX
Repository performance tuning
Jukka Zitting
 
PPTX
How and Why GraalVM is quickly becoming relevant for developers (ACEs@home - ...
Lucas Jellema
 
OSGi Community Event 2010 - OSGi Technical Update
mfrancis
 
Java Application Servers Are Dead!
Eberhard Wolff
 
Testing Automaton - CFSummit 2016
Ortus Solutions, Corp
 
Java byte code presentation
Mahnoor Hashmi
 
Peeling back the Lambda layers
Patrick McCaffrey
 
Ruby for devops
Adam Klein
 
Handling 1 Billion Requests/hr with Minimal Latency Using Docker
Matomy
 
Ekon21 Microservices - Event Driven Design
Arnaud Bouchez
 
Adding Real-time Features to PHP Applications
Ronny López
 
MariaDB - The Future of MySQL?
Bokowsky + Laymann GmbH
 
Lesson1 intro
attiqrocket
 
Java Persistence API (JPA) - A Brief Overview
Craig Dickson
 
Multi-threading in the modern era: Vertx Akka and Quasar
Gal Marder
 
OSGi In Anger - Tara Simpson
mfrancis
 
Deep Dive: Alfresco Core Repository (... embedded in a micro-services style a...
J V
 
Aws Lambda for Java Architects - Illinois VJug -2016-05-03
Derek Ashmore
 
Repository performance tuning
Jukka Zitting
 
How and Why GraalVM is quickly becoming relevant for developers (ACEs@home - ...
Lucas Jellema
 

Similar to A tour of Java and the JVM (20)

PDF
Java 2012 conference keynote - Java Strategy & Roadmap - WebLogic & GlassFish...
HUJAK - Hrvatska udruga Java korisnika / Croatian Java User Association
 
PDF
Java8 launch at AMIS Services / First8
Getting value from IoT, Integration and Data Analytics
 
PPTX
Java 8 Launch Event - Past, Present and Future of Java and Java 8 key themes
Lucas Jellema
 
PPTX
Java8 launch AMIS Services by Lucas Jellema
Getting value from IoT, Integration and Data Analytics
 
PPT
Object Oriented Programming-JAVA
Home
 
PPTX
1. Java Project Guidance for engineering
vyshukodumuri
 
PPTX
Java 101
javafxpert
 
PPT
PPS Java Overview Unit I.ppt
CDSukte
 
PPT
PPS Java Overview Unit I.ppt
RajeshSukte1
 
PPTX
Simple tweaks to get the most out of your JVM
Jamie Coleman
 
PPTX
The Java Story
David Parsons
 
PPTX
Simple tweaks to get the most out of your jvm
Jamie Coleman
 
PPTX
MWLUG - Universal Java
Philippe Riand
 
PDF
The State of Java under Oracle at JCertif 2011
Arun Gupta
 
PDF
Java platform
Universidade de São Paulo
 
PPTX
01. Introduction to programming with java
Intro C# Book
 
PPTX
JAVA PROGRAM CONSTRUCTS OR LANGUAGE BASICS.pptx
AALIM MUHAMMED SALEGH COLLEGE OF ENGINEERING
 
PPT
Java & J2EE Struts with Hibernate Framework
Mohit Belwal
 
PDF
TechSearchWeb.pdf
TechSearchWeb
 
PDF
Technology Tutorial.pdf
TechSearchWeb
 
Java 2012 conference keynote - Java Strategy & Roadmap - WebLogic & GlassFish...
HUJAK - Hrvatska udruga Java korisnika / Croatian Java User Association
 
Java8 launch at AMIS Services / First8
Getting value from IoT, Integration and Data Analytics
 
Java 8 Launch Event - Past, Present and Future of Java and Java 8 key themes
Lucas Jellema
 
Java8 launch AMIS Services by Lucas Jellema
Getting value from IoT, Integration and Data Analytics
 
Object Oriented Programming-JAVA
Home
 
1. Java Project Guidance for engineering
vyshukodumuri
 
Java 101
javafxpert
 
PPS Java Overview Unit I.ppt
CDSukte
 
PPS Java Overview Unit I.ppt
RajeshSukte1
 
Simple tweaks to get the most out of your JVM
Jamie Coleman
 
The Java Story
David Parsons
 
Simple tweaks to get the most out of your jvm
Jamie Coleman
 
MWLUG - Universal Java
Philippe Riand
 
The State of Java under Oracle at JCertif 2011
Arun Gupta
 
01. Introduction to programming with java
Intro C# Book
 
JAVA PROGRAM CONSTRUCTS OR LANGUAGE BASICS.pptx
AALIM MUHAMMED SALEGH COLLEGE OF ENGINEERING
 
Java & J2EE Struts with Hibernate Framework
Mohit Belwal
 
TechSearchWeb.pdf
TechSearchWeb
 
Technology Tutorial.pdf
TechSearchWeb
 
Ad

Recently uploaded (20)

PDF
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
PPTX
Agentforce World Tour Toronto '25 - MCP with MuleSoft
Alexandra N. Martinez
 
PPTX
Mastering ODC + Okta Configuration - Chennai OSUG
HathiMaryA
 
PPTX
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
PDF
AI Agents in the Cloud: The Rise of Agentic Cloud Architecture
Lilly Gracia
 
DOCX
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
PDF
NASA A Researcher’s Guide to International Space Station : Physical Sciences ...
Dr. PANKAJ DHUSSA
 
PPTX
Digital Circuits, important subject in CS
contactparinay1
 
PDF
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PDF
“Computer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,” a ...
Edge AI and Vision Alliance
 
PDF
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
PDF
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
PDF
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PDF
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PDF
Staying Human in a Machine- Accelerated World
Catalin Jora
 
PPTX
MuleSoft MCP Support (Model Context Protocol) and Use Case Demo
shyamraj55
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
Agentforce World Tour Toronto '25 - MCP with MuleSoft
Alexandra N. Martinez
 
Mastering ODC + Okta Configuration - Chennai OSUG
HathiMaryA
 
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
AI Agents in the Cloud: The Rise of Agentic Cloud Architecture
Lilly Gracia
 
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
NASA A Researcher’s Guide to International Space Station : Physical Sciences ...
Dr. PANKAJ DHUSSA
 
Digital Circuits, important subject in CS
contactparinay1
 
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
“Computer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,” a ...
Edge AI and Vision Alliance
 
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
Staying Human in a Machine- Accelerated World
Catalin Jora
 
MuleSoft MCP Support (Model Context Protocol) and Use Case Demo
shyamraj55
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
Ad

A tour of Java and the JVM

  • 1. Java And the Java Virtual Machine
  • 2. What is Java? • Language • Platform
  • 3. What’s a Java Platform? • Enables you to develop and run code on varied hardware and OSes • API specification • Runtime environment (JRE) • Libraries (which implement the platform API) • Execution engine (VM) • Development kit (JDK) • Includes JRE (above) • Compiler, debugger, profiler, disassembler…
  • 4. Show me some Java Platforms • Java SE (Standard Edition) • Jakarta EE (Enterprise Edition) • Open-sourced to the Eclipse Foundation • Oracle is keeping the Java EE trademark • Java ME (Micro Edition) • Mobile devices • Java Card • Embedded devices, IoT • Security-sensitive applications
  • 5. Diagram of the Java SE Platform • (Next slide)
  • 7. What’s Jakarta EE? • Java SE + specs and APIs for “enterprise” features • Servlet (handle a client request, frequently HTTP) • JPA (map JVM classes to database tables) • JTA (transactions) • JAX-RS (describe a RESTful web service) • JAXB (un)marshalling of JSON, XML • A Jakarta EE application server provides libraries fulfilling these APIs • Only a handful of servers are certified as complete implementations • There’s a (smaller) “Web Profile” with the bits people actually use
  • 8. Do I need Jakarta EE? • You could try your luck with a server that’s not certified as compatible • TomCat remains popular, and was once certified • You can cherry-pick the bits you want • If you like JPA, you can have it (e.g. via Hibernate) • You can disagree on some design points (see Spring) • Building to a standard may protect you from vendor lock-in • Beware drama: Oracle has restricted Eclipse’s use of trademarks • Jakarta EE will be forced to make a big breaking change to rename packages
  • 9. What’s the deal with Spring? • Application framework • Frequently served via an application server (e.g. TomCat) • Spring integrates with some Jakarta EE specs • Servlet, Bean Validation, JPA • Differs philosophically in some places • Spring MVC instead of JAX-RS for describing REST APIs • “Controllers” rather than “Resources” • You can still use JAX-RS if you want • Jackson/Gson for (un)marshalling • You can still use JAX-B if desired
  • 11. Breaking news (May 2019) • .NET Core now has most capabilities of .NET Framework 4.8 • .NET Framework is now deprecated • .NET Core is rebranded as .NET • Skips version 4 • So now we’re on .NET 5 • The upcoming slides were once correct
  • 12. In case any of this sounds familiar… Java SE .NET Bytecode format Java bytecode CIL (e.g. MSIL) Execution engine JVM VES (e.g. CLR) Standard library Java SE APIs .NET Standard Extended library Java EE APIs Additional APIs within .NET Core / .NET Framework
  • 13. Differences between .NET and Java Platform • Bytecode-compatibility • Old Java bytecode will run on new JVMs • .NET bytecode breaks forward-compatibility to enable new features • Linking • Java “links” via an execution engine option (classpath) • .NET libraries are dynamically linked, and can also load assemblies at runtime • Execution • Java has no executable; main class is an argument to execution engine • .NET executables are libraries plus metadata
  • 14. Differences between .NET and Java Platform • Generics • Java bytecode has no concept of generics (compilers “erase” them) • Generics exist at runtime in .NET bytecode, and can be reified • Special features supported in .NET bytecode • Value types, stackalloc, pointers • Move program counter / time-travel debugging • JIT • JVM JIT implementations use ambitious and complex optimizations • .NET JIT is simpler. Performance through language features instead
  • 15. Aside: .NET Framework vs .NET Core • Original .NET specification was coupled to Windows and IIS • Same GC and JIT (RyuJIT), same base class libraries (.NET Standard) • Core is refactored to be modular and with fewer dependencies • Core provides .NET Native; ahead-of-time compile CIL to native code • Core Lacks features like Application Domains, Code Access Security • Both implement Microsoft’s Common Language Infrastructure • Program structure • CIL bytecode format (e.g. MSIL) • Virtual Execution System (e.g. CLR)
  • 16. Aside: Mono • An open-source implementation of .NET Framework • Cross-platform • Microsoft-sponsored non-Microsoft project • Supported by Xamarin… who were bought by Microsoft • Implements Microsoft’s specifications for C# and the CIL (standardized by ECMA and ISO) • Pretty cool until .NET Core was announced
  • 17. Java is a poor man’s Docker • Application servers (e.g. Tomcat) are basically k8s worker nodes • JRE is basically a Container OS • JVM is basically runc • Java SE APIs are basically system libraries • EAR/WAR artefacts are basically Container Images • Compile your application once, deploy anywhere
  • 18. Method signatures • These impossible classes are possible in JVM bytecode, but not Java • Overload method on return type • Two fields with same name (but different types) class C { void a(String s) {} int a(String s) { return 0; } } class C { int a; String a; }
  • 19. JVM for ultra low-latency computing • Industry will pay $150k/month for a 3ms edge on the competition • JVM GC pauses are frequently bigger than this • Consider a Direct Market Access application • Parse, validate, serialize message, check risk, read market data, serialize, send • JVM can do this in ~10 microsecs, just as fast as C/C++ • Admittedly you have to write very non-idiomatic code, and complete warmup • FPGA ~1 microsec • ASIC ~400 nanosecs • Python 50x slower
  • 20. Should I run Java on the JVM? 1. Should I run Java on the JVM? 2. Should I run Java on the JVM?
  • 21. Sun/Oracle Hotspot JVM JIT • Method inlining, loop unrolling • On-stack replacement • Jump from interpreted code to JIT’d equivalent whenever code becomes hot • Escape analysis • Object fields are replaced with scalar values, avoiding heap allocation • Monomorphic dispatch (avoid vtable lookup) • Intrinsics (replace method with something more native) • Dynamic deoptimization • As access patterns change or new classes loaded: undo and try again
  • 22. Sun/Oracle Hotspot JVM JIT • Two compilers, tiered compilation (as of Java 7) • C1 (Client) • Fast startup • Emits simple native code • Still faster than executing bytecode in an interpreter • C2 (Server) • Generates better native code • Decides how best to optimize based on execution profiles • May frequently de-optimize • Old, complex C++ codebase (needs replacing – more on this later)
  • 23. Sun/Oracle Hotspot JVM JIT • Tiered compilation • Level 0 – interpreted code • Level 1 – simple C1 compiled code (with no profiling) • Level 2 – limited C1 compiled code (with light profiling) • Level 3 – full C1 compiled code (with full profiling) • Level 4 – C2 compiled code (uses profiling data from previous steps) • Usually 0 -> 3 -> 4 • More complex code warrants more profiling, compilation
  • 24. Sun/Oracle Hotspot JVM GC • G1 (Java 8) • Specify your latency requirements (“20 ms is the longest I’d wait for GC”) • ZGC (Java 11) • Low (<10ms) pause times even on multi-terabyte heaps • Future support: multi-tiered heaps (hot objects in DRAM, cold in NVMe flash) • Heap compression • Pointer colouring (sell more SPARC machines) • Shenandoah (Java 12) • Low, constant pause time • Most work done concurrently
  • 25. Dalvik • Google’s implementation of JVM for Android • Caused Oracle to sue Google for 9 years (so far) • Uses registers as primarily unit of data-storage instead of stack • Avoid instruction dispatch, unnecessary memory access • Higher semantic density per instruction • 30% fewer instructions, 35% fewer code units • 35% more bytes in instruction stream (but we consume two at a time) • Combines .class files into .dex (Dalvik Executables) • De-dupes any repeated information, saving 50% space
  • 26. OpenJDK vs Oracle JDK • Around Java SE 7, various JVMs converged. • Oracle provided some extra ”commercial features” • Incident analysis • Font rendering • Class sharing (for faster startup, smaller footprint) • ZGC garbage collector • For Java 11, Oracle upstreamed these. Basically the same now. • Oracle JDK is (now) commercial • OpenJDK is (now) provided by Red Hat (previously Oracle)
  • 27. Hipster JVMs • Amazon Corretto • Zero-cost LTS • Azul Zing • Faster startup (saves previously-used JIT profile for re-use) • Falcon JIT (high-performance server JIT based on LLVM) • C4 garbage collector (concurrent, compacting, no GC pause) • TeaVM • AoT compiles JVM bytecode to JS or WebAssembly • GraalVM (more on this later)
  • 28. Hipster JVMs • Or use the CLR • Not standards-compliant • Due to native interface
  • 29. Should I run Java on the JVM? 1. Should I run Java on the JVM? 2. Should I run Java on the JVM?
  • 30. JavaScript on the JVM • Rhino; Java 1.4/1997 – part of an all-Java Netscape Navigator • JVM JIT outperformed C++, but memory leaky and slow startup • Interpreted mode was • Nashorn; Java 8/2011 • “Several orders of magnitude” faster • Deprecated in Java 11 because JavaScript was changing too fast to keep up • GraalVM • Suggested as a way to replace Nashorn • More on this later
  • 31. Other JVM languages • Scala • Has a “criticism” section on Wikipedia • Kotlin • Made by JetBrains (i.e. IntelliJ, Resharper) • Coroutines, generators, safe navigation, elvis ?:, reification, data classes, FP • Fast compilation (aiming to be as fast as Java, and not slow like Scala) • Compiles to JS and native code • Clojure • Lisp, REPL • Compiles to JS too
  • 32. Other JVM languages • Groovy • Used for DSLs (for example data engineering) • Used for Gradle config (now being replaced by Kotlin) • JRuby • Contributed invokedynamic instruction to JVM (not used by Java!) • Dynamically changes classes and methods at runtime • Outperforms real Ruby, especially in concurrent code (thanks to JVM threads) • Jython • Sounds like it’s for people who concede JVM has good libraries, but hate Java
  • 33. GraalVM • Oracle Labs research project based on JDK 8 • Universal Virtual Machine • JVM-based languages • LLVM-based languages • Node.js, Python, Ruby, R • JIT and AoT compiler (Graal) • Language AST interpreter (Truffle) • Enables language-agnostic debugger, profiler, heap viewer • Compilation to native images, with minimal runtime (SubstrateVM)
  • 34. GraalVM – JIT Compiler (Graal) • Written in Java • Compile Java using Java, rather than C++ (“Java-on-Java”) • Generates native code (like LLVM/Clang does) • Integrates into any JDK that supports JVM CI (Compiler Interface) • JVM CI lets a JVM use as its dynamic compiler: any compiler written in Java • Oracle Labs has backported JVM CI to JDK 8 • JVM CI ships with JDK 11 proper • Replace Hotspot JIT’s C2 compiler • Optimized performance for Truffle-based languages running on JVM
  • 35. GraalVM – Ahead-of-time compilation • Uses Graal compiler too • Includes minimal runtime, SubstrateVM • Smaller memory footprint • Zero-dependency native image • Tiny filesize (Spring web application + runtime in 36MB) • Instant startup (deploy Spring web application in about 50ms) • Produce native libraries (for your other native code to link to) • Optionally include Graal compiler to complement AoT with JIT • Build image with profile-guided optimizations from previous runs
  • 36. GraalVM – Truffle • Library for building programming language implementations • Describe language as an interpreter for a self-modifying Abstract Syntax Tree • Low-overhead language interop • Performance matches or exceeds other language runtimes • General instrumentation framework • Multi-language debugging (via Chrome DevTools!) • Profiling • Heap view
  • 38. GraalVM – LLVM • GraalVM implements LLVM’s LLI tool • Directly execute programs from LLVM bitcode • First you must compile any program (e.g. C, C++, Rust) to LLVM IR • Note: platform-dependent • LLI interprets the IR, then dynamically compiles hot parts using Graal • Enables seamless interop with other dynamic languages in GraalVM
  • 39. GraalVM – Database embed • Oracle Database, MySQL • Use GraalVM languages and modules… inside a SQL statement • Write SELECT statements that: • Classify whether a string is an email address • Detect credit card brand
  • 40. GraalVM – Performance • Twitter cut their CPU usage by 13% by switching to GraalVM • Across thousands of machines running thousands of JVMs • See “Twitter’s Quest for a Wholly Graal Runtime” • Better inlining, and across language boundaries • Partial escape analysis • Remove costly object allocations in more scenarios • More aggressive speculative optimizations • Full set of optimizations only available with Enterprise license!
  • 41. Advantages compared to standard runtime • Run Node.js with large-heap configuration and JVM’s GC • V8 is tuned for browsers and small-heap scenarios • Re-use libraries from Java, R, or Python… in Node.js • Use Python for data science • Use R for plotting graphs • Use Java for Spark or Flink

Editor's Notes

  • #3: Platform was decoupled from language as of Java SE 7 https://docs.oracle.com/javase/specs/jls/se7/html/jls-0-preface7.html Java 7 JVM implements JSR 292: Supporting Dynamically Typed Languages[7] on the Java Platform, a new feature which supports dynamically typed languages in the JVM. This feature is developed within the Da Vinci Machine project whose mission is to extend the JVM so that it supports languages other than Java.[8][9]
  • #5: https://news.ycombinator.com/item?id=19825059
  • #6: *Until Java 1.7, where the platform was decoupled from the language
  • #9: https://docs.google.com/document/d/1IpYv5t3tYrH3JkctwkNQZmt8c19TAC0hxIrBdorT4y4/edit https://headcrashing.wordpress.com/2019/05/03/negotiations-failed-how-oracle-killed-java-ee/
  • #10: https://docs.google.com/document/d/1IpYv5t3tYrH3JkctwkNQZmt8c19TAC0hxIrBdorT4y4/edit https://content.pivotal.io/spring/oct-4-getting-reactive-with-spring-framework-5-0-s-ga-release-webinar
  • #12: https://devblogs.microsoft.com/dotnet/introducing-net-5/
  • #15: https://news.ycombinator.com/item?id=15955685 https://stackoverflow.com/a/295248/5257399 https://bugs.eclipse.org/bugs/show_bug.cgi?id=287795 https://bugs.openjdk.java.net/browse/JDK-4059717
  • #16: https://stackoverflow.com/a/26908101/5257399 https://stackoverflow.com/a/48599338/5257399 https://devblogs.microsoft.com/dotnet/introducing-net-core/
  • #17: https://stackoverflow.com/a/39740592/5257399
  • #18: https://blog.jessfraz.com/post/getting-towards-real-sandbox-containers/ https://blog.jessfraz.com/post/containers-zones-jails-vms/ https://twitter.com/thejsj/status/840295431779172352/photo/1?ref_src=twsrc%5Etfw%7Ctwcamp%5Etweetembed%7Ctwterm%5E840295431779172352&ref_url=https%3A%2F%2Fblue-sea-697d.quartiers047.workers.dev%3A443%2Fhttps%2Fblog.jessfraz.com%2Fpost%2Fcontainers-zones-jails-vms%2F https://blog.jessfraz.com/post/containers-security-and-echo-chambers/
  • #19: https://news.ycombinator.com/item?id=13976533 https://barahilia.github.io/blog/computers/2017/03/26/impossible-java.html
  • #20: https://www.youtube.com/watch?v=BD9cRbxWQx8&t=1776s
  • #22: https://jakubstransky.com/2018/08/28/hotspot-jvm-jit-optimisation-techniques/ https://stackoverflow.com/a/45781033/5257399 https://www.oracle.com/technetwork/java/whitepaper-135217.html
  • #23: https://dzone.com/articles/client-server-and-tiered-compilation
  • #24: https://dzone.com/articles/client-server-and-tiered-compilation
  • #25: https://www.opsian.com/blog/javas-new-zgc-is-very-exciting/
  • #26: https://stackoverflow.com/questions/2719469/why-is-the-jvm-stack-based-and-the-dalvik-vm-register-based https://markfaction.wordpress.com/2012/07/15/stack-based-vs-register-based-virtual-machine-architecture-and-the-dalvik-vm/
  • #27: https://stackoverflow.com/a/53749226/5257399 https://blog.joda.org/2018/09/do-not-fall-into-oracles-java-11-trap.html
  • #28: https://www.e4developer.com/2019/03/30/which-java-jdk-should-i-use-which-provide-free-lts/ https://www.azul.com/products/zulu-enterprise/jdk-comparison-matrix-2/ https://www.azul.com/resources/azul-technology/azul-c4-garbage-collector/
  • #33: https://stackoverflow.com/questions/1859865/what-is-jython-and-is-it-useful-at-all
  • #35: https://www.infoworld.com/article/3187868/oracles-java-on-java-experiment-picks-up-steam.html https://bugs.openjdk.java.net/browse/JDK-8062493 https://medium.com/@jponge/the-graalvm-frenzy-f54257f5932c
  • #36: https://www.infoworld.com/article/3187868/oracles-java-on-java-experiment-picks-up-steam.html https://bugs.openjdk.java.net/browse/JDK-8062493 https://medium.com/@jponge/the-graalvm-frenzy-f54257f5932c