2 // rdar://8052003 rdar://8077031
6 #include <malloc/malloc.h>
7 #include <objc/runtime.h>
9 // add SELCOUNT methods to each of CLASSCOUNT classes
10 #define CLASSCOUNT 100
16 malloc_statistics_t start, end;
19 root = objc_allocateClassPair(NULL, "Root", 0);
20 objc_registerClassPair(root);
22 Class classes[CLASSCOUNT];
23 for (i = 0; i < CLASSCOUNT; i++) {
25 asprintf(&classname, "GrP_class_%d", i);
26 classes[i] = objc_allocateClassPair(root, classname, 0);
27 objc_registerClassPair(classes[i]);
31 SEL selectors[SELCOUNT];
32 for (i = 0; i < SELCOUNT; i++) {
34 asprintf(&selname, "GrP_sel_%d", i);
35 selectors[i] = sel_registerName(selname);
39 malloc_zone_statistics(NULL, &start);
41 for (i = 0; i < CLASSCOUNT; i++) {
42 for (j = 0; j < SELCOUNT; j++) {
43 class_addMethod(classes[i], selectors[j], (IMP)main, "");
47 malloc_zone_statistics(NULL, &end);
49 // expected: 3-word method struct plus two other words
50 ssize_t expected = (sizeof(void*) * (3+2)) * SELCOUNT * CLASSCOUNT;
51 ssize_t actual = end.size_in_use - start.size_in_use;
52 testassert(actual < expected * 3); // allow generous fudge factor