Index: trunk/src/VBox/VMM/VMMR0/PGMR0DynMap.cpp
===================================================================
--- trunk/src/VBox/VMM/VMMR0/PGMR0DynMap.cpp	(revision 18955)
+++ trunk/src/VBox/VMM/VMMR0/PGMR0DynMap.cpp	(revision 18974)
@@ -1185,8 +1185,5 @@
 static uint32_t pgmR0DynMapPageSlow(PPGMR0DYNMAP pThis, RTHCPHYS HCPhys, uint32_t iPage, PVM pVM)
 {
-#ifdef VBOX_WITH_STATISTICS
-    PVMCPU pVCpu = VMMGetCpu(pVM);
-#endif
-    STAM_COUNTER_INC(&pVCpu->pgm.s.StatR0DynMapPageSlow);
+    STAM_COUNTER_INC(&pVM->pgm.s.StatR0DynMapPageSlow);
 
     /*
@@ -1216,5 +1213,5 @@
             if (paPages[iFreePage].HCPhys == HCPhys)
             {
-                STAM_COUNTER_INC(&pVCpu->pgm.s.StatR0DynMapPageSlowLoopHits);
+                STAM_COUNTER_INC(&pVM->pgm.s.StatR0DynMapPageSlowLoopHits);
                 return iFreePage;
             }
@@ -1227,5 +1224,5 @@
                 return UINT32_MAX;
         }
-        STAM_COUNTER_INC(&pVCpu->pgm.s.StatR0DynMapPageSlowLoopMisses);
+        STAM_COUNTER_INC(&pVM->pgm.s.StatR0DynMapPageSlowLoopMisses);
 #ifdef VBOX_WITH_STATISTICS
         fLooped = true;
@@ -1239,5 +1236,5 @@
         for (uint32_t iPage2 = (iPage + 3) % cPages; iPage2 != iPage; iPage2 = (iPage2 + 1) % cPages)
             if (paPages[iPage2].HCPhys == HCPhys)
-                STAM_COUNTER_INC(&pVCpu->pgm.s.StatR0DynMapPageSlowLostHits);
+                STAM_COUNTER_INC(&pVM->pgm.s.StatR0DynMapPageSlowLostHits);
 #endif
 
@@ -1287,11 +1284,8 @@
 DECLINLINE(uint32_t) pgmR0DynMapPage(PPGMR0DYNMAP pThis, RTHCPHYS HCPhys, int32_t iRealCpu, PVM pVM, void **ppvPage)
 {
-#ifdef VBOX_WITH_STATISTICS
-    PVMCPU pVCpu = VMMGetCpu(pVM);
-#endif
     RTSPINLOCKTMP   Tmp       = RTSPINLOCKTMP_INITIALIZER;
     RTSpinlockAcquire(pThis->hSpinlock, &Tmp);
     AssertMsg(!(HCPhys & PAGE_OFFSET_MASK), ("HCPhys=%RHp\n", HCPhys));
-    STAM_COUNTER_INC(&pVCpu->pgm.s.StatR0DynMapPage);
+    STAM_COUNTER_INC(&pVM->pgm.s.StatR0DynMapPage);
 
     /*
@@ -1307,5 +1301,5 @@
     PPGMR0DYNMAPENTRY   paPages = pThis->paPages;
     if (RT_LIKELY(paPages[iPage].HCPhys == HCPhys))
-        STAM_COUNTER_INC(&pVCpu->pgm.s.StatR0DynMapPageHits0);
+        STAM_COUNTER_INC(&pVM->pgm.s.StatR0DynMapPageHits0);
     else
     {
@@ -1314,5 +1308,5 @@
         {
             iPage = iPage2;
-            STAM_COUNTER_INC(&pVCpu->pgm.s.StatR0DynMapPageHits1);
+            STAM_COUNTER_INC(&pVM->pgm.s.StatR0DynMapPageHits1);
         }
         else
@@ -1322,5 +1316,5 @@
             {
                 iPage = iPage2;
-                STAM_COUNTER_INC(&pVCpu->pgm.s.StatR0DynMapPageHits2);
+                STAM_COUNTER_INC(&pVM->pgm.s.StatR0DynMapPageHits2);
             }
             else
@@ -1371,5 +1365,5 @@
     if (RT_UNLIKELY(fInvalidateIt))
     {
-        STAM_COUNTER_INC(&pVCpu->pgm.s.StatR0DynMapPageInvlPg);
+        STAM_COUNTER_INC(&pVM->pgm.s.StatR0DynMapPageInvlPg);
         ASMInvalidatePage(pvPage);
     }
@@ -1505,12 +1499,12 @@
  * API is called.
  *
- * @param   pVCpu       The shared data for the current virtual CPU.
- */
-VMMDECL(void) PGMDynMapStartAutoSet(PVMCPU pVCpu)
-{
-    Assert(pVCpu->pgm.s.AutoSet.cEntries == PGMMAPSET_CLOSED);
-    Assert(pVCpu->pgm.s.AutoSet.iSubset == UINT32_MAX);
-    pVCpu->pgm.s.AutoSet.cEntries = 0;
-    pVCpu->pgm.s.AutoSet.iCpu = RTMpCpuIdToSetIndex(RTMpCpuId());
+ * @param   pVM         Pointer to the shared VM structure.
+ */
+VMMDECL(void) PGMDynMapStartAutoSet(PVM pVM)
+{
+    Assert(pVM->pgm.s.AutoSet.cEntries == PGMMAPSET_CLOSED);
+    Assert(pVM->pgm.s.AutoSet.iSubset == UINT32_MAX);
+    pVM->pgm.s.AutoSet.cEntries = 0;
+    pVM->pgm.s.AutoSet.iCpu = RTMpCpuIdToSetIndex(RTMpCpuId());
 }
 
@@ -1557,9 +1551,9 @@
  * since the PGMDynMapStartAutoSet call.
  *
- * @param   pVCpu       The shared data for the current virtual CPU.
- */
-VMMDECL(void) PGMDynMapReleaseAutoSet(PVMCPU pVCpu)
-{
-    PPGMMAPSET  pSet = &pVCpu->pgm.s.AutoSet;
+ * @param   pVM         Pointer to the shared VM structure.
+ */
+VMMDECL(void) PGMDynMapReleaseAutoSet(PVM pVM)
+{
+    PPGMMAPSET  pSet = &pVM->pgm.s.AutoSet;
 
     /*
@@ -1572,5 +1566,5 @@
     pSet->iCpu = -1;
 
-    STAM_COUNTER_INC(&pVCpu->pgm.s.aStatR0DynMapSetSize[(cEntries * 10 / RT_ELEMENTS(pSet->aEntries)) % 11]);
+    STAM_COUNTER_INC(&pVM->pgm.s.aStatR0DynMapSetSize[(cEntries * 10 / RT_ELEMENTS(pSet->aEntries)) % 11]);
     AssertMsg(cEntries < PGMMAPSET_MAX_FILL, ("%u\n", cEntries));
     if (cEntries > RT_ELEMENTS(pSet->aEntries) * 50 / 100)
@@ -1584,9 +1578,9 @@
  * Flushes the set if it's above a certain threshold.
  *
- * @param   pVCpu       The shared data for the current virtual CPU.
- */
-VMMDECL(void) PGMDynMapFlushAutoSet(PVMCPU pVCpu)
-{
-    PPGMMAPSET  pSet = &pVCpu->pgm.s.AutoSet;
+ * @param   pVM         Pointer to the shared VM structure.
+ */
+VMMDECL(void) PGMDynMapFlushAutoSet(PVM pVM)
+{
+    PPGMMAPSET  pSet = &pVM->pgm.s.AutoSet;
     AssertMsg(pSet->iCpu == RTMpCpuIdToSetIndex(RTMpCpuId()), ("%d %d(%d) efl=%#x\n", pSet->iCpu, RTMpCpuIdToSetIndex(RTMpCpuId()), RTMpCpuId(), ASMGetFlags()));
 
@@ -1596,5 +1590,5 @@
     uint32_t cEntries = pSet->cEntries;
     AssertReturnVoid(cEntries != PGMMAPSET_CLOSED);
-    STAM_COUNTER_INC(&pVCpu->pgm.s.aStatR0DynMapSetSize[(cEntries * 10 / RT_ELEMENTS(pSet->aEntries)) % 11]);
+    STAM_COUNTER_INC(&pVM->pgm.s.aStatR0DynMapSetSize[(cEntries * 10 / RT_ELEMENTS(pSet->aEntries)) % 11]);
     if (cEntries >= RT_ELEMENTS(pSet->aEntries) * 45 / 100)
     {
@@ -1620,10 +1614,10 @@
  * the entries will have been flagged as invalidated.
  *
- * @param   pVCpu       The shared data for the current virtual CPU.
+ * @param   pVM         Pointer to the shared VM structure.
  * @thread  EMT
  */
-VMMDECL(void) PGMDynMapMigrateAutoSet(PVMCPU pVCpu)
-{
-    PPGMMAPSET      pSet     = &pVCpu->pgm.s.AutoSet;
+VMMDECL(void) PGMDynMapMigrateAutoSet(PVM pVM)
+{
+    PPGMMAPSET      pSet     = &pVM->pgm.s.AutoSet;
     int32_t         iRealCpu = RTMpCpuIdToSetIndex(RTMpCpuId());
     if (pSet->iCpu != iRealCpu)
@@ -1650,5 +1644,5 @@
 
                         ASMInvalidatePage(pThis->paPages[iPage].pvPage);
-                        STAM_COUNTER_INC(&pVCpu->pgm.s.StatR0DynMapMigrateInvlPg);
+                        STAM_COUNTER_INC(&pVM->pgm.s.StatR0DynMapMigrateInvlPg);
 
                         RTSpinlockAcquire(pThis->hSpinlock, &Tmp);
@@ -1718,14 +1712,14 @@
  * @returns The index of the previous subset. Pass this to
  *        PGMDynMapPopAutoSubset when poping it.
- * @param   pVCpu           Pointer to the virtual cpu data.
- */
-VMMDECL(uint32_t) PGMDynMapPushAutoSubset(PVMCPU pVCpu)
-{
-    PPGMMAPSET      pSet = &pVCpu->pgm.s.AutoSet;
+ * @param   pVM             Pointer to the shared VM structure.
+ */
+VMMDECL(uint32_t) PGMDynMapPushAutoSubset(PVM pVM)
+{
+    PPGMMAPSET      pSet = &pVM->pgm.s.AutoSet;
     AssertReturn(pSet->cEntries != PGMMAPSET_CLOSED, UINT32_MAX);
     uint32_t        iPrevSubset = pSet->iSubset;
 Assert(iPrevSubset == UINT32_MAX);
     pSet->iSubset = pSet->cEntries;
-    STAM_COUNTER_INC(&pVCpu->pgm.s.StatR0DynMapSubsets);
+    STAM_COUNTER_INC(&pVM->pgm.s.StatR0DynMapSubsets);
     return iPrevSubset;
 }
@@ -1735,15 +1729,15 @@
  * Pops a subset created by a previous call to PGMDynMapPushAutoSubset.
  *
- * @param   pVCpu           Pointer to the virtual cpu data.
+ * @param   pVM             Pointer to the shared VM structure.
  * @param   iPrevSubset     What PGMDynMapPushAutoSubset returned.
  */
-VMMDECL(void) PGMDynMapPopAutoSubset(PVMCPU pVCpu, uint32_t iPrevSubset)
-{
-    PPGMMAPSET      pSet = &pVCpu->pgm.s.AutoSet;
+VMMDECL(void) PGMDynMapPopAutoSubset(PVM pVM, uint32_t iPrevSubset)
+{
+    PPGMMAPSET      pSet = &pVM->pgm.s.AutoSet;
     uint32_t        cEntries = pSet->cEntries;
     AssertReturnVoid(cEntries != PGMMAPSET_CLOSED);
     AssertReturnVoid(pSet->iSubset <= iPrevSubset || iPrevSubset == UINT32_MAX);
 Assert(iPrevSubset == UINT32_MAX);
-    STAM_COUNTER_INC(&pVCpu->pgm.s.aStatR0DynMapSetSize[(cEntries * 10 / RT_ELEMENTS(pSet->aEntries)) % 11]);
+    STAM_COUNTER_INC(&pVM->pgm.s.aStatR0DynMapSetSize[(cEntries * 10 / RT_ELEMENTS(pSet->aEntries)) % 11]);
     if (    cEntries >= RT_ELEMENTS(pSet->aEntries) * 40 / 100
         &&  cEntries != pSet->iSubset)
@@ -1816,7 +1810,4 @@
 int pgmR0DynMapHCPageCommon(PVM pVM, PPGMMAPSET pSet, RTHCPHYS HCPhys, void **ppv)
 {
-#ifdef VBOX_WITH_STATISTICS
-    PVMCPU pVCpu = VMMGetCpu(pVM);
-#endif
     AssertMsg(pSet->iCpu == RTMpCpuIdToSetIndex(RTMpCpuId()), ("%d %d(%d) efl=%#x\n", pSet->iCpu, RTMpCpuIdToSetIndex(RTMpCpuId()), RTMpCpuId(), ASMGetFlags()));
 
@@ -1891,14 +1882,14 @@
             {
                 pSet->aEntries[i].cRefs++;
-                STAM_COUNTER_INC(&pVCpu->pgm.s.StatR0DynMapSetSearchHits);
+                STAM_COUNTER_INC(&pVM->pgm.s.StatR0DynMapSetSearchHits);
                 break;
             }
         if (i < 0)
         {
-            STAM_COUNTER_INC(&pVCpu->pgm.s.StatR0DynMapSetSearchMisses);
+            STAM_COUNTER_INC(&pVM->pgm.s.StatR0DynMapSetSearchMisses);
             if (pSet->iSubset < pSet->cEntries)
             {
-                STAM_COUNTER_INC(&pVCpu->pgm.s.StatR0DynMapSetSearchFlushes);
-                STAM_COUNTER_INC(&pVCpu->pgm.s.aStatR0DynMapSetSize[(pSet->cEntries * 10 / RT_ELEMENTS(pSet->aEntries)) % 11]);
+                STAM_COUNTER_INC(&pVM->pgm.s.StatR0DynMapSetSearchFlushes);
+                STAM_COUNTER_INC(&pVM->pgm.s.aStatR0DynMapSetSize[(pSet->cEntries * 10 / RT_ELEMENTS(pSet->aEntries)) % 11]);
                 AssertMsg(pSet->cEntries < PGMMAPSET_MAX_FILL, ("%u\n", pSet->cEntries));
                 pgmDynMapFlushSubset(pSet);
@@ -1907,5 +1898,5 @@
             if (RT_UNLIKELY(pSet->cEntries >= RT_ELEMENTS(pSet->aEntries)))
             {
-                STAM_COUNTER_INC(&pVCpu->pgm.s.StatR0DynMapSetOptimize);
+                STAM_COUNTER_INC(&pVM->pgm.s.StatR0DynMapSetOptimize);
                 pgmDynMapOptimizeAutoSet(pSet);
             }
@@ -1943,18 +1934,13 @@
 VMMDECL(int) PGMDynMapHCPage(PVM pVM, RTHCPHYS HCPhys, void **ppv)
 {
-#ifdef VBOX_WITH_STATISTICS
-    PVMCPU pVCpu = VMMGetCpu(pVM);
-#endif
     /*
      * Validate state.
      */
-    STAM_PROFILE_START(&pVCpu->pgm.s.StatR0DynMapHCPage, a);
+    STAM_PROFILE_START(&pVM->pgm.s.StatR0DynMapHCPage, a);
     AssertPtr(ppv);
     AssertMsg(pVM->pgm.s.pvR0DynMapUsed == g_pPGMR0DynMap,
               ("%p != %p\n", pVM->pgm.s.pvR0DynMapUsed, g_pPGMR0DynMap));
     AssertMsg(!(HCPhys & PAGE_OFFSET_MASK), ("HCPhys=%RHp\n", HCPhys));
-    PVMCPU          pVCpu   = VMMGetCpu(pVM);
-    AssertPtr(pVCpu);
-    PPGMMAPSET      pSet    = &pVCpu->pgm.s.AutoSet;
+    PPGMMAPSET      pSet    = &pVM->pgm.s.AutoSet;
     AssertMsg(pSet->cEntries <= RT_ELEMENTS(pSet->aEntries),
               ("%#x (%u)\n", pSet->cEntries, pSet->cEntries));
@@ -1965,5 +1951,5 @@
     int rc = pgmR0DynMapHCPageCommon(pVM, pSet, HCPhys, ppv);
 
-    STAM_PROFILE_STOP(&pVCpu->pgm.s.StatR0DynMapHCPage, a);
+    STAM_PROFILE_STOP(&pVM->pgm.s.StatR0DynMapHCPage, a);
     return rc;
 }
