[JSC] Thread VM& to JSCell::methodTable(VM&)
authorutatane.tea@gmail.com <utatane.tea@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 12 Jul 2018 08:43:38 +0000 (08:43 +0000)
committerutatane.tea@gmail.com <utatane.tea@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 12 Jul 2018 08:43:38 +0000 (08:43 +0000)
https://bugs.webkit.org/show_bug.cgi?id=187548

Reviewed by Saam Barati.

Source/JavaScriptCore:

This patch threads VM& to methodTable(VM&) and remove methodTable().
We add VM& parameter to estimatedSize() to thread VM& in estimatedSize implementations.

* API/APICast.h:
(toJS):
* API/JSCallbackObject.h:
* API/JSCallbackObjectFunctions.h:
(JSC::JSCallbackObject<Parent>::className):
* bytecode/CodeBlock.cpp:
(JSC::CodeBlock::estimatedSize):
* bytecode/CodeBlock.h:
* bytecode/UnlinkedCodeBlock.cpp:
(JSC::UnlinkedCodeBlock::estimatedSize):
* bytecode/UnlinkedCodeBlock.h:
* debugger/DebuggerScope.cpp:
(JSC::DebuggerScope::className):
* debugger/DebuggerScope.h:
* heap/Heap.cpp:
(JSC::GatherHeapSnapshotData::GatherHeapSnapshotData):
(JSC::GatherHeapSnapshotData::operator() const):
(JSC::Heap::gatherExtraHeapSnapshotData):
* heap/HeapSnapshotBuilder.cpp:
(JSC::HeapSnapshotBuilder::json):
* runtime/ArrayPrototype.cpp:
(JSC::arrayProtoFuncToString):
* runtime/ClassInfo.h:
* runtime/DirectArguments.cpp:
(JSC::DirectArguments::estimatedSize):
* runtime/DirectArguments.h:
* runtime/HashMapImpl.cpp:
(JSC::HashMapImpl<HashMapBucket>::estimatedSize):
* runtime/HashMapImpl.h:
* runtime/JSArrayBuffer.cpp:
(JSC::JSArrayBuffer::estimatedSize):
* runtime/JSArrayBuffer.h:
* runtime/JSBigInt.cpp:
(JSC::JSBigInt::estimatedSize):
* runtime/JSBigInt.h:
* runtime/JSCell.cpp:
(JSC::JSCell::dump const):
(JSC::JSCell::estimatedSizeInBytes const):
(JSC::JSCell::estimatedSize):
(JSC::JSCell::className):
* runtime/JSCell.h:
* runtime/JSCellInlines.h:
* runtime/JSGenericTypedArrayView.h:
* runtime/JSGenericTypedArrayViewInlines.h:
(JSC::JSGenericTypedArrayView<Adaptor>::estimatedSize):
* runtime/JSObject.cpp:
(JSC::JSObject::estimatedSize):
(JSC::JSObject::className):
(JSC::JSObject::toStringName):
(JSC::JSObject::calculatedClassName):
* runtime/JSObject.h:
* runtime/JSProxy.cpp:
(JSC::JSProxy::className):
* runtime/JSProxy.h:
* runtime/JSString.cpp:
(JSC::JSString::estimatedSize):
* runtime/JSString.h:
* runtime/RegExp.cpp:
(JSC::RegExp::estimatedSize):
* runtime/RegExp.h:
* runtime/WeakMapImpl.cpp:
(JSC::WeakMapImpl<WeakMapBucket>::estimatedSize):
* runtime/WeakMapImpl.h:

Source/WebCore:

* bindings/js/JSDOMConstructorBase.h:
(WebCore::JSDOMConstructorBase::className):
* bindings/js/JSPluginElementFunctions.cpp:
(WebCore::pluginElementCustomGetCallData):
* bindings/scripts/CodeGeneratorJS.pm:
(GenerateHeader):
(GenerateImplementation):
* bindings/scripts/test/JS/JSInterfaceName.cpp:
(WebCore::JSInterfaceName::estimatedSize):
* bindings/scripts/test/JS/JSInterfaceName.h:

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

43 files changed:
Source/JavaScriptCore/API/APICast.h
Source/JavaScriptCore/API/JSCallbackObject.h
Source/JavaScriptCore/API/JSCallbackObjectFunctions.h
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/bytecode/CodeBlock.cpp
Source/JavaScriptCore/bytecode/CodeBlock.h
Source/JavaScriptCore/bytecode/UnlinkedCodeBlock.cpp
Source/JavaScriptCore/bytecode/UnlinkedCodeBlock.h
Source/JavaScriptCore/debugger/DebuggerScope.cpp
Source/JavaScriptCore/debugger/DebuggerScope.h
Source/JavaScriptCore/heap/Heap.cpp
Source/JavaScriptCore/heap/HeapSnapshotBuilder.cpp
Source/JavaScriptCore/runtime/ArrayPrototype.cpp
Source/JavaScriptCore/runtime/ClassInfo.h
Source/JavaScriptCore/runtime/DirectArguments.cpp
Source/JavaScriptCore/runtime/DirectArguments.h
Source/JavaScriptCore/runtime/HashMapImpl.cpp
Source/JavaScriptCore/runtime/HashMapImpl.h
Source/JavaScriptCore/runtime/JSArrayBuffer.cpp
Source/JavaScriptCore/runtime/JSArrayBuffer.h
Source/JavaScriptCore/runtime/JSBigInt.cpp
Source/JavaScriptCore/runtime/JSBigInt.h
Source/JavaScriptCore/runtime/JSCell.cpp
Source/JavaScriptCore/runtime/JSCell.h
Source/JavaScriptCore/runtime/JSCellInlines.h
Source/JavaScriptCore/runtime/JSGenericTypedArrayView.h
Source/JavaScriptCore/runtime/JSGenericTypedArrayViewInlines.h
Source/JavaScriptCore/runtime/JSObject.cpp
Source/JavaScriptCore/runtime/JSObject.h
Source/JavaScriptCore/runtime/JSProxy.cpp
Source/JavaScriptCore/runtime/JSProxy.h
Source/JavaScriptCore/runtime/JSString.cpp
Source/JavaScriptCore/runtime/JSString.h
Source/JavaScriptCore/runtime/RegExp.cpp
Source/JavaScriptCore/runtime/RegExp.h
Source/JavaScriptCore/runtime/WeakMapImpl.cpp
Source/JavaScriptCore/runtime/WeakMapImpl.h
Source/WebCore/ChangeLog
Source/WebCore/bindings/js/JSDOMConstructorBase.h
Source/WebCore/bindings/js/JSPluginElementFunctions.cpp
Source/WebCore/bindings/scripts/CodeGeneratorJS.pm
Source/WebCore/bindings/scripts/test/JS/JSInterfaceName.cpp
Source/WebCore/bindings/scripts/test/JS/JSInterfaceName.h

