SlideShare a Scribd company logo
©2014 Azul Systems, Inc.	
 	
 	
 	
 	
 	
Closing the [last?] inherent C
vs. Java speed gap

Gil Tene, CTO & co-Founder, Azul Systems
http://objectlayout.org
ObjectLayout

(and StructuredArray)

!
©2014 Azul Systems, Inc.	
 	
 	
 	
 	
 	
ObjectLayout
Focus: Match the raw speed benefits C based
languages get from commonly used forms of memory
layout 

Expose these benefits to normal idiomatic POJO use

Focus: Speed. For regular Java Objects. On the heap.

Not looking for:

Improved footprint 

off-heap solutions 

immutability
These are all

orthogonal
concerns}
©2014 Azul Systems, Inc.	
 	
 	
 	
 	
 	
ObjectLayout: goal overlap?
Relationship to Value types: none

Relationship to Packet Objects (or JNR/FFI): none

Laser-focused on a different problem

Does not conflict or contradict concerns that drive
these other efforts

Minimal overlap does exist 

… The kind of overlap that ArrayList and HashMap
have as good alternatives of a bag of objects
Value
types
Packed
objects

&

JNR/FFI
ObjectLayout
precise layout
control
Speed!
For any Object
On Heap
Off Heap
Sharing data
Immutable
On-stack
Return values
Objects
usable by
all existing
code
New code
On Heap
Array of
small-footprint
values
New code
©2014 Azul Systems, Inc.	
 	
 	
 	
 	
 	
ObjectLayout Origin
ObjectLayout/StructuredArray started with a simple
argument. The common sides of the argument are:

“We need structs in Java…”: Look at all the unsafe
direct access stuff we do using flyweights over buffers
or byte arrays, just to squeeze out speed that C gets
trivially…

“We already have structs. They are called Objects.”:
What we need is competitively speedy access for the
data collection semantics that are currently faster in C

It’s all about capturing “enabling semantic limitations”
©2014 Azul Systems, Inc.	
 	
 	
 	
 	
 	
speed comes from ???
C’s layout speed benefits are dominated by two factors:

Dead reckoning: 

Data address derived from containing object address 

no data-dependent load operation

Streaming (In the case of an array of structs):

sequential access through multiple members

predictable striding access in memory

Prefetch logic compensates for miss latency
©2014 Azul Systems, Inc.	
 	
 	
 	
 	
 	
example of speed-enabling limitations
Why is Object[] inherently slower than struct foo[]?

Java: a mutable array of same-base-type objects

C: An immutable array of exact-same-type structures

Mutability (of the array itself) & non-uniform member
size both force de-reference, and both break streaming

StructuredArray<T>: An immutable array of [potentially]
mutable exact-same-type (T) objects

Supports Instantiation, get(), but not put()…
©2014 Azul Systems, Inc.	
 	
 	
 	
 	
 	
ObjectLayout target forms
Easily identified C-based layout forms:

array of structs

struct foo[];

struct with struct inside

struct foo { int a; struct bar b; int c; };

struct with array at the end

struct packet { int length; char[] body; }

None are currently (speed) matched in Java
©2014 Azul Systems, Inc.	
 	
 	
 	
 	
 	
ObjectLayout: starting point
Capture the semantics that enable speed in the various
C-like data layout forms behaviors 

Theory: we can do this all with no language change… 

Capture the needed semantics in “vanilla” Java classes
(targeting e.g. Java SE 6)

Have JDKs recognize and intrinsify behavior, optimizing
memory layout and access operations

“Vanilla” and “Intrinsified” implementation behavior
should be indistinguishable (except for speed)
©2014 Azul Systems, Inc.	
 	
 	
 	
 	
 	
Modeled after java.util.concurrent
Captured semantics enabled fast concurrent operations

No language changes. No required JVM changes.

Implementable in “vanilla” Java classes outside of JDK

e.g. AtomicLong CAS could be done with synchronized

JDKs improved to recognize and intrinsify behavior

e.g. AtomicLong CAS is a single x86 instruction

Moved into JDK and Java name space in order to secure
intrinsification and gain legitimate access to unsafe
©2014 Azul Systems, Inc.	
 	
 	
 	
 	
 	
ObjectLayout: StructuredArray
array of structs

struct foo[];

struct with struct inside

struct foo { int a; struct bar b; int c; };

struct with array at the end

struct packet { int len; char[] body; }
©2014 Azul Systems, Inc.	
 	
 	
 	
 	
 	
StructuredArray<T>
A collection of object instances of arbitrary type T

Arranged as array: T element = get(index);

Collection is immutable: cannot replace elements

Instantiated via factory method:

a = StructuredArray.newInstance(SomeClass.class, 100);

All elements constructed at instantiation time

Supports arbitrary constructor and args for members

Including support for index-specific CtorAndArgs
©2014 Azul Systems, Inc.	
 	
 	
 	
 	
 	
StructuredArray<T> liveness
We considered an “inner pointer keeps container alive”
approach, because that what other runtimes seem to do
with arrays of structs and field references

But then we realized: real objects have real liveness

A StructuredArray is just a regular idiomatic collection

The collection keeps it’s members alive

Collection members don’t (implicitly) keep it alive

*** Under the hood, optimized implementations will want
to keep the collection “together” as long as it is alive
©2014 Azul Systems, Inc.	
 	
 	
 	
 	
 	
Benefits of liveness approach
StructuredArray is just a collection of objects

No special behavior: acts like any other collection

Happens to be fast on JDKs that optimize it

Elements of a StructuredArray are regular objects

Can participate in other collections and object graphs

Can be locked

Can have an identity hashcode

Can be passed along to any existing java code

