Skip to content

Commit

Permalink
Place all non-default GC API behind USE_SHARED_GC
Browse files Browse the repository at this point in the history
  • Loading branch information
peterzhu2118 authored and eightbitraptor committed Nov 22, 2024
1 parent 98f3e2d commit 24adb7c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
15 changes: 10 additions & 5 deletions gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,13 @@ rb_gc_vm_barrier(void)
rb_vm_barrier();
}

#if USE_SHARED_GC
void *
rb_gc_get_ractor_newobj_cache(void)
{
return GET_RACTOR()->newobj_cache;
}

void
rb_gc_initialize_vm_context(struct rb_gc_vm_context *context)
{
Expand Down Expand Up @@ -221,6 +228,7 @@ rb_gc_worker_thread_unset_vm_context(struct rb_gc_vm_context *context)
native_tls_set(ruby_current_ec_key, NULL);
#endif
}
#endif

bool
rb_gc_event_hook_required_p(rb_event_flag_t event)
Expand All @@ -245,11 +253,6 @@ rb_gc_get_objspace(void)
return GET_VM()->gc.objspace;
}

void *
rb_gc_get_ractor_newobj_cache(void)
{
return GET_RACTOR()->newobj_cache;
}

void
rb_gc_ractor_newobj_cache_foreach(void (*func)(void *cache, void *data), void *data)
Expand Down Expand Up @@ -3286,6 +3289,7 @@ update_superclasses(void *objspace, VALUE obj)
extern rb_symbols_t ruby_global_symbols;
#define global_symbols ruby_global_symbols

#if USE_SHARED_GC
struct global_vm_table_foreach_data {
vm_table_foreach_callback_func callback;
vm_table_update_callback_func update_callback;
Expand Down Expand Up @@ -3419,6 +3423,7 @@ rb_gc_vm_weak_table_foreach(vm_table_foreach_callback_func callback,
rb_bug("rb_gc_vm_weak_table_foreach: unknown table %d", table);
}
}
#endif

void
rb_gc_update_vm_references(void *objspace)
Expand Down
19 changes: 12 additions & 7 deletions gc/gc.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
* first introduced for [Feature #20470].
*/
#include "ruby/ruby.h"

#if USE_SHARED_GC
#include "ruby/thread_native.h"

struct rb_gc_vm_context {
Expand All @@ -30,6 +32,7 @@ enum rb_gc_vm_weak_tables {
RB_GC_VM_FROZEN_STRINGS_TABLE,
RB_GC_VM_WEAK_TABLE_COUNT
};
#endif

RUBY_SYMBOL_EXPORT_BEGIN
unsigned int rb_gc_vm_lock(void);
Expand All @@ -39,17 +42,12 @@ void rb_gc_cr_unlock(unsigned int lev);
unsigned int rb_gc_vm_lock_no_barrier(void);
void rb_gc_vm_unlock_no_barrier(unsigned int lev);
void rb_gc_vm_barrier(void);
void rb_gc_initialize_vm_context(struct rb_gc_vm_context *context);
void rb_gc_worker_thread_set_vm_context(struct rb_gc_vm_context *context);
void rb_gc_worker_thread_unset_vm_context(struct rb_gc_vm_context *context);
size_t rb_gc_obj_optimal_size(VALUE obj);
void rb_gc_mark_children(void *objspace, VALUE obj);
void rb_gc_update_object_references(void *objspace, VALUE obj);
void rb_gc_update_vm_references(void *objspace);
bool rb_gc_event_hook_required_p(rb_event_flag_t event);
void rb_gc_event_hook(VALUE obj, rb_event_flag_t event);
void *rb_gc_get_objspace(void);
void *rb_gc_get_ractor_newobj_cache(void);
size_t rb_size_mul_or_raise(size_t x, size_t y, VALUE exc);
void rb_gc_run_obj_finalizer(VALUE objid, long count, VALUE (*callback)(long i, void *data), void *data);
void rb_gc_set_pending_interrupt(void);
Expand All @@ -70,10 +68,17 @@ void rb_gc_set_shape(VALUE obj, uint32_t shape_id);
uint32_t rb_gc_rebuild_shape(VALUE obj, size_t heap_id);
size_t rb_obj_memsize_of(VALUE obj);
void rb_gc_prepare_heap_process_object(VALUE obj);
void rb_gc_vm_weak_table_foreach(vm_table_foreach_callback_func callback, vm_table_update_callback_func update_callback, void *data, enum rb_gc_vm_weak_tables table);
bool ruby_free_at_exit_p(void);
RUBY_SYMBOL_EXPORT_END

#if USE_SHARED_GC
bool rb_gc_event_hook_required_p(rb_event_flag_t event);
void *rb_gc_get_ractor_newobj_cache(void);
void rb_gc_initialize_vm_context(struct rb_gc_vm_context *context);
void rb_gc_worker_thread_set_vm_context(struct rb_gc_vm_context *context);
void rb_gc_worker_thread_unset_vm_context(struct rb_gc_vm_context *context);
void rb_gc_vm_weak_table_foreach(vm_table_foreach_callback_func callback, vm_table_update_callback_func update_callback, void *data, enum rb_gc_vm_weak_tables table);
#endif
RUBY_SYMBOL_EXPORT_END

void rb_ractor_finish_marking(void);

Expand Down

0 comments on commit 24adb7c

Please sign in to comment.