Changeset 246578 in webkit
- Timestamp:
- Jun 18, 2019, 6:19:41 PM (7 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 9 edited
-
Source/JavaScriptCore/API/JSVirtualMachine.mm (modified) (1 diff)
-
Source/JavaScriptCore/API/JSVirtualMachineInternal.h (modified) (1 diff)
-
Source/JavaScriptCore/ChangeLog (modified) (1 diff)
-
Source/JavaScriptCore/runtime/JSLock.cpp (modified) (3 diffs)
-
Source/JavaScriptCore/runtime/JSLock.h (modified) (3 diffs)
-
Source/WebCore/ChangeLog (modified) (1 diff)
-
Source/WebCore/bindings/js/CommonVM.cpp (modified) (1 diff)
-
Tools/ChangeLog (modified) (1 diff)
-
Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (modified) (4 diffs)
-
Tools/TestWebKitAPI/Tests/WebKitLegacy/ios/JSLockTakesWebThreadLock.mm (added)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/API/JSVirtualMachine.mm
r243617 r246578 249 249 } 250 250 251 - (BOOL)isWebThreadAware 252 { 253 return [self vm].apiLock().isWebThreadAware(); 254 } 255 251 256 + (void)setCrashOnVMCreation:(BOOL)shouldCrash 252 257 { -
trunk/Source/JavaScriptCore/API/JSVirtualMachineInternal.h
r243617 r246578 47 47 - (JSC::VM&)vm; 48 48 49 - (BOOL)isWebThreadAware; 50 49 51 @end 50 52 -
trunk/Source/JavaScriptCore/ChangeLog
r246577 r246578 1 2019-06-18 Yusuke Suzuki <ysuzuki@apple.com> 2 3 [JSC] JSLock should be WebThread aware 4 https://bugs.webkit.org/show_bug.cgi?id=198911 5 6 Reviewed by Geoffrey Garen. 7 8 Since WebKitLegacy content rendering is done in WebThread instead of the main thread in iOS, user of WebKitLegacy (e.g. UIWebView) needs 9 to grab the WebThread lock (which is a recursive lock) in the main thread when touching the WebKitLegacy content. 10 But, WebKitLegacy can expose JSContext for the web view. And we can interact with the JS content through JavaScriptCore APIs. However, 11 since WebThread is a concept in WebCore, JavaScriptCore APIs do not grab the WebThread lock. As a result, WebKitLegacy web content can be 12 modified from the main thread without grabbing the WebThread lock through JavaScriptCore APIs. 13 14 This patch makes JSC aware of WebThread: JSLock grabs the WebThread lock before grabbing JS's lock. While this seems layering violation, 15 we already have many USE(WEB_THREAD) and WebThread aware code in WTF. Eventually, we should move WebThread code from WebCore to WTF since 16 JSC and WTF need to be aware of WebThread. But, for now, we just use the function pointer exposed by WebCore. 17 18 Since both JSLock and the WebThread lock are recursive locks, nested locking is totally OK. The possible problem is the order of locking. 19 We ensure that we always grab locks in (1) the WebThread lock and (2) JSLock order. 20 21 In JSLock, we take the WebThread lock, but we do not unlock it. This is how we use the WebThread lock: the WebThread lock is released 22 automatically when RunLoop finishes the current cycle, and in WebKitLegacy, we do not call unlocking function of the WebThread lock except 23 for some edge cases. 24 25 * API/JSVirtualMachine.mm: 26 (-[JSVirtualMachine isWebThreadAware]): 27 * API/JSVirtualMachineInternal.h: 28 * runtime/JSLock.cpp: 29 (JSC::JSLockHolder::JSLockHolder): 30 (JSC::JSLock::lock): 31 (JSC::JSLockHolder::init): Deleted. 32 * runtime/JSLock.h: 33 (JSC::JSLock::makeWebThreadAware): 34 (JSC::JSLock::isWebThreadAware const): 35 1 36 2019-06-18 Justin Michaud <justin_michaud@apple.com> 2 37 -
trunk/Source/JavaScriptCore/runtime/JSLock.cpp
r246490 r246578 36 36 #include <wtf/threads/Signals.h> 37 37 38 #if USE(WEB_THREAD) 39 #include <wtf/ios/WebCoreThread.h> 40 #endif 41 38 42 namespace JSC { 39 43 … … 51 55 52 56 JSLockHolder::JSLockHolder(ExecState* exec) 53 : m_vm(&exec->vm()) 54 { 55 init(); 57 : JSLockHolder(exec->vm()) 58 { 56 59 } 57 60 58 61 JSLockHolder::JSLockHolder(VM* vm) 59 : m_vm(vm) 60 { 61 init(); 62 : JSLockHolder(*vm) 63 { 62 64 } 63 65 64 66 JSLockHolder::JSLockHolder(VM& vm) 65 67 : m_vm(&vm) 66 {67 init();68 }69 70 void JSLockHolder::init()71 68 { 72 69 m_vm->apiLock().lock(); … … 106 103 { 107 104 ASSERT(lockCount > 0); 105 #if USE(WEB_THREAD) 106 if (m_isWebThreadAware) { 107 ASSERT(WebCoreWebThreadIsEnabled && WebCoreWebThreadIsEnabled()); 108 WebCoreWebThreadLock(); 109 } 110 #endif 111 108 112 bool success = m_lock.tryLock(); 109 113 if (UNLIKELY(!success)) { -
trunk/Source/JavaScriptCore/runtime/JSLock.h
r246490 r246578 71 71 72 72 JS_EXPORT_PRIVATE ~JSLockHolder(); 73 73 74 private: 74 void init();75 76 75 RefPtr<VM> m_vm; 77 76 }; … … 120 119 }; 121 120 121 void makeWebThreadAware() 122 { 123 m_isWebThreadAware = true; 124 } 125 126 bool isWebThreadAware() const { return m_isWebThreadAware; } 127 122 128 private: 123 129 void lock(intptr_t lockCount); … … 131 137 132 138 Lock m_lock; 139 bool m_isWebThreadAware { false }; 133 140 // We cannot make m_ownerThread an optional (instead of pairing it with an explicit 134 141 // m_hasOwnerThread) because currentThreadIsHoldingLock() may be called from a -
trunk/Source/WebCore/ChangeLog
r246573 r246578 1 2019-06-18 Yusuke Suzuki <ysuzuki@apple.com> 2 3 [JSC] JSLock should be WebThread aware 4 https://bugs.webkit.org/show_bug.cgi?id=198911 5 6 Reviewed by Geoffrey Garen. 7 8 * bindings/js/CommonVM.cpp: 9 (WebCore::commonVMSlow): 10 1 11 2019-06-18 Joseph Pecoraro <pecoraro@apple.com> 2 12 -
trunk/Source/WebCore/bindings/js/CommonVM.cpp
r246490 r246578 60 60 61 61 #if PLATFORM(IOS_FAMILY) 62 if (WebThreadIsEnabled()) 63 vm.apiLock().makeWebThreadAware(); 62 64 vm.setRunLoop(WebThreadRunLoop()); 63 65 vm.heap.machineThreads().addCurrentThread(); -
trunk/Tools/ChangeLog
r246566 r246578 1 2019-06-18 Yusuke Suzuki <ysuzuki@apple.com> 2 3 [JSC] JSLock should be WebThread aware 4 https://bugs.webkit.org/show_bug.cgi?id=198911 5 6 Reviewed by Geoffrey Garen. 7 8 * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: 9 * TestWebKitAPI/Tests/WebKitLegacy/ios/JSLockTakesWebThreadLock.mm: Added. 10 (TestWebKitAPI::TEST): 11 1 12 2019-06-18 Keith Miller <keith_miller@apple.com> 2 13 -
trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
r246514 r246578 876 876 E324A6F02041C82000A76593 /* UniqueArray.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E398BC0F2041C76300387136 /* UniqueArray.cpp */; }; 877 877 E32B549222810AC4008AD702 /* Packed.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E32B549122810AC0008AD702 /* Packed.cpp */; }; 878 E35FC7B222B82A7300F32F98 /* JSLockTakesWebThreadLock.mm in Sources */ = {isa = PBXBuildFile; fileRef = E35FC7B122B82A6D00F32F98 /* JSLockTakesWebThreadLock.mm */; }; 878 879 E373D7911F2CF35200C6FAAF /* Signals.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E3953F951F2CF32100A76A2E /* Signals.cpp */; }; 879 880 E38A0D351FD50CC300E98C8B /* Threading.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E38A0D341FD50CBC00E98C8B /* Threading.cpp */; }; … … 2273 2274 E19DB9781B32137C00DB38D4 /* NavigatorLanguage.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = NavigatorLanguage.mm; sourceTree = "<group>"; }; 2274 2275 E32B549122810AC0008AD702 /* Packed.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = Packed.cpp; sourceTree = "<group>"; }; 2276 E35FC7B122B82A6D00F32F98 /* JSLockTakesWebThreadLock.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = JSLockTakesWebThreadLock.mm; sourceTree = "<group>"; }; 2275 2277 E388887020C9098100E632BC /* WorkerPool.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WorkerPool.cpp; sourceTree = "<group>"; }; 2276 2278 E38A0D341FD50CBC00E98C8B /* Threading.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Threading.cpp; sourceTree = "<group>"; }; … … 3808 3810 CDC8E49A1BC728FE00594FEC /* Resources */, 3809 3811 CDC8E4851BC5B19400594FEC /* AudioSessionCategoryIOS.mm */, 3812 E35FC7B122B82A6D00F32F98 /* JSLockTakesWebThreadLock.mm */, 3810 3813 CDC0932A21C872C10030C4B0 /* ScrollingDoesNotPauseMedia.mm */, 3811 3814 0F4FFA9D1ED3AA8500F7111F /* SnapshotViaRenderInContext.mm */, … … 4304 4307 7CCE7EA51A411A0800447C4C /* JavaScriptTestMac.mm in Sources */, 4305 4308 5C0160C121A132460077FA32 /* JITEnabled.mm in Sources */, 4309 E35FC7B222B82A7300F32F98 /* JSLockTakesWebThreadLock.mm in Sources */, 4306 4310 7CCE7EC41A411A7E00447C4C /* JSWrapperForNodeInWebFrame.mm in Sources */, 4307 4311 F45E15732112CE2900307E82 /* KeyboardInputTestsIOS.mm in Sources */,
Note:
See TracChangeset
for help on using the changeset viewer.