Skip to content

Commit

Permalink
Merge r221223 - Merge WeakMapData into JSWeakMap and JSWeakSet
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=143919

Reviewed by Darin Adler.

This patch changes WeakMapData from JSCell to JSDestructibleObject,
renaming it to WeakMapBase, and JSWeakMap and JSWeakSet simply inherit
it instead of separately allocating WeakMapData. This reduces memory
consumption and allocation times.

Also this patch a bit optimizes sizeof(DeadKeyCleaner) by dropping m_target
field. Since this class is always embedded in WeakMapBase, we can calculate
WeakMapBase address from the address of DeadKeyCleaner.

This patch does not include the optimization changing WeakMapData to Set
for JSWeakSet.

* CMakeLists.txt:
* JavaScriptCore.xcodeproj/project.pbxproj:
* inspector/JSInjectedScriptHost.cpp:
(Inspector::JSInjectedScriptHost::weakMapSize):
(Inspector::JSInjectedScriptHost::weakMapEntries):
(Inspector::JSInjectedScriptHost::weakSetSize):
(Inspector::JSInjectedScriptHost::weakSetEntries):
* runtime/JSWeakMap.cpp:
(JSC::JSWeakMap::finishCreation): Deleted.
(JSC::JSWeakMap::visitChildren): Deleted.
* runtime/JSWeakMap.h:
(JSC::JSWeakMap::createStructure): Deleted.
(JSC::JSWeakMap::create): Deleted.
(JSC::JSWeakMap::weakMapData): Deleted.
(JSC::JSWeakMap::JSWeakMap): Deleted.
* runtime/JSWeakSet.cpp:
(JSC::JSWeakSet::finishCreation): Deleted.
(JSC::JSWeakSet::visitChildren): Deleted.
* runtime/JSWeakSet.h:
(JSC::JSWeakSet::createStructure): Deleted.
(JSC::JSWeakSet::create): Deleted.
(JSC::JSWeakSet::weakMapData): Deleted.
(JSC::JSWeakSet::JSWeakSet): Deleted.
* runtime/VM.cpp:
(JSC::VM::VM):
* runtime/VM.h:
* runtime/WeakMapBase.cpp: Renamed from Source/JavaScriptCore/runtime/WeakMapData.cpp.
(JSC::WeakMapBase::WeakMapBase):
(JSC::WeakMapBase::destroy):
(JSC::WeakMapBase::estimatedSize):
(JSC::WeakMapBase::visitChildren):
(JSC::WeakMapBase::set):
(JSC::WeakMapBase::get):
(JSC::WeakMapBase::remove):
(JSC::WeakMapBase::contains):
(JSC::WeakMapBase::clear):
(JSC::WeakMapBase::DeadKeyCleaner::target):
(JSC::WeakMapBase::DeadKeyCleaner::visitWeakReferences):
(JSC::WeakMapBase::DeadKeyCleaner::finalizeUnconditionally):
* runtime/WeakMapBase.h: Renamed from Source/JavaScriptCore/runtime/WeakMapData.h.
(JSC::WeakMapBase::size const):
* runtime/WeakMapPrototype.cpp:
(JSC::getWeakMap):
(JSC::protoFuncWeakMapDelete):
(JSC::protoFuncWeakMapGet):
(JSC::protoFuncWeakMapHas):
(JSC::protoFuncWeakMapSet):
(JSC::getWeakMapData): Deleted.
* runtime/WeakSetPrototype.cpp:
(JSC::getWeakSet):
(JSC::protoFuncWeakSetDelete):
(JSC::protoFuncWeakSetHas):
(JSC::protoFuncWeakSetAdd):
(JSC::getWeakMapData): Deleted.
  • Loading branch information
