Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cached interface dispatch for coreclr #111771

Open
wants to merge 39 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
2b2ca52
Move the cached interface dispatch code into a shared region
davidwrighton Jan 8, 2025
4892674
Split cached interface dispatch up into a component which is focussed…
davidwrighton Jan 14, 2025
d69528f
It builds for X64, VTable stuff isn't probably correct, but its basic…
davidwrighton Jan 16, 2025
5f1f2b5
Add indirection cell helper so that VSD and CachedInterfaceDispatch c…
davidwrighton Jan 21, 2025
976bf83
Ready to try running things. R2R not yet supported. Virtual delegates…
davidwrighton Jan 22, 2025
652930c
Initialize CachedInterfaceDispatch at startup
davidwrighton Jan 22, 2025
39a2574
AMD64 seems to work
davidwrighton Jan 22, 2025
4c0865c
Arm64 Windows assembly written and factored amd64 to be similar
davidwrighton Jan 22, 2025
645c487
Allow there to be flavors of the build which do not build cached inte…
davidwrighton Jan 22, 2025
921631a
Make it possible for some OS/Architecture sets to have cached interfa…
davidwrighton Jan 24, 2025
73b0b26
Fix X86 build
davidwrighton Jan 24, 2025
2cdd955
Get Linux Arm64 and Amd64 into a possibly good state
davidwrighton Jan 24, 2025
edad834
Enable cached interface dispatch to build properly on Linux Amd64. No…
davidwrighton Jan 24, 2025
df393d9
Enable building cached interface dispatch for Linux arm64
davidwrighton Jan 24, 2025
cce3bcb
Add AVLocation for the VTable helper which wasn't present in the Nati…
davidwrighton Jan 24, 2025
4bbcdaa
Merge branch 'main' of github.com:dotnet/runtime into cached_interfac…
davidwrighton Jan 24, 2025
c320e1d
Fix musl build failure
davidwrighton Jan 25, 2025
361588a
Handle missed RhpVTableOffsetDispatchAVLocation case
davidwrighton Jan 25, 2025
24e78b2
Move RiscV stub dispatch logic to the same place as everything else
davidwrighton Jan 25, 2025
5b0e5ac
Fix assertion issue with collectible assemblies
davidwrighton Jan 27, 2025
fa7826a
Reduce InterfaceDispatchCell size from 4 pointers to 2, and actually …
davidwrighton Jan 27, 2025
f1c2c65
Use the isCachedInterfaceDispatchStubAVLocation helper where appropriate
davidwrighton Jan 28, 2025
36c9cc0
Enable using cached interface dispatch in R2R
davidwrighton Jan 28, 2025
9377342
Merge branch 'main' of https://github.com/dotnet/runtime into cached_…
davidwrighton Jan 28, 2025
a3a4ff1
Move PalInterlockedCompareExchange128 to the PAL/minipal
davidwrighton Jan 28, 2025
18b3f13
Add support for cleaning up memory for the cache blocks
davidwrighton Jan 29, 2025
80ae02b
Fix Open Virtual Dispatch on Delegates
davidwrighton Jan 29, 2025
081fac5
Try to fix unix build
davidwrighton Jan 29, 2025
a0b9d2a
Fixes for issues found in CI
davidwrighton Jan 30, 2025
dcbe17c
Fix more issues found on Unix platforms
davidwrighton Jan 30, 2025
6e5a394
Merge branch 'main' into cached_interface_dispatch_for_coreclr
davidwrighton Jan 31, 2025
48b5009
Fix x64 stub dispatch code to use the right register, and switch to a…
davidwrighton Jan 31, 2025
ad64a55
Merge branch 'main' of https://github.com/dotnet/runtime into cached_…
davidwrighton Feb 3, 2025
fa72602
Add environment variable to control use of cached dispatch for testin…
davidwrighton Feb 3, 2025
08ac0a1
Fix interface stepping for cached interface dispatch
davidwrighton Feb 4, 2025
006537d
Respond to most of the feedback
davidwrighton Feb 7, 2025
2ff4d2a
Feedback and fixes
davidwrighton Feb 8, 2025
6cb2b78
Merge branch 'main' of https://github.com/dotnet/runtime into cached_…
davidwrighton Feb 8, 2025
70dacc0
Use runtime as the directory to hold stuff shared between NativeAOT a…
davidwrighton Feb 8, 2025
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
14 changes: 13 additions & 1 deletion src/coreclr/clrfeatures.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,16 @@ endif()