index 7d6d3f7..2c22975 100644 (file)
@@ -113,7 +113,7 @@ inline JSC::JSObject* toJS(JSObjectRef o)
 {
     JSC::JSObject* object = uncheckedToJS(o);
     if (object)
-        RELEASE_ASSERT(object->methodTable());
+        RELEASE_ASSERT(object->methodTable(*object->vm()));
     return object;
 }
 
index 9c478ce..1636469 100644 (file)
@@ -194,7 +194,7 @@ public:
     using Parent::methodTable;
 
 private:
-    static String className(const JSObject*);
+    static String className(const JSObject*, VM&);
 
     static JSValue defaultValue(const JSObject*, ExecState*, PreferredPrimitiveType);
 
index 4a05902..0b2f04e 100644 (file)
@@ -130,14 +130,14 @@ void JSCallbackObject<Parent>::init(ExecState* exec)
 }
 
 template <class Parent>
-String JSCallbackObject<Parent>::className(const JSObject* object)
+String JSCallbackObject<Parent>::className(const JSObject* object, VM& vm)
 {
     const JSCallbackObject* thisObject = jsCast<const JSCallbackObject*>(object);
     String thisClassName = thisObject->classRef()->className();
     if (!thisClassName.isEmpty())
         return thisClassName;
     
-    return Parent::className(object);
+    return Parent::className(object, vm);
 }
 
 template <class Parent>
index 15a063a..1fc6c62 100644 (file)
@@ -1,3 +1,77 @@
+2018-07-12  Yusuke Suzuki  <utatane.tea@gmail.com>
+
+        [JSC] Thread VM& to JSCell::methodTable(VM&)
+        https://bugs.webkit.org/show_bug.cgi?id=187548
+
+        Reviewed by Saam Barati.
+
+        This patch threads VM& to methodTable(VM&) and remove methodTable().
+        We add VM& parameter to estimatedSize() to thread VM& in estimatedSize implementations.
+
+        * API/APICast.h:
+        (toJS):
+        * API/JSCallbackObject.h:
+        * API/JSCallbackObjectFunctions.h:
+        (JSC::JSCallbackObject<Parent>::className):
+        * bytecode/CodeBlock.cpp:
+        (JSC::CodeBlock::estimatedSize):
+        * bytecode/CodeBlock.h:
+        * bytecode/UnlinkedCodeBlock.cpp:
+        (JSC::UnlinkedCodeBlock::estimatedSize):
+        * bytecode/UnlinkedCodeBlock.h:
+        * debugger/DebuggerScope.cpp:
+        (JSC::DebuggerScope::className):
+        * debugger/DebuggerScope.h:
+        * heap/Heap.cpp:
+        (JSC::GatherHeapSnapshotData::GatherHeapSnapshotData):
+        (JSC::GatherHeapSnapshotData::operator() const):
+        (JSC::Heap::gatherExtraHeapSnapshotData):
+        * heap/HeapSnapshotBuilder.cpp:
+        (JSC::HeapSnapshotBuilder::json):
+        * runtime/ArrayPrototype.cpp:
+        (JSC::arrayProtoFuncToString):
+        * runtime/ClassInfo.h:
+        * runtime/DirectArguments.cpp:
+        (JSC::DirectArguments::estimatedSize):
+        * runtime/DirectArguments.h:
+        * runtime/HashMapImpl.cpp:
+        (JSC::HashMapImpl<HashMapBucket>::estimatedSize):
+        * runtime/HashMapImpl.h:
+        * runtime/JSArrayBuffer.cpp:
+        (JSC::JSArrayBuffer::estimatedSize):
+        * runtime/JSArrayBuffer.h:
+        * runtime/JSBigInt.cpp:
+        (JSC::JSBigInt::estimatedSize):
+        * runtime/JSBigInt.h:
+        * runtime/JSCell.cpp:
+        (JSC::JSCell::dump const):
+        (JSC::JSCell::estimatedSizeInBytes const):
+        (JSC::JSCell::estimatedSize):
+        (JSC::JSCell::className):
+        * runtime/JSCell.h:
+        * runtime/JSCellInlines.h:
+        * runtime/JSGenericTypedArrayView.h:
+        * runtime/JSGenericTypedArrayViewInlines.h:
+        (JSC::JSGenericTypedArrayView<Adaptor>::estimatedSize):
+        * runtime/JSObject.cpp:
+        (JSC::JSObject::estimatedSize):
+        (JSC::JSObject::className):
+        (JSC::JSObject::toStringName):
+        (JSC::JSObject::calculatedClassName):
+        * runtime/JSObject.h:
+        * runtime/JSProxy.cpp:
+        (JSC::JSProxy::className):
+        * runtime/JSProxy.h:
+        * runtime/JSString.cpp:
+        (JSC::JSString::estimatedSize):
+        * runtime/JSString.h:
+        * runtime/RegExp.cpp:
+        (JSC::RegExp::estimatedSize):
+        * runtime/RegExp.h:
+        * runtime/WeakMapImpl.cpp:
+        (JSC::WeakMapImpl<WeakMapBucket>::estimatedSize):
+        * runtime/WeakMapImpl.h:
+
 2018-07-11  Commit Queue  <commit-queue@webkit.org>
 
         Unreviewed, rolling out r233714.
