Changeset f103fb in git
- Timestamp:
- Oct 4, 2000, 3:12:32 PM (24 years ago)
- Branches:
- (u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
- Children:
- 400633927935ad03438bf37f1f7967d1b891903d
- Parents:
- ff4e34fa88e2957ee964d2e38c9e058cf143c963
- Location:
- omalloc
- Files:
-
- 17 edited
Legend:
- Unmodified
- Added
- Removed
-
omalloc/omAlloc.c
rff4e34f rf103fb 4 4 * Author: obachman@mathematik.uni-kl.de (Olaf Bachmann) 5 5 * Created: 11/99 6 * Version: $Id: omAlloc.c,v 1. 8 2000-08-14 12:26:38 obachman Exp $6 * Version: $Id: omAlloc.c,v 1.9 2000-10-04 13:12:28 obachman Exp $ 7 7 *******************************************************************/ 8 8 #ifndef OM_ALLOC_C … … 134 134 } 135 135 136 if ( bin->current_page->next != NULL)136 if (!bin->sticky && bin->current_page->next != NULL) 137 137 { 138 138 omAssume(bin->current_page->next->current != NULL); … … 145 145 omInsertBinPage(bin->current_page, newpage, bin); 146 146 } 147 147 148 bin->current_page = newpage; 148 149 149 omAssume(newpage != NULL && newpage != om_ZeroPage && 150 150 newpage->current != NULL); … … 207 207 #else 208 208 # if defined(PAGE_AFTER_CURRENT) 209 omInsertBinPage(bin->current_page, page, bin);209 omInsertBinPage(bin->current_page, page, bin); 210 210 # else 211 omInsertBinPage(bin->last_page, page, bin);211 omInsertBinPage(bin->last_page, page, bin); 212 212 # endif 213 213 #endif -
omalloc/omAllocPrivate.h
rff4e34f rf103fb 5 5 * Author: obachman (Olaf Bachmann) 6 6 * Created: 11/99 7 * Version: $Id: omAllocPrivate.h,v 1. 4 2000-08-18 09:05:51obachman Exp $7 * Version: $Id: omAllocPrivate.h,v 1.5 2000-10-04 13:12:28 obachman Exp $ 8 8 *******************************************************************/ 9 9 #ifndef OM_ALLOC_PRIVATE_H … … 53 53 }; 54 54 55 extern omSpecBin om_SpecBin; 55 extern omSpecBin om_SpecBin; 56 extern omBin om_StickyBins; 56 57 extern omBinPage_t om_ZeroPage[]; 57 58 extern omBin om_Size2Bin[]; … … 69 70 (page)->bin_sticky= (void*)((unsigned long)bin + omGetStickyOfPage(page)) 70 71 #define omSetStickyOfPage(page, sticky) \ 71 (page)->bin_sticky = (void*)(( unsigned long)sticky+ \72 (page)->bin_sticky = (void*)(((unsigned long)sticky & (SIZEOF_VOIDP-1)) + \ 72 73 (unsigned long)omGetTopBinOfPage(page)) 73 74 #define omSetTopBinAndStickyOfPage(page, bin, sticky) \ 74 (page)->bin_sticky= (void*)((unsigned long)sticky + (unsigned long)bin) 75 (page)->bin_sticky= (void*)(((unsigned long)sticky & (SIZEOF_VOIDP-1)) \ 76 + (unsigned long)bin) 75 77 76 78 #define omGetTopBinOfAddr(addr) \ -
omalloc/omBin.c
rff4e34f rf103fb 4 4 * Author: obachman (Olaf Bachmann) 5 5 * Created: 11/99 6 * Version: $Id: omBin.c,v 1. 3 2000-08-14 12:26:40obachman Exp $6 * Version: $Id: omBin.c,v 1.4 2000-10-04 13:12:28 obachman Exp $ 7 7 *******************************************************************/ 8 8 … … 157 157 s_bin = omFindInSortedGList(om_SpecBin, next, max_blocks, bin->max_blocks); 158 158 159 omAssume(s_bin != NULL );159 omAssume(s_bin != NULL && bin == s_bin->bin); 160 160 if (s_bin != NULL) 161 161 { … … 163 163 if (s_bin->ref == 0 || force) 164 164 { 165 #ifdef OM_HAVE_TRACK 166 if (! track_bin) 167 #endif 168 omFreeKeptAddrFromBin(s_bin->bin); 165 169 if(s_bin->bin->last_page == NULL || force) 166 170 { … … 180 184 } 181 185 182 /***************************************************************** 183 * 184 * Statistics 185 * 186 *****************************************************************/ 187 static void omGetBinStat(omBin bin, int *pages_p, int *used_blocks_p, 188 int *free_blocks_p) 189 { 190 int pages = 0, used_blocks = 0, free_blocks = 0; 191 int where = 1; 192 193 omBinPage page = bin->last_page; 194 while (page != NULL) 195 { 196 pages++; if (where == 1) 197 { 198 used_blocks += omGetUsedBlocksOfPage(page) + 1; 199 if (bin->max_blocks > 0) 200 free_blocks += bin->max_blocks - omGetUsedBlocksOfPage(page) -1; 201 } 202 else 203 { 204 if (bin->max_blocks > 1) 205 used_blocks += bin->max_blocks; 206 else 207 used_blocks++; 208 } 209 if (page == bin->current_page) where = -1; 210 page = page->prev; 211 } 212 *pages_p = pages; 213 *used_blocks_p = used_blocks; 214 *free_blocks_p = free_blocks; 215 } 216 217 static void omGetTotalBinStat(omBin bin, int *pages_p, int *used_blocks_p, 218 int *free_blocks_p) 219 { 220 int t_pages = 0, t_used_blocks = 0, t_free_blocks = 0; 221 int pages = 0, used_blocks = 0, free_blocks = 0; 222 223 while (bin != NULL) 224 { 225 omGetBinStat(bin, &pages, &used_blocks, &free_blocks); 226 t_pages += pages; 227 t_used_blocks += used_blocks; 228 t_free_blocks += free_blocks; 229 bin = bin->next; 230 } 231 *pages_p = t_pages; 232 *used_blocks_p = t_used_blocks; 233 *free_blocks_p = t_free_blocks; 234 } 235 236 static void omPrintBinStat(FILE * fd, omBin bin, int track, int* pages, int* used_blocks, int* free_blocks) 237 { 238 if (track) 239 { 240 fprintf(fd, "T \t \t"); 241 } 242 else 243 { 244 fprintf(fd, "%s%u\t%ld\t", (omIsStaticNormalBin(bin) ? " " : (omIsTrackBin(bin) ? "T" : "*")), 245 bin->sizeW, bin->max_blocks); 246 } 247 omGetTotalBinStat(bin, pages, used_blocks, free_blocks); 248 fprintf(fd, "%d\t%d\t%d\n", *pages, *free_blocks, *used_blocks); 249 if (bin->next != NULL) 250 { 251 int s_pages, s_free_blocks, s_used_blocks; 252 while (bin != NULL) 253 { 254 omGetBinStat(bin, &s_pages, &s_used_blocks, &s_free_blocks); 255 fprintf(fd, " \t \t%d\t%d\t%d\t%d\n", s_pages, s_free_blocks, s_used_blocks, 256 (int) bin->sticky); 257 bin = bin->next; 258 *pages += s_pages; 259 *used_blocks += s_used_blocks; 260 *free_blocks += s_free_blocks; 261 } 262 } 263 } 264 265 void omPrintBinStats(FILE* fd) 266 { 267 int i = OM_MAX_BIN_INDEX, pages=0, used_blocks=0, free_blocks=0; 268 int pages_p, used_blocks_p, free_blocks_p; 269 omSpecBin s_bin = om_SpecBin; 270 271 fprintf(fd, " SizeW\tBlocks\tUPages\tFBlocks\tUBlocks\tSticky\n"); 272 fflush(fd); 273 while (s_bin != NULL || i >= 0) 274 { 275 if (s_bin == NULL || (i >= 0 && (unsigned long) om_StaticBin[i].max_blocks < (unsigned long) s_bin->bin->max_blocks)) 276 { 277 omPrintBinStat(fd, &om_StaticBin[i], 0, &pages_p, &used_blocks_p, &free_blocks_p); 278 pages += pages_p; 279 used_blocks += used_blocks_p; 280 free_blocks += free_blocks_p; 281 #ifdef OM_HAVE_TRACK 282 if (om_StaticTrackBin[i].current_page != om_ZeroPage) 283 { 284 omPrintBinStat(fd, &om_StaticTrackBin[i], 1, &pages_p, &used_blocks_p, &free_blocks_p); 285 pages += pages_p; 286 used_blocks += used_blocks_p; 287 free_blocks += free_blocks_p; 288 } 289 #endif 290 i--; 291 } 292 else 293 { 294 omPrintBinStat(fd, s_bin->bin,0, &pages_p, &used_blocks_p, &free_blocks_p); 295 pages += pages_p; 296 used_blocks += used_blocks_p; 297 free_blocks += free_blocks_p; 298 s_bin = s_bin->next; 299 } 300 } 301 #ifdef OM_HAVE_TRACK 302 s_bin = om_SpecTrackBin; 303 while (s_bin != NULL) 304 { 305 omPrintBinStat(fd, s_bin->bin, 0, &pages_p, &used_blocks_p, &free_blocks_p); 306 s_bin = s_bin->next; 307 pages += pages_p; 308 used_blocks += used_blocks_p; 309 free_blocks += free_blocks_p; 310 } 311 #endif 312 fprintf(fd, "----------------------------------------\n"); 313 fprintf(fd, " \t \t%d\t%d\t%d\n", pages, free_blocks, used_blocks); 314 } 315 186 316 187 /***************************************************************** 317 188 * … … 401 272 402 273 omBinPage page = from_bin->last_page; 403 omAssume(to_bin->sticky == 0);404 274 omAssume(to_bin->sizeW == from_bin->sizeW); 405 275 omAssume(to_bin != from_bin); 406 omAssume(omIsOnGList(to_bin->next, next, from_bin)407 ||408 omIsOnGList(from_bin->next, next, to_bin));409 276 410 277 if (page == NULL) return; 411 278 do 412 279 { 413 omSet StickyOfPage(page, 0);280 omSetTopBinAndStickyOfPage(page, to_bin, to_bin->sticky); 414 281 if (page->prev == NULL) break; 415 282 page = page->prev; … … 499 366 500 367 368 /***************************************************************** 369 * 370 * Sticky bins 371 * 372 *****************************************************************/ 373 omBin om_StickyBins = NULL; 374 omBin omGetStickyBinOfBin(omBin bin) 375 { 376 omBin new_bin = omAlloc(sizeof(omBin_t)); 377 omAssume(omIsKnownTopBin(bin, 1) && ! omIsStickyBin(bin)); 378 new_bin->sticky = SIZEOF_VOIDP; 379 new_bin->max_blocks = bin->max_blocks; 380 new_bin->sizeW = bin->sizeW; 381 new_bin->next = om_StickyBins; 382 om_StickyBins = new_bin; 383 new_bin->last_page = NULL; 384 new_bin->current_page = om_ZeroPage; 385 #if 0 386 if (omIsSpecBin(bin)) 387 { 388 omSpecBin s_bin = omFindInSortedGList(om_SpecBin, next, max_blocks, bin->max_blocks); 389 omAssume(s_bin != NULL); 390 if (s_bin != NULL) 391 s_bin->ref++; 392 } 393 #endif 394 return new_bin; 395 } 396 397 void omMergeStickyBinIntoBin(omBin sticky_bin, omBin into_bin) 398 { 399 omSpecBin s_bin; 400 if (! omIsOnGList(om_StickyBins, next, sticky_bin) || 401 !sticky_bin->sticky || 402 sticky_bin->max_blocks != into_bin->max_blocks || 403 sticky_bin == into_bin || 404 !omIsKnownTopBin(into_bin, 1) || 405 omIsStickyBin(into_bin)) 406 { 407 #ifndef OM_NDEBUG 408 omReportError(omError_StickyBin, omError_NoError, OM_FLR, 409 (! omIsOnGList(om_StickyBins, next, sticky_bin) ? "unknown sticky_bin" : 410 (!sticky_bin->sticky ? "sticky_bin is not sticky" : 411 (sticky_bin->max_blocks != into_bin->max_blocks ? "sticky_bin and into_bin have different block sizes" : 412 (sticky_bin == into_bin ? "sticky_bin == into_bin" : 413 (!omIsKnownTopBin(into_bin, 1) ? "unknown into_bin" : 414 (omIsStickyBin(into_bin) ? "into_bin is sticky" : 415 "unknown sticky_bin error"))))))); 416 #endif 417 return; 418 } 419 omFreeKeptAddrFromBin(sticky_bin); 420 om_StickyBins = omRemoveFromGList(om_StickyBins, next, sticky_bin); 421 omMergeStickyPages(into_bin, sticky_bin); 422 423 #if 0 424 if (! omIsStaticBin(into_bin)) 425 { 426 omBin _ibin = into_bin; 427 omUnGetSpecBin(&_ibin); 428 } 429 #endif 430 omFreeSize(sticky_bin, sizeof(omBin_t)); 431 #if defined(OM_INTERNAL_DEBUG) && !defined(OM_NDEBUG) 432 omTestBin(into_bin, 2); 433 #endif 434 } 501 435 502 436 /***************************************************************** … … 505 439 * 506 440 *****************************************************************/ 441 #ifndef OM_NDEBUG 442 int omIsKnownTopBin(omBin bin, int normal_bin) 443 { 444 omBin to_check; 445 omSpecBin s_bin; 446 int i; 447 448 omAssume(normal_bin == 1 || normal_bin == 0); 449 450 #ifdef OM_HAVE_TRACK 451 if (! normal_bin) 452 { 453 to_check = om_StaticTrackBin; 454 s_bin = om_SpecTrackBin; 455 } 456 else 457 #endif 458 { 459 omAssume(normal_bin); 460 to_check = om_StaticBin; 461 s_bin = om_SpecBin; 462 } 463 464 for (i=0; i<= OM_MAX_BIN_INDEX; i++) 465 { 466 if (bin == &(to_check[i])) 467 return 1; 468 } 469 470 while (s_bin != NULL) 471 { 472 if (bin == s_bin->bin) return 1; 473 s_bin = s_bin->next; 474 } 475 to_check = om_StickyBins; 476 477 while (to_check != NULL) 478 { 479 if (bin == to_check) return 1; 480 to_check = to_check->next; 481 } 482 return 0; 483 } 484 #endif 485 507 486 unsigned long omGetNewStickyAllBinTag() 508 487 { … … 625 604 #endif 626 605 606 /***************************************************************** 607 * 608 * Statistics 609 * 610 *****************************************************************/ 611 static void omGetBinStat(omBin bin, int *pages_p, int *used_blocks_p, 612 int *free_blocks_p) 613 { 614 int pages = 0, used_blocks = 0, free_blocks = 0; 615 int where = 1; 616 617 omBinPage page = bin->last_page; 618 while (page != NULL) 619 { 620 pages++; if (where == 1) 621 { 622 used_blocks += omGetUsedBlocksOfPage(page) + 1; 623 if (bin->max_blocks > 0) 624 free_blocks += bin->max_blocks - omGetUsedBlocksOfPage(page) -1; 625 } 626 else 627 { 628 if (bin->max_blocks > 1) 629 used_blocks += bin->max_blocks; 630 else 631 used_blocks++; 632 } 633 if (page == bin->current_page) where = -1; 634 page = page->prev; 635 } 636 *pages_p = pages; 637 *used_blocks_p = used_blocks; 638 *free_blocks_p = free_blocks; 639 } 640 641 static void omGetTotalBinStat(omBin bin, int *pages_p, int *used_blocks_p, 642 int *free_blocks_p) 643 { 644 int t_pages = 0, t_used_blocks = 0, t_free_blocks = 0; 645 int pages = 0, used_blocks = 0, free_blocks = 0; 646 647 while (bin != NULL) 648 { 649 omGetBinStat(bin, &pages, &used_blocks, &free_blocks); 650 t_pages += pages; 651 t_used_blocks += used_blocks; 652 t_free_blocks += free_blocks; 653 if (!omIsStickyBin(bin)) 654 bin = bin->next; 655 else 656 bin = NULL; 657 } 658 *pages_p = t_pages; 659 *used_blocks_p = t_used_blocks; 660 *free_blocks_p = t_free_blocks; 661 } 662 663 static void omPrintBinStat(FILE * fd, omBin bin, int track, int* pages, int* used_blocks, int* free_blocks) 664 { 665 if (track) 666 { 667 fprintf(fd, "T \t \t"); 668 } 669 else 670 { 671 fprintf(fd, "%s%u\t%ld\t", (omIsStaticNormalBin(bin) ? " " : 672 (omIsStickyBin(bin) ? "S" : 673 (omIsTrackBin(bin) ? "T" : "*"))), 674 bin->sizeW, bin->max_blocks); 675 } 676 omGetTotalBinStat(bin, pages, used_blocks, free_blocks); 677 fprintf(fd, "%d\t%d\t%d\n", *pages, *free_blocks, *used_blocks); 678 if (bin->next != NULL && !omIsStickyBin(bin)) 679 { 680 int s_pages, s_free_blocks, s_used_blocks; 681 while (bin != NULL) 682 { 683 omGetBinStat(bin, &s_pages, &s_used_blocks, &s_free_blocks); 684 fprintf(fd, " \t \t%d\t%d\t%d\t%d\n", s_pages, s_free_blocks, s_used_blocks, 685 (int) bin->sticky); 686 bin = bin->next; 687 *pages += s_pages; 688 *used_blocks += s_used_blocks; 689 *free_blocks += s_free_blocks; 690 } 691 } 692 } 693 694 void omPrintBinStats(FILE* fd) 695 { 696 int i = OM_MAX_BIN_INDEX, pages=0, used_blocks=0, free_blocks=0; 697 int pages_p, used_blocks_p, free_blocks_p; 698 omSpecBin s_bin = om_SpecBin; 699 omBin sticky; 700 701 fprintf(fd, " SizeW\tBlocks\tUPages\tFBlocks\tUBlocks\tSticky\n"); 702 fflush(fd); 703 while (s_bin != NULL || i >= 0) 704 { 705 if (s_bin == NULL || (i >= 0 && (unsigned long) om_StaticBin[i].max_blocks < (unsigned long) s_bin->bin->max_blocks)) 706 { 707 omPrintBinStat(fd, &om_StaticBin[i], 0, &pages_p, &used_blocks_p, &free_blocks_p); 708 pages += pages_p; 709 used_blocks += used_blocks_p; 710 free_blocks += free_blocks_p; 711 #ifdef OM_HAVE_TRACK 712 if (om_StaticTrackBin[i].current_page != om_ZeroPage) 713 { 714 omPrintBinStat(fd, &om_StaticTrackBin[i], 1, &pages_p, &used_blocks_p, &free_blocks_p); 715 pages += pages_p; 716 used_blocks += used_blocks_p; 717 free_blocks += free_blocks_p; 718 } 719 #endif 720 i--; 721 } 722 else 723 { 724 omPrintBinStat(fd, s_bin->bin,0, &pages_p, &used_blocks_p, &free_blocks_p); 725 pages += pages_p; 726 used_blocks += used_blocks_p; 727 free_blocks += free_blocks_p; 728 s_bin = s_bin->next; 729 } 730 } 731 #ifdef OM_HAVE_TRACK 732 s_bin = om_SpecTrackBin; 733 while (s_bin != NULL) 734 { 735 omPrintBinStat(fd, s_bin->bin, 0, &pages_p, &used_blocks_p, &free_blocks_p); 736 s_bin = s_bin->next; 737 pages += pages_p; 738 used_blocks += used_blocks_p; 739 free_blocks += free_blocks_p; 740 } 741 #endif 742 sticky = om_StickyBins; 743 while (sticky != NULL) 744 { 745 omPrintBinStat(fd, sticky, 0, &pages_p, &used_blocks_p, &free_blocks_p); 746 sticky = sticky->next; 747 pages += pages_p; 748 used_blocks += used_blocks_p; 749 free_blocks += free_blocks_p; 750 } 751 fprintf(fd, "----------------------------------------\n"); 752 fprintf(fd, " \t \t%d\t%d\t%d\n", pages, free_blocks, used_blocks); 753 } 754 627 755 static int omGetUsedBytesOfBin(omBin bin) 628 756 { … … 637 765 omSpecBin s_bin = om_SpecBin; 638 766 size_t used = 0; 767 omBin sticky; 639 768 640 769 for (; i>=0; i--) … … 660 789 #endif 661 790 791 sticky = om_StickyBins; 792 while (sticky != NULL) 793 { 794 used += omGetUsedBytesOfBin(sticky); 795 sticky = sticky->next; 796 } 662 797 return used; 663 798 } -
omalloc/omBin.h
rff4e34f rf103fb 4 4 * Author: obachman (Olaf Bachmann) 5 5 * Created: 11/99 6 * Version: $Id: omBin.h,v 1. 3 2000-08-14 12:26:41obachman Exp $6 * Version: $Id: omBin.h,v 1.4 2000-10-04 13:12:29 obachman Exp $ 7 7 *******************************************************************/ 8 8 #ifndef OM_BIN_H 9 9 #define OM_BIN_H 10 11 12 10 13 11 #define omGetAlignedSpecBin(size) _omGetSpecBin(size, 1, 0) … … 19 17 void _omUnGetSpecBin(omBin *bin, int force); 20 18 size_t omGetUsedBinBytes(); 19 20 omBin omGetStickyBinOfBin(omBin bin); 21 void omMergeStickyBinIntoBin(omBin sticky_bin, omBin into_bin); 21 22 22 23 unsigned long omGetNewStickyBinTag(omBin bin); … … 31 32 32 33 void omPrintBinStats(FILE* fd); 34 #define omIsStickyBin(bin) (bin->sticky >= SIZEOF_VOIDP) 33 35 34 36 /*BEGINPRIVATE*/ 37 #ifndef OM_NDEBUG 38 int omIsKnownTopBin(omBin bin, int normal_bin); 39 #endif 35 40 #ifdef OM_HAVE_TRACK 36 41 #define omGetSpecTrackBin(size) _omGetSpecBin(size, 0, 1) … … 40 45 ((unsigned long) bin >= ((unsigned long) &om_StaticBin[0]) && \ 41 46 (unsigned long) bin <= ((unsigned long) &om_StaticBin[OM_MAX_BIN_INDEX])) 42 #define omIsNormalBin(bin) omIsStaticNormalBin(bin) || omFindInGList(om_SpecBin, next, bin, bin) 47 #define omIsNormalBin(bin) omIsStaticNormalBin(bin) || omFindInGList(om_SpecBin, next, bin, bin) || omIsStickyBin(bin) 48 #define omIsSpecBin(bin) (!omIsStaticNormalBin(bin) && !omIsStickyBin(bin)) 43 49 44 50 #ifdef OM_HAVE_TRACK … … 48 54 #define omIsTrackBin(bin) omIsStaticTrackBin(bin) || omFindInGList(om_SpecTrackBin, next, bin, bin) 49 55 #else 56 #define omIsKnownTopBin(bin, normal_bin) 1 50 57 #define omIsStaticTrackBin(bin) 0 51 58 #define omIsTrackBin(bin) 0 -
omalloc/omDebug.c
rff4e34f rf103fb 4 4 * Author: obachman@mathematik.uni-kl.de (Olaf Bachmann) 5 5 * Created: 7/00 6 * Version: $Id: omDebug.c,v 1.1 1 2000-09-25 12:27:42obachman Exp $6 * Version: $Id: omDebug.c,v 1.12 2000-10-04 13:12:29 obachman Exp $ 7 7 *******************************************************************/ 8 8 #include <limits.h> 9 #include <string.h> 9 10 #include "omConfig.h" 10 11 #include "omAlloc.h" … … 268 269 269 270 #ifdef OM_INTERNAL_DEBUG 270 (void) _omCheckAddr(ret, i+1,OM_FUSED|OM_FSIZE,om_Opts.MinCheck, omError_InternalBug, OM_FLR);271 (void) _omCheckAddr(ret, (void*)i+1,OM_FUSED|OM_FSIZE,om_Opts.MinCheck, omError_InternalBug, OM_FLR); 271 272 #endif 272 273 return ret; … … 453 454 { 454 455 omBin bin = omGetTopBinOfAddr(addr); 455 if ( !omIsStaticNormalBin(bin)) return bin;456 if (omIsSpecBin(bin)) return bin; 456 457 } 457 458 } … … 536 537 } 537 538 539 void omFreeKeptAddrFromBin(omBin bin) 540 { 541 void* addr = om_KeptAddr; 542 void* prev_addr = NULL; 543 void* next_addr; 544 omTrackFlags_t flags; 545 546 while (addr != NULL) 547 { 548 next_addr = *((void**) addr); 549 if (omIsBinPageAddr(addr) && omGetTopBinOfAddr(addr) == bin) 550 { 551 if (prev_addr != NULL) 552 *((void**) prev_addr) = next_addr; 553 else 554 om_KeptAddr = next_addr; 555 if (addr == om_LastKeptAddr) 556 om_LastKeptAddr = prev_addr; 557 om_NumberOfKeptAddrs--; 558 #ifdef OM_HAVE_TRACK 559 if (omIsTrackAddr(addr)) 560 { 561 omMarkAsFreeTrackAddr(addr, 0, &flags, OM_FLR); 562 omFreeTrackAddr(addr); 563 } 564 else 565 #endif 566 __omFree(addr); 567 addr = next_addr; 568 } 569 else 570 { 571 prev_addr = addr; 572 addr = next_addr; 573 } 574 } 575 576 addr = om_AlwaysKeptAddrs; 577 prev_addr = NULL; 578 while (addr != NULL) 579 { 580 next_addr = *((void**) addr); 581 if (omIsBinPageAddr(addr) && omGetTopBinOfAddr(addr) == bin) 582 { 583 if (prev_addr != NULL) 584 *((void**) prev_addr) = next_addr; 585 else 586 om_AlwaysKeptAddrs = next_addr; 587 #ifdef OM_HAVE_TRACK 588 if (omIsTrackAddr(addr)) 589 { 590 omMarkAsFreeTrackAddr(addr, 0, &flags, OM_FLR); 591 omFreeTrackAddr(addr); 592 } 593 else 594 #endif 595 __omFree(addr); 596 addr = next_addr; 597 } 598 else 599 { 600 prev_addr = addr; 601 addr = next_addr; 602 } 603 } 604 } 605 538 606 void omFreeKeptAddr() 539 607 { … … 541 609 omBin bin; 542 610 omTrackFlags_t flags; 611 void* addr = om_KeptAddr; 543 612 544 613 if (om_LastKeptAddr != NULL) 545 614 *((void**) om_LastKeptAddr) = om_AlwaysKeptAddrs; 546 615 547 while (om_KeptAddr != NULL)548 {549 next = *((void**)om_KeptAddr);550 bin = omGetOrigSpecBinOfAddr(om_KeptAddr);551 552 #ifdef OM_HAVE_TRACK553 if (omIsTrackAddr(om_KeptAddr))554 {555 omMarkAsFreeTrackAddr(om_KeptAddr, 0, &flags, OM_FLR);556 omFreeTrackAddr(om_KeptAddr);557 }558 else559 #endif560 __omFree(om_KeptAddr);561 562 if (bin != NULL) omUnGetSpecBin(&bin);563 om_KeptAddr = next;564 }565 616 om_NumberOfKeptAddrs = 0; 566 617 om_LastKeptAddr = NULL; 567 618 om_AlwaysKeptAddrs = NULL; 619 om_KeptAddr = NULL; 620 621 while (addr != NULL) 622 { 623 next = *((void**)addr); 624 bin = omGetOrigSpecBinOfAddr(addr); 625 626 #ifdef OM_HAVE_TRACK 627 if (omIsTrackAddr(addr)) 628 { 629 omMarkAsFreeTrackAddr(addr, 0, &flags, OM_FLR); 630 omFreeTrackAddr(addr); 631 } 632 else 633 #endif 634 __omFree(addr); 635 636 addr = next; 637 if (bin != NULL) omUnGetSpecBin(&bin); 638 } 568 639 } 569 640 -
omalloc/omDebug.h
rff4e34f rf103fb 4 4 * Author: obachman@mathematik.uni-kl.de (Olaf Bachmann) 5 5 * Created: 7/00 6 * Version: $Id: omDebug.h,v 1.1 0 2000-09-18 09:12:14obachman Exp $6 * Version: $Id: omDebug.h,v 1.11 2000-10-04 13:12:29 obachman Exp $ 7 7 *******************************************************************/ 8 8 #ifndef OM_DEBUG_H … … 93 93 94 94 #ifndef OM_NDEBUG 95 96 97 95 void* om_KeptAddr; 98 96 void* om_LastKeptAddr; … … 101 99 void* om_AlwaysKeptAddrs; 102 100 101 void omFreeKeptAddrFromBin(omBin bin); 103 102 /*********************************************************************** 104 103 * … … 117 116 omError_t omDoCheckBin(omBin bin, int normal_bin, char level, 118 117 omError_t report, OM_FLR_DECL); 119 int omIsKnownTopBin(omBin bin, int normal_bin);120 118 void omIterateTroughAddrs(int normal, int track, void (*CallBackUsed)(void*), void (*CallBackFree)(void*)); 121 119 void omIterateTroughBinAddrs(omBin bin, void (*CallBackUsed)(void*), void (*CallBackFree)(void*)); … … 191 189 omAddrCheckReturnError(cond, omError_MemoryCorrupted) 192 190 191 #else 192 #define omFreeKeptAddrFromBin(bin) ((void)0) 193 193 #endif /* ! OM_NDEBUG */ 194 194 /*ENDPRIVATE*/ 195 195 196 196 197 #endif /* OM_DEBUG_H */ -
omalloc/omDebugCheck.c
rff4e34f rf103fb 4 4 * Author: obachman@mathematik.uni-kl.de (Olaf Bachmann) 5 5 * Created: 11/99 6 * Version: $Id: omDebugCheck.c,v 1. 8 2000-09-25 12:27:42obachman Exp $6 * Version: $Id: omDebugCheck.c,v 1.9 2000-10-04 13:12:30 obachman Exp $ 7 7 *******************************************************************/ 8 8 #include <limits.h> … … 61 61 int i = 0; 62 62 omSpecBin s_bin; 63 omBin sticky; 63 64 64 65 if (check <= 0) return omError_NoError; … … 79 80 } 80 81 82 sticky = om_StickyBins; 83 omCheckReturn(omCheckGList(sticky, next, check, omError_MemoryCorrupted, OM_FLR_VAL)); 84 while (sticky != NULL) 85 { 86 omCheckReturn(omDoCheckBin(sticky, 1, check, report, OM_FLR_VAL)); 87 sticky = sticky->next; 88 } 89 81 90 #ifdef OM_HAVE_TRACK 82 91 for (i=0; i<= OM_MAX_BIN_INDEX; i++) … … 233 242 && ((omBin) bin_size) != omGetTopBinOfAddr(addr), omError_WrongBin); 234 243 235 if ( flags & OM_FSIZE&& (!(flags & OM_FSLOPPY) || (size_t) bin_size > 0))244 if ((flags & OM_FSIZE) && (!(flags & OM_FSLOPPY) || (size_t) bin_size > 0)) 236 245 { 237 246 size_t size = (size_t) bin_size; … … 249 258 250 259 omCheckReturnError(!omIsKnownTopBin(bin, normal_bin), omError_UnknownBin); 251 omCheckReturn(omCheckGList(bin->next, next, level, report, OM_FLR_VAL)); 260 if (! omIsStickyBin(bin)) 261 omCheckReturn(omCheckGList(bin->next, next, level, report, OM_FLR_VAL)); 252 262 253 263 do … … 273 283 if (level <= 1) continue; 274 284 275 omCheckReturnCorrupted(omFindInGList(bin->next, next, sticky, bin->sticky)); 285 if (! omIsStickyBin(bin)) 286 omCheckReturnCorrupted(omFindInGList(bin->next, next, sticky, bin->sticky)); 276 287 omCheckReturn(omCheckGList(bin->last_page, prev, level-1, report, OM_FLR_VAL)); 277 288 page = omGListLast(bin->last_page, prev); … … 293 304 omCheckReturnCorrupted(page->prev != NULL && page->prev->next != page); 294 305 295 omCheckReturnCorrupted(omGetStickyOfPage(page) != bin->sticky );306 omCheckReturnCorrupted(omGetStickyOfPage(page) != bin->sticky && bin->sticky < SIZEOF_VOIDP); 296 307 omCheckReturnCorrupted(omGetBinOfPage(page) != bin); 297 308 298 if ( ! bin->sticky)309 if (where == -1) 299 310 { 300 if (where == -1) 311 /* we are at the left of current_page, 312 i.e., page is empty */ 313 omCheckReturnCorrupted(omGetUsedBlocksOfPage(page) != 0 || page->current != NULL); 314 } 315 else 316 { 317 if (page == bin->current_page) 301 318 { 302 /* we are at the left of current_page, 303 i.e., page is empty */ 304 omCheckReturnCorrupted(omGetUsedBlocksOfPage(page) != 0 || page->current != NULL); 319 where = -1; 305 320 } 306 321 else 307 322 { 308 if (page == bin->current_page) 309 { 310 where = -1; 311 } 312 else 313 { 314 /* we are at the right of current_page, 315 i.e., page is neither full nor empty */ 316 omCheckReturnCorrupted(page->current == NULL || 317 omGetUsedBlocksOfPage(page) == bin->max_blocks - 1); 318 } 323 /* we are at the right of current_page, 324 i.e., page is neither full nor empty */ 325 omCheckReturnCorrupted(page->current == NULL || 326 omGetUsedBlocksOfPage(page) == bin->max_blocks - 1); 319 327 } 320 328 } 321 329 page = page->prev; 322 330 } /* while (page != NULL) */ 323 } while ( (bin = bin->next) != NULL);331 } while (!omIsStickyBin(bin) && ((bin = bin->next) != NULL)); 324 332 325 333 return omError_NoError; 326 334 } 327 335 328 int omIsKnownTopBin(omBin bin, int normal_bin)329 {330 omBin to_check;331 omSpecBin s_bin;332 int i;333 334 omAssume(normal_bin == 1 || normal_bin == 0);335 336 #ifdef OM_HAVE_TRACK337 if (! normal_bin)338 {339 to_check = om_StaticTrackBin;340 s_bin = om_SpecTrackBin;341 }342 else343 #endif344 {345 omAssume(normal_bin);346 to_check = om_StaticBin;347 s_bin = om_SpecBin;348 }349 350 for (i=0; i<= OM_MAX_BIN_INDEX; i++)351 {352 if (bin == &(to_check[i]))353 return 1;354 }355 356 while (s_bin != NULL)357 {358 if (bin == s_bin->bin) return 1;359 s_bin = s_bin->next;360 }361 return 0;362 }363 336 364 337 static omError_t omDoCheckBinPage(omBinPage page, int normal_page, int level, … … 510 483 page = page->prev; 511 484 } 512 bin = bin->next; 485 if (omIsStickyBin(bin)) 486 bin = NULL; 487 else 488 bin = bin->next; 513 489 } while (bin != NULL); 514 490 … … 519 495 int i; 520 496 omSpecBin s_bin; 497 omBin sticky; 521 498 522 499 if (normal) … … 549 526 } 550 527 #endif 528 sticky = om_StickyBins; 529 while (sticky != NULL) 530 { 531 omIterateTroughBinAddrs(sticky, CallBackUsed, CallBackFree); 532 sticky = sticky->next; 533 } 551 534 } 552 535 -
omalloc/omDebugTrack.c
rff4e34f rf103fb 4 4 * Author: obachman@mathematik.uni-kl.de (Olaf Bachmann) 5 5 * Created: 11/99 6 * Version: $Id: omDebugTrack.c,v 1.1 0 2000-09-20 11:52:31obachman Exp $6 * Version: $Id: omDebugTrack.c,v 1.11 2000-10-04 13:12:30 obachman Exp $ 7 7 *******************************************************************/ 8 8 #include <limits.h> 9 #include <string.h> 9 10 #include "omConfig.h" 10 11 #include "omDerivedConfig.h" … … 326 327 if (track > 2) 327 328 { 328 d_addr->bin_size = (flags & OM_FBIN ? bin_size : (void*) o_size); 329 if (flags & OM_FBIN && ((omBin) bin_size)->sticky) 330 { 331 d_addr->bin_size = (void*)(((omBin) bin_size)->sizeW<<LOG_SIZEOF_LONG); 332 d_addr->flags &= ~OM_FBIN; 333 d_addr->flags |= OM_FSIZE; 334 } 335 else 336 d_addr->bin_size = (flags & OM_FBIN ? bin_size : (void*) o_size); 329 337 omAssume(OM_ALIGN_SIZE((size_t)d_addr->bin_size) == (size_t) d_addr->bin_size); 330 338 … … 494 502 495 503 omAddrCheckReturnError((flags & OM_FBINADDR) && !((d_addr->flags & OM_FBIN) || ((size_t) d_addr->bin_size <= OM_MAX_BLOCK_SIZE)), omError_NotBinAddr); 496 497 omAddrCheckReturnError((flags & OM_FBIN) && ( !(d_addr->flags & OM_FBIN) || d_addr->bin_size != bin_size),omError_WrongBin); 498 if (flags & OM_FSIZE) 499 { 500 if (d_addr->flags & OM_FSIZE) 501 omAddrCheckReturnError((size_t) d_addr->bin_size != OM_ALIGN_SIZE((size_t) bin_size), omError_WrongSize); 504 505 if (flags & OM_FBIN) 506 { 507 if (d_addr->flags & OM_FBIN) 508 omAddrCheckReturnError(((omBin) d_addr->bin_size)->sizeW != ((omBin) bin_size)->sizeW, omError_WrongBin); 502 509 else 503 omAddrCheckReturnError(omTrackAddr_2_OutSize(d_addr) < (size_t) bin_size, omError_WrongSize); 504 } 505 510 omAddrCheckReturnError((((omBin) bin_size)->sizeW << LOG_SIZEOF_LONG) != OM_ALIGN_SIZE((size_t) d_addr->bin_size), omError_WrongBin); 511 } 512 else if (flags & OM_FSIZE) 513 { 514 if (d_addr->flags & OM_FBIN) 515 { 516 omAddrCheckReturnError((((omBin) d_addr->bin_size)->sizeW << LOG_SIZEOF_LONG) < ((size_t) bin_size), omError_WrongSize); 517 } 518 else 519 { 520 omAddrCheckReturnError((size_t) d_addr->bin_size < (size_t) bin_size, omError_WrongSize); 521 } 522 } 523 506 524 omAddrCheckReturnError(omCheckPattern(omTrackAddr_2_FrontPattern(d_addr), OM_FRONT_PATTERN,omTrackAddr_2_SizeOfFrontPattern(d_addr)),omError_FrontPattern); 507 525 omAddrCheckReturnError(omCheckPattern(omTrackAddr_2_BackPattern(d_addr), OM_BACK_PATTERN,omTrackAddr_2_SizeOfBackPattern(d_addr)),omError_BackPattern); … … 628 646 { 629 647 omBin bin = (omBin) d_addr->bin_size; 630 if (! omIsStaticNormalBin(bin)) 631 return bin; 648 if (omIsSpecBin(bin)) return bin; 632 649 } 633 650 return NULL; -
omalloc/omError.c
rff4e34f rf103fb 4 4 * Author: obachman (Olaf Bachmann) 5 5 * Created: 11/99 6 * Version: $Id: omError.c,v 1. 6 2000-09-25 12:27:43obachman Exp $6 * Version: $Id: omError.c,v 1.7 2000-10-04 13:12:30 obachman Exp $ 7 7 *******************************************************************/ 8 8 … … 46 46 {omError_FreePattern, "omError_FreePattern", "written into freed memory"}, 47 47 {omError_NotString, "omError_NotString", "string not null terminated"}, 48 {omError_StickyBin, "omError_StickyBin", "wrong handling of sticky bins"}, 48 49 49 50 {omError_MaxError, NULL} /* this needs to be the last entry */ -
omalloc/omError.h
rff4e34f rf103fb 4 4 * Author: obachman (Olaf Bachmann) 5 5 * Created: 11/99 6 * Version: $Id: omError.h,v 1. 6 2000-09-18 09:12:15obachman Exp $6 * Version: $Id: omError.h,v 1.7 2000-10-04 13:12:30 obachman Exp $ 7 7 *******************************************************************/ 8 8 #ifndef OM_ERROR_H … … 40 40 omError_FrontPattern, 41 41 omError_NotString, 42 omError_StickyBin, 42 43 omError_MaxError 43 44 }; -
omalloc/omInline.h
rff4e34f rf103fb 5 5 * Author: obachman@mathematik.uni-kl.de (Olaf Bachmann) 6 6 * Created: 11/99 7 * Version: $Id: omInline.h,v 1. 4 2000-08-16 16:08:33obachman Exp $7 * Version: $Id: omInline.h,v 1.5 2000-10-04 13:12:31 obachman Exp $ 8 8 *******************************************************************/ 9 9 #if defined(OM_INLINE) || defined(OM_ALLOC_C) … … 16 16 unsigned long sticky = omGetStickyOfPage(page); 17 17 omBin bin = omGetTopBinOfPage(page); 18 19 while (bin->sticky != sticky && bin->next != NULL) 20 { 21 bin = bin->next; 18 19 if (! omIsStickyBin(bin)) 20 { 21 while (bin->sticky != sticky && bin->next != NULL) 22 { 23 bin = bin->next; 24 } 22 25 } 23 26 return bin; -
omalloc/omList.c
rff4e34f rf103fb 4 4 * Author: obachman (Olaf Bachmann) 5 5 * Created: 11/99 6 * Version: $Id: omList.c,v 1. 5 2000-08-14 12:26:46obachman Exp $6 * Version: $Id: omList.c,v 1.6 2000-10-04 13:12:31 obachman Exp $ 7 7 *******************************************************************/ 8 8 #include "omConfig.h" … … 177 177 omError_t _omCheckList(void* list, int next, int level, omError_t report, OM_FLR_DECL) 178 178 { 179 if (level < =1) return omError_NoError;179 if (level < 1) return omError_NoError; 180 180 181 181 if (level == 1) -
omalloc/omRet2Info.c
rff4e34f rf103fb 4 4 * Author: obachman (Olaf Bachmann) 5 5 * Created: 11/99 6 * Version: $Id: omRet2Info.c,v 1. 7 2000-09-18 09:12:16obachman Exp $6 * Version: $Id: omRet2Info.c,v 1.8 2000-10-04 13:12:31 obachman Exp $ 7 7 *******************************************************************/ 8 8 #include <stdio.h> … … 244 244 #endif 245 245 #ifdef OM_TRACK_RETURN 246 fprintf(fd," ra=%p" );246 fprintf(fd," ra=%p", r); 247 247 #endif 248 248 -
omalloc/omtTest.c
rff4e34f rf103fb 274 274 } 275 275 276 omBin omtGetStickyBin(omBin bin) 277 { 278 omBin sticky_bin = omFindInGList(om_StickyBins, next, max_blocks, bin->max_blocks); 279 if (sticky_bin == NULL) 280 sticky_bin = omGetStickyBinOfBin(bin); 281 return sticky_bin; 282 } 283 284 void omtMergeStickyBins(omMemCell cell, int n) 285 { 286 int i; 287 omBin bin; 288 289 for (i=0; i<n; i++) 290 { 291 if (cell[i].orig_bin != NULL) 292 { 293 if (omIsOnGList(om_StickyBins, next, cell[i].bin)) 294 omMergeStickyBinIntoBin(cell[i].bin, cell[i].orig_bin); 295 296 cell[i].bin = cell[i].orig_bin; 297 cell[i].orig_bin = NULL; 298 } 299 } 300 301 bin = om_StickyBins; 302 while (bin != NULL) 303 { 304 if (bin->current_page == om_ZeroPage) 305 { 306 omBin next_bin = bin->next; 307 om_StickyBins = omRemoveFromGList(om_StickyBins, next, bin); 308 __omFreeBinAddr(bin); 309 bin = next_bin; 310 } 311 else 312 { 313 bin = bin->next; 314 } 315 } 316 } 317 318 276 319 void my_exit() 277 320 { … … 351 394 } 352 395 #endif 396 omtMergeStickyBins(cells, n_cells); 353 397 while (i< n_cells) 354 398 { … … 357 401 } 358 402 omFreeKeptAddr(); 403 omtMergeStickyBins(cells, -1); 359 404 omPrintStats(stdout); 360 405 omPrintInfo(stdout); -
omalloc/omtTest.h
rff4e34f rf103fb 9 9 10 10 // #define MAX_CELLS 500000 11 // #define MAX_CELLS 100000 11 12 #define MAX_CELLS 100000 12 // #define MAX_CELLS 100013 13 #define KEEP_ADDR 100 14 14 #define END_CHECK_LEVEL 5 … … 26 26 omBin bin; 27 27 unsigned long spec; 28 omBin orig_bin; 28 29 }; 29 30 … … 45 46 #endif 46 47 48 #define IS_STICKY_BIN(spec) (spec & 1) 49 // #define IS_STICKY_BIN(spec) (0) 47 50 #define GET_SIZE(spec) (spec & ((1 << 14) -1)) 48 51 #define SET_SIZE(spec, size) spec = ((spec & ~((1 << 14) -1)) | (size)) … … 110 113 void InitCellAddrContent(omMemCell cell); 111 114 int omtTestErrors(); 115 omBin omtGetStickyBin(omBin bin); 112 116 113 117 #if CHECK_LEVEL > 0 -
omalloc/omtTestAlloc.c
rff4e34f rf103fb 4 4 * Author: obachman@mathematik.uni-kl.de (Olaf Bachmann) 5 5 * Created: 11/99 6 * Version: $Id: omtTestAlloc.c,v 1. 7 2000-09-18 09:18:26obachman Exp $6 * Version: $Id: omtTestAlloc.c,v 1.8 2000-10-04 13:12:32 obachman Exp $ 7 7 *******************************************************************/ 8 8 #include "omtTest.h" … … 36 36 void* addr; 37 37 omBin bin = NULL; 38 omBin orig_bin = NULL; 38 39 39 40 if (IS_BIN(spec) && (size <= OM_MAX_BLOCK_SIZE || IS_SPEC_BIN(spec))) … … 44 45 bin = omGetAlignedSpecBin(size); 45 46 else 46 bin = omGetSpecBin(size); 47 bin = omGetSpecBin(size); 47 48 } 48 49 else … … 52 53 else 53 54 bin = omSmallSize2Bin(size); 55 } 56 57 if (IS_STICKY_BIN(spec)) 58 { 59 orig_bin = bin; 60 bin = omtGetStickyBin(bin); 54 61 } 55 62 … … 118 125 cell->addr = addr; 119 126 cell->bin = bin; 127 cell->orig_bin = orig_bin; 120 128 cell->spec = spec; 121 129 … … 130 138 unsigned long spec = cell->spec; 131 139 omBin bin = cell->bin; 140 omBin orig_bin = cell->orig_bin; 132 141 size_t size = GET_SIZE(spec); 133 142 … … 156 165 157 166 if (bin != NULL && IS_SPEC_BIN(spec)) 158 omUnGetSpecBin(&bin); 167 { 168 if (orig_bin != NULL) 169 omUnGetSpecBin(&orig_bin); 170 else 171 omUnGetSpecBin(&bin); 172 } 159 173 160 174 cell->addr = NULL; 161 175 cell->spec = 0; 162 176 cell->bin = NULL; 177 cell->orig_bin = NULL; 163 178 } 164 179 … … 168 183 int old_spec = cell->spec; 169 184 omBin old_bin = cell->bin; 185 omBin old_orig_bin = cell->orig_bin; 170 186 size_t old_size = GET_SIZE(old_spec); 171 187 void* new_addr; 172 188 omBin new_bin = NULL; 189 omBin new_orig_bin = NULL; 173 190 size_t new_size = GET_SIZE(new_spec); 174 191 size_t real_old_size = omSizeOfAddr(old_addr); … … 194 211 new_bin = omSmallSize2Bin(new_size); 195 212 } 213 214 if (IS_STICKY_BIN(new_spec)) 215 { 216 new_orig_bin = new_bin; 217 new_bin = omtGetStickyBin(new_bin); 218 } 196 219 197 220 if (IS_INLINE(new_spec)) … … 294 317 295 318 if (old_bin != NULL && IS_SPEC_BIN(old_spec)) 319 { 320 if (old_orig_bin != NULL) 321 omUnGetSpecBin(&old_orig_bin); 322 else 296 323 omUnGetSpecBin(&old_bin); 324 } 297 325 298 326 new_size = omSizeOfAddr(new_addr); … … 312 340 cell->spec = new_spec; 313 341 cell->bin = new_bin; 342 cell->orig_bin = new_orig_bin; 314 343 InitCellAddrContent(cell); 315 344 omtTestDebug(cell); -
omalloc/omtTestError.c
rff4e34f rf103fb 124 124 spec.MinTrack = 3; 125 125 spec.NotIsBin = 1; 126 spec.MinSize = 2; 126 127 cell = omFindCell(spec); 127 128 if (cell != NULL) … … 387 388 #endif 388 389 omStrDup(NULL); 389 } 390 break; 391 } 392 393 case omError_StickyBin: 394 { 395 omMergeStickyBinIntoBin(NULL, NULL); 396 break; 397 } 398 390 399 default: 391 400 printf("No Error test implemented\n");
Note: See TracChangeset
for help on using the changeset viewer.