SlideShare ist ein Scribd-Unternehmen logo
1 von 28
Faster Object Arrays 
Closing the [last?] inherent C 
©2014 Azul Systems, Inc. 
vs. Java speed gap 
http://www.objectlayout.org 
Gil Tene, CTO & co-Founder, Azul Systems
Watch the video with slide 
synchronization on InfoQ.com! 
http://www.infoq.com/presentations 
/objectlayout-structuredarray 
InfoQ.com: News & Community Site 
• 750,000 unique visitors/month 
• Published in 4 languages (English, Chinese, Japanese and Brazilian 
Portuguese) 
• Post content from our QCon conferences 
• News 15-20 / week 
• Articles 3-4 / week 
• Presentations (videos) 12-15 / week 
• Interviews 2-3 / week 
• Books 1 / month
Presented at QCon San Francisco 
www.qconsf.com 
Purpose of QCon 
- to empower software development by facilitating the spread of 
knowledge and innovation 
Strategy 
- practitioner-driven conference designed for YOU: influencers of 
change and innovation in your teams 
- speakers and topics driving the evolution and innovation 
- connecting and catalyzing the influencers and innovators 
Highlights 
- attended by more than 12,000 delegates since 2007 
- held in 9 cities worldwide
©2014 Azul Systems, Inc. 
org.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 }
org.ObjectLayout: goal overlap? 
©2014 Azul Systems, Inc. 
Value types? Packed Objects? 
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 
Speed! 
For any Object 
ObjectLayout 
Packed 
objects 
& 
JNR/FFI 
On Heap 
precise layout 
control 
Off Heap 
Sharing data 
Immutable 
Return values 
On-stack 
Objects 
usable by 
all existing 
On Heap 
New code code 
Array of 
small-footprint 
values 
New code
©2014 Azul Systems, Inc. 
org.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 (e.g. in the case of an array of structs): 
sequential access through multiple members 
predictable striding access in memory 
prefetch logic compensates for miss latency
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) & non-uniform member size 
both (individually) force de-reference & break streaming 
StructuredArray<T>: An immutable array of [potentially] 
mutable exact-same-type (T) objects 
©2014 Azul Systems, Inc. 
Supports Instantiation, get(), but not put()…
org.ObjectLayout target forms 
The common C-style constructs we seek to match: 
array of structs 
©2014 Azul Systems, Inc. 
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
org.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.
org.ObjectLayout.StructuredArray 
array of structs 
©2014 Azul Systems, Inc. 
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
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…) 
Nested arrays are supported (multi-dim, composable) 
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 on github & in project discussion 
©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 project discussion… 
©2014 Azul Systems, Inc.
©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: 
Class Line { 
@Intrinsic 
private final Point endPoint1 = 
IntrinsicObjects.constructWithin(“endpoint1”, this); 
… 
} 
Intrinsic objects can be laid out within containing object 
Must deal with & survive reflection based overwrites
“struct with array at the end”: 
©2014 Azul Systems, Inc. 
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”
The org.ObjectLayout forms: 
StructuredArray<T> facilitates: 
©2014 Azul Systems, Inc. 
“struct foo[];" 
@Intrinsic of member objects facilitates: 
“struct foo { int a; struct bar b; int c; };” 
PrimitiveLongArray, .. , ReferenceArray facilitate: 
“struct packet { int len; char[] body; }”
The three forms are composable 
public class Octagons extends StructuredArray<Octagon> … 
public class Octagon { 
@Intrinsic(length = 8) 
private final StructuredArrayOfPoint points = 
©2014 Azul Systems, Inc. 
IntrinsicObjects.constructWithin(“points”, this); 
… 
} 
public class StructuredArrayOfPoint extends StructuredArray<Point>…
©2014 Azul Systems, Inc. 
Status 
Vanilla Java code on github. Public domain under CC0. 
See http://www.objectlayout.org 
Fairly mature semantically. Working out “spelling” 
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
Watch the video with slide synchronization on 
InfoQ.com! 
http://www.infoq.com/presentations/objectlayout 
-structuredarray

Weitere ähnliche Inhalte

Mehr von C4Media

Software Teams and Teamwork Trends Report Q1 2020
Software Teams and Teamwork Trends Report Q1 2020Software Teams and Teamwork Trends Report Q1 2020
Software Teams and Teamwork Trends Report Q1 2020C4Media
 