index b8b3de3..beadbca 100644 (file)
@@ -999,13 +999,13 @@ CodeBlock* CodeBlock::specialOSREntryBlockOrNull()
 #endif // ENABLE(FTL_JIT)
 }
 
-size_t CodeBlock::estimatedSize(JSCell* cell)
+size_t CodeBlock::estimatedSize(JSCell* cell, VM& vm)
 {
     CodeBlock* thisObject = jsCast<CodeBlock*>(cell);
     size_t extraMemoryAllocated = thisObject->m_instructions.size() * sizeof(Instruction);
     if (thisObject->m_jitCode)
         extraMemoryAllocated += thisObject->m_jitCode->size();
-    return Base::estimatedSize(cell) + extraMemoryAllocated;
+    return Base::estimatedSize(cell, vm) + extraMemoryAllocated;
 }
 
 void CodeBlock::visitChildren(JSCell* cell, SlotVisitor& visitor)
index 851b58b..667bd6a 100644 (file)
@@ -188,7 +188,7 @@ public:
     // https://bugs.webkit.org/show_bug.cgi?id=123677
     CodeBlock* baselineVersion();
 
-    static size_t estimatedSize(JSCell*);
+    static size_t estimatedSize(JSCell*, VM&);
     static void visitChildren(JSCell*, SlotVisitor&);
     void visitChildren(SlotVisitor&);
     void finalizeUnconditionally(VM&);
index f5b1bf7..248c881 100644 (file)
@@ -94,11 +94,11 @@ void UnlinkedCodeBlock::visitChildren(JSCell* cell, SlotVisitor& visitor)
         visitor.reportExtraMemoryVisited(thisObject->m_unlinkedInstructions->sizeInBytes());
 }
 
-size_t UnlinkedCodeBlock::estimatedSize(JSCell* cell)
+size_t UnlinkedCodeBlock::estimatedSize(JSCell* cell, VM& vm)
 {
     UnlinkedCodeBlock* thisObject = jsCast<UnlinkedCodeBlock*>(cell);
     size_t extraSize = thisObject->m_unlinkedInstructions ? thisObject->m_unlinkedInstructions->sizeInBytes() : 0;
-    return Base::estimatedSize(cell) + extraSize;
+    return Base::estimatedSize(cell, vm) + extraSize;
 }
 
 int UnlinkedCodeBlock::lineNumberForBytecodeOffset(unsigned bytecodeOffset)
index d76f8c9..0bda4f5 100644 (file)
@@ -509,7 +509,7 @@ private:
 
 protected:
     static void visitChildren(JSCell*, SlotVisitor&);
-    static size_t estimatedSize(JSCell*);
+    static size_t estimatedSize(JSCell*, VM&);
 
 public:
     DECLARE_INFO;
index d5404b5..e5adad9 100644 (file)
@@ -66,7 +66,7 @@ void DebuggerScope::visitChildren(JSCell* cell, SlotVisitor& visitor)
     visitor.append(thisObject->m_next);
 }
 
-String DebuggerScope::className(const JSObject* object)
+String DebuggerScope::className(const JSObject* object, VM& vm)
 {
     const DebuggerScope* scope = jsCast<const DebuggerScope*>(object);
     // We cannot assert that scope->isValid() because the TypeProfiler may encounter an invalidated
@@ -74,7 +74,7 @@ String DebuggerScope::className(const JSObject* object)
     if (!scope->isValid())
         return String();
     JSObject* thisObject = JSScope::objectAtScope(scope->jsScope());
-    return thisObject->methodTable()->className(thisObject);
+    return thisObject->methodTable(vm)->className(thisObject, vm);
 }
 
 bool DebuggerScope::getOwnPropertySlot(JSObject* object, ExecState* exec, PropertyName propertyName, PropertySlot& slot)
index b7185bc..cb21ba4 100644 (file)
@@ -41,7 +41,7 @@ public:
     JS_EXPORT_PRIVATE static DebuggerScope* create(VM& vm, JSScope* scope);
 
     static void visitChildren(JSCell*, SlotVisitor&);
-    static String className(const JSObject*);
+    static String className(const JSObject*, VM&);
     static bool getOwnPropertySlot(JSObject*, ExecState*, PropertyName, PropertySlot&);
     static bool put(JSCell*, ExecState*, PropertyName, JSValue, PutPropertySlot&);
     static bool deleteProperty(JSCell*, ExecState*, PropertyName);
