[V8] We should call the faster v8::Integer::New APIs
authorabarth@webkit.org <abarth@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 22 Oct 2012 22:50:36 +0000 (22:50 +0000)
committerabarth@webkit.org <abarth@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 22 Oct 2012 22:50:36 +0000 (22:50 +0000)
https://bugs.webkit.org/show_bug.cgi?id=100016

Reviewed by Eric Seidel.

In working to remove the integer cache, I added some faster APIs for
creating v8::Integers. These APIs are faster than the old APIs, but not
quite fast enough to replace the integer cache. We should still use
them when we miss the integer cache.

I've also included a small refactoring to V8PerIsolateData to make it
clearer when we're calling v8::Isolate::GetCurrent().

* bindings/v8/DOMData.cpp:
(WebCore::DOMData::getCurrentStore):
* bindings/v8/V8Binding.h:
(WebCore::v8ExternalString):
(WebCore::v8Integer):
(WebCore::v8UnsignedInteger):
* bindings/v8/V8PerIsolateData.h:
(WebCore::V8PerIsolateData::current):
(WebCore::V8PerIsolateData::from):
* bindings/v8/V8ValueCache.cpp:
(WebCore::StringCache::v8ExternalStringSlow):
(WebCore::IntegerCache::createSmallIntegers):
* bindings/v8/V8ValueCache.h:
(WebCore::IntegerCache::v8Integer):
(WebCore::IntegerCache::v8UnsignedInteger):
(IntegerCache):
* bindings/v8/custom/V8HTMLCanvasElementCustom.cpp:
(WebCore::V8HTMLCanvasElement::getContextCallback):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@132151 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/bindings/v8/DOMData.cpp
Source/WebCore/bindings/v8/V8Binding.h
Source/WebCore/bindings/v8/V8PerIsolateData.h
Source/WebCore/bindings/v8/V8ValueCache.cpp
Source/WebCore/bindings/v8/V8ValueCache.h
Source/WebCore/bindings/v8/custom/V8HTMLCanvasElementCustom.cpp

index 2f5fa7b..a1f3f0c 100644 (file)
@@ -1,3 +1,37 @@
+2012-10-22  Adam Barth  <abarth@webkit.org>
+
+        [V8] We should call the faster v8::Integer::New APIs
+        https://bugs.webkit.org/show_bug.cgi?id=100016
+
+        Reviewed by Eric Seidel.
+
+        In working to remove the integer cache, I added some faster APIs for
+        creating v8::Integers. These APIs are faster than the old APIs, but not
+        quite fast enough to replace the integer cache. We should still use
+        them when we miss the integer cache.
+
+        I've also included a small refactoring to V8PerIsolateData to make it
+        clearer when we're calling v8::Isolate::GetCurrent().
+
+        * bindings/v8/DOMData.cpp:
+        (WebCore::DOMData::getCurrentStore):
+        * bindings/v8/V8Binding.h:
+        (WebCore::v8ExternalString):
+        (WebCore::v8Integer):
+        (WebCore::v8UnsignedInteger):
+        * bindings/v8/V8PerIsolateData.h:
+        (WebCore::V8PerIsolateData::current):
+        (WebCore::V8PerIsolateData::from):
+        * bindings/v8/V8ValueCache.cpp:
+        (WebCore::StringCache::v8ExternalStringSlow):
+        (WebCore::IntegerCache::createSmallIntegers):
+        * bindings/v8/V8ValueCache.h:
+        (WebCore::IntegerCache::v8Integer):
+        (WebCore::IntegerCache::v8UnsignedInteger):
+        (IntegerCache):
+        * bindings/v8/custom/V8HTMLCanvasElementCustom.cpp:
+        (WebCore::V8HTMLCanvasElement::getContextCallback):
+
 2012-10-22  Julien Chaffraix  <jchaffraix@webkit.org>
 
         RenderTableCol::computePreferredLogicalWidths and RenderTableCol::layout should never be called
