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

[NativeAOT] Remove ThunkPool crst. #88778

Merged
merged 5 commits into from
Aug 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -257,34 +257,14 @@ internal static extern unsafe IntPtr RhpCallPropagateExceptionCallback(
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern unsafe void RhpCopyContextFromExInfo(void* pOSContext, int cbOSContext, EH.PAL_LIMITED_CONTEXT* pPalContext);

[RuntimeImport(Redhawk.BaseName, "RhpGetNumThunkBlocksPerMapping")]
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern int RhpGetNumThunkBlocksPerMapping();

[RuntimeImport(Redhawk.BaseName, "RhpGetNumThunksPerBlock")]
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern int RhpGetNumThunksPerBlock();

[RuntimeImport(Redhawk.BaseName, "RhpGetThunkSize")]
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern int RhpGetThunkSize();

[RuntimeImport(Redhawk.BaseName, "RhpGetThunkDataBlockAddress")]
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern IntPtr RhpGetThunkDataBlockAddress(IntPtr thunkStubAddress);

[RuntimeImport(Redhawk.BaseName, "RhpGetThunkStubsBlockAddress")]
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern IntPtr RhpGetThunkStubsBlockAddress(IntPtr thunkDataAddress);

[RuntimeImport(Redhawk.BaseName, "RhpGetThunkBlockSize")]
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern int RhpGetThunkBlockSize();

[RuntimeImport(Redhawk.BaseName, "RhpGetThreadAbortException")]
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern Exception RhpGetThreadAbortException();

[RuntimeImport(Redhawk.BaseName, "RhCurrentNativeThreadId")]
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern unsafe IntPtr RhCurrentNativeThreadId();

//------------------------------------------------------------------------------------------------------------
// PInvoke-based internal calls
//
Expand All @@ -310,18 +290,6 @@ internal static extern unsafe IntPtr RhpCallPropagateExceptionCallback(
[UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })]
internal static extern ulong RhpGetTickCount64();

[DllImport(Redhawk.BaseName)]
[UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })]
internal static extern void RhpAcquireThunkPoolLock();

[DllImport(Redhawk.BaseName)]
[UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })]
internal static extern void RhpReleaseThunkPoolLock();

[DllImport(Redhawk.BaseName)]
[UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })]
internal static extern IntPtr RhAllocateThunksMapping();

