Encapsulate or replace references to CORINFO_PAGE_SIZE.
authorPat Gavlin <pagavlin@microsoft.com>
Mon, 16 May 2016 21:05:17 +0000 (14:05 -0700)
committerPat Gavlin <pagavlin@microsoft.com>
Tue, 17 May 2016 19:00:38 +0000 (12:00 -0700)
This symbol will be replaced with a new field in CORINFO_EE_INFO as part of dotnet/coreclr#4912.
These changes prepare the JIT and EE for that change by (respectively) encapsulating
references to CORINFO_PAGE_SIZE in Compiler::eeGetPageSize and replacing
CORINFO_PAGE_SIZE with OS_PAGE_SIZE.

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

src/coreclr/src/jit/codegenarm64.cpp
src/coreclr/src/jit/codegencommon.cpp
src/coreclr/src/jit/codegenlegacy.cpp
src/coreclr/src/jit/codegenxarch.cpp
src/coreclr/src/jit/compiler.h
src/coreclr/src/jit/lowerarm64.cpp
src/coreclr/src/jit/lowerxarch.cpp
src/coreclr/src/vm/eetwain.cpp

index 8b78390..574e438 100644 (file)
@@ -3523,7 +3523,7 @@ CodeGen::genLclHeap(GenTreePtr tree)
             
             goto ALLOC_DONE;
         }
