Skip to content

Commit

Permalink
Added CallSite#reset.
Browse files Browse the repository at this point in the history
This will enable resetting all the CallSites in a process to a known state to
be able to eg using CallSite data for computing code coverage.
  • Loading branch information
brixen committed Apr 27, 2016
1 parent 20938ee commit 12f88d4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
5 changes: 5 additions & 0 deletions core/call_site.rb
Expand Up @@ -28,6 +28,11 @@ def misses
raise PrimitiveFailure, "CallSite#misses primitive failed"
end

def reset
Rubinius.primitive :call_site_reset
raise PrimitiveFailure, "CallSite#reset primitive failed"
end

def inspect
"#<#{self.class.name}:0x#{self.object_id.to_s(16)} name=#{@name} ip=#{ip} depth=#{depth} invokes=#{invokes} hits=#{hits} misses=#{misses}>"
end
Expand Down
18 changes: 15 additions & 3 deletions machine/builtin/call_site.hpp
Expand Up @@ -358,9 +358,9 @@ namespace rubinius {
if(atomic::compare_and_swap(reinterpret_cast<void**>(updated_caches),
previous_caches, inline_caches))
{
if(previous_caches) delete[] previous_caches;
if(previous_caches) delete previous_caches;
} else {
delete[] inline_caches;
delete inline_caches;
}

return;
Expand Down Expand Up @@ -397,7 +397,7 @@ namespace rubinius {
execute(CallSite::dispatch);
cache_miss(CallSite::dispatch);

delete[] caches();
delete caches();
caches(NULL);

atomic::memory_barrier();
Expand Down Expand Up @@ -506,6 +506,18 @@ namespace rubinius {
return Integer::from(state, misses());
}

// Rubinius.primitive :call_site_reset
CallSite* reset(STATE) {
if(caches()) delete caches();

invokes(0);
execute(default_execute);
cache_miss(default_execute);
caches(NULL);

return this;
}

class Info : public TypeInfo {
public:
Info(object_type type)
Expand Down

0 comments on commit 12f88d4

Please sign in to comment.