Understand the Trade-offs Using Compilers for Java Applications
Understand the Trade-offs Using Compilers for Java ApplicationsUnderstand the Trade-offs Using Compilers for Java Applications
Understand the Trade-offs Using Compilers for Java ApplicationsC4Media
 
Kafka Needs No Keeper
Kafka Needs No KeeperKafka Needs No Keeper
Kafka Needs No KeeperC4Media
 
High Performing Teams Act Like Owners
High Performing Teams Act Like OwnersHigh Performing Teams Act Like Owners
High Performing Teams Act Like OwnersC4Media
 
Does Java Need Inline Types? What Project Valhalla Can Bring to Java
Does Java Need Inline Types? What Project Valhalla Can Bring to JavaDoes Java Need Inline Types? What Project Valhalla Can Bring to Java
Does Java Need Inline Types? What Project Valhalla Can Bring to JavaC4Media
 
Service Meshes- The Ultimate Guide
Service Meshes- The Ultimate GuideService Meshes- The Ultimate Guide
Service Meshes- The Ultimate GuideC4Media
 
Shifting Left with Cloud Native CI/CD
Shifting Left with Cloud Native CI/CDShifting Left with Cloud Native CI/CD
Shifting Left with Cloud Native CI/CDC4Media
 
CI/CD for Machine Learning
CI/CD for Machine LearningCI/CD for Machine Learning
CI/CD for Machine LearningC4Media
 
Fault Tolerance at Speed
Fault Tolerance at SpeedFault Tolerance at Speed
Fault Tolerance at SpeedC4Media
 
Architectures That Scale Deep - Regaining Control in Deep Systems
Architectures That Scale Deep - Regaining Control in Deep SystemsArchitectures That Scale Deep - Regaining Control in Deep Systems
Architectures That Scale Deep - Regaining Control in Deep SystemsC4Media
 
ML in the Browser: Interactive Experiences with Tensorflow.js
ML in the Browser: Interactive Experiences with Tensorflow.jsML in the Browser: Interactive Experiences with Tensorflow.js
ML in the Browser: Interactive Experiences with Tensorflow.jsC4Media
 
Build Your Own WebAssembly Compiler
Build Your Own WebAssembly CompilerBuild Your Own WebAssembly Compiler
Build Your Own WebAssembly CompilerC4Media
 
User & Device Identity for Microservices @ Netflix Scale
User & Device Identity for Microservices @ Netflix ScaleUser & Device Identity for Microservices @ Netflix Scale
User & Device Identity for Microservices @ Netflix ScaleC4Media
 
Scaling Patterns for Netflix's Edge
Scaling Patterns for Netflix's EdgeScaling Patterns for Netflix's Edge
Scaling Patterns for Netflix's EdgeC4Media
 
Make Your Electron App Feel at Home Everywhere
Make Your Electron App Feel at Home EverywhereMake Your Electron App Feel at Home Everywhere
Make Your Electron App Feel at Home EverywhereC4Media
 
The Talk You've Been Await-ing For
The Talk You've Been Await-ing ForThe Talk You've Been Await-ing For
The Talk You've Been Await-ing ForC4Media
 
Future of Data Engineering
Future of Data EngineeringFuture of Data Engineering
Future of Data EngineeringC4Media
 
Automated Testing for Terraform, Docker, Packer, Kubernetes, and More
Automated Testing for Terraform, Docker, Packer, Kubernetes, and MoreAutomated Testing for Terraform, Docker, Packer, Kubernetes, and More
Automated Testing for Terraform, Docker, Packer, Kubernetes, and MoreC4Media
 
Navigating Complexity: High-performance Delivery and Discovery Teams
Navigating Complexity: High-performance Delivery and Discovery TeamsNavigating Complexity: High-performance Delivery and Discovery Teams
Navigating Complexity: High-performance Delivery and Discovery TeamsC4Media
 
High Performance Cooperative Distributed Systems in Adtech
High Performance Cooperative Distributed Systems in AdtechHigh Performance Cooperative Distributed Systems in Adtech
High Performance Cooperative Distributed Systems in AdtechC4Media
 

Mehr von C4Media (20)