It’s “natural”, and it’s easier to support in the JVM
©2014 Azul Systems, Inc.	
 	
 	
 	
 	
 	
StructuredArray<T> continued…
Indexes are longs (it’s 2014…)

Multi dimensional support

Non-leaf Elements are themselves StructuredArrays

StructuredArray is subclassable

Supports some useful coding styles and optimizations

StructuredArray is not constructable

must be created with factory methods

(*** Did you spot that small contradiction?)
©2014 Azul Systems, Inc.	
 	
 	
 	
 	
 	
Optimized JDK implementation
A new heap concept: “contained” and “container” objects

Contained and container objects are regular objects

Given a contained object, there is a means of finding
the immediately containing object

If GC needs to move an object that is contained in a
live container object, it will move the entire container

Very simple to implement in all current OpenJDK GC
mechanisms (and in Zing’s C4, and in others, we think)

More details in workshop…
©2014 Azul Systems, Inc.	
 	
 	
 	
 	
 	
Optimized JDK implementation
Streaming benefits come directly from layout

No compiler optimizations needed

Dead-reckoning benefits require some compiler support

no dereferencing, but….

e = (T) ( a + a.bodySize + (index * a.elementSize) );

elementSize and bodySize are not constant

But optimizations similar to CHA & inline-cache apply

More details in workshop…
©2014 Azul Systems, Inc.	
 	
 	
 	
 	
 	
ObjectLayout forms 2 & 3
array of structs

struct foo[];

struct with struct inside

struct foo { int a; struct bar b; int c; };

struct with array at the end

struct packet { int len; char[] body; }
©2014 Azul Systems, Inc.	
 	
 	
 	
 	
 	
“struct in struct”: 

intrinsic objects
Object instance x is intrinsic to object instance y

Proposal: factory based instantiation of final member
objects

Class SomeClass {

int a;

final SomeOtherClass o =

IntrinsifiedObjects.createIntrinsicObject(SomeOtherClass.class);

} 

Intrinsic object can be laid out within containing object

Must deal with & survive reflection based overwrites
©2014 Azul Systems, Inc.	
 	
 	
 	
 	
 	
“struct with array at the end”:

subclassable arrays
Semantics well captured by subclassable arrays classes

ObjectLayout describes one for each primitive type. E.g.
PrimitiveLongArray, PrimitiveDoubleArray, etc…

Also ReferenceArray<T>

StructuredArray<T> is also subclassable, and captures
“struct with array of structs at the end”
©2014 Azul Systems, Inc.	
 	
 	
 	
 	
 	
Status
Vanilla Java code on github. Public domain under CC0.
See http://objectlayout.org

StructuredArray is fairly mature semantically. Other
two forms (intrinsic objects and subclassable arrays)
are getting there…

Intrinsified implementations coming over the next few
months for both Zing and OpenJDK

Next steps: OpenJDK project with working code, JEP…

Aim: Add ObjectLayout to Java SE (9?)

Vanilla implementation will work on all JDKs
©2014 Azul Systems, Inc.	
 	
 	
 	
 	
 	
ObjectLayout Summary
New Java classes: org.ObjectLayout.*

Propose to move into java namespace in Java SE (9?)

Work “out of the box” on Java 6, 7, 8, 9, …

No syntax changes, No new bytecodes 

No new required JVM behavior

Can “go fast” on JDKs that optimize for them

Relatively simple, isolated JVM changes needed

Proposing to include “go fast” in OpenJDK (9?)

Zing will support “go fast” for Java 6, 7, 8, 9, …
Q & A
@giltene
http://www.azulsystems.com
!
http://objectlayout.org

https://github.com/ObjectLayout/ObjectLayout

More Related Content

What's hot

Hibernate in Nutshell
Hibernate in NutshellHibernate in Nutshell
Hibernate in Nutshell
Onkar Deshpande
 
Spring Data JPA
Spring Data JPASpring Data JPA
Spring Data JPA
Cheng Ta Yeh
 
Spring data jpa
Spring data jpaSpring data jpa
Spring data jpa
Jeevesh Pandey
 
Optimizing Application Architecture (.NET/Java topics)
Optimizing Application Architecture (.NET/Java topics)Optimizing Application Architecture (.NET/Java topics)
Optimizing Application Architecture (.NET/Java topics)
Ravi Okade
 
Hibernate tutorial
Hibernate tutorialHibernate tutorial
Hibernate tutorial
Mumbai Academisc
 
Mahout classification presentation
Mahout classification presentationMahout classification presentation
Mahout classification presentation
Naoki Nakatani
 
Introducing DataFrames in Spark for Large Scale Data Science
Introducing DataFrames in Spark for Large Scale Data ScienceIntroducing DataFrames in Spark for Large Scale Data Science
Introducing DataFrames in Spark for Large Scale Data Science
Databricks
 
Aspect oriented programming with spring
Aspect oriented programming with springAspect oriented programming with spring
Aspect oriented programming with spring
Sreenivas Kappala
 
OrientDB Distributed Architecture v2.0
OrientDB Distributed Architecture v2.0OrientDB Distributed Architecture v2.0
OrientDB Distributed Architecture v2.0
Orient Technologies
 
NHibernate
NHibernateNHibernate
NHibernate
Andriy Buday
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
S.Shayan Daneshvar
 
Entity framework
Entity frameworkEntity framework
Entity framework
icubesystem
 
NHibernate (The ORM For .NET Platform)
NHibernate (The ORM For .NET Platform)NHibernate (The ORM For .NET Platform)
NHibernate (The ORM For .NET Platform)
Samnang Chhun
 
Spring Data - Intro (Odessa Java TechTalks)
Spring Data - Intro (Odessa Java TechTalks)Spring Data - Intro (Odessa Java TechTalks)
Spring Data - Intro (Odessa Java TechTalks)
Igor Anishchenko
 
