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

Commit

Permalink
Merge in 'release/3.1' changes
Browse files Browse the repository at this point in the history
  • Loading branch information
dotnet-bot committed May 20, 2020
2 parents 9482ed8 + b174565 commit 018cfd0
Show file tree
Hide file tree
Showing 16 changed files with 55 additions and 14 deletions.
2 changes: 1 addition & 1 deletion eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project>
<PropertyGroup>
<!-- The .NET Core product branding version -->
<ProductVersion>3.1.4</ProductVersion>
<ProductVersion>3.1.5</ProductVersion>
<!-- File version numbers -->
<MajorVersion>4</MajorVersion>
<MinorVersion>7</MinorVersion>
Expand Down
12 changes: 12 additions & 0 deletions src/inc/daccess.h
Original file line number Diff line number Diff line change
Expand Up @@ -2459,4 +2459,16 @@ typedef DPTR(PTR_PCODE) PTR_PTR_PCODE;
// @dbgtodo : Separating asserts and target consistency checks is tracked by DevDiv Bugs 31674
#define TARGET_CONSISTENCY_CHECK(expr,msg) _ASSERTE_MSG(expr,msg)

// For cross compilation, controlling type layout is important
// We add a simple macro here which defines DAC_ALIGNAS to the C++11 alignas operator
// This helps force the alignment of the next member
// For most cross compilation cases the layout of types simply works
// There are a few cases (where this macro is helpful) which are not consistent accross platforms:
// - Base class whose size is padded to its align size. On Linux the gcc/clang
// layouts will reuse this padding in the derived class for the first member
// - Class with an vtable pointer and an alignment greater than the pointer size.
// The Windows compilers will align the first member to the alignment size of the
// class. Linux will align the first member to its natural alignment
#define DAC_ALIGNAS(a) alignas(a)

#endif // #ifndef __daccess_h__
2 changes: 2 additions & 0 deletions src/inc/sstring.h
Original file line number Diff line number Diff line change
Expand Up @@ -808,6 +808,7 @@ template <COUNT_T MEMSIZE>
class InlineSString : public SString
{
private:
DAC_ALIGNAS(SString)
BYTE m_inline[SBUFFER_PADDED_SIZE(MEMSIZE)];

public:
Expand Down Expand Up @@ -990,6 +991,7 @@ template <COUNT_T MEMSIZE>
class ScratchBuffer : public SString::AbstractScratchBuffer
{
private:
DAC_ALIGNAS(::SString::AbstractScratchBuffer)
BYTE m_inline[MEMSIZE];

public:
Expand Down
2 changes: 2 additions & 0 deletions src/inc/stgpool.h
Original file line number Diff line number Diff line change
Expand Up @@ -1105,6 +1105,7 @@ class StgGuidPool : public StgPool


private:
DAC_ALIGNAS(StgPool) // Align first member to alignment of base class
CGuidPoolHash m_Hash; // Hash table for lookups.
int m_bHash; // true to keep hash table.
}; // class StgGuidPool
Expand Down Expand Up @@ -1257,6 +1258,7 @@ class StgBlobPool : public StgPool
__checkReturn
HRESULT RehashBlobs();

DAC_ALIGNAS(StgPool) // Align first member to alignment of base class
CBlobPoolHash m_Hash; // Hash table for lookups.
}; // class StgBlobPool

Expand Down
1 change: 1 addition & 0 deletions src/inc/utilcode.h
Original file line number Diff line number Diff line change
Expand Up @@ -2648,6 +2648,7 @@ template <class MemMgr>
class CHashTableAndData : public CHashTable
{
public:
DAC_ALIGNAS(CHashTable)
ULONG m_iFree; // Index into m_pcEntries[] of next available slot
ULONG m_iEntries; // size of m_pcEntries[]

Expand Down
3 changes: 1 addition & 2 deletions src/md/compiler/regmeta.h
Original file line number Diff line number Diff line change
Expand Up @@ -1987,8 +1987,7 @@ class RegMeta :
#endif //FEATURE_METADATA_INTERNAL_APIS

UTSemReadWrite *m_pSemReadWrite;
bool m_fOwnSem;

unsigned m_fOwnSem : 1;
unsigned m_bRemap : 1; // If true, there is a token mapper.
unsigned m_bSaveOptimized : 1; // If true, save optimization has been done.
unsigned m_hasOptimizedRefToDef : 1; // true if we have performed ref to def optimization
Expand Down
1 change: 1 addition & 0 deletions src/md/inc/liteweightstgdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ class CLiteWeightStgdbRW : public CLiteWeightStgdb<CMiniMdRW>
const void **ppv, // [OUT] put pointer to MD stream here.
ULONG *pcb); // [OUT] put size of the stream here.