index b6bc8d9..aef44c3 100644 (file)
@@ -713,8 +713,9 @@ bool Heap::isHeapSnapshotting() const
 }
 
 struct GatherHeapSnapshotData : MarkedBlock::CountFunctor {
-    GatherHeapSnapshotData(HeapSnapshotBuilder& builder)
-        : m_builder(builder)
+    GatherHeapSnapshotData(VM& vm, HeapSnapshotBuilder& builder)
+        : m_vm(vm)
+        , m_builder(builder)
     {
     }
 
@@ -722,11 +723,12 @@ struct GatherHeapSnapshotData : MarkedBlock::CountFunctor {
     {
         if (isJSCellKind(kind)) {
             JSCell* cell = static_cast<JSCell*>(heapCell);
-            cell->methodTable()->heapSnapshot(cell, m_builder);
+            cell->methodTable(m_vm)->heapSnapshot(cell, m_builder);
         }
         return IterationStatus::Continue;
     }
 
+    VM& m_vm;
     HeapSnapshotBuilder& m_builder;
 };
 
@@ -734,7 +736,7 @@ void Heap::gatherExtraHeapSnapshotData(HeapProfiler& heapProfiler)
 {
     if (HeapSnapshotBuilder* builder = heapProfiler.activeSnapshotBuilder()) {
         HeapIterationScope heapIterationScope(*this);
-        GatherHeapSnapshotData functor(*builder);
+        GatherHeapSnapshotData functor(*m_vm, *builder);
         m_objectSpace.forEachLiveCell(heapIterationScope, functor);
     }
 }
index 65f633f..4d46eaf 100644 (file)
@@ -240,7 +240,7 @@ String HeapSnapshotBuilder::json(std::function<bool (const HeapSnapshotNode&)> a
         json.append(',');
         json.appendNumber(node.identifier);
         json.append(',');
-        json.appendNumber(node.cell->estimatedSizeInBytes());
+        json.appendNumber(node.cell->estimatedSizeInBytes(vm));
         json.append(',');
         json.appendNumber(classNameIndex);
         json.append(',');
index abe4929..cc06e65 100644 (file)
@@ -548,7 +548,7 @@ EncodedJSValue JSC_HOST_CALL arrayProtoFuncToString(ExecState* exec)
 
     if (UNLIKELY(customJoinCase)) {
         scope.release();
-        return JSValue::encode(jsMakeNontrivialString(exec, "[object ", thisObject->methodTable(vm)->className(thisObject), "]"));
+        return JSValue::encode(jsMakeNontrivialString(exec, "[object ", thisObject->methodTable(vm)->className(thisObject, vm), "]"));
     }
 
     // 4. Return the result of calling the [[Call]] internal method of func providing array as the this value and an empty arguments list.
index d5cffb6..d825a91 100644 (file)
@@ -89,7 +89,7 @@ struct MethodTable {
     GetPropertyNamesFunctionPtr WTF_METHOD_TABLE_ENTRY(getStructurePropertyNames);
     GetPropertyNamesFunctionPtr WTF_METHOD_TABLE_ENTRY(getGenericPropertyNames);
 
-    using ClassNameFunctionPtr = String (*)(const JSObject*);
+    using ClassNameFunctionPtr = String (*)(const JSObject*, VM&);
     ClassNameFunctionPtr WTF_METHOD_TABLE_ENTRY(className);
 
     using ToStringNameFunctionPtr = String (*)(const JSObject*, ExecState*);
@@ -119,7 +119,7 @@ struct MethodTable {
     using HeapSnapshotFunctionPtr = void (*)(JSCell*, HeapSnapshotBuilder&);
     HeapSnapshotFunctionPtr WTF_METHOD_TABLE_ENTRY(heapSnapshot);
 
-    using EstimatedSizeFunctionPtr = size_t (*)(JSCell*);
+    using EstimatedSizeFunctionPtr = size_t (*)(JSCell*, VM&);
     EstimatedSizeFunctionPtr WTF_METHOD_TABLE_ENTRY(estimatedSize);
 
     using VisitOutputConstraintsPtr = void (*)(JSCell*, SlotVisitor&);
index f910f09..e001be2 100644 (file)
@@ -83,12 +83,12 @@ DirectArguments* DirectArguments::createByCopying(ExecState* exec)
     return result;
 }
 
-size_t DirectArguments::estimatedSize(JSCell* cell)
+size_t DirectArguments::estimatedSize(JSCell* cell, VM& vm)
 {
     DirectArguments* thisObject = jsCast<DirectArguments*>(cell);
     size_t mappedArgumentsSize = thisObject->m_mappedArguments ? thisObject->mappedArgumentsSize() * sizeof(bool) : 0;
     size_t modifiedArgumentsSize = thisObject->m_modifiedArgumentsDescriptor ? thisObject->m_length * sizeof(bool) : 0;
-    return Base::estimatedSize(cell) + mappedArgumentsSize + modifiedArgumentsSize;
+    return Base::estimatedSize(cell, vm) + mappedArgumentsSize + modifiedArgumentsSize;
 }
 
 void DirectArguments::visitChildren(JSCell* thisCell, SlotVisitor& visitor)
index 48e9be0..1a2cc6f 100644 (file)
@@ -64,7 +64,7 @@ public:
     // Creates an arguments object by copying the argumnets from the stack.
     static DirectArguments* createByCopying(ExecState*);
 
-    static size_t estimatedSize(JSCell*);
+    static size_t estimatedSize(JSCell*, VM&);
     static void visitChildren(JSCell*, SlotVisitor&);
     
     uint32_t internalLength() const
index 5c757e5..3c2a82b 100644 (file)
@@ -67,9 +67,9 @@ void HashMapImpl<HashMapBucket>::visitChildren(JSCell* cell, SlotVisitor& visito
 }
 
 template <typename HashMapBucket>
-size_t HashMapImpl<HashMapBucket>::estimatedSize(JSCell* cell)
+size_t HashMapImpl<HashMapBucket>::estimatedSize(JSCell* cell, VM& vm)
 {
-    return Base::estimatedSize(cell) + static_cast<HashMapImpl<HashMapBucket>*>(cell)->approximateSize();
+    return Base::estimatedSize(cell, vm) + static_cast<HashMapImpl<HashMapBucket>*>(cell)->approximateSize();
 }
 
 const ClassInfo* getHashMapBucketKeyClassInfo()
index 7d949c2..692a5f9 100644 (file)
@@ -346,7 +346,7 @@ public:
 
     static void visitChildren(JSCell*, SlotVisitor&);
 
-    static size_t estimatedSize(JSCell*);
+    static size_t estimatedSize(JSCell*, VM&);
 
     HashMapImpl(VM& vm, Structure* structure)
         : Base(vm, structure)
index 3a64c34..6f7c527 100644 (file)
@@ -78,11 +78,11 @@ ArrayBufferSharingMode JSArrayBuffer::sharingMode() const
     return impl()->sharingMode();
 }
 
-size_t JSArrayBuffer::estimatedSize(JSCell* cell)
+size_t JSArrayBuffer::estimatedSize(JSCell* cell, VM& vm)
 {
     JSArrayBuffer* thisObject = jsCast<JSArrayBuffer*>(cell);
     size_t bufferEstimatedSize = thisObject->impl()->gcSizeEstimateInBytes();
-    return Base::estimatedSize(cell) + bufferEstimatedSize;
+    return Base::estimatedSize(cell, vm) + bufferEstimatedSize;
 }
 
 } // namespace JSC
index 2f5a5f9..8fdfc53 100644 (file)
@@ -58,7 +58,7 @@ public:
     static ArrayBuffer* toWrapped(VM&, JSValue);
     
 protected:
-    static size_t estimatedSize(JSCell*);
+    static size_t estimatedSize(JSCell*, VM&);
 
 private:
     Poisoned<JSArrayBufferPoison, ArrayBuffer*> m_impl;
index 27df1f4..ba355bd 100644 (file)
@@ -1183,9 +1183,9 @@ JSBigInt* JSBigInt::allocateFor(ExecState* exec, VM& vm, unsigned radix, unsigne
     return nullptr;
 }
 
-size_t JSBigInt::estimatedSize(JSCell* cell)
+size_t JSBigInt::estimatedSize(JSCell* cell, VM& vm)
 {
-    return Base::estimatedSize(cell) + jsCast<JSBigInt*>(cell)->m_length * sizeof(Digit);
+    return Base::estimatedSize(cell, vm) + jsCast<JSBigInt*>(cell)->m_length * sizeof(Digit);
 }
 
 double JSBigInt::toNumber(ExecState* exec) const
index 4af7a5f..5b7db74 100644 (file)
@@ -46,7 +46,7 @@ public:
     enum class InitializationType { None, WithZero };
     void initialize(InitializationType);
 
-    static size_t estimatedSize(JSCell*);
+    static size_t estimatedSize(JSCell*, VM&);
 
     static Structure* createStructure(VM&, JSGlobalObject*, JSValue prototype);
     static JSBigInt* createZero(VM&);
index 7059ab8..0731827 100644 (file)
@@ -46,7 +46,7 @@ void JSCell::destroy(JSCell* cell)
 
 void JSCell::dump(PrintStream& out) const
 {
-    methodTable()->dumpToStream(this, out);
+    methodTable(*vm())->dumpToStream(this, out);
 }
 
 void JSCell::dumpToStream(const JSCell* cell, PrintStream& out)
@@ -54,12 +54,12 @@ void JSCell::dumpToStream(const JSCell* cell, PrintStream& out)
     out.printf("<%p, %s>", cell, cell->className(*cell->vm()));
 }
 
