Changeset 88729 in webkit


Ignore:
Timestamp:
Jun 13, 2011 4:06:56 PM (13 years ago)
Author:
commit-queue@webkit.org
Message:

2011-06-13 Dmitry Lomov <dslomov@google.com>

Reviewed by Adam Barth.

https://bugs.webkit.org/show_bug.cgi?id=62345
Use per-isolate embedder data instead of statics for caches in bindings.
This is a prerequisite for more than one v8 isolate per process.

  • bindings/scripts/CodeGeneratorV8.pm:
  • bindings/v8/IDBBindingUtilities.cpp: (WebCore::createIDBKeyFromSerializedValueAndKeyPath): (WebCore::injectIDBKeyIntoSerializedValue):
  • bindings/v8/V8Binding.cpp: (WebCore::V8BindingPerIsolateData::V8BindingPerIsolateData): (WebCore::V8BindingPerIsolateData::~V8BindingPerIsolateData): (WebCore::V8BindingPerIsolateData::create): (WebCore::V8BindingPerIsolateData::ensureInitialized): (WebCore::V8BindingPerIsolateData::dispose): (WebCore::getToStringName): (WebCore::getToStringTemplate):
  • bindings/v8/V8Binding.h: (WebCore::V8BindingPerIsolateData::get): (WebCore::V8BindingPerIsolateData::current): (WebCore::V8BindingPerIsolateData::rawTemplateMap): (WebCore::V8BindingPerIsolateData::templateMap): (WebCore::V8BindingPerIsolateData::toStringName): (WebCore::V8BindingPerIsolateData::toStringTemplate):
  • bindings/v8/V8DOMWindowShell.cpp: (WebCore::V8DOMWindowShell::initContextIfNeeded):
  • bindings/v8/V8Utilities.cpp: (WebCore::V8LocalContext::V8LocalContext): (WebCore::V8LocalContext::~V8LocalContext):
  • bindings/v8/V8Utilities.h:
  • bindings/v8/WorkerContextExecutionProxy.cpp: (WebCore::WorkerContextExecutionProxy::initV8IfNeeded):

2011-06-13 Dmitry Lomov <dslomov@google.com>

Reviewed by Adam Barth.

https://bugs.webkit.org/show_bug.cgi?id=62345
Use per-isolate embedder data instead of statics for caches in bindings.
This is a prerequisite for more than one v8 isolate per process.

  • tests/IDBBindingUtilitiesTest.cpp: (WebCore::TEST):
