Changeset 61405 in webkit


Ignore:
Timestamp:
Jun 18, 2010 8:00:29 AM (14 years ago)
Author:
eric@webkit.org
Message:

2010-06-18 Tony Gentilcore <tonyg@chromium.org>

Reviewed by David Levin.

Persist V8's ScriptData to the memory cache.
https://bugs.webkit.org/show_bug.cgi?id=38661

When V8 ScriptData caching was originally submitted it causes crashes
in external scripts with high-byte characters. This new test crashes on
the original code, but now passes.

  • fast/js/parser-high-byte-character-expected.txt: Added.
  • fast/js/parser-high-byte-character.html: Added.
  • fast/js/script-tests/parser-high-byte-character.js: Added. (runTest):

2010-06-18 Tony Gentilcore <tonyg@chromium.org>

Reviewed by David Levin.

Persist V8's ScriptData to the memory cache.
https://bugs.webkit.org/show_bug.cgi?id=38661

This stores V8's ScriptData in the memory cache and also causes the
network platform layer to be notified of the available cacheable
metadata.

Chromium's morejs benchmark showed a ~7% improvement when this was
originally submitted (before it had to be rolled back).

Test: fast/js/parser-high-byte-character.html

  • bindings/v8/ScriptSourceCode.h: (WebCore::ScriptSourceCode::ScriptSourceCode): (WebCore::ScriptSourceCode::cachedScript):
  • bindings/v8/V8Proxy.cpp: (WebCore::V8Proxy::compileScript): (WebCore::V8Proxy::precompileScript): (WebCore::V8Proxy::evaluate):
  • bindings/v8/V8Proxy.h:
Location:
trunk
Files:
3 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r61403 r61405  
     12010-06-18  Tony Gentilcore  <tonyg@chromium.org>
     2
     3        Reviewed by David Levin.
     4
     5        Persist V8's ScriptData to the memory cache.
     6        https://bugs.webkit.org/show_bug.cgi?id=38661
     7
     8        When V8 ScriptData caching was originally submitted it causes crashes
     9        in external scripts with high-byte characters. This new test crashes on
     10        the original code, but now passes.
     11
     12        * fast/js/parser-high-byte-character-expected.txt: Added.
     13        * fast/js/parser-high-byte-character.html: Added.
     14        * fast/js/script-tests/parser-high-byte-character.js: Added.
     15        (runTest):
     16
    1172010-06-18  Dirk Schulze  <krit@webkit.org>
    218
  • trunk/WebCore/ChangeLog

    r61402 r61405  
     12010-06-18  Tony Gentilcore  <tonyg@chromium.org>
     2
     3        Reviewed by David Levin.
     4
     5        Persist V8's ScriptData to the memory cache.
     6        https://bugs.webkit.org/show_bug.cgi?id=38661
     7
     8        This stores V8's ScriptData in the memory cache and also causes the
     9        network platform layer to be notified of the available cacheable
     10        metadata.
     11
     12        Chromium's morejs benchmark showed a ~7% improvement when this was
     13        originally submitted (before it had to be rolled back).
     14
     15        Test: fast/js/parser-high-byte-character.html
     16
     17        * bindings/v8/ScriptSourceCode.h:
     18        (WebCore::ScriptSourceCode::ScriptSourceCode):
     19        (WebCore::ScriptSourceCode::cachedScript):
     20        * bindings/v8/V8Proxy.cpp:
     21        (WebCore::V8Proxy::compileScript):
     22        (WebCore::V8Proxy::precompileScript):
     23        (WebCore::V8Proxy::evaluate):
     24        * bindings/v8/V8Proxy.h:
     25
    1262010-06-18  Anton Muhin  <antonm@chromium.org>
    227
  • trunk/WebCore/bindings/v8/ScriptSourceCode.h

    r60728 r61405  
    3232#define ScriptSourceCode_h
    3333
     34#include "CachedResourceHandle.h"
    3435#include "CachedScript.h"
    3536#include "KURL.h"
     
    4243    ScriptSourceCode(const String& source, const KURL& url = KURL(), int startLine = 1)
    4344        : m_source(source)
     45        , m_cachedScript(0)
    4446        , m_url(url)
    4547        , m_startLine(startLine)
     
    5153    ScriptSourceCode(CachedScript* cs)
    5254        : m_source(cs->script())
     55        , m_cachedScript(cs)
    5356        , m_url(ParsedURLString, cs->url())
    5457        , m_startLine(1)
     
    5962
    6063    const String& source() const { return m_source; }
     64    CachedScript* cachedScript() const { return m_cachedScript.get(); }
    6165    const KURL& url() const { return m_url; }
    6266    int startLine() const { return m_startLine; }
     
    6468private:
    6569    String m_source;
     70    CachedResourceHandle<CachedScript> m_cachedScript;
    6671    KURL m_url;
    6772    int m_startLine;
  • trunk/WebCore/bindings/v8/V8Proxy.cpp

    r61337 r61405  
    3333
    3434#include "CSSMutableStyleDeclaration.h"
     35#include "CachedMetadata.h"
    3536#include "DateExtension.h"
    3637#include "DocumentLoader.h"
     
    7071#include <wtf/Assertions.h>
    7172#include <wtf/OwnArrayPtr.h>
     73#include <wtf/OwnPtr.h>
    7274#include <wtf/StdLibExtras.h>
    7375#include <wtf/StringExtras.h>
     
    233235}
    234236
    235 v8::Handle<v8::Script> V8Proxy::compileScript(v8::Handle<v8::String> code, const String& fileName, int baseLine)
     237v8::Handle<v8::Script> V8Proxy::compileScript(v8::Handle<v8::String> code, const String& fileName, int baseLine, v8::ScriptData* scriptData)
    236238{
    237239    const uint16_t* fileNameString = fromWebCoreString(fileName);
     
    239241    v8::Handle<v8::Integer> line = v8::Integer::New(baseLine);
    240242    v8::ScriptOrigin origin(name, line);
    241     v8::Handle<v8::Script> script = v8::Script::Compile(code, &origin);
     243    v8::Handle<v8::Script> script = v8::Script::Compile(code, &origin, scriptData);
    242244    return script;
    243245}
     
    338340}
    339341
     342PassOwnPtr<v8::ScriptData> V8Proxy::precompileScript(v8::Handle<v8::String> code, CachedScript* cachedScript)
     343{
     344    // A pseudo-randomly chosen ID used to store and retrieve V8 ScriptData from
     345    // the CachedScript. If the format changes, this ID should be changed too.
     346    static const unsigned dataTypeID = 0xECC13BD7;
     347
     348    // Very small scripts are not worth the effort to preparse.
     349    static const unsigned minPreparseLength = 1024;
     350
     351    if (!cachedScript || code->Length() < minPreparseLength)
     352        return 0;
     353
     354    CachedMetadata* cachedMetadata = cachedScript->cachedMetadata(dataTypeID);
     355    if (cachedMetadata)
     356        return v8::ScriptData::New(cachedMetadata->data(), cachedMetadata->size());
     357
     358    OwnPtr<v8::ScriptData> scriptData(v8::ScriptData::PreCompile(code));
     359    cachedScript->setCachedMetadata(dataTypeID, scriptData->Data(), scriptData->Length());
     360
     361    return scriptData.release();
     362}
     363
    340364v8::Local<v8::Value> V8Proxy::evaluate(const ScriptSourceCode& source, Node* node)
    341365{
     
    363387        PlatformBridge::traceEventBegin("v8.compile", node, "");
    364388#endif
     389        OwnPtr<v8::ScriptData> scriptData = precompileScript(code, source.cachedScript());
    365390
    366391        // NOTE: For compatibility with WebCore, ScriptSourceCode's line starts at
    367392        // 1, whereas v8 starts at 0.
    368         v8::Handle<v8::Script> script = compileScript(code, source.url(), source.startLine() - 1);
     393        v8::Handle<v8::Script> script = compileScript(code, source.url(), source.startLine() - 1, scriptData.get());
    369394#if PLATFORM(CHROMIUM)
    370395        PlatformBridge::traceEventEnd("v8.compile", node, "");
  • trunk/WebCore/bindings/v8/V8Proxy.h

    r61337 r61405  
    5454namespace WebCore {
    5555
     56    class CachedScript;
    5657    class DOMWindow;
    5758    class Frame;
     
    286287        static v8::Handle<v8::Value> checkNewLegal(const v8::Arguments&);
    287288
    288         static v8::Handle<v8::Script> compileScript(v8::Handle<v8::String> code, const String& fileName, int baseLine);
     289        static v8::Handle<v8::Script> compileScript(v8::Handle<v8::String> code, const String& fileName, int baseLine, v8::ScriptData* = 0);
    289290
    290291        // If the exception code is different from zero, a DOM exception is
     
    342343        void resetIsolatedWorlds();
    343344
     345        PassOwnPtr<v8::ScriptData> precompileScript(v8::Handle<v8::String>, CachedScript*);
     346
    344347        // Returns false when we're out of memory in V8.
    345348        bool setInjectedScriptContextDebugId(v8::Handle<v8::Context> targetContext);
Note: See TracChangeset for help on using the changeset viewer.