SlideShare a Scribd company logo
Projects Valhalla and Loom at IT Tage 2021
Contact
Vadym Kazulkin
ip.labs GmbH Bonn, Germany
Co-Organizer of the Java User Group Bonn
and Serverless Bonn Meetup
v.kazulkin@gmail.com
@VKazulkin
https://www.linkedin.com/in/vadymkazulkin
https://www.iplabs.de/
ip.labs
https://www.iplabs.de/
Agenda
Project Valhalla (Inline Types)
Project Loom (Virtual Threads and Continuations)
Project Valhalla
Inline Types
Source: http://openjdk.java.net/projects/valhalla/
Inline types = Value types
Project Valhalla
(Initial) Goal:
Reboot the layout of data in memory
Source: Brian Goetz, Oracle „Evolving the Java Language” https://www.youtube.com/watch?v=A-
mxj2vhVAA
Project Valhalla
Motivation:
Hardware has changed
• Multi-core
• The cost of cache misses has increased
Source: Brian Goetz, Oracle „Evolving the Java Language” https://www.youtube.com/watch?v=A-
mxj2vhVAA
Project Valhalla
Hardware Memory Model
Source: https://www.enterpriseai.news/2014/06/30/shared-memory-clusters-101/
Project Valhalla
Motivation
Source: „Latency Numbers Every Programmer Should Know”
https://colin-scott.github.io/personal_website/research/interactive_latency.html
Project Valhalla
Motivation
Source: „Latency Numbers Every Programmer Should Know”
https://colin-scott.github.io/personal_website/research/interactive_latency.html
Project Valhalla
Storing objects in the Java Heap has its price, because storing
object’s metadata consumes additional memory for :
• flags facilitating synchronization/locking
• Identity and polymorphismus
• garbage collection
Project Valhalla
Inline Types
Inline Type is an immutable type that is distinguishable only by the
state of its properties
Project Valhalla
Inline Types
Immutable: an instance of an inline-type can’t change, once it’s
been created
Identity-less: inline-types of the same type with the same contents
are indistinguishable from each other
Flattenable: JVMs are allowed to flatten an inline-type inside of its
container
Source: Tobi Ajila “Welcome to LWorld: The current state of value types in Java “
https://www.youtube.com/watch?v=Xf22I16jVyE&list=LLYgjRSI2oCzI9eooyFrWR7A&index=11
Existing Java Classes as Inline Types
• java.lang.Integer
• java.util.Optional
• java.time.LocalDateTime
Source: https://docs.oracle.com/javase/8/docs/api/java/lang/doc-files/ValueBased.html
Project Valhalla
Source: „What Is Project Valhalla?” https://dzone.com/articles/what-is-project-valhalla
Project Valhalla
Benefits:
• Reduced memory usage
• Reduced indirection
• Increased locality
Codes like a class, works like a primitive
(Brian Goetz)
Project Valhalla
Benefit: Reduced Memory Usage
No additional memory to store object metadata, such as
flags facilitating synchronization, identity, polymorphism and
garbage collection
Project Valhalla
Benefit: Reduced indirection
Since objects are stored as reference types in Java, each time
an object is accessed it must first be dereferenced, causing
additional instructions to be executed
The flattened data associated with inline types are
immediately present in the location in which they are needed
and therefore, require no dereferencing
Project Valhalla
Benefit: Increased locality
Flattened value objects remove indirection which increases
the likelihood that values are adjacently stored in memory–
especially for arrays or other contiguous memory structures
such as classes (i.e. if a class contains inline type fields)
Increases the chance of cache hits, because of hardware
prefetch of the cache lines
Project Valhalla
Inline Types
inline class Point {long x, y ;}
Project Valhalla
Inline Types
Can
• have method and field
• implement interfaces
• extend “well-formed” abstract class
• no fields
• empty no-arg constructor
• no synchronized methods
• use encapsulation
• be generic
Can’t
• be mutated
• be sub-classed (inline class is final)
• be cloned
• be Enums
• be used synchronization (IllegalMonitorStateException)
• be null
Source: Tobi Ajila “Welcome to LWorld: The current state of value types in Java “
https://www.youtube.com/watch?v=Xf22I16jVyE&list=LLYgjRSI2oCzI9eooyFrWR7A&index=11
Project Valhalla
Types Hierarchy
Source: Tobi Ajila “Welcome to LWorld: The current state of value types in Java “
https://www.youtube.com/watch?v=Xf22I16jVyE&list=LLYgjRSI2oCzI9eooyFrWR7A&index=11
Object
InlineObject
Inline Types
2 new interfaces IdentityObject
Reference Types
New java.util.Objects.newIdentity method
Source: http://mail.openjdk.java.net/pipermail/core-libs-dev/2021-June/079472.html
Project Valhalla
Reference and Value Projection
inline class V {} our code
sealed abstract class V.ref permits V.val {}
will be generated
inline class V.val extends V.ref {}
V – inline type
V.ref - reference projection for V
V.val - value projection for V
Source: Sergej Kuksenko „Valhalla is coming“ https://www.youtube.com/watch?v=ri5i3mnSNk8
Project Valhalla
Migrations of existing code
Map <K,V> V get (Object key)
Returns the value to which the specified key is mapped, or null if this map
contains no mapping for the key.
-> Map <K,V> V.ref get (Object key)
Optional <T> o;
o=null;
-> reference projection of Optional will be used by default. Rewrite
your code to use value projection for Optional with Inline classes
Source: Sergej Kuksenko „Valhalla is coming“ https://www.youtube.com/watch?v=ri5i3mnSNk8
Project Valhalla
Types Hierarchy
Source: Tobi Ajila “Welcome to LWorld: The current state of value types in Java “
https://www.youtube.com/watch?v=Xf22I16jVyE&list=LLYgjRSI2oCzI9eooyFrWR7A&index=11
Object
InlineObject
Inline Types
2 new interfaces IdentityObject
Reference Types
Primitive
types
Project Valhalla
Migrations of existing code
Yes, what about primitives?
inline class int {….}
Integer == int.ref
Integer.val==int
Benefits:
• Java becomes true OOP language
• Full covariant arrays : int[] <: Integer [] <: Object []
• Future support of things like List<int> will become easier
Source: Sergej Kuksenko „Valhalla is coming“ https://www.youtube.com/watch?v=ri5i3mnSNk8
https://openjdk.java.net/jeps/402
Project Valhalla
Migrations of the primitives
Source: https://openjdk.java.net/jeps/401, https://openjdk.java.net/jeps/402
Project Valhalla
(Initial) Goal:
Reboot the layout of data in memory
shifts to
Unify the Java type system
Source: Brian Goetz, Oracle „Evolving the Java Language” https://www.youtube.com/watch?v=A-
mxj2vhVAA
Project Inline classes vs Records
• A record requires you to give up on extension, mutability, and the ability to
decouple the representation from the API.
• In return, you get implementations of constructors, accessors and identity-based
equals and hashCode
• Inline class requires you to give up on identity, which includes giving up on
extension and mutability, as well as some other things (e.g., synchronization).
• In return, you get a different set of benefits: flattened representation, optimized
calling sequences, and state-based equals and hashCode.
Source: https://stackoverflow.com/questions/63352151/are-java-records-intended-to-
eventually-become-value-types
Project Loom
Virtual Thread and Continuations
Source: http://openjdk.java.net/projects/loom
Virtual Threads = Fibers=Lightweight Threads
Project Loom
Motivation:
Developers currently have 2 choices to write concurrent
code:
• use blocking/synchronous API, which is simple, but less scalable (number of
threads, that OS supports is far less that open and concurrent connections
required)
• asynchronous API (Spring Project Reactor, RXJava 2), which is scalable, but
complex, harder to debug and profile and limited (no asynchronous JDBC
standard in this area)
Sources: Alan Bateman, Oracle „Project Loom: Fibers and Continuations for Java”
https://www.youtube.com/watch?v=vbGbXUjlRyQ
Project Loom
Goal:
To write simple and scalable code
Project Loom
Lightweight Thread
Virtual thread scheduled not by the OS, but by the Java Runtime
with low memory footprint and low task-switching cost
Sources: https://inside.java/2020/07/29/loom-accentodev/
Project Loom
Continuation
Continuation is a program object, representing a computation that
may be suspended and resumed
Continuation
package java.lang;
public class Continuation {
public Continuation (ContinuationScope scope, Runnable target)
public final void run()
public static void yield (ContinuationScope scope)
public boolean isDone()
}
Project Loom
Continuations
example () {
var scope = new ContinuationScope(„Example_Scope“);
var continuation = new Continuation (scope, () -> {
out.print(„1“);
Continuation.yield(scope);
out.print(„2“);
Continuation.yield(scope);
out.print(„3“);
Continuation.yield(scope);
});
while (! continuation.isDone()) {
out.print(„ run.. “);
continuation.run();
}
}
Output: run.. 1 run.. 2 run.. 3
Project Loom
Virtual Thread & Continuations
Thread
=
Continuation + Schedular
Project Loom
Schedular
Schedular executes the task on a pool of carrier threads
java.util.concurrent.Executor API exposes the Schedular
Default schedular is a ForJoinPool
Source: Alan Bateman, Oracle „Project Loom Update” https://www.youtube.com/watch?v=NV46KFV1m-4
Project Loom
Virtual Thread Implementation
Currently Thread and Virtual Thread don’t have a common
supertype
Thread.currentThread() in context of Virtual Thread
• Creates adaptor (Shadow Thread)
• Adaptor emulates legacy Thread API (except deprecated methods like stop,
suspend and resume)
• Thread Local becomes Virtual Thread Local
Source: Alan Bateman, Oracle „Project Loom Update” https://www.youtube.com/watch?v=NV46KFV1m-4
Project Loom
Virtual Thread Implementation
Thread t = Thread.startVirtualThread (() -> {
System.out.println(„Hello World“);
});
Thread t = Thread.builder().virtual().task( () -> { … }).build();
Thread t = Thread.builder().virtual().task( () -> { … }).start();
ThreadFactory factory = Thread.builder().virtual().factory();
Source: Ron Pressler: “Project Loom: Modern Scalable Concurrency for the Java”
https://www.youtube.com/watch?v=23HjZBOIshY
https://cr.openjdk.java.net/~rpressler/loom/loom/
Project Loom
Structured Concurrency
Basic idea: Everytime that the control splits into multiple
concurrent paths, we want to guarantee that they join up again
try (var executor= Executors.newVirtualThreadExecutor()) {
executor.submit(task1);
executor.submit(task2);
} //blocks until task1 and task2 terminate
Sources: Nathanial J. Smith „Notes on structured concurrency, or: Go statement considered harmful”
https://vorpus.org/blog/notes-on-structured-concurrency-or-go-statement-considered-harmful/
R. Elizarov: “Structured concurrency with Coroutines in Kotlin” https://medium.com/@elizarov/structured-concurrency-
722d765aa952
Project Loom
Structured Concurrency
Cancelation :
We can also give all tasks a deadline that will interrupt those children
that have yet to terminate by the time it expires (as well as the current
thread)
try (var executor= Executors.newVirtualThreadExecutor().
withDeadline(Instant.now().plusSeconds(60))) {
executor.submit(task1);
executor.submit(task2);
}
Source: Ron Pressler: “Project Loom: Modern Scalable Concurrency for the Java Platform”
https://www.youtube.com/watch?v=EO9oMiL1fFo https://cr.openjdk.java.net/~rpressler/loom/loom/
Project Loom
Structured Concurrency JEP
Sources: „Structured Concurrency (Preview)“ https://openjdk.java.net/jeps/8277129
Project Loom
Structured Executor Class
Sources: StructuredExecutor Class
https://download.java.net/java/early_access/loom/docs/api/java.base/java/util/concurrent/StructuredExecutor.html
Project Loom
Structured Executor Example
Sources: „Structured Concurrency (Preview)“ https://openjdk.java.net/jeps/8277129
String foo() throws IOException, InterruptedException {
try (var s = StructuredExecutor.open()) {
var handler = new StructuredExecutor.ShutdownOnFailure();
Future<Integer> bar = s.fork(() -> bar(), handler);
Future<String> baz = s.fork(() -> baz(), handler);
s.join();
handler.throwIfFailed();
return baz.resultNow() + bar.resultNow();
} catch (ExecutionException e) { …}
Project Loom
Virtual Thread
Current Status:
Virtual Thread currently supports:
• scheduling
• parking/unparking
• waiting for a Virtual Thread to terminate
Virtual Thread -friendly APIs
• java.util.concurrent Locks
• java.io.Console, Reader, Writer Buffered/File/Piped I/O Streams
• Java.util.concurrent Executors, SynchronousQueue,
• java.net.Socket/ServerSocket/InetAdress (
• java.nio.channels.SocketChannel and Pipes
• Thread.sleep
• JSSE implementation of TLS
• AccessControl.doPrivileged
Source: Ron Pressler, Project Loom: Helping Write Concurrent Applications on the Java Platform
https://www.youtube.com/watch?v=lIq-x_iI-kc
Project Loom
Current Status:
• Refine the prototype with Continuation and Virtual Thread
support
• Current prototype of Continuations and Virtual Thread can
run existing code
• Debugger Support
Current focus on:
• Performance improvements
• Stable Virtual Thread API
• Java Flight Recorder support
Source: Alan Bateman, Oracle „Project Loom Update” https://www.youtube.com/watch?v=NV46KFV1m-4
Project Loom
Open Questions:
Should the existing Thread API be completely re-examined?
Can all existing code be run on top of Virtual Threads?
Current answers:
• Since Java 5 and 6 developers and library creators are
encouraged to use Executors and ThreadFactory APIs instead of
Thread directly
• In order to use Virtual Thread instead of Thread another Executor
implementation must be chosen
ThreadFactory factory = Thread.builder().virtual().factory();
Executor executor= Executors.newVirtualThreadExecutor(factory);
Projects Valhalla and Loom at IT Tage 2021
www.iplabs.de
Accelerate Your Photo Business
Get in Touch

More Related Content

PPTX
Projects Valhalla, Loom and GraalVM at JCon 2020
PDF
Projects Valhalla, Loom and GraalVM at JUG Mainz
PPTX
Using Apache Camel as AKKA
PDF
Akka Streams in Action @ ScalaDays Berlin 2016
PPTX
Scala in the Wild
PPTX
Apache Cayenne: a Java ORM Alternative
PPTX
Exploring Java Heap Dumps (Oracle Code One 2018)
PPTX
Full stack development with node and NoSQL - All Things Open - October 2017
Projects Valhalla, Loom and GraalVM at JCon 2020
Projects Valhalla, Loom and GraalVM at JUG Mainz
Using Apache Camel as AKKA
Akka Streams in Action @ ScalaDays Berlin 2016
Scala in the Wild
Apache Cayenne: a Java ORM Alternative
Exploring Java Heap Dumps (Oracle Code One 2018)
Full stack development with node and NoSQL - All Things Open - October 2017

What's hot (20)

PDF
7 New Tools Java Developers Should Know
PDF
Finding Patterns in the Clouds - Cloud Design Patterns
PDF
Scala Frameworks for Web Application 2016
PPTX
Faster java ee builds with gradle [con4921]
PDF
React, GraphQL и Relay - вполне себе нормальный компонентный подход (nodkz)
PPTX
Alberto Maria Angelo Paro - Isomorphic programming in Scala and WebDevelopmen...
PDF
Java APIs - the missing manual
PDF
Best Practices for Middleware and Integration Architecture Modernization with...
PPT
Introduction to the intermediate Python - v1.1
PDF
Ruby performance - The low hanging fruit
PPTX
Improving the Design of Existing Software
PDF
2015 Java update and roadmap, JUG sevilla
PPTX
Why akka
PPTX
Introducing domain driven design - dogfood con 2018
PPTX
Most Useful Design Patterns
PPTX
Apache Camel K - Copenhagen
PPTX
Serverless integration with Knative and Apache Camel on Kubernetes
PDF
Google AppEngine (GAE/J) - Introduction and Overview from a Java Guy
PDF
Scala Days NYC 2016
PPTX
Show Some Spine!
7 New Tools Java Developers Should Know
Finding Patterns in the Clouds - Cloud Design Patterns
Scala Frameworks for Web Application 2016
Faster java ee builds with gradle [con4921]
React, GraphQL и Relay - вполне себе нормальный компонентный подход (nodkz)
Alberto Maria Angelo Paro - Isomorphic programming in Scala and WebDevelopmen...
Java APIs - the missing manual
Best Practices for Middleware and Integration Architecture Modernization with...
Introduction to the intermediate Python - v1.1
Ruby performance - The low hanging fruit
Improving the Design of Existing Software
2015 Java update and roadmap, JUG sevilla
Why akka
Introducing domain driven design - dogfood con 2018
Most Useful Design Patterns
Apache Camel K - Copenhagen
Serverless integration with Knative and Apache Camel on Kubernetes
Google AppEngine (GAE/J) - Introduction and Overview from a Java Guy
Scala Days NYC 2016
Show Some Spine!
Ad

Similar to Projects Valhalla and Loom at IT Tage 2021 (20)

PDF
JavaFest. Вадим Казулькин. Projects Valhalla, Loom and GraalVM
PDF
Projects Valhalla, Loom and GraalVM at virtual JavaFest 2020 in Kiev, Ukraine...
PDF
Projects Valhalla and Loom DWX 2022
PDF
Does Java Need Inline Types? What Project Valhalla Can Bring to Java
PDF
Highlights from Java 10-13 and Future of Java at JCON 2019 by Alukhanov and K...
PPTX
Introduction to value types
PDF
Jvmls 2019 feedback valhalla update
PDF
Java Full Throttle
PPTX
Advanced java course
PDF
Highlights from Java 10, 11 and 12 and Future of Java at Javaland 2019 By Vad...
PDF
Jax keynote
PPTX
Comparing Golang and understanding Java Value Types
PPT
Intro to Java for C++ Developers
PPT
Java Basics
PDF
Learning Java Beginning programming with java for dummies First Edition John ...
PDF
Learning Java Beginning programming with java for dummies First Edition John ...
PDF
Post-graduate course: Object technology: Prototype-based object-oriented prog...
PPTX
GOTO Night with Charles Nutter Slides
PPTX
Java and the JVM
PDF
Java Enterprise Edition
JavaFest. Вадим Казулькин. Projects Valhalla, Loom and GraalVM
Projects Valhalla, Loom and GraalVM at virtual JavaFest 2020 in Kiev, Ukraine...
Projects Valhalla and Loom DWX 2022
Does Java Need Inline Types? What Project Valhalla Can Bring to Java
Highlights from Java 10-13 and Future of Java at JCON 2019 by Alukhanov and K...
Introduction to value types
Jvmls 2019 feedback valhalla update
Java Full Throttle
Advanced java course
Highlights from Java 10, 11 and 12 and Future of Java at Javaland 2019 By Vad...
Jax keynote
Comparing Golang and understanding Java Value Types
Intro to Java for C++ Developers
Java Basics
Learning Java Beginning programming with java for dummies First Edition John ...
Learning Java Beginning programming with java for dummies First Edition John ...
Post-graduate course: Object technology: Prototype-based object-oriented prog...
GOTO Night with Charles Nutter Slides
Java and the JVM
Java Enterprise Edition
Ad

More from Vadym Kazulkin (20)

PDF
How to develop, run and optimize Spring Boot 3 application on AWS Lambda - Wa...
PDF
Event-driven architecture patterns in highly scalable image storage solution-...
PDF
High performance Serverless Java on AWS- Serverless Architecture Javaland 2025
PDF
How to develop, run and optimize Spring Boot 3 application on AWS Lambda-OBI ...
PPTX
Making sense of AWS Serverless operations- AWS User Group Nuremberg
PDF
How to develop, run and optimize Spring Boot 3 application on AWS Lambda at V...
PPTX
Making sense of AWS Serverless operations at Believe in Serverless community ...
PDF
How to develop, run and optimize Spring Boot 3 application on AWS Lambda at I...
PDF
Making sense of AWS Serverless operations - Amarathon Geek China 2024
PDF
Event-driven architecture patterns in highly scalable image storage solution-...
PDF
High performance Serverless Java on AWS- Serverless Meetup Toronto
PDF
High performance Serverless Java on AWS- Serverless Architecture Conference B...
PDF
Making sense of AWS Serverless operations- Serverless Architecture Conference...
PDF
Detect operational anomalies in Serverless Applications with Amazon DevOps Gu...
PDF
Detect operational anomalies in Serverless Applications with Amazon DevOps Gu...
PDF
High performance Serverless Java on AWS- AWS Community Day Budapest 2024
PDF
Making sense of AWS Serverless operations AWS Community Day NL 2024-
PDF
Event-driven architecture patterns in highly scalable image storage solution ...
PDF
Detect operational anomalies in Serverless Applications with Amazon DevOps Gu...
PDF
High performance Serverless Java on AWS at We Are Developers 2024
How to develop, run and optimize Spring Boot 3 application on AWS Lambda - Wa...
Event-driven architecture patterns in highly scalable image storage solution-...
High performance Serverless Java on AWS- Serverless Architecture Javaland 2025
How to develop, run and optimize Spring Boot 3 application on AWS Lambda-OBI ...
Making sense of AWS Serverless operations- AWS User Group Nuremberg
How to develop, run and optimize Spring Boot 3 application on AWS Lambda at V...
Making sense of AWS Serverless operations at Believe in Serverless community ...
How to develop, run and optimize Spring Boot 3 application on AWS Lambda at I...
Making sense of AWS Serverless operations - Amarathon Geek China 2024
Event-driven architecture patterns in highly scalable image storage solution-...
High performance Serverless Java on AWS- Serverless Meetup Toronto
High performance Serverless Java on AWS- Serverless Architecture Conference B...
Making sense of AWS Serverless operations- Serverless Architecture Conference...
Detect operational anomalies in Serverless Applications with Amazon DevOps Gu...
Detect operational anomalies in Serverless Applications with Amazon DevOps Gu...
High performance Serverless Java on AWS- AWS Community Day Budapest 2024
Making sense of AWS Serverless operations AWS Community Day NL 2024-
Event-driven architecture patterns in highly scalable image storage solution ...
Detect operational anomalies in Serverless Applications with Amazon DevOps Gu...
High performance Serverless Java on AWS at We Are Developers 2024

Recently uploaded (20)

PDF
WOOl fibre morphology and structure.pdf for textiles
PDF
Taming the Chaos: How to Turn Unstructured Data into Decisions
PPTX
Benefits of Physical activity for teenagers.pptx
PDF
TrustArc Webinar - Click, Consent, Trust: Winning the Privacy Game
PDF
sustainability-14-14877-v2.pddhzftheheeeee
PDF
Hybrid model detection and classification of lung cancer
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PDF
A Late Bloomer's Guide to GenAI: Ethics, Bias, and Effective Prompting - Boha...
PDF
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
PDF
NewMind AI Weekly Chronicles – August ’25 Week III
PPT
Module 1.ppt Iot fundamentals and Architecture
PPT
What is a Computer? Input Devices /output devices
PPTX
Web Crawler for Trend Tracking Gen Z Insights.pptx
PDF
Hybrid horned lizard optimization algorithm-aquila optimizer for DC motor
PPT
Geologic Time for studying geology for geologist
PDF
Architecture types and enterprise applications.pdf
PDF
A novel scalable deep ensemble learning framework for big data classification...
PDF
1 - Historical Antecedents, Social Consideration.pdf
PPTX
Modernising the Digital Integration Hub
DOCX
search engine optimization ppt fir known well about this
WOOl fibre morphology and structure.pdf for textiles
Taming the Chaos: How to Turn Unstructured Data into Decisions
Benefits of Physical activity for teenagers.pptx
TrustArc Webinar - Click, Consent, Trust: Winning the Privacy Game
sustainability-14-14877-v2.pddhzftheheeeee
Hybrid model detection and classification of lung cancer
Group 1 Presentation -Planning and Decision Making .pptx
A Late Bloomer's Guide to GenAI: Ethics, Bias, and Effective Prompting - Boha...
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
NewMind AI Weekly Chronicles – August ’25 Week III
Module 1.ppt Iot fundamentals and Architecture
What is a Computer? Input Devices /output devices
Web Crawler for Trend Tracking Gen Z Insights.pptx
Hybrid horned lizard optimization algorithm-aquila optimizer for DC motor
Geologic Time for studying geology for geologist
Architecture types and enterprise applications.pdf
A novel scalable deep ensemble learning framework for big data classification...
1 - Historical Antecedents, Social Consideration.pdf
Modernising the Digital Integration Hub
search engine optimization ppt fir known well about this

Projects Valhalla and Loom at IT Tage 2021

  • 2. Contact Vadym Kazulkin ip.labs GmbH Bonn, Germany Co-Organizer of the Java User Group Bonn and Serverless Bonn Meetup v.kazulkin@gmail.com @VKazulkin https://www.linkedin.com/in/vadymkazulkin https://www.iplabs.de/
  • 4. Agenda Project Valhalla (Inline Types) Project Loom (Virtual Threads and Continuations)
  • 5. Project Valhalla Inline Types Source: http://openjdk.java.net/projects/valhalla/
  • 6. Inline types = Value types
  • 7. Project Valhalla (Initial) Goal: Reboot the layout of data in memory Source: Brian Goetz, Oracle „Evolving the Java Language” https://www.youtube.com/watch?v=A- mxj2vhVAA
  • 8. Project Valhalla Motivation: Hardware has changed • Multi-core • The cost of cache misses has increased Source: Brian Goetz, Oracle „Evolving the Java Language” https://www.youtube.com/watch?v=A- mxj2vhVAA
  • 9. Project Valhalla Hardware Memory Model Source: https://www.enterpriseai.news/2014/06/30/shared-memory-clusters-101/
  • 10. Project Valhalla Motivation Source: „Latency Numbers Every Programmer Should Know” https://colin-scott.github.io/personal_website/research/interactive_latency.html
  • 11. Project Valhalla Motivation Source: „Latency Numbers Every Programmer Should Know” https://colin-scott.github.io/personal_website/research/interactive_latency.html
  • 12. Project Valhalla Storing objects in the Java Heap has its price, because storing object’s metadata consumes additional memory for : • flags facilitating synchronization/locking • Identity and polymorphismus • garbage collection
  • 13. Project Valhalla Inline Types Inline Type is an immutable type that is distinguishable only by the state of its properties
  • 14. Project Valhalla Inline Types Immutable: an instance of an inline-type can’t change, once it’s been created Identity-less: inline-types of the same type with the same contents are indistinguishable from each other Flattenable: JVMs are allowed to flatten an inline-type inside of its container Source: Tobi Ajila “Welcome to LWorld: The current state of value types in Java “ https://www.youtube.com/watch?v=Xf22I16jVyE&list=LLYgjRSI2oCzI9eooyFrWR7A&index=11
  • 15. Existing Java Classes as Inline Types • java.lang.Integer • java.util.Optional • java.time.LocalDateTime Source: https://docs.oracle.com/javase/8/docs/api/java/lang/doc-files/ValueBased.html
  • 16. Project Valhalla Source: „What Is Project Valhalla?” https://dzone.com/articles/what-is-project-valhalla
  • 17. Project Valhalla Benefits: • Reduced memory usage • Reduced indirection • Increased locality Codes like a class, works like a primitive (Brian Goetz)
  • 18. Project Valhalla Benefit: Reduced Memory Usage No additional memory to store object metadata, such as flags facilitating synchronization, identity, polymorphism and garbage collection
  • 19. Project Valhalla Benefit: Reduced indirection Since objects are stored as reference types in Java, each time an object is accessed it must first be dereferenced, causing additional instructions to be executed The flattened data associated with inline types are immediately present in the location in which they are needed and therefore, require no dereferencing
  • 20. Project Valhalla Benefit: Increased locality Flattened value objects remove indirection which increases the likelihood that values are adjacently stored in memory– especially for arrays or other contiguous memory structures such as classes (i.e. if a class contains inline type fields) Increases the chance of cache hits, because of hardware prefetch of the cache lines
  • 21. Project Valhalla Inline Types inline class Point {long x, y ;}
  • 22. Project Valhalla Inline Types Can • have method and field • implement interfaces • extend “well-formed” abstract class • no fields • empty no-arg constructor • no synchronized methods • use encapsulation • be generic Can’t • be mutated • be sub-classed (inline class is final) • be cloned • be Enums • be used synchronization (IllegalMonitorStateException) • be null Source: Tobi Ajila “Welcome to LWorld: The current state of value types in Java “ https://www.youtube.com/watch?v=Xf22I16jVyE&list=LLYgjRSI2oCzI9eooyFrWR7A&index=11
  • 23. Project Valhalla Types Hierarchy Source: Tobi Ajila “Welcome to LWorld: The current state of value types in Java “ https://www.youtube.com/watch?v=Xf22I16jVyE&list=LLYgjRSI2oCzI9eooyFrWR7A&index=11 Object InlineObject Inline Types 2 new interfaces IdentityObject Reference Types
  • 24. New java.util.Objects.newIdentity method Source: http://mail.openjdk.java.net/pipermail/core-libs-dev/2021-June/079472.html
  • 25. Project Valhalla Reference and Value Projection inline class V {} our code sealed abstract class V.ref permits V.val {} will be generated inline class V.val extends V.ref {} V – inline type V.ref - reference projection for V V.val - value projection for V Source: Sergej Kuksenko „Valhalla is coming“ https://www.youtube.com/watch?v=ri5i3mnSNk8
  • 26. Project Valhalla Migrations of existing code Map <K,V> V get (Object key) Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key. -> Map <K,V> V.ref get (Object key) Optional <T> o; o=null; -> reference projection of Optional will be used by default. Rewrite your code to use value projection for Optional with Inline classes Source: Sergej Kuksenko „Valhalla is coming“ https://www.youtube.com/watch?v=ri5i3mnSNk8
  • 27. Project Valhalla Types Hierarchy Source: Tobi Ajila “Welcome to LWorld: The current state of value types in Java “ https://www.youtube.com/watch?v=Xf22I16jVyE&list=LLYgjRSI2oCzI9eooyFrWR7A&index=11 Object InlineObject Inline Types 2 new interfaces IdentityObject Reference Types Primitive types
  • 28. Project Valhalla Migrations of existing code Yes, what about primitives? inline class int {….} Integer == int.ref Integer.val==int Benefits: • Java becomes true OOP language • Full covariant arrays : int[] <: Integer [] <: Object [] • Future support of things like List<int> will become easier Source: Sergej Kuksenko „Valhalla is coming“ https://www.youtube.com/watch?v=ri5i3mnSNk8 https://openjdk.java.net/jeps/402
  • 29. Project Valhalla Migrations of the primitives Source: https://openjdk.java.net/jeps/401, https://openjdk.java.net/jeps/402
  • 30. Project Valhalla (Initial) Goal: Reboot the layout of data in memory shifts to Unify the Java type system Source: Brian Goetz, Oracle „Evolving the Java Language” https://www.youtube.com/watch?v=A- mxj2vhVAA
  • 31. Project Inline classes vs Records • A record requires you to give up on extension, mutability, and the ability to decouple the representation from the API. • In return, you get implementations of constructors, accessors and identity-based equals and hashCode • Inline class requires you to give up on identity, which includes giving up on extension and mutability, as well as some other things (e.g., synchronization). • In return, you get a different set of benefits: flattened representation, optimized calling sequences, and state-based equals and hashCode. Source: https://stackoverflow.com/questions/63352151/are-java-records-intended-to- eventually-become-value-types
  • 32. Project Loom Virtual Thread and Continuations Source: http://openjdk.java.net/projects/loom
  • 33. Virtual Threads = Fibers=Lightweight Threads
  • 34. Project Loom Motivation: Developers currently have 2 choices to write concurrent code: • use blocking/synchronous API, which is simple, but less scalable (number of threads, that OS supports is far less that open and concurrent connections required) • asynchronous API (Spring Project Reactor, RXJava 2), which is scalable, but complex, harder to debug and profile and limited (no asynchronous JDBC standard in this area) Sources: Alan Bateman, Oracle „Project Loom: Fibers and Continuations for Java” https://www.youtube.com/watch?v=vbGbXUjlRyQ
  • 35. Project Loom Goal: To write simple and scalable code
  • 36. Project Loom Lightweight Thread Virtual thread scheduled not by the OS, but by the Java Runtime with low memory footprint and low task-switching cost Sources: https://inside.java/2020/07/29/loom-accentodev/
  • 37. Project Loom Continuation Continuation is a program object, representing a computation that may be suspended and resumed
  • 38. Continuation package java.lang; public class Continuation { public Continuation (ContinuationScope scope, Runnable target) public final void run() public static void yield (ContinuationScope scope) public boolean isDone() }
  • 39. Project Loom Continuations example () { var scope = new ContinuationScope(„Example_Scope“); var continuation = new Continuation (scope, () -> { out.print(„1“); Continuation.yield(scope); out.print(„2“); Continuation.yield(scope); out.print(„3“); Continuation.yield(scope); }); while (! continuation.isDone()) { out.print(„ run.. “); continuation.run(); } } Output: run.. 1 run.. 2 run.. 3
  • 40. Project Loom Virtual Thread & Continuations Thread = Continuation + Schedular
  • 41. Project Loom Schedular Schedular executes the task on a pool of carrier threads java.util.concurrent.Executor API exposes the Schedular Default schedular is a ForJoinPool Source: Alan Bateman, Oracle „Project Loom Update” https://www.youtube.com/watch?v=NV46KFV1m-4
  • 42. Project Loom Virtual Thread Implementation Currently Thread and Virtual Thread don’t have a common supertype Thread.currentThread() in context of Virtual Thread • Creates adaptor (Shadow Thread) • Adaptor emulates legacy Thread API (except deprecated methods like stop, suspend and resume) • Thread Local becomes Virtual Thread Local Source: Alan Bateman, Oracle „Project Loom Update” https://www.youtube.com/watch?v=NV46KFV1m-4
  • 43. Project Loom Virtual Thread Implementation Thread t = Thread.startVirtualThread (() -> { System.out.println(„Hello World“); }); Thread t = Thread.builder().virtual().task( () -> { … }).build(); Thread t = Thread.builder().virtual().task( () -> { … }).start(); ThreadFactory factory = Thread.builder().virtual().factory(); Source: Ron Pressler: “Project Loom: Modern Scalable Concurrency for the Java” https://www.youtube.com/watch?v=23HjZBOIshY https://cr.openjdk.java.net/~rpressler/loom/loom/
  • 44. Project Loom Structured Concurrency Basic idea: Everytime that the control splits into multiple concurrent paths, we want to guarantee that they join up again try (var executor= Executors.newVirtualThreadExecutor()) { executor.submit(task1); executor.submit(task2); } //blocks until task1 and task2 terminate Sources: Nathanial J. Smith „Notes on structured concurrency, or: Go statement considered harmful” https://vorpus.org/blog/notes-on-structured-concurrency-or-go-statement-considered-harmful/ R. Elizarov: “Structured concurrency with Coroutines in Kotlin” https://medium.com/@elizarov/structured-concurrency- 722d765aa952
  • 45. Project Loom Structured Concurrency Cancelation : We can also give all tasks a deadline that will interrupt those children that have yet to terminate by the time it expires (as well as the current thread) try (var executor= Executors.newVirtualThreadExecutor(). withDeadline(Instant.now().plusSeconds(60))) { executor.submit(task1); executor.submit(task2); } Source: Ron Pressler: “Project Loom: Modern Scalable Concurrency for the Java Platform” https://www.youtube.com/watch?v=EO9oMiL1fFo https://cr.openjdk.java.net/~rpressler/loom/loom/
  • 46. Project Loom Structured Concurrency JEP Sources: „Structured Concurrency (Preview)“ https://openjdk.java.net/jeps/8277129
  • 47. Project Loom Structured Executor Class Sources: StructuredExecutor Class https://download.java.net/java/early_access/loom/docs/api/java.base/java/util/concurrent/StructuredExecutor.html
  • 48. Project Loom Structured Executor Example Sources: „Structured Concurrency (Preview)“ https://openjdk.java.net/jeps/8277129 String foo() throws IOException, InterruptedException { try (var s = StructuredExecutor.open()) { var handler = new StructuredExecutor.ShutdownOnFailure(); Future<Integer> bar = s.fork(() -> bar(), handler); Future<String> baz = s.fork(() -> baz(), handler); s.join(); handler.throwIfFailed(); return baz.resultNow() + bar.resultNow(); } catch (ExecutionException e) { …}
  • 49. Project Loom Virtual Thread Current Status: Virtual Thread currently supports: • scheduling • parking/unparking • waiting for a Virtual Thread to terminate Virtual Thread -friendly APIs • java.util.concurrent Locks • java.io.Console, Reader, Writer Buffered/File/Piped I/O Streams • Java.util.concurrent Executors, SynchronousQueue, • java.net.Socket/ServerSocket/InetAdress ( • java.nio.channels.SocketChannel and Pipes • Thread.sleep • JSSE implementation of TLS • AccessControl.doPrivileged Source: Ron Pressler, Project Loom: Helping Write Concurrent Applications on the Java Platform https://www.youtube.com/watch?v=lIq-x_iI-kc
  • 50. Project Loom Current Status: • Refine the prototype with Continuation and Virtual Thread support • Current prototype of Continuations and Virtual Thread can run existing code • Debugger Support Current focus on: • Performance improvements • Stable Virtual Thread API • Java Flight Recorder support Source: Alan Bateman, Oracle „Project Loom Update” https://www.youtube.com/watch?v=NV46KFV1m-4
  • 51. Project Loom Open Questions: Should the existing Thread API be completely re-examined? Can all existing code be run on top of Virtual Threads? Current answers: • Since Java 5 and 6 developers and library creators are encouraged to use Executors and ThreadFactory APIs instead of Thread directly • In order to use Virtual Thread instead of Thread another Executor implementation must be chosen ThreadFactory factory = Thread.builder().virtual().factory(); Executor executor= Executors.newVirtualThreadExecutor(factory);
  • 53. www.iplabs.de Accelerate Your Photo Business Get in Touch