index af50a1e..da6ea5b 100644 (file)
@@ -40,7 +40,9 @@ namespace WebCore {
 DOMDataStore& DOMData::getCurrentStore(v8::Isolate* isolate)
 {
     DEFINE_STATIC_LOCAL(StaticDOMDataStore, defaultStore, ());
-    V8PerIsolateData* data = V8PerIsolateData::current(isolate);
+    if (UNLIKELY(!isolate))
+        isolate = v8::Isolate::GetCurrent();
+    V8PerIsolateData* data = V8PerIsolateData::from(isolate);
     if (UNLIKELY(data->domDataStore() != 0))
         return *data->domDataStore();
     V8DOMWindowShell* context = V8DOMWindowShell::getEntered();
index a40e75a..19ba8bf 100644 (file)
@@ -96,9 +96,9 @@ namespace WebCore {
         StringImpl* stringImpl = string.impl();
         if (!stringImpl)
             return isolate ? v8::String::Empty(isolate) : v8::String::Empty();
-
-        V8PerIsolateData* data = V8PerIsolateData::current(isolate);
-        return data->stringCache()->v8ExternalString(stringImpl, isolate);
+        if (UNLIKELY(!isolate))
+            isolate = v8::Isolate::GetCurrent();
+        return V8PerIsolateData::from(isolate)->stringCache()->v8ExternalString(stringImpl, isolate);
     }
 
     // Convert a string to a V8 string.
@@ -109,14 +109,16 @@ namespace WebCore {
 
     inline v8::Handle<v8::Integer> v8Integer(int value, v8::Isolate* isolate = 0)
     {
-        V8PerIsolateData* data = V8PerIsolateData::current(isolate);
-        return data->integerCache()->v8Integer(value);
+        if (UNLIKELY(!isolate))
+            isolate = v8::Isolate::GetCurrent();
+        return V8PerIsolateData::from(isolate)->integerCache()->v8Integer(value, isolate);
     }
 
     inline v8::Handle<v8::Integer> v8UnsignedInteger(unsigned value, v8::Isolate* isolate = 0)
     {
-        V8PerIsolateData* data = V8PerIsolateData::current(isolate);
-        return data->integerCache()->v8UnsignedInteger(value);
+        if (UNLIKELY(!isolate))
+            isolate = v8::Isolate::GetCurrent();
+        return V8PerIsolateData::from(isolate)->integerCache()->v8UnsignedInteger(value, isolate);
     }
 
     inline v8::Handle<v8::Value> v8Undefined()
index 1082986..b7d5f65 100644 (file)
@@ -52,10 +52,13 @@ class V8PerIsolateData {
 public:
     static V8PerIsolateData* create(v8::Isolate*);
     static void ensureInitialized(v8::Isolate*);
-    static V8PerIsolateData* current(v8::Isolate* isolate = 0)
+    static V8PerIsolateData* current()
     {
-        if (UNLIKELY(!isolate))
-            isolate = v8::Isolate::GetCurrent();
+        return from(v8::Isolate::GetCurrent());
+    }
+    static V8PerIsolateData* from(v8::Isolate* isolate)
+    {
+        ASSERT(isolate);
         ASSERT(isolate->GetData());
         return static_cast<V8PerIsolateData*>(isolate->GetData()); 
     }
index c636f2c..39cffc5 100644 (file)
@@ -61,7 +61,7 @@ void StringCache::remove(StringImpl* stringImpl)
 v8::Local<v8::String> StringCache::v8ExternalStringSlow(StringImpl* stringImpl, v8::Isolate* isolate)
 {
     if (!stringImpl->length())
-        return isolate ? v8::String::Empty(isolate) : v8::String::Empty();
+        return v8::String::Empty(isolate);
 
     v8::String* cachedV8String = m_stringCache.get(stringImpl);
     if (cachedV8String) {
@@ -99,14 +99,14 @@ void WebCoreStringResource::visitStrings(ExternalStringVisitor* visitor)
         visitor->visitJSExternalString(m_atomicString.impl());
 }
 
-void IntegerCache::createSmallIntegers()
+void IntegerCache::createSmallIntegers(v8::Isolate* isolate)
 {
     ASSERT(!m_initialized);
     // We initialize m_smallIntegers not in a constructor but in v8Integer(),
     // because Integer::New() requires a HandleScope. At the point where
     // IntegerCache is constructed, a HandleScope might not exist.
     for (int value = 0; value < numberOfCachedSmallIntegers; value++)
-        m_smallIntegers[value] = v8::Persistent<v8::Integer>::New(v8::Integer::New(value));
+        m_smallIntegers[value] = v8::Persistent<v8::Integer>::New(v8::Integer::New(value, isolate));
     m_initialized = true;
 }
 
index 72a1b70..671f68d 100644 (file)
@@ -156,26 +156,26 @@ public:
      IntegerCache() : m_initialized(false) { };
     ~IntegerCache();
 
-    v8::Handle<v8::Integer> v8Integer(int value)
+    v8::Handle<v8::Integer> v8Integer(int value, v8::Isolate* isolate)
     {
         if (!m_initialized)
-            createSmallIntegers();
+            createSmallIntegers(isolate);
         if (0 <= value && value < numberOfCachedSmallIntegers)
             return m_smallIntegers[value];
-        return v8::Integer::New(value);
+        return v8::Integer::New(value, isolate);
     }
 
-    v8::Handle<v8::Integer> v8UnsignedInteger(unsigned value)
+    v8::Handle<v8::Integer> v8UnsignedInteger(unsigned value, v8::Isolate* isolate)
     {
         if (!m_initialized)
-            createSmallIntegers();
+            createSmallIntegers(isolate);
         if (value < static_cast<unsigned>(numberOfCachedSmallIntegers))
             return m_smallIntegers[value];
-        return v8::Integer::NewFromUnsigned(value);
+        return v8::Integer::NewFromUnsigned(value, isolate);
     }
 
 private:
-    void createSmallIntegers();
+    void createSmallIntegers(v8::Isolate*);
 
     v8::Persistent<v8::Integer> m_smallIntegers[numberOfCachedSmallIntegers];
     bool m_initialized;
index 14ad4ab..01e4764 100644 (file)
@@ -101,7 +101,7 @@ v8::Handle<v8::Value> V8HTMLCanvasElement::getContextCallback(const v8::Argument
         // 3D canvas contexts can hold on to lots of GPU resources, and we want to take an
         // opportunity to get rid of them as soon as possible when we navigate away from pages using
         // them.
-        V8PerIsolateData* perIsolateData = V8PerIsolateData::current(args.GetIsolate());
+        V8PerIsolateData* perIsolateData = V8PerIsolateData::from(args.GetIsolate());
         perIsolateData->setShouldCollectGarbageSoon();
 
         v8::Handle<v8::Value> v8Result = toV8(static_cast<WebGLRenderingContext*>(result), args.Holder(), args.GetIsolate());