VirtualBox

Changeset 288 in vbox for trunk/src


Ignore:
Timestamp:
Jan 25, 2007 5:14:15 AM (18 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
17834
Message:

debugged the heap.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/testcase/tstHeapSimple.cpp

    r283 r288  
    6868    } aOps[] =
    6969    {
    70         {        16,          0,    NULL,  0 },
     70        {        16,          0,    NULL,  0 },  // 0
    7171        {        16,          4,    NULL,  1 },
    7272        {        16,          8,    NULL,  2 },
    7373        {        16,         16,    NULL,  5 },
    7474        {        16,         32,    NULL,  4 },
    75         {        32,          0,    NULL,  3 },
     75        {        32,          0,    NULL,  3 },  // 5
    7676        {        31,          0,    NULL,  6 },
    7777        {      1024,          0,    NULL,  8 },
    7878        {      1024,         32,    NULL, 10 },
    7979        {      1024,         32,    NULL, 12 },
    80         { PAGE_SIZE,  PAGE_SIZE,    NULL, 13 },
     80        { PAGE_SIZE,  PAGE_SIZE,    NULL, 13 },  // 10
    8181        {      1024,         32,    NULL,  9 },
    8282        { PAGE_SIZE,         32,    NULL, 11 },
    8383        { PAGE_SIZE,  PAGE_SIZE,    NULL, 14 },
    8484        {        16,          0,    NULL, 15 },
    85         {        9,           0,    NULL,  7 },
     85        {        9,           0,    NULL,  7 },  // 15
    8686        {        16,          0,    NULL,  7 },
    8787        {        36,          0,    NULL,  7 },
    8888        {        16,          0,    NULL,  7 },
    8989        {     12344,          0,    NULL,  7 },
    90         {        50,          0,    NULL,  7 },
     90        {        50,          0,    NULL,  7 },  // 20
    9191        {        16,          0,    NULL,  7 },
    9292    };
    9393    unsigned i;
    94 #ifdef DEBUG
    95     RTHeapSimpleDump(Heap);
    96 #endif
    97 //    size_t cbBefore = RTHeapSimpleGetFreeSize(Heap);
    98     size_t cbBefore = 0;
     94    RTHeapSimpleDump(Heap, (PFNRTHEAPSIMPLEPRINTF)RTPrintf);
     95    size_t cbBefore = RTHeapSimpleGetFreeSize(Heap);
    9996    static char szFill[] = "01234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
    10097
     
    119116    for (i = 0; i < ELEMENTS(aOps); i++)
    120117    {
    121         if (    !aOps[i].pvAlloc
    122             ||  aOps[i].uAlignment == PAGE_SIZE)
     118        if (!aOps[i].pvAlloc)
    123119            continue;
    124         //size_t cbBeforeSub = RTHeapSimpleGetFreeSize(Heap);
     120        //RTPrintf("debug: i=%d pv=%#x cb=%#zx align=%#zx cbReal=%#zx\n", i, aOps[i].pvAlloc,
     121        //         aOps[i].cb, aOps[i].uAlignment, RTHeapSimpleSize(Heap, aOps[i].pvAlloc));
     122        size_t cbBeforeSub = RTHeapSimpleGetFreeSize(Heap);
    125123        RTHeapSimpleFree(Heap, aOps[i].pvAlloc);
     124        size_t cbAfterSubFree = RTHeapSimpleGetFreeSize(Heap);
    126125
    127         //RTPrintf("debug: i=%d cbBeforeSub=%d now=%d\n", i, cbBeforeSub, RTHeapSimpleGetFreeSize(Heap));
    128126        void *pv;
    129127        pv = RTHeapSimpleAlloc(Heap, aOps[i].cb, aOps[i].uAlignment);
    130         if (pv)
     128        if (!pv)
    131129        {
    132130            RTPrintf("Failure: RTHeapSimpleAlloc(%p, %#x, %#x,) -> NULL i=%d\n", (void *)Heap, aOps[i].cb, aOps[i].uAlignment, i);
    133131            return 1;
    134132        }
     133        //RTPrintf("debug: i=%d pv=%p cbReal=%#zx cbBeforeSub=%#zx cbAfterSubFree=%#zx cbAfterSubAlloc=%#zx \n", i, pv, RTHeapSimpleSize(Heap, pv),
     134        //         cbBeforeSub, cbAfterSubFree, RTHeapSimpleGetFreeSize(Heap));
    135135        if (pv != aOps[i].pvAlloc)
     136            RTPrintf("Warning: Free+Alloc returned different address. new=%p old=%p i=%d\n", pv, aOps[i].pvAlloc, i);
     137        aOps[i].pvAlloc = pv;
     138        size_t cbAfterSubAlloc = RTHeapSimpleGetFreeSize(Heap);
     139        if (cbBeforeSub != cbAfterSubAlloc)
    136140        {
    137             RTPrintf("Failure: Free+Alloc returned different address. new=%p old=%p i=%d (doesn't work with delayed free)\n", pv, aOps[i].pvAlloc, i);
    138             //return 1;
     141            RTPrintf("Warning: cbBeforeSub=%#zx cbAfterSubFree=%#zx cbAfterSubAlloc=%#zx. i=%d\n",
     142                     cbBeforeSub, cbAfterSubFree, cbAfterSubAlloc, i);
     143            //return 1; - won't work correctly until we start creating free block instead of donating memory on alignment.
    139144        }
    140         aOps[i].pvAlloc = pv;
    141         #if 0 /* won't work :/ */
    142         size_t cbAfterSub = RTHeapSimpleGetFreeSize(Heap);
    143         if (cbBeforeSub != cbAfterSub)
    144         {
    145             RTPrintf("Failure: cbBeforeSub=%d cbAfterSub=%d. i=%d\n", cbBeforeSub, cbAfterSub, i);
    146             return 1;
    147         }
    148         #endif
    149145    }
    150146
     
    160156                continue;
    161157            //RTPrintf("j=%d i=%d free=%d cb=%d pv=%p\n", j, i, RTHeapSimpleGetFreeSize(Heap), aOps[j].cb, aOps[j].pvAlloc);
    162             if (aOps[j].uAlignment == PAGE_SIZE)
    163                 cbBefore -= aOps[j].cb;
    164             else
    165                 RTHeapSimpleFree(Heap, aOps[j].pvAlloc);
     158            RTHeapSimpleFree(Heap, aOps[j].pvAlloc);
    166159            aOps[j].pvAlloc = NULL;
    167160            cFreed++;
     
    169162    }
    170163    Assert(cFreed == RT_ELEMENTS(aOps));
    171     //RTPrintf("i=done free=%d\n", RTHeapSimpleGetFreeSize(Heap));
     164    RTPrintf("i=done free=%d\n", RTHeapSimpleGetFreeSize(Heap));
    172165
    173 #if 0
    174166    /* check that we're back at the right amount of free memory. */
    175     //size_t cbAfter = RTHeapSimpleGetFreeSize(Heap);
     167    size_t cbAfter = RTHeapSimpleGetFreeSize(Heap);
    176168    if (cbBefore != cbAfter)
    177169    {
    178170        RTPrintf("Warning: Either we've split out an alignment chunk at the start, or we've got\n"
    179171                 "         an alloc/free accounting bug: cbBefore=%d cbAfter=%d\n", cbBefore, cbAfter);
    180 #ifdef DEBUG
    181         RTHeapSimpleDump(Heap);
    182 #endif
     172        RTHeapSimpleDump(Heap, (PFNRTHEAPSIMPLEPRINTF)RTPrintf);
    183173    }
    184 #endif
    185174
    186175    RTPrintf("tstHeapSimple: Success\n");
Note: See TracChangeset for help on using the changeset viewer.

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