SlideShare a Scribd company logo
1 of 55
Download to read offline
Projects Valhalla and Loom
Vadym Kazulkin, ip.labs, 6 July 2022
Contact
Vadym Kazulkin
ip.labs GmbH Bonn, Germany
Co-Organizer of the Java User Group Bonn
v.kazulkin@gmail.com
@VKazulkin
https://www.linkedin.com/in/vadymkazulkin
https://www.iplabs.de/
ip.labs
https://www.iplabs.de/
Agenda
Project Valhalla (Value Types)
Project Loom (Virtual Threads and Continuations)
Project Valhalla
Value Types
Source: http://openjdk.java.net/projects/valhalla/
Value types = Inline types = Value types
Project Valhalla
(Initial) Goal:
Reboot the layout of data in memory
Source: Brian Goetz „State of Valhalla Part 1: The Road to Valhalla”
https://openjdk.org/projects/valhalla/design-notes/state-of-valhalla/01-background
Project Valhalla
Motivation:
Hardware has changed
• Multi-core processors
• The cost of cache misses has increased
Project Valhalla
Hardware Memory Model
Source: https://www.researchgate.net/figure/Schematic-representation-of-contemporary-multi-
processor-systems-Each-processor_fig8_316231619
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
Value Types
Value Type is an immutable type that is distinguishable only by the
state of its properties
Project Valhalla
Value Types
Immutable: an instance of a value type can’t change, once it’s been
created
Identity-less: value types of the same type with the same contents
are indistinguishable from each other
Flattenable: JVMs are allowed to flatten a value type inside of its
container
Source: Brian Goetz „State of Valhalla Part 1: The Road to Valhalla”
https://openjdk.org/projects/valhalla/design-notes/state-of-valhalla/01-background
Project Valhalla
Source: Brian Goetz „State of Valhalla Part 1: The Road to Valhalla”
https://openjdk.org/projects/valhalla/design-notes/state-of-valhalla/01-background
Memory layout of XY Points Flattened memory layout of XY
Points in case of Value Type
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 value 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 value type fields)
Increases the chance of cache hits, because of hardware
prefetch of the cache lines
Project Valhalla
Value Types
value class RationalNumber {
private long nominator;
private long denominator;
……
}
Project Valhalla
Value Types
Can
• have method and field (implicitly final)
• 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 (value class is final)
• be cloned
• be Enums
• be used synchronization (IllegalMonitorStateException)
• be null *
Source: Brian Goetz „State of Valhalla Part 2: The Language Model”
https://openjdk.org/projects/valhalla/design-notes/state-of-valhalla/02-object-model
Project Valhalla
Types Hierarchy
Object
ValueObject
Value Types
2 new interfaces IdentityObject
Reference Types
Source: Brian Goetz „State of Valhalla Part 2: The Language Model”
https://openjdk.org/projects/valhalla/design-notes/state-of-valhalla/02-object-model
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
value class V {} our code
sealed abstract class V.ref permits V.val {}
will be generated
value class V.val extends V.ref {}
V – value 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
Existing Java Classes as Value Types
• Primitive Wrappers (like java.lang.Integer)
• have identity, but not only is this identity not directly useful, it can
be a source of bugs. For example, due to caching, Integers can be
accidentally compared correctly with == .
• java.util.Optional
• java.time.LocalDateTime
Source: https://docs.oracle.com/javase/8/docs/api/java/lang/doc-files/ValueBased.html
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 value classes
Source: Sergej Kuksenko „Valhalla is coming“ https://www.youtube.com/watch?v=ri5i3mnSNk8
Project Valhalla
Types Hierarchy
Object
ValueObject
Value Types
2 new interfaces IdentityObject
Reference Types
Primitive
types
Source: Brian Goetz „State of Valhalla Part 2: The Language Model”
https://openjdk.org/projects/valhalla/design-notes/state-of-valhalla/02-object-model
Project Valhalla
Primitive Types
primitive class Point implements Serializable {
private int x;
private int y;
….
}
A primitive class is a special value class whose instances can be represented as
values of a primitive type.
• The name of the class (Point) is also the name of the primitive type.
• Users of the primitive type can expect familiar primitive semantics and performance
— for example, the primitive type cannot be null.
A primitive class declaration is subject to the same constraints as value class
declarations
• the instance fields are implicitly final
• primitive type circularities in instance field types are not allowed—flattened instances
must not contain other instances of the same type.
Source: Brian Goetz „State of Valhalla Part 2: The Language Model”
https://openjdk.org/projects/valhalla/design-notes/state-of-valhalla/02-object-model
Project Valhalla
Migrations of existing code
Primitive Wrappers like Integer can be considered as value class
Primitives like int will be replaced by the primitive class int {….}
Integer == int.ref
Integer.val==int
Benefits:
• Java becomes true OOP language
• Full covariant arrays : int[] <: Integer [] <: Object []
• Future support of Specialized Generics List<int> will become easier
Source: Brian Goetz „State of Valhalla Part 2: The Language Model”
https://openjdk.org/projects/valhalla/design-notes/state-of-valhalla/02-object-model
Project Valhalla
Identity classes vs value classes vs primitives
• Use identity classes when we need mutability, layout extension, or
locking
• Consider value classes when we don’t need identity, but need
nullity or have cross-field invariants
• Consider primitive classes when we don’t need identity, nullity, or
cross-field invariants, and can tolerate the zero default that comes
with primitives
• Remember that the P.ref reference type for a primitive recovers the
benefits of a value class.
Source: Brian Goetz „State of Valhalla Part 2: The Language Model”
https://openjdk.org/projects/valhalla/design-notes/state-of-valhalla/02-object-model
Project Valhalla
Migrations of the primitives and universal generics JEPs
Source: https://openjdk.java.net/jeps/401, https://openjdk.java.net/jeps/402, https://openjdk.org/jeps/8261529
Project Valhalla
(Initial) Goal:
Reboot the layout of data in memory
shifts to
Unify the Java type system
Source: Brian Goetz „State of Valhalla Part 2: The Language Model”
https://openjdk.org/projects/valhalla/design-notes/state-of-valhalla/02-object-model
Project Value 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
• Value 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
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
JEP 428 Structured Concurrency JEP
Sources: „Structured Concurrency“ https://openjdk.org/jeps/428
Project Loom
StructuredTaskScope Class
Sources: StructuredTaskScope Class
https://download.java.net/java/early_access/loom/docs/api/jdk.incubator.concurrent/jdk/incubator/concurrent/StructuredTask
Scope.html
Project Loom
Structured Executor Example
Sources: „Structured Concurrency (Preview)“ https://openjdk.java.net/jeps/8277129
Response handle() throws ExecutionException,
InterruptedException {
try (var scope = new StructuredTaskScope.ShutdownOnFailure()) {
Future<String> user = s.fork(() -> findUser());
Future<Integer> order = s.fork(() -> fetchOrder());
scope.join(); //join both forks
scope.throwIfFailed();
// Here, both forks have succeeded, so compose their results
return new Response(user.resultNow() + order.resultNow());
}
Project Loom
Virtual Thread
Current Status:
Virtual Thread supports:
• scheduling
• parking/unparking
• waiting for a Virtual Thread to terminate
• Java Flight Recorder support
Virtual Thread -friendly APIs changes
• java.util.concurrent Locks
• java.io.Console, Reader, Writer Buffered/File/Piped I/O Streams, File
• 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:
In Preview for JDK 19 :
javac --release 19 --enable-preview --add-modules
jdk.incubator.concurrent YourClass.java
java --enable-preview --add-modules jdk.incubator.concurrent
YourClass
Source: „JEP 428: Structured Concurrency to Simplify Java Multithreaded Programming “
https://www.infoq.com/news/2022/06/java-structured-concurrency/
Project Loom
• 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 or
be configurable
ThreadFactory factory =
Thread.builder().virtual().factory();
Executor executor=
Executors.newVirtualThreadExecutor(factory);
www.iplabs.de
Accelerate Your Photo Business
Get in Touch

More Related Content

Similar to Projects Valhalla and Loom DWX 2022

Highlights from Java 10, 11 and 12 and Future of Java at Javaland 2019 By Vad...
Highlights from Java 10, 11 and 12 and Future of Java at Javaland 2019 By Vad...Highlights from Java 10, 11 and 12 and Future of Java at Javaland 2019 By Vad...
Highlights from Java 10, 11 and 12 and Future of Java at Javaland 2019 By Vad...Vadym Kazulkin
 
Scala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud FoundryScala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud FoundryPray Desai
 
Core java Basics
Core java BasicsCore java Basics
Core java BasicsRAMU KOLLI
 
Scala, Akka, and Play: An Introduction on Heroku
Scala, Akka, and Play: An Introduction on HerokuScala, Akka, and Play: An Introduction on Heroku
Scala, Akka, and Play: An Introduction on HerokuHavoc Pennington
 
02 java basics
02 java basics02 java basics
02 java basicsbsnl007
 
Apache Cayenne for WO Devs
Apache Cayenne for WO DevsApache Cayenne for WO Devs
Apache Cayenne for WO DevsWO Community
 
Hacking Java - Enhancing Java Code at Build or Runtime
Hacking Java - Enhancing Java Code at Build or RuntimeHacking Java - Enhancing Java Code at Build or Runtime
Hacking Java - Enhancing Java Code at Build or RuntimeSean P. Floyd
 
Kotlin presentation
Kotlin presentation Kotlin presentation
Kotlin presentation MobileAcademy
 
Knowledge graph construction with a façade - The SPARQL Anything Project
Knowledge graph construction with a façade - The SPARQL Anything ProjectKnowledge graph construction with a façade - The SPARQL Anything Project
Knowledge graph construction with a façade - The SPARQL Anything ProjectEnrico Daga
 
Modern Java - WeAreDevelopers - Berlin - 2023 - Ron Veen.pdf
Modern Java - WeAreDevelopers - Berlin - 2023  - Ron Veen.pdfModern Java - WeAreDevelopers - Berlin - 2023  - Ron Veen.pdf
Modern Java - WeAreDevelopers - Berlin - 2023 - Ron Veen.pdfRonVeen1
 
Java 102 intro to object-oriented programming in java
Java 102   intro to object-oriented programming in javaJava 102   intro to object-oriented programming in java
Java 102 intro to object-oriented programming in javaagorolabs
 
Unit No 2 Objects and Classes.pptx
Unit No 2 Objects and Classes.pptxUnit No 2 Objects and Classes.pptx
Unit No 2 Objects and Classes.pptxDrYogeshDeshmukh1
 

Similar to Projects Valhalla and Loom DWX 2022 (20)

Highlights from Java 10, 11 and 12 and Future of Java at Javaland 2019 By Vad...
Highlights from Java 10, 11 and 12 and Future of Java at Javaland 2019 By Vad...Highlights from Java 10, 11 and 12 and Future of Java at Javaland 2019 By Vad...
Highlights from Java 10, 11 and 12 and Future of Java at Javaland 2019 By Vad...
 
Scala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud FoundryScala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud Foundry
 
Sep 15
Sep 15Sep 15
Sep 15
 
Core java Basics
Core java BasicsCore java Basics
Core java Basics
 
Sep 15
Sep 15Sep 15
Sep 15
 
Scala, Akka, and Play: An Introduction on Heroku
Scala, Akka, and Play: An Introduction on HerokuScala, Akka, and Play: An Introduction on Heroku
Scala, Akka, and Play: An Introduction on Heroku
 
02 java basics
02 java basics02 java basics
02 java basics
 
Apache Cayenne for WO Devs
Apache Cayenne for WO DevsApache Cayenne for WO Devs
Apache Cayenne for WO Devs
 
Hacking Java - Enhancing Java Code at Build or Runtime
Hacking Java - Enhancing Java Code at Build or RuntimeHacking Java - Enhancing Java Code at Build or Runtime
Hacking Java - Enhancing Java Code at Build or Runtime
 
Javasession6
Javasession6Javasession6
Javasession6
 
Kotlin presentation
Kotlin presentation Kotlin presentation
Kotlin presentation
 
Knowledge graph construction with a façade - The SPARQL Anything Project
Knowledge graph construction with a façade - The SPARQL Anything ProjectKnowledge graph construction with a façade - The SPARQL Anything Project
Knowledge graph construction with a façade - The SPARQL Anything Project
 
Modern Java - WeAreDevelopers - Berlin - 2023 - Ron Veen.pdf
Modern Java - WeAreDevelopers - Berlin - 2023  - Ron Veen.pdfModern Java - WeAreDevelopers - Berlin - 2023  - Ron Veen.pdf
Modern Java - WeAreDevelopers - Berlin - 2023 - Ron Veen.pdf
 
Java 102 intro to object-oriented programming in java
Java 102   intro to object-oriented programming in javaJava 102   intro to object-oriented programming in java
Java 102 intro to object-oriented programming in java
 
Unit No 2 Objects and Classes.pptx
Unit No 2 Objects and Classes.pptxUnit No 2 Objects and Classes.pptx
Unit No 2 Objects and Classes.pptx
 
Concurrency
ConcurrencyConcurrency
Concurrency
 
Core_java_ppt.ppt
Core_java_ppt.pptCore_java_ppt.ppt
Core_java_ppt.ppt
 
From ontology to wiki
From ontology to wikiFrom ontology to wiki
From ontology to wiki
 
What is scala
What is scalaWhat is scala
What is scala
 
Complete Java Course
Complete Java CourseComplete Java Course
Complete Java Course
 

More from Vadym Kazulkin

How to reduce cold starts for Java Serverless applications in AWS at JCON Wor...
How to reduce cold starts for Java Serverless applications in AWS at JCON Wor...How to reduce cold starts for Java Serverless applications in AWS at JCON Wor...
How to reduce cold starts for Java Serverless applications in AWS at JCON Wor...Vadym Kazulkin
 
How to reduce cold starts for Java Serverless applications in AWS at Serverle...
How to reduce cold starts for Java Serverless applications in AWS at Serverle...How to reduce cold starts for Java Serverless applications in AWS at Serverle...
How to reduce cold starts for Java Serverless applications in AWS at Serverle...Vadym Kazulkin
 
Revolutionize DevOps lifecycle with Amazon CodeCatalyst and DevOps Guru at De...
Revolutionize DevOps lifecycle with Amazon CodeCatalyst and DevOps Guru at De...Revolutionize DevOps lifecycle with Amazon CodeCatalyst and DevOps Guru at De...
Revolutionize DevOps lifecycle with Amazon CodeCatalyst and DevOps Guru at De...Vadym Kazulkin
 
Amazon DevOps Guru for the Serverless Applications at AWS Community Day NL 2023
Amazon DevOps Guru for the Serverless Applications at AWS Community Day NL 2023Amazon DevOps Guru for the Serverless Applications at AWS Community Day NL 2023
Amazon DevOps Guru for the Serverless Applications at AWS Community Day NL 2023Vadym Kazulkin
 
Making sense of service quotas of AWS Serverless services and how to deal wit...
Making sense of service quotas of AWS Serverless services and how to deal wit...Making sense of service quotas of AWS Serverless services and how to deal wit...
Making sense of service quotas of AWS Serverless services and how to deal wit...Vadym Kazulkin
 
How to reduce cold starts for Java Serverless applications in AWS at InfoShar...
How to reduce cold starts for Java Serverless applications in AWS at InfoShar...How to reduce cold starts for Java Serverless applications in AWS at InfoShar...
How to reduce cold starts for Java Serverless applications in AWS at InfoShar...Vadym Kazulkin
 
Adopting Java for the Serverless World at Voxxed Days Bruxelles 2023
Adopting Java for the Serverless World at Voxxed Days Bruxelles 2023Adopting Java for the Serverless World at Voxxed Days Bruxelles 2023
Adopting Java for the Serverless World at Voxxed Days Bruxelles 2023Vadym Kazulkin
 
Github Copilot vs Amazon CodeWhisperer for Java developers at JCON 2023
Github Copilot vs Amazon CodeWhisperer for Java developers at JCON 2023Github Copilot vs Amazon CodeWhisperer for Java developers at JCON 2023
Github Copilot vs Amazon CodeWhisperer for Java developers at JCON 2023Vadym Kazulkin
 
AWS Lambda SnapStart: Why, How and What AWS Serverless Meetup New York Boston...
AWS Lambda SnapStart: Why, How and What AWS Serverless Meetup New York Boston...AWS Lambda SnapStart: Why, How and What AWS Serverless Meetup New York Boston...
AWS Lambda SnapStart: Why, How and What AWS Serverless Meetup New York Boston...Vadym Kazulkin
 
Revolutionize DevOps with ML capabilities. Deep dive into Amazon CodeGuru and...
Revolutionize DevOps with ML capabilities. Deep dive into Amazon CodeGuru and...Revolutionize DevOps with ML capabilities. Deep dive into Amazon CodeGuru and...
Revolutionize DevOps with ML capabilities. Deep dive into Amazon CodeGuru and...Vadym Kazulkin
 
Amazon DevOps Guru for the Serverless Applications at AWS Community Day Bene...
Amazon DevOps Guru for the Serverless Applications at  AWS Community Day Bene...Amazon DevOps Guru for the Serverless Applications at  AWS Community Day Bene...
Amazon DevOps Guru for the Serverless Applications at AWS Community Day Bene...Vadym Kazulkin
 
Amazon CodeGuru vs SonarQube for Java Developers at JCon 2022
Amazon CodeGuru vs SonarQube for Java Developers at JCon 2022Amazon CodeGuru vs SonarQube for Java Developers at JCon 2022
Amazon CodeGuru vs SonarQube for Java Developers at JCon 2022Vadym Kazulkin
 
Adopting Java for the Serverless World at JUG Saxony Day 2022
Adopting Java for the Serverless World at JUG Saxony Day 2022Adopting Java for the Serverless World at JUG Saxony Day 2022
Adopting Java for the Serverless World at JUG Saxony Day 2022Vadym Kazulkin
 
Adopting Java for the Serverless World at VoxxedDays Luxemburg
Adopting Java for the Serverless World at VoxxedDays LuxemburgAdopting Java for the Serverless World at VoxxedDays Luxemburg
Adopting Java for the Serverless World at VoxxedDays LuxemburgVadym Kazulkin
 
Revolutionize DevOps with ML capabilities. Introduction to Amazon CodeGuru an...
Revolutionize DevOps with ML capabilities. Introduction to Amazon CodeGuru an...Revolutionize DevOps with ML capabilities. Introduction to Amazon CodeGuru an...
Revolutionize DevOps with ML capabilities. Introduction to Amazon CodeGuru an...Vadym Kazulkin
 
Adopting Java for the Serverless World at JUG Bonn 2022
Adopting Java for the Serverless World at JUG Bonn 2022Adopting Java for the Serverless World at JUG Bonn 2022
Adopting Java for the Serverless World at JUG Bonn 2022Vadym Kazulkin
 
Adopting Java for the Serverless World at JUG Darmstadt 2022
Adopting Java for the Serverless World at JUG Darmstadt 2022Adopting Java for the Serverless World at JUG Darmstadt 2022
Adopting Java for the Serverless World at JUG Darmstadt 2022Vadym Kazulkin
 
Adopting Java for the Serverless World at JAX 2022
Adopting Java for the Serverless World at JAX 2022Adopting Java for the Serverless World at JAX 2022
Adopting Java for the Serverless World at JAX 2022Vadym Kazulkin
 
Adopting Java for the Serverless World at JUG Hessen 2022
Adopting Java for the Serverless World at JUG Hessen 2022Adopting Java for the Serverless World at JUG Hessen 2022
Adopting Java for the Serverless World at JUG Hessen 2022Vadym Kazulkin
 
Amazon CodeGuru vs SonarQube for Java Developers at AWS DeveloperWeek Europe ...
Amazon CodeGuru vs SonarQube for Java Developers at AWS DeveloperWeek Europe ...Amazon CodeGuru vs SonarQube for Java Developers at AWS DeveloperWeek Europe ...
Amazon CodeGuru vs SonarQube for Java Developers at AWS DeveloperWeek Europe ...Vadym Kazulkin
 

More from Vadym Kazulkin (20)

How to reduce cold starts for Java Serverless applications in AWS at JCON Wor...
How to reduce cold starts for Java Serverless applications in AWS at JCON Wor...How to reduce cold starts for Java Serverless applications in AWS at JCON Wor...
How to reduce cold starts for Java Serverless applications in AWS at JCON Wor...
 
How to reduce cold starts for Java Serverless applications in AWS at Serverle...
How to reduce cold starts for Java Serverless applications in AWS at Serverle...How to reduce cold starts for Java Serverless applications in AWS at Serverle...
How to reduce cold starts for Java Serverless applications in AWS at Serverle...
 
Revolutionize DevOps lifecycle with Amazon CodeCatalyst and DevOps Guru at De...
Revolutionize DevOps lifecycle with Amazon CodeCatalyst and DevOps Guru at De...Revolutionize DevOps lifecycle with Amazon CodeCatalyst and DevOps Guru at De...
Revolutionize DevOps lifecycle with Amazon CodeCatalyst and DevOps Guru at De...
 
Amazon DevOps Guru for the Serverless Applications at AWS Community Day NL 2023
Amazon DevOps Guru for the Serverless Applications at AWS Community Day NL 2023Amazon DevOps Guru for the Serverless Applications at AWS Community Day NL 2023
Amazon DevOps Guru for the Serverless Applications at AWS Community Day NL 2023
 
Making sense of service quotas of AWS Serverless services and how to deal wit...
Making sense of service quotas of AWS Serverless services and how to deal wit...Making sense of service quotas of AWS Serverless services and how to deal wit...
Making sense of service quotas of AWS Serverless services and how to deal wit...
 
How to reduce cold starts for Java Serverless applications in AWS at InfoShar...
How to reduce cold starts for Java Serverless applications in AWS at InfoShar...How to reduce cold starts for Java Serverless applications in AWS at InfoShar...
How to reduce cold starts for Java Serverless applications in AWS at InfoShar...
 
Adopting Java for the Serverless World at Voxxed Days Bruxelles 2023
Adopting Java for the Serverless World at Voxxed Days Bruxelles 2023Adopting Java for the Serverless World at Voxxed Days Bruxelles 2023
Adopting Java for the Serverless World at Voxxed Days Bruxelles 2023
 
Github Copilot vs Amazon CodeWhisperer for Java developers at JCON 2023
Github Copilot vs Amazon CodeWhisperer for Java developers at JCON 2023Github Copilot vs Amazon CodeWhisperer for Java developers at JCON 2023
Github Copilot vs Amazon CodeWhisperer for Java developers at JCON 2023
 
AWS Lambda SnapStart: Why, How and What AWS Serverless Meetup New York Boston...
AWS Lambda SnapStart: Why, How and What AWS Serverless Meetup New York Boston...AWS Lambda SnapStart: Why, How and What AWS Serverless Meetup New York Boston...
AWS Lambda SnapStart: Why, How and What AWS Serverless Meetup New York Boston...
 
Revolutionize DevOps with ML capabilities. Deep dive into Amazon CodeGuru and...
Revolutionize DevOps with ML capabilities. Deep dive into Amazon CodeGuru and...Revolutionize DevOps with ML capabilities. Deep dive into Amazon CodeGuru and...
Revolutionize DevOps with ML capabilities. Deep dive into Amazon CodeGuru and...
 
Amazon DevOps Guru for the Serverless Applications at AWS Community Day Bene...
Amazon DevOps Guru for the Serverless Applications at  AWS Community Day Bene...Amazon DevOps Guru for the Serverless Applications at  AWS Community Day Bene...
Amazon DevOps Guru for the Serverless Applications at AWS Community Day Bene...
 
Amazon CodeGuru vs SonarQube for Java Developers at JCon 2022
Amazon CodeGuru vs SonarQube for Java Developers at JCon 2022Amazon CodeGuru vs SonarQube for Java Developers at JCon 2022
Amazon CodeGuru vs SonarQube for Java Developers at JCon 2022
 
Adopting Java for the Serverless World at JUG Saxony Day 2022
Adopting Java for the Serverless World at JUG Saxony Day 2022Adopting Java for the Serverless World at JUG Saxony Day 2022
Adopting Java for the Serverless World at JUG Saxony Day 2022
 
Adopting Java for the Serverless World at VoxxedDays Luxemburg
Adopting Java for the Serverless World at VoxxedDays LuxemburgAdopting Java for the Serverless World at VoxxedDays Luxemburg
Adopting Java for the Serverless World at VoxxedDays Luxemburg
 
Revolutionize DevOps with ML capabilities. Introduction to Amazon CodeGuru an...
Revolutionize DevOps with ML capabilities. Introduction to Amazon CodeGuru an...Revolutionize DevOps with ML capabilities. Introduction to Amazon CodeGuru an...
Revolutionize DevOps with ML capabilities. Introduction to Amazon CodeGuru an...
 
Adopting Java for the Serverless World at JUG Bonn 2022
Adopting Java for the Serverless World at JUG Bonn 2022Adopting Java for the Serverless World at JUG Bonn 2022
Adopting Java for the Serverless World at JUG Bonn 2022
 
Adopting Java for the Serverless World at JUG Darmstadt 2022
Adopting Java for the Serverless World at JUG Darmstadt 2022Adopting Java for the Serverless World at JUG Darmstadt 2022
Adopting Java for the Serverless World at JUG Darmstadt 2022
 
Adopting Java for the Serverless World at JAX 2022
Adopting Java for the Serverless World at JAX 2022Adopting Java for the Serverless World at JAX 2022
Adopting Java for the Serverless World at JAX 2022
 
Adopting Java for the Serverless World at JUG Hessen 2022
Adopting Java for the Serverless World at JUG Hessen 2022Adopting Java for the Serverless World at JUG Hessen 2022
Adopting Java for the Serverless World at JUG Hessen 2022
 
Amazon CodeGuru vs SonarQube for Java Developers at AWS DeveloperWeek Europe ...
Amazon CodeGuru vs SonarQube for Java Developers at AWS DeveloperWeek Europe ...Amazon CodeGuru vs SonarQube for Java Developers at AWS DeveloperWeek Europe ...
Amazon CodeGuru vs SonarQube for Java Developers at AWS DeveloperWeek Europe ...
 

Recently uploaded

Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Science&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfScience&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfjimielynbastida
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Bluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfBluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfngoud9212
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 

Recently uploaded (20)

Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort ServiceHot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Science&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfScience&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdf
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
Bluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfBluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdf
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 

Projects Valhalla and Loom DWX 2022

  • 1. Projects Valhalla and Loom Vadym Kazulkin, ip.labs, 6 July 2022
  • 2. Contact Vadym Kazulkin ip.labs GmbH Bonn, Germany Co-Organizer of the Java User Group Bonn v.kazulkin@gmail.com @VKazulkin https://www.linkedin.com/in/vadymkazulkin https://www.iplabs.de/
  • 4. Agenda Project Valhalla (Value Types) Project Loom (Virtual Threads and Continuations)
  • 5. Project Valhalla Value Types Source: http://openjdk.java.net/projects/valhalla/
  • 6. Value types = Inline types = Value types
  • 7. Project Valhalla (Initial) Goal: Reboot the layout of data in memory Source: Brian Goetz „State of Valhalla Part 1: The Road to Valhalla” https://openjdk.org/projects/valhalla/design-notes/state-of-valhalla/01-background
  • 8. Project Valhalla Motivation: Hardware has changed • Multi-core processors • The cost of cache misses has increased
  • 9. Project Valhalla Hardware Memory Model Source: https://www.researchgate.net/figure/Schematic-representation-of-contemporary-multi- processor-systems-Each-processor_fig8_316231619
  • 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 Value Types Value Type is an immutable type that is distinguishable only by the state of its properties
  • 14. Project Valhalla Value Types Immutable: an instance of a value type can’t change, once it’s been created Identity-less: value types of the same type with the same contents are indistinguishable from each other Flattenable: JVMs are allowed to flatten a value type inside of its container Source: Brian Goetz „State of Valhalla Part 1: The Road to Valhalla” https://openjdk.org/projects/valhalla/design-notes/state-of-valhalla/01-background
  • 15. Project Valhalla Source: Brian Goetz „State of Valhalla Part 1: The Road to Valhalla” https://openjdk.org/projects/valhalla/design-notes/state-of-valhalla/01-background Memory layout of XY Points Flattened memory layout of XY Points in case of Value Type
  • 16. Project Valhalla Benefits: • Reduced memory usage • Reduced indirection • Increased locality Codes like a class, works like a primitive (Brian Goetz)
  • 17. Project Valhalla Benefit: Reduced Memory Usage No additional memory to store object metadata, such as flags facilitating synchronization, identity, polymorphism and garbage collection
  • 18. 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 value types are immediately present in the location in which they are needed and therefore, require no dereferencing
  • 19. 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 value type fields) Increases the chance of cache hits, because of hardware prefetch of the cache lines
  • 20. Project Valhalla Value Types value class RationalNumber { private long nominator; private long denominator; …… }
  • 21. Project Valhalla Value Types Can • have method and field (implicitly final) • 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 (value class is final) • be cloned • be Enums • be used synchronization (IllegalMonitorStateException) • be null * Source: Brian Goetz „State of Valhalla Part 2: The Language Model” https://openjdk.org/projects/valhalla/design-notes/state-of-valhalla/02-object-model
  • 22. Project Valhalla Types Hierarchy Object ValueObject Value Types 2 new interfaces IdentityObject Reference Types Source: Brian Goetz „State of Valhalla Part 2: The Language Model” https://openjdk.org/projects/valhalla/design-notes/state-of-valhalla/02-object-model
  • 23. New java.util.Objects.newIdentity method Source: http://mail.openjdk.java.net/pipermail/core-libs-dev/2021-June/079472.html
  • 24. Project Valhalla Reference and Value Projection value class V {} our code sealed abstract class V.ref permits V.val {} will be generated value class V.val extends V.ref {} V – value 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
  • 25. Existing Java Classes as Value Types • Primitive Wrappers (like java.lang.Integer) • have identity, but not only is this identity not directly useful, it can be a source of bugs. For example, due to caching, Integers can be accidentally compared correctly with == . • java.util.Optional • java.time.LocalDateTime Source: https://docs.oracle.com/javase/8/docs/api/java/lang/doc-files/ValueBased.html
  • 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 value classes Source: Sergej Kuksenko „Valhalla is coming“ https://www.youtube.com/watch?v=ri5i3mnSNk8
  • 27. Project Valhalla Types Hierarchy Object ValueObject Value Types 2 new interfaces IdentityObject Reference Types Primitive types Source: Brian Goetz „State of Valhalla Part 2: The Language Model” https://openjdk.org/projects/valhalla/design-notes/state-of-valhalla/02-object-model
  • 28. Project Valhalla Primitive Types primitive class Point implements Serializable { private int x; private int y; …. } A primitive class is a special value class whose instances can be represented as values of a primitive type. • The name of the class (Point) is also the name of the primitive type. • Users of the primitive type can expect familiar primitive semantics and performance — for example, the primitive type cannot be null. A primitive class declaration is subject to the same constraints as value class declarations • the instance fields are implicitly final • primitive type circularities in instance field types are not allowed—flattened instances must not contain other instances of the same type. Source: Brian Goetz „State of Valhalla Part 2: The Language Model” https://openjdk.org/projects/valhalla/design-notes/state-of-valhalla/02-object-model
  • 29. Project Valhalla Migrations of existing code Primitive Wrappers like Integer can be considered as value class Primitives like int will be replaced by the primitive class int {….} Integer == int.ref Integer.val==int Benefits: • Java becomes true OOP language • Full covariant arrays : int[] <: Integer [] <: Object [] • Future support of Specialized Generics List<int> will become easier Source: Brian Goetz „State of Valhalla Part 2: The Language Model” https://openjdk.org/projects/valhalla/design-notes/state-of-valhalla/02-object-model
  • 30. Project Valhalla Identity classes vs value classes vs primitives • Use identity classes when we need mutability, layout extension, or locking • Consider value classes when we don’t need identity, but need nullity or have cross-field invariants • Consider primitive classes when we don’t need identity, nullity, or cross-field invariants, and can tolerate the zero default that comes with primitives • Remember that the P.ref reference type for a primitive recovers the benefits of a value class. Source: Brian Goetz „State of Valhalla Part 2: The Language Model” https://openjdk.org/projects/valhalla/design-notes/state-of-valhalla/02-object-model
  • 31. Project Valhalla Migrations of the primitives and universal generics JEPs Source: https://openjdk.java.net/jeps/401, https://openjdk.java.net/jeps/402, https://openjdk.org/jeps/8261529
  • 32. Project Valhalla (Initial) Goal: Reboot the layout of data in memory shifts to Unify the Java type system Source: Brian Goetz „State of Valhalla Part 2: The Language Model” https://openjdk.org/projects/valhalla/design-notes/state-of-valhalla/02-object-model
  • 33. Project Value 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 • Value 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
  • 34. Project Loom Virtual Thread and Continuations Source: http://openjdk.java.net/projects/loom
  • 35. Virtual Threads = Fibers=Lightweight Threads
  • 36. 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
  • 37. Project Loom Goal: To write simple and scalable code
  • 38. 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/
  • 39. Project Loom Continuation Continuation is a program object, representing a computation that may be suspended and resumed
  • 40. 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() }
  • 41. 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
  • 42. Project Loom Virtual Thread & Continuations Thread = Continuation + Schedular
  • 43. 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
  • 44. Project Loom Virtual Thread Implementation 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
  • 45. 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/
  • 46. 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
  • 47. 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/
  • 48. Project Loom JEP 428 Structured Concurrency JEP Sources: „Structured Concurrency“ https://openjdk.org/jeps/428
  • 49. Project Loom StructuredTaskScope Class Sources: StructuredTaskScope Class https://download.java.net/java/early_access/loom/docs/api/jdk.incubator.concurrent/jdk/incubator/concurrent/StructuredTask Scope.html
  • 50. Project Loom Structured Executor Example Sources: „Structured Concurrency (Preview)“ https://openjdk.java.net/jeps/8277129 Response handle() throws ExecutionException, InterruptedException { try (var scope = new StructuredTaskScope.ShutdownOnFailure()) { Future<String> user = s.fork(() -> findUser()); Future<Integer> order = s.fork(() -> fetchOrder()); scope.join(); //join both forks scope.throwIfFailed(); // Here, both forks have succeeded, so compose their results return new Response(user.resultNow() + order.resultNow()); }
  • 51. Project Loom Virtual Thread Current Status: Virtual Thread supports: • scheduling • parking/unparking • waiting for a Virtual Thread to terminate • Java Flight Recorder support Virtual Thread -friendly APIs changes • java.util.concurrent Locks • java.io.Console, Reader, Writer Buffered/File/Piped I/O Streams, File • 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
  • 52. Project Loom Current Status: In Preview for JDK 19 : javac --release 19 --enable-preview --add-modules jdk.incubator.concurrent YourClass.java java --enable-preview --add-modules jdk.incubator.concurrent YourClass Source: „JEP 428: Structured Concurrency to Simplify Java Multithreaded Programming “ https://www.infoq.com/news/2022/06/java-structured-concurrency/
  • 53. Project Loom • 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 or be configurable ThreadFactory factory = Thread.builder().virtual().factory(); Executor executor= Executors.newVirtualThreadExecutor(factory);
  • 54.
  • 55. www.iplabs.de Accelerate Your Photo Business Get in Touch