-size_t JSCell::estimatedSizeInBytes() const
+size_t JSCell::estimatedSizeInBytes(VM& vm) const
 {
-    return methodTable()->estimatedSize(const_cast<JSCell*>(this));
+    return methodTable(vm)->estimatedSize(const_cast<JSCell*>(this), vm);
 }
 
-size_t JSCell::estimatedSize(JSCell* cell)
+size_t JSCell::estimatedSize(JSCell* cell, VM&)
 {
     return cell->cellSize();
 }
@@ -222,7 +222,7 @@ void JSCell::getOwnNonIndexPropertyNames(JSObject*, ExecState*, PropertyNameArra
     RELEASE_ASSERT_NOT_REACHED();
 }
 
-String JSCell::className(const JSObject*)
+String JSCell::className(const JSObject*, VM&)
 {
     RELEASE_ASSERT_NOT_REACHED();
     return String();
index 9ea70fd..9e8ba60 100644 (file)
@@ -170,8 +170,8 @@ public:
     void dump(PrintStream&) const;
     JS_EXPORT_PRIVATE static void dumpToStream(const JSCell*, PrintStream&);
 
-    size_t estimatedSizeInBytes() const;
-    JS_EXPORT_PRIVATE static size_t estimatedSize(JSCell*);
+    size_t estimatedSizeInBytes(VM&) const;
+    JS_EXPORT_PRIVATE static size_t estimatedSize(JSCell*, VM&);
 
     static void visitChildren(JSCell*, SlotVisitor&);
     static void visitOutputConstraints(JSCell*, SlotVisitor&);
@@ -180,7 +180,6 @@ public:
 
     // Object operations, with the toObject operation included.
     const ClassInfo* classInfo(VM&) const;
-    const MethodTable* methodTable() const;
     const MethodTable* methodTable(VM&) const;
     static bool put(JSCell*, ExecState*, PropertyName, JSValue, PutPropertySlot&);
     static bool putByIndex(JSCell*, ExecState*, unsigned propertyName, JSValue, bool shouldThrow);
@@ -259,7 +258,7 @@ protected:
     static NO_RETURN_DUE_TO_CRASH bool setPrototype(JSObject*, ExecState*, JSValue, bool);
     static NO_RETURN_DUE_TO_CRASH JSValue getPrototype(JSObject*, ExecState*);
 
-    static String className(const JSObject*);
+    static String className(const JSObject*, VM&);
     static String toStringName(const JSObject*, ExecState*);
     JS_EXPORT_PRIVATE static bool customHasInstance(JSObject*, ExecState*, JSValue);
     static bool defineOwnProperty(JSObject*, ExecState*, PropertyName, const PropertyDescriptor&, bool shouldThrow);
index cda6a1e..f69b380 100644 (file)
@@ -287,11 +287,6 @@ ALWAYS_INLINE void JSCell::setStructure(VM& vm, Structure* structure)
     vm.heap.writeBarrier(this, structure);
 }
 
