Exemplo n.º 1
0
  void test_mono_inline_cache_locate_succeeded() {
    Message msg(state);
    Symbol* sym = state->symbol("blah");
    SendSite* ss = SendSite::create(state, sym);
    Class* meta = G(object)->metaclass(state);
    CompiledMethod* cm = CompiledMethod::create(state);
    CompiledMethod* g_cm = CompiledMethod::create(state);

    TS_ASSERT_EQUALS(MonomorphicInlineCacheResolver::resolve, ss->resolver);

    ss->recv_class(state, meta);
    ss->module(state, G(object));
    ss->method(state, cm);
    ss->hits = 1U;

    msg.name = sym;
    msg.lookup_from = meta;
    msg.recv = G(object);
    msg.send_site = ss;
    msg.module = meta;
    msg.method = cm;

    state->global_cache->retain(state, meta, sym, meta, g_cm, false);

    TS_ASSERT(ss->locate(state, msg));
    TS_ASSERT_EQUALS(2U, ss->hits);
    TS_ASSERT_EQUALS(0U, ss->misses);
    TS_ASSERT_EQUALS(cm, msg.method);
    TS_ASSERT_EQUALS(G(object), msg.module);
  }
Exemplo n.º 2
0
  bool SendSite::fill(STATE, Module* klass, CallFrame* call_frame,
                                  SendSite::Internal* cache, bool priv,
                                  Module* lookup) {
    SendSite* ss = as<SendSite>(call_frame->cm->literals()->at(state, cache->literal));

    if(!lookup) lookup = klass;

    bool method_missing = false;

    if(find_method(state, lookup, ss->name(), priv, call_frame->self(),
                   &cache->method, &cache->module)) {
      cache->recv_class = klass;
      ss->write_barrier(state, cache->recv_class);
    } else {
      assert(find_method(state, lookup, G(sym_method_missing), true, call_frame->self(),
                         &cache->method, &cache->module));
      method_missing = true;
      cache->recv_class = 0; // Don't cache using method_missing
    }

    ss->write_barrier(state, cache->method);
    ss->write_barrier(state, cache->module);

    cache->execute = cache->method->execute;
    return method_missing;
  }
Exemplo n.º 3
0
  void test_hits_prim() {
    Symbol* sym = state->symbol("blah");
    SendSite* ss = SendSite::create(state, sym);

    ss->hits = 10;

    TS_ASSERT_EQUALS(Fixnum::from(10), (Fixnum*)ss->hits_prim(state));
  }
Exemplo n.º 4
0
 void CompiledMethod::post_marshal(STATE) {
   formalize(state); // side-effect, populates backend_method_
   // Set the sender attribute of all SendSites in this method to this CM
   Tuple *lit = literals();
   for(std::size_t i = 0; i < lit->num_fields(); i++) {
     SendSite *ss = try_as<SendSite>(lit->at(state, i));
     if(ss != NULL) ss->sender(state, this);
   }
 }
Exemplo n.º 5
0
  void Selector::clear(STATE) {
    size_t sz = send_sites_->size();
    SendSite* ss;

    for(size_t i = 0; i < sz; i++) {
      ss = (SendSite*)send_sites_->get(state, i);
      ss->initialize(state);
    }
  }
Exemplo n.º 6
0
  void test_set_sender() {
    Object* sym = state->symbol("blah");
    SendSite* ss = SendSite::create(state, sym);
    TS_ASSERT_EQUALS(ss->sender(), Qnil);

    CompiledMethod* cm = CompiledMethod::create(state);
    TS_ASSERT_EQUALS(ss->set_sender(state, cm), Qnil);
    TS_ASSERT_EQUALS(ss->sender(), cm);
  }
Exemplo n.º 7
0
  void test_mono_inline_cache_locate_failed() {
    Message msg(state);
    Symbol* sym = state->symbol("blah");
    SendSite* ss = SendSite::create(state, sym);
    Class* meta = G(object)->metaclass(state);
    CompiledMethod* cm = CompiledMethod::create(state);

    TS_ASSERT_EQUALS(MonomorphicInlineCacheResolver::resolve, ss->resolver);

    msg.name = sym;
    msg.lookup_from = meta;
    msg.recv = G(object);
    msg.send_site = ss;
    msg.module = (Module*)Qnil;
    msg.method = (Executable*)Qnil;

    state->global_cache->retain(state, meta, sym, meta, cm, false);

    TS_ASSERT(ss->locate(state, msg));
    TS_ASSERT_EQUALS(1U, ss->misses);
    TS_ASSERT_EQUALS(0U, ss->hits);
    TS_ASSERT_EQUALS(cm, msg.method);
    TS_ASSERT_EQUALS(meta, msg.module);
  }
Exemplo n.º 8
0
  void SendSite::Info::show(STATE, Object* self, int level) {
    SendSite* ss = as<SendSite>(self);

    class_header(state, self);
    indent_attribute(++level, "name"); ss->name()->show(state, level);
    indent_attribute(level, "sender"); class_info(state, ss->sender(), true);
    indent_attribute(level, "selector"); class_info(state, ss->selector(), true);
    indent_attribute(level, "hits"); std::cout << ss->hits << std::endl;
    indent_attribute(level, "misses"); std::cout << ss->misses << std::endl;
    indent_attribute(level, "module"); class_info(state, ss->module(), true);
    indent_attribute(level, "method"); class_info(state, ss->method(), true);
    indent_attribute(level, "recv_class"); class_info(state, ss->recv_class(), true);
    close_body(level);
  }
Exemplo n.º 9
0
  void test_initialize() {
    Object* sym = state->symbol("blah");
    SendSite* ss = SendSite::create(state, sym);
    CompiledMethod* cm = CompiledMethod::create(state);
    MethodResolver fake = (MethodResolver)Qnil;

    ss->resolver = fake;
    ss->recv_class(state, G(object));
    ss->method(state, cm);
    ss->module(state, G(object)->metaclass(state));
    TS_ASSERT_EQUALS(fake, ss->resolver);

    ss->initialize(state);
    TS_ASSERT_EQUALS(MonomorphicInlineCacheResolver::resolve, ss->resolver);
    TS_ASSERT(ss->recv_class()->nil_p());
    TS_ASSERT(ss->method()->nil_p());
    TS_ASSERT(ss->module()->nil_p());
  }
Exemplo n.º 10
0
  SendSite* SendSite::create(STATE, Object* name) {
    SendSite* ss = (SendSite*)state->new_struct(G(send_site), sizeof(SendSite));
    ss->name(state, (Symbol*)name);
    ss->sender(state, (CompiledMethod*)Qnil);
    ss->selector(state, Selector::lookup(state, name));

    ss->initialize(state);
    ss->selector()->associate(state, ss);

    return ss;
  }
Exemplo n.º 11
0
  void test_create() {
    Object* sym = state->symbol("blah");
    SendSite* ss = SendSite::create(state, sym);
    TS_ASSERT_EQUALS(ss->name(), sym);
    TS_ASSERT_EQUALS(ss->sender(), Qnil);
    
    Selector* sel = Selector::lookup(state, sym);
    TS_ASSERT_EQUALS(ss->selector(), sel);

    TS_ASSERT(sel->includes_p(state, ss));

    TS_ASSERT_EQUALS(ss->method(), Qnil);
    TS_ASSERT_EQUALS(ss->module(), Qnil);
    TS_ASSERT_EQUALS(ss->recv_class(), Qnil);
  }