Skip to content

Commit 947699b

Browse files
committed
refactor gc to only need to allocate virtual addresses on demand
1 parent 003a14f commit 947699b

File tree

4 files changed

+393
-215
lines changed

4 files changed

+393
-215
lines changed

src/gc-debug.c

Lines changed: 38 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,33 +20,26 @@ jl_gc_pagemeta_t *jl_gc_page_metadata(void *data)
2020
return page_metadata(data);
2121
}
2222

23-
region_t *jl_gc_find_region(void *ptr)
24-
{
25-
return find_region(ptr);
26-
}
27-
2823
// Find the memory block in the pool that owns the byte pointed to by p.
2924
// For end of object pointer (which is always the case for pointer to a
3025
// singleton object), this usually returns the same pointer which points to
3126
// the next object but it can also return NULL if the pointer is pointing to
3227
// the end of the page.
3328
JL_DLLEXPORT jl_taggedvalue_t *jl_gc_find_taggedvalue_pool(char *p, size_t *osize_p)
3429
{
35-
region_t *r = find_region(p);
36-
// Not in the pool
37-
if (!r)
30+
if (!page_metadata(p))
31+
// Not in the pool
3832
return NULL;
33+
struct jl_gc_metadata_ext info = page_metadata_ext(p);
3934
char *page_begin = gc_page_data(p) + GC_PAGE_OFFSET;
4035
// In the page header
4136
if (p < page_begin)
4237
return NULL;
4338
size_t ofs = p - page_begin;
44-
int pg_idx = page_index(r, page_begin);
4539
// Check if this is a free page
46-
if (!(r->allocmap[pg_idx / 32] & (uint32_t)(1 << (pg_idx % 32))))
40+
if (!(info.region0->allocmap[info.region0_i32 / 32] & (uint32_t)(1 << info.region0_i)))
4741
return NULL;
48-
jl_gc_pagemeta_t *pagemeta = &r->meta[pg_idx];
49-
int osize = pagemeta->osize;
42+
int osize = info.meta->osize;
5043
// Shouldn't be needed, just in case
5144
if (osize == 0)
5245
return NULL;
@@ -1016,14 +1009,42 @@ static void gc_count_pool_page(jl_gc_pagemeta_t *pg)
10161009
}
10171010
}
10181011

1019-
static void gc_count_pool_region(region_t *region)
1012+
static void gc_count_pool_region0(region0_t *region0)
1013+
{
1014+
for (int pg_i = 0; pg_i < REGION0_PG_COUNT / 32; pg_i++) {
1015+
uint32_t line = region0->allocmap[pg_i];
1016+
if (line) {
1017+
for (int j = 0; j < 32; j++) {
1018+
if ((line >> j) & 1) {
1019+
gc_count_pool_page(region0->meta[pg_i * 32 + j]);
1020+
}
1021+
}
1022+
}
1023+
}
1024+
}
1025+
1026+
static void gc_count_pool_region1(region1_t *region1)
10201027
{
1021-
for (int pg_i = 0; pg_i < region->pg_cnt / 32; pg_i++) {
1022-
uint32_t line = region->allocmap[pg_i];
1028+
for (int pg_i = 0; pg_i < REGION1_PG_COUNT / 32; pg_i++) {
1029+
uint32_t line = region1->allocmap0[pg_i];
10231030
if (line) {
10241031
for (int j = 0; j < 32; j++) {
10251032
if ((line >> j) & 1) {
1026-
gc_count_pool_page(&region->meta[pg_i*32 + j]);
1033+
gc_count_pool_region0(region1->meta0[pg_i * 32 + j]);
1034+
}
1035+
}
1036+
}
1037+
}
1038+
}
1039+
1040+
static void gc_count_pool_regions(void)
1041+
{
1042+
for (int pg_i = 0; pg_i < (REGION2_PG_COUNT + 31) / 32; pg_i++) {
1043+
uint32_t line = memory_map.allocmap1[pg_i];
1044+
if (line) {
1045+
for (int j = 0; j < 32; j++) {
1046+
if ((line >> j) & 1) {
1047+
gc_count_pool_region1(memory_map.meta1[pg_i * 32 + j]);
10271048
}
10281049
}
10291050
}
@@ -1034,11 +1055,7 @@ void gc_count_pool(void)
10341055
{
10351056
memset(&poolobj_sizes, 0, sizeof(poolobj_sizes));
10361057
empty_pages = 0;
1037-
for (int i = 0; i < REGION_COUNT; i++) {
1038-
if (!regions[i].pages)
1039-
break;
1040-
gc_count_pool_region(&regions[i]);
1041-
}
1058+
gc_count_pool_regions();
10421059
jl_safe_printf("****** Pool stat: ******\n");
10431060
for (int i = 0;i < 4;i++)
10441061
jl_safe_printf("bits(%d): %" PRId64 "\n", i, poolobj_sizes[i]);

0 commit comments

Comments
 (0)