Skip to content

Commit

Permalink
Rename keepalive to keepAlive
Browse files Browse the repository at this point in the history
  • Loading branch information
janvorli committed Jun 10, 2024
1 parent 8eccdbc commit f774c60
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 95 deletions.
4 changes: 2 additions & 2 deletions src/coreclr/vm/clrex.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ class StackTraceInfo
{
int m_dummy; // remove this

static OBJECTREF GetKeepaliveObject(MethodDesc* pMethod);
static OBJECTREF GetKeepAliveObject(MethodDesc* pMethod);
static void EnsureStackTraceArray(StackTraceArray *pStackTrace, size_t neededSize);
static void EnsureKeepaliveArray(PTRARRAYREF *ppKeepaliveArray, size_t neededSize);
static void EnsureKeepAliveArray(PTRARRAYREF *ppKeepAliveArray, size_t neededSize);
public:
static BOOL AppendElement(OBJECTHANDLE hThrowable, UINT_PTR currentIP, UINT_PTR currentSP, MethodDesc* pFunc, CrawlFrame* pCf);
};
Expand Down
38 changes: 19 additions & 19 deletions src/coreclr/vm/comutilnative.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ FCIMPL0(VOID, ExceptionNative::PrepareForForeignExceptionRaise)
}
FCIMPLEND