-inline const MethodTable* JSCell::methodTable() const
-{
-    return methodTable(*vm());
-}
-
 inline const MethodTable* JSCell::methodTable(VM& vm) const
 {
     Structure* structure = this->structure(vm);
index ffdd8e4..8642035 100644 (file)
@@ -285,7 +285,7 @@ protected:
     
     static void getOwnPropertyNames(JSObject*, ExecState*, PropertyNameArray&, EnumerationMode);
 
-    static size_t estimatedSize(JSCell*);
+    static size_t estimatedSize(JSCell*, VM&);
     static void visitChildren(JSCell*, SlotVisitor&);
 
 private:
index 144773f..5b2d1fb 100644 (file)
@@ -500,16 +500,16 @@ void JSGenericTypedArrayView<Adaptor>::getOwnPropertyNames(
 }
 
 template<typename Adaptor>
-size_t JSGenericTypedArrayView<Adaptor>::estimatedSize(JSCell* cell)
+size_t JSGenericTypedArrayView<Adaptor>::estimatedSize(JSCell* cell, VM& vm)
 {
     JSGenericTypedArrayView* thisObject = jsCast<JSGenericTypedArrayView*>(cell);
 
     if (thisObject->m_mode == OversizeTypedArray)
-        return Base::estimatedSize(thisObject) + thisObject->byteSize();
+        return Base::estimatedSize(thisObject, vm) + thisObject->byteSize();
     if (thisObject->m_mode == FastTypedArray && thisObject->m_vector)
-        return Base::estimatedSize(thisObject) + thisObject->byteSize();
+        return Base::estimatedSize(thisObject, vm) + thisObject->byteSize();
 
-    return Base::estimatedSize(thisObject);
+    return Base::estimatedSize(thisObject, vm);
 }
 
 template<typename Adaptor>
index 7ddc825..15e411c 100644 (file)
@@ -423,11 +423,11 @@ ALWAYS_INLINE Structure* JSObject::visitButterflyImpl(SlotVisitor& visitor)
     return structure;
 }
 
-size_t JSObject::estimatedSize(JSCell* cell)
+size_t JSObject::estimatedSize(JSCell* cell, VM& vm)
 {
     JSObject* thisObject = jsCast<JSObject*>(cell);
-    size_t butterflyOutOfLineSize = thisObject->m_butterfly ? thisObject->structure()->outOfLineSize() : 0;
-    return Base::estimatedSize(cell) + butterflyOutOfLineSize;
+    size_t butterflyOutOfLineSize = thisObject->m_butterfly ? thisObject->structure(vm)->outOfLineSize() : 0;
+    return Base::estimatedSize(cell, vm) + butterflyOutOfLineSize;
 }
 
 void JSObject::visitChildren(JSCell* cell, SlotVisitor& visitor)
@@ -507,18 +507,19 @@ void JSFinalObject::visitChildren(JSCell* cell, SlotVisitor& visitor)
 #endif
 }
 
-String JSObject::className(const JSObject* object)
+String JSObject::className(const JSObject* object, VM& vm)
 {
-    const ClassInfo* info = object->classInfo(*object->vm());
+    const ClassInfo* info = object->classInfo(vm);
     ASSERT(info);
     return info->className;
 }
 
-String JSObject::toStringName(const JSObject* object, ExecState*)
+String JSObject::toStringName(const JSObject* object, ExecState* exec)
 {
-    const ClassInfo* info = object->classInfo(*object->vm());
+    VM& vm = exec->vm();
+    const ClassInfo* info = object->classInfo(vm);
     ASSERT(info);
-    return info->methodTable.className(object);
+    return info->methodTable.className(object, vm);
 }
 
 String JSObject::calculatedClassName(JSObject* object)
