VirtualBox

Ignore:
Timestamp:
May 22, 2013 12:28:12 AM (12 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
85923
Message:

Speed up line number allocation and dwarf DIE allocations by using RTMemCacheXZY. Helps a lot with the EF heap, mainly by avoid it...

Location:
trunk/src/VBox/Runtime/common/dbg
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/dbg/dbgmodcontainer.cpp

    r46164 r46204  
    3535#include <iprt/err.h>
    3636#include <iprt/mem.h>
     37#define RTDBGMODCNT_WITH_MEM_CACHE
     38#ifdef RTDBGMODCNT_WITH_MEM_CACHE
     39# include <iprt/memcache.h>
     40#endif
    3741#include <iprt/string.h>
    3842#include <iprt/strcache.h>
     
    135139    /** The next line number ordinal. */
    136140    uint32_t                    iNextLineOrdinal;
     141#ifdef RTDBGMODCNT_WITH_MEM_CACHE
     142    /** Line number allocator.
     143     * Using a cache is a bit overkill since we normally won't free them, but
     144     * it's a construct that exists and does the job relatively efficiently. */
     145    RTMEMCACHE                  hLineNumAllocator;
     146#endif
    137147} RTDBGMODCTN;
    138148/** Pointer to instance data for the debug info container. */
     
    251261     * Create a new entry.
    252262     */
     263#ifdef RTDBGMODCNT_WITH_MEM_CACHE
     264    PRTDBGMODCTNLINE pLine = (PRTDBGMODCTNLINE)RTMemCacheAlloc(pThis->hLineNumAllocator);
     265#else
    253266    PRTDBGMODCTNLINE pLine = (PRTDBGMODCTNLINE)RTMemAllocZ(sizeof(*pLine));
     267#endif
    254268    if (!pLine)
    255269        return VERR_NO_MEMORY;
     
    625639static DECLCALLBACK(int)  rtDbgModContainer_DestroyTreeLineNode(PAVLU32NODECORE pNode, void *pvUser)
    626640{
     641    PRTDBGMODCTN     pThis = (PRTDBGMODCTN)pvUser;
    627642    PRTDBGMODCTNLINE pLine = RT_FROM_MEMBER(pNode, RTDBGMODCTNLINE, OrdinalCore);
    628643    RTStrCacheRelease(g_hDbgModStrCache, pLine->pszFile);
    629644    pLine->pszFile = NULL;
    630     RTMemFree(pLine);
    631     NOREF(pvUser);
     645#ifdef RTDBGMODCNT_WITH_MEM_CACHE
     646    RTMemCacheFree(pThis->hLineNumAllocator, pLine);
     647#else
     648    RTMemFree(pLine); NOREF(pThis);
     649#endif   
    632650    return 0;
    633651}
     
    664682    pThis->Names = NULL;
    665683
    666     RTAvlU32Destroy(&pThis->LineOrdinalTree, rtDbgModContainer_DestroyTreeLineNode, NULL);
     684#ifdef RTDBGMODCNT_WITH_MEM_CACHE
     685    RTMemCacheDestroy(pThis->hLineNumAllocator);
     686    pThis->hLineNumAllocator = NIL_RTMEMCACHE;
     687#else
     688    RTAvlU32Destroy(&pThis->LineOrdinalTree, rtDbgModContainer_DestroyTreeLineNode, pThis);
     689#endif
    667690
    668691    RTMemFree(pThis->paSegs);
     
    755778        pThis->paSegs[iSeg].LineAddrTree = NULL;
    756779
    757     RTAvlU32Destroy(&pThis->LineOrdinalTree, rtDbgModContainer_DestroyTreeLineNode, NULL);
     780    RTAvlU32Destroy(&pThis->LineOrdinalTree, rtDbgModContainer_DestroyTreeLineNode, pThis);
    758781    Assert(pThis->LineOrdinalTree == NULL);
    759782
     
    817840    pMod->pvDbgPriv = pThis;
    818841
    819     /*
    820      * Add the initial segment.
    821      */
    822     if (cbSeg)
    823     {
    824         int rc = rtDbgModContainer_SegmentAdd(pMod, 0, cbSeg, "default", sizeof("default") - 1, 0, NULL);
    825         if (RT_FAILURE(rc))
    826         {
    827             RTMemFree(pThis);
    828             pMod->pDbgVt = NULL;
    829             pMod->pvDbgPriv = NULL;
     842#ifdef RTDBGMODCNT_WITH_MEM_CACHE
     843    int rc = RTMemCacheCreate(&pThis->hLineNumAllocator, sizeof(RTDBGMODCTNLINE), sizeof(void *), UINT32_MAX,
     844                              NULL /*pfnCtor*/, NULL /*pfnDtor*/, NULL /*pvUser*/, 0 /*fFlags*/);
     845#else
     846    int rc = VINF_SUCCESS;
     847#endif
     848    if (RT_SUCCESS(rc))
     849    {
     850        /*
     851         * Add the initial segment.
     852         */
     853        if (cbSeg)
     854            rc = rtDbgModContainer_SegmentAdd(pMod, 0, cbSeg, "default", sizeof("default") - 1, 0, NULL);
     855        if (RT_SUCCESS(rc))
    830856            return rc;
    831         }
    832     }
    833 
    834     return VINF_SUCCESS;
    835 }
    836 
     857
     858#ifdef RTDBGMODCNT_WITH_MEM_CACHE
     859        RTMemCacheDestroy(pThis->hLineNumAllocator);
     860#endif
     861    }
     862
     863    RTMemFree(pThis);
     864    pMod->pDbgVt = NULL;
     865    pMod->pvDbgPriv = NULL;
     866    return rc;
     867}
     868
  • trunk/src/VBox/Runtime/common/dbg/dbgmoddwarf.cpp

    r46166 r46204  
    55
    66/*
    7  * Copyright (C) 2011-2012 Oracle Corporation
     7 * Copyright (C) 2011-2013 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    3939#include <iprt/log.h>
    4040#include <iprt/mem.h>
     41#define RTDBGMODDWARF_WITH_MEM_CACHE
     42#ifdef RTDBGMODDWARF_WITH_MEM_CACHE
     43# include <iprt/memcache.h>
     44#endif
    4145#include <iprt/path.h>
    4246#include <iprt/string.h>
     
    473477    /** Pointer to segments if iWatcomPass isn't -1. */
    474478    PRTDBGDWARFSEG          paSegs;
     479#ifdef RTDBGMODDWARF_WITH_MEM_CACHE
     480    /** DIE allocators.  */
     481    struct
     482    {
     483        RTMEMCACHE          hMemCache;
     484        uint32_t            cbMax;
     485    } aDieAllocators[2];
     486#endif
    475487} RTDBGMODDWARF;
    476488/** Pointer to instance data of the DWARF reader. */
     
    646658    /** The number of unknown or otherwise unhandled attributes. */
    647659    uint8_t             cUnhandledAttrs;
    648     /** The date tag, indicating which union structure to use. */
     660#ifdef RTDBGMODDWARF_WITH_MEM_CACHE
     661    /** The allocator index. */
     662    uint8_t             iAllocator;
     663#endif
     664    /** The die tag, indicating which union structure to use. */
    649665    uint16_t            uTag;
    650666    /** Offset of the abbreviation specification (within debug_abbrev). */
     
    38043820    NOREF(pThis);
    38053821    Assert(pDieDesc->cbDie >= sizeof(RTDWARFDIE));
     3822#ifdef RTDBGMODDWARF_WITH_MEM_CACHE
     3823    uint32_t iAllocator = pDieDesc->cbDie > pThis->aDieAllocators[0].cbMax;
     3824    Assert(pDieDesc->cbDie <= pThis->aDieAllocators[iAllocator].cbMax);
     3825    PRTDWARFDIE pDie = (PRTDWARFDIE)RTMemCacheAlloc(pThis->aDieAllocators[iAllocator].hMemCache);
     3826#else
    38063827    PRTDWARFDIE pDie = (PRTDWARFDIE)RTMemAllocZ(pDieDesc->cbDie);
     3828#endif
    38073829    if (pDie)
    38083830    {
     3831#ifdef RTDBGMODDWARF_WITH_MEM_CACHE
     3832        RT_BZERO(pDie, pDieDesc->cbDie);
     3833        pDie->iAllocator   = iAllocator;
     3834#endif
    38093835        rtDwarfInfo_InitDie(pDie, pDieDesc);
    38103836
     
    41054131                {
    41064132                    RTListNodeRemove(&pChild->SiblingNode);
     4133#ifdef RTDBGMODDWARF_WITH_MEM_CACHE
     4134                    RTMemCacheFree(pThis->aDieAllocators[pChild->iAllocator].hMemCache, pChild);
     4135#else
    41074136                    RTMemFree(pChild);
     4137#endif
    41084138                }
    41094139            }
     
    43374367        pThis->pNestedMod = NULL;
    43384368    }
     4369
     4370#ifdef RTDBGMODDWARF_WITH_MEM_CACHE
     4371    uint32_t i = RT_ELEMENTS(pThis->aDieAllocators);
     4372    while (i-- > 0)
     4373    {
     4374        RTMemCacheDestroy(pThis->aDieAllocators[i].hMemCache);
     4375        pThis->aDieAllocators[i].hMemCache = NIL_RTMEMCACHE;
     4376    }
     4377#endif
     4378
    43394379    RTMemFree(pThis);
    43404380
     
    44764516    RTListInit(&pThis->CompileUnitList);
    44774517
     4518#ifdef RTDBGMODDWARF_WITH_MEM_CACHE
     4519    AssertCompile(RT_ELEMENTS(pThis->aDieAllocators) == 2);
     4520    pThis->aDieAllocators[0].cbMax = sizeof(RTDWARFDIE);
     4521    pThis->aDieAllocators[1].cbMax = sizeof(RTDWARFDIECOMPILEUNIT);
     4522    for (uint32_t i = 0; i < RT_ELEMENTS(g_aTagDescs); i++)
     4523        if (g_aTagDescs[i].pDesc && g_aTagDescs[i].pDesc->cbDie > pThis->aDieAllocators[1].cbMax)
     4524            pThis->aDieAllocators[1].cbMax = g_aTagDescs[i].pDesc->cbDie;
     4525    pThis->aDieAllocators[1].cbMax = RT_ALIGN_32(pThis->aDieAllocators[1].cbMax, sizeof(uint64_t));
     4526
     4527    for (uint32_t i = 0; i < RT_ELEMENTS(pThis->aDieAllocators); i++)
     4528    {
     4529        int rc = RTMemCacheCreate(&pThis->aDieAllocators[i].hMemCache, pThis->aDieAllocators[i].cbMax, sizeof(uint64_t),
     4530                                  UINT32_MAX, NULL /*pfnCtor*/, NULL /*pfnDtor*/, NULL /*pvUser*/, 0 /*fFlags*/);
     4531        if (RT_FAILURE(rc))
     4532        {
     4533            while (i-- > 0)
     4534                RTMemCacheDestroy(pThis->aDieAllocators[i].hMemCache);
     4535            RTMemFree(pThis);
     4536            return rc;
     4537        }
     4538    }
     4539#endif
    44784540
    44794541    /*
     
    45294591                                                                     &pThis->aSections[iSect].pv);
    45304592
    4531 
     4593                    /** @todo Kill pThis->CompileUnitList and the alloc caches. */
    45324594                    return VINF_SUCCESS;
    45334595                }
     
    45414603            rc = VERR_DBG_NO_MATCHING_INTERPRETER;
    45424604    }
     4605
    45434606    RTMemFree(pThis->paCachedAbbrevs);
     4607
     4608#ifdef RTDBGMODDWARF_WITH_MEM_CACHE
     4609    uint32_t i = RT_ELEMENTS(pThis->aDieAllocators);
     4610    while (i-- > 0)
     4611    {
     4612        RTMemCacheDestroy(pThis->aDieAllocators[i].hMemCache);
     4613        pThis->aDieAllocators[i].hMemCache = NIL_RTMEMCACHE;
     4614    }
     4615#endif
     4616
    45444617    RTMemFree(pThis);
    45454618
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