Permalink
Browse files

Add very basic stat and debug options for method cache resets

  • Loading branch information...
1 parent de3776b commit d577a2cf52c1859dfa386ae8adf9e15b3de10064 @dbussink dbussink committed Jan 4, 2013
@@ -161,6 +161,9 @@
c.vm_variable "ic.stats", false,
"Print out stats about the InlineCaches before exiting"
+ c.vm_variable "ic.debug", false,
+ "Print out when inline caches are reset"
+
c.vm_variable "allocation_tracking", false,
"Enable allocation tracking for new objects"
View
@@ -526,6 +526,7 @@ namespace agent {
state->memory()->gc_stats.last_full_collection_time));
Tree* jit = system_->get_tree("jit");
+ jit->add(new ReadAtomicInteger("cache_resets", state->shared().stats.methods_cache_resets));
jit->add(new ReadAtomicInteger("methods", state->shared().stats.jitted_methods));
jit->add(new ReadAtomicInteger("time", state->shared().stats.jit_time_spent));
@@ -303,6 +303,12 @@ namespace rubinius {
return name_->to_str(state);
}
+ bool CompiledCode::kernel_method(STATE) {
+ std::string s = file()->cpp_str(state);
+ if(s.size() >= 7 && strncmp(s.data(), "kernel/", 7) == 0) return true;
+ return false;
+ }
+
void CompiledCode::set_interpreter(executor interp) {
set_executor(interp);
machine_code_->fallback = interp;
@@ -121,6 +121,8 @@ namespace rubinius {
String* full_name(STATE);
+ bool kernel_method(STATE);
+
void set_interpreter(executor interp);
class Info : public Executable::Info {
View
@@ -123,12 +123,6 @@ namespace rubinius {
return bt;
}
- static bool kernel_method(STATE, CompiledCode* code) {
- std::string s = code->file()->cpp_str(state);
- if(s.size() >= 7 && strncmp(s.data(), "kernel/", 7) == 0) return true;
- return false;
- }
-
Array* Location::mri_backtrace(STATE, CallFrame* call_frame) {
size_t count = 0;
@@ -143,7 +137,7 @@ namespace rubinius {
while(call_frame) {
// Ignore synthetic frames
if(call_frame->compiled_code &&
- !kernel_method(state, call_frame->compiled_code)) {
+ !call_frame->compiled_code->kernel_method(state)) {
Symbol* name;
Object* block = cFalse;
Fixnum* line = Fixnum::from(call_frame->line(state));
View
@@ -590,11 +590,19 @@ namespace rubinius {
return ary;
}
- Object* System::vm_reset_method_cache(STATE, Symbol* name) {
+ Object* System::vm_reset_method_cache(STATE, Symbol* name, CallFrame* calling_environment) {
// 1. clear the global cache
state->vm()->global_cache()->clear(state, name);
state->shared().ic_registry()->clear(state, name);
+ state->shared().stats.methods_cache_resets++;
+
+ if(state->shared().config.ic_debug) {
+ std::cout << "[IC Reset method cache for " << name->debug_str(state).c_str() << "]" << std::endl;
+ CallFrame* call_frame = calling_environment->previous;
+ call_frame->print_backtrace(state, 6, true);
+ }
+
return name;
}
@@ -948,7 +956,8 @@ namespace rubinius {
Object* System::vm_add_method(STATE, GCToken gct, Symbol* name,
CompiledCode* method,
- ConstantScope* scope, Object* vis)
+ ConstantScope* scope, Object* vis,
+ CallFrame* calling_environment)
{
Module* mod = scope->for_method_definition();
@@ -1000,14 +1009,15 @@ namespace rubinius {
}
}
- vm_reset_method_cache(state, name);
+ vm_reset_method_cache(state, name, calling_environment);
return method;
}
Object* System::vm_attach_method(STATE, GCToken gct, Symbol* name,
CompiledCode* method,
- ConstantScope* scope, Object* recv)
+ ConstantScope* scope, Object* recv,
+ CallFrame* calling_environment)
{
Module* mod = recv->singleton_class(state);
@@ -1018,7 +1028,7 @@ namespace rubinius {
mod->add_method(state, gct, name, method);
- vm_reset_method_cache(state, name);
+ vm_reset_method_cache(state, name, calling_environment);
return method;
}
View
@@ -135,7 +135,7 @@ namespace rubinius {
* will be picked up from calls.
*/
// Rubinius.primitive :vm_reset_method_cache
- static Object* vm_reset_method_cache(STATE, Symbol* name);
+ static Object* vm_reset_method_cache(STATE, Symbol* name, CallFrame* calling_environment);
/**
* Backtrace as an Array.
@@ -215,10 +215,10 @@ namespace rubinius {
static Tuple* vm_find_public_method(STATE, Object* recv, Symbol* name);
// Rubinius.primitive :vm_add_method
- static Object* vm_add_method(STATE, GCToken gct, Symbol* name, CompiledCode* meth, ConstantScope* scope, Object* vis);
+ static Object* vm_add_method(STATE, GCToken gct, Symbol* name, CompiledCode* meth, ConstantScope* scope, Object* vis, CallFrame* calling_environment);
// Rubinius.primitive :vm_attach_method
- static Object* vm_attach_method(STATE, GCToken gct, Symbol* name, CompiledCode* meth, ConstantScope* scope, Object* recv);
+ static Object* vm_attach_method(STATE, GCToken gct, Symbol* name, CompiledCode* meth, ConstantScope* scope, Object* recv, CallFrame* calling_environment);
// A robust way to get the class of an object, since Object#class can be redefined.
// Rubinius.primitive :vm_object_class
View
@@ -66,11 +66,11 @@ namespace rubinius {
return 0;
}
- void CallFrame::print_backtrace(STATE, int total) {
- print_backtrace(state, std::cout, total);
+ void CallFrame::print_backtrace(STATE, int total, bool filter) {
+ print_backtrace(state, std::cout, total, filter);
}
- void CallFrame::print_backtrace(STATE, std::ostream& stream, int total) {
+ void CallFrame::print_backtrace(STATE, std::ostream& stream, int total, bool filter) {
CallFrame* cf = this;
int i = -1;
@@ -79,9 +79,9 @@ namespace rubinius {
i++;
if(total > 0 && i == total) return;
- stream << static_cast<void*>(cf) << ": ";
if(NativeMethodFrame* nmf = cf->native_method_frame()) {
+ stream << static_cast<void*>(cf) << ": ";
NativeMethod* nm = try_as<NativeMethod>(nmf->get_object(nmf->method()));
if(nm && nm->name()->symbol_p()) {
stream << "capi:" << nm->name()->debug_str(state) << " at ";
@@ -100,6 +100,13 @@ namespace rubinius {
continue;
}
+ if(filter && cf->compiled_code->kernel_method(state)) {
+ cf = cf->previous;
+ continue;
+ }
+
+ stream << static_cast<void*>(cf) << ": ";
+
if(cf->is_block_p(state)) {
stream << "__block__";
} else {
View
@@ -239,8 +239,8 @@ namespace rubinius {
VariableScope* method_scope(STATE);
- void print_backtrace(STATE, int count=0);
- void print_backtrace(STATE, std::ostream& stream, int count=0);
+ void print_backtrace(STATE, int count=0, bool filter=false);
+ void print_backtrace(STATE, std::ostream& stream, int count=0, bool filter=false);
int line(STATE);
View
@@ -2,11 +2,13 @@
namespace rubinius {
struct Stats {
+ atomic::integer methods_cache_resets;
atomic::integer jitted_methods;
atomic::integer jit_time_spent;
Stats()
- : jitted_methods(0)
+ : methods_cache_resets(0)
+ , jitted_methods(0)
, jit_time_spent(0)
{}
};

0 comments on commit d577a2c

Please sign in to comment.