HBASE-17896 The FIXED_OVERHEAD of Segment is incorrect
This commit is contained in:
parent
d7ddc79198
commit
3aadc675b0
|
@ -20,6 +20,7 @@
|
|||
|
||||
package org.apache.hadoop.hbase.util;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
@ -235,6 +236,12 @@ public class ClassSize {
|
|||
}
|
||||
|
||||
private static final MemoryLayout memoryLayout = getMemoryLayout();
|
||||
private static final boolean USE_UNSAFE_LAYOUT = (memoryLayout instanceof UnsafeLayout);
|
||||
|
||||
@VisibleForTesting
|
||||
public static boolean useUnsafeLayout() {
|
||||
return USE_UNSAFE_LAYOUT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method for reading the arc settings and setting overheads according
|
||||
|
|
|
@ -48,12 +48,13 @@ import com.google.common.annotations.VisibleForTesting;
|
|||
@InterfaceAudience.Private
|
||||
public abstract class Segment {
|
||||
|
||||
final static long FIXED_OVERHEAD = ClassSize.align(ClassSize.OBJECT
|
||||
+ 5 * ClassSize.REFERENCE // cellSet, comparator, memStoreLAB, size, timeRangeTracker
|
||||
public final static long FIXED_OVERHEAD = ClassSize.align(ClassSize.OBJECT
|
||||
+ 6 * ClassSize.REFERENCE // cellSet, comparator, memStoreLAB, dataSize,
|
||||
// heapSize, and timeRangeTracker
|
||||
+ Bytes.SIZEOF_LONG // minSequenceId
|
||||
+ Bytes.SIZEOF_BOOLEAN); // tagsPresent
|
||||
public final static long DEEP_OVERHEAD = FIXED_OVERHEAD + ClassSize.ATOMIC_REFERENCE
|
||||
+ ClassSize.CELL_SET + ClassSize.ATOMIC_LONG + ClassSize.TIMERANGE_TRACKER;
|
||||
+ ClassSize.CELL_SET + 2 * ClassSize.ATOMIC_LONG + ClassSize.TIMERANGE_TRACKER;
|
||||
|
||||
private AtomicReference<CellSet> cellSet= new AtomicReference<>();
|
||||
private final CellComparator comparator;
|
||||
|
|
|
@ -344,7 +344,7 @@ public class TestHeapSize {
|
|||
cl = Segment.class;
|
||||
actual = Segment.DEEP_OVERHEAD;
|
||||
expected = ClassSize.estimateBase(cl, false);
|
||||
expected += ClassSize.estimateBase(AtomicLong.class, false);
|
||||
expected += 2 * ClassSize.estimateBase(AtomicLong.class, false);
|
||||
expected += ClassSize.estimateBase(AtomicReference.class, false);
|
||||
expected += ClassSize.estimateBase(CellSet.class, false);
|
||||
expected += ClassSize.estimateBase(TimeRangeTracker.class, false);
|
||||
|
@ -361,7 +361,7 @@ public class TestHeapSize {
|
|||
cl = MutableSegment.class;
|
||||
actual = MutableSegment.DEEP_OVERHEAD;
|
||||
expected = ClassSize.estimateBase(cl, false);
|
||||
expected += ClassSize.estimateBase(AtomicLong.class, false);
|
||||
expected += 2 * ClassSize.estimateBase(AtomicLong.class, false);
|
||||
expected += ClassSize.estimateBase(AtomicReference.class, false);
|
||||
expected += ClassSize.estimateBase(CellSet.class, false);
|
||||
expected += ClassSize.estimateBase(TimeRangeTracker.class, false);
|
||||
|
@ -380,7 +380,7 @@ public class TestHeapSize {
|
|||
cl = ImmutableSegment.class;
|
||||
actual = ImmutableSegment.DEEP_OVERHEAD_CSLM;
|
||||
expected = ClassSize.estimateBase(cl, false);
|
||||
expected += ClassSize.estimateBase(AtomicLong.class, false);
|
||||
expected += 2 * ClassSize.estimateBase(AtomicLong.class, false);
|
||||
expected += ClassSize.estimateBase(AtomicReference.class, false);
|
||||
expected += ClassSize.estimateBase(CellSet.class, false);
|
||||
expected += ClassSize.estimateBase(TimeRangeTracker.class, false);
|
||||
|
@ -398,7 +398,7 @@ public class TestHeapSize {
|
|||
}
|
||||
actual = ImmutableSegment.DEEP_OVERHEAD_CAM;
|
||||
expected = ClassSize.estimateBase(cl, false);
|
||||
expected += ClassSize.estimateBase(AtomicLong.class, false);
|
||||
expected += 2 * ClassSize.estimateBase(AtomicLong.class, false);
|
||||
expected += ClassSize.estimateBase(AtomicReference.class, false);
|
||||
expected += ClassSize.estimateBase(CellSet.class, false);
|
||||
expected += ClassSize.estimateBase(TimeRangeTracker.class, false);
|
||||
|
@ -504,8 +504,11 @@ public class TestHeapSize {
|
|||
} else {
|
||||
assertTrue(ClassSize.OBJECT == 12 || ClassSize.OBJECT == 16); // depending on CompressedOops
|
||||
}
|
||||
assertEquals(ClassSize.OBJECT + 4, ClassSize.ARRAY);
|
||||
if (ClassSize.useUnsafeLayout()) {
|
||||
assertEquals(ClassSize.OBJECT + 4, ClassSize.ARRAY);
|
||||
} else {
|
||||
assertEquals(ClassSize.OBJECT + 8, ClassSize.ARRAY);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue