Cross-bitness support in JitInterface (#18329)
authorEgor Chesakov <Egor.Chesakov@microsoft.com>
Thu, 7 Jun 2018 06:49:48 +0000 (23:49 -0700)
committerJan Kotas <jkotas@microsoft.com>
Thu, 7 Jun 2018 06:49:48 +0000 (23:49 -0700)
* Replace sizeof(tailCallType) / sizeof(tailCallType[0]) with _countof(tailCallType)

* Remove TransparentProxyObject and RealProxyObject

* InlinedCallFrame::GetEEInfo should not be used for R2R compilation

* Hardcode constants used in CEEInfo::getEEInfo

* Thread fields should not be used for R2R compilation

* Zero pEEInfoOut->inlinedCallFrameInfo when compiling R2R code

* Rename OFFSETOF__PtrArray__m_Array to avoid compilation conflicts with asmconstants

* Add assertions enabled in every non-crossbitness scenario

* Define and use CROSSBITNESS_COMPILE macro

src/inc/crosscomp.h
src/vm/jitinterface.cpp
src/vm/object.h
src/vm/vars.hpp

index 200c343..1476895 100644 (file)
@@ -8,6 +8,10 @@
 
 #pragma once
 
+#if (!defined(_WIN64) && defined(_TARGET_64BIT_)) || (defined(_WIN64) && !defined(_TARGET_64BIT_))
+#define CROSSBITNESS_COMPILE
+#endif
+
 #if defined(_X86_) && defined(_TARGET_ARM_)      // Host X86 managing ARM related code
 
 #ifndef CROSS_COMPILE
index 71e944a..ff8a89d 100644 (file)
@@ -8331,7 +8331,7 @@ void CEEInfo::reportTailCallDecision (CORINFO_METHOD_HANDLE callerHnd,
             static const char * const tailCallType[] = {
                 "optimized tail call", "recursive loop", "helper assisted tailcall"
             };
-            _ASSERTE(tailCallResult >= 0 && (size_t)tailCallResult < sizeof(tailCallType) / sizeof(tailCallType[0]));
+            _ASSERTE(tailCallResult >= 0 && (size_t)tailCallResult < _countof(tailCallType));
             LOG((LF_JIT, LL_INFO100000,
                  "While compiling '%S', %Splicit tail call from '%S' to '%S' generated as a %s.\n",
                  currentMethodName.GetUnicode(), fIsTailPrefix ? W("ex") : W("im"),
@@ -10090,24 +10090,43 @@ void CEEInfo::getEEInfo(CORINFO_EE_INFO *pEEInfoOut)
 
     JIT_TO_EE_TRANSITION();
 
-    InlinedCallFrame::GetEEInfo(&pEEInfoOut->inlinedCallFrameInfo);
+    if (!IsReadyToRunCompilation())
+    {
+        InlinedCallFrame::GetEEInfo(&pEEInfoOut->inlinedCallFrameInfo);
+
+        // Offsets into the Thread structure
+        pEEInfoOut->offsetOfThreadFrame = Thread::GetOffsetOfCurrentFrame();
+        pEEInfoOut->offsetOfGCState     = Thread::GetOffsetOfGCFlag();
+    }
+    else
+    {
+        // inlinedCallFrameInfo is not used for R2R compilation
+        ZeroMemory(&pEEInfoOut->inlinedCallFrameInfo, sizeof(pEEInfoOut->inlinedCallFrameInfo));
+
+        pEEInfoOut->offsetOfThreadFrame = (DWORD)-1;
+        pEEInfoOut->offsetOfGCState     = (DWORD)-1;
+    }
 
-    // Offsets into the Thread structure
-    pEEInfoOut->offsetOfThreadFrame = Thread::GetOffsetOfCurrentFrame();
-    pEEInfoOut->offsetOfGCState     = Thread::GetOffsetOfGCFlag();
+#ifndef CROSSBITNESS_COMPILE
+    // The assertions must hold in every non-crossbitness scenario
+    _ASSERTE(OFFSETOF__DelegateObject__target       == DelegateObject::GetOffsetOfTarget());
+    _ASSERTE(OFFSETOF__DelegateObject__methodPtr    == DelegateObject::GetOffsetOfMethodPtr());
+    _ASSERTE(OFFSETOF__DelegateObject__methodPtrAux == DelegateObject::GetOffsetOfMethodPtrAux());
+    _ASSERTE(OFFSETOF__PtrArray__m_Array_           == PtrArray::GetDataOffset());
+#endif
 
     // Delegate offsets
-    pEEInfoOut->offsetOfDelegateInstance    = DelegateObject::GetOffsetOfTarget();
-    pEEInfoOut->offsetOfDelegateFirstTarget = DelegateObject::GetOffsetOfMethodPtr();
+    pEEInfoOut->offsetOfDelegateInstance    = OFFSETOF__DelegateObject__target;
+    pEEInfoOut->offsetOfDelegateFirstTarget = OFFSETOF__DelegateObject__methodPtr;
 
     // Secure delegate offsets
-    pEEInfoOut->offsetOfSecureDelegateIndirectCell = DelegateObject::GetOffsetOfMethodPtrAux();
+    pEEInfoOut->offsetOfSecureDelegateIndirectCell = OFFSETOF__DelegateObject__methodPtrAux;
 
     // Remoting offsets
-    pEEInfoOut->offsetOfTransparentProxyRP = TransparentProxyObject::GetOffsetOfRP();
-    pEEInfoOut->offsetOfRealProxyServer    = RealProxyObject::GetOffsetOfServerObject();
+    pEEInfoOut->offsetOfTransparentProxyRP = (DWORD)-1;
+    pEEInfoOut->offsetOfRealProxyServer    = (DWORD)-1;
 
-    pEEInfoOut->offsetOfObjArrayData       = (DWORD)PtrArray::GetDataOffset();
+    pEEInfoOut->offsetOfObjArrayData       = OFFSETOF__PtrArray__m_Array_;
 
     pEEInfoOut->sizeOfReversePInvokeFrame  = (DWORD)-1;
 
index 184f636..29a53e1 100644 (file)
@@ -841,6 +841,8 @@ public:
     OBJECTREF    m_Array[1];
 };
 
+#define OFFSETOF__PtrArray__m_Array_              ARRAYBASE_SIZE
+
 /* a TypedByRef is a structure that is used to implement VB's BYREF variants.  
    it is basically a tuple of an address of some data along with a TypeHandle
    that indicates the type of the address */
@@ -2111,151 +2113,6 @@ typedef WeakReferenceObject* WEAKREFERENCEREF;
 STRINGREF AllocateString(SString sstr);
 CHARARRAYREF AllocateCharArray(DWORD dwArrayLength);
 
-
-class TransparentProxyObject : public Object
-{
-    friend class MscorlibBinder;
-    friend class CheckAsmOffsets;
-
-public:
-    MethodTable * GetMethodTableBeingProxied()
-    {
-        LIMITED_METHOD_CONTRACT;
-        return _pMT;
-    }
-    void SetMethodTableBeingProxied(MethodTable * pMT)
-    {
-        LIMITED_METHOD_CONTRACT;
-        _pMT = pMT;
-    }
-
-    MethodTable * GetInterfaceMethodTable()
-    {
-        LIMITED_METHOD_CONTRACT;
-        return _pInterfaceMT;
-    }
-    void SetInterfaceMethodTable(MethodTable * pInterfaceMT)
-    {
-        LIMITED_METHOD_CONTRACT;
-        _pInterfaceMT = pInterfaceMT;
-    }
-
-    void * GetStub()
-    {
-        LIMITED_METHOD_CONTRACT;
-        return _stub;
-    }
-    void SetStub(void * pStub)
-    {
-        LIMITED_METHOD_CONTRACT;
-        _stub = pStub;
-    }
-
-    OBJECTREF GetStubData()
-    {
-        LIMITED_METHOD_CONTRACT;
-        return _stubData;
-    }
-    void SetStubData(OBJECTREF stubData)
-    {
-        LIMITED_METHOD_CONTRACT;
-        SetObjectReference(&_stubData, stubData, GetAppDomain());
-    }
-
-    OBJECTREF GetRealProxy()
-    {
-        LIMITED_METHOD_CONTRACT;
-        return _rp;
-    }
-    void SetRealProxy(OBJECTREF realProxy)
-    {
-        LIMITED_METHOD_CONTRACT;
-        SetObjectReference(&_rp, realProxy, GetAppDomain());
-    }
-
-    static int GetOffsetOfRP() { LIMITED_METHOD_CONTRACT; return offsetof(TransparentProxyObject, _rp); }
-    
-protected:
-    TransparentProxyObject()
-    {LIMITED_METHOD_CONTRACT;}; // don't instantiate this class directly
-    ~TransparentProxyObject(){LIMITED_METHOD_CONTRACT;};
-
-private:
-    OBJECTREF       _rp;
-    OBJECTREF       _stubData;
-    MethodTable*    _pMT;
-    MethodTable*    _pInterfaceMT;
-    void*           _stub;
-};
-
-#ifdef USE_CHECKED_OBJECTREFS
-typedef REF<TransparentProxyObject> TRANSPARENTPROXYREF;
-#else
-typedef TransparentProxyObject*     TRANSPARENTPROXYREF;
-#endif
-
-
-class RealProxyObject : public Object
-{
-    friend class MscorlibBinder;
-
-public:
-    DWORD GetOptFlags()
-    {
-        LIMITED_METHOD_CONTRACT;
-        return _optFlags;
-    }
-    VOID SetOptFlags(DWORD flags)
-    {
-        LIMITED_METHOD_CONTRACT;
-        _optFlags = flags;
-    }
-
-    DWORD GetDomainID()
-    {
-        LIMITED_METHOD_CONTRACT;
-        return _domainID;
-    }
-
-    TRANSPARENTPROXYREF GetTransparentProxy()
-    {
-        LIMITED_METHOD_CONTRACT;
-        return (TRANSPARENTPROXYREF&)_tp;
-    }
-    void SetTransparentProxy(TRANSPARENTPROXYREF tp)
-    {
-        LIMITED_METHOD_CONTRACT;
-        SetObjectReference(&_tp, (OBJECTREF)tp, GetAppDomain());
-    }
-
-    static int GetOffsetOfIdentity() { LIMITED_METHOD_CONTRACT; return offsetof(RealProxyObject, _identity); }
-    static int GetOffsetOfServerObject() { LIMITED_METHOD_CONTRACT; return offsetof(RealProxyObject, _serverObject); }
-    static int GetOffsetOfServerIdentity() { LIMITED_METHOD_CONTRACT; return offsetof(RealProxyObject, _srvIdentity); }
-
-protected:
-    RealProxyObject()
-    {
-        LIMITED_METHOD_CONTRACT;
-    }; // don't instantiate this class directly
-    ~RealProxyObject(){ LIMITED_METHOD_CONTRACT; };
-
-private:
-    OBJECTREF       _tp;
-    OBJECTREF       _identity;
-    OBJECTREF       _serverObject;
-    DWORD           _flags;
-    DWORD           _optFlags;
-    DWORD           _domainID;
-    OBJECTHANDLE    _srvIdentity;
-};
-
-#ifdef USE_CHECKED_OBJECTREFS
-typedef REF<RealProxyObject> REALPROXYREF;
-#else
-typedef RealProxyObject*     REALPROXYREF;
-#endif
-
-
 #ifdef FEATURE_COMINTEROP
 
 //-------------------------------------------------------------
@@ -2715,6 +2572,10 @@ private:
     INT_PTR     _invocationCount;
 };
 
+#define OFFSETOF__DelegateObject__target          OBJECT_SIZE /* m_pMethTab */
+#define OFFSETOF__DelegateObject__methodPtr       (OFFSETOF__DelegateObject__target + TARGET_POINTER_SIZE /* _target */ + TARGET_POINTER_SIZE /* _methodBase */)
+#define OFFSETOF__DelegateObject__methodPtrAux    (OFFSETOF__DelegateObject__methodPtr + TARGET_POINTER_SIZE /* _methodPtr */)
+
 #ifdef USE_CHECKED_OBJECTREFS
 typedef REF<DelegateObject> DELEGATEREF;
 #else // USE_CHECKED_OBJECTREFS
index 50fbac0..b6da9c5 100644 (file)
@@ -79,7 +79,6 @@ class LoaderHeap;
 class IGCHeap;
 class Object;
 class StringObject;
-class TransparentProxyObject;
 class ArrayClass;
 class MethodTable;
 class MethodDesc;
@@ -158,7 +157,6 @@ class OBJECTREF {
         class ArrayBase* m_asArray;
         class PtrArray* m_asPtrArray;
         class DelegateObject* m_asDelegate;
-        class TransparentProxyObject* m_asTP;
 
         class ReflectClassBaseObject* m_asReflectClass;
         class ExecutionContextObject* m_asExecutionContext;