Constellation authored and carlosgcampos committed Aug 30, 2017
1 parent 8f07099 commit 71bb8c3
Show file tree
Hide file tree
Showing 14 changed files with 162 additions and 166 deletions.
2 changes: 1 addition & 1 deletion Source/JavaScriptCore/CMakeLists.txt
Expand Up @@ -927,8 +927,8 @@ set(JavaScriptCore_SOURCES
runtime/VMTraps.cpp
runtime/VarOffset.cpp
runtime/Watchdog.cpp
runtime/WeakMapBase.cpp
runtime/WeakMapConstructor.cpp
runtime/WeakMapData.cpp
runtime/WeakMapPrototype.cpp
runtime/WeakSetConstructor.cpp
runtime/WeakSetPrototype.cpp
Expand Down
74 changes: 74 additions & 0 deletions Source/JavaScriptCore/ChangeLog
@@ -1,3 +1,77 @@
2017-08-26 Yusuke Suzuki <utatane.tea@gmail.com>

Merge WeakMapData into JSWeakMap and JSWeakSet
https://bugs.webkit.org/show_bug.cgi?id=143919

Reviewed by Darin Adler.

This patch changes WeakMapData from JSCell to JSDestructibleObject,
renaming it to WeakMapBase, and JSWeakMap and JSWeakSet simply inherit
it instead of separately allocating WeakMapData. This reduces memory
consumption and allocation times.

Also this patch a bit optimizes sizeof(DeadKeyCleaner) by dropping m_target
field. Since this class is always embedded in WeakMapBase, we can calculate
WeakMapBase address from the address of DeadKeyCleaner.

This patch does not include the optimization changing WeakMapData to Set
for JSWeakSet.

* CMakeLists.txt:
* JavaScriptCore.xcodeproj/project.pbxproj:
* inspector/JSInjectedScriptHost.cpp:
(Inspector::JSInjectedScriptHost::weakMapSize):
(Inspector::JSInjectedScriptHost::weakMapEntries):
(Inspector::JSInjectedScriptHost::weakSetSize):
(Inspector::JSInjectedScriptHost::weakSetEntries):
* runtime/JSWeakMap.cpp:
(JSC::JSWeakMap::finishCreation): Deleted.
(JSC::JSWeakMap::visitChildren): Deleted.
* runtime/JSWeakMap.h:
(JSC::JSWeakMap::createStructure): Deleted.
(JSC::JSWeakMap::create): Deleted.
(JSC::JSWeakMap::weakMapData): Deleted.
(JSC::JSWeakMap::JSWeakMap): Deleted.
* runtime/JSWeakSet.cpp:
(JSC::JSWeakSet::finishCreation): Deleted.
(JSC::JSWeakSet::visitChildren): Deleted.
* runtime/JSWeakSet.h:
(JSC::JSWeakSet::createStructure): Deleted.
(JSC::JSWeakSet::create): Deleted.
(JSC::JSWeakSet::weakMapData): Deleted.
(JSC::JSWeakSet::JSWeakSet): Deleted.
* runtime/VM.cpp:
(JSC::VM::VM):
* runtime/VM.h:
* runtime/WeakMapBase.cpp: Renamed from Source/JavaScriptCore/runtime/WeakMapData.cpp.
(JSC::WeakMapBase::WeakMapBase):
(JSC::WeakMapBase::destroy):
(JSC::WeakMapBase::estimatedSize):
(JSC::WeakMapBase::visitChildren):
(JSC::WeakMapBase::set):
(JSC::WeakMapBase::get):
(JSC::WeakMapBase::remove):
(JSC::WeakMapBase::contains):
(JSC::WeakMapBase::clear):
(JSC::WeakMapBase::DeadKeyCleaner::target):
(JSC::WeakMapBase::DeadKeyCleaner::visitWeakReferences):
(JSC::WeakMapBase::DeadKeyCleaner::finalizeUnconditionally):
* runtime/WeakMapBase.h: Renamed from Source/JavaScriptCore/runtime/WeakMapData.h.
(JSC::WeakMapBase::size const):
* runtime/WeakMapPrototype.cpp:
(JSC::getWeakMap):
(JSC::protoFuncWeakMapDelete):
(JSC::protoFuncWeakMapGet):
(JSC::protoFuncWeakMapHas):
(JSC::protoFuncWeakMapSet):
(JSC::getWeakMapData): Deleted.
* runtime/WeakSetPrototype.cpp:
(JSC::getWeakSet):
(JSC::protoFuncWeakSetDelete):
(JSC::protoFuncWeakSetHas):
(JSC::protoFuncWeakSetAdd):
(JSC::getWeakMapData): Deleted.

2017-08-22 Saam Barati <sbarati@apple.com>

We are using valueProfileForBytecodeOffset when there may not be a value profile
Expand Down
16 changes: 8 additions & 8 deletions Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj
Expand Up @@ -2045,8 +2045,8 @@
A7CA3AE617DA41AE006538AF /* WeakMapPrototype.h in Headers */ = {isa = PBXBuildFile; fileRef = A7CA3AE017DA41AE006538AF /* WeakMapPrototype.h */; };
A7CA3AE717DA41AE006538AF /* JSWeakMap.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7CA3AE117DA41AE006538AF /* JSWeakMap.cpp */; };
A7CA3AE817DA41AE006538AF /* JSWeakMap.h in Headers */ = {isa = PBXBuildFile; fileRef = A7CA3AE217DA41AE006538AF /* JSWeakMap.h */; };
A7CA3AEB17DA5168006538AF /* WeakMapData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7CA3AE917DA5168006538AF /* WeakMapData.cpp */; };
A7CA3AEC17DA5168006538AF /* WeakMapData.h in Headers */ = {isa = PBXBuildFile; fileRef = A7CA3AEA17DA5168006538AF /* WeakMapData.h */; };
A7CA3AEB17DA5168006538AF /* WeakMapBase.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7CA3AE917DA5168006538AF /* WeakMapBase.cpp */; };
A7CA3AEC17DA5168006538AF /* WeakMapBase.h in Headers */ = {isa = PBXBuildFile; fileRef = A7CA3AEA17DA5168006538AF /* WeakMapBase.h */; };
A7D801A41880D66E0026C39B /* BuiltinExecutables.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7D801A11880D66E0026C39B /* BuiltinExecutables.cpp */; };
A7D801A51880D66E0026C39B /* BuiltinExecutables.h in Headers */ = {isa = PBXBuildFile; fileRef = A7D801A21880D66E0026C39B /* BuiltinExecutables.h */; settings = {ATTRIBUTES = (Private, ); }; };
A7D801A81880D6A80026C39B /* JSCBuiltins.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7D801A61880D6A80026C39B /* JSCBuiltins.cpp */; };
Expand Down Expand Up @@ -4687,8 +4687,8 @@
A7CA3AE017DA41AE006538AF /* WeakMapPrototype.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WeakMapPrototype.h; sourceTree = "<group>"; };
A7CA3AE117DA41AE006538AF /* JSWeakMap.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSWeakMap.cpp; sourceTree = "<group>"; };
A7CA3AE217DA41AE006538AF /* JSWeakMap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSWeakMap.h; sourceTree = "<group>"; };
A7CA3AE917DA5168006538AF /* WeakMapData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WeakMapData.cpp; sourceTree = "<group>"; };
A7CA3AEA17DA5168006538AF /* WeakMapData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WeakMapData.h; sourceTree = "<group>"; };
A7CA3AE917DA5168006538AF /* WeakMapBase.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WeakMapBase.cpp; sourceTree = "<group>"; };
A7CA3AEA17DA5168006538AF /* WeakMapBase.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WeakMapBase.h; sourceTree = "<group>"; };
A7D801A01880D66E0026C39B /* ArrayPrototype.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = ArrayPrototype.js; sourceTree = "<group>"; };
A7D801A11880D66E0026C39B /* BuiltinExecutables.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = BuiltinExecutables.cpp; sourceTree = "<group>"; };
A7D801A21880D66E0026C39B /* BuiltinExecutables.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BuiltinExecutables.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -7189,10 +7189,10 @@
FED94F2C171E3E2300BE77A4 /* Watchdog.h */,
14BFCE6810CDB1FC00364CCE /* WeakGCMap.h */,
AD86A93D1AA4D87C002FE77F /* WeakGCMapInlines.h */,
A7CA3AE917DA5168006538AF /* WeakMapBase.cpp */,
A7CA3AEA17DA5168006538AF /* WeakMapBase.h */,
A7CA3ADD17DA41AE006538AF /* WeakMapConstructor.cpp */,
A7CA3ADE17DA41AE006538AF /* WeakMapConstructor.h */,
A7CA3AE917DA5168006538AF /* WeakMapData.cpp */,
A7CA3AEA17DA5168006538AF /* WeakMapData.h */,
A7CA3ADF17DA41AE006538AF /* WeakMapPrototype.cpp */,
A7CA3AE017DA41AE006538AF /* WeakMapPrototype.h */,
709FB8631AE335C60039D069 /* WeakSetConstructor.cpp */,
Expand Down Expand Up @@ -9600,8 +9600,8 @@
14F7256614EE265E00B1652B /* WeakHandleOwner.h in Headers */,
14E84FA214EE1ACC00D6D5D4 /* WeakImpl.h in Headers */,
14BE7D3317135CF400D1807A /* WeakInlines.h in Headers */,
A7CA3AEC17DA5168006538AF /* WeakMapBase.h in Headers */,
A7CA3AE417DA41AE006538AF /* WeakMapConstructor.h in Headers */,
A7CA3AEC17DA5168006538AF /* WeakMapData.h in Headers */,
A7CA3AE617DA41AE006538AF /* WeakMapPrototype.h in Headers */,
0F242DA713F3B1E8007ADD4C /* WeakReferenceHarvester.h in Headers */,
14E84FA114EE1ACC00D6D5D4 /* WeakSet.h in Headers */,
Expand Down Expand Up @@ -11083,8 +11083,8 @@
1ACF7377171CA6FB00C9BB1E /* Weak.cpp in Sources */,
14E84F9E14EE1ACC00D6D5D4 /* WeakBlock.cpp in Sources */,
14F7256514EE265E00B1652B /* WeakHandleOwner.cpp in Sources */,
A7CA3AEB17DA5168006538AF /* WeakMapBase.cpp in Sources */,
A7CA3AE317DA41AE006538AF /* WeakMapConstructor.cpp in Sources */,
A7CA3AEB17DA5168006538AF /* WeakMapData.cpp in Sources */,
A7CA3AE517DA41AE006538AF /* WeakMapPrototype.cpp in Sources */,
14E84FA014EE1ACC00D6D5D4 /* WeakSet.cpp in Sources */,
709FB8691AE335C60039D069 /* WeakSetConstructor.cpp in Sources */,
Expand Down
10 changes: 5 additions & 5 deletions Source/JavaScriptCore/inspector/JSInjectedScriptHost.cpp
Expand Up @@ -57,7 +57,7 @@
#include "ScopedArguments.h"
#include "SourceCode.h"
#include "TypedArrayInlines.h"
#include "WeakMapData.h"
#include "WeakMapBase.h"

