Skip to content

Commit

Permalink
Merge pull request softdevteam#23 from jacob-hughes/finalizer_count_api
Browse files Browse the repository at this point in the history
Reimplement finalize count API
  • Loading branch information
ltratt authored Aug 23, 2024
2 parents 74bb8e4 + 4de0a20 commit 0da451d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
4 changes: 4 additions & 0 deletions include/gc/gc.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,10 @@ GC_API GC_ATTR_DEPRECATED int GC_finalize_on_demand;
GC_API void GC_CALL GC_set_finalize_on_demand(int);
GC_API int GC_CALL GC_get_finalize_on_demand(void);

/* Returns the total number of finalizers that have been run so far */
/* by the collector. */
GC_API size_t GC_CALL GC_finalized_total(void);

GC_API GC_ATTR_DEPRECATED int GC_java_finalization;
/* Mark objects reachable from finalizable */
/* objects in a separate post-pass. This makes */
Expand Down
3 changes: 3 additions & 0 deletions include/private/gc_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -1432,6 +1432,8 @@ struct _GC_arrays {
/* Bytes of memory explicitly deallocated while */
/* finalizers were running. Used to approximate memory */
/* explicitly deallocated by finalizers. */
size_t _finalizers_run;
/* Number of finalizers that have been run so far. */
bottom_index *_all_bottom_indices;
/* Pointer to the first (lowest address) bottom_index; */
/* assumes the allocator lock is held. */
Expand Down Expand Up @@ -1711,6 +1713,7 @@ GC_API_PRIV GC_FAR struct _GC_arrays GC_arrays;
#define GC_composite_in_use GC_arrays._composite_in_use
#define GC_excl_table GC_arrays._excl_table
#define GC_finalizer_bytes_freed GC_arrays._finalizer_bytes_freed
#define GC_finalizers_run GC_arrays._finalizers_run
#define GC_heapsize GC_arrays._heapsize
#define GC_large_allocd_bytes GC_arrays._large_allocd_bytes
#define GC_large_free_bytes GC_arrays._large_free_bytes
Expand Down
7 changes: 6 additions & 1 deletion reclaim.c
Original file line number Diff line number Diff line change
Expand Up @@ -894,7 +894,7 @@ static void* init_finalize_thread(void *arg)
}
flzr_can_work = 0;
pthread_mutex_unlock(&flzr_mtx);
GC_invoke_finalizers();
GC_finalizers_run += GC_invoke_finalizers();
}
return arg;
}
Expand All @@ -916,3 +916,8 @@ GC_INNER void GC_maybe_wake_finalizer_thread()
pthread_cond_signal(&flzr_t_has_work);
pthread_mutex_unlock(&flzr_mtx);
}

GC_API size_t GC_finalized_total()
{
return GC_finalizers_run;
}

0 comments on commit 0da451d

Please sign in to comment.