Skip to content
This repository has been archived by the owner on Nov 1, 2020. It is now read-only.

Commit

Permalink
Merge pull request #1850 from dotnet/nmirror
Browse files Browse the repository at this point in the history
Merge nmirror to master
  • Loading branch information
jkotas committed Sep 14, 2016
2 parents 695fae9 + d15efbe commit fe1c13a
Show file tree
Hide file tree
Showing 50 changed files with 1,470 additions and 1,314 deletions.
4 changes: 2 additions & 2 deletions src/Native/Runtime/AsmOffsets.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ ASM_OFFSET( 48, 78, Thread, m_pExInfoStackHead)

ASM_SIZEOF( 14, 20, EHEnum)

ASM_OFFSET( 0, 0, alloc_context, alloc_ptr)
ASM_OFFSET( 4, 8, alloc_context, alloc_limit)
ASM_OFFSET( 0, 0, gc_alloc_context, alloc_ptr)
ASM_OFFSET( 4, 8, gc_alloc_context, alloc_limit)

ASM_OFFSET( 4, 8, RuntimeInstance, m_pThreadStore)

Expand Down
4 changes: 2 additions & 2 deletions src/Native/Runtime/AsmOffsetsVerify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// See the LICENSE file in the project root for more information.
#include "common.h"
#include "gcenv.h"
#include "gc.h"
#include "gcheaputilities.h"
#include "rhassert.h"
#include "RedhawkWarnings.h"
#include "slist.h"
Expand All @@ -23,7 +23,7 @@

