Title: [89185] trunk/Source
Revision
89185
Author
[email protected]
Date
2011-06-17 21:41:55 -0700 (Fri, 17 Jun 2011)

Log Message

2011-06-17  Dmitry Lomov  <[email protected]>

        Reviewed by Adam Barth.

        https://bugs.webkit.org/show_bug.cgi?id=62653
        [V8][Chromium] Make StringCache in V8 bindings per-isolate
        This moves StringCache into V8BindingPerIsolateData.

        * bindings/v8/V8Binding.cpp:
        (WebCore::cachedStringCallback):
        (WebCore::StringCache::remove):
        (WebCore::StringCache::v8ExternalStringSlow):
        * bindings/v8/V8Binding.h:
        (WebCore::StringCache::StringCache):
        (WebCore::StringCache::v8ExternalString):
        (WebCore::StringCache::clearOnGC):
        (WebCore::V8BindingPerIsolateData::stringCache):
        (WebCore::v8ExternalString):
        * bindings/v8/V8GCController.cpp:
        (WebCore::V8GCController::gcPrologue):
2011-06-17  Dmitry Lomov  <[email protected]>

        Reviewed by Adam Barth.

        https://bugs.webkit.org/show_bug.cgi?id=62653
        [V8][Chromium] Make StringCache in V8 bindings per-isolate
        This moves StringCache into V8BindingPerIsolateData.

        * src/WebScriptController.cpp:
        (WebKit::WebScriptController::enableV8SingleThreadMode): StringCache is now per-isolate, so ok in multithreaded contexts.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (89184 => 89185)


--- trunk/Source/WebCore/ChangeLog	2011-06-18 04:25:57 UTC (rev 89184)
+++ trunk/Source/WebCore/ChangeLog	2011-06-18 04:41:55 UTC (rev 89185)
@@ -1,3 +1,24 @@
+2011-06-17  Dmitry Lomov  <[email protected]>
+
+        Reviewed by Adam Barth.
+
+        https://bugs.webkit.org/show_bug.cgi?id=62653
+        [V8][Chromium] Make StringCache in V8 bindings per-isolate
+        This moves StringCache into V8BindingPerIsolateData.
+
+        * bindings/v8/V8Binding.cpp:
+        (WebCore::cachedStringCallback):
+        (WebCore::StringCache::remove):
+        (WebCore::StringCache::v8ExternalStringSlow):
+        * bindings/v8/V8Binding.h:
+        (WebCore::StringCache::StringCache):
+        (WebCore::StringCache::v8ExternalString):
+        (WebCore::StringCache::clearOnGC):
+        (WebCore::V8BindingPerIsolateData::stringCache):
+        (WebCore::v8ExternalString):
+        * bindings/v8/V8GCController.cpp:
+        (WebCore::V8GCController::gcPrologue):
+
 2011-06-17  Julien Chaffraix  <[email protected]>
 
         Reviewed by Darin Adler.

Modified: trunk/Source/WebCore/bindings/v8/V8Binding.cpp (89184 => 89185)


--- trunk/Source/WebCore/bindings/v8/V8Binding.cpp	2011-06-18 04:25:57 UTC (rev 89184)
+++ trunk/Source/WebCore/bindings/v8/V8Binding.cpp	2011-06-18 04:41:55 UTC (rev 89185)
@@ -463,13 +463,6 @@
     return AtomicString(v8NonStringValueToWebCoreString(object));
 }
 
-static bool stringImplCacheEnabled = false;
-
-void enableStringImplCache()
-{
-    stringImplCacheEnabled = true;
-}
-
 static v8::Local<v8::String> makeExternalString(const String& string)
 {
     WebCoreStringResource* stringResource = new WebCoreStringResource(string);
@@ -480,43 +473,32 @@
     return newString;
 }
 
-typedef HashMap<StringImpl*, v8::String*> StringCache;
-
-static StringCache& getStringCache()
-{
-    ASSERT(WTF::isMainThread());
-    DEFINE_STATIC_LOCAL(StringCache, mainThreadStringCache, ());
-    return mainThreadStringCache;
-}
-
 static void cachedStringCallback(v8::Persistent<v8::Value> wrapper, void* parameter)
 {
-    ASSERT(WTF::isMainThread());
     StringImpl* stringImpl = static_cast<StringImpl*>(parameter);
-    ASSERT(getStringCache().contains(stringImpl));
-    getStringCache().remove(stringImpl);
+    V8BindingPerIsolateData::current()->stringCache()->remove(stringImpl);
     wrapper.Dispose();
     stringImpl->deref();
 }
 