// Enters a no GC region, possibly doing a blocking GC if there is not enough
// memory available to satisfy the caller's request.
[DllImport(Redhawk.BaseName)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,42 +332,6 @@ private static unsafe int RhpCalculateStackTraceWorker(IntPtr* pOutputBuffer, ui
return success ? (int)nFrames : -(int)nFrames;
}

[RuntimeExport("RhCreateThunksHeap")]
public static object RhCreateThunksHeap(IntPtr commonStubAddress)
{
return ThunksHeap.CreateThunksHeap(commonStubAddress);
}

[RuntimeExport("RhAllocateThunk")]
public static IntPtr RhAllocateThunk(object thunksHeap)
{
return ((ThunksHeap)thunksHeap).AllocateThunk();
}

[RuntimeExport("RhFreeThunk")]
public static void RhFreeThunk(object thunksHeap, IntPtr thunkAddress)
{
((ThunksHeap)thunksHeap).FreeThunk(thunkAddress);
}

[RuntimeExport("RhSetThunkData")]
public static void RhSetThunkData(object thunksHeap, IntPtr thunkAddress, IntPtr context, IntPtr target)
{
((ThunksHeap)thunksHeap).SetThunkData(thunkAddress, context, target);
}

[RuntimeExport("RhTryGetThunkData")]
public static bool RhTryGetThunkData(object thunksHeap, IntPtr thunkAddress, out IntPtr context, out IntPtr target)
{
return ((ThunksHeap)thunksHeap).TryGetThunkData(thunkAddress, out context, out target);
}

[RuntimeExport("RhGetThunkSize")]
public static int RhGetThunkSize()
{
return InternalCalls.RhpGetThunkSize();
}

[RuntimeExport("RhGetRuntimeHelperForType")]
internal static unsafe IntPtr RhGetRuntimeHelperForType(MethodTable* pEEType, RuntimeHelperKind kind)
{
Expand Down
2 changes: 0 additions & 2 deletions src/coreclr/nativeaot/Runtime/Crst.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ enum CrstType
CrstInterfaceDispatchGlobalLists,
CrstStressLog,
CrstRestrictedCallouts,
CrstObjectiveCMarshalCallouts,
CrstGcStressControl,
CrstThreadStore,
CrstThunkPool,
CrstYieldProcessorNormalized,
CrstEventPipe,
CrstEventPipeConfig,
Expand Down
12 changes: 0 additions & 12 deletions src/coreclr/nativeaot/Runtime/MiscHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,18 +340,6 @@ COOP_PINVOKE_HELPER(uint8_t *, RhGetCodeTarget, (uint8_t * pCodeOrg))
return pCodeOrg;
}

extern CrstStatic g_ThunkPoolLock;

EXTERN_C NATIVEAOT_API void __cdecl RhpAcquireThunkPoolLock()
{
g_ThunkPoolLock.Enter();
}

EXTERN_C NATIVEAOT_API void __cdecl RhpReleaseThunkPoolLock()
{
g_ThunkPoolLock.Leave();
}

EXTERN_C NATIVEAOT_API uint64_t __cdecl RhpGetTickCount64()
{
return PalGetTickCount64();
Expand Down
5 changes: 0 additions & 5 deletions src/coreclr/nativeaot/Runtime/startup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ static bool DetectCPUFeatures();

extern RhConfig * g_pRhConfig;

CrstStatic g_ThunkPoolLock;

#if defined(HOST_X86) || defined(HOST_AMD64) || defined(HOST_ARM64)
// This field is inspected from the generated code to determine what intrinsics are available.
EXTERN_C int g_cpuFeatures;
Expand Down Expand Up @@ -170,9 +168,6 @@ static bool InitDLL(HANDLE hPalInstance)
return false;
#endif

if (!g_ThunkPoolLock.InitNoThrow(CrstType::CrstThunkPool))
return false;

return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -819,38 +819,38 @@ public static string TryGetMethodDisplayStringFromIp(IntPtr ip)

public static object CreateThunksHeap(IntPtr commonStubAddress)
{
object newHeap = RuntimeImports.RhCreateThunksHeap(commonStubAddress);
object? newHeap = ThunksHeap.CreateThunksHeap(commonStubAddress);
if (newHeap == null)
throw new OutOfMemoryException();
return newHeap;
}

public static IntPtr AllocateThunk(object thunksHeap)
{
IntPtr newThunk = RuntimeImports.RhAllocateThunk(thunksHeap);
IntPtr newThunk = ((ThunksHeap)thunksHeap).AllocateThunk();
if (newThunk == IntPtr.Zero)
throw new OutOfMemoryException();
return newThunk;
}

public static void FreeThunk(object thunksHeap, IntPtr thunkAddress)
{
RuntimeImports.RhFreeThunk(thunksHeap, thunkAddress);
((ThunksHeap)thunksHeap).FreeThunk(thunkAddress);
}

public static void SetThunkData(object thunksHeap, IntPtr thunkAddress, IntPtr context, IntPtr target)
{
RuntimeImports.RhSetThunkData(thunksHeap, thunkAddress, context, target);
((ThunksHeap)thunksHeap).SetThunkData(thunkAddress, context, target);
}

public static bool TryGetThunkData(object thunksHeap, IntPtr thunkAddress, out IntPtr context, out IntPtr target)
{
return RuntimeImports.RhTryGetThunkData(thunksHeap, thunkAddress, out context, out target);
return ((ThunksHeap)thunksHeap).TryGetThunkData(thunkAddress, out context, out target);
}

public static int GetThunkSize()
{
return RuntimeImports.RhGetThunkSize();
return RuntimeImports.RhpGetThunkSize();
}

public static Delegate CreateObjectArrayDelegate(Type delegateType, Func<object?[], object?> invoker)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@
<Compile Include="System\Runtime\ExceptionIDs.cs" />
<Compile Include="System\Runtime\GCSettings.NativeAot.cs" />
<Compile Include="System\Runtime\TypeLoaderExports.cs" />
<Compile Include="System\Runtime\ThunkPool.cs" />
<Compile Include="System\Runtime\InitializeFinalizerThread.cs" />
<Compile Include="System\Runtime\InteropServices\ComEventsHelper.NativeAot.cs" Condition="'$(FeatureCominterop)' == 'true'" />
<Compile Include="System\Runtime\InteropServices\ComWrappers.NativeAot.cs" Condition="'$(FeatureComWrappers)' == 'true'" />
Expand Down Expand Up @@ -538,9 +539,6 @@
<Compile Include="$(RuntimeBasePath)System\Runtime\StackFrameIterator.cs">
<Link>Runtime.Base\src\System\Runtime\StackFrameIterator.cs</Link>
</Compile>
<Compile Include="$(RuntimeBasePath)System\Runtime\ThunkPool.cs">
<Link>Runtime.Base\src\System\Runtime\ThunkPool.cs</Link>
</Compile>
<Compile Include="$(RuntimeBasePath)System\Runtime\TypeCast.cs">
<Link>Runtime.Base\src\System\Runtime\TypeCast.cs</Link>
</Compile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,38 @@ internal static IntPtr RhHandleAllocDependent(object primary, object secondary)
[RuntimeImport(RuntimeLibrary, "RhHandleSetDependentSecondary")]
internal static extern void RhHandleSetDependentSecondary(IntPtr handle, object secondary);

//
// calls to runtime for thunk pool
//

[RuntimeImport(Redhawk.BaseName, "RhpGetNumThunkBlocksPerMapping")]
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern int RhpGetNumThunkBlocksPerMapping();

[RuntimeImport(Redhawk.BaseName, "RhpGetNumThunksPerBlock")]
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern int RhpGetNumThunksPerBlock();

[RuntimeImport(Redhawk.BaseName, "RhpGetThunkSize")]
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern int RhpGetThunkSize();

[RuntimeImport(Redhawk.BaseName, "RhpGetThunkDataBlockAddress")]
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern IntPtr RhpGetThunkDataBlockAddress(IntPtr thunkStubAddress);

[RuntimeImport(Redhawk.BaseName, "RhpGetThunkStubsBlockAddress")]
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern IntPtr RhpGetThunkStubsBlockAddress(IntPtr thunkDataAddress);

[RuntimeImport(Redhawk.BaseName, "RhpGetThunkBlockSize")]
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern int RhpGetThunkBlockSize();

[LibraryImport(RuntimeLibrary, EntryPoint = "RhAllocateThunksMapping")]
[UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })]
internal static partial IntPtr RhAllocateThunksMapping();