if (CLR_CMAKE_TARGET_WIN32)
set(FEATURE_TYPEEQUIVALENCE 1)
endif(CLR_CMAKE_TARGET_WIN32)
endif(CLR_CMAKE_TARGET_WIN32)

if (CLR_CMAKE_TARGET_ARCH_AMD64 OR CLR_CMAKE_TARGET_ARCH_ARM64)
if (CLR_CMAKE_TARGET_UNIX AND CLR_CMAKE_TARGET_ARCH_AMD64)
# Allow 16 byte compare-exchange (cmpxchg16b)
add_compile_options(-mcx16)
endif()
AaronRobinsonMSFT marked this conversation as resolved.
Show resolved Hide resolved
set(FEATURE_CORECLR_CACHED_INTERFACE_DISPATCH 1)
endif()

if (NOT (CLR_CMAKE_TARGET_ARCH_AMD64 OR CLR_CMAKE_TARGET_ARCH_ARM64))
set(FEATURE_CORECLR_VIRTUAL_STUB_DISPATCH 1)
endif()
3 changes: 3 additions & 0 deletions src/coreclr/crossgen-corelib.proj
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,10 @@
<CrossGenDllCmd Condition="'$(TargetsAndroid)' == 'true'">$(CrossGenDllCmd) --targetos:linux</CrossGenDllCmd>
<CrossGenDllCmd Condition="'$(UsingToolIbcOptimization)' != 'true' and '$(EnableNgenOptimization)' == 'true'">$(CrossGenDllCmd) -m:$(MergedMibcPath) --embed-pgo-data</CrossGenDllCmd>
<CrossGenDllCmd>$(CrossGenDllCmd) -O</CrossGenDllCmd>
<!-- Enable type and field layout verification to make it easier to catch when the crossgen2 type layout engine and the runtime disagree on layout conventions -->
<CrossGenDllCmd Condition="'$(Configuration)' == 'Debug' or '$(Configuration)' == 'Checked'">$(CrossGenDllCmd) --verify-type-and-field-layout</CrossGenDllCmd>
<!-- Enable Cached Interface Dispatch layout rules for the StubDispatch import section. This allows testing of this path on platforms that do not require CachedInterface Dispatch -->
<CrossGenDllCmd Condition="'$(Configuration)' == 'Debug' or '$(Configuration)' == 'Checked'">$(CrossGenDllCmd) --enable-cached-interface-dispatch-support</CrossGenDllCmd>
<CrossGenDllCmd>$(CrossGenDllCmd) @(CoreLib)</CrossGenDllCmd>
</PropertyGroup>

Expand Down
8 changes: 8 additions & 0 deletions src/coreclr/debug/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
if(FEATURE_CORECLR_CACHED_INTERFACE_DISPATCH)
add_definitions(-DFEATURE_CACHED_INTERFACE_DISPATCH)
endif(FEATURE_CORECLR_CACHED_INTERFACE_DISPATCH)

if(FEATURE_CORECLR_VIRTUAL_STUB_DISPATCH)
add_definitions(-DFEATURE_VIRTUAL_STUB_DISPATCH)
endif(FEATURE_CORECLR_VIRTUAL_STUB_DISPATCH)

