Update GCInfoDecoder with CoreRT changes (dotnet/coreclr#7938)
authorJan Kotas <jkotas@microsoft.com>
Wed, 2 Nov 2016 01:57:36 +0000 (18:57 -0700)
committerGitHub <noreply@github.com>
Wed, 2 Nov 2016 01:57:36 +0000 (18:57 -0700)
Porting most of the changes from https://github.com/dotnet/corert/pull/2116 to make GCInfoDecoder compile in CoreRT to keep the different copies in sync.

Commit migrated from https://github.com/dotnet/coreclr/commit/efbd7a0ffb8ea6bb8e9fc3b273482cfd7bd7d5cd

src/coreclr/src/inc/gcinfodecoder.h
src/coreclr/src/inc/gcinfotypes.h
src/coreclr/src/vm/gcinfodecoder.cpp

index b31afb3..6d4850a 100644 (file)
 #ifndef _GC_INFO_DECODER_
 #define _GC_INFO_DECODER_
 
-#include "gcinfotypes.h"
-
 #define _max(a, b) (((a) > (b)) ? (a) : (b)) 
 #define _min(a, b) (((a) < (b)) ? (a) : (b))
 
-#ifndef GCINFODECODER_NO_EE
+#if !defined(_TARGET_X86_)
+#define USE_GC_INFO_DECODER
+#endif
+
+#if !defined(GCINFODECODER_NO_EE)
 
 #include "eetwain.h"
 
-#else // GCINFODECODER_NO_EE
+#else
+
+#ifdef FEATURE_REDHAWK
+
+typedef ArrayDPTR(const uint8_t) PTR_CBYTE;
+
+#define LIMITED_METHOD_CONTRACT
+#define SUPPORTS_DAC
+
+#define LOG(x)
+#define LOG_PIPTR(pObjRef, gcFlags, hCallBack)
+#define DAC_ARG(x)
+
+#define VALIDATE_ROOT(isInterior, hCallBack, pObjRef)
+
+#define _ASSERTE(x) assert(x)
+
+#define UINT32 UInt32
+#define INT32 Int32
+#define UINT16 UInt16
+#define UINT UInt32
+#define SIZE_T UIntNative
+#define SSIZE_T IntNative
+#define LPVOID void*
+
+typedef void * OBJECTREF;
+
+#define GET_CALLER_SP(pREGDISPLAY) ((TADDR)0)
+
+#else // FEATURE_REDHAWK
 
 // Stuff from cgencpu.h:
 
@@ -117,6 +148,12 @@ typedef void (*GCEnumCallback)(
     uint32_t        flags           // is this a pinned and/or interior pointer
 );
 
+#endif // !_EETWAIN_H
+
+#include "regdisp.h"
+
+#endif // FEATURE_REDHAWK
+
 #ifndef _strike_h
 
 enum ICodeManagerFlags
@@ -135,16 +172,9 @@ enum ICodeManagerFlags
 
 #endif // !_strike_h
 
-#if !defined(_TARGET_X86_)
-#define USE_GC_INFO_DECODER
-#endif
-
-#include "regdisp.h"
-
-#endif // !_EETWAIN_H
-
 #endif // GCINFODECODER_NO_EE
 
+
 #include "gcinfotypes.h"
 
 #ifdef _DEBUG
@@ -425,7 +455,7 @@ class GcInfoDecoder
 {
 public:
 
-    // If you are not insterested in interruptibility or gc lifetime information, pass 0 as instructionOffset
+    // If you are not interested in interruptibility or gc lifetime information, pass 0 as instructionOffset
     GcInfoDecoder(
             GCInfoToken gcInfoToken,
             GcInfoDecoderFlags flags = DECODE_EVERYTHING,
@@ -484,7 +514,7 @@ public:
     UINT32  GetPrologSize();
     INT32   GetPSPSymStackSlot();
     INT32   GetGenericsInstContextStackSlot();
-    INT32   GetReversePInvokeStackSlot();
+    INT32   GetReversePInvokeFrameStackSlot();
     bool    HasMethodDescGenericsInstContext();
     bool    HasMethodTableGenericsInstContext();
     bool    GetIsVarArg();
@@ -512,7 +542,7 @@ private:
     bool    m_WantsReportOnlyLeaf;
     INT32   m_SecurityObjectStackSlot;
     INT32   m_GSCookieStackSlot;
-    INT32   m_ReversePInvokeStackSlot;
+    INT32   m_ReversePInvokeFrameStackSlot;
     UINT32  m_ValidRangeStart;
     UINT32  m_ValidRangeEnd;
     INT32   m_PSPSymStackSlot;
@@ -520,7 +550,6 @@ private:
     UINT32  m_CodeLength;
     UINT32  m_StackBaseRegister;
     UINT32  m_SizeOfEditAndContinuePreservedArea;
-    INT32  m_ReversePInvokeFrameSlot;
     ReturnKind m_ReturnKind;
 #ifdef PARTIALLY_INTERRUPTIBLE_GC_SUPPORTED
     UINT32  m_NumSafePoints;
index 05f35c4..c802d97 100644 (file)
@@ -6,7 +6,10 @@
 #ifndef __GCINFOTYPES_H__
 #define __GCINFOTYPES_H__
 
+#ifndef FEATURE_REDHAWK
 #include "gcinfo.h"
+#endif
+
 
 #define PARTIALLY_INTERRUPTIBLE_GC_SUPPORTED
 
index c49da86..89f4704 100644 (file)
@@ -4,6 +4,7 @@
 
 
 #include "common.h"
+
 #include "gcinfodecoder.h"
 
 #ifdef USE_GC_INFO_DECODER
@@ -282,11 +283,11 @@ GcInfoDecoder::GcInfoDecoder(
 
     if (hasReversePInvokeFrame)
     {
-        m_ReversePInvokeFrameSlot = (INT32)m_Reader.DecodeVarLengthSigned(REVERSE_PINVOKE_FRAME_ENCBASE);
+        m_ReversePInvokeFrameStackSlot = (INT32)m_Reader.DecodeVarLengthSigned(REVERSE_PINVOKE_FRAME_ENCBASE);
     }
     else
     {
-        m_ReversePInvokeFrameSlot = NO_REVERSE_PINVOKE_FRAME;
+        m_ReversePInvokeFrameStackSlot = NO_REVERSE_PINVOKE_FRAME;
     }
 
 
@@ -488,10 +489,10 @@ INT32 GcInfoDecoder::GetGSCookieStackSlot()
     return m_GSCookieStackSlot;
 }
 
-INT32 GcInfoDecoder::GetReversePInvokeStackSlot()
+INT32 GcInfoDecoder::GetReversePInvokeFrameStackSlot()
 {
     _ASSERTE(m_Flags & DECODE_REVERSE_PINVOKE_VAR);
-    return m_ReversePInvokeStackSlot;
+    return m_ReversePInvokeFrameStackSlot;
 }
 
 UINT32 GcInfoDecoder::GetGSCookieValidRangeStart()
@@ -615,24 +616,6 @@ bool GcInfoDecoder::EnumerateLiveSlots(
 
     UINT32 normBreakOffset = NORMALIZE_CODE_OFFSET(m_InstructionOffset);
 
-#if 0
-    // This is currently disabled because sometimes on IA64 we need
-    //  to make call sites non-interruptible
-    // TODO: review this
-#ifdef _DEBUG
-    if(!executionAborted)
-    {
-        GcInfoDecoder _decoder2(
-                m_GcInfoAddress,
-                DECODE_INTERRUPTIBILITY,
-                m_InstructionOffset
-                );
-
-        _ASSERTE(_decoder2.IsInterruptible());
-    }
-#endif
-#endif
-
     // Normalized break offset
     // Relative to interruptible ranges #if PARTIALLY_INTERRUPTIBLE_GC_SUPPORTED
 #ifdef PARTIALLY_INTERRUPTIBLE_GC_SUPPORTED
@@ -1358,11 +1341,15 @@ OBJECTREF* GcInfoDecoder::GetRegisterSlot(
     _ASSERTE(regNum >= 0 && regNum <= 16);
     _ASSERTE(regNum != 4);  // rsp
 
+#ifdef FEATURE_REDHAWK
+    PTR_UIntNative* ppRax = &pRD->pRax;
+    if (regNum > 4) regNum--; // rsp is skipped in Redhawk RegDisplay
+#else
     // The fields of KNONVOLATILE_CONTEXT_POINTERS are in the same order as
     // the processor encoding numbers.
 
-    ULONGLONG **ppRax;
-    ppRax = &pRD->pCurrentContextPointers->Rax;
+    ULONGLONG **ppRax = &pRD->pCurrentContextPointers->Rax;
+#endif
 
     return (OBJECTREF*)*(ppRax + regNum);
 }
@@ -1379,8 +1366,7 @@ OBJECTREF* GcInfoDecoder::GetCapturedRegister(
     // The fields of CONTEXT are in the same order as
     // the processor encoding numbers.
 
-    ULONGLONG *pRax;
-    pRax = &pRD->pCurrentContext->Rax;
+    ULONGLONG *pRax = &pRD->pCurrentContext->Rax;
 
     return (OBJECTREF*)(pRax + regNum);
 }
@@ -1412,7 +1398,7 @@ bool GcInfoDecoder::IsScratchStackSlot(INT32 spOffset, GcStackSlotBase spBase, P
 #ifdef FIXED_STACK_PARAMETER_SCRATCH_AREA
     _ASSERTE( m_Flags & DECODE_GC_LIFETIMES );
 
-    ULONGLONG pSlot = (ULONGLONG) GetStackSlot(spOffset, spBase, pRD);
+    TADDR pSlot = (TADDR) GetStackSlot(spOffset, spBase, pRD);
     _ASSERTE(pSlot >= pRD->SP);
 
     return (pSlot < pRD->SP + m_SizeOfStackOutgoingAndScratchArea);
@@ -1524,8 +1510,7 @@ OBJECTREF* GcInfoDecoder::GetCapturedRegister(
     // The fields of CONTEXT are in the same order as
     // the processor encoding numbers.
 
-    ULONG *pR0;
-    pR0 = &pRD->pCurrentContext->R0;
+    ULONG *pR0 = &pRD->pCurrentContext->R0;
 
     return (OBJECTREF*)(pR0 + regNum);
 }
@@ -1546,7 +1531,7 @@ bool GcInfoDecoder::IsScratchStackSlot(INT32 spOffset, GcStackSlotBase spBase, P
 #ifdef FIXED_STACK_PARAMETER_SCRATCH_AREA
     _ASSERTE( m_Flags & DECODE_GC_LIFETIMES );
 
-    DWORD pSlot = (DWORD) GetStackSlot(spOffset, spBase, pRD);
+    TADDR pSlot = (TADDR) GetStackSlot(spOffset, spBase, pRD);
     _ASSERTE(pSlot >= pRD->SP);
 
     return (pSlot < pRD->SP + m_SizeOfStackOutgoingAndScratchArea);
@@ -1637,7 +1622,7 @@ bool GcInfoDecoder::IsScratchStackSlot(INT32 spOffset, GcStackSlotBase spBase, P
 #ifdef FIXED_STACK_PARAMETER_SCRATCH_AREA
     _ASSERTE( m_Flags & DECODE_GC_LIFETIMES );
 
-    ULONGLONG pSlot = (ULONGLONG) GetStackSlot(spOffset, spBase, pRD);
+    TADDR pSlot = (TADDR) GetStackSlot(spOffset, spBase, pRD);
     _ASSERTE(pSlot >= pRD->SP);
 
     return (pSlot < pRD->SP + m_SizeOfStackOutgoingAndScratchArea);
@@ -1695,8 +1680,7 @@ OBJECTREF* GcInfoDecoder::GetCapturedRegister(
     // The fields of CONTEXT are in the same order as
     // the processor encoding numbers.
 
-    DWORD64 *pX0;
-    pX0 = &pRD->pCurrentContext->X0;
+    DWORD64 *pX0 = &pRD->pCurrentContext->X0;
 
     return (OBJECTREF*)(pX0 + regNum);
 }
@@ -1753,7 +1737,7 @@ OBJECTREF* GcInfoDecoder::GetStackSlot(
 
     if( GC_SP_REL == spBase )
     {
-        pObjRef = (OBJECTREF*) ((SIZE_T)GetRegdisplaySP(pRD) + spOffset);
+        pObjRef = (OBJECTREF*) ((SIZE_T)pRD->SP + spOffset);
     }
     else if( GC_CALLER_SP_REL == spBase )
     {