Пример #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);
  }
Пример #2
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());
  }
Пример #3
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);
  }
Пример #4
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);
  }