Software Teams and Teamwork Trends Report Q1 2020
Software Teams and Teamwork Trends Report Q1 2020Software Teams and Teamwork Trends Report Q1 2020
Software Teams and Teamwork Trends Report Q1 2020
 
Understand the Trade-offs Using Compilers for Java Applications
Understand the Trade-offs Using Compilers for Java ApplicationsUnderstand the Trade-offs Using Compilers for Java Applications
Understand the Trade-offs Using Compilers for Java Applications
 
Kafka Needs No Keeper
Kafka Needs No KeeperKafka Needs No Keeper
Kafka Needs No Keeper
 
High Performing Teams Act Like Owners
High Performing Teams Act Like OwnersHigh Performing Teams Act Like Owners
High Performing Teams Act Like Owners
 
Does Java Need Inline Types? What Project Valhalla Can Bring to Java
Does Java Need Inline Types? What Project Valhalla Can Bring to JavaDoes Java Need Inline Types? What Project Valhalla Can Bring to Java
Does Java Need Inline Types? What Project Valhalla Can Bring to Java
 
Service Meshes- The Ultimate Guide
Service Meshes- The Ultimate GuideService Meshes- The Ultimate Guide
Service Meshes- The Ultimate Guide
 
Shifting Left with Cloud Native CI/CD
Shifting Left with Cloud Native CI/CDShifting Left with Cloud Native CI/CD
Shifting Left with Cloud Native CI/CD
 
CI/CD for Machine Learning
CI/CD for Machine LearningCI/CD for Machine Learning
CI/CD for Machine Learning
 
Fault Tolerance at Speed
Fault Tolerance at SpeedFault Tolerance at Speed
Fault Tolerance at Speed
 
Architectures That Scale Deep - Regaining Control in Deep Systems
Architectures That Scale Deep - Regaining Control in Deep SystemsArchitectures That Scale Deep - Regaining Control in Deep Systems
Architectures That Scale Deep - Regaining Control in Deep Systems
 
ML in the Browser: Interactive Experiences with Tensorflow.js
ML in the Browser: Interactive Experiences with Tensorflow.jsML in the Browser: Interactive Experiences with Tensorflow.js
ML in the Browser: Interactive Experiences with Tensorflow.js
 
Build Your Own WebAssembly Compiler
Build Your Own WebAssembly CompilerBuild Your Own WebAssembly Compiler
Build Your Own WebAssembly Compiler
 
User & Device Identity for Microservices @ Netflix Scale
User & Device Identity for Microservices @ Netflix ScaleUser & Device Identity for Microservices @ Netflix Scale
User & Device Identity for Microservices @ Netflix Scale
 
Scaling Patterns for Netflix's Edge
Scaling Patterns for Netflix's EdgeScaling Patterns for Netflix's Edge
Scaling Patterns for Netflix's Edge
 
Make Your Electron App Feel at Home Everywhere
Make Your Electron App Feel at Home EverywhereMake Your Electron App Feel at Home Everywhere
Make Your Electron App Feel at Home Everywhere
 
The Talk You've Been Await-ing For
The Talk You've Been Await-ing ForThe Talk You've Been Await-ing For
The Talk You've Been Await-ing For
 
Future of Data Engineering
Future of Data EngineeringFuture of Data Engineering
Future of Data Engineering
 
Automated Testing for Terraform, Docker, Packer, Kubernetes, and More
Automated Testing for Terraform, Docker, Packer, Kubernetes, and MoreAutomated Testing for Terraform, Docker, Packer, Kubernetes, and More
Automated Testing for Terraform, Docker, Packer, Kubernetes, and More
 
Navigating Complexity: High-performance Delivery and Discovery Teams
Navigating Complexity: High-performance Delivery and Discovery TeamsNavigating Complexity: High-performance Delivery and Discovery Teams
Navigating Complexity: High-performance Delivery and Discovery Teams
 
High Performance Cooperative Distributed Systems in Adtech
High Performance Cooperative Distributed Systems in AdtechHigh Performance Cooperative Distributed Systems in Adtech
High Performance Cooperative Distributed Systems in Adtech
 

Kürzlich hochgeladen

The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
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
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
"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
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
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
 
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
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 

Kürzlich hochgeladen (20)

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
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
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
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
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
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
"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
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
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
 
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
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 