class AsmOffsets
{
static_assert(sizeof(Thread::m_rgbAllocContextBuffer) >= sizeof(alloc_context), "Thread::m_rgbAllocContextBuffer is not big enough to hold an alloc_context");
static_assert(sizeof(Thread::m_rgbAllocContextBuffer) >= sizeof(gc_alloc_context), "Thread::m_rgbAllocContextBuffer is not big enough to hold a gc_alloc_context");

#define PLAT_ASM_OFFSET(offset, cls, member) \
static_assert((offsetof(cls, member) == 0x##offset) || (offsetof(cls, member) > 0x##offset), "Bad asm offset for '" #cls "." #member "', the actual offset is smaller than 0x" #offset "."); \
Expand Down
1 change: 1 addition & 0 deletions src/Native/Runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ set(COMMON_RUNTIME_SOURCES
FinalizerHelpers.cpp
gcdump.cpp
GCHelpers.cpp
gcheaputilities.cpp
GCMemoryHelpers.cpp
gcrhenv.cpp
gcrhscan.cpp
Expand Down
6 changes: 3 additions & 3 deletions src/Native/Runtime/FinalizerHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//
#include "common.h"
#include "gcenv.h"
#include "gc.h"
#include "gcheaputilities.h"

#include "slist.h"
#include "gcrhinterface.h"
Expand All @@ -30,7 +30,7 @@ EXTERN_C REDHAWK_API UInt32_BOOL __cdecl RhpWaitForFinalizerRequest()
// request.
static bool fLastEventWasLowMemory = false;

GCHeap * pHeap = GCHeap::GetGCHeap();
IGCHeap * pHeap = GCHeapUtilities::GetGCHeap();

// Wait in a loop because we may have to retry if we decide to only wait for finalization events but the
// two second timeout expires.
Expand Down Expand Up @@ -91,7 +91,7 @@ COOP_PINVOKE_HELPER(OBJECTREF, RhpGetNextFinalizableObject, ())
while (true)
{
// Get the next finalizable object. If we get back NULL we've reached the end of the list.
OBJECTREF refNext = GCHeap::GetGCHeap()->GetNextFinalizable();
OBJECTREF refNext = GCHeapUtilities::GetGCHeap()->GetNextFinalizable();
if (refNext == NULL)
return NULL;

Expand Down
36 changes: 18 additions & 18 deletions src/Native/Runtime/GCHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include "common.h"
#include "gcenv.h"
#include "gc.h"
#include "gcheaputilities.h"
#include "RestrictedCallouts.h"

#include "gcrhinterface.h"
Expand Down Expand Up @@ -44,7 +44,7 @@ EXTERN_C REDHAWK_API void __cdecl RhpCollect(UInt32 uGeneration, UInt32 uMode)
pCurThread->DisablePreemptiveMode();

ASSERT(!pCurThread->IsDoNotTriggerGcSet());
GCHeap::GetGCHeap()->GarbageCollect(uGeneration, FALSE, uMode);
GCHeapUtilities::GetGCHeap()->GarbageCollect(uGeneration, FALSE, uMode);

pCurThread->EnablePreemptiveMode();
}
Expand All @@ -58,7 +58,7 @@ EXTERN_C REDHAWK_API Int64 __cdecl RhpGetGcTotalMemory()
pCurThread->SetupHackPInvokeTunnel();
pCurThread->DisablePreemptiveMode();

Int64 ret = GCHeap::GetGCHeap()->GetTotalBytesInUse();
Int64 ret = GCHeapUtilities::GetGCHeap()->GetTotalBytesInUse();

pCurThread->EnablePreemptiveMode();

Expand All @@ -69,44 +69,44 @@ COOP_PINVOKE_HELPER(void, RhSuppressFinalize, (OBJECTREF refObj))
{
if (!refObj->get_EEType()->HasFinalizer())
return;
GCHeap::GetGCHeap()->SetFinalizationRun(refObj);
GCHeapUtilities::GetGCHeap()->SetFinalizationRun(refObj);
}

COOP_PINVOKE_HELPER(Boolean, RhReRegisterForFinalize, (OBJECTREF refObj))
{
if (!refObj->get_EEType()->HasFinalizer())
return Boolean_true;
return GCHeap::GetGCHeap()->RegisterForFinalization(-1, refObj) ? Boolean_true : Boolean_false;
return GCHeapUtilities::GetGCHeap()->RegisterForFinalization(-1, refObj) ? Boolean_true : Boolean_false;
}

COOP_PINVOKE_HELPER(Int32, RhGetMaxGcGeneration, ())
{
return GCHeap::GetGCHeap()->GetMaxGeneration();
return GCHeapUtilities::GetGCHeap()->GetMaxGeneration();
}

COOP_PINVOKE_HELPER(Int32, RhGetGcCollectionCount, (Int32 generation, Boolean getSpecialGCCount))
{
return GCHeap::GetGCHeap()->CollectionCount(generation, getSpecialGCCount);
return GCHeapUtilities::GetGCHeap()->CollectionCount(generation, getSpecialGCCount);
}

COOP_PINVOKE_HELPER(Int32, RhGetGeneration, (OBJECTREF obj))
{
return GCHeap::GetGCHeap()->WhichGeneration(obj);
return GCHeapUtilities::GetGCHeap()->WhichGeneration(obj);
}

COOP_PINVOKE_HELPER(Int32, RhGetGcLatencyMode, ())
{
return GCHeap::GetGCHeap()->GetGcLatencyMode();
return GCHeapUtilities::GetGCHeap()->GetGcLatencyMode();
}

COOP_PINVOKE_HELPER(void, RhSetGcLatencyMode, (Int32 newLatencyMode))
{
GCHeap::GetGCHeap()->SetGcLatencyMode(newLatencyMode);
GCHeapUtilities::GetGCHeap()->SetGcLatencyMode(newLatencyMode);
}

COOP_PINVOKE_HELPER(Boolean, RhIsServerGc, ())
{
return GCHeap::IsServerHeap();
return GCHeapUtilities::IsServerHeap();
}

COOP_PINVOKE_HELPER(Boolean, RhRegisterGcCallout, (GcRestrictedCalloutKind eKind, void * pCallout))
Expand All @@ -121,35 +121,35 @@ COOP_PINVOKE_HELPER(void, RhUnregisterGcCallout, (GcRestrictedCalloutKind eKind,

COOP_PINVOKE_HELPER(Boolean, RhIsPromoted, (OBJECTREF obj))
{
return GCHeap::GetGCHeap()->IsPromoted(obj) ? Boolean_true : Boolean_false;
return GCHeapUtilities::GetGCHeap()->IsPromoted(obj) ? Boolean_true : Boolean_false;
}

COOP_PINVOKE_HELPER(Int32, RhGetLohCompactionMode, ())
{
return GCHeap::GetGCHeap()->GetLOHCompactionMode();
return GCHeapUtilities::GetGCHeap()->GetLOHCompactionMode();
}

COOP_PINVOKE_HELPER(void, RhSetLohCompactionMode, (Int32 newLohCompactionMode))
{
GCHeap::GetGCHeap()->SetLOHCompactionMode(newLohCompactionMode);
GCHeapUtilities::GetGCHeap()->SetLOHCompactionMode(newLohCompactionMode);
}

COOP_PINVOKE_HELPER(Int64, RhGetCurrentObjSize, ())
{
return GCHeap::GetGCHeap()->GetCurrentObjSize();
return GCHeapUtilities::GetGCHeap()->GetCurrentObjSize();
}

COOP_PINVOKE_HELPER(Int64, RhGetGCNow, ())
{
return GCHeap::GetGCHeap()->GetNow();
return GCHeapUtilities::GetGCHeap()->GetNow();
}

COOP_PINVOKE_HELPER(Int64, RhGetLastGCStartTime, (Int32 generation))
{
return GCHeap::GetGCHeap()->GetLastGCStartTime(generation);
return GCHeapUtilities::GetGCHeap()->GetLastGCStartTime(generation);
}

COOP_PINVOKE_HELPER(Int64, RhGetLastGCDuration, (Int32 generation))
{
return GCHeap::GetGCHeap()->GetLastGCDuration(generation);
return GCHeapUtilities::GetGCHeap()->GetLastGCDuration(generation);
}
4 changes: 2 additions & 2 deletions src/Native/Runtime/amd64/AsmMacros.inc
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,8 @@ TSF_DoNotTriggerGc equ 10h
;;
;; Rename fields of nested structs
;;
OFFSETOF__Thread__m_alloc_context__alloc_ptr equ OFFSETOF__Thread__m_rgbAllocContextBuffer + OFFSETOF__alloc_context__alloc_ptr
OFFSETOF__Thread__m_alloc_context__alloc_limit equ OFFSETOF__Thread__m_rgbAllocContextBuffer + OFFSETOF__alloc_context__alloc_limit
OFFSETOF__Thread__m_alloc_context__alloc_ptr equ OFFSETOF__Thread__m_rgbAllocContextBuffer + OFFSETOF__gc_alloc_context__alloc_ptr
OFFSETOF__Thread__m_alloc_context__alloc_limit equ OFFSETOF__Thread__m_rgbAllocContextBuffer + OFFSETOF__gc_alloc_context__alloc_limit



Expand Down
4 changes: 2 additions & 2 deletions src/Native/Runtime/arm/AsmMacros.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ PTFF_R0_IS_BYREF equ 0x00008000 ;; iff PTFF_SAVE_R0: set -> r0 is ByRef,
;;
;; Rename fields of nested structs
;;
OFFSETOF__Thread__m_alloc_context__alloc_ptr equ OFFSETOF__Thread__m_rgbAllocContextBuffer + OFFSETOF__alloc_context__alloc_ptr
OFFSETOF__Thread__m_alloc_context__alloc_limit equ OFFSETOF__Thread__m_rgbAllocContextBuffer + OFFSETOF__alloc_context__alloc_limit
OFFSETOF__Thread__m_alloc_context__alloc_ptr equ OFFSETOF__Thread__m_rgbAllocContextBuffer + OFFSETOF__gc_alloc_context__alloc_ptr
OFFSETOF__Thread__m_alloc_context__alloc_limit equ OFFSETOF__Thread__m_rgbAllocContextBuffer + OFFSETOF__gc_alloc_context__alloc_limit


__tls_array equ 0x2C ;; offsetof(TEB, ThreadLocalStoragePointer)
Expand Down
4 changes: 2 additions & 2 deletions src/Native/Runtime/arm64/AsmMacros.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ GC_ALLOC_ALIGN8 equ 8
;;
;; Rename fields of nested structs
;;
OFFSETOF__Thread__m_alloc_context__alloc_ptr equ OFFSETOF__Thread__m_rgbAllocContextBuffer + OFFSETOF__alloc_context__alloc_ptr
OFFSETOF__Thread__m_alloc_context__alloc_limit equ OFFSETOF__Thread__m_rgbAllocContextBuffer + OFFSETOF__alloc_context__alloc_limit
OFFSETOF__Thread__m_alloc_context__alloc_ptr equ OFFSETOF__Thread__m_rgbAllocContextBuffer + OFFSETOF__gc_alloc_context__alloc_ptr
OFFSETOF__Thread__m_alloc_context__alloc_limit equ OFFSETOF__Thread__m_rgbAllocContextBuffer + OFFSETOF__gc_alloc_context__alloc_limit

4 changes: 2 additions & 2 deletions src/Native/Runtime/gcenv.h
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,8 @@ inline UInt16 GetClrInstanceId()
return (UInt16)_tls_index;
}

class GCHeap;
typedef DPTR(GCHeap) PTR_GCHeap;
class IGCHeap;
typedef DPTR(IGCHeap) PTR_IGCHeap;
typedef DPTR(uint32_t) PTR_uint32_t;

enum CLRDataEnumMemoryFlags : int;
Expand Down
10 changes: 10 additions & 0 deletions src/Native/Runtime/gcheaputilities.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#include "common.h"
#include "gcenv.h"
#include "gcheaputilities.h"

// This is the global GC heap, maintained by the VM.
GPTR_IMPL(IGCHeap, g_pGCHeap);
110 changes: 110 additions & 0 deletions src/Native/Runtime/gcheaputilities.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#ifndef _GCHEAPUTILITIES_H_
#define _GCHEAPUTILITIES_H_

#include "gcinterface.h"

// The singular heap instance.
GPTR_DECL(IGCHeap, g_pGCHeap);

// GCHeapUtilities provides a number of static methods
// that operate on the global heap instance. It can't be
// instantiated.
class GCHeapUtilities {
public:
// Retrieves the GC heap.
inline static IGCHeap* GetGCHeap()
{
assert(g_pGCHeap != nullptr);
return g_pGCHeap;
}

// Returns true if the heap has been initialized, false otherwise.
inline static bool IsGCHeapInitialized()
{
return g_pGCHeap != nullptr;
}

// Returns true if a the heap is initialized and a garbage collection
// is in progress, false otherwise.
inline static BOOL IsGCInProgress(BOOL bConsiderGCStart = FALSE)
{
WRAPPER_NO_CONTRACT;

return (IsGCHeapInitialized() ? GetGCHeap()->IsGCInProgressHelper(bConsiderGCStart) : false);
}

// Returns true if we should be competing marking for statics. This
// influences the behavior of `GCToEEInterface::GcScanRoots`.
inline static BOOL MarkShouldCompeteForStatics()
{
WRAPPER_NO_CONTRACT;

return IsServerHeap() && g_SystemInfo.dwNumberOfProcessors >= 2;
}

// Waits until a GC is complete, if the heap has been initialized.
inline static void WaitForGCCompletion(BOOL bConsiderGCStart = FALSE)
{
WRAPPER_NO_CONTRACT;

if (IsGCHeapInitialized())
GetGCHeap()->WaitUntilGCComplete(bConsiderGCStart);
}

// Returns true if we should be using allocation contexts, false otherwise.
inline static bool UseAllocationContexts()
{
WRAPPER_NO_CONTRACT;
#ifdef FEATURE_REDHAWK
// SIMPLIFY: only use allocation contexts
return true;
#else
#if defined(_TARGET_ARM_) || defined(FEATURE_PAL)
return true;
#else
return ((IsServerHeap() ? true : (g_SystemInfo.dwNumberOfProcessors >= 2)));
#endif
#endif
}

// Returns true if the held GC heap is a Server GC heap, false otherwise.
inline static bool IsServerHeap()
{
LIMITED_METHOD_CONTRACT;
#ifdef FEATURE_SVR_GC
_ASSERTE(IGCHeap::gcHeapType != IGCHeap::GC_HEAP_INVALID);
return (IGCHeap::gcHeapType == IGCHeap::GC_HEAP_SVR);
#else // FEATURE_SVR_GC
return false;
#endif // FEATURE_SVR_GC
}

// Gets the maximum generation number by reading the static field
// on IGCHeap. This should only be done by the DAC code paths - all other code
// should go through IGCHeap::GetMaxGeneration.
//
// The reason for this is that, while we are in the early stages of
// decoupling the GC, the GC and the DAC still remain tightly coupled
// and, in particular, the DAC needs to know how many generations the GC
// has. However, it is not permitted to invoke virtual methods on g_pGCHeap
// while on a DAC code path. Therefore, we need to determine the max generation
// non-virtually, while still in a manner consistent with the interface -
// therefore, a static field is used.
//
// This is not without precedent - IGCHeap::gcHeapType is a static field used
// for a similar reason (the DAC needs to know what kind of heap it's looking at).
inline static unsigned GetMaxGeneration()
{
return IGCHeap::maxGeneration;
}

private:
// This class should never be instantiated.
GCHeapUtilities() = delete;
};

#endif // _GCHEAPUTILITIES_H_
Loading

0 comments on commit fe1c13a

Please sign in to comment.