Skip to content

Instantly share code, notes, and snippets.

@jballanc
Created March 27, 2010 19:38
Show Gist options
  • Save jballanc/346310 to your computer and use it in GitHub Desktop.
Save jballanc/346310 to your computer and use it in GitHub Desktop.
diff --git a/dispatcher.cpp b/dispatcher.cpp
index 3eca605..08f2a32 100644
--- a/dispatcher.cpp
+++ b/dispatcher.cpp
@@ -484,6 +484,7 @@ fill_rcache(struct mcache *cache, Class klass, SEL sel,
{
cache->flag = MCACHE_RCALL;
rcache.klass = klass;
+ printf("Filling rcache <%p> with node: %p\n", (void *)&rcache, (void *)node);
rcache.node = node;
}
@@ -506,6 +507,7 @@ static void
fill_ocache(struct mcache *cache, VALUE self, Class klass, IMP imp, SEL sel,
Method method, int argc)
{
+ printf("Filling ocache: %p for selector: '%s'\n", (void *)cache, (char *)sel);
cache->flag = MCACHE_OCALL;
ocache.klass = klass;
ocache.imp = imp;
@@ -581,17 +583,20 @@ __rb_vm_dispatch(RoxorVM *vm, struct mcache *cache, VALUE top, VALUE self,
if (cache->flag == 0) {
recache:
+ printf("cache is %p and cache->flag is 0\n", (void *)cache);
#if ROXOR_VM_DEBUG
cached = false;
#endif
Method method;
+ printf("looking for [%s %s]\n", class_getName(klass), (char *)sel);
if (opt == DISPATCH_SUPER) {
method = rb_vm_super_lookup((VALUE)klass, sel);
}
else {
method = class_getInstanceMethod(klass, sel);
}
+ printf("found: [%s <%p>]\n", class_getName(klass), (void *)method);
if (method != NULL) {
recache2:
@@ -773,6 +778,10 @@ dispatch:
MACRUBY_METHOD_ENTRY(class_name, method_name, file, line);
}
+#if ROXOR_VM_DEBUG
+ printf("calling __rb_vm_ruby_dispatch: cache=%p rcache.node=%p rcache.node->klass=%p\n", (void *)cache, (void *)rcache.node, (void *)rcache.node->klass);
+#endif
+
VALUE v = __rb_vm_ruby_dispatch(top, self, sel, rcache.node, opt,
argc, argv);
@@ -892,6 +901,9 @@ sel_target_found:
}
}
+#if ROXOR_VM_DEBUG
+ printf("calling __rb_vm_objc_dispatch: cache=%p ocache.stub=%p ocache.imp=%p\n", (void *)cache, (void *)ocache.stub, (void *)ocache.imp);
+#endif
return __rb_vm_objc_dispatch(ocache.stub, ocache.imp, ocrcv, sel,
argc, argv);
}
diff --git a/vm.cpp b/vm.cpp
index 8d738e5..bdfa964 100644
--- a/vm.cpp
+++ b/vm.cpp
@@ -656,6 +656,7 @@ RoxorCore::method_cache_get(SEL sel, bool super)
struct mcache *cache = (struct mcache *)malloc(sizeof(struct mcache));
cache->flag = 0;
// TODO store the cache somewhere and invalidate it appropriately.
+ printf("Returning cache <%p> for seletor '%s' to be called on super\n", (void *)cache, (char *)sel);
return cache;
}
std::map<SEL, struct mcache *>::iterator iter = mcache.find(sel);
@@ -663,8 +664,10 @@ RoxorCore::method_cache_get(SEL sel, bool super)
struct mcache *cache = (struct mcache *)malloc(sizeof(struct mcache));
cache->flag = 0;
mcache[sel] = cache;
+ printf("Returning cache <%p> for seletor '%s'\n", (void *)cache, (char *)sel);
return cache;
}
+ printf("Returning cache <%p> for seletor '%s' from our map\n", (void *)iter->second, (char *)sel);
return iter->second;
}
@@ -673,7 +676,7 @@ void *
rb_vm_get_method_cache(SEL sel)
{
const bool super = strncmp(sel_getName(sel), "__super__:", 10) == 0;
- return GET_CORE()->method_cache_get(sel, super);
+ return GET_CORE()->method_cache_get(sel, super);
}
rb_vm_method_node_t *
@@ -849,6 +852,7 @@ RoxorCore::invalidate_method_cache(SEL sel)
{
std::map<SEL, struct mcache *>::iterator iter = mcache.find(sel);
if (iter != mcache.end()) {
+ printf("AHH METHOD CACHE INVALID!!!\n");
iter->second->flag = 0;
}
}
@@ -863,7 +867,6 @@ RoxorCore::add_method(Class klass, SEL sel, IMP imp, IMP ruby_imp,
flags |= VM_METHOD_PRIVATE;
}
-#if ROXOR_VM_DEBUG
printf("defining %c[%s %s] with imp %p/%p types %s flags %d arity %d\n",
class_isMetaClass(klass) ? '+' : '-',
class_getName(klass),
@@ -873,7 +876,6 @@ RoxorCore::add_method(Class klass, SEL sel, IMP imp, IMP ruby_imp,
types,
flags,
arity.real);
-#endif
// Register the implementation into the runtime.
class_replaceMethod(klass, sel, imp, types);
@@ -1903,6 +1905,7 @@ RoxorCore::resolve_method(Class klass, SEL sel, Function *func,
}
}
+ printf("Resolutions...\n");
// Finally, add the method.
return add_method(klass, sel, objc_imp, imp, arity, flags, types);
}
@@ -1911,6 +1914,7 @@ bool
RoxorCore::resolve_methods(std::map<Class, rb_vm_method_source_t *> *map,
Class klass, SEL sel)
{
+ printf("Resolving methods for [%s %s]\n", class_getName(klass), (char *)sel);
bool did_something = false;
std::map<Class, rb_vm_method_source_t *>::iterator iter = map->begin();
while (iter != map->end()) {
@@ -1947,12 +1951,10 @@ rb_vm_resolve_method(Class klass, SEL sel)
bool status = false;
-#if ROXOR_VM_DEBUG
printf("resolving %c[%s %s]\n",
class_isMetaClass(klass) ? '+' : '-',
class_getName(klass),
sel_getName(sel));
-#endif
std::map<Class, rb_vm_method_source_t *> *map =
GET_CORE()->method_sources_for_sel(sel, false);
@@ -1970,6 +1972,7 @@ rb_vm_resolve_method(Class klass, SEL sel)
// Now let's resolve all methods of the given name on the given class
// and superclasses.
+ printf("About to resolve methods for [%s %s]\n", class_getName(klass), (char *)sel);
status = GET_CORE()->resolve_methods(map, klass, sel);
bails:
@@ -3112,14 +3115,22 @@ extern "C"
void *
rb_vm_get_call_cache(SEL sel)
{
- return GET_CORE()->method_cache_get(sel, false);
+ struct mcache *mcache = GET_CORE()->method_cache_get(sel, false);
+#if ROXOR_VM_DEBUG
+ printf("Returning cache node %p for selector '%s'\n", (void *)mcache, (char *)sel);
+#endif
+ return mcache;
}
extern "C"
void *
rb_vm_get_call_cache2(SEL sel, unsigned char super)
{
- return GET_CORE()->method_cache_get(sel, super);
+ struct mcache *mcache = GET_CORE()->method_cache_get(sel, super);
+#if ROXOR_VM_DEBUG
+ printf("Returning cache <%p> for seletor '%s'[%c]\n", (void *)mcache, (char *)sel, super);
+#endif
+ return mcache;
}
// Should be used inside a method implementation.
@@ -4735,6 +4746,7 @@ static IMP old_resolveInstanceMethod_imp = NULL;
static BOOL
resolveClassMethod_imp(void *self, SEL sel, SEL name)
{
+ printf("resolveClassMethod_imp for [%s %s]\n", class_getName(*(Class *)self), (char *)sel);
if (rb_vm_resolve_method(*(Class *)self, name)) {
return YES;
}
@@ -4744,6 +4756,7 @@ resolveClassMethod_imp(void *self, SEL sel, SEL name)
static BOOL
resolveInstanceMethod_imp(void *self, SEL sel, SEL name)
{
+ printf("resolveInstanceMethod_imp for [%s %s]\n", class_getName(*(Class *)self), (char *)sel);
if (rb_vm_resolve_method((Class)self, name)) {
return YES;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment