Skip to content

Commit b1e550c

Browse files
authored
Miscellaneous cleanup (#122573)
- Fix comments - Delete some dead code - Fix disabled file system test - Add const - Avoid redundant virtual calls - Improve GS cookie - Use Interlocked.Or/And
1 parent e7eb44a commit b1e550c

File tree

11 files changed

+52
-111
lines changed

11 files changed

+52
-111
lines changed

src/coreclr/debug/ee/controller.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2039,8 +2039,8 @@ BOOL DebuggerController::AddBindAndActivateILReplicaPatch(DebuggerControllerPatc
20392039
// causing the patch table to grow and move.
20402040
SIZE_T primaryILOffset = primary->offset;
20412041

2042-
// Loop through all the native offsets mapped to the given IL offset. On x86 the mapping
2043-
// should be 1:1. On WIN64, because there are funclets, we have a 1:N mapping.
2042+
// Loop through all the native offsets mapped to the given IL offset.
2043+
// It is 1:N mapping due to optimizations like funclet inlining or loop cloning.
20442044
DebuggerJitInfo::ILToNativeOffsetIterator it;
20452045
for (dji->InitILToNativeOffsetIterator(it, primaryILOffset); !it.IsAtEnd(); it.Next())
20462046
{
@@ -5294,7 +5294,7 @@ bool DebuggerStepper::IsRangeAppropriate(ControllerStackInfo *info)
52945294
}
52955295

52965296
#if defined(FEATURE_EH_FUNCLETS)
5297-
// There are three scenarios which make this function more complicated on WIN64.
5297+
// There are three scenarios which make this function more complicated with funclets.
52985298
// 1) We initiate a step in the parent method or a funclet but end up stepping into another funclet closer to the leaf.
52995299
// a) start in the parent method
53005300
// b) start in a funclet
@@ -6348,7 +6348,7 @@ bool DebuggerStepper::IsAddrWithinFrame(DebuggerJitInfo *dji,
63486348
}
63496349

63506350
#if defined(FEATURE_EH_FUNCLETS)
6351-
// On WIN64, we also check whether the targetAddr and the currentAddr is in the same funclet.
6351+
// Also check whether the targetAddr and the currentAddr is in the same funclet.
63526352
_ASSERTE(currentAddr != NULL);
63536353
if (result)
63546354
{
@@ -6895,7 +6895,7 @@ bool DebuggerStepper::SetRangesFromIL(DebuggerJitInfo *dji, COR_DEBUG_STEP_RANGE
68956895
rToEnd = rTo + realRangeCount;
68966896

68976897
// <NOTE>
6898-
// rTo may also be incremented in the middle of the loop on WIN64 platforms.
6898+
// rTo may also be incremented in the middle of the loop
68996899
// </NOTE>
69006900
for (/**/; r < rEnd; r++, rTo++)
69016901
{

src/coreclr/debug/ee/rcthread.cpp

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -134,34 +134,6 @@ HANDLE CreateWin32EventOrThrow(
134134
RETURN h;
135135
}
136136

137-
//-----------------------------------------------------------------------------
138-
// Open an event. Another helper for DebuggerRCThread::Init
139-
//-----------------------------------------------------------------------------
140-
HANDLE OpenWin32EventOrThrow(
141-
DWORD dwDesiredAccess,
142-
BOOL bInheritHandle,
143-
LPCWSTR lpName
144-
)
145-
{
146-
CONTRACT(HANDLE)
147-
{
148-
THROWS;
149-
GC_NOTRIGGER;
150-
POSTCONDITION(RETVAL != NULL);
151-
}
152-
CONTRACT_END;
153-
154-
HANDLE h = OpenEvent(
155-
dwDesiredAccess,
156-
bInheritHandle,
157-
lpName
158-
);
159-
if (h == NULL)
160-
ThrowLastError();
161-
162-
RETURN h;
163-
}
164-
165137
//---------------------------------------------------------------------------------------
166138
//
167139
// Init

src/coreclr/nativeaot/Runtime/startup.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "yieldprocessornormalized.h"
2626
#include <minipal/cpufeatures.h>
2727
#include <minipal/time.h>
28+
#include <minipal/random.h>
2829

2930
#ifdef FEATURE_PERFTRACING
3031
#include "EventPipeInterface.h"
@@ -224,8 +225,9 @@ bool InitGSCookie()
224225
}
225226
#endif
226227

227-
// REVIEW: Need something better for PAL...
228-
GSCookie val = (GSCookie)minipal_lowres_ticks();
228+
GSCookie val;
229+
230+
minipal_get_non_cryptographically_secure_random_bytes((uint8_t*)&val, sizeof(val));
229231

230232
#ifdef _DEBUG
231233
// In _DEBUG, always use the same value to make it easier to search for the cookie

src/coreclr/nativeaot/System.Private.CoreLib/src/System/Threading/Thread.NativeAot.cs

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -272,24 +272,12 @@ private bool GetThreadStateBit(ThreadState bit)
272272

273273
private int SetThreadStateBit(ThreadState bit)
274274
{
275-
int oldState, newState;
276-
do
277-
{
278-
oldState = _threadState;
279-
newState = oldState | (int)bit;
280-
} while (Interlocked.CompareExchange(ref _threadState, newState, oldState) != oldState);
281-
return oldState;
275+
return Interlocked.Or(ref _threadState, (int)bit);
282276
}
283277

284278
private int ClearThreadStateBit(ThreadState bit)
285279
{
286-
int oldState, newState;
287-
do
288-
{
289-
oldState = _threadState;
290-
newState = oldState & ~(int)bit;
291-
} while (Interlocked.CompareExchange(ref _threadState, newState, oldState) != oldState);
292-
return oldState;
280+
return Interlocked.And(ref _threadState, ~(int)bit);
293281
}
294282

295283
internal void SetWaitSleepJoinState()

src/coreclr/pal/inc/pal.h

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -266,27 +266,6 @@ PAL_GenerateCoreDump(
266266
LPSTR errorMessageBuffer,
267267
INT cbErrorMessageBuffer);
268268

269-
typedef VOID (*PPAL_STARTUP_CALLBACK)(
270-
char *modulePath,
271-
HMODULE hModule,
272-
PVOID parameter);
273-
274-
PALIMPORT
275-
DWORD
276-
PALAPI
277-
PAL_RegisterForRuntimeStartup(
278-
IN DWORD dwProcessId,
279-
IN LPCWSTR lpApplicationGroupId,
280-
IN PPAL_STARTUP_CALLBACK pfnCallback,
281-
IN PVOID parameter,
282-
OUT PVOID *ppUnregisterToken);
283-
284-
PALIMPORT
285-
DWORD
286-
PALAPI
287-
PAL_UnregisterForRuntimeStartup(
288-
IN PVOID pUnregisterToken);
289-
290269
PALIMPORT
291270
BOOL
292271
PALAPI

src/coreclr/runtime/CachedInterfaceDispatch.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,13 @@ static bool UpdateCacheEntryAtomically(InterfaceDispatchCacheEntry *pEntry,
129129
// supplied (in the case where another thread raced with us for the update and won). In any case, if the
130130
// returned pointer is non-NULL it represents a cache that should be scheduled for release.
131131
static InterfaceDispatchCache * UpdateCellStubAndCache(InterfaceDispatchCell * pCell,
132-
void * pStub,
132+
PCODE pStub,
133133
uintptr_t newCacheValue)
134134
{
135135
static_assert(offsetof(InterfaceDispatchCell, m_pStub) == 0);
136136
static_assert(offsetof(InterfaceDispatchCell, m_pCache) == sizeof(void*));
137137

138-
uintptr_t oldCacheValue = (uintptr_t)UpdatePointerPairAtomically(pCell, pStub, (void*)newCacheValue, false);
138+
uintptr_t oldCacheValue = (uintptr_t)UpdatePointerPairAtomically(pCell, (void*)pStub, (void*)newCacheValue, false);
139139

140140
if (InterfaceDispatchCell::IsCache(oldCacheValue))
141141
{
@@ -204,14 +204,14 @@ extern "C" void RhpVTableOffsetDispatch();
204204

205205
typedef void (*InterfaceDispatchStub)();
206206

207-
static void * g_rgDispatchStubs[CID_MAX_CACHE_SIZE_LOG2 + 1] = {
208-
(void *)&RhpInterfaceDispatch1,
209-
(void *)&RhpInterfaceDispatch2,
210-
(void *)&RhpInterfaceDispatch4,
211-
(void *)&RhpInterfaceDispatch8,
212-
(void *)&RhpInterfaceDispatch16,
213-
(void *)&RhpInterfaceDispatch32,
214-
(void *)&RhpInterfaceDispatch64,
207+
static const PCODE g_rgDispatchStubs[CID_MAX_CACHE_SIZE_LOG2 + 1] = {
208+
(PCODE)&RhpInterfaceDispatch1,
209+
(PCODE)&RhpInterfaceDispatch2,
210+
(PCODE)&RhpInterfaceDispatch4,
211+
(PCODE)&RhpInterfaceDispatch8,
212+
(PCODE)&RhpInterfaceDispatch16,
213+
(PCODE)&RhpInterfaceDispatch32,
214+
(PCODE)&RhpInterfaceDispatch64,
215215
};
216216

217217
// Map a cache size into a linear index.
@@ -241,12 +241,12 @@ static uint32_t CacheSizeToIndex(uint32_t cCacheEntries)
241241
// Allocates and initializes new cache of the given size. If given a previous version of the cache (guaranteed
242242
// to be smaller) it will also pre-populate the new cache with the contents of the old. Additionally the
243243
// address of the interface dispatch stub associated with this size of cache is returned.
244-
static uintptr_t AllocateCache(uint32_t cCacheEntries, InterfaceDispatchCache * pExistingCache, const DispatchCellInfo *pNewCellInfo, void ** ppStub)
244+
static uintptr_t AllocateCache(uint32_t cCacheEntries, InterfaceDispatchCache * pExistingCache, const DispatchCellInfo *pNewCellInfo, PCODE * ppStub)
245245
{
246246
#ifndef FEATURE_NATIVEAOT
247247
if (pNewCellInfo->CellType == DispatchCellType::VTableOffset)
248248
{
249-
*ppStub = (void *)&RhpVTableOffsetDispatch;
249+
*ppStub = (PCODE)&RhpVTableOffsetDispatch;
250250
ASSERT(!InterfaceDispatchCell::IsCache(pNewCellInfo->GetVTableOffset()));
251251
return pNewCellInfo->GetVTableOffset();
252252
}
@@ -455,7 +455,7 @@ PCODE InterfaceDispatch_UpdateDispatchCellCache(InterfaceDispatchCell * pCell, P
455455
}
456456

457457
uint32_t cNewCacheEntries = cOldCacheEntries ? cOldCacheEntries * 2 : 1;
458-
void *pStub;
458+
PCODE pStub;
459459
uintptr_t newCacheValue = AllocateCache(cNewCacheEntries, pCache, pNewCellInfo, &pStub);
460460
if (newCacheValue == 0)
461461
{

src/coreclr/tools/Common/TypeSystem/IL/Stubs/DelegateMethodILEmitter.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,19 +55,20 @@ public static MethodIL EmitIL(MethodDesc method)
5555
// Store the function pointer into local variable to avoid unnecessary register usage by JIT
5656
ILLocalVariable functionPointer = emit.NewLocal(context.GetWellKnownType(WellKnownType.IntPtr));
5757

58+
MethodSignature signature = method.Signature;
59+
5860
codeStream.EmitLdArg(0);
5961
codeStream.Emit(ILOpcode.ldfld, emit.NewToken(functionPointerField.InstantiateAsOpen()));
6062
codeStream.EmitStLoc(functionPointer);
6163

6264
codeStream.EmitLdArg(0);
6365
codeStream.Emit(ILOpcode.ldfld, emit.NewToken(firstParameterField.InstantiateAsOpen()));
64-
for (int i = 0; i < method.Signature.Length; i++)
66+
for (int i = 0; i < signature.Length; i++)
6567
{
6668
codeStream.EmitLdArg(i + 1);
6769
}
6870
codeStream.EmitLdLoc(functionPointer);
6971

70-
MethodSignature signature = method.Signature;
7172
if (method.OwningType.HasInstantiation)
7273
{
7374
// If the owning type is generic, the signature will contain T's and U's.

0 commit comments

Comments
 (0)