From 6a2c2cfaf4bb7aa509c3cb14c3e863b13ff5e02d Mon Sep 17 00:00:00 2001 From: Apple Date: Thu, 2 Feb 2012 16:16:01 +0000 Subject: [PATCH] objc4-493.11.tar.gz --- runtime/objc-arr.mm | 17 +++++++++++++++++ runtime/objc-os.h | 2 +- runtime/objc-private.h | 2 ++ runtime/objc-runtime-new.mm | 10 +++++++++- runtime/objc-runtime-old.m | 10 +++++++++- runtime/objc-weak.mm | 3 ++- 6 files changed, 40 insertions(+), 4 deletions(-) diff --git a/runtime/objc-arr.mm b/runtime/objc-arr.mm index 0bcd995..89a039e 100644 --- a/runtime/objc-arr.mm +++ b/runtime/objc-arr.mm @@ -130,6 +130,19 @@ public: new (&table_buf[i * SIDE_TABLE_SIZE]) SideTable; } } + + static bool noLocksHeld(void) { + bool gotAll = true; + for (int i = 0; i < SIDE_TABLE_STRIPE && gotAll; i++) { + SideTable *s = (SideTable *)(&table_buf[i * SIDE_TABLE_SIZE]); + if (OSSpinLockTry(&s->slock)) { + OSSpinLockUnlock(&s->slock); + } else { + gotAll = false; + } + } + return gotAll; + } }; STATIC_ASSERT(sizeof(SideTable) <= SIDE_TABLE_SIZE); @@ -142,6 +155,10 @@ SideTable::table_buf[SIDE_TABLE_STRIPE * SIDE_TABLE_SIZE]; // anonymous namespace }; +bool noSideTableLocksHeld(void) +{ + return SideTable::noLocksHeld(); +} // // The -fobjc-arr flag causes the compiler to issue calls to objc_{retain/release/autorelease/retain_block} diff --git a/runtime/objc-os.h b/runtime/objc-os.h index f6b2bf6..5866799 100644 --- a/runtime/objc-os.h +++ b/runtime/objc-os.h @@ -599,7 +599,7 @@ typedef pthread_mutex_t mutex_t; extern int DebuggerMode; extern void gdb_objc_debuggerModeFailure(void); extern BOOL isManagedDuringDebugger(void *lock); -extern BOOL isLockedDuringDebugger(mutex_t *lock); +extern BOOL isLockedDuringDebugger(void *lock); static inline int _mutex_lock_nodebug(mutex_t *m) { if (DebuggerMode && isManagedDuringDebugger(m)) { diff --git a/runtime/objc-private.h b/runtime/objc-private.h index 837d4e1..36f49ce 100644 --- a/runtime/objc-private.h +++ b/runtime/objc-private.h @@ -359,6 +359,8 @@ extern void _rwlock_assert_unlocked_debug(rwlock_t *l, const char *name); #endif +extern bool noSideTableLocksHeld(void); + #define rwlock_unlock(m, s) \ do { \ if ((s) == RDONLY) rwlock_unlock_read(m); \ diff --git a/runtime/objc-runtime-new.mm b/runtime/objc-runtime-new.mm index 296df91..abf133c 100644 --- a/runtime/objc-runtime-new.mm +++ b/runtime/objc-runtime-new.mm @@ -122,6 +122,14 @@ PRIVATE_EXTERN int startDebuggerMode(void) return DEBUGGER_OFF; } + // side table locks are not optional + if (!noSideTableLocksHeld()) { + rwlock_unlock(&runtimeLock, debugger_runtimeLock); + mutex_unlock(&cacheUpdateLock); + debugger_runtimeLock = 0; + return DEBUGGER_OFF; + } + // selLock is optional if (rwlock_try_write(&selLock)) { debugger_selLock = RDWR; @@ -188,7 +196,7 @@ PRIVATE_EXTERN BOOL isManagedDuringDebugger(void *lock) * Locking a managed mutex during debugger mode causes a trap unless * this returns YES. **********************************************************************/ -PRIVATE_EXTERN BOOL isLockedDuringDebugger(mutex_t *lock) +PRIVATE_EXTERN BOOL isLockedDuringDebugger(void *lock) { assert(DebuggerMode); diff --git a/runtime/objc-runtime-old.m b/runtime/objc-runtime-old.m index f0ac76d..9d53fdc 100644 --- a/runtime/objc-runtime-old.m +++ b/runtime/objc-runtime-old.m @@ -3340,6 +3340,14 @@ PRIVATE_EXTERN int startDebuggerMode(void) return DEBUGGER_OFF; } + // side table locks are not optional because we're being conservative + if (!noSideTableLocksHeld()) { + mutex_unlock(&cacheUpdateLock); + mutex_unlock(&methodListLock); + mutex_unlock(&classLock); + return DEBUGGER_OFF; + } + // selLock is optional if (rwlock_try_write(&selLock)) { debugger_selLock = RDWR; @@ -3400,7 +3408,7 @@ PRIVATE_EXTERN BOOL isManagedDuringDebugger(void *lock) * Locking a managed mutex during debugger mode causes a trap unless * this returns YES. **********************************************************************/ -PRIVATE_EXTERN BOOL isLockedDuringDebugger(mutex_t *lock) +PRIVATE_EXTERN BOOL isLockedDuringDebugger(void *lock) { assert(DebuggerMode); diff --git a/runtime/objc-weak.mm b/runtime/objc-weak.mm index 7744330..f8a34b4 100644 --- a/runtime/objc-weak.mm +++ b/runtime/objc-weak.mm @@ -463,7 +463,7 @@ arr_clear_deallocating(weak_table_t *weak_table, id referent) { PRIVATE_EXTERN id weak_register_no_lock(weak_table_t *weak_table, id referent, id *referrer) { - if (referent) { + if (referent && !OBJC_IS_TAGGED_PTR(referent)) { // ensure that the referenced object is viable BOOL (*allowsWeakReference)(id, SEL) = (BOOL(*)(id, SEL)) class_getMethodImplementation(object_getClass(referent), @@ -509,6 +509,7 @@ arr_read_weak_reference(weak_table_t *weak_table, id *referrer) { // find entry and mark that it needs retaining { referent = *referrer; + if (OBJC_IS_TAGGED_PTR(referent)) return referent; weak_entry_t *entry; if (referent == NULL || !(entry = weak_entry_for_referent(weak_table, referent))) { *referrer = NULL; -- 2.47.2