Integrate jtempl heap allocation recursion fix.

This commit is contained in:
David Brown 2016-12-22 17:16:42 +00:00
parent 37fc052d95
commit 535f80d91c

View file

@ -266,18 +266,15 @@ MODULE Heap;
IF adr = 0 THEN (* Nothing free *) IF adr = 0 THEN (* Nothing free *)
IF firstTry THEN IF firstTry THEN
GC(TRUE); INC(blksz, Unit); GC(TRUE); INC(blksz, Unit);
IF uLT(heapsize - allocated, blksz) (* Anti-thrashing heuristics: ensure 1/4 of the heap will not be allocated. *)
OR uLT((heapsize - allocated - blksz) * 4, heapsize) THEN t := (allocated + blksz) DIV (3*Unit) * (4*Unit); (* Minimum required new heapsize *)
(* heap would still be more than 3/4 full; expand to avoid thrashing *) IF uLT(heapsize, t) THEN ExtendHeap(t - heapsize) END;
ExtendHeap((allocated + blksz) DIV (3*Unit) * (4*Unit) - heapsize) firstTry := FALSE; new := NEWREC(tag);
END; IF new = NIL THEN (* Fragmentation prevented allocation, heap is 1/4 free *)
firstTry := FALSE; new := NEWREC(tag); firstTry := TRUE; ExtendHeap(blksz);
IF new = NIL THEN new := NEWREC(tag) (* Will find a free block if heap has been expanded successfully *)
(* depending on the fragmentation, the heap may not have been extended by
the anti-thrashing heuristics above *)
ExtendHeap((allocated + blksz) DIV (3*Unit) * (4*Unit) - heapsize);
new := NEWREC(tag); (* will find a free block if heap has been expanded properly *)
END; END;
firstTry := TRUE;
Unlock(); RETURN new Unlock(); RETURN new
ELSE ELSE
Unlock(); RETURN NIL Unlock(); RETURN NIL