add_subdirectory(daccess)
add_subdirectory(ee)
add_subdirectory(di)
Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/debug/daccess/dacdbiimpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3544,7 +3544,9 @@ void DacDbiInterfaceImpl::EnumerateMemRangesForLoaderAllocator(PTR_LoaderAllocat
if (pVcsMgr)
{
if (pVcsMgr->indcell_heap != NULL) heapsToEnumerate.Push(pVcsMgr->indcell_heap);
#ifdef FEATURE_VIRTUAL_STUB_DISPATCH
if (pVcsMgr->cache_entry_heap != NULL) heapsToEnumerate.Push(pVcsMgr->cache_entry_heap);
#endif
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#endif
#endif // FEATURE_VIRTUAL_STUB_DISPATCH

}

TADDR rangeAccumAsTaddr = TO_TADDR(rangeAcummulator);
Expand Down
10 changes: 9 additions & 1 deletion src/coreclr/debug/daccess/request.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3595,14 +3595,18 @@ ClrDataAccess::TraverseVirtCallStubHeap(CLRDATA_ADDRESS pAppDomain, VCSHeapType
break;

case CacheEntryHeap:
#ifdef FEATURE_VIRTUAL_STUB_DISPATCH
pLoaderHeap = pVcsMgr->cache_entry_heap;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we get a small comment here on why the CacheEntryHeap is not used in the caching logic? I'm ignorant of this area and it feels odd that the VirtualCallStubManager is used, but ignored in some cases. Perhaps an assert or some other breadcrumb to indicate why this isn't appropriate.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could use it, and possibly should, but as I noted in the PR description, I intentionally disabled this feature since it was more work to enable, and this change is already too big for easy development. If we decide that this sort of caching is advantageous, it would be appropriate in a separate PR to enable it for the cached interface dispatch scenario.

#else
hr = S_OK;
davidwrighton marked this conversation as resolved.
Show resolved Hide resolved
#endif
break;

default:
hr = E_INVALIDARG;
}

if (SUCCEEDED(hr))
if (SUCCEEDED(hr) && (pLoaderHeap != NULL))
{
hr = TraverseLoaderHeapBlock(pLoaderHeap->m_pFirstBlock, pFunc);
}
Expand Down Expand Up @@ -3645,7 +3649,9 @@ static const char *LoaderAllocatorLoaderHeapNames[] =
"FixupPrecodeHeap",
"NewStubPrecodeHeap",
"IndcellHeap",
#ifdef FEATURE_VIRTUAL_STUB_DISPATCH
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This adds to the confusion from above considering case CacheEntryHeap: remains, but we define out the string.

"CacheEntryHeap",
#endif
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#endif
#endif // FEATURE_VIRTUAL_STUB_DISPATCH

};


