Changeset 210458 in webkit
- Timestamp:
- Jan 6, 2017 3:38:31 PM (7 years ago)
- Location:
- trunk/Source/JavaScriptCore
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/API/JSVirtualMachine.mm
r208720 r210458 1 1 /* 2 * Copyright (C) 2013-201 6Apple Inc. All rights reserved.2 * Copyright (C) 2013-2017 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 82 82 @implementation JSVirtualMachine { 83 83 JSContextGroupRef m_group; 84 Lock m_externalDataMutex; 84 85 NSMapTable *m_contextCache; 85 86 NSMapTable *m_externalObjectGraph; … … 157 158 - (void)addExternalRememberedObject:(id)object 158 159 { 160 auto locker = holdLock(m_externalDataMutex); 159 161 ASSERT([self isOldExternalObject:object]); 160 162 [m_externalRememberedSet setObject:@YES forKey:object]; … … 176 178 [self addExternalRememberedObject:owner]; 177 179 180 auto externalDataMutexLocker = holdLock(m_externalDataMutex); 178 181 NSMapTable *ownedObjects = [m_externalObjectGraph objectForKey:owner]; 179 182 if (!ownedObjects) { … … 203 206 JSC::JSLockHolder locker(toJS(m_group)); 204 207 208 auto externalDataMutexLocker = holdLock(m_externalDataMutex); 205 209 NSMapTable *ownedObjects = [m_externalObjectGraph objectForKey:owner]; 206 210 if (!ownedObjects) … … 249 253 } 250 254 255 - (Lock&)externalDataMutex 256 { 257 return m_externalDataMutex; 258 } 259 251 260 - (NSMapTable *)externalObjectGraph 252 261 { … … 261 270 @end 262 271 263 void scanExternalObjectGraph(JSC::VM& vm, JSC::SlotVisitor& visitor, void* root)272 static void scanExternalObjectGraph(JSC::VM& vm, JSC::SlotVisitor& visitor, void* root, bool lockAcquired) 264 273 { 265 274 @autoreleasepool { … … 268 277 return; 269 278 NSMapTable *externalObjectGraph = [virtualMachine externalObjectGraph]; 279 Lock& externalDataMutex = [virtualMachine externalDataMutex]; 270 280 Vector<void*> stack; 271 281 stack.append(root); … … 276 286 continue; 277 287 visitor.addOpaqueRoot(nextRoot); 278 279 NSMapTable *ownedObjects = [externalObjectGraph objectForKey:static_cast<id>(nextRoot)]; 280 for (id ownedObject in ownedObjects) 281 stack.append(static_cast<void*>(ownedObject)); 288 289 auto appendOwnedObjects = [&] { 290 NSMapTable *ownedObjects = [externalObjectGraph objectForKey:static_cast<id>(nextRoot)]; 291 for (id ownedObject in ownedObjects) 292 stack.append(static_cast<void*>(ownedObject)); 293 }; 294 295 if (lockAcquired) 296 appendOwnedObjects(); 297 else { 298 auto locker = holdLock(externalDataMutex); 299 appendOwnedObjects(); 300 } 282 301 } 283 302 } 303 } 304 305 void scanExternalObjectGraph(JSC::VM& vm, JSC::SlotVisitor& visitor, void* root) 306 { 307 bool lockAcquired = false; 308 scanExternalObjectGraph(vm, visitor, root, lockAcquired); 284 309 } 285 310 … … 290 315 if (!virtualMachine) 291 316 return; 317 Lock& externalDataMutex = [virtualMachine externalDataMutex]; 318 auto locker = holdLock(externalDataMutex); 292 319 NSMapTable *externalObjectGraph = [virtualMachine externalObjectGraph]; 293 320 NSMapTable *externalRememberedSet = [virtualMachine externalRememberedSet]; 294 321 for (id key in externalRememberedSet) { 295 322 NSMapTable *ownedObjects = [externalObjectGraph objectForKey:key]; 323 bool lockAcquired = true; 296 324 for (id ownedObject in ownedObjects) 297 scanExternalObjectGraph(vm, visitor, ownedObject );325 scanExternalObjectGraph(vm, visitor, ownedObject, lockAcquired); 298 326 } 299 327 [externalRememberedSet removeAllObjects]; -
trunk/Source/JavaScriptCore/API/JSVirtualMachineInternal.h
r174110 r210458 1 1 /* 2 * Copyright (C) 2013 Apple Inc. All rights reserved.2 * Copyright (C) 2013, 2017 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 48 48 - (void)addContext:(JSContext *)wrapper forGlobalContextRef:(JSGlobalContextRef)globalContext; 49 49 50 - (NSMapTable *)externalObjectGraph;51 52 50 @end 53 51 #endif // defined(__OBJC__) -
trunk/Source/JavaScriptCore/ChangeLog
r210457 r210458 1 2017-01-06 Mark Lam <mark.lam@apple.com> 2 3 The ObjC API's JSVirtualMachine's map tables need to be guarded by a lock. 4 https://bugs.webkit.org/show_bug.cgi?id=166778 5 <rdar://problem/29761198> 6 7 Reviewed by Filip Pizlo. 8 9 Now that we have a concurrent GC, access to JSVirtualMachine's 10 m_externalObjectGraph and m_externalRememberedSet need to be guarded by a lock 11 since both the GC marker thread and the mutator thread may access them at the 12 same time. 13 14 * API/JSVirtualMachine.mm: 15 (-[JSVirtualMachine addExternalRememberedObject:]): 16 (-[JSVirtualMachine addManagedReference:withOwner:]): 17 (-[JSVirtualMachine removeManagedReference:withOwner:]): 18 (-[JSVirtualMachine externalDataMutex]): 19 (scanExternalObjectGraph): 20 (scanExternalRememberedSet): 21 22 * API/JSVirtualMachineInternal.h: 23 - Deleted externalObjectGraph method. There's no need to expose this. 24 1 25 2017-01-06 Michael Saboff <msaboff@apple.com> 2 26
Note: See TracChangeset
for help on using the changeset viewer.