Ignore:
Timestamp:
Aug 17, 2009, 6:05:37 PM (16 years ago)
Author:
[email protected]
Message:

Fix 300,000+ leaks seen during the regression tests.

Reviewed by Darin Adler.

EvalCodeCache::get was heap-allocating an EvalExecutable instance without adopting the initial reference.
While fixing this we noticed that EvalExecutable was a RefCounted type that was sometimes stack allocated.
To make this cleaner and to prevent clients from attempting to ref a stack-allocated instance, we move the
refcounting down to a new CacheableEvalExecutable class that derives from EvalExecutable. EvalCodeCache::get
now uses CacheableEvalExecutable::create and avoids the leak.

  • bytecode/EvalCodeCache.h:

(JSC::EvalCodeCache::get):

  • interpreter/Interpreter.cpp:

(JSC::Interpreter::callEval):

  • runtime/Executable.h:

(JSC::CacheableEvalExecutable::create):
(JSC::CacheableEvalExecutable::CacheableEvalExecutable):

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/bytecode/EvalCodeCache.h

    r47304 r47405  
    4343    class EvalCodeCache {
    4444    public:
    45         PassRefPtr<EvalExecutable> get(ExecState* exec, const UString& evalSource, ScopeChainNode* scopeChain, JSValue& exceptionValue)
     45        PassRefPtr<CacheableEvalExecutable> get(ExecState* exec, const UString& evalSource, ScopeChainNode* scopeChain, JSValue& exceptionValue)
    4646        {
    47             RefPtr<EvalExecutable> evalExecutable;
     47            RefPtr<CacheableEvalExecutable> evalExecutable;
    4848
    4949            if (evalSource.size() < maxCacheableSourceLength && (*scopeChain->begin())->isVariableObject())
     
    5151
    5252            if (!evalExecutable) {
    53                 evalExecutable = new EvalExecutable(makeSource(evalSource));
     53                evalExecutable = CacheableEvalExecutable::create(makeSource(evalSource));
    5454                exceptionValue = evalExecutable->parse(exec);
    5555                if (exceptionValue)
     
    7575        static const int maxCacheEntries = 64;
    7676
    77         typedef HashMap<RefPtr<UString::Rep>, RefPtr<EvalExecutable> > EvalCacheMap;
     77        typedef HashMap<RefPtr<UString::Rep>, RefPtr<CacheableEvalExecutable> > EvalCacheMap;
    7878        EvalCacheMap m_cacheMap;
    7979    };
Note: See TracChangeset for help on using the changeset viewer.