DAC_ALIGNAS(CLiteWeightStgdb<CMiniMdRW>) // Align the first member to the alignment of the base class
UINT32 m_cbSaveSize; // Size of the saved streams.
int m_bSaveCompressed; // If true, save as compressed stream (#-, not #~)
VOID* m_pImage; // Set in OpenForRead, NULL for anything but PE files
Expand Down
1 change: 1 addition & 0 deletions src/md/inc/metamodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -2120,6 +2120,7 @@ template <class Impl> class CMiniMdTemplate : public CMiniMdBase

FORCEINLINE void MarkUnsafeToDelete() { m_isSafeToDelete = false; }

DAC_ALIGNAS(CMiniMdBase)
bool m_isSafeToDelete; // This starts out true, but gets set to FALSE if we detect
// a MiniMd API call that might have given out an internal pointer.
#endif
Expand Down
1 change: 1 addition & 0 deletions src/md/inc/metamodelro.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class CMiniMd final: public CMiniMdTemplate<CMiniMd>
#endif //FEATURE_PREJIT

protected:
DAC_ALIGNAS(CMiniMdTemplate<CMiniMd>) // Align the first member to the alignment of the base class
// Table info.
MetaData::TableRO m_Tables[TBL_COUNT];
#ifdef FEATURE_PREJIT
Expand Down
1 change: 1 addition & 0 deletions src/md/inc/metamodelrw.h
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,7 @@ class CMiniMdRW : public CMiniMdTemplate<CMiniMdRW>
return HashToken(tkObject);
}

DAC_ALIGNAS(CMiniMdTemplate<CMiniMdRW>) // Align the first member to the alignment of the base class
CMemberRefHash *m_pMemberRefHash;

// Hash table for Methods and Fields
Expand Down
1 change: 1 addition & 0 deletions src/md/inc/recordpool.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ class RecordPool : public StgPool
void **pContext); // Stored context here.

