Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Replace some sizeof-s with target specific constants #18245

Merged
merged 5 commits into from Jun 4, 2018
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/inc/stdmacros.h
Expand Up @@ -112,15 +112,19 @@
#define NOT_ARM64_ARG(x) , x
#endif

#ifdef _TARGET_64BIT_
#define LOG2_PTRSIZE 3
#else
#define LOG2_PTRSIZE 2
#endif

#ifdef _WIN64
#define LOG2_PTRSIZE 3
#define INVALID_POINTER_CC 0xcccccccccccccccc
#define INVALID_POINTER_CD 0xcdcdcdcdcdcdcdcd
#define FMT_ADDR " %08x`%08x "
#define LFMT_ADDR W(" %08x`%08x ")
#define DBG_ADDR(ptr) (((UINT_PTR) (ptr)) >> 32), (((UINT_PTR) (ptr)) & 0xffffffff)
#else // _WIN64
#define LOG2_PTRSIZE 2
#define INVALID_POINTER_CC 0xcccccccc
#define INVALID_POINTER_CD 0xcdcdcdcd
#define FMT_ADDR " %08x "
Expand Down
6 changes: 3 additions & 3 deletions src/vm/array.cpp
Expand Up @@ -499,7 +499,7 @@ MethodTable* Module::CreateArrayMethodTable(TypeHandle elemTypeHnd, CorElementTy
_ASSERTE(pMT->IsClassPreInited());

// Set BaseSize to be size of non-data portion of the array
DWORD baseSize = ObjSizeOf(ArrayBase);
DWORD baseSize = ARRAYBASE_BASESIZE;
if (arrayKind == ELEMENT_TYPE_ARRAY)
baseSize += Rank*sizeof(DWORD)*2;

Expand Down Expand Up @@ -682,7 +682,7 @@ MethodTable* Module::CreateArrayMethodTable(TypeHandle elemTypeHnd, CorElementTy
// This equals the offset of the first pointer if this were an array of entirely pointers, plus the offset of the
// first pointer in the value class
pSeries->SetSeriesOffset(ArrayBase::GetDataPtrOffset(pMT)
+ (sortedSeries[0]->GetSeriesOffset()) - sizeof (Object) );
+ (sortedSeries[0]->GetSeriesOffset()) - OBJECT_SIZE);
for (index = 0; index < nSeries; index ++)
{
size_t numPtrsInBytes = sortedSeries[index]->GetSeriesSize()
Expand All @@ -701,7 +701,7 @@ MethodTable* Module::CreateArrayMethodTable(TypeHandle elemTypeHnd, CorElementTy
else
{
skip = sortedSeries[0]->GetSeriesOffset() + pElemMT->GetBaseSize()
- ObjSizeOf(Object) - currentOffset;
- OBJECT_BASESIZE - currentOffset;
}

_ASSERTE(!"Module::CreateArrayMethodTable() - unaligned GC info" || IS_ALIGNED(skip, TARGET_POINTER_SIZE));
Expand Down
12 changes: 6 additions & 6 deletions src/vm/ceeload.cpp
Expand Up @@ -2139,7 +2139,7 @@ void Module::BuildStaticsOffsets(AllocMemTracker *pamTracker)
(S_SIZE_T(2 * sizeof(DWORD))*(S_SIZE_T(dwNumTypes)+S_SIZE_T(1)))));

for (DWORD i = 0; i < dwIndex; i++) {
pRegularStaticOffsets[i * 2 ] = dwGCHandles[0]*sizeof(OBJECTREF);
Copy link
Member

Choose a reason for hiding this comment

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

sizeof(OBJECTREF) can be just TARGET_POINTER_SIZE. We use TARGET_POINTER_SIZE for object reference sizes in many places already, so a few more are not a concern.

Copy link
Author

Choose a reason for hiding this comment

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

Sure, I will replace with TARGET_POINTER_SIZE instead

pRegularStaticOffsets[i * 2 ] = dwGCHandles[0]*TARGET_POINTER_SIZE;
pRegularStaticOffsets[i * 2 + 1] = dwNonGCBytes[0];
}
}
Expand All @@ -2152,7 +2152,7 @@ void Module::BuildStaticsOffsets(AllocMemTracker *pamTracker)
(S_SIZE_T(2 * sizeof(DWORD))*(S_SIZE_T(dwNumTypes)+S_SIZE_T(1)))));

