* include/ruby/ruby.h (SIZET2NUM): new macro.

(NUM2SIZET): new macro.

* gc.c (struct rb_objspace): use size_t for increment, length and
  used for 64bit.
  (allocate_heaps): ditto.
  (assign_heap_slot): ditto.
  (set_heaps_increment): ditto.
  (gc_mark_all): ditto.
  (is_pointer_to_heap): ditto.
  (free_unused_heaps): ditto.
  (gc_sweep): ditto.
  (os_obj_of): ditto.
  (rb_gc_call_finalizer_at_exit): ditto.
  (count_objects): ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@16356 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2008-05-11 05:44:36 +00:00
parent 14a97fd48a
commit e389ce0676
3 changed files with 64 additions and 31 deletions

View File

@ -1,3 +1,21 @@
Sun May 11 14:40:36 2008 Tanaka Akira <akr@fsij.org>
* include/ruby/ruby.h (SIZET2NUM): new macro.
(NUM2SIZET): new macro.
* gc.c (struct rb_objspace): use size_t for increment, length and
used for 64bit.
(allocate_heaps): ditto.
(assign_heap_slot): ditto.
(set_heaps_increment): ditto.
(gc_mark_all): ditto.
(is_pointer_to_heap): ditto.
(free_unused_heaps): ditto.
(gc_sweep): ditto.
(os_obj_of): ditto.
(rb_gc_call_finalizer_at_exit): ditto.
(count_objects): ditto.
Sun May 11 13:14:09 2008 Tanaka Akira <akr@fsij.org> Sun May 11 13:14:09 2008 Tanaka Akira <akr@fsij.org>
* thread.c (thread_cleanup_func_before_exec): extracted from * thread.c (thread_cleanup_func_before_exec): extracted from

63
gc.c
View File