Faster Object Arrays

  • 1. Faster Object Arrays Closing the [last?] inherent C ©2014 Azul Systems, Inc. vs. Java speed gap http://www.objectlayout.org Gil Tene, CTO & co-Founder, Azul Systems
  • 2. Watch the video with slide synchronization on InfoQ.com! http://www.infoq.com/presentations /objectlayout-structuredarray InfoQ.com: News & Community Site • 750,000 unique visitors/month • Published in 4 languages (English, Chinese, Japanese and Brazilian Portuguese) • Post content from our QCon conferences • News 15-20 / week • Articles 3-4 / week • Presentations (videos) 12-15 / week • Interviews 2-3 / week • Books 1 / month
  • 3. Presented at QCon San Francisco www.qconsf.com Purpose of QCon - to empower software development by facilitating the spread of knowledge and innovation Strategy - practitioner-driven conference designed for YOU: influencers of change and innovation in your teams - speakers and topics driving the evolution and innovation - connecting and catalyzing the influencers and innovators Highlights - attended by more than 12,000 delegates since 2007 - held in 9 cities worldwide
  • 4. ©2014 Azul Systems, Inc. org.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 }
  • 5. org.ObjectLayout: goal overlap? ©2014 Azul Systems, Inc. Value types? Packed Objects? 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
  • 6. Value types Speed! For any Object ObjectLayout Packed objects & JNR/FFI On Heap precise layout control Off Heap Sharing data Immutable Return values On-stack Objects usable by all existing On Heap New code code Array of small-footprint values New code
  • 7. ©2014 Azul Systems, Inc. org.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”
  • 8. ©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 (e.g. in the case of an array of structs): sequential access through multiple members predictable striding access in memory prefetch logic compensates for miss latency
  • 9. 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) & non-uniform member size both (individually) force de-reference & break streaming StructuredArray<T>: An immutable array of [potentially] mutable exact-same-type (T) objects ©2014 Azul Systems, Inc. Supports Instantiation, get(), but not put()…
  • 10. org.ObjectLayout target forms The common C-style constructs we seek to match: array of structs ©2014 Azul Systems, Inc. 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
  • 11. org.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.
  • 12. 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.
  • 13. org.ObjectLayout.StructuredArray array of structs ©2014 Azul Systems, Inc. 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; }
  • 14. ©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
  • 15. 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.
  • 16. 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.
  • 17. StructuredArray<T> continued… Indexes are longs (it’s 2014…) Nested arrays are supported (multi-dim, composable) 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.
  • 18. 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 on github & in project discussion ©2014 Azul Systems, Inc.
  • 19. 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 project discussion… ©2014 Azul Systems, Inc.
  • 20. ©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; }
  • 21. ©2014 Azul Systems, Inc. “struct in struct”: intrinsic objects Object instance x is intrinsic to object instance y: Class Line { @Intrinsic private final Point endPoint1 = IntrinsicObjects.constructWithin(“endpoint1”, this); … } Intrinsic objects can be laid out within containing object Must deal with & survive reflection based overwrites
  • 22. “struct with array at the end”: ©2014 Azul Systems, Inc. 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”
  • 23. The org.ObjectLayout forms: StructuredArray<T> facilitates: ©2014 Azul Systems, Inc. “struct foo[];" @Intrinsic of member objects facilitates: “struct foo { int a; struct bar b; int c; };” PrimitiveLongArray, .. , ReferenceArray facilitate: “struct packet { int len; char[] body; }”
  • 24. The three forms are composable public class Octagons extends StructuredArray<Octagon> … public class Octagon { @Intrinsic(length = 8) private final StructuredArrayOfPoint points = ©2014 Azul Systems, Inc. IntrinsicObjects.constructWithin(“points”, this); … } public class StructuredArrayOfPoint extends StructuredArray<Point>…
  • 25. ©2014 Azul Systems, Inc. Status Vanilla Java code on github. Public domain under CC0. See http://www.objectlayout.org Fairly mature semantically. Working out “spelling” 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
  • 26. ©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, …
  • 27. Q & A @giltene http://www.azulsystems.com http://objectlayout.org https://github.com/ObjectLayout/ObjectLayout
  • 28. Watch the video with slide synchronization on InfoQ.com! http://www.infoq.com/presentations/objectlayout -structuredarray