Mercurial > hg > xemacs-beta
comparison src/mc-alloc.c @ 5216:9b8c2168d231
Allocate lrecord arrays in own size class.
author | Marcus Crestani <crestani@informatik.uni-tuebingen.de> |
---|---|
date | Sat, 29 May 2010 07:10:49 +0200 |
parents | e374ea766cc1 |
children | 2cc24c69446c |
comparison
equal
deleted
inserted
replaced
5215:956d54c39176 | 5216:9b8c2168d231 |
---|---|
295 | 295 |
296 /* Holds all allocated pages, each object size class in its separate list, | 296 /* Holds all allocated pages, each object size class in its separate list, |
297 to guarantee fast allocation on partially filled pages. */ | 297 to guarantee fast allocation on partially filled pages. */ |
298 page_list_header *used_heap_pages; | 298 page_list_header *used_heap_pages; |
299 | 299 |
300 /* Holds all allocated pages that contain array elements. */ | |
301 page_list_header array_heap_pages; | |
302 | |
300 /* Holds all free pages in the heap. N multiples of PAGE_SIZE are | 303 /* Holds all free pages in the heap. N multiples of PAGE_SIZE are |
301 kept on the Nth free list. Contiguos pages are coalesced. */ | 304 kept on the Nth free list. Contiguos pages are coalesced. */ |
302 page_list_header free_heap_pages[N_FREE_PAGE_LISTS]; | 305 page_list_header free_heap_pages[N_FREE_PAGE_LISTS]; |
303 | 306 |
304 /* ptr lookup table */ | 307 /* ptr lookup table */ |
321 | 324 |
322 /*--- macro accessors --------------------------------------------------*/ | 325 /*--- macro accessors --------------------------------------------------*/ |
323 | 326 |
324 #define USED_HEAP_PAGES(i) \ | 327 #define USED_HEAP_PAGES(i) \ |
325 ((page_list_header*) &mc_allocator_globals.used_heap_pages[i]) | 328 ((page_list_header*) &mc_allocator_globals.used_heap_pages[i]) |
329 | |
330 #define ARRAY_HEAP_PAGES \ | |
331 ((page_list_header*) &mc_allocator_globals.array_heap_pages) | |
326 | 332 |
327 #define FREE_HEAP_PAGES(i) \ | 333 #define FREE_HEAP_PAGES(i) \ |
328 ((page_list_header*) &mc_allocator_globals.free_heap_pages[i]) | 334 ((page_list_header*) &mc_allocator_globals.free_heap_pages[i]) |
329 | 335 |
330 #define PLH(plh) plh | 336 #define PLH(plh) plh |
435 number_of_pages_processed += f (ph); | 441 number_of_pages_processed += f (ph); |
436 ph = next; | 442 ph = next; |
437 } | 443 } |
438 number_of_pages_processed += f (ph); | 444 number_of_pages_processed += f (ph); |
439 } | 445 } |
446 | |
447 if (PLH_FIRST (ARRAY_HEAP_PAGES)) | |
448 { | |
449 page_header *ph = PLH_FIRST (ARRAY_HEAP_PAGES); | |
450 while (PH_NEXT (ph)) | |
451 { | |
452 page_header *next = PH_NEXT (ph); /* in case f removes the page */ | |
453 number_of_pages_processed += f (ph); | |
454 ph = next; | |
455 } | |
456 number_of_pages_processed += f (ph); | |
457 } | |
458 | |
440 return number_of_pages_processed; | 459 return number_of_pages_processed; |
441 } | 460 } |
442 | 461 |
443 | 462 |
444 | 463 |
1170 | 1189 |
1171 | 1190 |
1172 /*--- used heap functions ----------------------------------------------*/ | 1191 /*--- used heap functions ----------------------------------------------*/ |
1173 /* Installs initial free list. */ | 1192 /* Installs initial free list. */ |
1174 static void | 1193 static void |
1175 install_cell_free_list (page_header *ph, EMACS_INT elemcount) | 1194 install_cell_free_list (page_header *ph) |
1176 { | 1195 { |
1177 Rawbyte *p; | 1196 Rawbyte *p; |
1178 EMACS_INT i; | 1197 EMACS_INT i; |
1179 EMACS_INT cell_size = PH_CELL_SIZE (ph); | 1198 EMACS_INT cell_size = PH_CELL_SIZE (ph); |
1180 /* write initial free list if cell_size is < PAGE_SIZE */ | 1199 /* write initial free list if cell_size is < PAGE_SIZE */ |
1183 { | 1202 { |
1184 #ifdef ERROR_CHECK_GC | 1203 #ifdef ERROR_CHECK_GC |
1185 assert (!LRECORD_FREE_P (p)); | 1204 assert (!LRECORD_FREE_P (p)); |
1186 MARK_LRECORD_AS_FREE (p); | 1205 MARK_LRECORD_AS_FREE (p); |
1187 #endif | 1206 #endif |
1188 if (elemcount == 1) | 1207 if (!PH_ARRAY_BIT (ph)) |
1189 NEXT_FREE (p) = FREE_LIST (p + cell_size); | 1208 NEXT_FREE (p) = FREE_LIST (p + cell_size); |
1190 set_lookup_table (p, ph); | 1209 set_lookup_table (p, ph); |
1191 p += cell_size; | 1210 p += cell_size; |
1192 } | 1211 } |
1193 #ifdef ERROR_CHECK_GC | 1212 #ifdef ERROR_CHECK_GC |
1225 if (PLH_SIZE (plh)) | 1244 if (PLH_SIZE (plh)) |
1226 PH_CELL_SIZE (ph) = PLH_SIZE (plh); | 1245 PH_CELL_SIZE (ph) = PLH_SIZE (plh); |
1227 else | 1246 else |
1228 PH_CELL_SIZE (ph) = size; | 1247 PH_CELL_SIZE (ph) = size; |
1229 if (elemcount == 1) | 1248 if (elemcount == 1) |
1230 PH_CELLS_ON_PAGE (ph) = (PAGE_SIZE * PH_N_PAGES (ph)) / PH_CELL_SIZE (ph); | 1249 { |
1250 PH_CELLS_ON_PAGE (ph) = (PAGE_SIZE * PH_N_PAGES (ph)) / PH_CELL_SIZE (ph); | |
1251 PH_ARRAY_BIT (ph) = 0; | |
1252 } | |
1231 else | 1253 else |
1232 { | 1254 { |
1233 PH_CELLS_ON_PAGE (ph) = elemcount; | 1255 PH_CELLS_ON_PAGE (ph) = elemcount; |
1234 PH_ARRAY_BIT (ph) = 1; | 1256 PH_ARRAY_BIT (ph) = 1; |
1235 } | 1257 } |
1238 PH_CELLS_USED (ph) = 0; | 1260 PH_CELLS_USED (ph) = 0; |
1239 | 1261 |
1240 /* install mark bits and initialize cell free list */ | 1262 /* install mark bits and initialize cell free list */ |
1241 install_mark_bits (ph); | 1263 install_mark_bits (ph); |
1242 | 1264 |
1243 install_cell_free_list (ph, elemcount); | 1265 install_cell_free_list (ph); |
1244 | 1266 |
1245 #ifdef MEMORY_USAGE_STATS | 1267 #ifdef MEMORY_USAGE_STATS |
1246 PLH_TOTAL_CELLS (plh) += PH_CELLS_ON_PAGE (ph); | 1268 PLH_TOTAL_CELLS (plh) += PH_CELLS_ON_PAGE (ph); |
1247 PLH_TOTAL_SPACE (plh) += PAGE_SIZE * PH_N_PAGES (ph); | 1269 PLH_TOTAL_SPACE (plh) += PAGE_SIZE * PH_N_PAGES (ph); |
1248 #endif | 1270 #endif |
1377 { | 1399 { |
1378 page_list_header *plh = 0; | 1400 page_list_header *plh = 0; |
1379 page_header *ph = 0; | 1401 page_header *ph = 0; |
1380 void *result = 0; | 1402 void *result = 0; |
1381 | 1403 |
1382 plh = USED_HEAP_PAGES (get_used_list_index (size)); | |
1383 | |
1384 if (size == 0) | 1404 if (size == 0) |
1385 return 0; | 1405 return 0; |
1386 if ((elemcount == 1) && (size < (size_t) PAGE_SIZE_DIV_2)) | 1406 |
1387 /* first check any free cells */ | 1407 if (elemcount == 1) |
1388 ph = allocate_cell (plh); | 1408 { |
1409 plh = USED_HEAP_PAGES (get_used_list_index (size)); | |
1410 if (size < (size_t) USED_LIST_UPPER_THRESHOLD) | |
1411 /* first check any free cells */ | |
1412 ph = allocate_cell (plh); | |
1413 } | |
1414 else | |
1415 { | |
1416 plh = ARRAY_HEAP_PAGES; | |
1417 } | |
1418 | |
1389 if (!ph) | 1419 if (!ph) |
1390 /* allocate a new page */ | 1420 /* allocate a new page */ |
1391 ph = allocate_new_page (plh, size, elemcount); | 1421 ph = allocate_new_page (plh, size, elemcount); |
1392 | 1422 |
1393 /* return first element of free list and remove it from the list */ | 1423 /* return first element of free list and remove it from the list */ |
1668 PLH_TOTAL_CELLS (plh) = 0; | 1698 PLH_TOTAL_CELLS (plh) = 0; |
1669 PLH_TOTAL_SPACE (plh) = 0; | 1699 PLH_TOTAL_SPACE (plh) = 0; |
1670 #endif | 1700 #endif |
1671 } | 1701 } |
1672 | 1702 |
1703 { | |
1704 page_list_header *plh = ARRAY_HEAP_PAGES; | |
1705 PLH_LIST_TYPE (plh) = USED_LIST; | |
1706 PLH_SIZE (plh) = 0; | |
1707 PLH_FIRST (plh) = 0; | |
1708 PLH_LAST (plh) = 0; | |
1709 PLH_MARK_BIT_FREE_LIST (plh) = 0; | |
1710 #ifdef MEMORY_USAGE_STATS | |
1711 PLH_PAGE_COUNT (plh) = 0; | |
1712 PLH_USED_CELLS (plh) = 0; | |
1713 PLH_USED_SPACE (plh) = 0; | |
1714 PLH_TOTAL_CELLS (plh) = 0; | |
1715 PLH_TOTAL_SPACE (plh) = 0; | |
1716 #endif | |
1717 } | |
1718 | |
1673 for (i = 0; i < N_FREE_PAGE_LISTS; i++) | 1719 for (i = 0; i < N_FREE_PAGE_LISTS; i++) |
1674 { | 1720 { |
1675 page_list_header *plh = FREE_HEAP_PAGES (i); | 1721 page_list_header *plh = FREE_HEAP_PAGES (i); |
1676 PLH_LIST_TYPE (plh) = FREE_LIST; | 1722 PLH_LIST_TYPE (plh) = FREE_LIST; |
1677 PLH_SIZE (plh) = get_free_list_size_value (i); | 1723 PLH_SIZE (plh) = get_free_list_size_value (i); |
1733 make_int (PLH_USED_SPACE (USED_HEAP_PAGES(i))), | 1779 make_int (PLH_USED_SPACE (USED_HEAP_PAGES(i))), |
1734 make_int (PLH_TOTAL_CELLS (USED_HEAP_PAGES(i))), | 1780 make_int (PLH_TOTAL_CELLS (USED_HEAP_PAGES(i))), |
1735 make_int (PLH_TOTAL_SPACE (USED_HEAP_PAGES(i)))), | 1781 make_int (PLH_TOTAL_SPACE (USED_HEAP_PAGES(i)))), |
1736 used_plhs); | 1782 used_plhs); |
1737 | 1783 |
1784 used_plhs = | |
1785 acons (make_int (0), | |
1786 list5 (make_int (PLH_PAGE_COUNT(ARRAY_HEAP_PAGES)), | |
1787 make_int (PLH_USED_CELLS (ARRAY_HEAP_PAGES)), | |
1788 make_int (PLH_USED_SPACE (ARRAY_HEAP_PAGES)), | |
1789 make_int (PLH_TOTAL_CELLS (ARRAY_HEAP_PAGES)), | |
1790 make_int (PLH_TOTAL_SPACE (ARRAY_HEAP_PAGES))), | |
1791 used_plhs); | |
1792 | |
1738 for (i = 0; i < N_HEAP_SECTIONS; i++) { | 1793 for (i = 0; i < N_HEAP_SECTIONS; i++) { |
1739 used_size += HEAP_SECTION(i).n_pages * PAGE_SIZE; | 1794 used_size += HEAP_SECTION(i).n_pages * PAGE_SIZE; |
1740 real_size += | 1795 real_size += |
1741 malloced_storage_size (0, HEAP_SECTION(i).real_size, 0); | 1796 malloced_storage_size (0, HEAP_SECTION(i).real_size, 0); |
1742 } | 1797 } |