mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
Changed the object_count so that it only iterates over the RBasic object, not the full RVALUE known by the GC
This commit is contained in:
+2
-31
@@ -12,38 +12,9 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
#include "mruby.h"
|
||||
#include "mruby/array.h"
|
||||
#include "mruby/class.h"
|
||||
#include "mruby/data.h"
|
||||
#include "mruby/hash.h"
|
||||
#include "mruby/proc.h"
|
||||
#include "mruby/range.h"
|
||||
#include "mruby/string.h"
|
||||
#include "mruby/variable.h"
|
||||
#include "mruby/value.h"
|
||||
|
||||
struct free_obj {
|
||||
MRB_OBJECT_HEADER;
|
||||
struct RBasic *next;
|
||||
};
|
||||
|
||||
struct RVALUE {
|
||||
union {
|
||||
struct free_obj free;
|
||||
struct RBasic basic;
|
||||
struct RObject object;
|
||||
struct RClass klass;
|
||||
struct RString string;
|
||||
struct RArray array;
|
||||
struct RHash hash;
|
||||
struct RRange range;
|
||||
struct RData data;
|
||||
struct RProc proc;
|
||||
} as;
|
||||
};
|
||||
|
||||
typedef struct RVALUE RVALUE;
|
||||
|
||||
typedef int each_object_callback(RVALUE *obj, void *data);
|
||||
typedef int each_object_callback(mrb_state *mrb, struct RBasic obj, void *data);
|
||||
void mrb_objspace_each_objects(mrb_state *mrb, each_object_callback* callback, void *data);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include <mruby.h>
|
||||
#include <mruby/gc.h>
|
||||
#include <mruby/hash.h>
|
||||
#include <stdio.h>
|
||||
#include <mruby/value.h>
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
@@ -25,22 +27,30 @@
|
||||
|
||||
struct os_count_struct {
|
||||
size_t total;
|
||||
size_t freed;
|
||||
size_t counts[MRB_TT_MAXDEFINE+1];
|
||||
};
|
||||
|
||||
void os_count_object_type(RVALUE *obj, void *data)
|
||||
void os_count_object_type(mrb_state *mrb, struct RBasic obj, void *data)
|
||||
{
|
||||
struct os_count_struct* obj_count;
|
||||
obj_count = (struct os_count_struct*)(data);
|
||||
obj_count->counts[mrb_type(obj->as.basic)]++;
|
||||
obj_count->total++;
|
||||
obj_count->counts[mrb_type(obj)]++;
|
||||
if (is_dead(mrb, &obj))
|
||||
{
|
||||
obj_count->freed++;
|
||||
}
|
||||
else
|
||||
{
|
||||
obj_count->total++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
mrb_value
|
||||
os_count_objects(mrb_state *mrb, mrb_value self)
|
||||
{
|
||||
struct os_count_struct obj_count;
|
||||
size_t freed = 0;
|
||||
size_t i;
|
||||
mrb_value hash;
|
||||
struct heap_page* page = mrb->heaps;
|
||||
@@ -56,11 +66,13 @@ os_count_objects(mrb_state *mrb, mrb_value self)
|
||||
for (i = 0; i <= MRB_TT_MAXDEFINE; i++) {
|
||||
obj_count.counts[i] = 0;
|
||||
}
|
||||
obj_count.total = 0;
|
||||
obj_count.freed = 0;
|
||||
|
||||
mrb_objspace_each_objects(mrb, os_count_object_type, &obj_count);
|
||||
|
||||
mrb_hash_set(mrb, hash, mrb_symbol_value(mrb_intern_cstr(mrb, "TOTAL")), mrb_fixnum_value(obj_count.total));
|
||||
mrb_hash_set(mrb, hash, mrb_symbol_value(mrb_intern_cstr(mrb, "FREE")), mrb_fixnum_value(freed));
|
||||
mrb_hash_set(mrb, hash, mrb_symbol_value(mrb_intern_cstr(mrb, "FREE")), mrb_fixnum_value(obj_count.freed));
|
||||
|
||||
for (i = 0; i < MRB_TT_MAXDEFINE; i++) {
|
||||
mrb_value type;
|
||||
|
||||
@@ -5,6 +5,11 @@ assert('ObjectSpace.count_objects') do
|
||||
assert_true(h.keys.all? {|x| x.is_a?(Symbol) || x.is_a?(Integer) })
|
||||
assert_true(h.values.all? {|x| x.is_a?(Integer) })
|
||||
|
||||
assert_true(h.has_key?(:TOTAL))
|
||||
assert_true(h.has_key?(:FREE))
|
||||
|
||||
p h.inspect
|
||||
|
||||
h = ObjectSpace.count_objects
|
||||
assert_kind_of(Hash, h)
|
||||
assert_true(h.keys.all? {|x| x.is_a?(Symbol) || x.is_a?(Integer) })
|
||||
@@ -12,6 +17,8 @@ assert('ObjectSpace.count_objects') do
|
||||
|
||||
assert_raise(TypeError) { ObjectSpace.count_objects(1) }
|
||||
|
||||
p h.inspect
|
||||
|
||||
h0 = {:MRB_TT_FOO=>1000}
|
||||
h = ObjectSpace.count_objects(h0)
|
||||
assert_false(h0.has_key?(:MRB_TT_FOO))
|
||||
@@ -31,4 +38,8 @@ assert('ObjectSpace.count_objects') do
|
||||
|
||||
assert_equal(h_before[:MRB_TT_HASH] + 1000, h[:MRB_TT_HASH])
|
||||
assert_equal(h_before[:MRB_TT_HASH], h_after[:MRB_TT_HASH])
|
||||
|
||||
p h.inspect
|
||||
p h_after.inspect
|
||||
|
||||
end
|
||||
@@ -73,6 +73,26 @@
|
||||
|
||||
*/
|
||||
|
||||
struct free_obj {
|
||||
MRB_OBJECT_HEADER;
|
||||
struct RBasic *next;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
union {
|
||||
struct free_obj free;
|
||||
struct RBasic basic;
|
||||
struct RObject object;
|
||||
struct RClass klass;
|
||||
struct RString string;
|
||||
struct RArray array;
|
||||
struct RHash hash;
|
||||
struct RRange range;
|
||||
struct RData data;
|
||||
struct RProc proc;
|
||||
} as;
|
||||
} RVALUE;
|
||||
|
||||
#ifdef GC_PROFILE
|
||||
#include <stdio.h>
|
||||
#include <sys/time.h>
|
||||
@@ -1133,7 +1153,7 @@ mrb_objspace_each_objects(mrb_state *mrb, each_object_callback* callback, void *
|
||||
p = page->objects;
|
||||
pend = p + MRB_HEAP_PAGE_SIZE;
|
||||
for (;p < pend; p++) {
|
||||
callback(p, data);
|
||||
callback(mrb, p->as.basic, data);
|
||||
}
|
||||
|
||||
page = page->next;
|
||||
|
||||
Reference in New Issue
Block a user