Changeset 248751 in webkit
- Timestamp:
- Aug 15, 2019, 5:12:42 PM (7 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 2 added
- 12 edited
-
ChangeLog (modified) (1 diff)
-
Modules/indexeddb/server/IDBSerializationContext.cpp (added)
-
Modules/indexeddb/server/IDBSerializationContext.h (added)
-
Modules/indexeddb/server/IDBServer.cpp (modified) (1 diff)
-
Modules/indexeddb/server/MemoryIDBBackingStore.cpp (modified) (2 diffs)
-
Modules/indexeddb/server/MemoryIDBBackingStore.h (modified) (2 diffs)
-
Modules/indexeddb/server/MemoryObjectStore.cpp (modified) (5 diffs)
-
Modules/indexeddb/server/MemoryObjectStore.h (modified) (5 diffs)
-
Modules/indexeddb/server/SQLiteIDBBackingStore.cpp (modified) (7 diffs)
-
Modules/indexeddb/server/SQLiteIDBBackingStore.h (modified) (3 diffs)
-
Modules/indexeddb/server/UniqueIDBDatabase.cpp (modified) (1 diff)
-
Modules/indexeddb/server/UniqueIDBDatabase.h (modified) (2 diffs)
-
Sources.txt (modified) (1 diff)
-
WebCore.xcodeproj/project.pbxproj (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r248750 r248751 1 2019-08-15 Sihui Liu <sihui_liu@apple.com> 2 3 Use one VM per thread for IDB serialization work in network process 4 https://bugs.webkit.org/show_bug.cgi?id=200526 5 6 Reviewed by Geoffrey Garen. 7 8 We had one static VM in UniqueIDBDatabase for serialization/deserialization in MemoryObjectStore. This VM was 9 never destroyed and could be used on different background threads. 10 11 We also had one VM per SQLiteIDBBackingStore for serialization/deserialization in SQLiteIDBBackingStore. If 12 there were multiple IndexedDB databases of the same session opened, we would have multiple VMs created 13 on the same thread. Each VM has its memory allocator and garbage collector, which takes up memory. 14 15 To be more memory efficient and safe, we can use one VM per thread in the network process, and create/destroy 16 the VMs on demand. 17 18 * Modules/indexeddb/server/IDBSerializationContext.cpp: Added. 19 (WebCore::IDBServer::IDBSerializationContext::getOrCreateIDBSerializationContext): 20 (WebCore::IDBServer::IDBSerializationContext::~IDBSerializationContext): 21 (WebCore::IDBServer::IDBSerializationContext::initializeVM): 22 (WebCore::IDBServer::IDBSerializationContext::vm): 23 (WebCore::IDBServer::IDBSerializationContext::execState): 24 (WebCore::IDBServer::IDBSerializationContext::IDBSerializationContext): 25 * Modules/indexeddb/server/IDBSerializationContext.h: Added. 26 * Modules/indexeddb/server/IDBServer.cpp: 27 (WebCore::IDBServer::IDBServer::createBackingStore): 28 * Modules/indexeddb/server/MemoryIDBBackingStore.cpp: 29 (WebCore::IDBServer::MemoryIDBBackingStore::create): 30 (WebCore::IDBServer::MemoryIDBBackingStore::MemoryIDBBackingStore): 31 (WebCore::IDBServer::MemoryIDBBackingStore::createObjectStore): 32 * Modules/indexeddb/server/MemoryIDBBackingStore.h: 33 * Modules/indexeddb/server/MemoryObjectStore.cpp: 34 (WebCore::IDBServer::MemoryObjectStore::create): 35 (WebCore::IDBServer::MemoryObjectStore::MemoryObjectStore): 36 (WebCore::IDBServer::MemoryObjectStore::updateIndexesForPutRecord): 37 (WebCore::IDBServer::MemoryObjectStore::populateIndexWithExistingRecords): 38 * Modules/indexeddb/server/MemoryObjectStore.h: 39 * Modules/indexeddb/server/SQLiteIDBBackingStore.cpp: 40 (WebCore::IDBServer::SQLiteIDBBackingStore::SQLiteIDBBackingStore): 41 (WebCore::IDBServer::SQLiteIDBBackingStore::~SQLiteIDBBackingStore): 42 (WebCore::IDBServer::SQLiteIDBBackingStore::updateOneIndexForAddRecord): 43 (WebCore::IDBServer::SQLiteIDBBackingStore::updateAllIndexesForAddRecord): 44 (WebCore::IDBServer::SQLiteIDBBackingStore::initializeVM): Deleted. 45 (WebCore::IDBServer::SQLiteIDBBackingStore::vm): Deleted. 46 (WebCore::IDBServer::SQLiteIDBBackingStore::globalObject): Deleted. 47 * Modules/indexeddb/server/SQLiteIDBBackingStore.h: 48 * Modules/indexeddb/server/UniqueIDBDatabase.cpp: 49 (WebCore::IDBServer::UniqueIDBDatabase::databaseThreadVM): Deleted. 50 (WebCore::IDBServer::UniqueIDBDatabase::databaseThreadExecState): Deleted. 51 * Modules/indexeddb/server/UniqueIDBDatabase.h: 52 * Sources.txt: 53 1 54 2019-08-15 Zalan Bujtas <zalan@apple.com> 2 55 -
trunk/Source/WebCore/Modules/indexeddb/server/IDBServer.cpp
r248699 r248751 134 134 135 135 if (m_databaseDirectoryPath.isEmpty()) 136 return MemoryIDBBackingStore::create( identifier);136 return MemoryIDBBackingStore::create(m_sessionID, identifier); 137 137 138 138 return std::make_unique<SQLiteIDBBackingStore>(m_sessionID, identifier, m_databaseDirectoryPath, m_backingStoreTemporaryFileHandler, m_perOriginQuota); -
trunk/Source/WebCore/Modules/indexeddb/server/MemoryIDBBackingStore.cpp
r244436 r248751 47 47 static uint64_t maxGeneratedKeyValue = 0x20000000000000; 48 48 49 std::unique_ptr<MemoryIDBBackingStore> MemoryIDBBackingStore::create( const IDBDatabaseIdentifier& identifier)50 { 51 return std::make_unique<MemoryIDBBackingStore>( identifier);52 } 53 54 MemoryIDBBackingStore::MemoryIDBBackingStore( const IDBDatabaseIdentifier& identifier)49 std::unique_ptr<MemoryIDBBackingStore> MemoryIDBBackingStore::create(PAL::SessionID sessionID, const IDBDatabaseIdentifier& identifier) 50 { 51 return std::make_unique<MemoryIDBBackingStore>(sessionID, identifier); 52 } 53 54 MemoryIDBBackingStore::MemoryIDBBackingStore(PAL::SessionID sessionID, const IDBDatabaseIdentifier& identifier) 55 55 : m_identifier(identifier) 56 , m_sessionID(sessionID) 56 57 { 57 58 } … … 136 137 137 138 ASSERT(!m_objectStoresByIdentifier.contains(info.identifier())); 138 auto objectStore = MemoryObjectStore::create( info);139 auto objectStore = MemoryObjectStore::create(m_sessionID, info); 139 140 140 141 m_databaseInfo->addExistingObjectStore(info); -
trunk/Source/WebCore/Modules/indexeddb/server/MemoryIDBBackingStore.h
r248699 r248751 42 42 WTF_MAKE_FAST_ALLOCATED; 43 43 public: 44 static std::unique_ptr<MemoryIDBBackingStore> create( const IDBDatabaseIdentifier&);44 static std::unique_ptr<MemoryIDBBackingStore> create(PAL::SessionID, const IDBDatabaseIdentifier&); 45 45 46 MemoryIDBBackingStore( const IDBDatabaseIdentifier&);46 MemoryIDBBackingStore(PAL::SessionID, const IDBDatabaseIdentifier&); 47 47 ~MemoryIDBBackingStore() final; 48 48 … … 92 92 93 93 IDBDatabaseIdentifier m_identifier; 94 PAL::SessionID m_sessionID; 94 95 std::unique_ptr<IDBDatabaseInfo> m_databaseInfo; 95 96 -
trunk/Source/WebCore/Modules/indexeddb/server/MemoryObjectStore.cpp
r244436 r248751 33 33 #include "IDBGetAllResult.h" 34 34 #include "IDBKeyRangeData.h" 35 #include "IDBSerializationContext.h" 35 36 #include "IDBValue.h" 36 37 #include "IndexKey.h" … … 46 47 namespace IDBServer { 47 48 48 Ref<MemoryObjectStore> MemoryObjectStore::create( const IDBObjectStoreInfo& info)49 { 50 return adoptRef(*new MemoryObjectStore( info));51 } 52 53 MemoryObjectStore::MemoryObjectStore( const IDBObjectStoreInfo& info)49 Ref<MemoryObjectStore> MemoryObjectStore::create(PAL::SessionID sessionID, const IDBObjectStoreInfo& info) 50 { 51 return adoptRef(*new MemoryObjectStore(sessionID, info)); 52 } 53 54 MemoryObjectStore::MemoryObjectStore(PAL::SessionID sessionID, const IDBObjectStoreInfo& info) 54 55 : m_info(info) 56 , m_serializationContext(IDBSerializationContext::getOrCreateIDBSerializationContext(sessionID)) 55 57 { 56 58 } … … 300 302 IDBError MemoryObjectStore::updateIndexesForPutRecord(const IDBKeyData& key, const ThreadSafeDataBuffer& value) 301 303 { 302 JSLockHolder locker( UniqueIDBDatabase::databaseThreadVM());303 304 auto jsValue = deserializeIDBValueToJSValue( UniqueIDBDatabase::databaseThreadExecState(), value);304 JSLockHolder locker(m_serializationContext->vm()); 305 306 auto jsValue = deserializeIDBValueToJSValue(m_serializationContext->execState(), value); 305 307 if (jsValue.isUndefinedOrNull()) 306 308 return IDBError { }; … … 311 313 for (auto& index : m_indexesByName.values()) { 312 314 IndexKey indexKey; 313 generateIndexKeyForValue( UniqueIDBDatabase::databaseThreadExecState(), index->info(), jsValue, indexKey, m_info.keyPath(), key);315 generateIndexKeyForValue(m_serializationContext->execState(), index->info(), jsValue, indexKey, m_info.keyPath(), key); 314 316 315 317 if (indexKey.isNull()) … … 337 339 return IDBError { }; 338 340 339 JSLockHolder locker( UniqueIDBDatabase::databaseThreadVM());341 JSLockHolder locker(m_serializationContext->vm()); 340 342 341 343 for (const auto& iterator : *m_keyValueStore) { 342 auto jsValue = deserializeIDBValueToJSValue( UniqueIDBDatabase::databaseThreadExecState(), iterator.value);344 auto jsValue = deserializeIDBValueToJSValue(m_serializationContext->execState(), iterator.value); 343 345 if (jsValue.isUndefinedOrNull()) 344 346 return IDBError { }; 345 347 346 348 IndexKey indexKey; 347 generateIndexKeyForValue( UniqueIDBDatabase::databaseThreadExecState(), index.info(), jsValue, indexKey, m_info.keyPath(), iterator.key);349 generateIndexKeyForValue(m_serializationContext->execState(), index.info(), jsValue, indexKey, m_info.keyPath(), iterator.key); 348 350 349 351 if (indexKey.isNull()) -
trunk/Source/WebCore/Modules/indexeddb/server/MemoryObjectStore.h
r239427 r248751 36 36 #include <wtf/RefCounted.h> 37 37 38 namespace PAL { 39 class SessionID; 40 } 41 38 42 namespace WebCore { 39 43 … … 53 57 namespace IDBServer { 54 58 59 class IDBSerializationContext; 55 60 class MemoryBackingStoreTransaction; 56 61 … … 59 64 class MemoryObjectStore : public RefCounted<MemoryObjectStore> { 60 65 public: 61 static Ref<MemoryObjectStore> create( const IDBObjectStoreInfo&);66 static Ref<MemoryObjectStore> create(PAL::SessionID, const IDBObjectStoreInfo&); 62 67 63 68 ~MemoryObjectStore(); … … 105 110 106 111 private: 107 MemoryObjectStore( const IDBObjectStoreInfo&);112 MemoryObjectStore(PAL::SessionID, const IDBObjectStoreInfo&); 108 113 109 114 IDBKeyDataSet::iterator lowestIteratorInRange(const IDBKeyRangeData&, bool reverse) const; … … 129 134 HashMap<String, RefPtr<MemoryIndex>> m_indexesByName; 130 135 HashMap<IDBResourceIdentifier, std::unique_ptr<MemoryObjectStoreCursor>> m_cursors; 136 137 Ref<IDBSerializationContext> m_serializationContext; 131 138 }; 132 139 -
trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBBackingStore.cpp
r248699 r248751 39 39 #include "IDBObjectStoreInfo.h" 40 40 #include "IDBSerialization.h" 41 #include "IDBSerializationContext.h" 41 42 #include "IDBTransactionInfo.h" 42 43 #include "IDBValue.h" … … 235 236 , m_temporaryFileHandler(fileHandler) 236 237 , m_quota(quota) 238 , m_serializationContext(IDBSerializationContext::getOrCreateIDBSerializationContext(sessionID)) 237 239 { 238 240 m_databaseDirectory = fullDatabaseDirectoryWithUpgrade(); … … 243 245 if (m_sqliteDB) 244 246 closeSQLiteDB(); 245 246 if (m_vm) {247 JSLockHolder locker(m_vm.get());248 m_globalObject.clear();249 m_vm = nullptr;250 }251 }252 253 254 void SQLiteIDBBackingStore::initializeVM()255 {256 if (!m_vm) {257 ASSERT(!m_globalObject);258 m_vm = VM::create();259 260 JSLockHolder locker(m_vm.get());261 m_globalObject.set(*m_vm, JSGlobalObject::create(*m_vm, JSGlobalObject::createStructure(*m_vm, jsNull())));262 }263 }264 265 VM& SQLiteIDBBackingStore::vm()266 {267 initializeVM();268 return *m_vm;269 }270 271 JSGlobalObject& SQLiteIDBBackingStore::globalObject()272 {273 initializeVM();274 return **m_globalObject;275 247 } 276 248 … … 1733 1705 IDBError SQLiteIDBBackingStore::updateOneIndexForAddRecord(const IDBIndexInfo& info, const IDBKeyData& key, const ThreadSafeDataBuffer& value, int64_t recordID) 1734 1706 { 1735 JSLockHolder locker( vm());1736 1737 auto jsValue = deserializeIDBValueToJSValue( *globalObject().globalExec(), value);1707 JSLockHolder locker(m_serializationContext->vm()); 1708 1709 auto jsValue = deserializeIDBValueToJSValue(m_serializationContext->execState(), value); 1738 1710 if (jsValue.isUndefinedOrNull()) 1739 1711 return IDBError { }; … … 1742 1714 auto* objectStoreInfo = infoForObjectStore(info.objectStoreIdentifier()); 1743 1715 ASSERT(objectStoreInfo); 1744 generateIndexKeyForValue( *m_globalObject->globalExec(), info, jsValue, indexKey, objectStoreInfo->keyPath(), key);1716 generateIndexKeyForValue(m_serializationContext->execState(), info, jsValue, indexKey, objectStoreInfo->keyPath(), key); 1745 1717 1746 1718 if (indexKey.isNull()) … … 1752 1724 IDBError SQLiteIDBBackingStore::updateAllIndexesForAddRecord(const IDBObjectStoreInfo& info, const IDBKeyData& key, const ThreadSafeDataBuffer& value, int64_t recordID) 1753 1725 { 1754 JSLockHolder locker( vm());1755 1756 auto jsValue = deserializeIDBValueToJSValue( *globalObject().globalExec(), value);1726 JSLockHolder locker(m_serializationContext->vm()); 1727 1728 auto jsValue = deserializeIDBValueToJSValue(m_serializationContext->execState(), value); 1757 1729 if (jsValue.isUndefinedOrNull()) 1758 1730 return IDBError { }; … … 1762 1734 for (auto& index : info.indexMap().values()) { 1763 1735 IndexKey indexKey; 1764 generateIndexKeyForValue( *m_globalObject->globalExec(), index, jsValue, indexKey, info.keyPath(), key);1736 generateIndexKeyForValue(m_serializationContext->execState(), index, jsValue, indexKey, info.keyPath(), key); 1765 1737 1766 1738 if (indexKey.isNull()) -
trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBBackingStore.h
r248699 r248751 44 44 namespace IDBServer { 45 45 46 class IDBSerializationContext; 46 47 class SQLiteIDBCursor; 47 48 … … 191 192 std::unique_ptr<SQLiteStatement> m_cachedStatements[static_cast<int>(SQL::Count)]; 192 193 193 JSC::VM& vm();194 JSC::JSGlobalObject& globalObject();195 void initializeVM();196 197 194 PAL::SessionID m_sessionID; 198 195 IDBDatabaseIdentifier m_identifier; … … 208 205 String m_databaseDirectory; 209 206 210 RefPtr<JSC::VM> m_vm;211 JSC::Strong<JSC::JSGlobalObject> m_globalObject;212 213 207 IDBBackingStoreTemporaryFileHandler& m_temporaryFileHandler; 214 208 215 209 uint64_t m_quota; 210 211 Ref<IDBSerializationContext> m_serializationContext; 216 212 }; 217 213 -
trunk/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.cpp
r248699 r248751 1198 1198 } 1199 1199 1200 VM& UniqueIDBDatabase::databaseThreadVM()1201 {1202 ASSERT(!isMainThread());1203 static VM* vm = &VM::create().leakRef();1204 return *vm;1205 }1206 1207 ExecState& UniqueIDBDatabase::databaseThreadExecState()1208 {1209 ASSERT(!isMainThread());1210 1211 static NeverDestroyed<Strong<JSGlobalObject>> globalObject(databaseThreadVM(), JSGlobalObject::create(databaseThreadVM(), JSGlobalObject::createStructure(databaseThreadVM(), jsNull())));1212 1213 RELEASE_ASSERT(globalObject.get()->globalExec());1214 return *globalObject.get()->globalExec();1215 }1216 1217 1200 void UniqueIDBDatabase::performPutOrAdd(uint64_t callbackIdentifier, const IDBResourceIdentifier& transactionIdentifier, uint64_t objectStoreIdentifier, const IDBKeyData& keyData, const IDBValue& originalRecordValue, IndexedDB::ObjectStoreOverwriteMode overwriteMode) 1218 1201 { -
trunk/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.h
r248699 r248751 43 43 #include <wtf/ListHashSet.h> 44 44 45 namespace JSC {46 class ExecState;47 class VM;48 }49 50 45 namespace WebCore { 51 46 … … 119 114 void handleDelete(IDBConnectionToClient&, const IDBRequestData&); 120 115 void immediateCloseForUserDelete(); 121 122 static JSC::VM& databaseThreadVM();123 static JSC::ExecState& databaseThreadExecState();124 116 125 117 bool hardClosedForUserDelete() const { return m_hardClosedForUserDelete; } -
trunk/Source/WebCore/Sources.txt
r248657 r248751 103 103 Modules/indexeddb/server/IDBConnectionToClient.cpp 104 104 Modules/indexeddb/server/IDBSerialization.cpp 105 Modules/indexeddb/server/IDBSerializationContext.cpp 105 106 Modules/indexeddb/server/IDBServer.cpp 106 107 Modules/indexeddb/server/IndexValueEntry.cpp -
trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj
r248713 r248751 2547 2547 931CBD11161A44E900E4C874 /* ScrollingStateTree.h in Headers */ = {isa = PBXBuildFile; fileRef = 931CBD0B161A44E900E4C874 /* ScrollingStateTree.h */; settings = {ATTRIBUTES = (Private, ); }; }; 2548 2548 931D72F615FE695300C4C07E /* LayoutMilestone.h in Headers */ = {isa = PBXBuildFile; fileRef = 931D72F515FE695300C4C07E /* LayoutMilestone.h */; settings = {ATTRIBUTES = (Private, ); }; }; 2549 9323B07023061F9700901C8B /* IDBSerializationContext.h in Headers */ = {isa = PBXBuildFile; fileRef = 9323B06F23061E9C00901C8B /* IDBSerializationContext.h */; }; 2549 2550 932CC0B71DFFD158004C0F9F /* MediaTrackConstraints.h in Headers */ = {isa = PBXBuildFile; fileRef = 932CC0B61DFFD158004C0F9F /* MediaTrackConstraints.h */; settings = {ATTRIBUTES = (Private, ); }; }; 2550 2551 932CC0D51DFFD667004C0F9F /* JSMediaTrackConstraints.h in Headers */ = {isa = PBXBuildFile; fileRef = 932CC0D11DFFD667004C0F9F /* JSMediaTrackConstraints.h */; }; … … 10407 10408 931CBD0B161A44E900E4C874 /* ScrollingStateTree.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScrollingStateTree.h; sourceTree = "<group>"; }; 10408 10409 931D72F515FE695300C4C07E /* LayoutMilestone.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LayoutMilestone.h; sourceTree = "<group>"; }; 10410 9323B06D23061E9B00901C8B /* IDBSerializationContext.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = IDBSerializationContext.cpp; sourceTree = "<group>"; }; 10411 9323B06F23061E9C00901C8B /* IDBSerializationContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IDBSerializationContext.h; sourceTree = "<group>"; }; 10409 10412 9327A94109968D1A0068A546 /* HTMLOptionsCollection.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = HTMLOptionsCollection.cpp; sourceTree = "<group>"; }; 10410 10413 932CC0B61DFFD158004C0F9F /* MediaTrackConstraints.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MediaTrackConstraints.h; sourceTree = "<group>"; }; … … 18556 18559 isa = PBXGroup; 18557 18560 children = ( 18561 9323B06D23061E9B00901C8B /* IDBSerializationContext.cpp */, 18562 9323B06F23061E9C00901C8B /* IDBSerializationContext.h */, 18558 18563 51BA4AC71BBC5AD600DF3D6D /* IDBBackingStore.h */, 18559 18564 516D7D6D1BB5F06500AF7C77 /* IDBConnectionToClient.cpp */, … … 30005 30010 1AE2AA980A1CDD2D00B42B25 /* JSHTMLImageElement.h in Headers */, 30006 30011 A80E7E970A1A83E3007FB8C5 /* JSHTMLInputElement.h in Headers */, 30012 9323B07023061F9700901C8B /* IDBSerializationContext.h in Headers */, 30007 30013 836B09561F5F34D9003C3702 /* JSHTMLInputElementEntriesAPI.h in Headers */, 30008 30014 A6148A7912E41E3B0044A784 /* JSHTMLKeygenElement.h in Headers */,
Note:
See TracChangeset
for help on using the changeset viewer.