Ignore:
Timestamp:
Jan 25, 2011, 10:44:11 AM (14 years ago)
Author:
Antti Koivisto
Message:

REGRESSION: Leak in JSParser::Scope::copyCapturedVariablesToVector()
https://bugs.webkit.org/show_bug.cgi?id=53061

Reviewed by Oliver Hunt.

Cache did not know about the subclass so failed to fully delete the items.
Got rid of the subclass and moved the classes to separate files.

(JSC::JSParser::Scope::saveFunctionInfo):
(JSC::JSParser::Scope::restoreFunctionInfo):
(JSC::JSParser::findCachedFunctionInfo):
(JSC::JSParser::parseFunctionInfo):

  • parser/SourceProvider.h:
  • parser/SourceProviderCache.cpp: Added.

(JSC::SourceProviderCache::~SourceProviderCache):
(JSC::SourceProviderCache::byteSize):

  • parser/SourceProviderCache.h: Added.

(JSC::SourceProviderCache::SourceProviderCache):
(JSC::SourceProviderCache::add):
(JSC::SourceProviderCache::get):

  • parser/SourceProviderCacheItem.h: Added.

(JSC::SourceProviderCacheItem::SourceProviderCacheItem):
(JSC::SourceProviderCacheItem::approximateByteSize):
(JSC::SourceProviderCacheItem::closeBraceToken):

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/parser/JSParser.cpp

    r76376 r76611  
    3535#include "ASTBuilder.h"
    3636#include "SourceProvider.h"
     37#include "SourceProviderCacheItem.h"
    3738#include <wtf/HashFunctions.h>
    3839#include <wtf/WTFThreadData.h>
     
    9798    };
    9899   
    99     struct CachedFunctionInfo : public SourceProviderCache::Item {
    100         CachedFunctionInfo(int closeBraceLine, int closeBracePos)
    101             : closeBraceLine(closeBraceLine)
    102             , closeBracePos(closeBracePos)
    103         {
    104         }
    105         unsigned approximateByteSize() const
    106         {
    107             // The identifiers are uniqued strings so most likely there are few names that actually use any additional memory.
    108             static const unsigned assummedAverageIdentifierSize = sizeof(RefPtr<StringImpl>) + 2;
    109             unsigned size = sizeof(*this);
    110             size += usedVariables.size() * assummedAverageIdentifierSize;
    111             size += writtenVariables.size() * assummedAverageIdentifierSize;
    112             return size;
    113         }
    114         JSToken closeBraceToken() const
    115         {
    116             JSToken token;
    117             token.m_type = CLOSEBRACE;
    118             token.m_data.intValue = closeBracePos;
    119             token.m_info.startOffset = closeBracePos;
    120             token.m_info.endOffset = closeBracePos + 1;
    121             token.m_info.line = closeBraceLine;
    122             return token;
    123         }
    124 
    125         int closeBraceLine;
    126         int closeBracePos;
    127         bool usesEval;
    128         Vector<RefPtr<StringImpl> > usedVariables;
    129         Vector<RefPtr<StringImpl> > writtenVariables;
    130     };
    131 
    132100    void next(Lexer::LexType lexType = Lexer::IdentifyReservedWords)
    133101    {
     
    464432        }
    465433
    466         void saveFunctionInfo(CachedFunctionInfo* info)
     434        void saveFunctionInfo(SourceProviderCacheItem* info)
    467435        {
    468436            ASSERT(m_isFunction);
     
    472440        }
    473441
    474         void restoreFunctionInfo(const CachedFunctionInfo* info)
     442        void restoreFunctionInfo(const SourceProviderCacheItem* info)
    475443        {
    476444            ASSERT(m_isFunction);
     
    610578    ScopeStack m_scopeStack;
    611579
    612     const CachedFunctionInfo* findCachedFunctionInfo(int openBracePos)
     580    const SourceProviderCacheItem* findCachedFunctionInfo(int openBracePos)
    613581    {
    614         return m_functionCache ? static_cast<const CachedFunctionInfo*>(m_functionCache->get(openBracePos)) : 0;
     582        return m_functionCache ? m_functionCache->get(openBracePos) : 0;
    615583    }
    616584
     
    13191287    bodyStartLine = tokenLine();
    13201288
    1321     if (const CachedFunctionInfo* cachedInfo = TreeBuilder::CanUseFunctionCache ? findCachedFunctionInfo(openBracePos) : 0) {
     1289    if (const SourceProviderCacheItem* cachedInfo = TreeBuilder::CanUseFunctionCache ? findCachedFunctionInfo(openBracePos) : 0) {
    13221290        // If we know about this function already, we can use the cached info and skip the parser to the end of the function.
    13231291        body = context.createFunctionBody(strictMode());
     
    13481316    // Any future reparsing can then skip the function.
    13491317    static const int minimumFunctionLengthToCache = 64;
    1350     OwnPtr<CachedFunctionInfo> newInfo;
     1318    OwnPtr<SourceProviderCacheItem> newInfo;
    13511319    int functionLength = closeBracePos - openBracePos;
    13521320    if (TreeBuilder::CanUseFunctionCache && m_functionCache && functionLength > minimumFunctionLengthToCache) {
    1353         newInfo = adoptPtr(new CachedFunctionInfo(m_token.m_info.line, closeBracePos));
     1321        newInfo = adoptPtr(new SourceProviderCacheItem(m_token.m_info.line, closeBracePos));
    13541322        functionScope->saveFunctionInfo(newInfo.get());
    13551323    }
Note: See TracChangeset for help on using the changeset viewer.