Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
* @author Attila Szegedi
*/
public class ObjectSizeCalculator {
private static final ThreadLocal<ObjectSizeCalculator> OBJECT_SIZE_CALCULATOR_THREAD_LOCAL = ThreadLocal.withInitial(() -> new ObjectSizeCalculator(CurrentLayout.SPEC));

private static class CurrentLayout {

private static final MemoryLayoutSpecification SPEC = getEffectiveMemoryLayoutSpecification();
Expand All @@ -71,7 +73,7 @@ private static class CurrentLayout {
* @throws UnsupportedOperationException if the current vm memory layout cannot be detected.
*/
public static long getObjectSize(Object obj) throws UnsupportedOperationException {
return obj == null ? 0 : new ObjectSizeCalculator(CurrentLayout.SPEC).calculateObjectSize(obj);
return obj == null ? 0 : OBJECT_SIZE_CALCULATOR_THREAD_LOCAL.get().calculateObjectSize(obj);
}

// Fixed object header size for arrays.
Expand Down