Skip to content

Commit

Permalink
ISPN-8655 Off Heap Size Estimation rounds improperly
Browse files Browse the repository at this point in the history
* Make sure to round up to 16 properly
* Added tests
  • Loading branch information
wburns authored and galderz committed Jan 12, 2018
1 parent e2c117c commit b7ae986
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
Expand Up @@ -72,6 +72,6 @@ public long getAllocatedAmount() {
*/
public static long estimateSizeOverhead(long size) {
// We take 8 and add the number provided and then round up to 16 (& operator has higher precedence than +)
return (size + 8 + 15) & ~0x15;
return (size + 8 + 15) & ~15;
}
}
@@ -0,0 +1,33 @@
package org.infinispan.container.offheap;

import static org.testng.AssertJUnit.assertEquals;

import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

/**
* @author wburns
* @since 9.0
*/
@Test(groups = "functional", testName = "container.offheap.UnpooledOffHeapMemoryAllocatorTest")
public class UnpooledOffHeapMemoryAllocatorTest {

@DataProvider(name = "roundings")
Object[][] roundings() {
return new Object[][] {
{ 2, 16 },
{ 14, 32 },
{ 23, 32 },
{ 32, 48 },
{ 123, 144 },
{ 43, 64 },
{ 73, 96 },
};
}

@Test(dataProvider = "roundings")
public void testRoundings(long original, long expected) {
// The estimate adds 8 and rounds up to 16
assertEquals(expected, UnpooledOffHeapMemoryAllocator.estimateSizeOverhead(original));
}
}

0 comments on commit b7ae986

Please sign in to comment.