@ -149,10 +149,10 @@ typedef struct rb_objspace {
unsigned long increase; unsigned long increase;
} params; } params;
struct { struct {
long increment; size_t increment;
struct heaps_slot *ptr; struct heaps_slot *ptr;
long length; size_t length;
long used; size_t used;
RVALUE *freelist; RVALUE *freelist;
RVALUE *range[2]; RVALUE *range[2];
RVALUE *freed; RVALUE *freed;
@ -517,30 +517,30 @@ rb_gc_unregister_address(VALUE *addr)
static void static void
allocate_heaps(rb_objspace_t *objspace, int next_heaps_length) allocate_heaps(rb_objspace_t *objspace, size_t next_heaps_length)
{ {
struct heaps_slot *p; struct heaps_slot *p;
int length; size_t size;
heaps_length = next_heaps_length; size = next_heaps_length*sizeof(struct heaps_slot);
length = heaps_length*sizeof(struct heaps_slot);
RUBY_CRITICAL( RUBY_CRITICAL(
if (heaps_used > 0) { if (heaps_used > 0) {
p = (struct heaps_slot *)realloc(heaps, length); p = (struct heaps_slot *)realloc(heaps, size);
if (p) heaps = p; if (p) heaps = p;
} }
else { else {
p = heaps = (struct heaps_slot *)malloc(length); p = heaps = (struct heaps_slot *)malloc(size);
} }
); );
if (p == 0) rb_memerror(); if (p == 0) rb_memerror();
heaps_length = next_heaps_length;
} }
static void static void
assign_heap_slot(rb_objspace_t *objspace) assign_heap_slot(rb_objspace_t *objspace)
{ {
RVALUE *p, *pend, *membase; RVALUE *p, *pend, *membase;
long hi, lo, mid; size_t hi, lo, mid;
int objs; int objs;
objs = HEAP_OBJ_LIMIT; objs = HEAP_OBJ_LIMIT;
@ -596,7 +596,7 @@ assign_heap_slot(rb_objspace_t *objspace)
static void static void
init_heap(rb_objspace_t *objspace) init_heap(rb_objspace_t *objspace)
{ {
int add, i; size_t add, i;
add = HEAP_MIN_SLOTS / HEAP_OBJ_LIMIT; add = HEAP_MIN_SLOTS / HEAP_OBJ_LIMIT;
@ -614,10 +614,11 @@ init_heap(rb_objspace_t *objspace)
static void static void
set_heaps_increment(rb_objspace_t *objspace) set_heaps_increment(rb_objspace_t *objspace)
{ {
heaps_inc = heaps_used * 1.8 - heaps_used; size_t next_heaps_length = heaps_used * 1.8;
heaps_inc = next_heaps_length - heaps_used;
if ((heaps_used + heaps_inc) > heaps_length) { if (next_heaps_length > heaps_length) {
allocate_heaps(objspace, heaps_used + heaps_inc); allocate_heaps(objspace, next_heaps_length);
} }
} }
@ -818,7 +819,7 @@ static void
gc_mark_all(rb_objspace_t *objspace) gc_mark_all(rb_objspace_t *objspace)
{ {
RVALUE *p, *pend; RVALUE *p, *pend;
int i; size_t i;
init_mark_stack(objspace); init_mark_stack(objspace);
for (i = 0; i < heaps_used; i++) { for (i = 0; i < heaps_used; i++) {
@ -854,7 +855,7 @@ is_pointer_to_heap(rb_objspace_t *objspace, void *ptr)
{ {
register RVALUE *p = RANY(ptr); register RVALUE *p = RANY(ptr);
register struct heaps_slot *heap; register struct heaps_slot *heap;
register long hi, lo, mid; register size_t hi, lo, mid;
if (p < lomem || p > himem) return Qfalse; if (p < lomem || p > himem) return Qfalse;
if ((VALUE)p % sizeof(RVALUE) != 0) return Qfalse; if ((VALUE)p % sizeof(RVALUE) != 0) return Qfalse;
@ -1317,7 +1318,7 @@ finalize_list(rb_objspace_t *objspace, RVALUE *p)
static void static void
free_unused_heaps(rb_objspace_t *objspace) free_unused_heaps(rb_objspace_t *objspace)
{ {
int i, j; size_t i, j;
RVALUE *last = 0; RVALUE *last = 0;
for (i = j = 1; j < heaps_used; i++) { for (i = j = 1; j < heaps_used; i++) {
@ -1354,9 +1355,9 @@ static void
gc_sweep(rb_objspace_t *objspace) gc_sweep(rb_objspace_t *objspace)
{ {
RVALUE *p, *pend, *final_list; RVALUE *p, *pend, *final_list;
int freed = 0; size_t freed = 0;
int i; size_t i;
unsigned long live = 0, free_min = 0, do_heap_free = 0; size_t live = 0, free_min = 0, do_heap_free = 0;
do_heap_free = (heaps_used * HEAP_OBJ_LIMIT) * 0.65; do_heap_free = (heaps_used * HEAP_OBJ_LIMIT) * 0.65;
free_min = (heaps_used * HEAP_OBJ_LIMIT) * 0.2; free_min = (heaps_used * HEAP_OBJ_LIMIT) * 0.2;
@ -1865,8 +1866,8 @@ Init_heap(void)
static VALUE static VALUE
os_obj_of(rb_objspace_t *objspace, VALUE of) os_obj_of(rb_objspace_t *objspace, VALUE of)
{ {
int i; size_t i;
int n = 0; size_t n = 0;
for (i = 0; i < heaps_used; i++) { for (i = 0; i < heaps_used; i++) {
RVALUE *p, *pend; RVALUE *p, *pend;
@ -1893,7 +1894,7 @@ os_obj_of(rb_objspace_t *objspace, VALUE of)
} }
} }
return INT2FIX(n); return SIZET2NUM(n);
} }
/* /*
@ -2075,7 +2076,7 @@ rb_gc_call_finalizer_at_exit(void)
{ {
rb_objspace_t *objspace = &rb_objspace; rb_objspace_t *objspace = &rb_objspace;
RVALUE *p, *pend; RVALUE *p, *pend;
int i; size_t i;
/* finalizers are part of garbage collection */ /* finalizers are part of garbage collection */
during_gc++; during_gc++;
@ -2275,10 +2276,10 @@ static VALUE
count_objects(int argc, VALUE *argv, VALUE os) count_objects(int argc, VALUE *argv, VALUE os)
{ {
rb_objspace_t *objspace = &rb_objspace; rb_objspace_t *objspace = &rb_objspace;
long counts[T_MASK+1]; size_t counts[T_MASK+1];
long freed = 0; size_t freed = 0;
long total = 0; size_t total = 0;
int i; size_t i;
VALUE hash; VALUE hash;
if (rb_scan_args(argc, argv, "01", &hash) == 1) { if (rb_scan_args(argc, argv, "01", &hash) == 1) {
@ -2307,8 +2308,8 @@ count_objects(int argc, VALUE *argv, VALUE os)
if (hash == Qnil) if (hash == Qnil)
hash = rb_hash_new(); hash = rb_hash_new();
rb_hash_aset(hash, ID2SYM(rb_intern("TOTAL")), LONG2NUM(total)); rb_hash_aset(hash, ID2SYM(rb_intern("TOTAL")), SIZET2NUM(total));
rb_hash_aset(hash, ID2SYM(rb_intern("FREE")), LONG2NUM(freed)); rb_hash_aset(hash, ID2SYM(rb_intern("FREE")), SIZET2NUM(freed));
for (i = 0; i <= T_MASK; i++) { for (i = 0; i <= T_MASK; i++) {
VALUE type; VALUE type;
switch (i) { switch (i) {
@ -2342,7 +2343,7 @@ count_objects(int argc, VALUE *argv, VALUE os)
default: type = INT2NUM(i); break; default: type = INT2NUM(i); break;
} }
if (counts[i]) if (counts[i])
rb_hash_aset(hash, type, LONG2NUM(counts[i])); rb_hash_aset(hash, type, SIZET2NUM(counts[i]));
} }
return hash; return hash;

View File

@ -171,6 +171,14 @@ VALUE rb_ull2inum(unsigned LONG_LONG);
# define OFFT2NUM(v) INT2NUM(v) # define OFFT2NUM(v) INT2NUM(v)
#endif #endif
#if SIZEOF_SIZE_T > SIZEOF_LONG && defined(HAVE_LONG_LONG)
# define SIZET2NUM(v) ULL2NUM(v)
#elif SIZEOF_SIZE_T == SIZEOF_LONG
# define SIZET2NUM(v) ULONG2NUM(v)
#else
# define SIZET2NUM(v) UINT2NUM(v)
#endif
#ifndef PIDT2NUM #ifndef PIDT2NUM
#define PIDT2NUM(v) LONG2NUM(v) #define PIDT2NUM(v) LONG2NUM(v)
#endif #endif
@ -364,6 +372,12 @@ unsigned LONG_LONG rb_num2ull(VALUE);
# define NUM2OFFT(x) NUM2LONG(x) # define NUM2OFFT(x) NUM2LONG(x)
#endif #endif
#if defined(HAVE_LONG_LONG) && SIZEOF_SIZE_T > SIZEOF_LONG
# define NUM2SIZET(x) ((size_t)NUM2ULL(x))
#else
# define NUM2SIZET(x) NUM2ULONG(x)
#endif
double rb_num2dbl(VALUE); double rb_num2dbl(VALUE);
#define NUM2DBL(x) rb_num2dbl((VALUE)(x)) #define NUM2DBL(x) rb_num2dbl((VALUE)(x))