8 @interface Deallocator : TestRoot @end
9 @implementation Deallocator
16 testprintf("Retain/release during dealloc\n");
18 testassertequal([o retainCount], 0);
20 testassertequal([o retainCount], 0);
22 testassertequal([o retainCount], 0);
29 size_t clz(uintptr_t isa) {
30 if (sizeof(uintptr_t) == 4)
31 return __builtin_clzl(isa);
32 testassert(sizeof(uintptr_t) == 8);
33 return __builtin_clzll(isa);
38 Deallocator *o = [Deallocator new];
43 uintptr_t isa = *(uintptr_t *)o;
45 // Assume refcount in high bits.
46 LOTS = 1 << (4 + clz(isa));
47 testprintf("LOTS %zu via cntlzw\n", LOTS);
50 testprintf("LOTS %zu via guess\n", LOTS);
56 testprintf("Retain a lot\n");
59 testassert([o retainCount] == rc);
62 if (rc % 0x100000 == 0) testprintf("%zx/%zx ++\n", rc, LOTS);
63 } while (++rc < LOTS);
65 testassert([o retainCount] == rc);
69 if (rc % 0x100000 == 0) testprintf("%zx/%zx --\n", rc, LOTS);
73 testassert([o retainCount] == rc);
76 testprintf("tryRetain a lot\n");
79 objc_storeWeak(&w, o);
83 testassert([o retainCount] == rc);
85 objc_loadWeakRetained(&w);
86 if (rc % 0x100000 == 0) testprintf("%zx/%zx ++\n", rc, LOTS);
87 } while (++rc < LOTS);
89 testassert([o retainCount] == rc);
93 if (rc % 0x100000 == 0) testprintf("%zx/%zx --\n", rc, LOTS);
97 testassert([o retainCount] == rc);
99 testprintf("dealloc\n");
101 testassert(TestRootDealloc == 0);
102 testassert(w != nil);
104 testassert(TestRootDealloc == 1);
105 testassert(w == nil);