ElasticSearch for .NET Developers
ElasticSearch for .NET DevelopersElasticSearch for .NET Developers
ElasticSearch for .NET Developers
Ben van Mol
 
icpe2019_ishizaki_public
icpe2019_ishizaki_publicicpe2019_ishizaki_public
icpe2019_ishizaki_public
Kazuaki Ishizaki
 
Spring Data in 10 minutes
Spring Data in 10 minutesSpring Data in 10 minutes
Spring Data in 10 minutes
Corneil du Plessis
 
ADO.NET Entity Framework
ADO.NET Entity FrameworkADO.NET Entity Framework
ADO.NET Entity Framework
Doncho Minkov
 
Building a modern Application with DataFrames
Building a modern Application with DataFramesBuilding a modern Application with DataFrames
Building a modern Application with DataFrames
Spark Summit
 
Approaching (almost) Any Machine Learning Problem (kaggledays dubai)
Approaching (almost) Any Machine Learning Problem (kaggledays dubai)Approaching (almost) Any Machine Learning Problem (kaggledays dubai)
Approaching (almost) Any Machine Learning Problem (kaggledays dubai)
Abhishek Thakur
 

What's hot (20)

Hibernate in Nutshell
Hibernate in NutshellHibernate in Nutshell
Hibernate in Nutshell
 
Spring Data JPA
Spring Data JPASpring Data JPA
Spring Data JPA
 
Spring data jpa
Spring data jpaSpring data jpa
Spring data jpa
 
Optimizing Application Architecture (.NET/Java topics)
Optimizing Application Architecture (.NET/Java topics)Optimizing Application Architecture (.NET/Java topics)
Optimizing Application Architecture (.NET/Java topics)
 
Hibernate tutorial
Hibernate tutorialHibernate tutorial
Hibernate tutorial
 
Mahout classification presentation
Mahout classification presentationMahout classification presentation
Mahout classification presentation
 
Introducing DataFrames in Spark for Large Scale Data Science
Introducing DataFrames in Spark for Large Scale Data ScienceIntroducing DataFrames in Spark for Large Scale Data Science
Introducing DataFrames in Spark for Large Scale Data Science
 
Aspect oriented programming with spring
Aspect oriented programming with springAspect oriented programming with spring
Aspect oriented programming with spring
 
OrientDB Distributed Architecture v2.0
OrientDB Distributed Architecture v2.0OrientDB Distributed Architecture v2.0
OrientDB Distributed Architecture v2.0
 
NHibernate
NHibernateNHibernate
NHibernate
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
Entity framework
Entity frameworkEntity framework
Entity framework
 
NHibernate (The ORM For .NET Platform)
NHibernate (The ORM For .NET Platform)NHibernate (The ORM For .NET Platform)
NHibernate (The ORM For .NET Platform)
 
Spring Data - Intro (Odessa Java TechTalks)
Spring Data - Intro (Odessa Java TechTalks)Spring Data - Intro (Odessa Java TechTalks)
Spring Data - Intro (Odessa Java TechTalks)
 
ElasticSearch for .NET Developers
ElasticSearch for .NET DevelopersElasticSearch for .NET Developers
ElasticSearch for .NET Developers
 
icpe2019_ishizaki_public
icpe2019_ishizaki_publicicpe2019_ishizaki_public
icpe2019_ishizaki_public
 
Spring Data in 10 minutes
Spring Data in 10 minutesSpring Data in 10 minutes
Spring Data in 10 minutes
 
ADO.NET Entity Framework
ADO.NET Entity FrameworkADO.NET Entity Framework
ADO.NET Entity Framework
 
Building a modern Application with DataFrames
Building a modern Application with DataFramesBuilding a modern Application with DataFrames
Building a modern Application with DataFrames
 
Approaching (almost) Any Machine Learning Problem (kaggledays dubai)
Approaching (almost) Any Machine Learning Problem (kaggledays dubai)Approaching (almost) Any Machine Learning Problem (kaggledays dubai)
Approaching (almost) Any Machine Learning Problem (kaggledays dubai)
 

Viewers also liked

KCPOS Brochure 2015 - Email
KCPOS Brochure 2015 - EmailKCPOS Brochure 2015 - Email
KCPOS Brochure 2015 - Email
Richard Wellham
 
Hair loss and Growth Problems
Hair loss and Growth ProblemsHair loss and Growth Problems
Hair loss and Growth Problems
martinaCarry
 
The Justification for an Analysis of Stakeholder Input in the National Inform...
The Justification for an Analysis of Stakeholder Input in the National Inform...The Justification for an Analysis of Stakeholder Input in the National Inform...
The Justification for an Analysis of Stakeholder Input in the National Inform...
Jeremy Pesner
 
Silicon Valley JUG: JVM Mechanics
Silicon Valley JUG: JVM MechanicsSilicon Valley JUG: JVM Mechanics
Silicon Valley JUG: JVM Mechanics
Azul Systems, Inc.
 
Immune System Defense
Immune System DefenseImmune System Defense
Immune System Defense
Jeremy Pesner
 
Рабочая программа "Эффективность общения"
Рабочая программа "Эффективность общения"Рабочая программа "Эффективность общения"
Рабочая программа "Эффективность общения"
Юрий Карабанов
 
SPACE SHUTTLE & ITS TPS
SPACE SHUTTLE  & ITS TPSSPACE SHUTTLE  & ITS TPS
SPACE SHUTTLE & ITS TPS
Nagarjuna Reddy Kolli
 
