Garbage collector problems
incrediball opened this issue · comments
The simple garbage collector in amxgc.c
appears to have a few issues which lead to loops never terminating. If the table has filled up and gc_mark
is called, then the condition if (SharedGC.count>=(1<<SharedGC.exponent))
in gc_mark
, which is for enlarging the table, is never true because it appears that SharedGC.count
is always zero. The only assignments to SharedGC.count
set it to 0. (The naming of count
is perhaps unfortunate because there are two of them, one in GCPAIR
and one in GCINFO
and both appear to have totally different uses.) Since the table is not enlarged the while loop in gc_mark
cannot find a free entry and never terminates.
Furthermore, scansection
has two while loops and the inner one will loop forever if the table is full and the value in *start
cannot be found (which is likely) and the table has no free entries.
I am unsure what the search algorithm is trying to achieve, i.e. with the "folding" etc. It appears to be trying to implement something that is faster than a simple linear search but without more information on the algorithm I don't feel like modifying the while loop in scansection.
Not a bug but just out of curiosity, what is the point of the inverse array? What does *minorbyte=inverse[*minorbyte]
do that *minorbyte=~(*minorbyte)
or *minorbyte=255 - *minorbyte
does not?
One more thing: the line SharedGC.count=flags;
in gc_settable
meant that the flags parameter was ignored and the table would never grow automatically even if the condition mentioned previously were ever true. It should be SharedGC.flags=flags;
Fixed in commit c9dc9da.