@@ -552,7 +553,7 @@ String JSObject::calculatedClassName(JSObject* object)
         scope.clearException();
 
     if (prototypeFunctionName.isNull() || prototypeFunctionName == "Object") {
-        String tableClassName = object->methodTable(vm)->className(object);
+        String tableClassName = object->methodTable(vm)->className(object, vm);
         if (!tableClassName.isNull() && tableClassName != "Object")
             return tableClassName;
 
index 941412a..c11d050 100644 (file)
@@ -114,11 +114,11 @@ public:
     // JSFinalObject or a JSArray. This is the method that will do that.
     static JSObject* createRawObject(ExecState* exec, Structure* structure, Butterfly* = nullptr);
 
-    JS_EXPORT_PRIVATE static size_t estimatedSize(JSCell*);
+    JS_EXPORT_PRIVATE static size_t estimatedSize(JSCell*, VM&);
     JS_EXPORT_PRIVATE static void visitChildren(JSCell*, SlotVisitor&);
     JS_EXPORT_PRIVATE static void heapSnapshot(JSCell*, HeapSnapshotBuilder&);
 
-    JS_EXPORT_PRIVATE static String className(const JSObject*);
+    JS_EXPORT_PRIVATE static String className(const JSObject*, VM&);
     JS_EXPORT_PRIVATE static String calculatedClassName(JSObject*);
 
     // This function is what Object.prototype.toString() will use to get the name of
@@ -760,7 +760,7 @@ public:
     // You should only call isStructureExtensible() when:
     // - Performing this check in a way that isn't described in the specification 
     //   as calling the virtual [[IsExtensible]] trap.
-    // - When you're guaranteed that object->methodTable()->isExtensible isn't
+    // - When you're guaranteed that object->methodTable(vm)->isExtensible isn't
     //   overridden.
     ALWAYS_INLINE bool isStructureExtensible(VM& vm) { return structure(vm)->isStructureExtensible(); }
     // You should call this when performing [[IsExtensible]] trap in a place
index df136fb..bf187d8 100644 (file)
@@ -49,10 +49,10 @@ void JSProxy::setTarget(VM& vm, JSGlobalObject* globalObject)
     setPrototypeDirect(vm, globalObject->getPrototypeDirect(vm));
 }
 
-String JSProxy::className(const JSObject* object)
+String JSProxy::className(const JSObject* object, VM& vm)
 {
     const JSProxy* thisObject = jsCast<const JSProxy*>(object);
-    return thisObject->target()->methodTable()->className(thisObject->target());
+    return thisObject->target()->methodTable(vm)->className(thisObject->target(), vm);
 }
 
 String JSProxy::toStringName(const JSObject* object, ExecState* exec)
index b407af7..0bd35c9 100644 (file)
@@ -80,7 +80,7 @@ protected:
 
     JS_EXPORT_PRIVATE static void visitChildren(JSCell*, SlotVisitor&);
 
-    JS_EXPORT_PRIVATE static String className(const JSObject*);
+    JS_EXPORT_PRIVATE static String className(const JSObject*, VM&);
     JS_EXPORT_PRIVATE static String toStringName(const JSObject*, ExecState*);
     JS_EXPORT_PRIVATE static bool getOwnPropertySlot(JSObject*, ExecState*, PropertyName, PropertySlot&);
     JS_EXPORT_PRIVATE static bool getOwnPropertySlotByIndex(JSObject*, ExecState*, unsigned, PropertySlot&);
index 640bb84..092d749 100644 (file)
@@ -83,12 +83,12 @@ bool JSString::equalSlowCase(ExecState* exec, JSString* other) const
     return WTF::equal(*str1.impl(), *str2.impl());
 }
 
-size_t JSString::estimatedSize(JSCell* cell)
+size_t JSString::estimatedSize(JSCell* cell, VM& vm)
 {
     JSString* thisObject = asString(cell);
     if (thisObject->isRope())
-        return Base::estimatedSize(cell);
-    return Base::estimatedSize(cell) + thisObject->m_value.impl()->costDuringGC();
+        return Base::estimatedSize(cell, vm);
+    return Base::estimatedSize(cell, vm) + thisObject->m_value.impl()->costDuringGC();
 }
 
 void JSString::visitChildren(JSCell* cell, SlotVisitor& visitor)
index c755911..7c76909 100644 (file)
@@ -185,7 +185,7 @@ public:
     DECLARE_EXPORT_INFO;
 
     static void dumpToStream(const JSCell*, PrintStream&);
-    static size_t estimatedSize(JSCell*);
+    static size_t estimatedSize(JSCell*, VM&);
     static void visitChildren(JSCell*, SlotVisitor&);
 
     enum {
index 41e005e..05399b2 100644 (file)
@@ -238,14 +238,14 @@ void RegExp::destroy(JSCell* cell)
     thisObject->RegExp::~RegExp();
 }
 
-size_t RegExp::estimatedSize(JSCell* cell)
+size_t RegExp::estimatedSize(JSCell* cell, VM& vm)
 {
     RegExp* thisObject = static_cast<RegExp*>(cell);
     size_t regexDataSize = thisObject->m_regExpBytecode ? thisObject->m_regExpBytecode->estimatedSizeInBytes() : 0;
 #if ENABLE(YARR_JIT)
     regexDataSize += thisObject->m_regExpJITCode.size();
 #endif
-    return Base::estimatedSize(cell) + regexDataSize;
+    return Base::estimatedSize(cell, vm) + regexDataSize;
 }
 
 RegExp* RegExp::createWithoutCaching(VM& vm, const String& patternString, RegExpFlags flags)
index 05ce5c0..de256e1 100644 (file)
@@ -48,7 +48,7 @@ public:
     JS_EXPORT_PRIVATE static RegExp* create(VM&, const String& pattern, RegExpFlags);
     static const bool needsDestruction = true;
     static void destroy(JSCell*);
-    static size_t estimatedSize(JSCell*);
+    static size_t estimatedSize(JSCell*, VM&);
     JS_EXPORT_PRIVATE static void dumpToStream(const JSCell*, PrintStream&);
 
     bool global() const { return m_flags & FlagGlobal; }
index 0e31bd6..e7caca9 100644 (file)
@@ -49,10 +49,10 @@ void WeakMapImpl<WeakMapBucket>::visitChildren(JSCell* cell, SlotVisitor& visito
 }
 
 template <typename WeakMapBucket>
