SlideShare uma empresa Scribd logo
1 de 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

Mais conteúdo relacionado

Mais de C4Media

Mais de 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
 

Último

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Último (20)

Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 

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