//
// calls to runtime for type equality checks
//
Expand Down Expand Up @@ -467,30 +499,6 @@ internal static unsafe int RhCompatibleReentrantWaitAny(bool alertable, int time
[RuntimeImport(RuntimeLibrary, "RhpResolveInterfaceMethod")]
internal static extern IntPtr RhpResolveInterfaceMethod(object pObject, IntPtr pCell);

[MethodImplAttribute(MethodImplOptions.InternalCall)]
[RuntimeImport(RuntimeLibrary, "RhCreateThunksHeap")]
internal static extern object RhCreateThunksHeap(IntPtr commonStubAddress);

[MethodImplAttribute(MethodImplOptions.InternalCall)]
[RuntimeImport(RuntimeLibrary, "RhAllocateThunk")]
internal static extern IntPtr RhAllocateThunk(object thunksHeap);

[MethodImplAttribute(MethodImplOptions.InternalCall)]
[RuntimeImport(RuntimeLibrary, "RhFreeThunk")]
internal static extern void RhFreeThunk(object thunksHeap, IntPtr thunkAddress);

[MethodImplAttribute(MethodImplOptions.InternalCall)]
[RuntimeImport(RuntimeLibrary, "RhSetThunkData")]
internal static extern void RhSetThunkData(object thunksHeap, IntPtr thunkAddress, IntPtr context, IntPtr target);

[MethodImplAttribute(MethodImplOptions.InternalCall)]
[RuntimeImport(RuntimeLibrary, "RhTryGetThunkData")]
internal static extern bool RhTryGetThunkData(object thunksHeap, IntPtr thunkAddress, out IntPtr context, out IntPtr target);

[MethodImplAttribute(MethodImplOptions.InternalCall)]
[RuntimeImport(RuntimeLibrary, "RhGetThunkSize")]
internal static extern int RhGetThunkSize();

[MethodImplAttribute(MethodImplOptions.InternalCall)]
[RuntimeImport(RuntimeLibrary, "RhResolveDispatchOnType")]
internal static extern unsafe IntPtr RhResolveDispatchOnType(EETypePtr instanceType, EETypePtr interfaceType, ushort slot, EETypePtr* pGenericContext);
Expand Down
Loading