data structures that are cloned frequently. • Cloning objects is not only an error-prone and hard to maintain activity, but also can hinder system performance and has some well known inherent flaws [1]. • We conducted an investigation about object cloning to make an evidence-based design decision. • Key drivers • High performance; • Low memory usage; • High code maintainability. 2 1 - Joshua Bloch. Effective Java. 2nd Edition, 2008.
undesirable side effects • Deep • Pros: avoid undesirable side effects • Cons: performance penalties and high memory usage • LAZY – novel approach • Pros: consumes only the necessary memory and improves performance avoiding unnecessary clone operations • Cons: undesirable behavior for non-previsible mutable objects 4 original clone DEEP original clone SHALLOW
each cloning implementation • Synthetic workloads were useful to simulate each implementation on hypothetic scenarios • Measurement Tools • Execution time: JMH¹ • Memory usage: Memory Analyzer² • To evaluate the impact on source code we counted the number of modified LOC to introduce each implementation 7 1 - http://openjdk.java.net/projects/code-tools/jmh/ 2 - http://www.eclipse.org/mat/
Medium case: heaviest fields accesses pattern from the real workload. • Worst case: entire clone’s graph of fields is accessed. SYNTHETIC WORKLOAD RESULTS Memory Usage (bytes) Execution time (µs) 19 45 44 112 159 248 244 259 248 23 119 364 6 39 261 0 50 100 150 200 250 300 350 400 Best Case Medium Case Worst Case AOP DP S R DA DA R S DP AOP 51 0 2 8 2 Modified LOC 4560 4560 4560 4560 4560 4560 5032 5032 5032 104 984 6184 80 560 4560 0 1000 2000 3000 4000 5000 6000 7000 Best Case Medium Case Worst Case AOP DP S R DA
DP) of object cloning based on the lazy approach. • The results can help developers to make evidence-based design decisions when faced with problems that require object cloning. • AOP implementation can be an alternative when high performance and low memory usage are demanded without compromise code maintainability. • For non-previsible mutable objects lazy approach is not recommended. 11