Fix #283: mcode_alloc() doing busywork on exhausted allocation pool

Instead of doing a hard-coded number of randomized allocation attempts
in mcode_alloc(), do at most LJ_TARGET_JUMPRANGE iterations as a
heuristic to try harder for bigger allocation pools (i.e. higher
LJ_TARGET_JUMPRANGE values), but don't waste CPU cycles for smaller
pools that can be easily exhausted.
This commit is contained in:
Alexey Kopytov 2017-02-25 17:13:28 +03:00
parent a25c0b99b8
commit 0fdcdd92a1

View File

@ -233,7 +233,10 @@ static void *mcode_alloc(jit_State *J, size_t sz)
/* First try a contiguous area below the last one. */ /* First try a contiguous area below the last one. */
uintptr_t hint = J->mcarea ? (uintptr_t)J->mcarea - sz : 0; uintptr_t hint = J->mcarea ? (uintptr_t)J->mcarea - sz : 0;
int i; int i;
for (i = 0; i < 32; i++) { /* 32 attempts ought to be enough ... */ /* Do at most LJ_TARGET_JUMPRANGE iterations as a heuristic to try harder for
** bigger allocation pools (i.e. higher LJ_TARGET_JUMPRANGE values), but don't
** waste CPU cycles for smaller pools that can be easily exhausted. */
for (i = 0; i < LJ_TARGET_JUMPRANGE; i++) {
if (mcode_validptr(hint)) { if (mcode_validptr(hint)) {
void *p = mcode_alloc_at(J, hint, sz, MCPROT_GEN); void *p = mcode_alloc_at(J, hint, sz, MCPROT_GEN);