Ticket #2808: ShrinkingGCHack.diff

File ShrinkingGCHack.diff, 2.5 KB (added by Yves, 10 years ago)

A hack that calls very frequent shrinking GCs for testing

  • source/gui/GUIManager.cpp

     
    379379
    380380    // We share the script runtime with everything else that runs in the same thread.
    381381    // This call makes sure we trigger GC regularly even if the simulation is not running.
    382     m_ScriptInterface->MaybeIncrementalRuntimeGC(1.0f);
    383382   
     383    //m_ScriptInterface->MaybeIncrementalRuntimeGC(1.0f);
     384   
     385    m_ScriptInterface->ShrinkingGC();
     386   
    384387    // Save an immutable copy so iterators aren't invalidated by tick handlers
    385388    PageStackType pageStack = m_PageStack;
    386389
  • source/scriptinterface/ScriptInterface.cpp

     
    230231        }
    231232    }
    232233   
     234    void ShrinkingGC()
     235    {   
     236        int gcBytes = JS_GetGCParameter(m_rt, JSGC_BYTES);
     237        int gcUnusedChunks = JS_GetGCParameter(m_rt, JSGC_UNUSED_CHUNKS);
     238        int gcTotalChunks = JS_GetGCParameter(m_rt, JSGC_TOTAL_CHUNKS);
     239        std::cout << "gcBytes: " << gcBytes << std::endl; // debugging
     240        std::cout << "gcUnusedChunks: " << gcUnusedChunks << std::endl; // debugging
     241        std::cout << "gcTotalChunks: " << gcTotalChunks << std::endl; // debugging
     242
     243        std::cout << "Calling a shrinking GC!" << std::endl;
     244       
     245        JS::PrepareForFullGC(m_rt);
     246        JS::ShrinkingGC(m_rt, JS::gcreason::REFRESH_FRAME);
     247       
     248        std::cout << "gcBytes: " << gcBytes << std::endl; // debugging
     249        std::cout << "gcUnusedChunks: " << gcUnusedChunks << std::endl; // debugging
     250        std::cout << "gcTotalChunks: " << gcTotalChunks << std::endl; // debugging
     251    }
     252   
     253   
    233254    void RegisterContext(JSContext* cx)
    234255    {
    235256        m_Contexts.push_back(cx);
     
    14241445    m->m_runtime->MaybeIncrementalGC(delay);
    14251446}
    14261447
     1448void ScriptInterface::ShrinkingGC()
     1449{
     1450    m->m_runtime->ShrinkingGC();
     1451}
     1452
    14271453void ScriptInterface::MaybeGC()
    14281454{
    14291455    JS_MaybeGC(m->m_cx);
  • source/scriptinterface/ScriptInterface.h

     
    363363     */
    364364    void MaybeIncrementalRuntimeGC(double delay);
    365365   
     366    void ShrinkingGC();
     367   
    366368    /**
    367369     * Triggers a full non-incremental garbage collection immediately. That should only be required in special cases and normally
    368370     * you should try to use MaybeIncrementalRuntimeGC instead.