Location:
trunk/Source
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r88727 r88729  
     12011-06-13  Dmitry Lomov  <dslomov@google.com>
     2
     3        Reviewed by Adam Barth.
     4
     5        https://bugs.webkit.org/show_bug.cgi?id=62345
     6        Use per-isolate embedder data instead of statics for caches in bindings.
     7        This is a prerequisite for more than one v8 isolate per process.
     8
     9        * bindings/scripts/CodeGeneratorV8.pm:
     10        * bindings/v8/IDBBindingUtilities.cpp:
     11        (WebCore::createIDBKeyFromSerializedValueAndKeyPath):
     12        (WebCore::injectIDBKeyIntoSerializedValue):
     13        * bindings/v8/V8Binding.cpp:
     14        (WebCore::V8BindingPerIsolateData::V8BindingPerIsolateData):
     15        (WebCore::V8BindingPerIsolateData::~V8BindingPerIsolateData):
     16        (WebCore::V8BindingPerIsolateData::create):
     17        (WebCore::V8BindingPerIsolateData::ensureInitialized):
     18        (WebCore::V8BindingPerIsolateData::dispose):
     19        (WebCore::getToStringName):
     20        (WebCore::getToStringTemplate):
     21        * bindings/v8/V8Binding.h:
     22        (WebCore::V8BindingPerIsolateData::get):
     23        (WebCore::V8BindingPerIsolateData::current):
     24        (WebCore::V8BindingPerIsolateData::rawTemplateMap):
     25        (WebCore::V8BindingPerIsolateData::templateMap):
     26        (WebCore::V8BindingPerIsolateData::toStringName):
     27        (WebCore::V8BindingPerIsolateData::toStringTemplate):
     28        * bindings/v8/V8DOMWindowShell.cpp:
     29        (WebCore::V8DOMWindowShell::initContextIfNeeded):
     30        * bindings/v8/V8Utilities.cpp:
     31        (WebCore::V8LocalContext::V8LocalContext):
     32        (WebCore::V8LocalContext::~V8LocalContext):
     33        * bindings/v8/V8Utilities.h:
     34        * bindings/v8/WorkerContextExecutionProxy.cpp:
     35        (WebCore::WorkerContextExecutionProxy::initV8IfNeeded):
     36
    1372011-06-13  Caio Marcelo de Oliveira Filho  <caio.oliveira@openbossa.org>
    238
  • trunk/Source/WebCore/bindings/scripts/CodeGeneratorV8.pm

    r87138 r88729  
    22022202v8::Persistent<v8::FunctionTemplate> ${className}::GetRawTemplate()
    22032203{
    2204     static v8::Persistent<v8::FunctionTemplate> ${className}RawCache = createRawTemplate();
    2205     return ${className}RawCache;
    2206 }
    2207 
    2208 v8::Persistent<v8::FunctionTemplate> ${className}::GetTemplate()\
    2209 {
    2210     static v8::Persistent<v8::FunctionTemplate> ${className}Cache = Configure${className}Template(GetRawTemplate());
    2211     return ${className}Cache;
     2204    V8BindingPerIsolateData* data = V8BindingPerIsolateData::current();
     2205    V8BindingPerIsolateData::TemplateMap::iterator result = data->rawTemplateMap().find(&info);
     2206    if (result != data->rawTemplateMap().end())
     2207        return result->second;
     2208
     2209    v8::HandleScope handleScope;
     2210    v8::Persistent<v8::FunctionTemplate> templ = createRawTemplate();
     2211    data->rawTemplateMap().add(&info, templ);
     2212    return templ;
     2213}
     2214
     2215v8::Persistent<v8::FunctionTemplate> ${className}::GetTemplate()
     2216{
     2217    V8BindingPerIsolateData* data = V8BindingPerIsolateData::current();
     2218    V8BindingPerIsolateData::TemplateMap::iterator result = data->templateMap().find(&info);
     2219    if (result != data->templateMap().end())
     2220        return result->second;
     2221
     2222    v8::HandleScope handleScope;
     2223    v8::Persistent<v8::FunctionTemplate> templ =
     2224        Configure${className}Template(GetRawTemplate());
     2225    data->templateMap().add(&info, templ);
     2226    return templ;
    22122227}
    22132228
  • trunk/Source/WebCore/bindings/v8/IDBBindingUtilities.cpp

    r78721 r88729  
    9999}
    100100
    101 class LocalContext {
    102 public:
    103     LocalContext()
    104         : m_context(v8::Context::New())
    105     {
    106         m_context->Enter();
    107     }
    108 
    109     ~LocalContext()
    110     {
    111         m_context->Exit();
    112         m_context.Dispose();
    113     }
    114 
    115 private:
    116     v8::HandleScope m_scope;
    117     v8::Persistent<v8::Context> m_context;
    118 };
    119 
    120101v8::Handle<v8::Value> getNthValueOnKeyPath(v8::Handle<v8::Value>& rootValue, const Vector<IDBKeyPathElement>& keyPathElements, size_t index)
    121102{
     
    135116PassRefPtr<IDBKey> createIDBKeyFromSerializedValueAndKeyPath(PassRefPtr<SerializedScriptValue> value, const Vector<IDBKeyPathElement>& keyPath)
    136117{
    137     LocalContext localContext;
     118    V8LocalContext localContext;
    138119    v8::Handle<v8::Value> v8Value(value->deserialize());
    139120    v8::Handle<v8::Value> v8Key(getNthValueOnKeyPath(v8Value, keyPath, keyPath.size()));
     
    145126PassRefPtr<SerializedScriptValue> injectIDBKeyIntoSerializedValue(PassRefPtr<IDBKey> key, PassRefPtr<SerializedScriptValue> value, const Vector<IDBKeyPathElement>& keyPath)
    146127{
    147     LocalContext localContext;
     128    V8LocalContext localContext;
    148129    if (!keyPath.size())
    149130        return 0;
  • trunk/Source/WebCore/bindings/v8/V8Binding.cpp

    r77597 r88729  
    4848namespace WebCore {
    4949
     50
     51V8BindingPerIsolateData::V8BindingPerIsolateData(v8::Isolate* isolate)
     52{
     53}
     54
     55V8BindingPerIsolateData::~V8BindingPerIsolateData()
     56{
     57}
     58
     59V8BindingPerIsolateData* V8BindingPerIsolateData::create(v8::Isolate* isolate)
     60{
     61    ASSERT(isolate);
     62    ASSERT(!isolate->GetData());
     63    V8BindingPerIsolateData* data = new V8BindingPerIsolateData(isolate);
     64    isolate->SetData(data);
     65    return data;
     66}
     67
     68void V8BindingPerIsolateData::ensureInitialized(v8::Isolate* isolate)
     69{
     70    ASSERT(isolate);
     71    if (!isolate->GetData())
     72        create(isolate);
     73}
     74
     75void V8BindingPerIsolateData::dispose(v8::Isolate* isolate)
     76{
     77    void* data = isolate->GetData();
     78    delete static_cast<V8BindingPerIsolateData*>(data);
     79    isolate->SetData(0);
     80}
     81
     82
     83
    5084// WebCoreStringResource is a helper class for v8ExternalString. It is used
    5185// to manage the life-cycle of the underlying buffer of the external string.
     
    541575v8::Persistent<v8::String> getToStringName()
    542576{
    543     DEFINE_STATIC_LOCAL(v8::Persistent<v8::String>, value, ());
    544     if (value.IsEmpty())
    545         value = v8::Persistent<v8::String>::New(v8::String::New("toString"));
    546     return value;
     577    v8::Persistent<v8::String>& toStringName = V8BindingPerIsolateData::current()->toStringName();
     578    if (toStringName.IsEmpty())
     579        toStringName = v8::Persistent<v8::String>::New(v8::String::New("toString"));
     580    return *toStringName;
     581
    547582}
    548583
     
    565600v8::Persistent<v8::FunctionTemplate> getToStringTemplate()
    566601{
    567     DEFINE_STATIC_LOCAL(v8::Persistent<v8::FunctionTemplate>, toStringTemplate, ());
     602    v8::Persistent<v8::FunctionTemplate>& toStringTemplate = V8BindingPerIsolateData::current()->toStringTemplate();
    568603    if (toStringTemplate.IsEmpty())
    569604        toStringTemplate = v8::Persistent<v8::FunctionTemplate>::New(v8::FunctionTemplate::New(constructorToString));
  • trunk/Source/WebCore/bindings/v8/V8Binding.h

    r77597 r88729  
    5151    typedef BindingSecurity<V8Binding> V8BindingSecurity;
    5252
     53    class V8BindingPerIsolateData {
     54    public:
     55        static V8BindingPerIsolateData* create(v8::Isolate*);
     56        static void ensureInitialized(v8::Isolate*);
     57        static V8BindingPerIsolateData* get(v8::Isolate* isolate)
     58        {
     59            ASSERT(isolate->GetData());
     60            return static_cast<V8BindingPerIsolateData*>(isolate->GetData());
     61        }
     62
     63        static V8BindingPerIsolateData* current()
     64        {
     65            return get(v8::Isolate::GetCurrent());
     66        }
     67        static void dispose(v8::Isolate*);
     68
     69        typedef HashMap<WrapperTypeInfo*, v8::Persistent<v8::FunctionTemplate> > TemplateMap;
     70
     71        TemplateMap& rawTemplateMap() { return m_rawTemplates; }
     72        TemplateMap& templateMap() { return m_templates; }
     73        v8::Persistent<v8::String>& toStringName() { return m_toStringName; }
     74        v8::Persistent<v8::FunctionTemplate>& toStringTemplate() { return m_toStringTemplate; }
     75
     76    private:
     77        explicit V8BindingPerIsolateData(v8::Isolate*);
     78        ~V8BindingPerIsolateData();
     79
     80        TemplateMap m_rawTemplates;
     81        TemplateMap m_templates;
     82        v8::Persistent<v8::String> m_toStringName;
     83        v8::Persistent<v8::FunctionTemplate> m_toStringTemplate;
     84    };
     85
     86
    5387    enum ExternalMode {
    5488        Externalize,
  • trunk/Source/WebCore/bindings/v8/V8DOMWindowShell.cpp

    r85484 r88729  
    300300
    301301        ScriptProfiler::initialize();
    302        
     302
     303        V8BindingPerIsolateData::ensureInitialized(v8::Isolate::GetCurrent());
     304
    303305        isV8Initialized = true;
    304306    }
    305 
    306307
    307308    m_context = createNewContext(m_global, 0);
  • trunk/Source/WebCore/bindings/v8/V8Utilities.cpp

    r82940 r88729  
    4848
    4949namespace WebCore {
     50
     51V8LocalContext::V8LocalContext()
     52{
     53    V8BindingPerIsolateData::ensureInitialized(v8::Isolate::GetCurrent());
     54    m_context.set(v8::Context::New());
     55    m_context.get()->Enter();
     56}
     57
     58
     59V8LocalContext::~V8LocalContext()
     60{
     61    m_context.get()->Exit();
     62}
    5063
    5164// Use an array to hold dependents. It works like a ref-counted scheme.
  • trunk/Source/WebCore/bindings/v8/V8Utilities.h

    r83115 r88729  
    3535#include <v8.h>
    3636
     37#include "OwnHandle.h"
     38
    3739namespace WebCore {
    3840
     
    6466
    6567    typedef unsigned CallbackAllowedValueFlags;
     68
     69    class V8LocalContext {
     70    public:
     71        V8LocalContext();
     72        virtual ~V8LocalContext();
     73    private:
     74        v8::HandleScope m_handleScope;
     75        OwnHandle<v8::Context> m_context;
     76    };
    6677
    6778    // 'FunctionOnly' is assumed for the created callback.
  • trunk/Source/WebCore/bindings/v8/WorkerContextExecutionProxy.cpp

    r83900 r88729  
    125125    v8::SetResourceConstraints(&resource_constraints);
    126126
     127    V8BindingPerIsolateData::create(v8::Isolate::GetCurrent());
     128
    127129    v8Initialized = true;
    128130}
  • trunk/Source/WebKit/chromium/ChangeLog

    • Property svn:executable deleted
    r88728 r88729  
     12011-06-13  Dmitry Lomov  <dslomov@google.com>
     2
     3        Reviewed by Adam Barth.
     4
     5        https://bugs.webkit.org/show_bug.cgi?id=62345
     6        Use per-isolate embedder data instead of statics for caches in bindings.
     7        This is a prerequisite for more than one v8 isolate per process.
     8
     9        * tests/IDBBindingUtilitiesTest.cpp:
     10        (WebCore::TEST):
     11
    1122011-06-13  Lei Zhang  <thestig@chromium.org>
    213
  • trunk/Source/WebKit/chromium/tests/IDBBindingUtilitiesTest.cpp

    r83331 r88729  
    2929#include "IDBKeyPath.h"
    3030#include "SerializedScriptValue.h"
     31#include "V8Utilities.h"
    3132
    3233#include <gtest/gtest.h>
     
    3839
    3940namespace {
    40 
    41 class LocalContext {
    42 public:
    43     LocalContext()
    44         : m_context(v8::Context::New())
    45     {
    46         m_context->Enter();
    47     }
    48 
    49     virtual ~LocalContext()
    50     {
    51         m_context->Exit();
    52         m_context.Dispose();
    53     }
    54 
    55 private:
    56     v8::HandleScope m_scope;
    57     v8::Persistent<v8::Context> m_context;
    58 };
    5941
    6042PassRefPtr<IDBKey> checkKeyFromValueAndKeyPathInternal(SerializedScriptValue* value, const String& keyPath)
     
    11496TEST(IDBKeyFromValueAndKeyPathTest, TopLevelPropertyStringValue)
    11597{
    116     LocalContext v8context;
     98    V8LocalContext v8context;
    11799    v8::Local<v8::Object> object = v8::Object::New();
    118100    object->Set(v8::String::New("foo"), v8::String::New("zoo"));
     
    127109TEST(IDBKeyFromValueAndKeyPathTest, TopLevelPropertyNumberValue)
    128110{
    129     LocalContext v8context;
     111    V8LocalContext v8context;
    130112    v8::Local<v8::Object> object = v8::Object::New();
    131113    object->Set(v8::String::New("foo"), v8::Number::New(456));
     
    140122TEST(IDBKeyFromValueAndKeyPathTest, TopLevelArrayElement)
    141123{
    142     LocalContext v8context;
     124    V8LocalContext v8context;
    143125    v8::Local<v8::Array> array = v8::Array::New();
    144126    array->Set(3, v8::String::New("zoo"));
     
    153135TEST(IDBKeyFromValueAndKeyPathTest, SubProperty)
    154136{
    155     LocalContext v8context;
     137    V8LocalContext v8context;
    156138    v8::Local<v8::Object> object = v8::Object::New();
    157139    v8::Local<v8::Object> subProperty = v8::Object::New();
     
    168150TEST(IDBKeyFromValueAndKeyPathTest, Array2D)
    169151{
    170     LocalContext v8context;
     152    V8LocalContext v8context;
    171153    v8::Local<v8::Object> object = v8::Object::New();
    172154    v8::Local<v8::Array> array = v8::Array::New();
     
    185167TEST(InjectIDBKeyTest, TopLevelPropertyStringValue)
    186168{
    187     LocalContext v8context;
     169    V8LocalContext v8context;
    188170    v8::Local<v8::Object> object = v8::Object::New();
    189171    object->Set(v8::String::New("foo"), v8::String::New("zoo"));
     
    198180TEST(InjectIDBKeyTest, TopLevelArrayElement)
    199181{
    200     LocalContext v8context;
     182    V8LocalContext v8context;
    201183    v8::Local<v8::Array> array = v8::Array::New();
    202184    array->Set(3, v8::String::New("zoo"));
     
    211193TEST(InjectIDBKeyTest, SubProperty)
    212194{
    213     LocalContext v8context;
     195    V8LocalContext v8context;
    214196    v8::Local<v8::Object> object = v8::Object::New();
    215197    v8::Local<v8::Object> subProperty = v8::Object::New();
     
    228210TEST(InjectIDBKeyTest, Array2D)
    229211{
    230     LocalContext v8context;
     212    V8LocalContext v8context;
    231213    v8::Local<v8::Object> object = v8::Object::New();
    232214    v8::Local<v8::Array> array = v8::Array::New();
Note: See TracChangeset for help on using the changeset viewer.