mem3 15551 sqlite3/libsqlite/sqlite3.c } mem3 = { 97535575 }; mem3 15553 sqlite3/libsqlite/sqlite3.c #define mem3 GLOBAL(struct Mem3Global, mem3) mem3 15560 sqlite3/libsqlite/sqlite3.c u32 next = mem3.aPool[i].u.list.next; mem3 15561 sqlite3/libsqlite/sqlite3.c u32 prev = mem3.aPool[i].u.list.prev; mem3 15562 sqlite3/libsqlite/sqlite3.c assert( sqlite3_mutex_held(mem3.mutex) ); mem3 15566 sqlite3/libsqlite/sqlite3.c mem3.aPool[prev].u.list.next = next; mem3 15569 sqlite3/libsqlite/sqlite3.c mem3.aPool[next].u.list.prev = prev; mem3 15571 sqlite3/libsqlite/sqlite3.c mem3.aPool[i].u.list.next = 0; mem3 15572 sqlite3/libsqlite/sqlite3.c mem3.aPool[i].u.list.prev = 0; mem3 15581 sqlite3/libsqlite/sqlite3.c assert( sqlite3_mutex_held(mem3.mutex) ); mem3 15582 sqlite3/libsqlite/sqlite3.c assert( (mem3.aPool[i-1].u.hdr.size4x & 1)==0 ); mem3 15584 sqlite3/libsqlite/sqlite3.c size = mem3.aPool[i-1].u.hdr.size4x/4; mem3 15585 sqlite3/libsqlite/sqlite3.c assert( size==mem3.aPool[i+size-1].u.hdr.prevSize ); mem3 15588 sqlite3/libsqlite/sqlite3.c memsys3UnlinkFromList(i, &mem3.aiSmall[size-2]); mem3 15591 sqlite3/libsqlite/sqlite3.c memsys3UnlinkFromList(i, &mem3.aiHash[hash]); mem3 15600 sqlite3/libsqlite/sqlite3.c assert( sqlite3_mutex_held(mem3.mutex) ); mem3 15601 sqlite3/libsqlite/sqlite3.c mem3.aPool[i].u.list.next = *pRoot; mem3 15602 sqlite3/libsqlite/sqlite3.c mem3.aPool[i].u.list.prev = 0; mem3 15604 sqlite3/libsqlite/sqlite3.c mem3.aPool[*pRoot].u.list.prev = i; mem3 15615 sqlite3/libsqlite/sqlite3.c assert( sqlite3_mutex_held(mem3.mutex) ); mem3 15617 sqlite3/libsqlite/sqlite3.c assert( (mem3.aPool[i-1].u.hdr.size4x & 1)==0 ); mem3 15618 sqlite3/libsqlite/sqlite3.c size = mem3.aPool[i-1].u.hdr.size4x/4; mem3 15619 sqlite3/libsqlite/sqlite3.c assert( size==mem3.aPool[i+size-1].u.hdr.prevSize ); mem3 15622 sqlite3/libsqlite/sqlite3.c memsys3LinkIntoList(i, &mem3.aiSmall[size-2]); mem3 15625 sqlite3/libsqlite/sqlite3.c memsys3LinkIntoList(i, &mem3.aiHash[hash]); mem3 15635 sqlite3/libsqlite/sqlite3.c if( sqlite3GlobalConfig.bMemstat==0 && mem3.mutex==0 ){ mem3 15636 sqlite3/libsqlite/sqlite3.c mem3.mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MEM); mem3 15638 sqlite3/libsqlite/sqlite3.c sqlite3_mutex_enter(mem3.mutex); mem3 15641 sqlite3/libsqlite/sqlite3.c sqlite3_mutex_leave(mem3.mutex); mem3 15648 sqlite3/libsqlite/sqlite3.c if( !mem3.alarmBusy ){ mem3 15649 sqlite3/libsqlite/sqlite3.c mem3.alarmBusy = 1; mem3 15650 sqlite3/libsqlite/sqlite3.c assert( sqlite3_mutex_held(mem3.mutex) ); mem3 15651 sqlite3/libsqlite/sqlite3.c sqlite3_mutex_leave(mem3.mutex); mem3 15653 sqlite3/libsqlite/sqlite3.c sqlite3_mutex_enter(mem3.mutex); mem3 15654 sqlite3/libsqlite/sqlite3.c mem3.alarmBusy = 0; mem3 15666 sqlite3/libsqlite/sqlite3.c assert( sqlite3_mutex_held(mem3.mutex) ); mem3 15668 sqlite3/libsqlite/sqlite3.c assert( mem3.aPool[i-1].u.hdr.size4x/4==nBlock ); mem3 15669 sqlite3/libsqlite/sqlite3.c assert( mem3.aPool[i+nBlock-1].u.hdr.prevSize==nBlock ); mem3 15670 sqlite3/libsqlite/sqlite3.c x = mem3.aPool[i-1].u.hdr.size4x; mem3 15671 sqlite3/libsqlite/sqlite3.c mem3.aPool[i-1].u.hdr.size4x = nBlock*4 | 1 | (x&2); mem3 15672 sqlite3/libsqlite/sqlite3.c mem3.aPool[i+nBlock-1].u.hdr.prevSize = nBlock; mem3 15673 sqlite3/libsqlite/sqlite3.c mem3.aPool[i+nBlock-1].u.hdr.size4x |= 2; mem3 15674 sqlite3/libsqlite/sqlite3.c return &mem3.aPool[i]; mem3 15683 sqlite3/libsqlite/sqlite3.c assert( sqlite3_mutex_held(mem3.mutex) ); mem3 15684 sqlite3/libsqlite/sqlite3.c assert( mem3.szMaster>=nBlock ); mem3 15685 sqlite3/libsqlite/sqlite3.c if( nBlock>=mem3.szMaster-1 ){ mem3 15687 sqlite3/libsqlite/sqlite3.c void *p = memsys3Checkout(mem3.iMaster, mem3.szMaster); mem3 15688 sqlite3/libsqlite/sqlite3.c mem3.iMaster = 0; mem3 15689 sqlite3/libsqlite/sqlite3.c mem3.szMaster = 0; mem3 15690 sqlite3/libsqlite/sqlite3.c mem3.mnMaster = 0; mem3 15695 sqlite3/libsqlite/sqlite3.c newi = mem3.iMaster + mem3.szMaster - nBlock; mem3 15696 sqlite3/libsqlite/sqlite3.c assert( newi > mem3.iMaster+1 ); mem3 15697 sqlite3/libsqlite/sqlite3.c mem3.aPool[mem3.iMaster+mem3.szMaster-1].u.hdr.prevSize = nBlock; mem3 15698 sqlite3/libsqlite/sqlite3.c mem3.aPool[mem3.iMaster+mem3.szMaster-1].u.hdr.size4x |= 2; mem3 15699 sqlite3/libsqlite/sqlite3.c mem3.aPool[newi-1].u.hdr.size4x = nBlock*4 + 1; mem3 15700 sqlite3/libsqlite/sqlite3.c mem3.szMaster -= nBlock; mem3 15701 sqlite3/libsqlite/sqlite3.c mem3.aPool[newi-1].u.hdr.prevSize = mem3.szMaster; mem3 15702 sqlite3/libsqlite/sqlite3.c x = mem3.aPool[mem3.iMaster-1].u.hdr.size4x & 2; mem3 15703 sqlite3/libsqlite/sqlite3.c mem3.aPool[mem3.iMaster-1].u.hdr.size4x = mem3.szMaster*4 | x; mem3 15704 sqlite3/libsqlite/sqlite3.c if( mem3.szMaster < mem3.mnMaster ){ mem3 15705 sqlite3/libsqlite/sqlite3.c mem3.mnMaster = mem3.szMaster; mem3 15707 sqlite3/libsqlite/sqlite3.c return (void*)&mem3.aPool[newi]; mem3 15730 sqlite3/libsqlite/sqlite3.c assert( sqlite3_mutex_held(mem3.mutex) ); mem3 15732 sqlite3/libsqlite/sqlite3.c iNext = mem3.aPool[i].u.list.next; mem3 15733 sqlite3/libsqlite/sqlite3.c size = mem3.aPool[i-1].u.hdr.size4x; mem3 15737 sqlite3/libsqlite/sqlite3.c assert( i > mem3.aPool[i-1].u.hdr.prevSize ); mem3 15738 sqlite3/libsqlite/sqlite3.c prev = i - mem3.aPool[i-1].u.hdr.prevSize; mem3 15740 sqlite3/libsqlite/sqlite3.c iNext = mem3.aPool[prev].u.list.next; mem3 15744 sqlite3/libsqlite/sqlite3.c x = mem3.aPool[prev-1].u.hdr.size4x & 2; mem3 15745 sqlite3/libsqlite/sqlite3.c mem3.aPool[prev-1].u.hdr.size4x = size*4 | x; mem3 15746 sqlite3/libsqlite/sqlite3.c mem3.aPool[prev+size-1].u.hdr.prevSize = size; mem3 15752 sqlite3/libsqlite/sqlite3.c if( size>mem3.szMaster ){ mem3 15753 sqlite3/libsqlite/sqlite3.c mem3.iMaster = i; mem3 15754 sqlite3/libsqlite/sqlite3.c mem3.szMaster = size; mem3 15771 sqlite3/libsqlite/sqlite3.c assert( sqlite3_mutex_held(mem3.mutex) ); mem3 15786 sqlite3/libsqlite/sqlite3.c i = mem3.aiSmall[nBlock-2]; mem3 15788 sqlite3/libsqlite/sqlite3.c memsys3UnlinkFromList(i, &mem3.aiSmall[nBlock-2]); mem3 15793 sqlite3/libsqlite/sqlite3.c for(i=mem3.aiHash[hash]; i>0; i=mem3.aPool[i].u.list.next){ mem3 15794 sqlite3/libsqlite/sqlite3.c if( mem3.aPool[i-1].u.hdr.size4x/4==nBlock ){ mem3 15795 sqlite3/libsqlite/sqlite3.c memsys3UnlinkFromList(i, &mem3.aiHash[hash]); mem3 15805 sqlite3/libsqlite/sqlite3.c if( mem3.szMaster>=nBlock ){ mem3 15817 sqlite3/libsqlite/sqlite3.c for(toFree=nBlock*16; toFree<(mem3.nPool*16); toFree *= 2){ mem3 15819 sqlite3/libsqlite/sqlite3.c if( mem3.iMaster ){ mem3 15820 sqlite3/libsqlite/sqlite3.c memsys3Link(mem3.iMaster); mem3 15821 sqlite3/libsqlite/sqlite3.c mem3.iMaster = 0; mem3 15822 sqlite3/libsqlite/sqlite3.c mem3.szMaster = 0; mem3 15825 sqlite3/libsqlite/sqlite3.c memsys3Merge(&mem3.aiHash[i]); mem3 15828 sqlite3/libsqlite/sqlite3.c memsys3Merge(&mem3.aiSmall[i]); mem3 15830 sqlite3/libsqlite/sqlite3.c if( mem3.szMaster ){ mem3 15831 sqlite3/libsqlite/sqlite3.c memsys3Unlink(mem3.iMaster); mem3 15832 sqlite3/libsqlite/sqlite3.c if( mem3.szMaster>=nBlock ){ mem3 15852 sqlite3/libsqlite/sqlite3.c assert( sqlite3_mutex_held(mem3.mutex) ); mem3 15853 sqlite3/libsqlite/sqlite3.c assert( p>mem3.aPool && p<&mem3.aPool[mem3.nPool] ); mem3 15854 sqlite3/libsqlite/sqlite3.c i = p - mem3.aPool; mem3 15855 sqlite3/libsqlite/sqlite3.c assert( (mem3.aPool[i-1].u.hdr.size4x&1)==1 ); mem3 15856 sqlite3/libsqlite/sqlite3.c size = mem3.aPool[i-1].u.hdr.size4x/4; mem3 15857 sqlite3/libsqlite/sqlite3.c assert( i+size<=mem3.nPool+1 ); mem3 15858 sqlite3/libsqlite/sqlite3.c mem3.aPool[i-1].u.hdr.size4x &= ~1; mem3 15859 sqlite3/libsqlite/sqlite3.c mem3.aPool[i+size-1].u.hdr.prevSize = size; mem3 15860 sqlite3/libsqlite/sqlite3.c mem3.aPool[i+size-1].u.hdr.size4x &= ~2; mem3 15864 sqlite3/libsqlite/sqlite3.c if( mem3.iMaster ){ mem3 15865 sqlite3/libsqlite/sqlite3.c while( (mem3.aPool[mem3.iMaster-1].u.hdr.size4x&2)==0 ){ mem3 15866 sqlite3/libsqlite/sqlite3.c size = mem3.aPool[mem3.iMaster-1].u.hdr.prevSize; mem3 15867 sqlite3/libsqlite/sqlite3.c mem3.iMaster -= size; mem3 15868 sqlite3/libsqlite/sqlite3.c mem3.szMaster += size; mem3 15869 sqlite3/libsqlite/sqlite3.c memsys3Unlink(mem3.iMaster); mem3 15870 sqlite3/libsqlite/sqlite3.c x = mem3.aPool[mem3.iMaster-1].u.hdr.size4x & 2; mem3 15871 sqlite3/libsqlite/sqlite3.c mem3.aPool[mem3.iMaster-1].u.hdr.size4x = mem3.szMaster*4 | x; mem3 15872 sqlite3/libsqlite/sqlite3.c mem3.aPool[mem3.iMaster+mem3.szMaster-1].u.hdr.prevSize = mem3.szMaster; mem3 15874 sqlite3/libsqlite/sqlite3.c x = mem3.aPool[mem3.iMaster-1].u.hdr.size4x & 2; mem3 15875 sqlite3/libsqlite/sqlite3.c while( (mem3.aPool[mem3.iMaster+mem3.szMaster-1].u.hdr.size4x&1)==0 ){ mem3 15876 sqlite3/libsqlite/sqlite3.c memsys3Unlink(mem3.iMaster+mem3.szMaster); mem3 15877 sqlite3/libsqlite/sqlite3.c mem3.szMaster += mem3.aPool[mem3.iMaster+mem3.szMaster-1].u.hdr.size4x/4; mem3 15878 sqlite3/libsqlite/sqlite3.c mem3.aPool[mem3.iMaster-1].u.hdr.size4x = mem3.szMaster*4 | x; mem3 15879 sqlite3/libsqlite/sqlite3.c mem3.aPool[mem3.iMaster+mem3.szMaster-1].u.hdr.prevSize = mem3.szMaster; mem3 15972 sqlite3/libsqlite/sqlite3.c mem3.aPool = (Mem3Block *)sqlite3GlobalConfig.pHeap; mem3 15973 sqlite3/libsqlite/sqlite3.c mem3.nPool = (sqlite3GlobalConfig.nHeap / sizeof(Mem3Block)) - 2; mem3 15976 sqlite3/libsqlite/sqlite3.c mem3.szMaster = mem3.nPool; mem3 15977 sqlite3/libsqlite/sqlite3.c mem3.mnMaster = mem3.szMaster; mem3 15978 sqlite3/libsqlite/sqlite3.c mem3.iMaster = 1; mem3 15979 sqlite3/libsqlite/sqlite3.c mem3.aPool[0].u.hdr.size4x = (mem3.szMaster<<2) + 2; mem3 15980 sqlite3/libsqlite/sqlite3.c mem3.aPool[mem3.nPool].u.hdr.prevSize = mem3.nPool; mem3 15981 sqlite3/libsqlite/sqlite3.c mem3.aPool[mem3.nPool].u.hdr.size4x = 1; mem3 15991 sqlite3/libsqlite/sqlite3.c mem3.mutex = 0; mem3 16018 sqlite3/libsqlite/sqlite3.c for(i=1; i<=mem3.nPool; i+=size/4){ mem3 16019 sqlite3/libsqlite/sqlite3.c size = mem3.aPool[i-1].u.hdr.size4x; mem3 16021 sqlite3/libsqlite/sqlite3.c fprintf(out, "%p size error\n", &mem3.aPool[i]); mem3 16025 sqlite3/libsqlite/sqlite3.c if( (size&1)==0 && mem3.aPool[i+size/4-1].u.hdr.prevSize!=size/4 ){ mem3 16026 sqlite3/libsqlite/sqlite3.c fprintf(out, "%p tail size does not match\n", &mem3.aPool[i]); mem3 16030 sqlite3/libsqlite/sqlite3.c if( ((mem3.aPool[i+size/4-1].u.hdr.size4x&2)>>1)!=(size&1) ){ mem3 16031 sqlite3/libsqlite/sqlite3.c fprintf(out, "%p tail checkout bit is incorrect\n", &mem3.aPool[i]); mem3 16036 sqlite3/libsqlite/sqlite3.c fprintf(out, "%p %6d bytes checked out\n", &mem3.aPool[i], (size/4)*8-8); mem3 16038 sqlite3/libsqlite/sqlite3.c fprintf(out, "%p %6d bytes free%s\n", &mem3.aPool[i], (size/4)*8-8, mem3 16039 sqlite3/libsqlite/sqlite3.c i==mem3.iMaster ? " **master**" : ""); mem3 16043 sqlite3/libsqlite/sqlite3.c if( mem3.aiSmall[i]==0 ) continue; mem3 16045 sqlite3/libsqlite/sqlite3.c for(j = mem3.aiSmall[i]; j>0; j=mem3.aPool[j].u.list.next){ mem3 16046 sqlite3/libsqlite/sqlite3.c fprintf(out, " %p(%d)", &mem3.aPool[j], mem3 16047 sqlite3/libsqlite/sqlite3.c (mem3.aPool[j-1].u.hdr.size4x/4)*8-8); mem3 16052 sqlite3/libsqlite/sqlite3.c if( mem3.aiHash[i]==0 ) continue; mem3 16054 sqlite3/libsqlite/sqlite3.c for(j = mem3.aiHash[i]; j>0; j=mem3.aPool[j].u.list.next){ mem3 16055 sqlite3/libsqlite/sqlite3.c fprintf(out, " %p(%d)", &mem3.aPool[j], mem3 16056 sqlite3/libsqlite/sqlite3.c (mem3.aPool[j-1].u.hdr.size4x/4)*8-8); mem3 16060 sqlite3/libsqlite/sqlite3.c fprintf(out, "master=%d\n", mem3.iMaster); mem3 16061 sqlite3/libsqlite/sqlite3.c fprintf(out, "nowUsed=%d\n", mem3.nPool*8 - mem3.szMaster*8); mem3 16062 sqlite3/libsqlite/sqlite3.c fprintf(out, "mxUsed=%d\n", mem3.nPool*8 - mem3.mnMaster*8); mem3 16063 sqlite3/libsqlite/sqlite3.c sqlite3_mutex_leave(mem3.mutex);