Expand Down Expand Up @@ -3689,7 +3695,9 @@ HRESULT ClrDataAccess::GetLoaderAllocatorHeaps(CLRDATA_ADDRESS loaderAllocatorAd
else
{
pLoaderHeaps[i++] = HOST_CDADDR(pVcsMgr->indcell_heap);
#ifdef FEATURE_VIRTUAL_STUB_DISPATCH
pLoaderHeaps[i++] = HOST_CDADDR(pVcsMgr->cache_entry_heap);
#endif
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#endif
#endif // FEATURE_VIRTUAL_STUB_DISPATCH

}

// All of the above are "LoaderHeap" and not the ExplicitControl version.
Expand Down
3 changes: 3 additions & 0 deletions src/coreclr/inc/CrstTypes.def
Original file line number Diff line number Diff line change
Expand Up @@ -532,3 +532,6 @@ End
Crst PerfMap
AcquiredAfter CodeVersioning AssemblyList
End

Crst InterfaceDispatchGlobalLists
End
123 changes: 63 additions & 60 deletions src/coreclr/inc/crsttypes_generated.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,66 +60,67 @@ enum CrstType
CrstILStubGen = 42,
CrstInlineTrackingMap = 43,
CrstInstMethodHashTable = 44,
CrstInterop = 45,
CrstInteropData = 46,
CrstIsJMCMethod = 47,
CrstISymUnmanagedReader = 48,
CrstJit = 49,
CrstJitInlineTrackingMap = 50,
CrstJitPatchpoint = 51,
CrstJumpStubCache = 52,
CrstLeafLock = 53,
CrstListLock = 54,
CrstLoaderAllocator = 55,
CrstLoaderAllocatorReferences = 56,
CrstLoaderHeap = 57,
CrstManagedObjectWrapperMap = 58,
CrstMethodDescBackpatchInfoTracker = 59,
CrstMethodTableExposedObject = 60,
CrstModule = 61,
CrstModuleLookupTable = 62,
CrstMulticoreJitHash = 63,
CrstMulticoreJitManager = 64,
CrstNativeImageEagerFixups = 65,
CrstNativeImageLoad = 66,
CrstNotifyGdb = 67,
CrstPEImage = 68,
CrstPendingTypeLoadEntry = 69,
CrstPerfMap = 70,
CrstPgoData = 71,
CrstPinnedByrefValidation = 72,
CrstPinnedHeapHandleTable = 73,
CrstProfilerGCRefDataFreeList = 74,
CrstProfilingAPIStatus = 75,
CrstRCWCache = 76,
CrstRCWCleanupList = 77,
CrstReadyToRunEntryPointToMethodDescMap = 78,
CrstReflection = 79,
CrstReJITGlobalRequest = 80,
CrstRetThunkCache = 81,
CrstSigConvert = 82,
CrstSingleUseLock = 83,
CrstStressLog = 84,
CrstStubCache = 85,
CrstStubDispatchCache = 86,
CrstSyncBlockCache = 87,
CrstSyncHashLock = 88,
CrstSystemDomain = 89,
CrstSystemDomainDelayedUnloadList = 90,
CrstThreadIdDispenser = 91,
CrstThreadLocalStorageLock = 92,
CrstThreadStore = 93,
CrstTieredCompilation = 94,
CrstTypeEquivalenceMap = 95,
CrstTypeIDMap = 96,
CrstUMEntryThunkCache = 97,
CrstUMEntryThunkFreeListLock = 98,
CrstUniqueStack = 99,
CrstUnresolvedClassLock = 100,
CrstUnwindInfoTableLock = 101,
CrstVSDIndirectionCellLock = 102,
CrstWrapperTemplate = 103,
kNumberOfCrstTypes = 104
CrstInterfaceDispatchGlobalLists = 45,
CrstInterop = 46,
CrstInteropData = 47,
CrstIsJMCMethod = 48,
CrstISymUnmanagedReader = 49,
CrstJit = 50,
CrstJitInlineTrackingMap = 51,
CrstJitPatchpoint = 52,
CrstJumpStubCache = 53,
CrstLeafLock = 54,
CrstListLock = 55,
CrstLoaderAllocator = 56,
CrstLoaderAllocatorReferences = 57,
CrstLoaderHeap = 58,
CrstManagedObjectWrapperMap = 59,
CrstMethodDescBackpatchInfoTracker = 60,
CrstMethodTableExposedObject = 61,
CrstModule = 62,
CrstModuleLookupTable = 63,
CrstMulticoreJitHash = 64,
CrstMulticoreJitManager = 65,
CrstNativeImageEagerFixups = 66,
CrstNativeImageLoad = 67,
CrstNotifyGdb = 68,
CrstPEImage = 69,
CrstPendingTypeLoadEntry = 70,
CrstPerfMap = 71,
CrstPgoData = 72,
CrstPinnedByrefValidation = 73,
CrstPinnedHeapHandleTable = 74,
CrstProfilerGCRefDataFreeList = 75,
CrstProfilingAPIStatus = 76,
CrstRCWCache = 77,
CrstRCWCleanupList = 78,
CrstReadyToRunEntryPointToMethodDescMap = 79,
CrstReflection = 80,
CrstReJITGlobalRequest = 81,
CrstRetThunkCache = 82,
CrstSigConvert = 83,
CrstSingleUseLock = 84,
CrstStressLog = 85,
CrstStubCache = 86,
CrstStubDispatchCache = 87,
CrstSyncBlockCache = 88,
CrstSyncHashLock = 89,
CrstSystemDomain = 90,
CrstSystemDomainDelayedUnloadList = 91,
CrstThreadIdDispenser = 92,
CrstThreadLocalStorageLock = 93,
CrstThreadStore = 94,
CrstTieredCompilation = 95,
CrstTypeEquivalenceMap = 96,
CrstTypeIDMap = 97,
CrstUMEntryThunkCache = 98,
CrstUMEntryThunkFreeListLock = 99,
CrstUniqueStack = 100,
CrstUnresolvedClassLock = 101,
CrstUnwindInfoTableLock = 102,
CrstVSDIndirectionCellLock = 103,
CrstWrapperTemplate = 104,
kNumberOfCrstTypes = 105
};

#endif // __CRST_TYPES_INCLUDED
Expand Down Expand Up @@ -175,6 +176,7 @@ int g_rgCrstLevelMap[] =
6, // CrstILStubGen
2, // CrstInlineTrackingMap
18, // CrstInstMethodHashTable
0, // CrstInterfaceDispatchGlobalLists
21, // CrstInterop
9, // CrstInteropData
0, // CrstIsJMCMethod
Expand Down Expand Up @@ -284,6 +286,7 @@ LPCSTR g_rgCrstNameMap[] =
"CrstILStubGen",
"CrstInlineTrackingMap",
"CrstInstMethodHashTable",
"CrstInterfaceDispatchGlobalLists",
"CrstInterop",
"CrstInteropData",
"CrstIsJMCMethod",
Expand Down
12 changes: 2 additions & 10 deletions src/coreclr/jit/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -8538,16 +8538,8 @@ class Compiler
reg = REG_EAX;
regMask = RBM_EAX;
#elif defined(TARGET_AMD64)
if (isNativeAOT)
{
reg = REG_R10;
regMask = RBM_R10;
}
else
{
reg = REG_R11;
regMask = RBM_R11;
}
reg = REG_R11;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AAGGHH.. reading this has sent me down the rabbit hole of sadness which has told me that I need to move both CoreCLR and NativeAOT to use r10, and not to r11 as that is the only way to keep CFG from exploding sadly. (Or I can keep the difference between CoreCLR and NativeAOT).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea of getting these unified as you may guess.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or rather... this won't break stuff, but the codegen for CFG is required to be a bit non-ideal in native aot..OTOH, it appears with some quick testing that this doesn't actually effect the codegen in any case, since our CFG generation logic isn't what I'd call great right now, so I'd like to keep moving everything to r11. If we want to use r10 we can swap back all of the amd64 stuff at once.

