Skip to content

Commit 917a734

Browse files
committed
give up USE_GC_MALLOC_OBJ_INFO_DETAILS
This feature is no longer possible under current design; now that our GC is pluggable, we cannot assume what was achieved by this compiler flag is always possble by the dynamically-loaded GC implementation.
1 parent 9acc0ef commit 917a734

File tree

3 files changed

+7
-304
lines changed

3 files changed

+7
-304
lines changed

gc.c

+6-132
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ int ruby_gc_debug_indent = 0;
467467
#endif
468468

469469
#ifndef CALC_EXACT_MALLOC_SIZE
470-
# define CALC_EXACT_MALLOC_SIZE USE_GC_MALLOC_OBJ_INFO_DETAILS
470+
# define CALC_EXACT_MALLOC_SIZE 0
471471
#endif
472472

473473
VALUE rb_mGC;
@@ -4313,63 +4313,13 @@ rb_memerror(void)
43134313
EC_JUMP_TAG(ec, TAG_RAISE);
43144314
}
43154315

4316-
#if CALC_EXACT_MALLOC_SIZE && USE_GC_MALLOC_OBJ_INFO_DETAILS
4317-
4318-
#define MALLOC_INFO_GEN_SIZE 100
4319-
#define MALLOC_INFO_SIZE_SIZE 10
4320-
static size_t malloc_info_gen_cnt[MALLOC_INFO_GEN_SIZE];
4321-
static size_t malloc_info_gen_size[MALLOC_INFO_GEN_SIZE];
4322-
static size_t malloc_info_size[MALLOC_INFO_SIZE_SIZE+1];
4323-
static st_table *malloc_info_file_table;
4324-
4325-
static int
4326-
mmalloc_info_file_i(st_data_t key, st_data_t val, st_data_t dmy)
4327-
{
4328-
const char *file = (void *)key;
4329-
const size_t *data = (void *)val;
4330-
4331-
fprintf(stderr, "%s\t%"PRIdSIZE"\t%"PRIdSIZE"\n", file, data[0], data[1]);
4332-
4333-
return ST_CONTINUE;
4334-
}
4335-
4336-
__attribute__((destructor))
4337-
void
4338-
rb_malloc_info_show_results(void)
4339-
{
4340-
int i;
4341-
4342-
fprintf(stderr, "* malloc_info gen statistics\n");
4343-
for (i=0; i<MALLOC_INFO_GEN_SIZE; i++) {
4344-
if (i == MALLOC_INFO_GEN_SIZE-1) {
4345-
fprintf(stderr, "more\t%"PRIdSIZE"\t%"PRIdSIZE"\n", malloc_info_gen_cnt[i], malloc_info_gen_size[i]);
4346-
}
4347-
else {
4348-
fprintf(stderr, "%d\t%"PRIdSIZE"\t%"PRIdSIZE"\n", i, malloc_info_gen_cnt[i], malloc_info_gen_size[i]);
4349-
}
4350-
}
4351-
4352-
fprintf(stderr, "* malloc_info size statistics\n");
4353-
for (i=0; i<MALLOC_INFO_SIZE_SIZE; i++) {
4354-
int s = 16 << i;
4355-
fprintf(stderr, "%d\t%"PRIdSIZE"\n", s, malloc_info_size[i]);
4356-
}
4357-
fprintf(stderr, "more\t%"PRIdSIZE"\n", malloc_info_size[i]);
4358-
4359-
if (malloc_info_file_table) {
4360-
fprintf(stderr, "* malloc_info file statistics\n");
4361-
st_foreach(malloc_info_file_table, mmalloc_info_file_i, 0);
4362-
}
4363-
}
4364-
#else
43654316
void
43664317
rb_malloc_info_show_results(void)
43674318
{
43684319
}
4369-
#endif
43704320

43714321
void *
4372-
ruby_xmalloc_body(size_t size)
4322+
ruby_xmalloc(size_t size)
43734323
{
43744324
if ((ssize_t)size < 0) {
43754325
negative_size_allocation_error("too large allocation size");
@@ -4393,13 +4343,13 @@ xmalloc2_size(const size_t count, const size_t elsize)
43934343
}
43944344

43954345
void *
4396-
ruby_xmalloc2_body(size_t n, size_t size)
4346+
ruby_xmalloc2(size_t n, size_t size)
43974347
{
43984348
return rb_gc_impl_malloc(rb_gc_get_objspace(), xmalloc2_size(n, size));
43994349
}
44004350

44014351
void *
4402-
ruby_xcalloc_body(size_t n, size_t size)
4352+
ruby_xcalloc(size_t n, size_t size)
44034353
{
44044354
return rb_gc_impl_calloc(rb_gc_get_objspace(), xmalloc2_size(n, size));
44054355
}
@@ -4418,7 +4368,7 @@ ruby_sized_xrealloc(void *ptr, size_t new_size, size_t old_size)
44184368
}
44194369

