-
Notifications
You must be signed in to change notification settings - Fork 608
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for custom call sites for respond_to
This sets up a new type of call site for respond_to? calls at the place where respond_to? is called. Currently it only stores the last symbol and visibility tag that is has seen and returns the cached value if they match.
- Loading branch information
Showing
17 changed files
with
255 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#include "detection.hpp" | ||
|
||
#include "arguments.hpp" | ||
#include "call_frame.hpp" | ||
#include "global_cache.hpp" | ||
#include "ontology.hpp" | ||
|
||
#include "builtin/respond_to_cache.hpp" | ||
#include "builtin/class.hpp" | ||
#include "builtin/symbol.hpp" | ||
|
||
namespace rubinius { | ||
|
||
void RespondToCache::init(STATE) { | ||
GO(respond_to_cache).set( | ||
ontology::new_class(state, "RespondToCache", | ||
G(call_site), G(rubinius))); | ||
|
||
} | ||
|
||
RespondToCache* RespondToCache::empty(STATE, CallSite* fallback, CallSite** location) { | ||
RespondToCache* cache = | ||
state->vm()->new_object_mature<RespondToCache>(G(respond_to_cache)); | ||
cache->fallback(state, fallback); | ||
cache->receiver_class_ = nil<Class>(); | ||
cache->visibility_ = nil<Symbol>(); | ||
cache->responds_ = cNil; | ||
cache->initial_backend_ = empty_cache; | ||
cache->execute_backend_ = empty_cache; | ||
cache->location_ = location; | ||
cache->clear_receiver_data(); | ||
return cache; | ||
} | ||
|
||
Object* RespondToCache::empty_cache(STATE, CallSite* call_site, CallFrame* call_frame, | ||
Arguments& args) { | ||
RespondToCache* cache = static_cast<RespondToCache*>(call_site); | ||
return cache->fallback_->execute(state, call_frame, args); | ||
} | ||
|
||
Object* RespondToCache::check_cache(STATE, CallSite* call_site, CallFrame* call_frame, | ||
Arguments& args) { | ||
RespondToCache* cache = static_cast<RespondToCache*>(call_site); | ||
|
||
Class* const recv_class = args.recv()->lookup_begin(state); | ||
Object* const message = args.get_argument(0); | ||
Object* visibility = cFalse; | ||
if(args.total() > 1) { | ||
visibility = args.get_argument(1); | ||
} | ||
|
||
register uint64_t recv_data = recv_class->data_id(); | ||
if(likely(recv_data == cache->receiver_data() && message == cache->message_ && visibility == cache->visibility_)) { | ||
return cache->responds_; | ||
} | ||
|
||
// Invalidate the cache here so we don't see anything else | ||
cache->clear_receiver_data(); | ||
atomic::memory_barrier(); | ||
return cache->initialize(state, call_frame, args); | ||
} | ||
|
||
void RespondToCache::update(STATE, Object* recv, Symbol* msg, Object* priv, Object* res) { | ||
Class* const recv_class = recv->lookup_begin(state); | ||
uint64_t recv_data = recv_class->data_id(); | ||
message(state, msg); | ||
visibility(state, priv); | ||
responds(state, res); | ||
atomic::memory_barrier(); | ||
set_receiver_data(recv_data); | ||
execute_backend_ = check_cache; | ||
} | ||
|
||
void RespondToCache::Info::mark(Object* obj, ObjectMark& mark) { | ||
auto_mark(obj, mark); | ||
} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
#ifndef RBX_RESPOND_TO_CACHE_HPP | ||
#define RBX_RESPOND_TO_CACHE_HPP | ||
|
||
#include "dispatch.hpp" | ||
#include "builtin/object.hpp" | ||
#include "builtin/class.hpp" | ||
#include "builtin/call_site.hpp" | ||
#include "builtin/exception.hpp" | ||
#include "type_info.hpp" | ||
|
||
namespace rubinius { | ||
struct CallFrame; | ||
class Arguments; | ||
class Module; | ||
|
||
class RespondToCache : public CallSite { | ||
public: | ||
const static object_type type = RespondToCacheType; | ||
|
||
private: | ||
ClassData receiver_; | ||
Class* receiver_class_; // slot | ||
Object* message_; // slot | ||
Object* visibility_; // slot | ||
Object* responds_; // slot | ||
CallSite* fallback_; // slot | ||
|
||
public: | ||
attr_accessor(receiver_class, Class); | ||
attr_accessor(message, Object); | ||
attr_accessor(visibility, Object); | ||
attr_accessor(responds, Object); | ||
attr_accessor(fallback, CallSite); | ||
|
||
void clear_receiver_data() { | ||
receiver_.raw = 0; | ||
} | ||
|
||
void set_receiver_data(uint64_t data) { | ||
receiver_.raw = data; | ||
} | ||
|
||
uint64_t receiver_data() { | ||
return receiver_.raw; | ||
} | ||
|
||
uint32_t receiver_class_id() { | ||
return receiver_.f.class_id; | ||
} | ||
|
||
uint32_t receiver_serial_id() { | ||
return receiver_.f.serial_id; | ||
} | ||
|
||
public: | ||
static void init(STATE); | ||
static RespondToCache* empty(STATE, CallSite* fallback, CallSite** location); | ||
|
||
static Object* empty_cache(STATE, CallSite* call_site, CallFrame* call_frame, | ||
Arguments& args); | ||
|
||
static Object* check_cache(STATE, CallSite* call_site, CallFrame* call_frame, | ||
Arguments& args); | ||
|
||
void update(STATE, Object* recv, Symbol* msg, Object* priv, Object* res); | ||
|
||
public: // Rubinius Type stuff | ||
class Info : public CallSite::Info { | ||
public: | ||
BASIC_TYPEINFO(CallSite::Info) | ||
virtual void mark(Object* t, ObjectMark& mark); | ||
}; | ||
|
||
}; | ||
} | ||
|
||
#endif | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.