regMask = RBM_R11;
#elif defined(TARGET_ARM)
if (isNativeAOT)
{
Expand Down
13 changes: 13 additions & 0 deletions src/coreclr/minipal/minipal.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,16 @@ class VMToOSInterface
// true if it succeeded, false if it failed
static bool ReleaseRWMapping(void* pStart, size_t size);
};

#if defined(HOST_64BIT) && defined(FEATURE_CACHED_INTERFACE_DISPATCH)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice if we added the InterlockedCompareExchange128 to the VMToOSInterface above and implemented it for Unix / Windows in the respective subfolders.
When I have started with this minipal, the intent was that all stuff that needs to be platform specific will go there. Once we get rid of coreclr PAL, this was meant to be the only place for platform specific code.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, this is a case where we want to have a shared set of PAL apis between CoreCLR and NativeAOT, and NativeAOT hasn't moved towards the VmToOSInterface idea (And this change is already WAY too big to add that to it.) I'd welcome some rationalization after this is all merged.

EXTERN_C uint8_t _InterlockedCompareExchange128(int64_t volatile *, int64_t, int64_t, int64_t *);

#if defined(HOST_WINDOWS)
#pragma intrinsic(_InterlockedCompareExchange128)
#endif

FORCEINLINE uint8_t PalInterlockedCompareExchange128(_Inout_ int64_t volatile *pDst, int64_t iValueHigh, int64_t iValueLow, int64_t *pComparandAndResult)
{
return _InterlockedCompareExchange128(pDst, iValueHigh, iValueLow, pComparandAndResult);
}
#endif // defined(HOST_64BIT) && defined(FEATURE_CACHED_INTERFACE_DISPATCH)
2 changes: 1 addition & 1 deletion src/coreclr/nativeaot/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ if(CLR_CMAKE_HOST_UNIX)
endif(CLR_CMAKE_TARGET_APPLE)

if(CLR_CMAKE_TARGET_ARCH_AMD64 OR CLR_CMAKE_TARGET_ARCH_I386)
# Allow 16 byte compare-exchange
# Allow 16 byte compare-exchange (cmpxchg16b)
add_compile_options(-mcx16)
endif(CLR_CMAKE_TARGET_ARCH_AMD64 OR CLR_CMAKE_TARGET_ARCH_I386)
endif (CLR_CMAKE_HOST_UNIX)
Expand Down
13 changes: 11 additions & 2 deletions src/coreclr/nativeaot/Runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
set(GC_DIR ../../gc)
set(SHARED_RUNTIME_DIR ../../shared_runtime)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A nit - we don't have any folders that have names with underscores, it would be nice to stay consistent.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to hear opinions on the directory structure from several people here. @AaronRobinsonMSFT might also be interested to comment on this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jit and gc are shared too, but they do not have shared_ in the name. I am not a fan of the shared_ prefix.

Maybe just call it runtime?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

runtime seems appropriate. I agree that a prefix would be nice, but I agree with @janvorli's consistency argument. @jkotas's dislike of shared_ is something I share too. I think shared is also dangerous as it breeds a dumping ground akin to utils.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

runtime it is. I'll make the changes soon.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll be leaving the CMAKE name of the directory as SHARED_RUNTIME_DIR though, as RUNTIME_DIR is already taken for src/coreclr/nativeaot/Runtime

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename RUNTIME_DIR -> NATIVEAOT_RUNTIME_DIR and SHARED_RUNTIME_DIR -> RUNTIME_DIR? There are only 25 instances of RUNTIME_DIR spread over 4 files.


