Return the number of bytes allocated, adjusted for explicit storage */ management, etc.. This number is used in deciding when to trigger */ collections. */
| 170 | /* management, etc.. This number is used in deciding when to trigger */ |
| 171 | /* collections. */ |
| 172 | word GC_adj_bytes_allocd(void) |
| 173 | { |
| 174 | signed_word result; |
| 175 | signed_word expl_managed = |
| 176 | (signed_word)GC_non_gc_bytes |
| 177 | - (signed_word)GC_non_gc_bytes_at_gc; |
| 178 | |
| 179 | /* Don't count what was explicitly freed, or newly allocated for */ |
| 180 | /* explicit management. Note that deallocating an explicitly */ |
| 181 | /* managed object should not alter result, assuming the client */ |
| 182 | /* is playing by the rules. */ |
| 183 | result = (signed_word)GC_bytes_allocd |
| 184 | - (signed_word)GC_bytes_freed |
| 185 | + (signed_word)GC_finalizer_bytes_freed |
| 186 | - expl_managed; |
| 187 | if (result > (signed_word)GC_bytes_allocd) { |
| 188 | result = GC_bytes_allocd; |
| 189 | /* probably client bug or unfortunate scheduling */ |
| 190 | } |
| 191 | result += GC_bytes_finalized; |
| 192 | /* We count objects enqueued for finalization as though they */ |
| 193 | /* had been reallocated this round. Finalization is user */ |
| 194 | /* visible progress. And if we don't count this, we have */ |
| 195 | /* stability problems for programs that finalize all objects. */ |
| 196 | if (result < (signed_word)(GC_bytes_allocd >> 3)) { |
| 197 | /* Always count at least 1/8 of the allocations. We don't want */ |
| 198 | /* to collect too infrequently, since that would inhibit */ |
| 199 | /* coalescing of free storage blocks. */ |
| 200 | /* This also makes us partially robust against client bugs. */ |
| 201 | return(GC_bytes_allocd >> 3); |
| 202 | } else { |
| 203 | return(result); |
| 204 | } |
| 205 | } |
| 206 | |
| 207 | |
| 208 | /* Clear up a few frames worth of garbage left at the top of the stack. */ |