-size_t WeakMapImpl<WeakMapBucket>::estimatedSize(JSCell* cell)
+size_t WeakMapImpl<WeakMapBucket>::estimatedSize(JSCell* cell, VM& vm)
 {
     auto* thisObject = static_cast<WeakMapImpl*>(cell);
-    return Base::estimatedSize(thisObject) + (sizeof(WeakMapImpl) - sizeof(Base)) + thisObject->m_capacity * sizeof(WeakMapBucket);
+    return Base::estimatedSize(thisObject, vm) + (sizeof(WeakMapImpl) - sizeof(Base)) + thisObject->m_capacity * sizeof(WeakMapBucket);
 }
 
 template <>
index 088bac5..5258cbc 100644 (file)
@@ -203,7 +203,7 @@ public:
 
     static void visitChildren(JSCell*, SlotVisitor&);
 
-    static size_t estimatedSize(JSCell*);
+    static size_t estimatedSize(JSCell*, VM&);
 
     WeakMapImpl(VM& vm, Structure* structure)
         : Base(vm, structure)
index b5abf7f..5f342ab 100644 (file)
@@ -1,3 +1,21 @@
+2018-07-12  Yusuke Suzuki  <utatane.tea@gmail.com>
+
+        [JSC] Thread VM& to JSCell::methodTable(VM&)
+        https://bugs.webkit.org/show_bug.cgi?id=187548
+
+        Reviewed by Saam Barati.
+
+        * bindings/js/JSDOMConstructorBase.h:
+        (WebCore::JSDOMConstructorBase::className):
+        * bindings/js/JSPluginElementFunctions.cpp:
+        (WebCore::pluginElementCustomGetCallData):
+        * bindings/scripts/CodeGeneratorJS.pm:
+        (GenerateHeader):
+        (GenerateImplementation):
+        * bindings/scripts/test/JS/JSInterfaceName.cpp:
+        (WebCore::JSInterfaceName::estimatedSize):
+        * bindings/scripts/test/JS/JSInterfaceName.h:
+
 2018-07-11  Youenn Fablet  <youenn@apple.com>
 
         MediaDevices should derive from EventTarget in its IDL
index fee5648..cd24c08 100644 (file)
@@ -37,7 +37,7 @@ protected:
     {
     }
 
-    static String className(const JSObject*);
+    static String className(const JSObject*, JSC::VM&);
     static JSC::CallType getCallData(JSCell*, JSC::CallData&);
 };
 
@@ -46,7 +46,7 @@ inline JSC::Structure* JSDOMConstructorBase::createStructure(JSC::VM& vm, JSC::J
     return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
 }
 
-inline String JSDOMConstructorBase::className(const JSObject*)
+inline String JSDOMConstructorBase::className(const JSObject*, JSC::VM&)
 {
     return "Function"_s;
 }
index 7669ec7..40f2617 100644 (file)
@@ -168,7 +168,8 @@ CallType pluginElementCustomGetCallData(JSHTMLElement* element, CallData& callDa
     if (JSObject* scriptObject = pluginScriptObjectFromPluginViewBase(element)) {
         CallData scriptObjectCallData;
         
-        if (scriptObject->methodTable()->getCallData(scriptObject, scriptObjectCallData) == CallType::None)
+        VM& vm = *scriptObject->vm();
+        if (scriptObject->methodTable(vm)->getCallData(scriptObject, scriptObjectCallData) == CallType::None)
             return CallType::None;
 
         callData.native.function = callPlugin;
index b5ed507..d9d4583 100644 (file)
@@ -2650,7 +2650,7 @@ sub GenerateHeader
     }
     
     if (InstanceNeedsEstimatedSize($interface)) {
-        push(@headerContent, "    static size_t estimatedSize(JSCell*);\n");
+        push(@headerContent, "    static size_t estimatedSize(JSCell*, JSC::VM&);\n");
     }
     
     if (!$hasParent) {
@@ -4505,10 +4505,10 @@ sub GenerateImplementation
     }
 
     if (InstanceNeedsEstimatedSize($interface)) {
-        push(@implContent, "size_t ${className}::estimatedSize(JSCell* cell)\n");
+        push(@implContent, "size_t ${className}::estimatedSize(JSCell* cell, VM& vm)\n");
         push(@implContent, "{\n");
         push(@implContent, "    auto* thisObject = jsCast<${className}*>(cell);\n");
-        push(@implContent, "    return Base::estimatedSize(thisObject) + thisObject->wrapped().memoryCost();\n");
+        push(@implContent, "    return Base::estimatedSize(thisObject, vm) + thisObject->wrapped().memoryCost();\n");
         push(@implContent, "}\n\n");
     }
 
index 9eb8d26..d8c10a2 100644 (file)
@@ -162,10 +162,10 @@ void JSInterfaceName::visitChildren(JSCell* cell, SlotVisitor& visitor)
     visitor.reportExtraMemoryVisited(thisObject->wrapped().memoryCost());
 }
 
-size_t JSInterfaceName::estimatedSize(JSCell* cell)
+size_t JSInterfaceName::estimatedSize(JSCell* cell, VM& vm)
 {
     auto* thisObject = jsCast<JSInterfaceName*>(cell);
-    return Base::estimatedSize(thisObject) + thisObject->wrapped().memoryCost();
+    return Base::estimatedSize(thisObject, vm) + thisObject->wrapped().memoryCost();
 }
 
 bool JSInterfaceNameOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor)
index a123148..9ddbbc3 100644 (file)
@@ -39,7 +39,7 @@ public:
     static JSC::JSObject* createPrototype(JSC::VM&, JSDOMGlobalObject&);
     static JSC::JSObject* prototype(JSC::VM&, JSDOMGlobalObject&);
     static InterfaceName* toWrapped(JSC::VM&, JSC::JSValue);
-    static size_t estimatedSize(JSCell*);
+    static size_t estimatedSize(JSCell*, JSC::VM&);
     static void destroy(JSC::JSCell*);
 
     DECLARE_INFO;