A Guide To Efficient Home Cleaning in Tweed Heads
A Guide To Efficient Home Cleaning in Tweed HeadsA Guide To Efficient Home Cleaning in Tweed Heads
A Guide To Efficient Home Cleaning in Tweed Heads
Deb Dalgleish
 
Novartis-NerdBlog
Novartis-NerdBlogNovartis-NerdBlog
Novartis-NerdBlog
Manishha Patel
 
Making Business Happen, Greater Birmingham
Making Business Happen, Greater Birmingham Making Business Happen, Greater Birmingham
Making Business Happen, Greater Birmingham
Kate Evans
 
Tech m merged2013
Tech m merged2013Tech m merged2013
Tech m merged2013
SkywayMAnoj
 
Ict Tools for Esl Teaching
Ict Tools for Esl TeachingIct Tools for Esl Teaching
Ict Tools for Esl Teaching
Yves Esle
 

Viewers also liked (12)

KCPOS Brochure 2015 - Email
KCPOS Brochure 2015 - EmailKCPOS Brochure 2015 - Email
KCPOS Brochure 2015 - Email
 
Hair loss and Growth Problems
Hair loss and Growth ProblemsHair loss and Growth Problems
Hair loss and Growth Problems
 
The Justification for an Analysis of Stakeholder Input in the National Inform...
The Justification for an Analysis of Stakeholder Input in the National Inform...The Justification for an Analysis of Stakeholder Input in the National Inform...
The Justification for an Analysis of Stakeholder Input in the National Inform...
 
Silicon Valley JUG: JVM Mechanics
Silicon Valley JUG: JVM MechanicsSilicon Valley JUG: JVM Mechanics
Silicon Valley JUG: JVM Mechanics
 
Immune System Defense
Immune System DefenseImmune System Defense
Immune System Defense
 
Рабочая программа "Эффективность общения"
Рабочая программа "Эффективность общения"Рабочая программа "Эффективность общения"
Рабочая программа "Эффективность общения"
 
SPACE SHUTTLE & ITS TPS
SPACE SHUTTLE  & ITS TPSSPACE SHUTTLE  & ITS TPS
SPACE SHUTTLE & ITS TPS
 
A Guide To Efficient Home Cleaning in Tweed Heads
A Guide To Efficient Home Cleaning in Tweed HeadsA Guide To Efficient Home Cleaning in Tweed Heads
A Guide To Efficient Home Cleaning in Tweed Heads
 
Novartis-NerdBlog
Novartis-NerdBlogNovartis-NerdBlog
Novartis-NerdBlog
 
Making Business Happen, Greater Birmingham
Making Business Happen, Greater Birmingham Making Business Happen, Greater Birmingham
Making Business Happen, Greater Birmingham
 
Tech m merged2013
Tech m merged2013Tech m merged2013
Tech m merged2013
 
Ict Tools for Esl Teaching
Ict Tools for Esl TeachingIct Tools for Esl Teaching
Ict Tools for Esl Teaching
 

Similar to JVM Language Summit: Object layout presentation

ObjectLayout: Closing the (last?) inherent C vs. Java speed gap
ObjectLayout: Closing the (last?) inherent C vs. Java speed gapObjectLayout: Closing the (last?) inherent C vs. Java speed gap
ObjectLayout: Closing the (last?) inherent C vs. Java speed gap
Azul Systems Inc.
 
JVM Language Summit: Object layout workshop
JVM Language Summit: Object layout workshopJVM Language Summit: Object layout workshop
JVM Language Summit: Object layout workshop
Azul Systems, Inc.
 
Eclipse Day India 2011 - Extending JDT
Eclipse Day India 2011 - Extending JDTEclipse Day India 2011 - Extending JDT
Eclipse Day India 2011 - Extending JDT
deepakazad
 
How to train the jdt dragon
How to train the jdt dragonHow to train the jdt dragon
How to train the jdt dragon
Ayushman Jain
 