void DeepCopyStackTrace(StackTraceArray &stackTrace, StackTraceArray &stackTraceCopy, PTRARRAYREF *pKeepaliveArray, PTRARRAYREF *pKeepaliveArrayCopy)
void DeepCopyStackTrace(StackTraceArray &stackTrace, StackTraceArray &stackTraceCopy, PTRARRAYREF *pKeepAliveArray, PTRARRAYREF *pKeepAliveArrayCopy)
{
CONTRACTL
{
Expand All @@ -85,8 +85,8 @@ void DeepCopyStackTrace(StackTraceArray &stackTrace, StackTraceArray &stackTrace
MODE_COOPERATIVE;
PRECONDITION(IsProtectedByGCFrame((OBJECTREF*)&stackTrace));
PRECONDITION(IsProtectedByGCFrame((OBJECTREF*)&stackTraceCopy));
PRECONDITION(IsProtectedByGCFrame((OBJECTREF*)pKeepaliveArray));
PRECONDITION(IsProtectedByGCFrame((OBJECTREF*)pKeepaliveArrayCopy));
PRECONDITION(IsProtectedByGCFrame((OBJECTREF*)pKeepAliveArray));
PRECONDITION(IsProtectedByGCFrame((OBJECTREF*)pKeepAliveArrayCopy));
}
CONTRACTL_END;

Expand All @@ -99,20 +99,20 @@ void DeepCopyStackTrace(StackTraceArray &stackTrace, StackTraceArray &stackTrace
stackTraceCopy.Set(NULL);
}

if (*pKeepaliveArray != NULL)
if (*pKeepAliveArray != NULL)
{
// The stack trace object is the keepalive array with its first slot set to the stack trace I1Array.
// The stack trace object is the keepAlive array with its first slot set to the stack trace I1Array.
// Get the number of elements in the dynamic methods array
unsigned cOrigKeepalive = (*pKeepaliveArray)->GetNumComponents();
unsigned cOrigKeepAlive = (*pKeepAliveArray)->GetNumComponents();

// ..and allocate a new array. This can trigger GC or throw under OOM.
*pKeepaliveArrayCopy = (PTRARRAYREF)AllocateObjectArray(cOrigKeepalive, g_pObjectClass);
*pKeepAliveArrayCopy = (PTRARRAYREF)AllocateObjectArray(cOrigKeepAlive, g_pObjectClass);

// Deepcopy references to the new array we just allocated
memmoveGCRefs((*pKeepaliveArrayCopy)->GetDataPtr(), (*pKeepaliveArray)->GetDataPtr(),
cOrigKeepalive * sizeof(Object *));
memmoveGCRefs((*pKeepAliveArrayCopy)->GetDataPtr(), (*pKeepAliveArray)->GetDataPtr(),
cOrigKeepAlive * sizeof(Object *));

(*pKeepaliveArrayCopy)->SetAt(0, (PTRARRAYREF)stackTraceCopy.Get());
(*pKeepAliveArrayCopy)->SetAt(0, (PTRARRAYREF)stackTraceCopy.Get());
}
}

Expand All @@ -132,7 +132,7 @@ FCIMPL2(VOID, ExceptionNative::GetStackTracesDeepCopy, Object* pExceptionObjectU
{
StackTraceArray stackTrace;
EXCEPTIONREF refException = NULL;
PTRARRAYREF keepaliveArray = NULL; // Object array of Managed Resolvers
PTRARRAYREF keepAliveArray = NULL; // Object array of Managed Resolvers
} gc;

// GC protect the array reference
Expand All @@ -141,13 +141,13 @@ FCIMPL2(VOID, ExceptionNative::GetStackTracesDeepCopy, Object* pExceptionObjectU
// Get the exception object reference
gc.refException = (EXCEPTIONREF)(ObjectToOBJECTREF(pExceptionObjectUnsafe));

gc.refException->GetStackTrace(gc.stackTrace, &gc.keepaliveArray);
gc.refException->GetStackTrace(gc.stackTrace, &gc.keepAliveArray);

gc.stackTrace.MarkAsFrozen();

if (gc.keepaliveArray != NULL)
if (gc.keepAliveArray != NULL)
{
*pStackTraceUnsafe = OBJECTREFToObject(gc.keepaliveArray);
*pStackTraceUnsafe = OBJECTREFToObject(gc.keepAliveArray);
}
else if (gc.stackTrace.Get() != NULL)
{
Expand Down Expand Up @@ -176,7 +176,7 @@ FCIMPL2(VOID, ExceptionNative::SaveStackTracesFromDeepCopy, Object* pExceptionOb
{
StackTraceArray stackTrace;
OBJECTREF refStackTrace = NULL;
PTRARRAYREF refKeepaliveArray = NULL;
PTRARRAYREF refKeepAliveArray = NULL;
EXCEPTIONREF refException = NULL;
} gc;

Expand All @@ -187,14 +187,14 @@ FCIMPL2(VOID, ExceptionNative::SaveStackTracesFromDeepCopy, Object* pExceptionOb
gc.refException = (EXCEPTIONREF)(ObjectToOBJECTREF(pExceptionObjectUnsafe));
gc.refStackTrace = (OBJECTREF)(ObjectToOBJECTREF(pStackTraceUnsafe));

ExceptionObject::GetStackTraceParts(gc.refStackTrace, gc.stackTrace, &gc.refKeepaliveArray);
ExceptionObject::GetStackTraceParts(gc.refStackTrace, gc.stackTrace, &gc.refKeepAliveArray);
_ASSERTE((gc.stackTrace.Get() == NULL) || gc.stackTrace.IsFrozen());

if (gc.refKeepaliveArray != NULL)
if (gc.refKeepAliveArray != NULL)
{
// The stack trace object is the keepalive array with its first slot set to the stack trace I1Array.
// The stack trace object is the keepAlive array with its first slot set to the stack trace I1Array.
// Save the stacktrace details in the exception
gc.refException->SetStackTrace(gc.refKeepaliveArray);
gc.refException->SetStackTrace(gc.refKeepAliveArray);
}
else
{
Expand Down
88 changes: 44 additions & 44 deletions src/coreclr/vm/excep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2926,24 +2926,24 @@ void StackTraceInfo::EnsureStackTraceArray(StackTraceArray *pStackTrace, size_t
GCPROTECT_END();
}

// Ensure that there is space for the neededSize elements in the keepalive array.
void StackTraceInfo::EnsureKeepaliveArray(PTRARRAYREF *ppKeepaliveArray, size_t neededSize)
// Ensure that there is space for the neededSize elements in the keepAlive array.
void StackTraceInfo::EnsureKeepAliveArray(PTRARRAYREF *ppKeepAliveArray, size_t neededSize)
{
CONTRACTL
{
GC_TRIGGERS;
THROWS;
PRECONDITION(CheckPointer(ppKeepaliveArray));
PRECONDITION(CheckPointer(ppKeepAliveArray));
}
CONTRACTL_END;

PTRARRAYREF pNewKeepaliveArray = NULL;
GCPROTECT_BEGIN(pNewKeepaliveArray);
PTRARRAYREF pNewKeepAliveArray = NULL;
GCPROTECT_BEGIN(pNewKeepAliveArray);

size_t keepaliveArrayCapacity = (*ppKeepaliveArray != NULL) ? (*ppKeepaliveArray)->GetNumComponents() : 0;
if (neededSize > keepaliveArrayCapacity)
size_t keepAliveArrayCapacity = (*ppKeepAliveArray != NULL) ? (*ppKeepAliveArray)->GetNumComponents() : 0;
if (neededSize > keepAliveArrayCapacity)
{
S_SIZE_T newCapacity = S_SIZE_T(keepaliveArrayCapacity) * S_SIZE_T(2);
S_SIZE_T newCapacity = S_SIZE_T(keepAliveArrayCapacity) * S_SIZE_T(2);
if (newCapacity.IsOverflow() || (neededSize > newCapacity.Value()))
{
newCapacity = S_SIZE_T(neededSize);
Expand All @@ -2953,33 +2953,33 @@ void StackTraceInfo::EnsureKeepaliveArray(PTRARRAYREF *ppKeepaliveArray, size_t
}
}

keepaliveArrayCapacity = newCapacity.Value();
keepAliveArrayCapacity = newCapacity.Value();

if (!FitsIn<DWORD>(keepaliveArrayCapacity))
if (!FitsIn<DWORD>(keepAliveArrayCapacity))
{
EX_THROW(EEMessageException, (kOverflowException, IDS_EE_ARRAY_DIMENSIONS_EXCEEDED));
}

// Allocate a new array with the needed size
pNewKeepaliveArray = (PTRARRAYREF)AllocateObjectArray(static_cast<DWORD>(keepaliveArrayCapacity), g_pObjectClass);
if ((*ppKeepaliveArray) != NULL)
pNewKeepAliveArray = (PTRARRAYREF)AllocateObjectArray(static_cast<DWORD>(keepAliveArrayCapacity), g_pObjectClass);
if ((*ppKeepAliveArray) != NULL)
{
memmoveGCRefs(pNewKeepaliveArray->GetDataPtr(),
(*ppKeepaliveArray)->GetDataPtr(),
memmoveGCRefs(pNewKeepAliveArray->GetDataPtr(),
(*ppKeepAliveArray)->GetDataPtr(),
neededSize * sizeof(Object *));
}
// Update the keepalive array
*ppKeepaliveArray = pNewKeepaliveArray;
// Update the keepAlive array
*ppKeepAliveArray = pNewKeepAliveArray;
}

GCPROTECT_END();
}

// Get a keepalive object for the given method. The keepalive object is either a
// Get a keepAlive object for the given method. The keepAlive object is either a
// Resolver object for DynamicMethodDesc or a LoaderAllocator object for methods in
// collectible assemblies.
// Returns NULL if the method code cannot be destroyed.
OBJECTREF StackTraceInfo::GetKeepaliveObject(MethodDesc* pMethod)
OBJECTREF StackTraceInfo::GetKeepAliveObject(MethodDesc* pMethod)
{
LIMITED_METHOD_CONTRACT;

Expand All @@ -3006,9 +3006,9 @@ OBJECTREF StackTraceInfo::GetKeepaliveObject(MethodDesc* pMethod)
}

#ifdef _DEBUG
// Get number of methods in the stack trace that can be collected. We need to store keepalive
// Get number of methods in the stack trace that can be collected. We need to store keepAlive
// objects (Resolver / LoaderAllocator) for these methods.
int GetKeepaliveItemsCount(StackTraceArray *pStackTrace)
int GetKeepAliveItemsCount(StackTraceArray *pStackTrace)
{
LIMITED_METHOD_CONTRACT;

Expand Down Expand Up @@ -3101,15 +3101,15 @@ BOOL StackTraceInfo::AppendElement(OBJECTHANDLE hThrowable, UINT_PTR currentIP,
struct
{
StackTraceArray stackTrace;
PTRARRAYREF pKeepaliveArray = NULL; // Object array of Managed Resolvers / Loader Allocators of methods that can be collected
OBJECTREF keepaliveObject = NULL;
PTRARRAYREF pKeepAliveArray = NULL; // Object array of Managed Resolvers / Loader Allocators of methods that can be collected
OBJECTREF keepAliveObject = NULL;
} gc;

GCPROTECT_BEGIN_THREAD(pThread, gc);

// Fetch the stacktrace and the keepalive array from the exception object. It returns clones of those arrays in case the
// Fetch the stacktrace and the keepAlive array from the exception object. It returns clones of those arrays in case the
// stack trace was created by a different thread.
bool wasCreatedByForeignThread = ((EXCEPTIONREF)ObjectFromHandle(hThrowable))->GetStackTrace(gc.stackTrace, &gc.pKeepaliveArray);
bool wasCreatedByForeignThread = ((EXCEPTIONREF)ObjectFromHandle(hThrowable))->GetStackTrace(gc.stackTrace, &gc.pKeepAliveArray);

// The stack trace returned by the GetStackTrace has to be created by the current thread or be NULL.
_ASSERTE((gc.stackTrace.Get() == NULL) || (gc.stackTrace.GetObjectThread() == pThread));
Expand All @@ -3131,47 +3131,47 @@ BOOL StackTraceInfo::AppendElement(OBJECTHANDLE hThrowable, UINT_PTR currentIP,
}
}

size_t keepaliveItemsCount = gc.stackTrace.GetKeepAliveItemsCount();
_ASSERTE(keepaliveItemsCount == GetKeepaliveItemsCount(&gc.stackTrace));
size_t keepAliveItemsCount = gc.stackTrace.GetKeepAliveItemsCount();
_ASSERTE(keepAliveItemsCount == GetKeepAliveItemsCount(&gc.stackTrace));

gc.keepaliveObject = GetKeepaliveObject(pFunc);
if (gc.keepaliveObject != NULL)
gc.keepAliveObject = GetKeepAliveObject(pFunc);
if (gc.keepAliveObject != NULL)
{
// The new frame to be added is a method that can be collected, so we need to update the keepalive items count.
keepaliveItemsCount++;
// The new frame to be added is a method that can be collected, so we need to update the keepAlive items count.
keepAliveItemsCount++;
stackTraceElem.flags |= STEF_KEEPALIVE;
}

if (keepaliveItemsCount != 0)
if (keepAliveItemsCount != 0)
{
// One extra slot is added for the stack trace array
EnsureKeepaliveArray(&gc.pKeepaliveArray, keepaliveItemsCount + 1);
if (gc.keepaliveObject != NULL)
EnsureKeepAliveArray(&gc.pKeepAliveArray, keepAliveItemsCount + 1);
if (gc.keepAliveObject != NULL)
{
// Add the method to the keepalive array
gc.pKeepaliveArray->SetAt(keepaliveItemsCount, gc.keepaliveObject);
// Add the method to the keepAlive array
gc.pKeepAliveArray->SetAt(keepAliveItemsCount, gc.keepAliveObject);
}
}
else
{
// There are no methods that can be collected, so we don't need the keepalive array
gc.pKeepaliveArray = NULL;
// There are no methods that can be collected, so we don't need the keepAlive array
gc.pKeepAliveArray = NULL;
}

gc.stackTrace.SetKeepAliveItemsCount(keepaliveItemsCount);
gc.stackTrace.SetKeepAliveItemsCount(keepAliveItemsCount);

gc.stackTrace.Append(&stackTraceElem);
_ASSERTE(GetKeepaliveItemsCount(&gc.stackTrace) == keepaliveItemsCount);
_ASSERTE(GetKeepAliveItemsCount(&gc.stackTrace) == keepAliveItemsCount);

if (gc.pKeepaliveArray != NULL)
if (gc.pKeepAliveArray != NULL)
{
_ASSERTE(keepaliveItemsCount > 0);
gc.pKeepaliveArray->SetAt(0, gc.stackTrace.Get());
((EXCEPTIONREF)ObjectFromHandle(hThrowable))->SetStackTrace(dac_cast<OBJECTREF>(gc.pKeepaliveArray));
_ASSERTE(keepAliveItemsCount > 0);
gc.pKeepAliveArray->SetAt(0, gc.stackTrace.Get());
((EXCEPTIONREF)ObjectFromHandle(hThrowable))->SetStackTrace(dac_cast<OBJECTREF>(gc.pKeepAliveArray));
}
else
{
_ASSERTE(keepaliveItemsCount == 0);
_ASSERTE(keepAliveItemsCount == 0);
((EXCEPTIONREF)ObjectFromHandle(hThrowable))->SetStackTrace(dac_cast<OBJECTREF>(gc.stackTrace.Get()));
}

Expand Down
Loading

0 comments on commit f774c60

Please sign in to comment.