for (DWORD i = 0; i < dwIndex; i++) {
pThreadStaticOffsets[i * 2 ] = dwGCHandles[1]*sizeof(OBJECTREF);
pThreadStaticOffsets[i * 2 ] = dwGCHandles[1]*TARGET_POINTER_SIZE;
pThreadStaticOffsets[i * 2 + 1] = dwNonGCBytes[1];
}
}
Expand All @@ -2164,7 +2164,7 @@ void Module::BuildStaticsOffsets(AllocMemTracker *pamTracker)
dwNonGCBytes[0] = (DWORD) ALIGN_UP(dwNonGCBytes[0], dwAlignment[0]);

// Save current offsets
pRegularStaticOffsets[dwIndex*2] = dwGCHandles[0]*sizeof(OBJECTREF);
pRegularStaticOffsets[dwIndex*2] = dwGCHandles[0]*TARGET_POINTER_SIZE;
pRegularStaticOffsets[dwIndex*2 + 1] = dwNonGCBytes[0];

// Increment for next class
Expand All @@ -2178,7 +2178,7 @@ void Module::BuildStaticsOffsets(AllocMemTracker *pamTracker)
dwNonGCBytes[1] = (DWORD) ALIGN_UP(dwNonGCBytes[1], dwAlignment[1]);

// Save current offsets
pThreadStaticOffsets[dwIndex*2] = dwGCHandles[1]*sizeof(OBJECTREF);
pThreadStaticOffsets[dwIndex*2] = dwGCHandles[1]*TARGET_POINTER_SIZE;
pThreadStaticOffsets[dwIndex*2 + 1] = dwNonGCBytes[1];

// Increment for next class
Expand All @@ -2191,13 +2191,13 @@ void Module::BuildStaticsOffsets(AllocMemTracker *pamTracker)

if (pRegularStaticOffsets != NULL)
{
pRegularStaticOffsets[dwNumTypes*2] = dwGCHandles[0]*sizeof(OBJECTREF);
pRegularStaticOffsets[dwNumTypes*2] = dwGCHandles[0]*TARGET_POINTER_SIZE;
pRegularStaticOffsets[dwNumTypes*2 + 1] = dwNonGCBytes[0];
}

if (pThreadStaticOffsets != NULL)
{
pThreadStaticOffsets[dwNumTypes*2] = dwGCHandles[1]*sizeof(OBJECTREF);
pThreadStaticOffsets[dwNumTypes*2] = dwGCHandles[1]*TARGET_POINTER_SIZE;
pThreadStaticOffsets[dwNumTypes*2 + 1] = dwNonGCBytes[1];
}

Expand Down
2 changes: 1 addition & 1 deletion src/vm/ceemain.cpp
Expand Up @@ -2456,7 +2456,7 @@ void InitializeGarbageCollector()
// in the object, there is no gc descriptor, and thus no need to adjust
// the pointer to skip the gc descriptor.

g_pFreeObjectMethodTable->SetBaseSize(ObjSizeOf (ArrayBase));
g_pFreeObjectMethodTable->SetBaseSize(ARRAYBASE_BASESIZE);
g_pFreeObjectMethodTable->SetComponentSize(1);