-        else if (!compiler->info.compInitMem && (amount < CORINFO_PAGE_SIZE))  // must be < not <=
+        else if (!compiler->info.compInitMem && (amount < compiler->eeGetPageSize()))  // must be < not <=
         {               
             // Since the size is a page or less, simply adjust the SP value              
             // The SP might already be in the guard page, must touch it BEFORE
@@ -3636,7 +3636,7 @@ CodeGen::genLclHeap(GenTreePtr tree)
         getEmitter()->emitIns_R_R_I(INS_ldr, EA_4BYTE, REG_ZR, REG_SPBASE, 0);
 
         // decrement SP by PAGE_SIZE
-        getEmitter()->emitIns_R_R_I(INS_sub, EA_PTRSIZE, regTmp, REG_SPBASE, CORINFO_PAGE_SIZE);
+        getEmitter()->emitIns_R_R_I(INS_sub, EA_PTRSIZE, regTmp, REG_SPBASE, compiler->eeGetPageSize());
 
         getEmitter()->emitIns_R_R(INS_cmp, EA_PTRSIZE, regTmp, regCnt);
         emitJumpKind jmpLTU = genJumpKindForOper(GT_LT, CK_UNSIGNED);
index 7a9b9f9..0ce079c 100644 (file)
@@ -5648,6 +5648,8 @@ void CodeGen::genAllocLclFrame(unsigned  frameSize,
     if  (frameSize == 0)
         return;
 
+    const size_t pageSize = compiler->eeGetPageSize();
+
 #ifdef _TARGET_ARM_
     assert(!compiler->info.compPublishStubParam || (REG_SECRET_STUB_PARAM != initReg));
 #endif // _TARGET_ARM_
@@ -5660,36 +5662,36 @@ void CodeGen::genAllocLclFrame(unsigned  frameSize,
     }
     else 
 #endif // _TARGET_XARCH_
-    if (frameSize < CORINFO_PAGE_SIZE)
+    if (frameSize < pageSize)
     {
 #ifndef _TARGET_ARM64_
         // Frame size is (0x0008..0x1000)
         inst_RV_IV(INS_sub, REG_SPBASE, frameSize, EA_PTRSIZE);
 #endif // !_TARGET_ARM64_
     }
-    else if (frameSize < VERY_LARGE_FRAME_SIZE)
+    else if (frameSize < compiler->getVeryLargeFrameSize())
     {
         // Frame size is (0x1000..0x3000)
 
 #if CPU_LOAD_STORE_ARCH
-        instGen_Set_Reg_To_Imm(EA_PTRSIZE, initReg, -CORINFO_PAGE_SIZE);
+        instGen_Set_Reg_To_Imm(EA_PTRSIZE, initReg, -(ssize_t)pageSize);
         getEmitter()->emitIns_R_R_R(INS_ldr, EA_4BYTE, initReg, REG_SPBASE, initReg);
         regTracker.rsTrackRegTrash(initReg);
         *pInitRegZeroed = false;  // The initReg does not contain zero
 #else
         getEmitter()->emitIns_AR_R(INS_TEST, EA_PTRSIZE,
-                                  REG_EAX, REG_SPBASE, -CORINFO_PAGE_SIZE);
+                                  REG_EAX, REG_SPBASE, -(int)pageSize);
 #endif
 
         if (frameSize >= 0x2000)
         {    
 #if CPU_LOAD_STORE_ARCH
-            instGen_Set_Reg_To_Imm(EA_PTRSIZE, initReg, -2 * CORINFO_PAGE_SIZE);
+            instGen_Set_Reg_To_Imm(EA_PTRSIZE, initReg, -2 * (ssize_t)pageSize);
             getEmitter()->emitIns_R_R_R(INS_ldr, EA_4BYTE, initReg, REG_SPBASE, initReg);
             regTracker.rsTrackRegTrash(initReg);
 #else
             getEmitter()->emitIns_AR_R(INS_TEST, EA_PTRSIZE,
-                                  REG_EAX, REG_SPBASE, -2 * CORINFO_PAGE_SIZE);
+                                  REG_EAX, REG_SPBASE, -2 * (int)pageSize);
 #endif
         }
 
@@ -5709,7 +5711,7 @@ void CodeGen::genAllocLclFrame(unsigned  frameSize,
     else
     {
         // Frame size >= 0x3000
-        assert(frameSize >= VERY_LARGE_FRAME_SIZE);
+        assert(frameSize >= compiler->getVeryLargeFrameSize());
 
         // Emit the following sequence to 'tickle' the pages.
         // Note it is important that stack pointer not change until this is
@@ -5772,9 +5774,9 @@ void CodeGen::genAllocLclFrame(unsigned  frameSize,
         getEmitter()->emitIns_R_R_R(INS_ldr, EA_4BYTE, rTemp, REG_SPBASE, rOffset);
         regTracker.rsTrackRegTrash(rTemp);
 #if defined(_TARGET_ARM_)
-        getEmitter()->emitIns_R_I(INS_sub, EA_PTRSIZE, rOffset, CORINFO_PAGE_SIZE);
+        getEmitter()->emitIns_R_I(INS_sub, EA_PTRSIZE, rOffset, pageSize);
 #elif defined(_TARGET_ARM64_)
-        getEmitter()->emitIns_R_R_I(INS_sub, EA_PTRSIZE, rOffset, rOffset, CORINFO_PAGE_SIZE);
+        getEmitter()->emitIns_R_R_I(INS_sub, EA_PTRSIZE, rOffset, rOffset, pageSize);
 #endif // _TARGET_ARM64_
         getEmitter()->emitIns_R_R(INS_cmp, EA_PTRSIZE, rOffset, rLimit);
         getEmitter()->emitIns_J(INS_bhi, NULL, -4);
@@ -5806,7 +5808,7 @@ void CodeGen::genAllocLclFrame(unsigned  frameSize,
         //      jge loop                    2
 
         getEmitter()->emitIns_R_ARR(INS_TEST, EA_PTRSIZE, initReg, REG_SPBASE, initReg, 0);
-        inst_RV_IV(INS_sub,  initReg, CORINFO_PAGE_SIZE, EA_PTRSIZE);
+        inst_RV_IV(INS_sub,  initReg, pageSize, EA_PTRSIZE);
         inst_RV_IV(INS_cmp,  initReg, -((ssize_t)frameSize), EA_PTRSIZE);
 
         int bytesForBackwardJump;
@@ -7712,7 +7714,7 @@ void                CodeGen::genFinalizeFrame()
 #if defined(_TARGET_ARMARCH_)
     // We need to determine if we will change SP larger than a specific amount to determine if we want to use a loop
     // to touch stack pages, that will require multiple registers. See genAllocLclFrame() for details.
-    if (compiler->compLclFrameSize >= VERY_LARGE_FRAME_SIZE)
+    if (compiler->compLclFrameSize >= compiler->getVeryLargeFrameSize())
     {
         regSet.rsSetRegsModified(VERY_LARGE_FRAME_SIZE_REG_MASK);
     }
@@ -8216,7 +8218,7 @@ void                CodeGen::genFnProlog()
 #endif // _TARGET_ARM_
 
 #if defined(_TARGET_XARCH_)
-    if (compiler->compLclFrameSize >= VERY_LARGE_FRAME_SIZE)
+    if (compiler->compLclFrameSize >= compiler->getVeryLargeFrameSize())
     {
         // We currently must use REG_EAX on x86 here
         // because the loop's backwards branch depends upon the size of EAX encodings
@@ -10166,7 +10168,7 @@ void CodeGen::genGenerateStackProbe()
     // of bytes, to set up a frame in the unmanaged code..
 
     static_assert_no_msg(
-        CORINFO_STACKPROBE_DEPTH + JIT_RESERVED_STACK < CORINFO_PAGE_SIZE);
+        CORINFO_STACKPROBE_DEPTH + JIT_RESERVED_STACK < compiler->eeGetPageSize());
 
     JITDUMP("Emitting stack probe:\n");
     getEmitter()->emitIns_AR_R(INS_TEST, EA_PTRSIZE,
index 93a1956..248ed5b 100644 (file)
@@ -21064,7 +21064,7 @@ regNumber           CodeGen::genLclHeap(GenTreePtr size)
                 // Re-bias amount to be number of bytes to adjust the SP 
                 amount <<= STACK_ALIGN_SHIFT;
                 size->gtIntCon.gtIconVal = amount;  // update the GT_CNS value in the node
-                if (amount < CORINFO_PAGE_SIZE)   // must be < not <=
+                if (amount < compiler->eeGetPageSize())   // must be < not <=
                 {
                     // Since the size is a page or less, simply adjust ESP 
                     
@@ -21249,7 +21249,7 @@ regNumber           CodeGen::genLclHeap(GenTreePtr size)
         inst_RV_RV(INS_mov, regTemp, REG_SPBASE, TYP_I_IMPL);
         regTracker.rsTrackRegTrash(regTemp);
 
-        inst_RV_IV(INS_sub, regTemp, CORINFO_PAGE_SIZE, EA_PTRSIZE);
+        inst_RV_IV(INS_sub, regTemp, compiler->eeGetPageSize(), EA_PTRSIZE);
         inst_RV_RV(INS_mov, REG_SPBASE, regTemp, TYP_I_IMPL);
 
         genRecoverReg(size, RBM_ALLINT, RegSet::KEEP_REG); // not purely the 'size' tree anymore; though it is derived from 'size'
index 506e1e6..b35268e 100644 (file)
@@ -3008,7 +3008,7 @@ CodeGen::genLclHeap(GenTreePtr tree)
             
             goto ALLOC_DONE;
         }
-        else if (!compiler->info.compInitMem && (amount < CORINFO_PAGE_SIZE))  // must be < not <=
+        else if (!compiler->info.compInitMem && (amount < compiler->eeGetPageSize()))  // must be < not <=
         {               
             // Since the size is less than a page, simply adjust ESP.
             // ESP might already be in the guard page, so we must touch it BEFORE
@@ -3118,7 +3118,7 @@ CodeGen::genLclHeap(GenTreePtr tree)
         regNumber regTmp = genRegNumFromMask(tmpRegsMask);
 
         inst_RV_RV(INS_mov, regTmp, REG_SPBASE, TYP_I_IMPL);
-        inst_RV_IV(INS_sub, regTmp, CORINFO_PAGE_SIZE, EA_PTRSIZE);
+        inst_RV_IV(INS_sub, regTmp, compiler->eeGetPageSize(), EA_PTRSIZE);
         inst_RV_RV(INS_mov, REG_SPBASE, regTmp, TYP_I_IMPL);
 
         inst_RV_RV(INS_cmp, REG_SPBASE, regCnt, TYP_I_IMPL);
index 4c3c548..a3f1279 100644 (file)
@@ -6361,6 +6361,25 @@ public :
 
     GenTreePtr                  eeGetPInvokeCookie(CORINFO_SIG_INFO *szMetaSig);
 
+    // Returns the page size for the target machine as reported by the EE.
+    inline size_t               eeGetPageSize() const
+    {
+        return CORINFO_PAGE_SIZE;
+    }
+
+    // Returns the frame size at which we will generate a loop to probe the stack.
+    inline size_t               getVeryLargeFrameSize() const
+    {
+#ifdef _TARGET_ARM_
+        // The looping probe code is 40 bytes, whereas the straight-line probing for
+        // the (0x2000..0x3000) case is 44, so use looping for anything 0x2000 bytes
+        // or greater, to generate smaller code.
+        return 2 * eeGetPageSize();
+#else
+        return 3 * eeGetPageSize();
+#endif
+    }
+
     // Exceptions
 
     unsigned                    eeGetEHcount        (CORINFO_METHOD_HANDLE handle);
@@ -9101,18 +9120,8 @@ extern const BYTE          genActualTypes[];
 
 /*****************************************************************************/
 
-// Define the frame size at which we will generate a loop to probe the stack.
-// VERY_LARGE_FRAME_SIZE_REG_MASK is the set of registers we need to use for the probing loop.
-
-#ifdef _TARGET_ARM_
-// The looping probe code is 40 bytes, whereas the straight-line probing for
-// the (0x2000..0x3000) case is 44, so use looping for anything 0x2000 bytes
-// or greater, to generate smaller code.
-
-#define VERY_LARGE_FRAME_SIZE           (2 * CORINFO_PAGE_SIZE)
-#else
-#define VERY_LARGE_FRAME_SIZE           (3 * CORINFO_PAGE_SIZE)
-#endif
+// VERY_LARGE_FRAME_SIZE_REG_MASK is the set of registers we need to use for
+// the probing loop generated for very large stack frames (see `getVeryLargeFrameSize`).
 
 #ifdef _TARGET_ARM_
 #define VERY_LARGE_FRAME_SIZE_REG_MASK  (RBM_R4 | RBM_R5 | RBM_R6)
index b3475cd..c58d4f1 100644 (file)
@@ -815,7 +815,7 @@ void Lowering::TreeNodeInfoInit(GenTree* stmt)
                         else if (!compiler->info.compInitMem)
                         {
                             // No need to initialize allocated stack space.
-                            if (sizeVal < CORINFO_PAGE_SIZE)
+                            if (sizeVal < compiler->eeGetPageSize())
                             {
                                 info->internalIntCount = 0;
                             }
index e311ddd..354dc98 100644 (file)
@@ -1399,7 +1399,7 @@ void Lowering::TreeNodeInfoInit(GenTree* stmt)
                     else if (!compiler->info.compInitMem)
                     {
                         // No need to initialize allocated stack space.
-                        if (sizeVal < CORINFO_PAGE_SIZE)
+                        if (sizeVal < compiler->eeGetPageSize())
                         {
                             info->internalIntCount = 0;
                         }
index 28bd1ce..69eb177 100644 (file)
@@ -3002,12 +3002,12 @@ unsigned SKIP_ALLOC_FRAME(int size, PTR_CBYTE base, unsigned offset)
         return (SKIP_PUSH_REG(base, offset));
     }
 
-    if (size >= CORINFO_PAGE_SIZE)
+    if (size >= OS_PAGE_SIZE)
     {
-        if (size < (3 * CORINFO_PAGE_SIZE))
+        if (size < (3 * OS_PAGE_SIZE))
         {
-            // add 7 bytes for one or two TEST EAX, [ESP+CORINFO_PAGE_SIZE]
-            offset += (size / CORINFO_PAGE_SIZE) * 7;
+            // add 7 bytes for one or two TEST EAX, [ESP+OS_PAGE_SIZE]
+            offset += (size / OS_PAGE_SIZE) * 7;
         }
         else
         {