-RefPtr<StringImpl> lastStringImpl = 0;
-v8::Persistent<v8::String> lastV8String;
+void StringCache::remove(StringImpl* stringImpl) 
+{
+    ASSERT(m_stringCache.contains(stringImpl));
+    m_stringCache.remove(stringImpl);
+}
 
-v8::Local<v8::String> v8ExternalStringSlow(StringImpl* stringImpl)
+
+v8::Local<v8::String> StringCache::v8ExternalStringSlow(StringImpl* stringImpl)
 {
     if (!stringImpl->length())
         return v8::String::Empty();
 
-    if (!stringImplCacheEnabled)
-        return makeExternalString(String(stringImpl));
-
-    StringCache& stringCache = getStringCache();
-    v8::String* cachedV8String = stringCache.get(stringImpl);
+    v8::String* cachedV8String = m_stringCache.get(stringImpl);
     if (cachedV8String) {
         v8::Persistent<v8::String> handle(cachedV8String);
         if (!handle.IsNearDeath() && !handle.IsEmpty()) {
-            lastStringImpl = stringImpl;
-            lastV8String = handle;
+            m_lastStringImpl = stringImpl;
+            m_lastV8String = handle;
             return v8::Local<v8::String>::New(handle);
         }
     }
@@ -531,10 +513,10 @@
 
     stringImpl->ref();
     wrapper.MakeWeak(stringImpl, cachedStringCallback);
-    stringCache.set(stringImpl, *wrapper);
+    m_stringCache.set(stringImpl, *wrapper);
 
-    lastStringImpl = stringImpl;
-    lastV8String = wrapper;
+    m_lastStringImpl = stringImpl;
+    m_lastV8String = wrapper;
 
     return newString;
 }

Modified: trunk/Source/WebCore/bindings/v8/V8Binding.h (89184 => 89185)


--- trunk/Source/WebCore/bindings/v8/V8Binding.h	2011-06-18 04:25:57 UTC (rev 89184)
+++ trunk/Source/WebCore/bindings/v8/V8Binding.h	2011-06-18 04:41:55 UTC (rev 89185)
@@ -50,6 +50,40 @@
     };
     typedef BindingSecurity<V8Binding> V8BindingSecurity;
 
+    class StringCache {
+    public:
+        StringCache() { }
+
+        v8::Local<v8::String> v8ExternalString(StringImpl* stringImpl) 
+        {
+            if (m_lastStringImpl.get() == stringImpl) {
+                ASSERT(!m_lastV8String.IsNearDeath());
+                ASSERT(!m_lastV8String.IsEmpty());
+                return v8::Local<v8::String>::New(m_lastV8String);
+            }
+
+            return v8ExternalStringSlow(stringImpl);
+        }
+
+        void clearOnGC() 
+        {
+            m_lastStringImpl = 0;
+            m_lastV8String.Clear();
+        }
+
+        void remove(StringImpl*);
+
+    private:
+        v8::Local<v8::String> v8ExternalStringSlow(StringImpl*);
+
+        HashMap<StringImpl*, v8::String*> m_stringCache;
+        v8::Persistent<v8::String> m_lastV8String;
+        // Note: RefPtr is a must as we cache by StringImpl* equality, not identity
+        // hence lastStringImpl might be not a key of the cache (in sense of identity)
+        // and hence it's not refed on addition.
+        RefPtr<StringImpl> m_lastStringImpl;
+    };
+
     class V8BindingPerIsolateData {
     public:
         static V8BindingPerIsolateData* create(v8::Isolate*);
@@ -72,6 +106,7 @@
         TemplateMap& templateMap() { return m_templates; }
         v8::Persistent<v8::String>& toStringName() { return m_toStringName; }
         v8::Persistent<v8::FunctionTemplate>& toStringTemplate() { return m_toStringTemplate; }
+        StringCache* stringCache() { return &m_stringCache; }
 
     private:
         explicit V8BindingPerIsolateData(v8::Isolate*);
@@ -81,6 +116,7 @@
         TemplateMap m_templates;
         v8::Persistent<v8::String> m_toStringName;
         v8::Persistent<v8::FunctionTemplate> m_toStringTemplate;
+        StringCache m_stringCache;
     };
 
 
