Changeset 221223 in webkit
- Timestamp:
- Aug 26, 2017, 1:01:24 AM (9 years ago)
- Location:
- trunk/Source/JavaScriptCore
- Files:
-
- 12 edited
- 2 moved
-
CMakeLists.txt (modified) (1 diff)
-
ChangeLog (modified) (1 diff)
-
JavaScriptCore.xcodeproj/project.pbxproj (modified) (5 diffs)
-
inspector/JSInjectedScriptHost.cpp (modified) (5 diffs)
-
runtime/JSWeakMap.cpp (modified) (1 diff)
-
runtime/JSWeakMap.h (modified) (3 diffs)
-
runtime/JSWeakSet.cpp (modified) (1 diff)
-
runtime/JSWeakSet.h (modified) (3 diffs)
-
runtime/VM.cpp (modified) (2 diffs)
-
runtime/VM.h (modified) (1 diff)
-
runtime/WeakMapBase.cpp (moved) (moved from trunk/Source/JavaScriptCore/runtime/WeakMapData.cpp ) (7 diffs)
-
runtime/WeakMapBase.h (moved) (moved from trunk/Source/JavaScriptCore/runtime/WeakMapData.h ) (3 diffs)
-
runtime/WeakMapPrototype.cpp (modified) (7 diffs)
-
runtime/WeakSetPrototype.cpp (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/CMakeLists.txt
r221196 r221223 936 936 runtime/VarOffset.cpp 937 937 runtime/Watchdog.cpp 938 runtime/WeakMapBase.cpp 938 939 runtime/WeakMapConstructor.cpp 939 runtime/WeakMapData.cpp940 940 runtime/WeakMapPrototype.cpp 941 941 runtime/WeakSetConstructor.cpp -
trunk/Source/JavaScriptCore/ChangeLog
r221213 r221223 1 2017-08-26 Yusuke Suzuki <utatane.tea@gmail.com> 2 3 Merge WeakMapData into JSWeakMap and JSWeakSet 4 https://bugs.webkit.org/show_bug.cgi?id=143919 5 6 Reviewed by Darin Adler. 7 8 This patch changes WeakMapData from JSCell to JSDestructibleObject, 9 renaming it to WeakMapBase, and JSWeakMap and JSWeakSet simply inherit 10 it instead of separately allocating WeakMapData. This reduces memory 11 consumption and allocation times. 12 13 Also this patch a bit optimizes sizeof(DeadKeyCleaner) by dropping m_target 14 field. Since this class is always embedded in WeakMapBase, we can calculate 15 WeakMapBase address from the address of DeadKeyCleaner. 16 17 This patch does not include the optimization changing WeakMapData to Set 18 for JSWeakSet. 19 20 * CMakeLists.txt: 21 * JavaScriptCore.xcodeproj/project.pbxproj: 22 * inspector/JSInjectedScriptHost.cpp: 23 (Inspector::JSInjectedScriptHost::weakMapSize): 24 (Inspector::JSInjectedScriptHost::weakMapEntries): 25 (Inspector::JSInjectedScriptHost::weakSetSize): 26 (Inspector::JSInjectedScriptHost::weakSetEntries): 27 * runtime/JSWeakMap.cpp: 28 (JSC::JSWeakMap::finishCreation): Deleted. 29 (JSC::JSWeakMap::visitChildren): Deleted. 30 * runtime/JSWeakMap.h: 31 (JSC::JSWeakMap::createStructure): Deleted. 32 (JSC::JSWeakMap::create): Deleted. 33 (JSC::JSWeakMap::weakMapData): Deleted. 34 (JSC::JSWeakMap::JSWeakMap): Deleted. 35 * runtime/JSWeakSet.cpp: 36 (JSC::JSWeakSet::finishCreation): Deleted. 37 (JSC::JSWeakSet::visitChildren): Deleted. 38 * runtime/JSWeakSet.h: 39 (JSC::JSWeakSet::createStructure): Deleted. 40 (JSC::JSWeakSet::create): Deleted. 41 (JSC::JSWeakSet::weakMapData): Deleted. 42 (JSC::JSWeakSet::JSWeakSet): Deleted. 43 * runtime/VM.cpp: 44 (JSC::VM::VM): 45 * runtime/VM.h: 46 * runtime/WeakMapBase.cpp: Renamed from Source/JavaScriptCore/runtime/WeakMapData.cpp. 47 (JSC::WeakMapBase::WeakMapBase): 48 (JSC::WeakMapBase::destroy): 49 (JSC::WeakMapBase::estimatedSize): 50 (JSC::WeakMapBase::visitChildren): 51 (JSC::WeakMapBase::set): 52 (JSC::WeakMapBase::get): 53 (JSC::WeakMapBase::remove): 54 (JSC::WeakMapBase::contains): 55 (JSC::WeakMapBase::clear): 56 (JSC::WeakMapBase::DeadKeyCleaner::target): 57 (JSC::WeakMapBase::DeadKeyCleaner::visitWeakReferences): 58 (JSC::WeakMapBase::DeadKeyCleaner::finalizeUnconditionally): 59 * runtime/WeakMapBase.h: Renamed from Source/JavaScriptCore/runtime/WeakMapData.h. 60 (JSC::WeakMapBase::size const): 61 * runtime/WeakMapPrototype.cpp: 62 (JSC::getWeakMap): 63 (JSC::protoFuncWeakMapDelete): 64 (JSC::protoFuncWeakMapGet): 65 (JSC::protoFuncWeakMapHas): 66 (JSC::protoFuncWeakMapSet): 67 (JSC::getWeakMapData): Deleted. 68 * runtime/WeakSetPrototype.cpp: 69 (JSC::getWeakSet): 70 (JSC::protoFuncWeakSetDelete): 71 (JSC::protoFuncWeakSetHas): 72 (JSC::protoFuncWeakSetAdd): 73 (JSC::getWeakMapData): Deleted. 74 1 75 2017-08-25 Daniel Bates <dabates@apple.com> 2 76 -
trunk/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj
r221196 r221223 2057 2057 A7CA3AE717DA41AE006538AF /* JSWeakMap.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7CA3AE117DA41AE006538AF /* JSWeakMap.cpp */; }; 2058 2058 A7CA3AE817DA41AE006538AF /* JSWeakMap.h in Headers */ = {isa = PBXBuildFile; fileRef = A7CA3AE217DA41AE006538AF /* JSWeakMap.h */; }; 2059 A7CA3AEB17DA5168006538AF /* WeakMap Data.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7CA3AE917DA5168006538AF /* WeakMapData.cpp */; };2060 A7CA3AEC17DA5168006538AF /* WeakMap Data.h in Headers */ = {isa = PBXBuildFile; fileRef = A7CA3AEA17DA5168006538AF /* WeakMapData.h */; };2059 A7CA3AEB17DA5168006538AF /* WeakMapBase.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7CA3AE917DA5168006538AF /* WeakMapBase.cpp */; }; 2060 A7CA3AEC17DA5168006538AF /* WeakMapBase.h in Headers */ = {isa = PBXBuildFile; fileRef = A7CA3AEA17DA5168006538AF /* WeakMapBase.h */; }; 2061 2061 A7D801A41880D66E0026C39B /* BuiltinExecutables.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7D801A11880D66E0026C39B /* BuiltinExecutables.cpp */; }; 2062 2062 A7D801A51880D66E0026C39B /* BuiltinExecutables.h in Headers */ = {isa = PBXBuildFile; fileRef = A7D801A21880D66E0026C39B /* BuiltinExecutables.h */; settings = {ATTRIBUTES = (Private, ); }; }; … … 4717 4717 A7CA3AE117DA41AE006538AF /* JSWeakMap.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSWeakMap.cpp; sourceTree = "<group>"; }; 4718 4718 A7CA3AE217DA41AE006538AF /* JSWeakMap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSWeakMap.h; sourceTree = "<group>"; }; 4719 A7CA3AE917DA5168006538AF /* WeakMap Data.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WeakMapData.cpp; sourceTree = "<group>"; };4720 A7CA3AEA17DA5168006538AF /* WeakMap Data.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WeakMapData.h; sourceTree = "<group>"; };4719 A7CA3AE917DA5168006538AF /* WeakMapBase.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WeakMapBase.cpp; sourceTree = "<group>"; }; 4720 A7CA3AEA17DA5168006538AF /* WeakMapBase.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WeakMapBase.h; sourceTree = "<group>"; }; 4721 4721 A7D801A01880D66E0026C39B /* ArrayPrototype.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = ArrayPrototype.js; sourceTree = "<group>"; }; 4722 4722 A7D801A11880D66E0026C39B /* BuiltinExecutables.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = BuiltinExecutables.cpp; sourceTree = "<group>"; }; … … 7236 7236 14BFCE6810CDB1FC00364CCE /* WeakGCMap.h */, 7237 7237 AD86A93D1AA4D87C002FE77F /* WeakGCMapInlines.h */, 7238 A7CA3AE917DA5168006538AF /* WeakMapBase.cpp */, 7239 A7CA3AEA17DA5168006538AF /* WeakMapBase.h */, 7238 7240 A7CA3ADD17DA41AE006538AF /* WeakMapConstructor.cpp */, 7239 7241 A7CA3ADE17DA41AE006538AF /* WeakMapConstructor.h */, 7240 A7CA3AE917DA5168006538AF /* WeakMapData.cpp */,7241 A7CA3AEA17DA5168006538AF /* WeakMapData.h */,7242 7242 A7CA3ADF17DA41AE006538AF /* WeakMapPrototype.cpp */, 7243 7243 A7CA3AE017DA41AE006538AF /* WeakMapPrototype.h */, … … 9660 9660 14E84FA214EE1ACC00D6D5D4 /* WeakImpl.h in Headers */, 9661 9661 14BE7D3317135CF400D1807A /* WeakInlines.h in Headers */, 9662 A7CA3AEC17DA5168006538AF /* WeakMapBase.h in Headers */, 9662 9663 A7CA3AE417DA41AE006538AF /* WeakMapConstructor.h in Headers */, 9663 A7CA3AEC17DA5168006538AF /* WeakMapData.h in Headers */,9664 9664 A7CA3AE617DA41AE006538AF /* WeakMapPrototype.h in Headers */, 9665 9665 0F242DA713F3B1E8007ADD4C /* WeakReferenceHarvester.h in Headers */, … … 11150 11150 14E84F9E14EE1ACC00D6D5D4 /* WeakBlock.cpp in Sources */, 11151 11151 14F7256514EE265E00B1652B /* WeakHandleOwner.cpp in Sources */, 11152 A7CA3AEB17DA5168006538AF /* WeakMapBase.cpp in Sources */, 11152 11153 A7CA3AE317DA41AE006538AF /* WeakMapConstructor.cpp in Sources */, 11153 A7CA3AEB17DA5168006538AF /* WeakMapData.cpp in Sources */,11154 11154 A7CA3AE517DA41AE006538AF /* WeakMapPrototype.cpp in Sources */, 11155 11155 14E84FA014EE1ACC00D6D5D4 /* WeakSet.cpp in Sources */, -
trunk/Source/JavaScriptCore/inspector/JSInjectedScriptHost.cpp
r221110 r221223 59 59 #include "SourceCode.h" 60 60 #include "TypedArrayInlines.h" 61 #include "WeakMap Data.h"61 #include "WeakMapBase.h" 62 62 63 63 using namespace JSC; … … 430 430 return jsUndefined(); 431 431 432 return jsNumber(weakMap-> weakMapData()->size());432 return jsNumber(weakMap->size()); 433 433 } 434 434 … … 455 455 JSArray* array = constructEmptyArray(exec, nullptr); 456 456 RETURN_IF_EXCEPTION(scope, JSValue()); 457 for (auto it = weakMap-> weakMapData()->begin(); it != weakMap->weakMapData()->end(); ++it) {457 for (auto it = weakMap->begin(); it != weakMap->end(); ++it) { 458 458 JSObject* entry = constructEmptyObject(exec); 459 459 entry->putDirect(exec->vm(), Identifier::fromString(exec, "key"), it->key); … … 479 479 return jsUndefined(); 480 480 481 return jsNumber(weakSet-> weakMapData()->size());481 return jsNumber(weakSet->size()); 482 482 } 483 483 … … 504 504 JSArray* array = constructEmptyArray(exec, nullptr); 505 505 RETURN_IF_EXCEPTION(scope, JSValue()); 506 for (auto it = weakSet-> weakMapData()->begin(); it != weakSet->weakMapData()->end(); ++it) {506 for (auto it = weakSet->begin(); it != weakSet->end(); ++it) { 507 507 JSObject* entry = constructEmptyObject(exec); 508 508 entry->putDirect(exec->vm(), Identifier::fromString(exec, "value"), it->key); -
trunk/Source/JavaScriptCore/runtime/JSWeakMap.cpp
r217108 r221223 28 28 29 29 #include "JSCInlines.h" 30 #include "WeakMap Data.h"30 #include "WeakMapBase.h" 31 31 32 32 namespace JSC { 33 33 34 34 const ClassInfo JSWeakMap::s_info = { "WeakMap", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSWeakMap) }; 35 36 void JSWeakMap::finishCreation(VM& vm)37 {38 Base::finishCreation(vm);39 m_weakMapData.set(vm, this, WeakMapData::create(vm));40 }41 42 void JSWeakMap::visitChildren(JSCell* cell, SlotVisitor& visitor)43 {44 Base::visitChildren(cell, visitor);45 JSWeakMap* thisObj = jsCast<JSWeakMap*>(cell);46 visitor.append(thisObj->m_weakMapData);47 }48 35 49 36 String JSWeakMap::toStringName(const JSObject*, ExecState*) -
trunk/Source/JavaScriptCore/runtime/JSWeakMap.h
r206525 r221223 27 27 28 28 #include "JSObject.h" 29 #include "WeakMapBase.h" 29 30 30 31 namespace JSC { 31 32 32 class WeakMapData; 33 34 class JSWeakMap : public JSNonFinalObject { 33 class JSWeakMap final : public WeakMapBase { 35 34 public: 36 typedef JSNonFinalObjectBase;35 using Base = WeakMapBase; 37 36 38 37 DECLARE_EXPORT_INFO; … … 55 54 } 56 55 57 WeakMapData* weakMapData() { return m_weakMapData.get(); }58 59 JSValue get(CallFrame*, JSObject*);60 bool has(CallFrame*, JSObject*);61 bool remove(CallFrame*, JSObject*);62 63 void set(CallFrame*, JSObject*, JSValue);64 void clear(CallFrame*);65 66 56 private: 67 57 JSWeakMap(VM& vm, Structure* structure) … … 70 60 } 71 61 72 void finishCreation(VM&);73 static void visitChildren(JSCell*, SlotVisitor&);74 62 static String toStringName(const JSObject*, ExecState*); 75 76 WriteBarrier<WeakMapData> m_weakMapData;77 63 }; 78 64 -
trunk/Source/JavaScriptCore/runtime/JSWeakSet.cpp
r217108 r221223 28 28 29 29 #include "JSCInlines.h" 30 #include "WeakMap Data.h"30 #include "WeakMapBase.h" 31 31 32 32 namespace JSC { 33 33 34 34 const ClassInfo JSWeakSet::s_info = { "WeakSet", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSWeakSet) }; 35 36 void JSWeakSet::finishCreation(VM& vm)37 {38 Base::finishCreation(vm);39 m_weakMapData.set(vm, this, WeakMapData::create(vm));40 }41 42 void JSWeakSet::visitChildren(JSCell* cell, SlotVisitor& visitor)43 {44 Base::visitChildren(cell, visitor);45 JSWeakSet* thisObj = jsCast<JSWeakSet*>(cell);46 visitor.append(thisObj->m_weakMapData);47 }48 35 49 36 String JSWeakSet::toStringName(const JSC::JSObject*, ExecState*) -
trunk/Source/JavaScriptCore/runtime/JSWeakSet.h
r206525 r221223 27 27 28 28 #include "JSObject.h" 29 #include "WeakMapBase.h" 29 30 30 31 namespace JSC { 31 32 32 class WeakMapData; 33 34 class JSWeakSet : public JSNonFinalObject { 33 class JSWeakSet final : public WeakMapBase { 35 34 public: 36 typedef JSNonFinalObjectBase;35 using Base = WeakMapBase; 37 36 38 37 DECLARE_EXPORT_INFO; … … 55 54 } 56 55 57 WeakMapData* weakMapData() { return m_weakMapData.get(); }58 59 JSValue get(CallFrame*, JSObject*);60 bool has(CallFrame*, JSObject*);61 bool remove(CallFrame*, JSObject*);62 63 void set(CallFrame*, JSObject*, JSValue);64 void clear(CallFrame*);65 66 56 private: 67 57 JSWeakSet(VM& vm, Structure* structure) … … 70 60 } 71 61 72 void finishCreation(VM&);73 static void visitChildren(JSCell*, SlotVisitor&);74 62 static String toStringName(const JSObject*, ExecState*); 75 76 WriteBarrier<WeakMapData> m_weakMapData;77 63 }; 78 64 -
trunk/Source/JavaScriptCore/runtime/VM.cpp
r221110 r221223 115 115 #include "Watchdog.h" 116 116 #include "WeakGCMapInlines.h" 117 #include "WeakMapData.h"118 117 #include <wtf/CurrentTime.h> 119 118 #include <wtf/ProcessID.h> … … 265 264 unlinkedModuleProgramCodeBlockStructure.set(*this, UnlinkedModuleProgramCodeBlock::createStructure(*this, 0, jsNull())); 266 265 propertyTableStructure.set(*this, PropertyTable::createStructure(*this, 0, jsNull())); 267 weakMapDataStructure.set(*this, WeakMapData::createStructure(*this, 0, jsNull()));268 266 inferredValueStructure.set(*this, InferredValue::createStructure(*this, 0, jsNull())); 269 267 inferredTypeStructure.set(*this, InferredType::createStructure(*this, 0, jsNull())); -
trunk/Source/JavaScriptCore/runtime/VM.h
r221110 r221223 370 370 Strong<Structure> unlinkedModuleProgramCodeBlockStructure; 371 371 Strong<Structure> propertyTableStructure; 372 Strong<Structure> weakMapDataStructure;373 372 Strong<Structure> inferredValueStructure; 374 373 Strong<Structure> inferredTypeStructure; -
trunk/Source/JavaScriptCore/runtime/WeakMapBase.cpp
r221222 r221223 25 25 26 26 #include "config.h" 27 #include "WeakMap Data.h"27 #include "WeakMapBase.h" 28 28 29 29 #include "ExceptionHelpers.h" … … 34 34 namespace JSC { 35 35 36 const ClassInfo WeakMap Data::s_info = { "WeakMapData", nullptr, nullptr, nullptr, CREATE_METHOD_TABLE(WeakMapData) };36 const ClassInfo WeakMapBase::s_info = { "WeakMapBase", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(WeakMapBase) }; 37 37 38 WeakMapData::WeakMapData(VM& vm) 39 : Base(vm, vm.weakMapDataStructure.get()) 40 , m_deadKeyCleaner(this) 38 WeakMapBase::WeakMapBase(VM& vm, Structure* structure) 39 : Base(vm, structure) 41 40 { 41 ASSERT(m_deadKeyCleaner.target() == this); 42 42 } 43 43 44 void WeakMap Data::finishCreation(VM& vm)44 void WeakMapBase::destroy(JSCell* cell) 45 45 { 46 Base::finishCreation(vm);46 static_cast<WeakMapBase*>(cell)->~WeakMapBase(); 47 47 } 48 48 49 void WeakMapData::destroy(JSCell* cell)49 size_t WeakMapBase::estimatedSize(JSCell* cell) 50 50 { 51 static_cast<WeakMapData*>(cell)->~WeakMapData(); 52 } 53 54 size_t WeakMapData::estimatedSize(JSCell* cell) 55 { 56 WeakMapData* thisObj = jsCast<WeakMapData*>(cell); 51 auto* thisObj = jsCast<WeakMapBase*>(cell); 57 52 return Base::estimatedSize(cell) + (thisObj->m_map.capacity() * (sizeof(JSObject*) + sizeof(WriteBarrier<Unknown>))); 58 53 } 59 54 60 void WeakMap Data::visitChildren(JSCell* cell, SlotVisitor& visitor)55 void WeakMapBase::visitChildren(JSCell* cell, SlotVisitor& visitor) 61 56 { 62 57 Base::visitChildren(cell, visitor); 63 WeakMapData* thisObj = jsCast<WeakMapData*>(cell);58 auto* thisObj = jsCast<WeakMapBase*>(cell); 64 59 visitor.addUnconditionalFinalizer(&thisObj->m_deadKeyCleaner); 65 60 visitor.addWeakReferenceHarvester(&thisObj->m_deadKeyCleaner); … … 71 66 } 72 67 73 void WeakMap Data::set(VM& vm, JSObject* key, JSValue value)68 void WeakMapBase::set(VM& vm, JSObject* key, JSValue value) 74 69 { 75 70 // Here we force the write barrier on the key. … … 78 73 } 79 74 80 JSValue WeakMap Data::get(JSObject* key)75 JSValue WeakMapBase::get(JSObject* key) 81 76 { 82 77 auto iter = m_map.find(key); … … 86 81 } 87 82 88 bool WeakMap Data::remove(JSObject* key)83 bool WeakMapBase::remove(JSObject* key) 89 84 { 90 auto iter = m_map.find(key); 91 if (iter == m_map.end()) 92 return false; 93 94 m_map.remove(iter); 95 return true; 85 return m_map.remove(key); 96 86 } 97 87 98 bool WeakMap Data::contains(JSObject* key)88 bool WeakMapBase::contains(JSObject* key) 99 89 { 100 90 return m_map.contains(key); 101 91 } 102 92 103 void WeakMap Data::clear()93 void WeakMapBase::clear() 104 94 { 105 95 m_map.clear(); 106 96 } 107 97 108 void WeakMapData::DeadKeyCleaner::visitWeakReferences(SlotVisitor& visitor)98 inline WeakMapBase* WeakMapBase::DeadKeyCleaner::target() 109 99 { 100 return bitwise_cast<WeakMapBase*>(bitwise_cast<char*>(this) - OBJECT_OFFSETOF(WeakMapBase, m_deadKeyCleaner)); 101 } 102 103 void WeakMapBase::DeadKeyCleaner::visitWeakReferences(SlotVisitor& visitor) 104 { 105 WeakMapBase* map = target(); 110 106 m_liveKeyCount = 0; 111 for (auto& pair : m _target->m_map) {107 for (auto& pair : map->m_map) { 112 108 if (!Heap::isMarked(pair.key)) 113 109 continue; … … 115 111 visitor.append(pair.value); 116 112 } 117 RELEASE_ASSERT(m_liveKeyCount <= m_target->m_map.size());113 ASSERT(m_liveKeyCount <= map->m_map.size()); 118 114 } 119 115 120 void WeakMap Data::DeadKeyCleaner::finalizeUnconditionally()116 void WeakMapBase::DeadKeyCleaner::finalizeUnconditionally() 121 117 { 122 if (m_liveKeyCount > m_target->m_map.size() / 2) { 123 RELEASE_ASSERT(m_liveKeyCount <= m_target->m_map.size()); 124 int deadCount = m_target->m_map.size() - m_liveKeyCount; 118 WeakMapBase* map = target(); 119 if (m_liveKeyCount > map->m_map.size() / 2) { 120 RELEASE_ASSERT(m_liveKeyCount <= map->m_map.size()); 121 int deadCount = map->m_map.size() - m_liveKeyCount; 125 122 if (!deadCount) 126 123 return; 127 124 Vector<JSObject*> deadEntries; 128 125 deadEntries.reserveCapacity(deadCount); 129 for (auto& pair : m _target->m_map) {126 for (auto& pair : map->m_map) { 130 127 if (Heap::isMarked(pair.key)) 131 128 continue; … … 133 130 } 134 131 for (auto& deadEntry : deadEntries) 135 m _target->m_map.remove(deadEntry);132 map->m_map.remove(deadEntry); 136 133 } else { 137 134 MapType newMap; 138 for (auto& pair : m _target->m_map) {135 for (auto& pair : map->m_map) { 139 136 if (!Heap::isMarked(pair.key)) 140 137 continue; 141 138 newMap.add(pair.key, pair.value); 142 139 } 143 m _target->m_map.swap(newMap);140 map->m_map.swap(newMap); 144 141 } 145 142 } -
trunk/Source/JavaScriptCore/runtime/WeakMapBase.h
r221222 r221223 26 26 #pragma once 27 27 28 #include "JS Cell.h"28 #include "JSDestructibleObject.h" 29 29 #include "Structure.h" 30 30 #include <wtf/HashMap.h> … … 33 33 namespace JSC { 34 34 35 class WeakMap Data final : public JSCell{35 class WeakMapBase : public JSDestructibleObject { 36 36 public: 37 typedef JSCell Base; 38 static const unsigned StructureFlags = Base::StructureFlags | StructureIsImmortal; 39 40 static WeakMapData* create(VM& vm) 41 { 42 WeakMapData* weakMapData = new (NotNull, allocateCell<WeakMapData>(vm.heap)) WeakMapData(vm); 43 weakMapData->finishCreation(vm); 44 return weakMapData; 45 } 46 47 static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype) 48 { 49 return Structure::create(vm, globalObject, prototype, TypeInfo(CellType, StructureFlags), info()); 50 } 51 52 static const bool needsDestruction = true; 37 using Base = JSDestructibleObject; 53 38 54 39 void set(VM&, JSObject*, JSValue); … … 60 45 DECLARE_INFO; 61 46 62 typedef HashMap<JSObject*, WriteBarrier<Unknown>> MapType;47 using MapType = HashMap<JSObject*, WriteBarrier<Unknown>>; 63 48 MapType::const_iterator begin() const { return m_map.begin(); } 64 49 MapType::const_iterator end() const { return m_map.end(); } 65 50 66 intsize() const { return m_map.size(); }51 unsigned size() const { return m_map.size(); } 67 52 68 private:69 WeakMapData(VM&);70 static void destroy(JSCell*);71 53 static size_t estimatedSize(JSCell*); 72 54 static void visitChildren(JSCell*, SlotVisitor&); 73 void finishCreation(VM&); 55 56 protected: 57 WeakMapBase(VM&, Structure*); 58 static void destroy(JSCell*); 74 59 75 60 class DeadKeyCleaner : public UnconditionalFinalizer, public WeakReferenceHarvester { 76 61 public: 77 DeadKeyCleaner(WeakMapData* target) 78 : m_target(target) 79 { 80 } 62 WeakMapBase* target(); 63 81 64 private: 82 65 void visitWeakReferences(SlotVisitor&) override; 83 66 void finalizeUnconditionally() override; 84 67 unsigned m_liveKeyCount; 85 WeakMapData* m_target;86 68 }; 87 69 DeadKeyCleaner m_deadKeyCleaner; -
trunk/Source/JavaScriptCore/runtime/WeakMapPrototype.cpp
r217108 r221223 29 29 #include "JSCInlines.h" 30 30 #include "JSWeakMap.h" 31 #include "WeakMap Data.h"31 #include "WeakMapBase.h" 32 32 33 33 namespace JSC { … … 54 54 } 55 55 56 static WeakMapData* getWeakMapData(CallFrame* callFrame, JSValue value)56 static JSWeakMap* getWeakMap(CallFrame* callFrame, JSValue value) 57 57 { 58 58 VM& vm = callFrame->vm(); … … 65 65 66 66 if (JSWeakMap* weakMap = jsDynamicCast<JSWeakMap*>(vm, value)) 67 return weakMap ->weakMapData();67 return weakMap; 68 68 69 69 throwTypeError(callFrame, scope, WTF::ASCIILiteral("Called WeakMap function on a non-WeakMap object")); … … 73 73 EncodedJSValue JSC_HOST_CALL protoFuncWeakMapDelete(CallFrame* callFrame) 74 74 { 75 WeakMapData* map = getWeakMapData(callFrame, callFrame->thisValue());75 auto* map = getWeakMap(callFrame, callFrame->thisValue()); 76 76 if (!map) 77 77 return JSValue::encode(jsUndefined()); … … 82 82 EncodedJSValue JSC_HOST_CALL protoFuncWeakMapGet(CallFrame* callFrame) 83 83 { 84 WeakMapData* map = getWeakMapData(callFrame, callFrame->thisValue());84 auto* map = getWeakMap(callFrame, callFrame->thisValue()); 85 85 if (!map) 86 86 return JSValue::encode(jsUndefined()); … … 93 93 EncodedJSValue JSC_HOST_CALL protoFuncWeakMapHas(CallFrame* callFrame) 94 94 { 95 WeakMapData* map = getWeakMapData(callFrame, callFrame->thisValue());95 auto* map = getWeakMap(callFrame, callFrame->thisValue()); 96 96 if (!map) 97 97 return JSValue::encode(jsUndefined()); … … 105 105 auto scope = DECLARE_THROW_SCOPE(vm); 106 106 107 WeakMapData* map = getWeakMapData(callFrame, callFrame->thisValue());107 auto* map = getWeakMap(callFrame, callFrame->thisValue()); 108 108 ASSERT(!!scope.exception() == !map); 109 109 if (!map) -
trunk/Source/JavaScriptCore/runtime/WeakSetPrototype.cpp
r217108 r221223 29 29 #include "JSCInlines.h" 30 30 #include "JSWeakSet.h" 31 #include "WeakMap Data.h"31 #include "WeakMapBase.h" 32 32 33 33 namespace JSC { … … 52 52 } 53 53 54 static WeakMapData* getWeakMapData(CallFrame* callFrame, JSValue value)54 static JSWeakSet* getWeakSet(CallFrame* callFrame, JSValue value) 55 55 { 56 56 VM& vm = callFrame->vm(); … … 63 63 64 64 if (JSWeakSet* weakSet = jsDynamicCast<JSWeakSet*>(vm, value)) 65 return weakSet ->weakMapData();65 return weakSet; 66 66 67 67 throwTypeError(callFrame, scope, WTF::ASCIILiteral("Called WeakSet function on a non-WeakSet object")); … … 71 71 EncodedJSValue JSC_HOST_CALL protoFuncWeakSetDelete(CallFrame* callFrame) 72 72 { 73 WeakMapData* map = getWeakMapData(callFrame, callFrame->thisValue());74 if (! map)73 auto* set = getWeakSet(callFrame, callFrame->thisValue()); 74 if (!set) 75 75 return JSValue::encode(jsUndefined()); 76 76 JSValue key = callFrame->argument(0); 77 return JSValue::encode(jsBoolean(key.isObject() && map->remove(asObject(key))));77 return JSValue::encode(jsBoolean(key.isObject() && set->remove(asObject(key)))); 78 78 } 79 79 80 80 EncodedJSValue JSC_HOST_CALL protoFuncWeakSetHas(CallFrame* callFrame) 81 81 { 82 WeakMapData* map = getWeakMapData(callFrame, callFrame->thisValue());83 if (! map)82 auto* set = getWeakSet(callFrame, callFrame->thisValue()); 83 if (!set) 84 84 return JSValue::encode(jsUndefined()); 85 85 JSValue key = callFrame->argument(0); 86 return JSValue::encode(jsBoolean(key.isObject() && map->contains(asObject(key))));86 return JSValue::encode(jsBoolean(key.isObject() && set->contains(asObject(key)))); 87 87 } 88 88 … … 92 92 auto scope = DECLARE_THROW_SCOPE(vm); 93 93 94 WeakMapData* map = getWeakMapData(callFrame, callFrame->thisValue());95 ASSERT(!!scope.exception() == ! map);96 if (! map)94 auto* set = getWeakSet(callFrame, callFrame->thisValue()); 95 ASSERT(!!scope.exception() == !set); 96 if (!set) 97 97 return JSValue::encode(jsUndefined()); 98 98 JSValue key = callFrame->argument(0); 99 99 if (!key.isObject()) 100 100 return JSValue::encode(throwTypeError(callFrame, scope, WTF::ASCIILiteral("Attempted to add a non-object key to a WeakSet"))); 101 map->set(vm, asObject(key), jsUndefined());101 set->set(vm, asObject(key), jsUndefined()); 102 102 return JSValue::encode(callFrame->thisValue()); 103 103 }
Note:
See TracChangeset
for help on using the changeset viewer.