Source Code for Me (s-c.me)

Allows you to paste souce code to blogs! Adapted for Twitter! Here is Search Form in case you missed your code.
Code:
Selected Language:
Show Linenumbers:
Short link for Twitter:
HTML:

HTML view:

Copy Source | Copy HTML
  1. /****************************************************************************/
  2. /* assigns 'val to 'array[idx], after doing all the proper checks */
  3.  
  4. HCIMPL3(void, JIT_Stelem_Ref_Portable, PtrArray* array, unsigned idx, Object *val)
  5. {
  6.     if (!array)
  7.     {
  8.         FCThrowVoid(kNullReferenceException);
  9.     }
  10.     if (idx >= array->GetNumComponents())
  11.     {
  12.         FCThrowVoid(kIndexOutOfRangeException);
  13.     }
  14.  
  15.     if (val)
  16.     {
  17.         MethodTable *valMT = val->GetMethodTable();
  18.         TypeHandle arrayElemTH = array->GetArrayElementTypeHandle();
  19.  
  20.         if (arrayElemTH != TypeHandle(valMT) && arrayElemTH != TypeHandle(g_pObjectClass))
  21.         {
  22.             TypeHandle::CastResult result = ObjIsInstanceOfNoGC(val, arrayElemTH);
  23.             if (result != TypeHandle::CanCast)
  24.             {
  25.                 HELPER_METHOD_FRAME_BEGIN_2(val, array);
  26.  
  27.                 // This is equivalent to ArrayStoreCheck(&val, &array);
  28. #ifdef STRESS_HEAP
  29.                 // Force a GC on every jit if the stress level is high enough
  30.                 if (g_pConfig->GetGCStressLevel() !=  0
  31. #ifdef _DEBUG
  32.                     && !g_pConfig->FastGCStressLevel()
  33. #endif
  34.                    )
  35.                     GCHeap::GetGCHeap()->StressHeap();
  36. #endif
  37.  
  38. #if CHECK_APP_DOMAIN_LEAKS
  39.                 // If the instance is agile or check agile
  40.                 if (!arrayElemTH.IsAppDomainAgile() && !arrayElemTH.IsCheckAppDomainAgile() && g_pConfig->AppDomainLeaks())
  41.                 {
  42.                     val->AssignAppDomain(array->GetAppDomain());
  43.                 }
  44. #endif
  45.                 if (!ObjIsInstanceOf(val, arrayElemTH))
  46.                 {
  47.                     COMPlusThrow(kArrayTypeMismatchException);
  48.                 }
  49.  
  50.                 HELPER_METHOD_FRAME_END();
  51.             }
  52.         }
  53.  
  54.         // The performance gain of the optimized JIT_Stelem_Ref in
  55.         // jitinterfacex86.cpp is mainly due to calling JIT_WriteBarrierReg_Buf.
  56.         // By calling write barrier directly here,
  57.         // we can avoid translating in-line assembly from MSVC to gcc
  58.         // while keeping most of the performance gain.
  59.         HCCALL2(JIT_WriteBarrier, (Object **)&array->m_Array[idx], val);
  60.  
  61.     }
  62.     else
  63.     {
  64.         // no need to go through write-barrier for NULL
  65.         ClearObjectReference(&array->m_Array[idx]);
  66.     }
  67. }
  68. HCIMPLEND




Based on Manoli.Net's CodeFormatter. Made by Topbot (c) 2008-2012