VirtualBox

Changeset 12792 in vbox for trunk/src/VBox/VMM/VMMAll


Ignore:
Timestamp:
Sep 29, 2008 12:14:42 PM (16 years ago)
Author:
vboxsync
Message:

#1865: some MM stuff.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/VMMAll/MMAllHyper.cpp

    r11311 r12792  
    4848#define ASSERT_OFFPREV(pHeap, pChunk)  \
    4949    do { Assert(MMHYPERCHUNK_GET_OFFPREV(pChunk) <= 0); \
    50          Assert(MMHYPERCHUNK_GET_OFFPREV(pChunk) >= (intptr_t)CTXSUFF((pHeap)->pbHeap) - (intptr_t)(pChunk)); \
     50         Assert(MMHYPERCHUNK_GET_OFFPREV(pChunk) >= (intptr_t)(pHeap)->CTX_SUFF(pbHeap) - (intptr_t)(pChunk)); \
    5151         AssertMsg(     MMHYPERCHUNK_GET_OFFPREV(pChunk) != 0 \
    52                    ||   (uint8_t *)(pChunk) == CTXSUFF((pHeap)->pbHeap), \
    53                    ("pChunk=%p pvHyperHeap=%p\n", (pChunk), CTXSUFF((pHeap)->pbHeap))); \
     52                   ||   (uint8_t *)(pChunk) == (pHeap)->CTX_SUFF(pbHeap), \
     53                   ("pChunk=%p pvHyperHeap=%p\n", (pChunk), (pHeap)->CTX_SUFF(pbHeap))); \
    5454    } while (0)
    5555
    5656#define ASSERT_OFFNEXT(pHeap, pChunk) \
    5757    do { ASSERT_ALIGN((pChunk)->offNext); \
    58          ASSERT_L((pChunk)->offNext, (uintptr_t)CTXSUFF((pHeap)->pbHeap) + (pHeap)->offPageAligned - (uintptr_t)(pChunk)); \
     58         ASSERT_L((pChunk)->offNext, (uintptr_t)(pHeap)->CTX_SUFF(pbHeap) + (pHeap)->offPageAligned - (uintptr_t)(pChunk)); \
    5959    } while (0)
    6060
     
    7575             AssertMsg(!((pChunk)->offStat & (MMHYPER_HEAP_ALIGN_MIN - 1)), ("offStat=%RX32\n", (pChunk)->offStat)); \
    7676             uintptr_t uPtr = (uintptr_t)(pChunk)->offStat + (uintptr_t)pChunk; NOREF(uPtr); \
    77              AssertMsg(uPtr - (uintptr_t)CTXSUFF((pHeap)->pbHeap) < (pHeap)->offPageAligned, \
    78                        ("%p - %p < %RX32\n", uPtr, CTXSUFF((pHeap)->pbHeap), (pHeap)->offPageAligned)); \
     77             AssertMsg(uPtr - (uintptr_t)(pHeap)->CTX_SUFF(pbHeap) < (pHeap)->offPageAligned, \
     78                       ("%p - %p < %RX32\n", uPtr, (pHeap)->CTX_SUFF(pbHeap), (pHeap)->offPageAligned)); \
    7979         } \
    8080    } while (0)
     
    9999#define ASSERT_FREE_OFFPREV(pHeap, pChunk)  \
    100100    do { ASSERT_ALIGN((pChunk)->offPrev); \
    101          ASSERT_GE(((pChunk)->offPrev  & (MMHYPER_HEAP_ALIGN_MIN - 1)), (intptr_t)CTXSUFF((pHeap)->pbHeap) - (intptr_t)(pChunk)); \
     101         ASSERT_GE(((pChunk)->offPrev  & (MMHYPER_HEAP_ALIGN_MIN - 1)), (intptr_t)(pHeap)->CTX_SUFF(pbHeap) - (intptr_t)(pChunk)); \
    102102         Assert((pChunk)->offPrev != MMHYPERCHUNK_GET_OFFPREV(&(pChunk)->core) || !(pChunk)->offPrev); \
    103103         AssertMsg(    (pChunk)->offPrev \
    104                   ||   (uintptr_t)(pChunk) - (uintptr_t)CTXSUFF((pHeap)->pbHeap) == (pHeap)->offFreeHead, \
    105                   ("pChunk=%p offChunk=%#x offFreeHead=%#x\n", (pChunk), (uintptr_t)(pChunk) - (uintptr_t)CTXSUFF((pHeap)->pbHeap),\
     104                  ||   (uintptr_t)(pChunk) - (uintptr_t)(pHeap)->CTX_SUFF(pbHeap) == (pHeap)->offFreeHead, \
     105                  ("pChunk=%p offChunk=%#x offFreeHead=%#x\n", (pChunk), (uintptr_t)(pChunk) - (uintptr_t)(pHeap)->CTX_SUFF(pbHeap),\
    106106                  (pHeap)->offFreeHead)); \
    107107    } while (0)
     
    109109#define ASSERT_FREE_OFFNEXT(pHeap, pChunk) \
    110110    do { ASSERT_ALIGN((pChunk)->offNext); \
    111          ASSERT_L((pChunk)->offNext, (uintptr_t)CTXSUFF((pHeap)->pbHeap) + (pHeap)->offPageAligned - (uintptr_t)(pChunk)); \
     111         ASSERT_L((pChunk)->offNext, (uintptr_t)(pHeap)->CTX_SUFF(pbHeap) + (pHeap)->offPageAligned - (uintptr_t)(pChunk)); \
    112112         Assert((pChunk)->offNext != (pChunk)->core.offNext || !(pChunk)->offNext); \
    113113         AssertMsg(     (pChunk)->offNext \
    114                    ||   (uintptr_t)(pChunk) - (uintptr_t)CTXSUFF((pHeap)->pbHeap) == (pHeap)->offFreeTail, \
    115                    ("pChunk=%p offChunk=%#x offFreeTail=%#x\n", (pChunk),  (uintptr_t)(pChunk) - (uintptr_t)CTXSUFF((pHeap)->pbHeap), \
     114                   ||   (uintptr_t)(pChunk) - (uintptr_t)(pHeap)->CTX_SUFF(pbHeap) == (pHeap)->offFreeTail, \
     115                   ("pChunk=%p offChunk=%#x offFreeTail=%#x\n", (pChunk),  (uintptr_t)(pChunk) - (uintptr_t)(pHeap)->CTX_SUFF(pbHeap), \
    116116                    (pHeap)->offFreeTail)); \
    117117    } while (0)
     
    124124                       ("cb=%d offNext=%d\n", (pChunk)->cb, (pChunk)->core.offNext)); \
    125125         else \
    126              ASSERT_LE((pChunk)->cb, (uintptr_t)CTXSUFF((pHeap)->pbHeap) + (pHeap)->offPageAligned - (uintptr_t)(pChunk)); \
     126             ASSERT_LE((pChunk)->cb, (uintptr_t)(pHeap)->CTX_SUFF(pbHeap) + (pHeap)->offPageAligned - (uintptr_t)(pChunk)); \
    127127    } while (0)
    128128
     
    234234            const uint32_t cbChunk = pChunk->offNext
    235235                ? pChunk->offNext
    236                 : CTXSUFF(pHeap->pbHeap) + pHeap->offPageAligned - (uint8_t *)pChunk;
     236                : pHeap->CTX_SUFF(pbHeap) + pHeap->offPageAligned - (uint8_t *)pChunk;
    237237            pStat->cbAllocated += (uint32_t)cbChunk;
    238238            pStat->cbCurAllocated += (uint32_t)cbChunk;
     
    319319     */
    320320    PMMHYPERCHUNK     pRet = NULL;
    321     PMMHYPERCHUNKFREE pFree = (PMMHYPERCHUNKFREE)((char *)CTXSUFF(pHeap->pbHeap) + pHeap->offFreeHead);
     321    PMMHYPERCHUNKFREE pFree = (PMMHYPERCHUNKFREE)((char *)pHeap->CTX_SUFF(pbHeap) + pHeap->offFreeHead);
    322322    while (pFree)
    323323    {
     
    350350                    {
    351351                        /* make new head node, mark it USED for simplisity. */
    352                         PMMHYPERCHUNK pPrev = (PMMHYPERCHUNK)CTXSUFF(pHeap->pbHeap);
     352                        PMMHYPERCHUNK pPrev = (PMMHYPERCHUNK)pHeap->CTX_SUFF(pbHeap);
    353353                        Assert(pPrev == &pFree->core);
    354354                        pPrev->offPrev = 0;
     
    564564     * boundrary.
    565565     */
    566     PMMHYPERCHUNKFREE pFree = (PMMHYPERCHUNKFREE)((char *)CTXSUFF(pHeap->pbHeap) + pHeap->offFreeTail);
     566    PMMHYPERCHUNKFREE pFree = (PMMHYPERCHUNKFREE)((char *)pHeap->CTX_SUFF(pbHeap) + pHeap->offFreeTail);
    567567    ASSERT_CHUNK_FREE(pHeap, pFree);
    568568    if (    (((uintptr_t)(&pFree->core + 1) + pFree->cb) & (PAGE_OFFSET_MASK - 1))
     
    624624        Log3(("mmHyperAllocPages: Unlinked pFree=%d\n", pFree));
    625625    }
    626     pHeap->offPageAligned = (uintptr_t)pvRet - (uintptr_t)CTXSUFF(pHeap->pbHeap);
     626    pHeap->offPageAligned = (uintptr_t)pvRet - (uintptr_t)pHeap->CTX_SUFF(pbHeap);
    627627    Log3(("mmHyperAllocPages: Returning %p (page aligned)\n", pvRet));
    628628
     
    633633}
    634634
    635 
    636635#ifdef VBOX_WITH_STATISTICS
     636
    637637/**
    638638 * Get the statistic record for a tag.
     
    662662    if (!pStat->fRegistered)
    663663    {
    664 #ifdef IN_RING3
    665         mmR3HyperStatRegisterOne(pHeap->pVMHC, pStat);
    666 #else
    667         /** @todo schedule a HC action. */
    668 #endif
     664# ifdef IN_RING3
     665        mmR3HyperStatRegisterOne(pHeap->pVMR3, pStat);
     666# else
     667        /** @todo schedule a R3 action. */
     668# endif
    669669    }
    670670    return pStat;
    671671}
    672672
    673 #ifdef IN_RING3
     673
     674# ifdef IN_RING3
    674675/**
    675676 * Registers statistics with STAM.
     
    681682        return;
    682683    const char *pszTag = mmR3GetTagName((MMTAG)pStat->Core.Key);
    683 
    684     char szName[128];
    685     RTStrPrintf(szName, sizeof(szName), "/MM/HyperHeap/%s/cAllocations", pszTag);
    686     STAMR3Register(pVM, &pStat->cAllocations,   STAMTYPE_U64, STAMVISIBILITY_ALWAYS, szName, STAMUNIT_COUNT, "Number of alloc calls.");
    687 
    688     RTStrPrintf(szName, sizeof(szName), "/MM/HyperHeap/%s/cFrees", pszTag);
    689     STAMR3Register(pVM, &pStat->cFrees,         STAMTYPE_U64, STAMVISIBILITY_ALWAYS, szName, STAMUNIT_COUNT, "Number of free calls.");
    690 
    691     RTStrPrintf(szName, sizeof(szName), "/MM/HyperHeap/%s/cFailures", pszTag);
    692     STAMR3Register(pVM, &pStat->cFailures,      STAMTYPE_U64, STAMVISIBILITY_ALWAYS, szName, STAMUNIT_COUNT, "Number of failures.");
    693 
    694     RTStrPrintf(szName, sizeof(szName), "/MM/HyperHeap/%s/cbAllocated", pszTag);
    695     STAMR3Register(pVM, &pStat->cbAllocated,    STAMTYPE_U64, STAMVISIBILITY_ALWAYS, szName, STAMUNIT_BYTES, "Total number of allocated bytes.");
    696 
    697     RTStrPrintf(szName, sizeof(szName), "/MM/HyperHeap/%s/cbFreed", pszTag);
    698     STAMR3Register(pVM, &pStat->cbFreed,        STAMTYPE_U64, STAMVISIBILITY_ALWAYS, szName, STAMUNIT_BYTES, "Total number of freed bytes.");
    699 
    700     RTStrPrintf(szName, sizeof(szName), "/MM/HyperHeap/%s/cbCurAllocated", pszTag);
    701     STAMR3Register(pVM, &pStat->cbCurAllocated, STAMTYPE_U32, STAMVISIBILITY_ALWAYS, szName, STAMUNIT_BYTES, "Number of bytes currently allocated.");
    702 
    703     RTStrPrintf(szName, sizeof(szName), "/MM/HyperHeap/%s/cbMaxAllocated", pszTag);
    704     STAMR3Register(pVM, &pStat->cbMaxAllocated, STAMTYPE_U32, STAMVISIBILITY_ALWAYS, szName, STAMUNIT_BYTES, "Max number of bytes allocated at the same time.");
    705 
     684    STAMR3RegisterF(pVM, &pStat->cAllocations,   STAMTYPE_U64, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Number of alloc calls.",                         "/MM/HyperHeap/%s/cAllocations", pszTag);
     685    STAMR3RegisterF(pVM, &pStat->cFrees,         STAMTYPE_U64, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Number of free calls.",                          "/MM/HyperHeap/%s/cFrees", pszTag);
     686    STAMR3RegisterF(pVM, &pStat->cFailures,      STAMTYPE_U64, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Number of failures.",                            "/MM/HyperHeap/%s/cFailures", pszTag);
     687    STAMR3RegisterF(pVM, &pStat->cbAllocated,    STAMTYPE_U64, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Total number of allocated bytes.",               "/MM/HyperHeap/%s/cbAllocated", pszTag);
     688    STAMR3RegisterF(pVM, &pStat->cbFreed,        STAMTYPE_U64, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Total number of freed bytes.",                   "/MM/HyperHeap/%s/cbFreed", pszTag);
     689    STAMR3RegisterF(pVM, &pStat->cbCurAllocated, STAMTYPE_U32, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Number of bytes currently allocated.",           "/MM/HyperHeap/%s/cbCurAllocated", pszTag);
     690    STAMR3RegisterF(pVM, &pStat->cbMaxAllocated, STAMTYPE_U32, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Max number of bytes allocated at the same time.","/MM/HyperHeap/%s/cbMaxAllocated", pszTag);
    706691    pStat->fRegistered = true;
    707692}
    708 #endif
    709 
    710 #endif
     693# endif /* IN_RING3 */
     694
     695#endif /* VBOX_WITH_STATISTICS */
    711696
    712697
     
    776761
    777762    /* Some more verifications using additional info from pHeap. */
    778     AssertMsgReturn((uintptr_t)pChunk + offPrev >= (uintptr_t)CTXSUFF(pHeap->pbHeap),
     763    AssertMsgReturn((uintptr_t)pChunk + offPrev >= (uintptr_t)pHeap->CTX_SUFF(pbHeap),
    779764                    ("%p: offPrev=%#RX32!\n", pv, offPrev),
    780765                    VERR_INVALID_POINTER);
     
    784769                    VERR_INVALID_POINTER);
    785770
    786     AssertMsgReturn(   (uintptr_t)pv - (uintptr_t)CTXSUFF(pHeap->pbHeap) <= pHeap->offPageAligned,
    787                     ("Invalid pointer %p! (heap: %p-%p)\n", pv, CTXSUFF(pHeap->pbHeap),
    788                     (char *)CTXSUFF(pHeap->pbHeap) + pHeap->offPageAligned),
     771    AssertMsgReturn(   (uintptr_t)pv - (uintptr_t)pHeap->CTX_SUFF(pbHeap) <= pHeap->offPageAligned,
     772                    ("Invalid pointer %p! (heap: %p-%p)\n", pv, pHeap->CTX_SUFF(pbHeap),
     773                    (char *)pHeap->CTX_SUFF(pbHeap) + pHeap->offPageAligned),
    789774                    VERR_INVALID_POINTER);
    790775
     
    797782    const uint32_t cbChunk = pChunk->offNext
    798783        ? pChunk->offNext
    799         : CTXSUFF(pHeap->pbHeap) + pHeap->offPageAligned - (uint8_t *)pChunk;
     784        : pHeap->CTX_SUFF(pbHeap) + pHeap->offPageAligned - (uint8_t *)pChunk;
    800785#endif
    801786#ifdef MMHYPER_HEAP_FREE_POISON
     
    816801            const size_t cb = pCur->offNext
    817802                ? pCur->offNext - sizeof(*pCur)
    818                 : CTXSUFF(pHeap->pbHeap) + pHeap->offPageAligned - (uint8_t *)pCur - sizeof(*pCur);
     803                : pHeap->CTX_SUFF(pbHeap) + pHeap->offPageAligned - (uint8_t *)pCur - sizeof(*pCur);
    819804            uint8_t *pab = (uint8_t *)(pCur + 1);
    820805            for (unsigned off = 0; off < cb; off++)
     
    901886        }
    902887        if (!pRight)
    903             pRight = (PMMHYPERCHUNKFREE)((char *)CTXSUFF(pHeap->pbHeap) + pHeap->offFreeTail); /** @todo this can't be correct! 'pLeft = .. ; else' I think */
     888            pRight = (PMMHYPERCHUNKFREE)((char *)pHeap->CTX_SUFF(pbHeap) + pHeap->offFreeTail); /** @todo this can't be correct! 'pLeft = .. ; else' I think */
    904889        if (pRight)
    905890        {
     
    926911        MMHYPERCHUNK_SET_TYPE(&pFree->core, MMHYPERCHUNK_FLAGS_FREE);
    927912        pFree->offPrev = 0;
    928         pHeap->offFreeHead = (uintptr_t)pFree - (uintptr_t)CTXSUFF(pHeap->pbHeap);
     913        pHeap->offFreeHead = (uintptr_t)pFree - (uintptr_t)pHeap->CTX_SUFF(pbHeap);
    929914        if (pRight)
    930915        {
     
    974959            {
    975960                pFree->offNext = 0;
    976                 pHeap->offFreeTail = (uintptr_t)pFree - (uintptr_t)CTXSUFF(pHeap->pbHeap);
     961                pHeap->offFreeTail = (uintptr_t)pFree - (uintptr_t)pHeap->CTX_SUFF(pbHeap);
    977962            }
    978963            Log3(("mmHyperFree: Inserted %p after %p in free list.\n", pFree, pLeft));
     
    1005990        {
    1006991            pFree->offNext = 0;
    1007             pHeap->offFreeTail = (uintptr_t)pFree - (uintptr_t)CTXSUFF(pHeap->pbHeap);
     992            pHeap->offFreeTail = (uintptr_t)pFree - (uintptr_t)pHeap->CTX_SUFF(pbHeap);
    1008993        }
    1009994        Log3(("mmHyperFree: cbFree %d -> %d (%d)\n", pHeap->cbFree, pHeap->cbFree - pRight->cb, -(int32_t)pRight->cb));
     
    10161001        pFree->cb = pFree->core.offNext - sizeof(MMHYPERCHUNK);
    10171002    else
    1018         pFree->cb = pHeap->offPageAligned - ((uintptr_t)pFree - (uintptr_t)CTXSUFF(pHeap->pbHeap)) - sizeof(MMHYPERCHUNK);
     1003        pFree->cb = pHeap->offPageAligned - ((uintptr_t)pFree - (uintptr_t)pHeap->CTX_SUFF(pbHeap)) - sizeof(MMHYPERCHUNK);
    10191004    Log3(("mmHyperFree: cbFree %d -> %d (%d)\n", pHeap->cbFree, pHeap->cbFree + pFree->cb, pFree->cb));
    10201005    pHeap->cbFree += pFree->cb;
     
    10451030#ifdef IN_RING3
    10461031            Log(("%p  %06x USED offNext=%06x offPrev=-%06x %s%s\n",
    1047                  pCur, (uintptr_t)pCur - (uintptr_t)CTXSUFF(pHeap->pbHeap),
     1032                 pCur, (uintptr_t)pCur - (uintptr_t)pHeap->CTX_SUFF(pbHeap),
    10481033                 pCur->core.offNext, -MMHYPERCHUNK_GET_OFFPREV(&pCur->core),
    10491034                 mmR3GetTagName((MMTAG)pStat->Core.Key), pszSelf));
    10501035#else
    10511036            Log(("%p  %06x USED offNext=%06x offPrev=-%06x %d%s\n",
    1052                  pCur, (uintptr_t)pCur - (uintptr_t)CTXSUFF(pHeap->pbHeap),
     1037                 pCur, (uintptr_t)pCur - (uintptr_t)pHeap->CTX_SUFF(pbHeap),
    10531038                 pCur->core.offNext, -MMHYPERCHUNK_GET_OFFPREV(&pCur->core),
    10541039                 (MMTAG)pStat->Core.Key, pszSelf));
     
    10571042        else
    10581043            Log(("%p  %06x USED offNext=%06x offPrev=-%06x\n",
    1059                  pCur, (uintptr_t)pCur - (uintptr_t)CTXSUFF(pHeap->pbHeap),
     1044                 pCur, (uintptr_t)pCur - (uintptr_t)pHeap->CTX_SUFF(pbHeap),
    10601045                 pCur->core.offNext, -MMHYPERCHUNK_GET_OFFPREV(&pCur->core)));
    10611046    }
    10621047    else
    10631048        Log(("%p  %06x FREE offNext=%06x offPrev=-%06x : cb=%06x offNext=%06x offPrev=-%06x\n",
    1064              pCur, (uintptr_t)pCur - (uintptr_t)CTXSUFF(pHeap->pbHeap),
     1049             pCur, (uintptr_t)pCur - (uintptr_t)pHeap->CTX_SUFF(pbHeap),
    10651050             pCur->core.offNext, -MMHYPERCHUNK_GET_OFFPREV(&pCur->core), pCur->cb, pCur->offNext, pCur->offPrev));
    10661051}
     
    10751060{
    10761061    PMMHYPERCHUNKFREE pPrev = NULL;
    1077     PMMHYPERCHUNKFREE pCur = (PMMHYPERCHUNKFREE)CTXSUFF(pHeap->pbHeap);
     1062    PMMHYPERCHUNKFREE pCur = (PMMHYPERCHUNKFREE)pHeap->CTX_SUFF(pbHeap);
    10781063    for (;;)
    10791064    {
     
    10871072
    10881073# ifdef MMHYPER_HEAP_STRICT_FENCE
    1089         uint32_t off = (uint8_t *)pCur - CTXSUFF(pHeap->pbHeap);
     1074        uint32_t off = (uint8_t *)pCur - pHeap->CTX_SUFF(pbHeap);
    10901075        if (    MMHYPERCHUNK_ISUSED(&pCur->core)
    10911076            &&  off < pHeap->offPageAligned)
     
    11461131    Log(("MMHyperHeapDump: *** heap dump - start ***\n"));
    11471132    PMMHYPERHEAP pHeap = CTXSUFF(pVM->mm.s.pHyperHeap);
    1148     PMMHYPERCHUNKFREE pCur = (PMMHYPERCHUNKFREE)CTXSUFF(pHeap->pbHeap);
     1133    PMMHYPERCHUNKFREE pCur = (PMMHYPERCHUNKFREE)pHeap->CTX_SUFF(pbHeap);
    11491134    for (;;)
    11501135    {
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette