mirror of
https://github.com/vishapoberon/compiler.git
synced 2026-04-06 22:42:24 +00:00
Integrate jtempl heap allocation recursion fix.
This commit is contained in:
parent
37fc052d95
commit
535f80d91c
1 changed files with 8 additions and 11 deletions
|
|
@ -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
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue