Changeset 36267 in webkit for trunk/JavaScriptCore/VM/CodeBlock.h


Ignore:
Timestamp:
Sep 8, 2008, 5:17:33 AM (17 years ago)
Author:
[email protected]
Message:

JavaScriptCore:

2008-09-08 Maciej Stachowiak <[email protected]>

Reviewed by Anders Carlsson.



1.052x on SunSpider
2.29x on date-format-tofte


Lots of real sites seem to get many hits on this cache as well,
including GMail, Google Spreadsheets, Slate and Digg (the last of
these gets over 100 hits on initial page load).

  • VM/CodeBlock.h: (JSC::EvalCodeCache::get):
  • VM/Machine.cpp: (JSC::Machine::callEval): (JSC::Machine::privateExecute): (JSC::Machine::cti_op_call_eval):
  • VM/Machine.h:

LayoutTests:

2008-09-08 Maciej Stachowiak <[email protected]>

Reviewed by Anders Carlsson.

  • fast/js/eval-cache-crash-expected.txt: Added.
  • fast/js/eval-cache-crash.html: Added.
  • fast/js/resources/eval-cache-crash.js: Added.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/VM/CodeBlock.h

    r36263 r36267  
    3434#include "JSGlobalObject.h"
    3535#include "nodes.h"
     36#include "Parser.h"
    3637#include "SourceRange.h"
    3738#include "ustring.h"
     
    128129        }
    129130#endif
     131    };
     132
     133    class EvalCodeCache {
     134    public:
     135        PassRefPtr<EvalNode> get(ExecState* exec, const UString& evalSource, ScopeChainNode* scopeChain, JSValue*& exceptionValue)
     136        {
     137            RefPtr<EvalNode> evalNode;
     138
     139            if (evalSource.size() < maxCacheableSourceLength && (*scopeChain->begin())->isVariableObject())
     140                evalNode = cacheMap.get(evalSource.rep());
     141
     142            if (!evalNode) {
     143                int sourceId;
     144                int errLine;
     145                UString errMsg;
     146               
     147                evalNode = exec->parser()->parse<EvalNode>(exec, UString(), 1, UStringSourceProvider::create(evalSource), &sourceId, &errLine, &errMsg);
     148                if (evalNode) {
     149                    if (evalSource.size() < maxCacheableSourceLength && (*scopeChain->begin())->isVariableObject() && cacheMap.size() < maxCacheEntries)
     150                        cacheMap.set(evalSource.rep(), evalNode);
     151                } else {
     152                    exceptionValue = Error::create(exec, SyntaxError, errMsg, errLine, sourceId, NULL);
     153                    return 0;
     154                }
     155            }
     156
     157            return evalNode.release();
     158        }
     159
     160    private:
     161        static const int maxCacheableSourceLength = 256;
     162        static const int maxCacheEntries = 64;
     163
     164        HashMap<RefPtr<UString::Rep>, RefPtr<EvalNode> > cacheMap;
    130165    };
    131166
     
    208243#endif
    209244
     245        EvalCodeCache evalCodeCache;
     246
    210247    private:
    211248#if !defined(NDEBUG) || ENABLE(SAMPLING_TOOL)
    212249        void dump(ExecState*, const Vector<Instruction>::const_iterator& begin, Vector<Instruction>::const_iterator&) const;
    213250#endif
     251
    214252    };
    215253
Note: See TracChangeset for help on using the changeset viewer.