Title: [100375] trunk/Source/_javascript_Core
Revision
100375
Author
[email protected]
Date
2011-11-15 17:25:17 -0800 (Tue, 15 Nov 2011)

Log Message

Removed a use of ArgList that baked in the assumption that arguments
are forward in the regiter file.

Reviewed by Sam Weinig.

* dfg/DFGOperations.cpp:
* jit/JITStubs.cpp:
(JSC::DEFINE_STUB_FUNCTION): Use new API.

* runtime/ArgList.cpp:
(JSC::ArgList::getSlice): No need to provide an arbitrary constructor --
getSlice can do the right thing by using its rights to private data.

* runtime/ArgList.h: Removed constructor that took a forward-contiguous
set of arguments.

* runtime/JSArray.cpp:
(JSC::JSArray::finishCreation):
* runtime/JSArray.h:
(JSC::JSArray::create):
* runtime/JSGlobalObject.h:
(JSC::constructArray): Added explicit support for creating an array from
a pre-allocated set of values, so we could stop relying on the ArgList
API we want to remove.

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (100374 => 100375)


--- trunk/Source/_javascript_Core/ChangeLog	2011-11-16 01:23:19 UTC (rev 100374)
+++ trunk/Source/_javascript_Core/ChangeLog	2011-11-16 01:25:17 UTC (rev 100375)
@@ -1,3 +1,30 @@
+2011-11-15  Geoffrey Garen  <[email protected]>
+
+        Removed a use of ArgList that baked in the assumption that arguments
+        are forward in the regiter file.
+
+        Reviewed by Sam Weinig.
+
+        * dfg/DFGOperations.cpp:
+        * jit/JITStubs.cpp:
+        (JSC::DEFINE_STUB_FUNCTION): Use new API.
+
+        * runtime/ArgList.cpp:
+        (JSC::ArgList::getSlice): No need to provide an arbitrary constructor --
+        getSlice can do the right thing by using its rights to private data.
+
+        * runtime/ArgList.h: Removed constructor that took a forward-contiguous
+        set of arguments.
+
+        * runtime/JSArray.cpp:
+        (JSC::JSArray::finishCreation):
+        * runtime/JSArray.h:
+        (JSC::JSArray::create):
+        * runtime/JSGlobalObject.h:
+        (JSC::constructArray): Added explicit support for creating an array from
+        a pre-allocated set of values, so we could stop relying on the ArgList
+        API we want to remove.
+
 2011-11-15  Filip Pizlo  <[email protected]>
 
         Crash in JSC::DFG::OSRExitCompiler::compileExit(JSC::DFG::OSRExit const&, JSC::DFG::SpeculationRecovery*)

Modified: trunk/Source/_javascript_Core/dfg/DFGOperations.cpp (100374 => 100375)


--- trunk/Source/_javascript_Core/dfg/DFGOperations.cpp	2011-11-16 01:23:19 UTC (rev 100374)
+++ trunk/Source/_javascript_Core/dfg/DFGOperations.cpp	2011-11-16 01:25:17 UTC (rev 100375)
@@ -779,8 +779,7 @@
 
 EncodedJSValue DFG_OPERATION operationNewArrayBuffer(ExecState* exec, size_t start, size_t size)
 {
-    ArgList argList(exec->codeBlock()->constantBuffer(start), size);
-    return JSValue::encode(constructArray(exec, argList));
+    return constructArray(exec, exec->codeBlock()->constantBuffer(start), size);
 }
 
 EncodedJSValue DFG_OPERATION operationNewRegexp(ExecState* exec, void* regexpPtr)

Modified: trunk/Source/_javascript_Core/jit/JITStubs.cpp (100374 => 100375)


--- trunk/Source/_javascript_Core/jit/JITStubs.cpp	2011-11-16 01:23:19 UTC (rev 100374)
+++ trunk/Source/_javascript_Core/jit/JITStubs.cpp	2011-11-16 01:25:17 UTC (rev 100375)
@@ -2440,8 +2440,7 @@
 {
     STUB_INIT_STACK_FRAME(stackFrame);
     
-    ArgList argList(stackFrame.callFrame->codeBlock()->constantBuffer(stackFrame.args[0].int32()), stackFrame.args[1].int32());
-    return constructArray(stackFrame.callFrame, argList);
+    return constructArray(stackFrame.callFrame, stackFrame.callFrame->codeBlock()->constantBuffer(stackFrame.args[0].int32()), stackFrame.args[1].int32());
 }
 
 DEFINE_STUB_FUNCTION(EncodedJSValue, op_resolve)

Modified: trunk/Source/_javascript_Core/runtime/ArgList.cpp (100374 => 100375)


--- trunk/Source/_javascript_Core/runtime/ArgList.cpp	2011-11-16 01:23:19 UTC (rev 100374)
+++ trunk/Source/_javascript_Core/runtime/ArgList.cpp	2011-11-16 01:25:17 UTC (rev 100375)
@@ -33,10 +33,12 @@
 void ArgList::getSlice(int startIndex, ArgList& result) const
 {
     if (startIndex <= 0 || static_cast<unsigned>(startIndex) >= m_argCount) {
-        result = ArgList(m_args, 0);
+        result = ArgList();
         return;
     }
-    result = ArgList(m_args + startIndex, m_argCount - startIndex);
+
+    result.m_args = m_args + startIndex;
+    result.m_argCount =  m_argCount - startIndex;
 }
 
 void MarkedArgumentBuffer::markLists(HeapRootVisitor& heapRootVisitor, ListSet& markSet)