using namespace JSC;

Expand Down Expand Up @@ -424,7 +424,7 @@ JSValue JSInjectedScriptHost::weakMapSize(ExecState* exec)
if (!weakMap)
return jsUndefined();

return jsNumber(weakMap->weakMapData()->size());
return jsNumber(weakMap->size());
}

JSValue JSInjectedScriptHost::weakMapEntries(ExecState* exec)
Expand All @@ -449,7 +449,7 @@ JSValue JSInjectedScriptHost::weakMapEntries(ExecState* exec)

JSArray* array = constructEmptyArray(exec, nullptr);
RETURN_IF_EXCEPTION(scope, JSValue());
for (auto it = weakMap->weakMapData()->begin(); it != weakMap->weakMapData()->end(); ++it) {
for (auto it = weakMap->begin(); it != weakMap->end(); ++it) {
JSObject* entry = constructEmptyObject(exec);
entry->putDirect(exec->vm(), Identifier::fromString(exec, "key"), it->key);
entry->putDirect(exec->vm(), Identifier::fromString(exec, "value"), it->value.get());
Expand All @@ -473,7 +473,7 @@ JSValue JSInjectedScriptHost::weakSetSize(ExecState* exec)
if (!weakSet)
return jsUndefined();

return jsNumber(weakSet->weakMapData()->size());
return jsNumber(weakSet->size());
}

JSValue JSInjectedScriptHost::weakSetEntries(ExecState* exec)
Expand All @@ -498,7 +498,7 @@ JSValue JSInjectedScriptHost::weakSetEntries(ExecState* exec)

JSArray* array = constructEmptyArray(exec, nullptr);
RETURN_IF_EXCEPTION(scope, JSValue());
for (auto it = weakSet->weakMapData()->begin(); it != weakSet->weakMapData()->end(); ++it) {
for (auto it = weakSet->begin(); it != weakSet->end(); ++it) {
JSObject* entry = constructEmptyObject(exec);
entry->putDirect(exec->vm(), Identifier::fromString(exec, "value"), it->key);
array->putDirectIndex(exec, fetched++, entry);
Expand Down
15 changes: 1 addition & 14 deletions Source/JavaScriptCore/runtime/JSWeakMap.cpp
Expand Up @@ -27,25 +27,12 @@
#include "JSWeakMap.h"

#include "JSCInlines.h"
#include "WeakMapData.h"
#include "WeakMapBase.h"

namespace JSC {

const ClassInfo JSWeakMap::s_info = { "WeakMap", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSWeakMap) };

void JSWeakMap::finishCreation(VM& vm)
{
Base::finishCreation(vm);
m_weakMapData.set(vm, this, WeakMapData::create(vm));
}

void JSWeakMap::visitChildren(JSCell* cell, SlotVisitor& visitor)
{
Base::visitChildren(cell, visitor);
JSWeakMap* thisObj = jsCast<JSWeakMap*>(cell);
visitor.append(thisObj->m_weakMapData);
}

String JSWeakMap::toStringName(const JSObject*, ExecState*)
{
return ASCIILiteral("Object");
Expand Down
20 changes: 3 additions & 17 deletions Source/JavaScriptCore/runtime/JSWeakMap.h
Expand Up @@ -26,14 +26,13 @@
#pragma once

#include "JSObject.h"
#include "WeakMapBase.h"

namespace JSC {

class WeakMapData;

class JSWeakMap : public JSNonFinalObject {
class JSWeakMap final : public WeakMapBase {
public:
typedef JSNonFinalObject Base;
using Base = WeakMapBase;

DECLARE_EXPORT_INFO;

Expand All @@ -54,26 +53,13 @@ class JSWeakMap : public JSNonFinalObject {
return create(exec->vm(), structure);
}

WeakMapData* weakMapData() { return m_weakMapData.get(); }

JSValue get(CallFrame*, JSObject*);
bool has(CallFrame*, JSObject*);
bool remove(CallFrame*, JSObject*);

void set(CallFrame*, JSObject*, JSValue);
void clear(CallFrame*);

private:
JSWeakMap(VM& vm, Structure* structure)
: Base(vm, structure)
{
}

void finishCreation(VM&);
static void visitChildren(JSCell*, SlotVisitor&);
static String toStringName(const JSObject*, ExecState*);

WriteBarrier<WeakMapData> m_weakMapData;
};

} // namespace JSC
15 changes: 1 addition & 14 deletions Source/JavaScriptCore/runtime/JSWeakSet.cpp
Expand Up @@ -27,25 +27,12 @@
#include "JSWeakSet.h"

#include "JSCInlines.h"
#include "WeakMapData.h"
#include "WeakMapBase.h"

namespace JSC {

const ClassInfo JSWeakSet::s_info = { "WeakSet", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSWeakSet) };

void JSWeakSet::finishCreation(VM& vm)
{
Base::finishCreation(vm);
m_weakMapData.set(vm, this, WeakMapData::create(vm));
}

void JSWeakSet::visitChildren(JSCell* cell, SlotVisitor& visitor)
{
Base::visitChildren(cell, visitor);
JSWeakSet* thisObj = jsCast<JSWeakSet*>(cell);
visitor.append(thisObj->m_weakMapData);
}

String JSWeakSet::toStringName(const JSC::JSObject*, ExecState*)
{
return ASCIILiteral("Object");
Expand Down
20 changes: 3 additions & 17 deletions Source/JavaScriptCore/runtime/JSWeakSet.h
Expand Up @@ -26,14 +26,13 @@
#pragma once

#include "JSObject.h"
#include "WeakMapBase.h"

namespace JSC {

class WeakMapData;

class JSWeakSet : public JSNonFinalObject {
class JSWeakSet final : public WeakMapBase {
public:
typedef JSNonFinalObject Base;
using Base = WeakMapBase;

DECLARE_EXPORT_INFO;

Expand All @@ -54,26 +53,13 @@ class JSWeakSet : public JSNonFinalObject {
return create(exec->vm(), structure);
}

WeakMapData* weakMapData() { return m_weakMapData.get(); }

JSValue get(CallFrame*, JSObject*);
bool has(CallFrame*, JSObject*);
bool remove(CallFrame*, JSObject*);

void set(CallFrame*, JSObject*, JSValue);
void clear(CallFrame*);

private:
JSWeakSet(VM& vm, Structure* structure)
: Base(vm, structure)
{
}

void finishCreation(VM&);
static void visitChildren(JSCell*, SlotVisitor&);
static String toStringName(const JSObject*, ExecState*);

WriteBarrier<WeakMapData> m_weakMapData;
};

} // namespace JSC
2 changes: 0 additions & 2 deletions Source/JavaScriptCore/runtime/VM.cpp
Expand Up @@ -111,7 +111,6 @@
#include "WasmWorklist.h"
#include "Watchdog.h"
#include "WeakGCMapInlines.h"
#include "WeakMapData.h"
#include <wtf/CurrentTime.h>
#include <wtf/ProcessID.h>
#include <wtf/ReadWriteLock.h>
Expand Down Expand Up @@ -260,7 +259,6 @@ VM::VM(VMType vmType, HeapType heapType)
unlinkedFunctionCodeBlockStructure.set(*this, UnlinkedFunctionCodeBlock::createStructure(*this, 0, jsNull()));
unlinkedModuleProgramCodeBlockStructure.set(*this, UnlinkedModuleProgramCodeBlock::createStructure(*this, 0, jsNull()));
propertyTableStructure.set(*this, PropertyTable::createStructure(*this, 0, jsNull()));
weakMapDataStructure.set(*this, WeakMapData::createStructure(*this, 0, jsNull()));
inferredValueStructure.set(*this, InferredValue::createStructure(*this, 0, jsNull()));
inferredTypeStructure.set(*this, InferredType::createStructure(*this, 0, jsNull()));
inferredTypeTableStructure.set(*this, InferredTypeTable::createStructure(*this, 0, jsNull()));
Expand Down
1 change: 0 additions & 1 deletion Source/JavaScriptCore/runtime/VM.h
Expand Up @@ -368,7 +368,6 @@ class VM : public ThreadSafeRefCounted<VM>, public DoublyLinkedListNode<VM> {
Strong<Structure> unlinkedFunctionCodeBlockStructure;
Strong<Structure> unlinkedModuleProgramCodeBlockStructure;
Strong<Structure> propertyTableStructure;
Strong<Structure> weakMapDataStructure;
Strong<Structure> inferredValueStructure;
Strong<Structure> inferredTypeStructure;
Strong<Structure> inferredTypeTableStructure;
Expand Down

0 comments on commit 71bb8c3

Please sign in to comment.