Mercurial > repos > rhope
comparison runtime/fixed_alloc.c @ 110:336da6ce8174
Merge
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Wed, 06 Oct 2010 23:48:32 +0000 |
parents | 43cc42df26cc |
children | 72c648bca43b |
comparison
equal
deleted
inserted
replaced
109:b7df624895b2 | 110:336da6ce8174 |
---|---|
1 #include "fixed_alloc.h" | 1 #include "fixed_alloc.h" |
2 #include "object.h" | |
2 #include <stdlib.h> | 3 #include <stdlib.h> |
3 #include <string.h> | 4 #include <string.h> |
4 #include <stdio.h> | 5 #include <stdio.h> |
5 | 6 |
6 uint16_t max_free[(MAX_SIZE-MIN_SIZE)/STRIDE+1]; | 7 uint16_t max_free[(MAX_SIZE-MIN_SIZE)/STRIDE+1]; |
22 | 23 |
23 void print_mem_info(mem_manager * manager) | 24 void print_mem_info(mem_manager * manager) |
24 { | 25 { |
25 int i,count,freeobjs; | 26 int i,count,freeobjs; |
26 mem_block * cur; | 27 mem_block * cur; |
27 printf("Free blocks: %d\n", manager->freecount); | 28 //printf("Free blocks: %d\n", manager->freecount); |
28 printf("Full Blocks: %d\n", manager->fullcount); | 29 if (manager->fullcount) |
30 printf("Full Blocks: %d\n", manager->fullcount); | |
29 for (i = 0; i < (MAX_SIZE-MIN_SIZE)/STRIDE; i++) | 31 for (i = 0; i < (MAX_SIZE-MIN_SIZE)/STRIDE; i++) |
30 { | 32 { |
31 count = 0; | 33 count = 0; |
32 freeobjs = 0; | 34 freeobjs = 0; |
33 cur = manager->inuse[i]; | 35 cur = manager->inuse[i]; |
35 { | 37 { |
36 count++; | 38 count++; |
37 freeobjs += ((int)cur->numfree); | 39 freeobjs += ((int)cur->numfree); |
38 cur = cur->next; | 40 cur = cur->next; |
39 } | 41 } |
40 printf("Bucket %d(size: %d) has %d blocks in use with %d total free slots\n", i, i*STRIDE+MIN_SIZE,count, freeobjs); | 42 if (freeobjs) |
41 } | 43 printf("Bucket %d(size: %d) has %d blocks in use with %d free slots out of %d\n", i, i*STRIDE+MIN_SIZE,count, freeobjs, max_free[i]*count); |
44 } | |
45 fflush(stdout); | |
46 } | |
47 | |
48 void print_live_object_types(mem_manager * manager) | |
49 { | |
50 object * obj; | |
51 mem_block * cur; | |
52 int32_t i,j,bitslots,bit,*counts = malloc(sizeof(int32_t)*max_registered_type); | |
53 memset(counts, 0, sizeof(int32_t)*max_registered_type); | |
54 for (i = 0; i < (MAX_SIZE-MIN_SIZE)/STRIDE; i++) | |
55 { | |
56 cur = manager->inuse[i]; | |
57 while(cur) | |
58 { | |
59 bitslots = max_free[i]/8; | |
60 if(max_free[i]&7) | |
61 ++bitslots; | |
62 for(j = 0; j < bitslots; ++j) | |
63 if(cur->bitmap[j] != 0xFF) | |
64 { | |
65 for (bit = 0; bit < 8; ++bit) | |
66 { | |
67 if (!(cur->bitmap[j] & (1 << bit))) | |
68 { | |
69 obj = (object *)(((char *)cur)+BLOCK_SIZE-(((j*8+bit)+1)*(i*STRIDE+MIN_SIZE))); | |
70 counts[obj->bprint->type_id]++; | |
71 } | |
72 } | |
73 } | |
74 cur = cur->next; | |
75 } | |
76 } | |
77 for (i = 0; i < max_registered_type; ++i) | |
78 if(counts[i]) | |
79 printf("%d live objects of type %d\n", counts[i], i); | |
42 fflush(stdout); | 80 fflush(stdout); |
43 } | 81 } |
44 | 82 |
45 void * falloc(size_t size, mem_manager * manager) | 83 void * falloc(size_t size, mem_manager * manager) |
46 { | 84 { |