private:
DAC_ALIGNAS(StgPool) // Align first member to alignment of base class
UINT32 m_cbRec; // How large is each record?

}; // class RecordPool
Expand Down
2 changes: 2 additions & 0 deletions src/vm/class.h
Original file line number Diff line number Diff line change
Expand Up @@ -2171,6 +2171,7 @@ struct ComPlusCallInfo;
class DelegateEEClass : public EEClass
{
public:
DAC_ALIGNAS(EEClass) // Align the first member to the alignment of the base class
PTR_Stub m_pStaticCallStub;
PTR_Stub m_pInstRetBuffCallStub;
RelativePointer<PTR_MethodDesc> m_pInvokeMethod;
Expand Down Expand Up @@ -2241,6 +2242,7 @@ class ArrayClass : public EEClass

private:

DAC_ALIGNAS(EEClass) // Align the first member to the alignment of the base class
unsigned char m_rank;
CorElementType m_ElementType;// Cache of element type in m_ElementTypeHnd

Expand Down
24 changes: 15 additions & 9 deletions src/vm/dynamicmethod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -851,20 +851,26 @@ void DynamicMethodDesc::Destroy()
LoaderAllocator *pLoaderAllocator = GetLoaderAllocator();

LOG((LF_BCL, LL_INFO1000, "Level3 - Destroying DynamicMethod {0x%p}\n", this));
if (!m_pSig.IsNull())

// The m_pSig and m_pszMethodName need to be destroyed after the GetLCGMethodResolver()->Destroy() call
// otherwise the EEJitManager::CodeHeapIterator could return DynamicMethodDesc with these members NULLed, but
// the nibble map for the corresponding code memory indicating that this DynamicMethodDesc is still alive.
PCODE pSig = m_pSig.GetValue();
PTR_CUTF8 pszMethodName = m_pszMethodName.GetValue();

GetLCGMethodResolver()->Destroy();
// The current DynamicMethodDesc storage is destroyed at this point

if (pszMethodName != NULL)
{
delete[] (BYTE*)m_pSig.GetValue();
m_pSig.SetValueMaybeNull(NULL);
delete[] pszMethodName;
}
m_cSig = 0;
if (!m_pszMethodName.IsNull())

if (pSig != NULL)
{
delete[] m_pszMethodName.GetValue();
m_pszMethodName.SetValueMaybeNull(NULL);
delete[] (BYTE*)pSig;
}

GetLCGMethodResolver()->Destroy();

if (pLoaderAllocator->IsCollectible())
{
if (pLoaderAllocator->Release())
Expand Down
6 changes: 4 additions & 2 deletions src/vm/eventpipebuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ EventPipeBuffer::EventPipeBuffer(unsigned int bufferSize, EventPipeThread* pWrit
m_state = EventPipeBufferState::WRITABLE;
m_pWriterThread = pWriterThread;
m_eventSequenceNumber = eventSequenceNumber;
m_pBuffer = new BYTE[bufferSize];
// Use ClrVirtualAlloc instead of malloc to allocate buffer to avoid potential internal fragmentation in the native CRT heap.
// (See https://github.com/dotnet/runtime/pull/35924 and https://github.com/microsoft/ApplicationInsights-dotnet/issues/1678 for more details)
m_pBuffer = (BYTE*)ClrVirtualAlloc(NULL, bufferSize, MEM_COMMIT, PAGE_READWRITE);
memset(m_pBuffer, 0, bufferSize);
m_pLimit = m_pBuffer + bufferSize;
m_pCurrent = GetNextAlignedAddress(m_pBuffer);
Expand All @@ -47,7 +49,7 @@ EventPipeBuffer::~EventPipeBuffer()
}
CONTRACTL_END;

delete[] m_pBuffer;
ClrVirtualFree(m_pBuffer, 0, MEM_RELEASE);
}

bool EventPipeBuffer::WriteEvent(Thread *pThread, EventPipeSession &session, EventPipeEvent &event, EventPipeEventPayload &payload, LPCGUID pActivityId, LPCGUID pRelatedActivityId, StackContents *pStack)
Expand Down
6 changes: 6 additions & 0 deletions src/vm/eventpipebuffermanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,12 @@ EventPipeBuffer* EventPipeBufferManager::AllocateBufferForThread(EventPipeThread
const unsigned int maxBufferSize = 1024 * 1024;
bufferSize = Min(bufferSize, maxBufferSize);

// Make the buffer size fit into with pagesize-aligned block,
// since ClrVirtualAlloc expects page-aligned sizes to be passed
// as arguments (see ctor of EventPipeBuffer)
bufferSize = (bufferSize + g_SystemInfo.dwAllocationGranularity - 1) & ~static_cast<unsigned int>(g_SystemInfo.dwAllocationGranularity - 1);


// EX_TRY is used here as opposed to new (nothrow) because
// the constructor also allocates a private buffer, which
// could throw, and cannot be easily checked
Expand Down
4 changes: 4 additions & 0 deletions src/vm/loaderallocator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ class LoaderAllocator
// Heaps for allocating data that persists for the life of the AppDomain
// Objects that are allocated frequently should be allocated into the HighFreq heap for
// better page management

DAC_ALIGNAS(UINT64) // Align the first member to alignof(m_nLoaderAllocator). Windows does this by default, force Linux to match.
BYTE * m_InitialReservedMemForLoaderHeaps;
BYTE m_LowFreqHeapInstance[sizeof(LoaderHeap)];
BYTE m_HighFreqHeapInstance[sizeof(LoaderHeap)];
Expand Down Expand Up @@ -623,6 +625,7 @@ class GlobalLoaderAllocator : public LoaderAllocator
VPTR_VTABLE_CLASS(GlobalLoaderAllocator, LoaderAllocator)
VPTR_UNIQUE(VPTRU_LoaderAllocator+1)

DAC_ALIGNAS(LoaderAllocator) // Align the first member to the alignment of the base class
BYTE m_ExecutableHeapInstance[sizeof(LoaderHeap)];

protected:
Expand All @@ -645,6 +648,7 @@ class AssemblyLoaderAllocator : public LoaderAllocator
VPTR_UNIQUE(VPTRU_LoaderAllocator+3)

protected:
DAC_ALIGNAS(LoaderAllocator) // Align the first member to the alignment of the base class
LoaderAllocatorID m_Id;
ShuffleThunkCache* m_pShuffleThunkCache;
public:
Expand Down

0 comments on commit 018cfd0

Please sign in to comment.