本篇文章基于V0.16 JOLSample_28_Difference
本来用来演示如何使用GraphLayout
差异来计算对象图之间的变更。
我们还是使用ConcurrentHashMap
, 然后设定三个测量步骤
ConcurrentHashMap
对象初始测量为空
This is the example how would one use the GraphLayout differences to figure out the object graph changes.
Here, we have the ConcurrentHashMap, and three measurements:
- The initial CHM that has no backing storage;
- After adding the first KV pair, when both KV pair is allocated, and the backing storage is allocated;
- After adding the second KV pair.
An API for subtracting the GraphLayouts helps to show the difference between the snapshots.
Note that differences are based on object addresses, so if GC moves under our feet, the difference is unreliable.
It is a good idea to keep the allocations at minimum between the snapshots.
1 | public class JOLSample_28_Difference { |
运行结果
1 | # Running 64-bit HotSpot VM. |