ibm java packedobjects
DESCRIPTION
PackedObject is an experimental feature in IBM J9 Virtual Machine. Goal(s) of Feature: Improve serialization and I/O of Java objects Allow direct access to “native” (off-heap) data Allow for explicit source-level representation of compact data-structure Intended Use: Provide an opportunity for feedback and experimentation Not meant for production support Not a committed language changeTRANSCRIPT
© 2012 IBM Corporation
IBM Java PackedObjects: An OverviewIBM Software Group: Java Technology Centre
Marcel Mitran – STSM, Architect Java on System [email protected] 20th, 2012
2 © 2012 IBM Corporation
Important Disclaimers
THE INFORMATION CONTAINED IN THIS PRESENTATION IS PROVIDED FOR INFORMATIONAL PURPOSES ONLY.
WHILST EFFORTS WERE MADE TO VERIFY THE COMPLETENESS AND ACCURACY OF THE INFORMATION CONTAINED IN THIS PRESENTATION, IT IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED.
ALL PERFORMANCE DATA INCLUDED IN THIS PRESENTATION HAVE BEEN GATHERED IN A CONTROLLED ENVIRONMENT. YOUR OWN TEST RESULTS MAY VARY BASED ON HARDWARE, SOFTWARE OR INFRASTRUCTURE DIFFERENCES.
ALL DATA INCLUDED IN THIS PRESENTATION ARE MEANT TO BE USED ONLY AS A GUIDE.
IN ADDITION, THE INFORMATION CONTAINED IN THIS PRESENTATION IS BASED ON IBM’S CURRENT PRODUCT PLANS AND STRATEGY, WHICH ARE SUBJECT TO CHANGE BY IBM, WITHOUT NOTICE.
IBM AND ITS AFFILIATED COMPANIES SHALL NOT BE RESPONSIBLE FOR ANY DAMAGES ARISING OUT OF THE USE OF, OR OTHERWISE RELATED TO, THIS PRESENTATION OR ANY OTHER DOCUMENTATION.
NOTHING CONTAINED IN THIS PRESENTATION IS INTENDED TO, OR SHALL HAVE THE EFFECT OF:
- CREATING ANY WARRANT OR REPRESENTATION FROM IBM, ITS AFFILIATED COMPANIES OR ITS OR THEIR SUPPLIERS AND/OR LICENSORS
3 © 2012 IBM Corporation
PackedObject Delivery and Intended Use
PackedObject is an experimental feature in IBM J9 Virtual Machine.
Goal(s) of Feature:■ Improve serialization and I/O of Java objects
■ Allow direct access to “native” (off-heap) data
■ Allow for explicit source-level representation of compact data-structure
Intended Use:■ Provide an opportunity for feedback and experimentation
– Not meant for production support – Not a committed language change
4 © 2012 IBM Corporation
PackedObjects for IBM's Java
Features of today's Java work well in certain scenarios, poorly in others... Present l...changing how Java data is represented and
native data is accessed and used introduces new efficiencies into the Java language
● Bloated Objects: Data headers and references required to access and use data stored outside of Java
● No direct access to off-heap data: Java Native Interface or Direct Byte Buffers required when accessing.
● Redundant Data Copying: Copies of off-heap data required to incorporate/act-on changes to source data
● Suboptimal heap placement: Non-adjacent placement of objects in memory slows down serialization, garbage collection
● Shared Headers & No References
● Direct access to native stored off-heap
● Elimination of data copies
● In-lined data allows for optimal caching
5 © 2012 IBM Corporation
Speak to me in 'Java', I don't speak 'Native'■ Java only speaks ‘Java’…
– Data typically must be copied/(de)serialized/marshalled onto/off Java heap– Costly in path-length and footprint
6 © 2012 IBM Corporation
On-Heap PackedObjects Example
■ Allows controlled layout of storage of data structures on the Java heap– Reduces footprint of data on Java heap– No (de)serialization required
JVM
Native storage (20 bytes)
I/O
Java heap
7 © 2012 IBM Corporation
Off-Heap Packed Objects Example■ Enable Java to talk directly to the native data structure
– Avoid overhead of data copy onto/off Java heap– No (de)serialization required
JVM
Native storage (20 bytes)
I/O
Meta Data
Java heap
8 © 2012 IBM Corporation
Example: Distributed Computing High-Level Architecture
Node
DB
App. Server
Node
App. Server
Data persistency on each node (DB, file-system, etc):
● Data copy● (De)serialization
Communication between nodes(RDMA, hyper-sockets, ORB, etc):● Data copy● (De)Serialization
DB
JVM JVM
Using Java packed objects, data can be moved between the persistency and communication layers without being copied or (de)serialized onto/off the Java heap
Page 9
© 2012 IBM Corporation
Example: Inter-language Communication
COBOL Java
foo(…){…goo();}
goo(…){…loo();}
C/C++
loo(…){…}
COBOL Java
foo(…){…goo();}
goo(…){…loo();}
C/C++
loo(…){…}
Java packed objects avoids data copies, marshaling and serialization
Java requires data copies, marshalling and serialization across language boundaries
10 © 2012 IBM Corporation
PackedObjects 101
■ A new PackedObject type for the Java language, which allows for:– Direct access of data located outside of the Java heap – Contiguous allocation of all object's data (objects and arrays)– Is not derived from Object, and hence dis-allows assignment and casting– Special BoxingPackedObject is glue to reference a PackedObject from Object
■ Current Java Capabilities– Current Java logic requires language interpreters and data copies for execution.– PackedObjects eliminate data copies across the Java Native Interface and the
need to design and maintain Direct Byte Buffers
■ Using PackedObjects: annotation-based (or later a packed key word) above a class definition is required to create a packed class. The class instances can be accessed and modified identically to current Java objects
java/lang/object
java/lang/Stringjava/math/BigDecimal
java/lang/PackedObject
java/lang/PackedArrayetc… etc…
java/lang/PackedString
java/lang/HashMapEntry java/lang/BoxedPackedObject java/lang/PackedHashMapEntry
java/lang/object
java/lang/Stringjava/math/BigDecimal
java/lang/PackedObject
java/lang/PackedArrayetc… etc…
java/lang/PackedString
java/lang/HashMapEntry java/lang/BoxedPackedObject java/lang/PackedHashMapEntry
11 © 2012 IBM Corporation
Scope of Implementation ■ “@Packed” class annotation used to define a PackedObject class
■ “@Length” field annotation used to specify length of PackedObject arrays
Proposed Initial Rules ■ Packed types must directly subclass PackedObject
■ Packed inlining can only happen for field declarations which are primitives, PackedObjects or arrays of PackedObjects
■ Fields made up of arrays must provide a length that is a compile time constant
■ Regular Java primitive types cannot be used to declare a PackedObject array. Boxed types for primitive arrays must be used instead.
■ A field declaration cannot introduce a circular class dependency
■ When a PackedObject is instantiated, only the constructor for the top-level PackedObject is called
■ Local variable assignment and parameter passing of a PackedObject is copy-by-reference
■ BoxedPackedObject is used to box a PackedObject with an Object reference
■ Allocating a PackedObject using the 'new' keyword creates an on-heap PackedObject
■ Off-heap PackedObject creation is done using factory method provided in the class library
12 © 2012 IBM Corporation
Code Snippets
■ Packed class definition
■ Off-heap Packed Allocation
■ On-Heap Packed Allocation
13 © 2012 IBM Corporation
Functionality Changes
Data Field Allocation and Storage
■ Object fields limited to primitives or references to other objects; non-primitives must be initialized and copied into a format understood by Java.
■ When allocating a PackedObject, all corresponding data fields get allocated simultaneously and packed into a single contiguous object (rather than referenced).
Child objects ■ Headers for child objects copied onto the Java heap when accessed.
■ No headers for child objects which all share global header on the PackedObject.
■ For arrays of objects each element in an array has it's own header and a reference to it. The elements are not contiguous in memory.
■ Arrays packed together contiguously under one common header; array length marked in PackedObject header. Full access to elements in array and bounds checking still performed.
Current Java PackedObject
Off-heap
Arrays
■ Data can not be accessed or modified outside of the Java heap. Data must be converted into a Java version and then this copy can then be accessed and manipulated.
■ Data that does not exist in Java can be accessed and modified directly by using the data's memory location. The Java Virtual Machine takes care of the accessors and modifiers internally.
14 © 2012 IBM Corporation
Off Heap Benefit: Lowers Memory Footprint, increases performanceH
EAD
ER
After
HE
ADER
Data
Data
DataDataHeader
Header
Header
Header
Data Copy
Data Copy
Data CopyData Copy
Before
Direct Access, No Copy
Native memory
Java Heap
● Java requires objects to be in primitive form to be accessed directly*
● If objects are not in primitive form, references and copies required to access data; time-consuming conversion process
● When objects are graphed onto the heap, they are placed randomly and occupy more space than is needed
● Memory bloat occurs due to data copies (data must be accessed and copied, including headers)
reference
reference
reference
reference
Header
HeaderHeader
Header
● PackedObjects eliminate requirement for objects to be in primitive form
● PackedObjects can be accessed directly from source without the redundant copying; no conversion
● PackedObject allocates and packs all data fields (including other PackedObject and arrays) into a single well defined contiguous storage area
*without the use of JNI or DBB
15 © 2012 IBM Corporation
Copyright and Trademarks
© IBM Corporation 2012. All Rights Reserved.
IBM, the IBM logo, and ibm.com are trademarks or registered trademarks of International Business Machines Corp., and registered in many jurisdictions worldwide.
Other product and service names might be trademarks of IBM or other companies.
A current list of IBM trademarks is available on the Web – see the IBM “Copyright and trademark information” page at URL: www.ibm.com/legal/copytrade.shtml