@@ -110,13 +146,6 @@
     AtomicString v8NonStringValueToAtomicWebCoreString(v8::Handle<v8::Value>);
     AtomicString v8ValueToAtomicWebCoreString(v8::Handle<v8::Value> value);
 
-    // Note: RefPtr is a must as we cache by StringImpl* equality, not identity
-    // hence lastStringImpl might be not a key of the cache (in sense of identity)
-    // and hence it's not refed on addition.
-    extern RefPtr<StringImpl> lastStringImpl;
-    extern v8::Persistent<v8::String> lastV8String;
-    v8::Local<v8::String> v8ExternalStringSlow(StringImpl* stringImpl);
-
     // Return a V8 external string that shares the underlying buffer with the given
     // WebCore string. The reference counting mechanism is used to keep the
     // underlying buffer alive while the string is still live in the V8 engine.
@@ -126,13 +155,8 @@
         if (!stringImpl)
             return v8::String::Empty();
 
-        if (lastStringImpl.get() == stringImpl) {
-            ASSERT(!lastV8String.IsNearDeath());
-            ASSERT(!lastV8String.IsEmpty());
-            return v8::Local<v8::String>::New(lastV8String);
-        }
-
-        return v8ExternalStringSlow(stringImpl);
+        V8BindingPerIsolateData* data = ""
+        return data->stringCache()->v8ExternalString(stringImpl);
     }
 
     // Convert a string to a V8 string.

Modified: trunk/Source/WebCore/bindings/v8/V8GCController.cpp (89184 => 89185)


--- trunk/Source/WebCore/bindings/v8/V8GCController.cpp	2011-06-18 04:25:57 UTC (rev 89184)
+++ trunk/Source/WebCore/bindings/v8/V8GCController.cpp	2011-06-18 04:41:55 UTC (rev 89185)
@@ -467,8 +467,8 @@
     grouperVisitor.applyGrouping();
 
     // Clean single element cache for string conversions.
-    lastStringImpl = 0;
-    lastV8String.Clear();
+    V8BindingPerIsolateData* data = ""
+    data->stringCache()->clearOnGC();
 }
 
 class GCEpilogueVisitor : public DOMWrapperMap<void>::Visitor {

Modified: trunk/Source/WebKit/chromium/ChangeLog (89184 => 89185)


--- trunk/Source/WebKit/chromium/ChangeLog	2011-06-18 04:25:57 UTC (rev 89184)
+++ trunk/Source/WebKit/chromium/ChangeLog	2011-06-18 04:41:55 UTC (rev 89185)
@@ -1,3 +1,14 @@
+2011-06-17  Dmitry Lomov  <[email protected]>
+
+        Reviewed by Adam Barth.
+
+        https://bugs.webkit.org/show_bug.cgi?id=62653
+        [V8][Chromium] Make StringCache in V8 bindings per-isolate
+        This moves StringCache into V8BindingPerIsolateData.
+
+        * src/WebScriptController.cpp:
+        (WebKit::WebScriptController::enableV8SingleThreadMode): StringCache is now per-isolate, so ok in multithreaded contexts.
+
 2011-06-17  Ryosuke Niwa  <[email protected]>
 
         Roll Chromium DEPS.

Modified: trunk/Source/WebKit/chromium/src/WebScriptController.cpp (89184 => 89185)


--- trunk/Source/WebKit/chromium/src/WebScriptController.cpp	2011-06-18 04:25:57 UTC (rev 89184)
+++ trunk/Source/WebKit/chromium/src/WebScriptController.cpp	2011-06-18 04:41:55 UTC (rev 89185)
@@ -48,7 +48,6 @@
 
 void WebScriptController::enableV8SingleThreadMode()
 {
-    enableStringImplCache();
     enableFasterDOMStoreAccess();
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to