Write barrier optimizations in regions

obj_x.field0 = obj_y;

More precise WB in 7.0

In .NET 7.0 we made the WB much more precise for the regions case, especially for Server GC. Peter did the work. One of the major differences between regions and segments is a region can only belong to one generation, unlike segments where the ephemeral segment can contain gen0, gen1 and potentially gen2 objects. We maintain a compact generation info map for regions (so it's likely in the cache) and pass this info over to the WB side. Then in WB we can get the generation for any address that's on the GC heap. We do the following in the WB -

  1. Get the generation number for the location.
  2. If this is in gen0, nothing to do; else get the generation of the child object.
  3. If the generation of the child object is >= generation of location, nothing to do; else we need to set the card, if it hasn't been set.
enum WriteBarrierFlavor 
{
WRITE_BARRIER_DEFAULT = 0,
WRITE_BARRIER_REGION_BIT = 1,
WRITE_BARRIER_REGION_BYTE = 2,
WRITE_BARRIER_SERVER = 3,
};
ModLoad: 00007fff`28420000 00007fff`2890a000   C:\runtime-segments\artifacts\tests\coreclr\windows.x64.Release\Tests\Core_Root\coreclr.dllBreakpoint 1 hit  
coreclr!JIT_WriteBarrier:
00007fff`2857e040 488911 mov qword ptr [rcx],rdx ds:00000240`80ad46c8=0000000000000000
ModLoad: 00007fff`26150000 00007fff`2663a000   C:\runtime-segments\artifacts\tests\coreclr\windows.x64.Release\Tests\Core_Root\coreclr.dll

Breakpoint 1 hit
coreclr!JIT_WriteBarrier_Callable:
00007fff`262ae240 ff25baed3600 jmp qword ptr [coreclr!JIT_WriteBarrier_Loc (00007fff`2661d000)] ds:00007fff`2661d000={CORINFO_HELP_ASSIGN_REF (00007ffe`c65d0010)}
0:017> t
CORINFO_HELP_ASSIGN_REF:
00007ffe`c65d0010 488911 mov qword ptr [rcx],rdx ds:0000029c`2c86b7e8=0000000000000000

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Maoni0

Maoni0

52 Followers

loves working on #dotnet #dotnetcore GC and other perf stuff; avid zoo-goer; wannabe hiphop dancer.