hr = GCHeapUtilities::LoadAndInitialize();
Expand Down
4 changes: 2 additions & 2 deletions src/vm/class.cpp
Expand Up @@ -2619,7 +2619,7 @@ MethodTable::DebugDumpGCDesc(
{
ssBuff.Printf(W(" offset %5d (%d w/o Object), size %5d (%5d w/o BaseSize subtr)\n"),
pSeries->GetSeriesOffset(),
pSeries->GetSeriesOffset() - sizeof(Object),
pSeries->GetSeriesOffset() - OBJECT_SIZE,
pSeries->GetSeriesSize(),
pSeries->GetSeriesSize() + GetBaseSize() );
WszOutputDebugString(ssBuff.GetUnicode());
Expand All @@ -2629,7 +2629,7 @@ MethodTable::DebugDumpGCDesc(
//LF_ALWAYS allowed here because this is controlled by special env var ShouldDumpOnClassLoad
LOG((LF_ALWAYS, LL_ALWAYS, " offset %5d (%d w/o Object), size %5d (%5d w/o BaseSize subtr)\n",
pSeries->GetSeriesOffset(),
pSeries->GetSeriesOffset() - sizeof(Object),
pSeries->GetSeriesOffset() - OBJECT_SIZE,
pSeries->GetSeriesSize(),
pSeries->GetSeriesSize() + GetBaseSize()
));
Expand Down
2 changes: 1 addition & 1 deletion src/vm/compile.cpp
Expand Up @@ -926,7 +926,7 @@ void FakePromote(PTR_PTR_Object ppObj, ScanContext *pSC, uint32_t dwFlags)

CORCOMPILE_GCREFMAP_TOKENS newToken = (dwFlags & GC_CALL_INTERIOR) ? GCREFMAP_INTERIOR : GCREFMAP_REF;

_ASSERTE((*ppObj == NULL) || (*(CORCOMPILE_GCREFMAP_TOKENS *)ppObj == newToken));
_ASSERTE((*(CORCOMPILE_GCREFMAP_TOKENS *)ppObj == NULL) || (*(CORCOMPILE_GCREFMAP_TOKENS *)ppObj == newToken));

*(CORCOMPILE_GCREFMAP_TOKENS *)ppObj = newToken;
}
Expand Down
6 changes: 3 additions & 3 deletions src/vm/jitinterface.cpp
Expand Up @@ -1645,7 +1645,7 @@ void CEEInfo::getFieldInfo (CORINFO_RESOLVED_TOKEN * pResolvedToken,
// FieldDesc::GetOffset() does not include the size of Object
if (!pFieldMT->IsValueType())
{
pResult->offset += sizeof(Object);
pResult->offset += OBJECT_SIZE;
}
}

Expand Down Expand Up @@ -2226,7 +2226,7 @@ unsigned CEEInfo::getClassGClayout (CORINFO_CLASS_HANDLE clsHnd, BYTE* gcPtrs)
{
// Get offset into the value class of the first pointer field (includes a +Object)
size_t cbSeriesSize = pByValueSeries->GetSeriesSize() + pMT->GetBaseSize();
size_t cbOffset = pByValueSeries->GetSeriesOffset() - sizeof(Object);
size_t cbOffset = pByValueSeries->GetSeriesOffset() - OBJECT_SIZE;

_ASSERTE (cbOffset % TARGET_POINTER_SIZE == 0);
_ASSERTE (cbSeriesSize % TARGET_POINTER_SIZE == 0);
Expand Down Expand Up @@ -9360,7 +9360,7 @@ unsigned CEEInfo::getFieldOffset (CORINFO_FIELD_HANDLE fieldHnd)
}
else if (!field->GetApproxEnclosingMethodTable()->IsValueType())
{
result += sizeof(Object);
result += OBJECT_SIZE;
}

EE_TO_JIT_TRANSITION();
Expand Down
2 changes: 1 addition & 1 deletion src/vm/methodtable.cpp
Expand Up @@ -942,7 +942,7 @@ MethodTable* CreateMinimalMethodTable(Module* pContainingModule,
pMT->SetLoaderModule(pContainingModule);
pMT->SetLoaderAllocator(pContainingModule->GetLoaderAllocator());
pMT->SetInternalCorElementType(ELEMENT_TYPE_CLASS);
pMT->SetBaseSize(ObjSizeOf(Object));
pMT->SetBaseSize(OBJECT_BASESIZE);

#ifdef _DEBUG
pClass->SetDebugClassName("dynamicClass");
Expand Down
20 changes: 10 additions & 10 deletions src/vm/methodtablebuilder.cpp
Expand Up @@ -8359,7 +8359,7 @@ MethodTableBuilder::HandleExplicitLayout(
if (CorTypeInfo::IsObjRef(pFD->GetFieldType()))
{
// Check that the ref offset is pointer aligned
if ((pFD->GetOffset_NoLogging() & ((ULONG)sizeof(OBJECTREF) - 1)) != 0)
if ((pFD->GetOffset_NoLogging() & ((ULONG)TARGET_POINTER_SIZE - 1)) != 0)
{
badOffset = pFD->GetOffset_NoLogging();
fieldTrust.SetTrust(ExplicitFieldTrust::kNone);
Expand Down Expand Up @@ -8597,7 +8597,7 @@ MethodTableBuilder::HandleExplicitLayout(
{
CONSISTENCY_CHECK(pSeries <= map->GetHighestSeries());

memset((void*)&vcLayout[pSeries->GetSeriesOffset()-sizeof(Object)], oref, pSeries->GetSeriesSize() + pMT->GetBaseSize());
memset((void*)&vcLayout[pSeries->GetSeriesOffset() - OBJECT_SIZE], oref, pSeries->GetSeriesSize() + pMT->GetBaseSize());
pSeries++;
}

Expand Down Expand Up @@ -8679,8 +8679,8 @@ void MethodTableBuilder::FindPointerSeriesExplicit(UINT instanceSliceSize,
// ref-non-ref-non, and since only ref series are recorded and non-ref series
// are skipped, the max number of series is total instance size / 2 / sizeof(ref).
// But watch out for the case where we have e.g. an instanceSlizeSize of 4.
DWORD sz = (instanceSliceSize + (2 * sizeof(OBJECTREF)) - 1);
bmtGCSeries->pSeries = new bmtGCSeriesInfo::Series[sz/2/sizeof(OBJECTREF)];
DWORD sz = (instanceSliceSize + (2 * TARGET_POINTER_SIZE) - 1);
bmtGCSeries->pSeries = new bmtGCSeriesInfo::Series[sz/2/ TARGET_POINTER_SIZE];

BYTE *loc = pFieldLayout;
BYTE *layoutEnd = pFieldLayout + instanceSliceSize;
Expand Down Expand Up @@ -8733,7 +8733,7 @@ MethodTableBuilder::HandleGCForExplicitLayout()
CGCDesc::Init( (PVOID) pMT, 1);
pSeries = ((CGCDesc*)pMT)->GetLowestSeries();
pSeries->SetSeriesSize( (size_t) (0) - (size_t) pMT->GetBaseSize());
pSeries->SetSeriesOffset(sizeof(Object));
pSeries->SetSeriesOffset(OBJECT_SIZE);
}
else
#endif // FEATURE_COLLECTIBLE_TYPES
Expand All @@ -8759,7 +8759,7 @@ MethodTableBuilder::HandleGCForExplicitLayout()
BAD_FORMAT_NOTHROW_ASSERT(pSeries <= CGCDesc::GetCGCDescFromMT(pMT)->GetHighestSeries());

pSeries->SetSeriesSize( (size_t) bmtGCSeries->pSeries[i].len - (size_t) pMT->GetBaseSize() );
pSeries->SetSeriesOffset(bmtGCSeries->pSeries[i].offset + sizeof(Object) + dwInstanceSliceOffset);
pSeries->SetSeriesOffset(bmtGCSeries->pSeries[i].offset + OBJECT_SIZE + dwInstanceSliceOffset);
pSeries++;
}
}
Expand Down Expand Up @@ -10309,7 +10309,7 @@ MethodTableBuilder::SetupMethodTable2(
// when the instance is in its "boxed" state.
if (!IsInterface())
{
DWORD baseSize = Max<DWORD>(bmtFP->NumInstanceFieldBytes + ObjSizeOf(Object), MIN_OBJECT_SIZE);
DWORD baseSize = Max<DWORD>(bmtFP->NumInstanceFieldBytes + OBJECT_BASESIZE, MIN_OBJECT_SIZE);
baseSize = (baseSize + ALLOC_ALIGN_CONSTANT) & ~ALLOC_ALIGN_CONSTANT; // m_BaseSize must be aligned
pMT->SetBaseSize(baseSize);

Expand Down Expand Up @@ -11309,7 +11309,7 @@ VOID MethodTableBuilder::HandleGCForValueClasses(MethodTable ** pByValueClassCac
CGCDesc::Init( (PVOID) pMT, 1);
pSeries = ((CGCDesc*)pMT)->GetLowestSeries();
pSeries->SetSeriesSize( (size_t) (0) - (size_t) pMT->GetBaseSize());
pSeries->SetSeriesOffset(sizeof(Object));
pSeries->SetSeriesOffset(OBJECT_SIZE);
}
else
#endif // FEATURE_COLLECTIBLE_TYPES
Expand Down Expand Up @@ -11337,8 +11337,8 @@ VOID MethodTableBuilder::HandleGCForValueClasses(MethodTable ** pByValueClassCac
if (bmtFP->NumInstanceGCPointerFields)
{
// See gcdesc.h for an explanation of why we adjust by subtracting BaseSize
pSeries->SetSeriesSize( (size_t) (bmtFP->NumInstanceGCPointerFields * sizeof(OBJECTREF)) - (size_t) pMT->GetBaseSize());
pSeries->SetSeriesOffset(bmtFP->GCPointerFieldStart+sizeof(Object));
pSeries->SetSeriesSize( (size_t) (bmtFP->NumInstanceGCPointerFields * TARGET_POINTER_SIZE) - (size_t) pMT->GetBaseSize());
pSeries->SetSeriesOffset(bmtFP->GCPointerFieldStart + OBJECT_SIZE);
pSeries++;
}

Expand Down
2 changes: 1 addition & 1 deletion src/vm/nativeoverlapped.cpp
Expand Up @@ -443,7 +443,7 @@ void AddMTForPinHandle(OBJECTREF obj)
}
else
{
pNewMT->SetBaseSize(ObjSizeOf (ArrayBase));
pNewMT->SetBaseSize(ARRAYBASE_BASESIZE);
pNewMT->SetComponentSize(static_cast<WORD>(-size));
}
s_pPinHandleTable->InsertValue(size, (HashDatum)pNewMT);
Expand Down
19 changes: 18 additions & 1 deletion src/vm/object.h
Expand Up @@ -95,11 +95,28 @@ class ArgDestination;

struct RCW;

#ifdef _TARGET_64BIT_
#define OBJHEADER_SIZE (sizeof(DWORD) /* m_alignpad */ + sizeof(DWORD) /* m_SyncBlockValue */)
#else
#define OBJHEADER_SIZE sizeof(DWORD) /* m_SyncBlockValue */
#endif

#define OBJECT_SIZE TARGET_POINTER_SIZE /* m_pMethTab */
#define OBJECT_BASESIZE (OBJHEADER_SIZE + OBJECT_SIZE)

#ifdef _TARGET_64BIT_
#define ARRAYBASE_SIZE (OBJECT_SIZE /* m_pMethTab */ + sizeof(DWORD) /* m_NumComponents */ + sizeof(DWORD) /* pad */)
#else
#define ARRAYBASE_SIZE (OBJECT_SIZE /* m_pMethTab */ + sizeof(DWORD) /* m_NumComponents */)
#endif

#define ARRAYBASE_BASESIZE (OBJHEADER_SIZE + ARRAYBASE_SIZE)

//
// The generational GC requires that every object be at least 12 bytes
// in size.

#define MIN_OBJECT_SIZE (2*sizeof(BYTE*) + sizeof(ObjHeader))
#define MIN_OBJECT_SIZE (2*TARGET_POINTER_SIZE + OBJHEADER_SIZE)

#define PTRALIGNCONST (DATA_ALIGNMENT-1)

Expand Down
8 changes: 4 additions & 4 deletions src/vm/object.inl
Expand Up @@ -62,7 +62,7 @@ __forceinline /*static*/ DWORD StringObject::GetBaseSize()
{
LIMITED_METHOD_DAC_CONTRACT;

return ObjSizeOf(Object) + sizeof(DWORD) /* length */ + sizeof(WCHAR) /* null terminator */;
return OBJECT_BASESIZE + sizeof(DWORD) /* length */ + sizeof(WCHAR) /* null terminator */;
}

__forceinline /*static*/ SIZE_T StringObject::GetSize(DWORD strLen)
Expand Down Expand Up @@ -247,17 +247,17 @@ inline /* static */ unsigned ArrayBase::GetDataPtrOffset(MethodTable* pMT)
_ASSERTE(pMT->IsArray());
#endif // DACCESS_COMPILE
// The -sizeof(ObjHeader) is because of the sync block, which is before "this"
return pMT->GetBaseSize() - sizeof(ObjHeader);
return pMT->GetBaseSize() - OBJHEADER_SIZE;
}

inline /* static */ unsigned ArrayBase::GetBoundsOffset(MethodTable* pMT)
{
WRAPPER_NO_CONTRACT;
_ASSERTE(pMT->IsArray());
if (!pMT->IsMultiDimArray())
return(offsetof(ArrayBase, m_NumComponents));
return OBJECT_SIZE /* offset(ArrayBase, m_NumComponents */;
_ASSERTE(pMT->GetInternalCorElementType() == ELEMENT_TYPE_ARRAY);
return sizeof(ArrayBase);
return ARRAYBASE_SIZE;
}
inline /* static */ unsigned ArrayBase::GetLowerBoundsOffset(MethodTable* pMT)
{
Expand Down
2 changes: 1 addition & 1 deletion src/vm/readytoruninfo.cpp
Expand Up @@ -889,7 +889,7 @@ DWORD ReadyToRunInfo::GetFieldBaseOffset(MethodTable * pMT)

dwCumulativeInstanceFieldPos = (DWORD)ALIGN_UP(dwCumulativeInstanceFieldPos, dwAlignment);

return (DWORD)sizeof(Object) + dwCumulativeInstanceFieldPos - dwOffsetBias;
return OBJECT_SIZE + dwCumulativeInstanceFieldPos - dwOffsetBias;
}

BOOL ReadyToRunInfo::IsImageVersionAtLeast(int majorVersion, int minorVersion)
Expand Down
2 changes: 1 addition & 1 deletion src/vm/siginfo.cpp
Expand Up @@ -4981,7 +4981,7 @@ void ReportPointersFromValueType(promote_func *fn, ScanContext *sc, PTR_MethodTa
while (srcPtr < srcPtrStop)
{
(*fn)(dac_cast<PTR_PTR_Object>(srcPtr), sc, 0);
srcPtr++;
srcPtr = (PTR_OBJECTREF)(PTR_BYTE(srcPtr) + TARGET_POINTER_SIZE);
}
cur--;
} while (cur >= last);
Expand Down
8 changes: 0 additions & 8 deletions src/vm/syncblk.h
Expand Up @@ -85,7 +85,6 @@ typedef DPTR(EnCSyncBlockInfo) PTR_EnCSyncBlockInfo;

#include "synch.h"


// At a negative offset from each Object is an ObjHeader. The 'size' of the
// object includes these bytes. However, we rely on the previous object allocation
// to zero out the ObjHeader for the current allocation. And the limits of the
Expand Down Expand Up @@ -1610,13 +1609,6 @@ struct ThreadQueue
#endif
};


// The true size of an object is whatever C++ thinks, plus the ObjHeader we
// allocate before it.

#define ObjSizeOf(c) (sizeof(c) + sizeof(ObjHeader))


inline void AwareLock::SetPrecious()
{
LIMITED_METHOD_CONTRACT;
Expand Down