Modified: trunk/Source/_javascript_Core/runtime/ArgList.h (100374 => 100375)


--- trunk/Source/_javascript_Core/runtime/ArgList.h	2011-11-16 01:23:19 UTC (rev 100374)
+++ trunk/Source/_javascript_Core/runtime/ArgList.h	2011-11-16 01:25:17 UTC (rev 100375)
@@ -191,12 +191,6 @@
         {
         }
         
-        ArgList(JSValue* args, unsigned argCount)
-            : m_args(args)
-            , m_argCount(argCount)
-        {
-        }
-        
         ArgList(Register* args, int argCount)
             : m_args(reinterpret_cast<JSValue*>(args))
             , m_argCount(argCount)

Modified: trunk/Source/_javascript_Core/runtime/JSArray.cpp (100374 => 100375)


--- trunk/Source/_javascript_Core/runtime/JSArray.cpp	2011-11-16 01:23:19 UTC (rev 100374)
+++ trunk/Source/_javascript_Core/runtime/JSArray.cpp	2011-11-16 01:25:17 UTC (rev 100375)
@@ -236,6 +236,46 @@
     Heap::heap(this)->reportExtraMemoryCost(storageSize(initialStorage));
 }
 
+void JSArray::finishCreation(JSGlobalData& globalData, const JSValue* values, size_t length)
+{
+    Base::finishCreation(globalData);
+    ASSERT(inherits(&s_info));
+
+    unsigned initialCapacity = length;
+    unsigned initialStorage;
+    
+    // If the ArgList is empty, allocate space for 3 entries.  This value empirically
+    // works well for benchmarks.
+    if (!initialCapacity)
+        initialStorage = 3;
+    else
+        initialStorage = initialCapacity;
+    
+    m_storage = static_cast<ArrayStorage*>(fastMalloc(storageSize(initialStorage)));
+    m_storage->m_allocBase = m_storage;
+    m_indexBias = 0;
+    m_storage->m_length = initialCapacity;
+    m_vectorLength = initialStorage;
+    m_storage->m_numValuesInVector = initialCapacity;
+    m_storage->m_sparseValueMap = 0;
+    m_storage->subclassData = 0;
+    m_storage->reportedMapCapacity = 0;
+#if CHECK_ARRAY_CONSISTENCY
+    m_storage->m_inCompactInitialization = false;
+#endif
+
+    size_t i = 0;
+    WriteBarrier<Unknown>* vector = m_storage->m_vector;
+    for ( ; i != length; ++i)
+        vector[i].set(globalData, this, values[i]);
+    for (; i < initialStorage; i++)
+        vector[i].clear();
+
+    checkConsistency();
+
+    Heap::heap(this)->reportExtraMemoryCost(storageSize(initialStorage));
+}
+
 JSArray::~JSArray()
 {
     ASSERT(vptr() == JSGlobalData::jsArrayVPtr);

Modified: trunk/Source/_javascript_Core/runtime/JSArray.h (100374 => 100375)


--- trunk/Source/_javascript_Core/runtime/JSArray.h	2011-11-16 01:23:19 UTC (rev 100374)
+++ trunk/Source/_javascript_Core/runtime/JSArray.h	2011-11-16 01:25:17 UTC (rev 100375)
@@ -66,6 +66,7 @@
         void finishCreation(JSGlobalData&);
         void finishCreation(JSGlobalData&, unsigned initialLength, ArrayCreationMode);
         void finishCreation(JSGlobalData&, const ArgList&);
+        void finishCreation(JSGlobalData&, const JSValue*, size_t length);
     
     public:
         typedef JSNonFinalObject Base;
@@ -94,6 +95,13 @@
             return array;
         }
 
+        static JSArray* create(JSGlobalData& globalData, Structure* structure, const JSValue* values, size_t length)
+        {
+            JSArray* array = new (allocateCell<JSArray>(globalData.heap)) JSArray(globalData, structure);
+            array->finishCreation(globalData, values, length);
+            return array;
+        }
+
         static bool getOwnPropertySlot(JSCell*, ExecState*, const Identifier& propertyName, PropertySlot&);
         static bool getOwnPropertySlotByIndex(JSCell*, ExecState*, unsigned propertyName, PropertySlot&);
         static bool getOwnPropertyDescriptor(JSObject*, ExecState*, const Identifier&, PropertyDescriptor&);

Modified: trunk/Source/_javascript_Core/runtime/JSGlobalObject.h (100374 => 100375)


--- trunk/Source/_javascript_Core/runtime/JSGlobalObject.h	2011-11-16 01:23:19 UTC (rev 100374)
+++ trunk/Source/_javascript_Core/runtime/JSGlobalObject.h	2011-11-16 01:25:17 UTC (rev 100375)
@@ -473,6 +473,11 @@
         return constructArray(exec, exec->lexicalGlobalObject(), values);
     }
 
+    inline JSArray* constructArray(ExecState* exec, const JSValue* values, size_t length)
+    {
+        return JSArray::create(exec->globalData(), exec->lexicalGlobalObject()->arrayStructure(), values, length);
+    }
+
     class DynamicGlobalObjectScope {
         WTF_MAKE_NONCOPYABLE(DynamicGlobalObjectScope);
     public:
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to