44204370
void *
4421-
ruby_xrealloc_body(void *ptr, size_t new_size)
4371+
ruby_xrealloc(void *ptr, size_t new_size)
44224372
{
44234373
return ruby_sized_xrealloc(ptr, new_size, 0);
44244374
}
@@ -4434,7 +4384,7 @@ ruby_sized_xrealloc2(void *ptr, size_t n, size_t size, size_t old_n)
44344384
}
44354385

44364386
void *
4437-
ruby_xrealloc2_body(void *ptr, size_t n, size_t size)
4387+
ruby_xrealloc2(void *ptr, size_t n, size_t size)
44384388
{
44394389
return ruby_sized_xrealloc2(ptr, n, size, 0);
44404390
}
@@ -4519,11 +4469,6 @@ ruby_mimmalloc(size_t size)
45194469
{
45204470
struct malloc_obj_info *info = mem;
45214471
info->size = 0;
4522-
#if USE_GC_MALLOC_OBJ_INFO_DETAILS
4523-
info->gen = 0;
4524-
info->file = NULL;
4525-
info->line = 0;
4526-
#endif
45274472
mem = info + 1;
45284473
}
45294474
#endif
@@ -4549,11 +4494,6 @@ ruby_mimcalloc(size_t num, size_t size)
45494494
{
45504495
struct malloc_obj_info *info = mem;
45514496
info->size = 0;
4552-
#if USE_GC_MALLOC_OBJ_INFO_DETAILS
4553-
info->gen = 0;
4554-
info->file = NULL;
4555-
info->line = 0;
4556-
#endif
45574497
mem = info + 1;
45584498
}
45594499
#else
@@ -4673,69 +4613,3 @@ Init_GC(void)
46734613

46744614
rb_gc_impl_init();
46754615
}
4676-
4677-
#ifdef ruby_xmalloc
4678-
#undef ruby_xmalloc
4679-
#endif
4680-
#ifdef ruby_xmalloc2
4681-
#undef ruby_xmalloc2
4682-
#endif
4683-
#ifdef ruby_xcalloc
4684-
#undef ruby_xcalloc
4685-
#endif
4686-
#ifdef ruby_xrealloc
4687-
#undef ruby_xrealloc
4688-
#endif
4689-
#ifdef ruby_xrealloc2
4690-
#undef ruby_xrealloc2
4691-
#endif
4692-
4693-
void *
4694-
ruby_xmalloc(size_t size)
4695-
{
4696-
#if USE_GC_MALLOC_OBJ_INFO_DETAILS
4697-
ruby_malloc_info_file = __FILE__;
4698-
ruby_malloc_info_line = __LINE__;
4699-
#endif
4700-
return ruby_xmalloc_body(size);
4701-
}
4702-
4703-
void *
4704-
ruby_xmalloc2(size_t n, size_t size)
4705-
{
4706-
#if USE_GC_MALLOC_OBJ_INFO_DETAILS
4707-
ruby_malloc_info_file = __FILE__;
4708-
ruby_malloc_info_line = __LINE__;
4709-
#endif
4710-
return ruby_xmalloc2_body(n, size);
4711-
}
4712-
4713-
void *
4714-
ruby_xcalloc(size_t n, size_t size)
4715-
{
4716-
#if USE_GC_MALLOC_OBJ_INFO_DETAILS
4717-
ruby_malloc_info_file = __FILE__;
4718-
ruby_malloc_info_line = __LINE__;
4719-
#endif
4720-
return ruby_xcalloc_body(n, size);
4721-
}
4722-
4723-
void *
4724-
ruby_xrealloc(void *ptr, size_t new_size)
4725-
{
4726-
#if USE_GC_MALLOC_OBJ_INFO_DETAILS
4727-
ruby_malloc_info_file = __FILE__;
4728-
ruby_malloc_info_line = __LINE__;
4729-
#endif
4730-
return ruby_xrealloc_body(ptr, new_size);
4731-
}
4732-
4733-
void *
4734-
ruby_xrealloc2(void *ptr, size_t n, size_t new_size)
4735-
{
4736-
#if USE_GC_MALLOC_OBJ_INFO_DETAILS
4737-
ruby_malloc_info_file = __FILE__;
4738-
ruby_malloc_info_line = __LINE__;
4739-
#endif
4740-
return ruby_xrealloc2_body(ptr, n, new_size);
4741-
}

