Skip to content

Commit fa86966

Browse files
committed
Implement large object space
1 parent 8230dac commit fa86966

3 files changed

Lines changed: 26 additions & 6 deletions

File tree

gc/mmtk/mmtk.c

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ struct objspace {
5757

5858
uintptr_t vo_bit_log_region_size;
5959
uintptr_t vo_bit_base_addr;
60+
size_t max_non_los_default_alloc_bytes;
6061
};
6162

6263
#define OBJ_FREE_BUF_CAPACITY 128
@@ -110,6 +111,7 @@ RB_THREAD_LOCAL_SPECIFIER VALUE marking_parent_object;
110111
#include <pthread.h>
111112

112113
#define MMTK_ALLOCATION_SEMANTICS_DEFAULT 0
114+
#define MMTK_ALLOCATION_SEMANTICS_LOS 2
113115

114116
static inline VALUE rb_mmtk_call_object_closure(VALUE obj, bool pin);
115117

@@ -604,6 +606,7 @@ rb_gc_impl_objspace_init(void *objspace_ptr)
604606

605607
objspace->vo_bit_log_region_size = mmtk_get_vo_bit_log_region_size();
606608
objspace->vo_bit_base_addr = mmtk_get_vo_bit_base_addr();
609+
objspace->max_non_los_default_alloc_bytes = mmtk_max_non_los_default_alloc_bytes();
607610
}
608611

609612
void
@@ -687,6 +690,8 @@ rb_gc_impl_zjit_new_obj_fastpath(void *objspace_ptr, size_t alloc_size, VALUE fl
687690
size_t object_size = total_size - sizeof(VALUE) - RB_GC_OBJ_SUFFIX_SIZE;
688691
size_t value_size_shift = sizeof(VALUE) == 8 ? 3 : 2;
689692

693+
if (total_size > objspace->max_non_los_default_alloc_bytes) return false;
694+
690695
struct rb_gc_zjit_mmtk_new_obj_fastpath mmtk_fastpath = {
691696
objspace,
692697
offsetof(struct objspace, total_allocated_objects),
@@ -956,21 +961,26 @@ rb_gc_impl_new_obj(void *objspace_ptr, void *cache_ptr, VALUE klass, VALUE flags
956961
struct MMTk_ractor_cache *ractor_cache = cache_ptr;
957962

958963
if (alloc_size == 0) {
959-
rb_bug("rb_gc_impl_new_obj: allocation size is zero");
964+
rb_bug("rb_gc_impl_new_obj: allocation size out of range (size=%"PRIuSIZE")", alloc_size);
960965
}
961966

962967
// Layout: [hidden size header (sizeof(VALUE))][payload (alloc_size)][suffix (RB_GC_OBJ_SUFFIX_SIZE)]
963968
size_t total_size = rb_mmtk_align_obj_size(alloc_size + sizeof(VALUE) + RB_GC_OBJ_SUFFIX_SIZE);
964969
size_t object_size = total_size - sizeof(VALUE) - RB_GC_OBJ_SUFFIX_SIZE;
970+
MMTk_AllocationSemantics semantics = total_size > objspace->max_non_los_default_alloc_bytes
971+
? MMTK_ALLOCATION_SEMANTICS_LOS
972+
: MMTK_ALLOCATION_SEMANTICS_DEFAULT;
965973
*actual_alloc_size = object_size;
966974

967975
if (objspace->gc_stress) {
968976
mmtk_handle_user_collection_request(ractor_cache, false, false);
969977
}
970978

971-
VALUE *alloc_obj = (VALUE *)rb_mmtk_alloc_fast_path(objspace, ractor_cache, total_size, MMTk_MIN_OBJ_ALIGN);
979+
VALUE *alloc_obj = semantics == MMTK_ALLOCATION_SEMANTICS_DEFAULT
980+
? (VALUE *)rb_mmtk_alloc_fast_path(objspace, ractor_cache, total_size, MMTk_MIN_OBJ_ALIGN)
981+
: NULL;
972982
if (!alloc_obj) {
973-
alloc_obj = mmtk_alloc(ractor_cache->mutator, total_size, MMTk_MIN_OBJ_ALIGN, 0, MMTK_ALLOCATION_SEMANTICS_DEFAULT);
983+
alloc_obj = mmtk_alloc(ractor_cache->mutator, total_size, MMTk_MIN_OBJ_ALIGN, 0, semantics);
974984

975985
// On heap exhaustion raise NoMemoryError.
976986
if (RB_UNLIKELY(alloc_obj == NULL)) {
@@ -983,8 +993,8 @@ rb_gc_impl_new_obj(void *objspace_ptr, void *cache_ptr, VALUE klass, VALUE flags
983993
alloc_obj[0] = flags;
984994
alloc_obj[1] = klass;
985995

986-
if (ractor_cache->bump_pointer == NULL) {
987-
mmtk_post_alloc(ractor_cache->mutator, (void*)alloc_obj, object_size, MMTK_ALLOCATION_SEMANTICS_DEFAULT);
996+
if (semantics == MMTK_ALLOCATION_SEMANTICS_LOS || ractor_cache->bump_pointer == NULL) {
997+
mmtk_post_alloc(ractor_cache->mutator, (void*)alloc_obj, total_size, semantics);
988998
}
989999
else {
9901000
// We can use the post alloc fast path if we're using Immix bump pointer allocator
@@ -1024,7 +1034,7 @@ rb_gc_impl_size_allocatable_p(size_t size)
10241034
size_t
10251035
rb_gc_impl_max_allocation_size(void)
10261036
{
1027-
return SIZE_T_MAX;
1037+
return SIZE_MAX;
10281038
}
10291039

10301040
// Malloc

gc/mmtk/mmtk.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ void mmtk_set_gc_enabled(bool enable);
115115

116116
bool mmtk_gc_enabled_p(void);
117117

118+
size_t mmtk_max_non_los_default_alloc_bytes(void);
119+
118120
MMTk_Address mmtk_alloc(MMTk_Mutator *mutator,
119121
size_t size,
120122
size_t align,

gc/mmtk/src/api.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,14 @@ pub extern "C" fn mmtk_gc_enabled_p() -> bool {
314314

315315
// =============== Object allocation ===============
316316

317+
#[no_mangle]
318+
pub extern "C" fn mmtk_max_non_los_default_alloc_bytes() -> usize {
319+
mmtk()
320+
.get_plan()
321+
.constraints()
322+
.max_non_los_default_alloc_bytes
323+
}
324+
317325
#[no_mangle]
318326
pub unsafe extern "C" fn mmtk_alloc(
319327
mutator: *mut RubyMutator,

0 commit comments

Comments
 (0)