set(COMMON_RUNTIME_SOURCES
allocheap.cpp
rhassert.cpp
CachedInterfaceDispatch.cpp
${SHARED_RUNTIME_DIR}/CachedInterfaceDispatch.cpp
CachedInterfaceDispatchAot.cpp
Crst.cpp
DebugHeader.cpp
MethodTable.cpp
Expand Down Expand Up @@ -76,6 +78,7 @@ include_directories(.)
include_directories(${GC_DIR})
include_directories(${GC_DIR}/env)
include_directories(${CMAKE_CURRENT_BINARY_DIR}/eventpipe/inc)
include_directories(${SHARED_RUNTIME_DIR})

if (WIN32)
set(GC_HEADERS
Expand Down Expand Up @@ -208,11 +211,17 @@ list(APPEND RUNTIME_SOURCES_ARCH_ASM
${ARCH_SOURCES_DIR}/MiscStubs.${ASM_SUFFIX}
${ARCH_SOURCES_DIR}/PInvoke.${ASM_SUFFIX}
${ARCH_SOURCES_DIR}/InteropThunksHelpers.${ASM_SUFFIX}
${ARCH_SOURCES_DIR}/StubDispatch.${ASM_SUFFIX}
${SHARED_RUNTIME_DIR}/${ARCH_SOURCES_DIR}/StubDispatch.${ASM_SUFFIX}
${ARCH_SOURCES_DIR}/UniversalTransition.${ASM_SUFFIX}
${ARCH_SOURCES_DIR}/WriteBarriers.${ASM_SUFFIX}
)

if (CLR_CMAKE_TARGET_ARCH_AMD64 OR CLR_CMAKE_TARGET_ARCH_ARM64)
list(APPEND RUNTIME_SOURCES_ARCH_ASM
${ARCH_SOURCES_DIR}/CachedInterfaceDispatchAot.${ASM_SUFFIX}
)
endif ()

# Add architecture specific folder for looking up headers.
convert_to_absolute_path(ARCH_SOURCES_DIR ${ARCH_SOURCES_DIR})
include_directories(${ARCH_SOURCES_DIR})
Expand Down
54 changes: 54 additions & 0 deletions src/coreclr/nativeaot/Runtime/CachedInterfaceDispatchAot.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#include "common.h"
#include "CachedInterfaceDispatchPal.h"
#include "CachedInterfaceDispatch.h"

// The base memory allocator.
static AllocHeap * g_pAllocHeap = NULL;

bool InterfaceDispatch_InitializePal()
{
g_pAllocHeap = new (nothrow) AllocHeap();
if (g_pAllocHeap == NULL)
return false;

if (!g_pAllocHeap->Init())
return false;

return true;
}

// Allocate memory aligned at sizeof(void*)*2 boundaries
void *InterfaceDispatch_AllocDoublePointerAligned(size_t size)
{
return g_pAllocHeap->AllocAligned(size, sizeof(void*) * 2);
}

// Allocate memory aligned at at least sizeof(void*)
void *InterfaceDispatch_AllocPointerAligned(size_t size)
{
return g_pAllocHeap->Alloc(size);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return g_pAllocHeap->Alloc(size);
return g_pAllocHeap->AllocAligned(size, sizeof(void*));

I get that perhaps the Alloc() provides this guarantee, but it looks odd for one to call out alignment and use an explicit API and the other providing a similar guarantee and calling a seemingly more general function. It also looks like Alloc() calls AllocAligned() and passes 1, so now I have more questions.

}

FCIMPL4(PCODE, RhpUpdateDispatchCellCache, InterfaceDispatchCell * pCell, PCODE pTargetCode, MethodTable* pInstanceType, DispatchCellInfo *pNewCellInfo)
{
return InterfaceDispatch_UpdateDispatchCellCache(pCell, pTargetCode, pInstanceType, pNewCellInfo);
}
FCIMPLEND

FCIMPL2(PCODE, RhpSearchDispatchCellCache, InterfaceDispatchCell * pCell, MethodTable* pInstanceType)
{
return InterfaceDispatch_SearchDispatchCellCache(pCell, pInstanceType);
}
FCIMPLEND

// Given a dispatch cell, get the type and slot associated with it. This function MUST be implemented
// in cooperative native code, as the m_pCache field on the cell is unsafe to access from managed
// code due to its use of the GC state as a lock, and as lifetime control
FCIMPL2(void, RhpGetDispatchCellInfo, InterfaceDispatchCell * pCell, DispatchCellInfo* pDispatchCellInfo)
{
*pDispatchCellInfo = pCell->GetDispatchCellInfo();
}
FCIMPLEND
Loading
Loading