ruby-changes:35539
From: nobu <ko1@a...>
Date: Thu, 18 Sep 2014 09:36:44 +0900 (JST)
Subject: [ruby-changes:35539] nobu:r47621 (trunk): vm_method.c: configurable global method cache size
nobu 2014-09-18 09:36:37 +0900 (Thu, 18 Sep 2014) New Revision: 47621 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=47621 Log: vm_method.c: configurable global method cache size * vm_method.c (Init_Method): make global method cache size configurable by environment variable "RUBY_GLOBAL_METHOD_CACHE_SIZE" [Fix GH-719] Modified files: trunk/ChangeLog trunk/inits.c trunk/vm_method.c Index: ChangeLog =================================================================== --- ChangeLog (revision 47620) +++ ChangeLog (revision 47621) @@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Thu Sep 18 09:36:37 2014 Scott Francis <scott.francis@s...> + + * vm_method.c (Init_Method): make global method cache size + configurable by environment variable + "RUBY_GLOBAL_METHOD_CACHE_SIZE" [Fix GH-719] + Thu Sep 18 07:03:36 2014 Eric Wong <e@8...> * test/-ext-/string/test_modify_expand.rb: increase limit Index: vm_method.c =================================================================== --- vm_method.c (revision 47620) +++ vm_method.c (revision 47621) @@ -15,8 +15,8 @@ https://github.com/ruby/ruby/blob/trunk/vm_method.c#L15 #define GLOBAL_METHOD_CACHE_MASK (GLOBAL_METHOD_CACHE_SIZE-1) #endif -#define GLOBAL_METHOD_CACHE_KEY(c,m) ((((c)>>3)^(m))&GLOBAL_METHOD_CACHE_MASK) -#define GLOBAL_METHOD_CACHE(c,m) (global_method_cache + GLOBAL_METHOD_CACHE_KEY(c,m)) +#define GLOBAL_METHOD_CACHE_KEY(c,m) ((((c)>>3)^(m))&(global_method_cache.mask)) +#define GLOBAL_METHOD_CACHE(c,m) (global_method_cache.entries + GLOBAL_METHOD_CACHE_KEY(c,m)) #else #define GLOBAL_METHOD_CACHE(c,m) (rb_bug("global method cache disabled improperly"), NULL) #endif @@ -47,7 +47,14 @@ struct cache_entry { https://github.com/ruby/ruby/blob/trunk/vm_method.c#L47 }; #if OPT_GLOBAL_METHOD_CACHE -static struct cache_entry global_method_cache[GLOBAL_METHOD_CACHE_SIZE]; +static struct { + unsigned int size; + unsigned int mask; + struct cache_entry *entries; +} global_method_cache = { + GLOBAL_METHOD_CACHE_SIZE, + GLOBAL_METHOD_CACHE_MASK, +}; #endif #define ruby_running (GET_VM()->running) @@ -1726,6 +1733,31 @@ obj_respond_to_missing(VALUE obj, VALUE https://github.com/ruby/ruby/blob/trunk/vm_method.c#L1733 } void +Init_Method(void) +{ +#if OPT_GLOBAL_METHOD_CACHE + char *ptr = getenv("RUBY_GLOBAL_METHOD_CACHE_SIZE"); + int val; + + if (ptr != NULL && (val = atoi(ptr)) > 0) { + if ((val & (val - 1)) == 0) { /* ensure val is a power of 2 */ + global_method_cache.size = val; + global_method_cache.mask = val - 1; + } + else { + fprintf(stderr, "RUBY_GLOBAL_METHOD_CACHE_SIZE was set to %d but ignored because the value is not a power of 2.\n", val); + } + } + + global_method_cache.entries = (struct cache_entry *)calloc(global_method_cache.size, sizeof(struct cache_entry)); + if (global_method_cache.entries == NULL) { + fprintf(stderr, "[FATAL] failed to allocate memory\n"); + exit(EXIT_FAILURE); + } +#endif +} + +void Init_eval_method(void) { #undef rb_intern Index: inits.c =================================================================== --- inits.c (revision 47620) +++ inits.c (revision 47621) @@ -17,6 +17,7 @@ https://github.com/ruby/ruby/blob/trunk/inits.c#L17 void rb_call_inits(void) { + CALL(Method); CALL(RandomSeed); CALL(sym); CALL(var_tables); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/