methodListSize.m 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // TEST_CONFIG
  2. // rdar://8052003 rdar://8077031
  3. #include "test.h"
  4. #include <malloc/malloc.h>
  5. #include <objc/runtime.h>
  6. // add SELCOUNT methods to each of CLASSCOUNT classes
  7. #define CLASSCOUNT 100
  8. #define SELCOUNT 200
  9. int main()
  10. {
  11. int i, j;
  12. malloc_statistics_t start, end;
  13. Class root;
  14. root = objc_allocateClassPair(NULL, "Root", 0);
  15. objc_registerClassPair(root);
  16. Class classes[CLASSCOUNT];
  17. for (i = 0; i < CLASSCOUNT; i++) {
  18. char *classname;
  19. asprintf(&classname, "GrP_class_%d", i);
  20. classes[i] = objc_allocateClassPair(root, classname, 0);
  21. objc_registerClassPair(classes[i]);
  22. free(classname);
  23. }
  24. SEL selectors[SELCOUNT];
  25. for (i = 0; i < SELCOUNT; i++) {
  26. char *selname;
  27. asprintf(&selname, "GrP_sel_%d", i);
  28. selectors[i] = sel_registerName(selname);
  29. free(selname);
  30. }
  31. malloc_zone_statistics(NULL, &start);
  32. for (i = 0; i < CLASSCOUNT; i++) {
  33. for (j = 0; j < SELCOUNT; j++) {
  34. class_addMethod(classes[i], selectors[j], (IMP)main, "");
  35. }
  36. }
  37. malloc_zone_statistics(NULL, &end);
  38. // expected: 3-word method struct plus two other words
  39. ssize_t expected = (sizeof(void*) * (3+2)) * SELCOUNT * CLASSCOUNT;
  40. ssize_t actual = end.size_in_use - start.size_in_use;
  41. testassert(actual < expected * 3); // allow generous fudge factor
  42. succeed(__FILE__);
  43. }