gc/default.c

+1-68
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ int ruby_rgengc_debug;
319319
# define GC_ENABLE_LAZY_SWEEP 1
320320
#endif
321321
#ifndef CALC_EXACT_MALLOC_SIZE
322-
# define CALC_EXACT_MALLOC_SIZE USE_GC_MALLOC_OBJ_INFO_DETAILS
322+
# define CALC_EXACT_MALLOC_SIZE 0
323323
#endif
324324
#if defined(HAVE_MALLOC_USABLE_SIZE) || CALC_EXACT_MALLOC_SIZE > 0
325325
# ifndef MALLOC_ALLOCATED_SIZE
@@ -8360,18 +8360,8 @@ objspace_malloc_increase_body(rb_objspace_t *objspace, void *mem, size_t new_siz
83608360

83618361
struct malloc_obj_info { /* 4 words */
83628362
size_t size;
8363-
#if USE_GC_MALLOC_OBJ_INFO_DETAILS
8364-
size_t gen;
8365-
const char *file;
8366-
size_t line;
8367-
#endif
83688363
};
83698364

8370-
#if USE_GC_MALLOC_OBJ_INFO_DETAILS
8371-
const char *ruby_malloc_info_file;
8372-
int ruby_malloc_info_line;
8373-
#endif
8374-
83758365
static inline size_t
83768366
objspace_malloc_prepare(rb_objspace_t *objspace, size_t size)
83778367
{
@@ -8404,11 +8394,6 @@ objspace_malloc_fixup(rb_objspace_t *objspace, void *mem, size_t size)
84048394
{
84058395
struct malloc_obj_info *info = mem;
84068396
info->size = size;
8407-
#if USE_GC_MALLOC_OBJ_INFO_DETAILS
8408-
info->gen = objspace->profile.count;
8409-
info->file = ruby_malloc_info_file;
8410-
info->line = info->file ? ruby_malloc_info_line : 0;
8411-
#endif
84128397
mem = info + 1;
84138398
}
84148399
#endif
@@ -8478,58 +8463,6 @@ rb_gc_impl_free(void *objspace_ptr, void *ptr, size_t old_size)
84788463
struct malloc_obj_info *info = (struct malloc_obj_info *)ptr - 1;
84798464
ptr = info;
84808465
old_size = info->size;
8481-
8482-
#if USE_GC_MALLOC_OBJ_INFO_DETAILS
8483-
{
8484-
int gen = (int)(objspace->profile.count - info->gen);
8485-
int gen_index = gen >= MALLOC_INFO_GEN_SIZE ? MALLOC_INFO_GEN_SIZE-1 : gen;
8486-
int i;
8487-
8488-
malloc_info_gen_cnt[gen_index]++;
8489-
malloc_info_gen_size[gen_index] += info->size;
8490-
8491-
for (i=0; i<MALLOC_INFO_SIZE_SIZE; i++) {
8492-
size_t s = 16 << i;
8493-
if (info->size <= s) {
8494-
malloc_info_size[i]++;
8495-
goto found;
8496-
}
8497-
}
8498-
malloc_info_size[i]++;
8499-
found:;
8500-
8501-
{
8502-
st_data_t key = (st_data_t)info->file, d;
8503-
size_t *data;
8504-
8505-
if (malloc_info_file_table == NULL) {
8506-
malloc_info_file_table = st_init_numtable_with_size(1024);
8507-
}
8508-
if (st_lookup(malloc_info_file_table, key, &d)) {
8509-
/* hit */
8510-
data = (size_t *)d;
8511-
}
8512-
else {
8513-
data = malloc(xmalloc2_size(2, sizeof(size_t)));
8514-
if (data == NULL) rb_bug("objspace_xfree: can not allocate memory");
8515-
data[0] = data[1] = 0;
8516-
st_insert(malloc_info_file_table, key, (st_data_t)data);
8517-
}
8518-
data[0] ++;
8519-
data[1] += info->size;
8520-
};
8521-
if (0 && gen >= 2) { /* verbose output */
8522-
if (info->file) {
8523-
fprintf(stderr, "free - size:%"PRIdSIZE", gen:%d, pos: %s:%"PRIdSIZE"\n",
8524-
info->size, gen, info->file, info->line);
8525-
}
8526-
else {
8527-
fprintf(stderr, "free - size:%"PRIdSIZE", gen:%d\n",
8528-
info->size, gen);
8529-
}
8530-
}
8531-
}
8532-
#endif
85338466
#endif
85348467
old_size = objspace_malloc_size(objspace, ptr, old_size);
85358468

0 commit comments

Comments
 (0)