Skip to content

Commit

Permalink
Avoid caching singleton classes.
Browse files Browse the repository at this point in the history
Singleton classes reference the object.
  • Loading branch information
brixen committed Oct 15, 2014
1 parent d6c0dd2 commit 977fe2e
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
8 changes: 7 additions & 1 deletion vm/builtin/call_site.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,13 @@ namespace rubinius {
}
}

void CallSite::empty_cache_updater(STATE, CallSite* call_site, Class* klass, Dispatch& dispatch) {
void CallSite::empty_cache_updater(STATE, CallSite* call_site, Class* klass,
Dispatch& dispatch)
{
if(SingletonClass* cls = try_as<SingletonClass>(klass)) {
if(!try_as<Class>(cls->attached_instance())) return;
}

MonoInlineCache* cache = MonoInlineCache::create(state, call_site, klass, dispatch);
call_site->update_call_site(state, cache);
}
Expand Down
4 changes: 4 additions & 0 deletions vm/builtin/mono_inline_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ namespace rubinius {
void MonoInlineCache::mono_cache_updater(STATE, CallSite* call_site, Class* klass, Dispatch& dispatch) {
MonoInlineCache* mono_cache = reinterpret_cast<MonoInlineCache*>(call_site);

if(SingletonClass* cls = try_as<SingletonClass>(klass)) {
if(!try_as<Class>(cls->attached_instance())) return;
}

// If it's the same class, replace it since the old cache is
// for an older version of the same class and we don't
// want to go polymorphic in that case.
Expand Down
15 changes: 10 additions & 5 deletions vm/builtin/object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -860,11 +860,16 @@ namespace rubinius {
if(RespondToCache* rct = try_as<RespondToCache>(existing)) {
existing = rct->fallback_call_site();
}
RespondToCache* cache = RespondToCache::create(state, existing,
self, name, priv, responds, 1);
state->vm()->global_cache()->add_seen(state, name);
atomic::memory_barrier();
existing->update_call_site(state, cache);

SingletonClass* cls = try_as<SingletonClass>(self->direct_class(state));

if(!cls || try_as<Class>(cls->attached_instance())) {
RespondToCache* cache = RespondToCache::create(state, existing,
self, name, priv, responds, 1);
state->vm()->global_cache()->add_seen(state, name);
atomic::memory_barrier();
existing->update_call_site(state, cache);
}
}

return responds;
Expand Down
5 changes: 5 additions & 0 deletions vm/builtin/poly_inline_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@ namespace rubinius {

void PolyInlineCache::inline_cache_updater(STATE, CallSite* call_site, Class* klass, Dispatch& dispatch) {
PolyInlineCache* cache = reinterpret_cast<PolyInlineCache*>(call_site);

if(SingletonClass* cls = try_as<SingletonClass>(klass)) {
if(!try_as<Class>(cls->attached_instance())) return;
}

InlineCacheEntry* entry = InlineCacheEntry::create(state, klass->data(), klass, dispatch, 1);
cache->set_cache(state, entry);
}
Expand Down

0 comments on commit 977fe2e

Please sign in to comment.