Changeset 106310 in vbox
- Timestamp:
- Oct 14, 2024 3:17:55 PM (6 weeks ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/VMM/VMMAll/IEMAllN8veExecMem.cpp
r106309 r106310 651 651 # ifdef RT_ARCH_AMD64 652 652 unsigned cZerosInWord = __popcnt64(~uWord); 653 # elif defined(RT_ARCH_ARM64) 654 unsigned cZerosInWord = _CountOneBits64(~uWord); 653 655 # else 654 656 # pragma message("need popcount intrinsic or something...") /** @todo port me: Win/ARM. */ … … 856 858 857 859 858 static PIEMNATIVEINSTR 859 iemExecMemAllocatorAllocInChunk(PIEMEXECMEMALLOCATOR pExecMemAllocator, uint32_t idxChunk, uint32_t cbReq, PIEMTB pTb, 860 PIEMNATIVEINSTR *ppaExec, PCIEMNATIVEPERCHUNKCTX *ppChunkCtx) 861 { 862 /* 863 * Figure out how much to allocate. 864 */ 860 /** 861 * Converts requested number of bytes into a unit count. 862 */ 863 DECL_FORCE_INLINE(uint32_t) iemExecMemAllocBytesToUnits(uint32_t cbReq) 864 { 865 865 #ifdef IEMEXECMEM_ALT_SUB_WITH_ALLOC_HEADER 866 uint32_t const cReqUnits =(cbReq + sizeof(IEMEXECMEMALLOCHDR) + IEMEXECMEM_ALT_SUB_ALLOC_UNIT_SIZE - 1)866 return (cbReq + sizeof(IEMEXECMEMALLOCHDR) + IEMEXECMEM_ALT_SUB_ALLOC_UNIT_SIZE - 1) 867 867 #else 868 uint32_t const cReqUnits = (cbReq + IEMEXECMEM_ALT_SUB_ALLOC_UNIT_SIZE - 1) 869 #endif 870 >> IEMEXECMEM_ALT_SUB_ALLOC_UNIT_SHIFT; 868 return (cbReq + IEMEXECMEM_ALT_SUB_ALLOC_UNIT_SIZE - 1) 869 #endif 870 >> IEMEXECMEM_ALT_SUB_ALLOC_UNIT_SHIFT; 871 } 872 873 874 DECL_FORCE_INLINE(PIEMNATIVEINSTR) 875 iemExecMemAllocatorAllocUnitsInChunkInner(PIEMEXECMEMALLOCATOR pExecMemAllocator, uint32_t idxChunk, uint32_t cReqUnits, 876 PIEMTB pTb, PIEMNATIVEINSTR *ppaExec, PCIEMNATIVEPERCHUNKCTX *ppChunkCtx) 877 { 878 uint64_t * const pbmAlloc = &pExecMemAllocator->pbmAlloc[pExecMemAllocator->cBitmapElementsPerChunk * idxChunk]; 879 uint32_t const idxHint = pExecMemAllocator->aChunks[idxChunk].idxFreeHint & ~(uint32_t)63; 880 if (idxHint + cReqUnits <= pExecMemAllocator->cUnitsPerChunk) 881 { 882 void *pvRet = iemExecMemAllocatorAllocInChunkInt(pExecMemAllocator, pbmAlloc, idxHint, 883 pExecMemAllocator->cUnitsPerChunk - idxHint, 884 cReqUnits, idxChunk, pTb, (void **)ppaExec, ppChunkCtx); 885 if (pvRet) 886 return (PIEMNATIVEINSTR)pvRet; 887 } 888 void *pvRet = iemExecMemAllocatorAllocInChunkInt(pExecMemAllocator, pbmAlloc, 0, 889 RT_MIN(pExecMemAllocator->cUnitsPerChunk, 890 RT_ALIGN_32(idxHint + cReqUnits, 64*4)), 891 cReqUnits, idxChunk, pTb, (void **)ppaExec, ppChunkCtx); 892 if (!pvRet) 893 pExecMemAllocator->cFruitlessChunkScans += 1; 894 return (PIEMNATIVEINSTR)pvRet; 895 } 896 897 898 DECL_FORCE_INLINE(PIEMNATIVEINSTR) 899 iemExecMemAllocatorAllocUnitsInChunk(PIEMEXECMEMALLOCATOR pExecMemAllocator, uint32_t idxChunk, uint32_t cReqUnits, PIEMTB pTb, 900 PIEMNATIVEINSTR *ppaExec, PCIEMNATIVEPERCHUNKCTX *ppChunkCtx) 901 { 871 902 if (cReqUnits <= pExecMemAllocator->aChunks[idxChunk].cFreeUnits) 872 { 873 uint64_t * const pbmAlloc = &pExecMemAllocator->pbmAlloc[pExecMemAllocator->cBitmapElementsPerChunk * idxChunk]; 874 uint32_t const idxHint = pExecMemAllocator->aChunks[idxChunk].idxFreeHint & ~(uint32_t)63; 875 if (idxHint + cReqUnits <= pExecMemAllocator->cUnitsPerChunk) 876 { 877 void *pvRet = iemExecMemAllocatorAllocInChunkInt(pExecMemAllocator, pbmAlloc, idxHint, 878 pExecMemAllocator->cUnitsPerChunk - idxHint, 879 cReqUnits, idxChunk, pTb, (void **)ppaExec, ppChunkCtx); 880 if (pvRet) 881 { 882 #ifdef VBOX_WITH_STATISTICS 883 pExecMemAllocator->cbUnusable += (cReqUnits << IEMEXECMEM_ALT_SUB_ALLOC_UNIT_SHIFT) - cbReq; 884 #endif 885 return (PIEMNATIVEINSTR)pvRet; 886 } 887 } 888 void *pvRet = iemExecMemAllocatorAllocInChunkInt(pExecMemAllocator, pbmAlloc, 0, 889 RT_MIN(pExecMemAllocator->cUnitsPerChunk, 890 RT_ALIGN_32(idxHint + cReqUnits, 64*4)), 891 cReqUnits, idxChunk, pTb, (void **)ppaExec, ppChunkCtx); 892 if (!pvRet) 893 pExecMemAllocator->cFruitlessChunkScans += 1; 894 #ifdef VBOX_WITH_STATISTICS 895 else 896 pExecMemAllocator->cbUnusable += (cReqUnits << IEMEXECMEM_ALT_SUB_ALLOC_UNIT_SHIFT) - cbReq; 897 #endif 898 return (PIEMNATIVEINSTR)pvRet; 899 } 903 return iemExecMemAllocatorAllocUnitsInChunkInner(pExecMemAllocator, idxChunk, cReqUnits, pTb, ppaExec, ppChunkCtx); 900 904 return NULL; 905 } 906 907 908 DECLINLINE(PIEMNATIVEINSTR) 909 iemExecMemAllocatorAllocBytesInChunk(PIEMEXECMEMALLOCATOR pExecMemAllocator, uint32_t idxChunk, uint32_t cbReq, 910 PIEMNATIVEINSTR *ppaExec) 911 { 912 return iemExecMemAllocatorAllocUnitsInChunk(pExecMemAllocator, idxChunk, iemExecMemAllocBytesToUnits(cbReq), NULL /*pTb*/, 913 ppaExec, NULL /*ppChunkCtx*/); 901 914 } 902 915 … … 924 937 STAM_PROFILE_START(&pExecMemAllocator->StatAlloc, a); 925 938 939 uint32_t const cReqUnits = iemExecMemAllocBytesToUnits(cbReq); 926 940 for (unsigned iIteration = 0;; iIteration++) 927 941 { … … 932 946 for (uint32_t idxChunk = idxChunkHint; idxChunk < cChunks; idxChunk++) 933 947 { 934 PIEMNATIVEINSTR const pRet = iemExecMemAllocatorAlloc InChunk(pExecMemAllocator, idxChunk, cbReq, pTb,935 ppaExec, ppChunkCtx);948 PIEMNATIVEINSTR const pRet = iemExecMemAllocatorAllocUnitsInChunk(pExecMemAllocator, idxChunk, cReqUnits, pTb, 949 ppaExec, ppChunkCtx); 936 950 if (pRet) 937 951 { 938 952 STAM_PROFILE_STOP(&pExecMemAllocator->StatAlloc, a); 953 #ifdef VBOX_WITH_STATISTICS 954 pExecMemAllocator->cbUnusable += (cReqUnits << IEMEXECMEM_ALT_SUB_ALLOC_UNIT_SHIFT) - cbReq; 955 #endif 939 956 return pRet; 940 957 } … … 942 959 for (uint32_t idxChunk = 0; idxChunk < idxChunkHint; idxChunk++) 943 960 { 944 PIEMNATIVEINSTR const pRet = iemExecMemAllocatorAlloc InChunk(pExecMemAllocator, idxChunk, cbReq, pTb,945 ppaExec, ppChunkCtx);961 PIEMNATIVEINSTR const pRet = iemExecMemAllocatorAllocUnitsInChunk(pExecMemAllocator, idxChunk, cReqUnits, pTb, 962 ppaExec, ppChunkCtx); 946 963 if (pRet) 947 964 { 948 965 STAM_PROFILE_STOP(&pExecMemAllocator->StatAlloc, a); 966 #ifdef VBOX_WITH_STATISTICS 967 pExecMemAllocator->cbUnusable += (cReqUnits << IEMEXECMEM_ALT_SUB_ALLOC_UNIT_SHIFT) - cbReq; 968 #endif 949 969 return pRet; 950 970 } … … 961 981 962 982 uint32_t const idxChunk = pExecMemAllocator->cChunks - 1; 963 PIEMNATIVEINSTR const pRet = iemExecMemAllocatorAlloc InChunk(pExecMemAllocator, idxChunk, cbReq, pTb,964 ppaExec, ppChunkCtx);983 PIEMNATIVEINSTR const pRet = iemExecMemAllocatorAllocUnitsInChunk(pExecMemAllocator, idxChunk, cReqUnits, pTb, 984 ppaExec, ppChunkCtx); 965 985 if (pRet) 966 986 { 967 987 STAM_PROFILE_STOP(&pExecMemAllocator->StatAlloc, a); 988 #ifdef VBOX_WITH_STATISTICS 989 pExecMemAllocator->cbUnusable += (cReqUnits << IEMEXECMEM_ALT_SUB_ALLOC_UNIT_SHIFT) - cbReq; 990 #endif 968 991 return pRet; 969 992 } … … 1197 1220 AssertReturn(idxChunk < pExecMemAllocator->cChunks, NULL); 1198 1221 Assert(cbReq < _1M); 1199 return iemExecMemAllocatorAlloc InChunk(pExecMemAllocator, idxChunk, cbReq, NULL /*pTb*/, ppaExec, NULL /*ppChunkCtx*/);1222 return iemExecMemAllocatorAllocBytesInChunk(pExecMemAllocator, idxChunk, cbReq, ppaExec); 1200 1223 } 1201 1224 … … 1287 1310 unsigned const cbNeeded = sizeof(IMAGE_RUNTIME_FUNCTION_ENTRY) * cFunctionEntries + cbUnwindInfo; 1288 1311 PIMAGE_RUNTIME_FUNCTION_ENTRY const paFunctions 1289 = (PIMAGE_RUNTIME_FUNCTION_ENTRY)iemExecMemAllocatorAlloc InChunk(pExecMemAllocator, idxChunk, cbNeeded, NULL, NULL, NULL);1312 = (PIMAGE_RUNTIME_FUNCTION_ENTRY)iemExecMemAllocatorAllocBytesInChunk(pExecMemAllocator, idxChunk, cbNeeded, NULL); 1290 1313 AssertReturn(paFunctions, VERR_INTERNAL_ERROR_5); 1291 1314 pExecMemAllocator->aChunks[idxChunk].pvUnwindInfo = paFunctions; … … 1522 1545 * This seems to work best with ET_DYN. 1523 1546 */ 1524 GDBJITSYMFILE * const pSymFile = (GDBJITSYMFILE *)iemExecMemAllocatorAlloc InChunk(pExecMemAllocator, idxChunk,1525 sizeof(GDBJITSYMFILE), NULL, NULL, NULL);1547 GDBJITSYMFILE * const pSymFile = (GDBJITSYMFILE *)iemExecMemAllocatorAllocBytesInChunk(pExecMemAllocator, idxChunk, 1548 sizeof(GDBJITSYMFILE), NULL); 1526 1549 AssertReturn(pSymFile, VERR_INTERNAL_ERROR_5); 1527 1550 unsigned const offSymFileInChunk = (uintptr_t)pSymFile - (uintptr_t)pvChunk;
Note:
See TracChangeset
for help on using the changeset viewer.