Hibernate
HibernateHibernate
iPhone development from a Java perspective (Jazoon '09)
iPhone development from a Java perspective (Jazoon '09)iPhone development from a Java perspective (Jazoon '09)
iPhone development from a Java perspective (Jazoon '09)
Netcetera
 
Core_java_ppt.ppt
Core_java_ppt.pptCore_java_ppt.ppt
Core_java_ppt.ppt
SHIBDASDUTTA
 
Introduction to odbms
Introduction to odbmsIntroduction to odbms
Introduction to odbms
ajay pashankar
 
PATTERNS09 - Generics in .NET and Java
PATTERNS09 - Generics in .NET and JavaPATTERNS09 - Generics in .NET and Java
PATTERNS09 - Generics in .NET and Java
Michael Heron
 
Qb it1301
Qb   it1301Qb   it1301
Qb it1301
ArthyR3
 
ppt_on_java.pptx
ppt_on_java.pptxppt_on_java.pptx
ppt_on_java.pptx
MAYANKKUMAR492040
 
Java Tutorials
Java Tutorials Java Tutorials
Java Tutorials
Woxa Technologies
 
Hibernate Session 1
Hibernate Session 1Hibernate Session 1
Hibernate Session 1
b_kathir
 
Oop java
Oop javaOop java
Oop java
Minal Maniar
 
Object Oriented Programming All Unit Notes
Object Oriented Programming All Unit NotesObject Oriented Programming All Unit Notes
Object Oriented Programming All Unit Notes
BalamuruganV28
 
java training faridabad
java training faridabadjava training faridabad
java training faridabad
Woxa Technologies
 
2CPP16 - STL
2CPP16 - STL2CPP16 - STL
2CPP16 - STL
Michael Heron
 
Modern C++
Modern C++Modern C++
Modern C++
Richard Thomson
 
core java
core javacore java
core java
Vinodh Kumar
 
Object Oriented Programming Concepts using Java
Object Oriented Programming Concepts using JavaObject Oriented Programming Concepts using Java
Object Oriented Programming Concepts using Java
Glenn Guden
 

Similar to JVM Language Summit: Object layout presentation (20)

ObjectLayout: Closing the (last?) inherent C vs. Java speed gap
ObjectLayout: Closing the (last?) inherent C vs. Java speed gapObjectLayout: Closing the (last?) inherent C vs. Java speed gap
ObjectLayout: Closing the (last?) inherent C vs. Java speed gap
 
JVM Language Summit: Object layout workshop
JVM Language Summit: Object layout workshopJVM Language Summit: Object layout workshop
JVM Language Summit: Object layout workshop
 
Eclipse Day India 2011 - Extending JDT
Eclipse Day India 2011 - Extending JDTEclipse Day India 2011 - Extending JDT
Eclipse Day India 2011 - Extending JDT
 
How to train the jdt dragon
How to train the jdt dragonHow to train the jdt dragon
How to train the jdt dragon
 
Hibernate
HibernateHibernate
Hibernate
 
iPhone development from a Java perspective (Jazoon '09)
iPhone development from a Java perspective (Jazoon '09)iPhone development from a Java perspective (Jazoon '09)
iPhone development from a Java perspective (Jazoon '09)
 
Core_java_ppt.ppt
Core_java_ppt.pptCore_java_ppt.ppt
Core_java_ppt.ppt
 
Introduction to odbms
Introduction to odbmsIntroduction to odbms
Introduction to odbms
 
PATTERNS09 - Generics in .NET and Java
PATTERNS09 - Generics in .NET and JavaPATTERNS09 - Generics in .NET and Java
PATTERNS09 - Generics in .NET and Java
 
Qb it1301
Qb   it1301Qb   it1301
Qb it1301
 
ppt_on_java.pptx
ppt_on_java.pptxppt_on_java.pptx
ppt_on_java.pptx
 
Java Tutorials
Java Tutorials Java Tutorials
Java Tutorials
 
Hibernate Session 1
Hibernate Session 1Hibernate Session 1
Hibernate Session 1
 
Oop java
Oop javaOop java
Oop java
 
Object Oriented Programming All Unit Notes
Object Oriented Programming All Unit NotesObject Oriented Programming All Unit Notes
Object Oriented Programming All Unit Notes
 
java training faridabad
java training faridabadjava training faridabad
java training faridabad
 
2CPP16 - STL
2CPP16 - STL2CPP16 - STL
2CPP16 - STL
 
Modern C++
Modern C++Modern C++
Modern C++
 
core java
core javacore java
core java
 
Object Oriented Programming Concepts using Java
Object Oriented Programming Concepts using JavaObject Oriented Programming Concepts using Java
Object Oriented Programming Concepts using Java
 

More from Azul Systems, Inc.

Unleash the Power of Apache Cassandra
Unleash the Power of Apache CassandraUnleash the Power of Apache Cassandra
Unleash the Power of Apache Cassandra
Azul Systems, Inc.
 
How NOT to Measure Latency
How NOT to Measure LatencyHow NOT to Measure Latency
How NOT to Measure Latency
Azul Systems, Inc.
 
Enabling Java in Latency Sensitive Environments - Dallas JUG April 2015
Enabling Java in Latency Sensitive Environments - Dallas JUG April 2015Enabling Java in Latency Sensitive Environments - Dallas JUG April 2015
Enabling Java in Latency Sensitive Environments - Dallas JUG April 2015
Azul Systems, Inc.
 
Enabling Java in Latency-Sensitive Environments - Austin JUG April 2015
Enabling Java in Latency-Sensitive Environments - Austin JUG April 2015Enabling Java in Latency-Sensitive Environments - Austin JUG April 2015
Enabling Java in Latency-Sensitive Environments - Austin JUG April 2015
Azul Systems, Inc.
 
QCon London: Low latency Java in the real world - LMAX Exchange and the Zing JVM
QCon London: Low latency Java in the real world - LMAX Exchange and the Zing JVMQCon London: Low latency Java in the real world - LMAX Exchange and the Zing JVM
QCon London: Low latency Java in the real world - LMAX Exchange and the Zing JVM
Azul Systems, Inc.
 
What's New in the JVM in Java 8?
What's New in the JVM in Java 8?What's New in the JVM in Java 8?
What's New in the JVM in Java 8?
Azul Systems, Inc.
 
DC JUG: Understanding Java Garbage Collection
DC JUG: Understanding Java Garbage CollectionDC JUG: Understanding Java Garbage Collection
DC JUG: Understanding Java Garbage Collection
Azul Systems, Inc.
 
Winning With Java at Market Open
Winning With Java at Market OpenWinning With Java at Market Open
Winning With Java at Market Open
Azul Systems, Inc.
 

More from Azul Systems, Inc. (8)

Unleash the Power of Apache Cassandra
Unleash the Power of Apache CassandraUnleash the Power of Apache Cassandra
Unleash the Power of Apache Cassandra
 
How NOT to Measure Latency
How NOT to Measure LatencyHow NOT to Measure Latency
How NOT to Measure Latency
 
Enabling Java in Latency Sensitive Environments - Dallas JUG April 2015
Enabling Java in Latency Sensitive Environments - Dallas JUG April 2015Enabling Java in Latency Sensitive Environments - Dallas JUG April 2015
Enabling Java in Latency Sensitive Environments - Dallas JUG April 2015
 
Enabling Java in Latency-Sensitive Environments - Austin JUG April 2015
Enabling Java in Latency-Sensitive Environments - Austin JUG April 2015Enabling Java in Latency-Sensitive Environments - Austin JUG April 2015
Enabling Java in Latency-Sensitive Environments - Austin JUG April 2015
 
QCon London: Low latency Java in the real world - LMAX Exchange and the Zing JVM
QCon London: Low latency Java in the real world - LMAX Exchange and the Zing JVMQCon London: Low latency Java in the real world - LMAX Exchange and the Zing JVM
QCon London: Low latency Java in the real world - LMAX Exchange and the Zing JVM
 
What's New in the JVM in Java 8?
What's New in the JVM in Java 8?What's New in the JVM in Java 8?
What's New in the JVM in Java 8?
 
DC JUG: Understanding Java Garbage Collection
DC JUG: Understanding Java Garbage CollectionDC JUG: Understanding Java Garbage Collection
DC JUG: Understanding Java Garbage Collection
 
Winning With Java at Market Open
Winning With Java at Market OpenWinning With Java at Market Open
Winning With Java at Market Open
 

Recently uploaded

Migration From CH 1.0 to CH 2.0 and Mule 4.6 & Java 17 Upgrade.pptx
Migration From CH 1.0 to CH 2.0 and  Mule 4.6 & Java 17 Upgrade.pptxMigration From CH 1.0 to CH 2.0 and  Mule 4.6 & Java 17 Upgrade.pptx
Migration From CH 1.0 to CH 2.0 and Mule 4.6 & Java 17 Upgrade.pptx
ervikas4
 
Malibou Pitch Deck For Its €3M Seed Round
Malibou Pitch Deck For Its €3M Seed RoundMalibou Pitch Deck For Its €3M Seed Round
Malibou Pitch Deck For Its €3M Seed Round
sjcobrien
 
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
dakas1
 
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdfBaha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
Baha Majid
 
14 th Edition of International conference on computer vision
14 th Edition of International conference on computer vision14 th Edition of International conference on computer vision
14 th Edition of International conference on computer vision
ShulagnaSarkar2
 
Assure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyesAssure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
The Comprehensive Guide to Validating Audio-Visual Performances.pdf
The Comprehensive Guide to Validating Audio-Visual Performances.pdfThe Comprehensive Guide to Validating Audio-Visual Performances.pdf
The Comprehensive Guide to Validating Audio-Visual Performances.pdf
kalichargn70th171
 
The Rising Future of CPaaS in the Middle East 2024
The Rising Future of CPaaS in the Middle East 2024The Rising Future of CPaaS in the Middle East 2024
The Rising Future of CPaaS in the Middle East 2024
Yara Milbes
 
Alluxio Webinar | 10x Faster Trino Queries on Your Data Platform
Alluxio Webinar | 10x Faster Trino Queries on Your Data PlatformAlluxio Webinar | 10x Faster Trino Queries on Your Data Platform
Alluxio Webinar | 10x Faster Trino Queries on Your Data Platform
Alluxio, Inc.
 
WWDC 2024 Keynote Review: For CocoaCoders Austin
WWDC 2024 Keynote Review: For CocoaCoders AustinWWDC 2024 Keynote Review: For CocoaCoders Austin
WWDC 2024 Keynote Review: For CocoaCoders Austin
Patrick Weigel
 
Enums On Steroids - let's look at sealed classes !
Enums On Steroids - let's look at sealed classes !Enums On Steroids - let's look at sealed classes !
Enums On Steroids - let's look at sealed classes !
Marcin Chrost
 
Upturn India Technologies - Web development company in Nashik
Upturn India Technologies - Web development company in NashikUpturn India Technologies - Web development company in Nashik
Upturn India Technologies - Web development company in Nashik
Upturn India Technologies
 
Transforming Product Development using OnePlan To Boost Efficiency and Innova...
Transforming Product Development using OnePlan To Boost Efficiency and Innova...Transforming Product Development using OnePlan To Boost Efficiency and Innova...
Transforming Product Development using OnePlan To Boost Efficiency and Innova...
OnePlan Solutions
 
Liberarsi dai framework con i Web Component.pptx
Liberarsi dai framework con i Web Component.pptxLiberarsi dai framework con i Web Component.pptx
Liberarsi dai framework con i Web Component.pptx
Massimo Artizzu
 
美洲杯赔率投注网【​网址​🎉3977·EE​🎉】
美洲杯赔率投注网【​网址​🎉3977·EE​🎉】美洲杯赔率投注网【​网址​🎉3977·EE​🎉】
美洲杯赔率投注网【​网址​🎉3977·EE​🎉】
widenerjobeyrl638
 
Enhanced Screen Flows UI/UX using SLDS with Tom Kitt
Enhanced Screen Flows UI/UX using SLDS with Tom KittEnhanced Screen Flows UI/UX using SLDS with Tom Kitt
Enhanced Screen Flows UI/UX using SLDS with Tom Kitt
Peter Caitens
 
Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...
Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...
Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...
The Third Creative Media
 
ppt on the brain chip neuralink.pptx
ppt  on   the brain  chip neuralink.pptxppt  on   the brain  chip neuralink.pptx
ppt on the brain chip neuralink.pptx
Reetu63
 
如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样
如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样
如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样
gapen1
 
Using Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query PerformanceUsing Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query Performance
Grant Fritchey
 

Recently uploaded (20)

Migration From CH 1.0 to CH 2.0 and Mule 4.6 & Java 17 Upgrade.pptx
Migration From CH 1.0 to CH 2.0 and  Mule 4.6 & Java 17 Upgrade.pptxMigration From CH 1.0 to CH 2.0 and  Mule 4.6 & Java 17 Upgrade.pptx
Migration From CH 1.0 to CH 2.0 and Mule 4.6 & Java 17 Upgrade.pptx
 
Malibou Pitch Deck For Its €3M Seed Round
Malibou Pitch Deck For Its €3M Seed RoundMalibou Pitch Deck For Its €3M Seed Round
Malibou Pitch Deck For Its €3M Seed Round
 
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
 
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdfBaha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
 
14 th Edition of International conference on computer vision
14 th Edition of International conference on computer vision14 th Edition of International conference on computer vision
14 th Edition of International conference on computer vision
 
Assure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyesAssure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyes
 
The Comprehensive Guide to Validating Audio-Visual Performances.pdf
The Comprehensive Guide to Validating Audio-Visual Performances.pdfThe Comprehensive Guide to Validating Audio-Visual Performances.pdf
The Comprehensive Guide to Validating Audio-Visual Performances.pdf
 
The Rising Future of CPaaS in the Middle East 2024
The Rising Future of CPaaS in the Middle East 2024The Rising Future of CPaaS in the Middle East 2024
The Rising Future of CPaaS in the Middle East 2024
 
Alluxio Webinar | 10x Faster Trino Queries on Your Data Platform
Alluxio Webinar | 10x Faster Trino Queries on Your Data PlatformAlluxio Webinar | 10x Faster Trino Queries on Your Data Platform
Alluxio Webinar | 10x Faster Trino Queries on Your Data Platform
 
WWDC 2024 Keynote Review: For CocoaCoders Austin
WWDC 2024 Keynote Review: For CocoaCoders AustinWWDC 2024 Keynote Review: For CocoaCoders Austin
WWDC 2024 Keynote Review: For CocoaCoders Austin
 
Enums On Steroids - let's look at sealed classes !
Enums On Steroids - let's look at sealed classes !Enums On Steroids - let's look at sealed classes !
Enums On Steroids - let's look at sealed classes !
 
Upturn India Technologies - Web development company in Nashik
Upturn India Technologies - Web development company in NashikUpturn India Technologies - Web development company in Nashik
Upturn India Technologies - Web development company in Nashik
 
Transforming Product Development using OnePlan To Boost Efficiency and Innova...
Transforming Product Development using OnePlan To Boost Efficiency and Innova...Transforming Product Development using OnePlan To Boost Efficiency and Innova...
Transforming Product Development using OnePlan To Boost Efficiency and Innova...
 
Liberarsi dai framework con i Web Component.pptx
Liberarsi dai framework con i Web Component.pptxLiberarsi dai framework con i Web Component.pptx
Liberarsi dai framework con i Web Component.pptx
 
美洲杯赔率投注网【​网址​🎉3977·EE​🎉】
美洲杯赔率投注网【​网址​🎉3977·EE​🎉】美洲杯赔率投注网【​网址​🎉3977·EE​🎉】
美洲杯赔率投注网【​网址​🎉3977·EE​🎉】
 
Enhanced Screen Flows UI/UX using SLDS with Tom Kitt
Enhanced Screen Flows UI/UX using SLDS with Tom KittEnhanced Screen Flows UI/UX using SLDS with Tom Kitt
Enhanced Screen Flows UI/UX using SLDS with Tom Kitt
 
Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...
Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...
Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...
 
ppt on the brain chip neuralink.pptx
ppt  on   the brain  chip neuralink.pptxppt  on   the brain  chip neuralink.pptx
ppt on the brain chip neuralink.pptx
 
如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样
如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样
如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样
 
Using Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query PerformanceUsing Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query Performance
 

JVM Language Summit: Object layout presentation

  • 1. ©2014 Azul Systems, Inc. Closing the [last?] inherent C vs. Java speed gap Gil Tene, CTO & co-Founder, Azul Systems http://objectlayout.org ObjectLayout (and StructuredArray) !
  • 2. ©2014 Azul Systems, Inc. ObjectLayout Focus: Match the raw speed benefits C based languages get from commonly used forms of memory layout Expose these benefits to normal idiomatic POJO use Focus: Speed. For regular Java Objects. On the heap. Not looking for: Improved footprint off-heap solutions immutability These are all orthogonal concerns}
  • 3. ©2014 Azul Systems, Inc. ObjectLayout: goal overlap? Relationship to Value types: none Relationship to Packet Objects (or JNR/FFI): none Laser-focused on a different problem Does not conflict or contradict concerns that drive these other efforts Minimal overlap does exist … The kind of overlap that ArrayList and HashMap have as good alternatives of a bag of objects
  • 4. Value types Packed objects & JNR/FFI ObjectLayout precise layout control Speed! For any Object On Heap Off Heap Sharing data Immutable On-stack Return values Objects usable by all existing code New code On Heap Array of small-footprint values New code
  • 5. ©2014 Azul Systems, Inc. ObjectLayout Origin ObjectLayout/StructuredArray started with a simple argument. The common sides of the argument are: “We need structs in Java…”: Look at all the unsafe direct access stuff we do using flyweights over buffers or byte arrays, just to squeeze out speed that C gets trivially… “We already have structs. They are called Objects.”: What we need is competitively speedy access for the data collection semantics that are currently faster in C It’s all about capturing “enabling semantic limitations”
  • 6. ©2014 Azul Systems, Inc. speed comes from ??? C’s layout speed benefits are dominated by two factors: Dead reckoning: Data address derived from containing object address no data-dependent load operation Streaming (In the case of an array of structs): sequential access through multiple members predictable striding access in memory Prefetch logic compensates for miss latency
  • 7. ©2014 Azul Systems, Inc. example of speed-enabling limitations Why is Object[] inherently slower than struct foo[]? Java: a mutable array of same-base-type objects C: An immutable array of exact-same-type structures Mutability (of the array itself) & non-uniform member size both force de-reference, and both break streaming StructuredArray<T>: An immutable array of [potentially] mutable exact-same-type (T) objects Supports Instantiation, get(), but not put()…
  • 8. ©2014 Azul Systems, Inc. ObjectLayout target forms Easily identified C-based layout forms: array of structs struct foo[]; struct with struct inside struct foo { int a; struct bar b; int c; }; struct with array at the end struct packet { int length; char[] body; } None are currently (speed) matched in Java
  • 9. ©2014 Azul Systems, Inc. ObjectLayout: starting point Capture the semantics that enable speed in the various C-like data layout forms behaviors Theory: we can do this all with no language change… Capture the needed semantics in “vanilla” Java classes (targeting e.g. Java SE 6) Have JDKs recognize and intrinsify behavior, optimizing memory layout and access operations “Vanilla” and “Intrinsified” implementation behavior should be indistinguishable (except for speed)
  • 10. ©2014 Azul Systems, Inc. Modeled after java.util.concurrent Captured semantics enabled fast concurrent operations No language changes. No required JVM changes. Implementable in “vanilla” Java classes outside of JDK e.g. AtomicLong CAS could be done with synchronized JDKs improved to recognize and intrinsify behavior e.g. AtomicLong CAS is a single x86 instruction Moved into JDK and Java name space in order to secure intrinsification and gain legitimate access to unsafe
  • 11. ©2014 Azul Systems, Inc. ObjectLayout: StructuredArray array of structs struct foo[]; struct with struct inside struct foo { int a; struct bar b; int c; }; struct with array at the end struct packet { int len; char[] body; }
  • 12. ©2014 Azul Systems, Inc. StructuredArray<T> A collection of object instances of arbitrary type T Arranged as array: T element = get(index); Collection is immutable: cannot replace elements Instantiated via factory method: a = StructuredArray.newInstance(SomeClass.class, 100); All elements constructed at instantiation time Supports arbitrary constructor and args for members Including support for index-specific CtorAndArgs
  • 13. ©2014 Azul Systems, Inc. StructuredArray<T> liveness We considered an “inner pointer keeps container alive” approach, because that what other runtimes seem to do with arrays of structs and field references But then we realized: real objects have real liveness A StructuredArray is just a regular idiomatic collection The collection keeps it’s members alive Collection members don’t (implicitly) keep it alive *** Under the hood, optimized implementations will want to keep the collection “together” as long as it is alive
  • 14. ©2014 Azul Systems, Inc. Benefits of liveness approach StructuredArray is just a collection of objects No special behavior: acts like any other collection Happens to be fast on JDKs that optimize it Elements of a StructuredArray are regular objects Can participate in other collections and object graphs Can be locked Can have an identity hashcode Can be passed along to any existing java code It’s “natural”, and it’s easier to support in the JVM
  • 15. ©2014 Azul Systems, Inc. StructuredArray<T> continued… Indexes are longs (it’s 2014…) Multi dimensional support Non-leaf Elements are themselves StructuredArrays StructuredArray is subclassable Supports some useful coding styles and optimizations StructuredArray is not constructable must be created with factory methods (*** Did you spot that small contradiction?)
  • 16. ©2014 Azul Systems, Inc. Optimized JDK implementation A new heap concept: “contained” and “container” objects Contained and container objects are regular objects Given a contained object, there is a means of finding the immediately containing object If GC needs to move an object that is contained in a live container object, it will move the entire container Very simple to implement in all current OpenJDK GC mechanisms (and in Zing’s C4, and in others, we think) More details in workshop…
  • 17. ©2014 Azul Systems, Inc. Optimized JDK implementation Streaming benefits come directly from layout No compiler optimizations needed Dead-reckoning benefits require some compiler support no dereferencing, but…. e = (T) ( a + a.bodySize + (index * a.elementSize) ); elementSize and bodySize are not constant But optimizations similar to CHA & inline-cache apply More details in workshop…
  • 18. ©2014 Azul Systems, Inc. ObjectLayout forms 2 & 3 array of structs struct foo[]; struct with struct inside struct foo { int a; struct bar b; int c; }; struct with array at the end struct packet { int len; char[] body; }
  • 19. ©2014 Azul Systems, Inc. “struct in struct”: intrinsic objects Object instance x is intrinsic to object instance y Proposal: factory based instantiation of final member objects Class SomeClass { int a; final SomeOtherClass o = IntrinsifiedObjects.createIntrinsicObject(SomeOtherClass.class); } Intrinsic object can be laid out within containing object Must deal with & survive reflection based overwrites
  • 20. ©2014 Azul Systems, Inc. “struct with array at the end”: subclassable arrays Semantics well captured by subclassable arrays classes ObjectLayout describes one for each primitive type. E.g. PrimitiveLongArray, PrimitiveDoubleArray, etc… Also ReferenceArray<T> StructuredArray<T> is also subclassable, and captures “struct with array of structs at the end”
  • 21. ©2014 Azul Systems, Inc. Status Vanilla Java code on github. Public domain under CC0. See http://objectlayout.org StructuredArray is fairly mature semantically. Other two forms (intrinsic objects and subclassable arrays) are getting there… Intrinsified implementations coming over the next few months for both Zing and OpenJDK Next steps: OpenJDK project with working code, JEP… Aim: Add ObjectLayout to Java SE (9?) Vanilla implementation will work on all JDKs
  • 22. ©2014 Azul Systems, Inc. ObjectLayout Summary New Java classes: org.ObjectLayout.* Propose to move into java namespace in Java SE (9?) Work “out of the box” on Java 6, 7, 8, 9, … No syntax changes, No new bytecodes No new required JVM behavior Can “go fast” on JDKs that optimize for them Relatively simple, isolated JVM changes needed Proposing to include “go fast” in OpenJDK (9?) Zing will support “go fast” for Java 6, 7, 8, 9, …