Skip to content

Commit

Permalink
mem layout
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Peck committed May 7, 2024
1 parent 3196417 commit 3e24514
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="Moq" Version="4.20.69" />
<PackageReference Include="ObjectLayoutInspector" Version="0.1.4" />
<PackageReference Include="xunit" Version="2.8.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PrivateAssets>all</PrivateAssets>
Expand Down
96 changes: 96 additions & 0 deletions BitFaster.Caching.UnitTests/Lfu/NodeMemoryLayoutDumps.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
using BitFaster.Caching.Lfu;
using ObjectLayoutInspector;
using Xunit;
using Xunit.Abstractions;

namespace BitFaster.Caching.UnitTests.Lfu
{
public class NodeMemoryLayoutDumps
{
private readonly ITestOutputHelper testOutputHelper;

public NodeMemoryLayoutDumps(ITestOutputHelper testOutputHelper)
{
this.testOutputHelper = testOutputHelper;
}

//Type layout for 'AccessOrderNode`2'
//Size: 48 bytes.Paddings: 2 bytes(%4 of empty space)
//|====================================================|
//| Object Header(8 bytes) |
//|----------------------------------------------------|
//| Method Table Ptr(8 bytes) |
//|====================================================|
//| 0-7: LfuNodeList`2 list(8 bytes) |
//|----------------------------------------------------|
//| 8-15: LfuNode`2 next(8 bytes) |
//|----------------------------------------------------|
//| 16-23: LfuNode`2 prev(8 bytes) |
//|----------------------------------------------------|
//| 24-31: Object Key(8 bytes) |
//|----------------------------------------------------|
//| 32-39: Object<Value> k__BackingField(8 bytes) |
//|----------------------------------------------------|
//| 40-43: Position<Position> k__BackingField(4 bytes) |
//| |===============================| |
//| | 0-3: Int32 value__(4 bytes) | |
//| |===============================| |
//|----------------------------------------------------|
//| 44: Boolean wasRemoved(1 byte) |
//|----------------------------------------------------|
//| 45: Boolean wasDeleted(1 byte) |
//|----------------------------------------------------|
//| 46-47: padding(2 bytes) |
//|====================================================|
[Fact]
public void DumpAccessOrderNode()
{
var layout = TypeLayout.GetLayout<AccessOrderNode<object, object>>(includePaddings: true);
testOutputHelper.WriteLine(layout.ToString());
}

//Type layout for 'TimeOrderNode`2'
//Size: 72 bytes.Paddings: 2 bytes(%2 of empty space)
//|====================================================|
//| Object Header(8 bytes) |
//|----------------------------------------------------|
//| Method Table Ptr(8 bytes) |
//|====================================================|
//| 0-7: LfuNodeList`2 list(8 bytes) |
//|----------------------------------------------------|
//| 8-15: LfuNode`2 next(8 bytes) |
//|----------------------------------------------------|
//| 16-23: LfuNode`2 prev(8 bytes) |
//|----------------------------------------------------|
//| 24-31: Object Key(8 bytes) |
//|----------------------------------------------------|
//| 32-39: Object<Value> k__BackingField(8 bytes) |
//|----------------------------------------------------|
//| 40-43: Position<Position> k__BackingField(4 bytes) |
//| |===============================| |
//| | 0-3: Int32 value__(4 bytes) | |
//| |===============================| |
//|----------------------------------------------------|
//| 44: Boolean wasRemoved(1 byte) |
//|----------------------------------------------------|
//| 45: Boolean wasDeleted(1 byte) |
//|----------------------------------------------------|
//| 46-47: padding(2 bytes) |
//|----------------------------------------------------|
//| 48-55: TimeOrderNode`2 prevTime(8 bytes) |
//|----------------------------------------------------|
//| 56-63: TimeOrderNode`2 nextTime(8 bytes) |
//|----------------------------------------------------|
//| 64-71: Duration timeToExpire(8 bytes) |
//| |===========================| |
//| | 0-7: Int64 raw(8 bytes) | |
//| |===========================| |
//|====================================================|
[Fact]
public void DumpTimeOrderNode()
{
var layout = TypeLayout.GetLayout<TimeOrderNode<object, object>>(includePaddings: true);
testOutputHelper.WriteLine(layout.ToString());
}
}
}

0 comments on commit 3e24514

Please sign in to comment.