本文整理汇总了C++中CompiledMethod类的典型用法代码示例。如果您正苦于以下问题:C++ CompiledMethod类的具体用法?C++ CompiledMethod怎么用?C++ CompiledMethod使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CompiledMethod类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: test_enter_method
void test_enter_method() {
Symbol* meth = state->symbol("meth");
CompiledMethod* cm = CompiledMethod::create(state);
cm->name(state, meth);
state->shared.enable_profiling(state);
profiler::Profiler* prof = state->profiler();
Dispatch dis(meth, G(object), cm);
Arguments args;
profiler::MethodEntry* me1 = new profiler::MethodEntry(state, dis, args, cm);
TS_ASSERT_EQUALS(prof->methods_.size(), 1U);
TS_ASSERT_EQUALS(me1->method_, prof->methods_.find(me1->method_->id())->second);
dis.module = G(object)->metaclass(state);
profiler::MethodEntry* me2 = new profiler::MethodEntry(state, dis, args);
TS_ASSERT_EQUALS(prof->methods_.size(), 2U);
TS_ASSERT_EQUALS(me2->method_, prof->methods_.find(me2->method_->id())->second);
delete me1;
delete me2;
}
示例2: log
void LLVMState::compile_callframe(STATE, CompiledMethod* start, CallFrame* call_frame,
int primitive) {
if(config().jit_inline_debug) {
if(start) {
log() << "JIT: target search from "
<< symbol_cstr(start->name()) << "\n";
} else {
log() << "JIT: target search from primitive\n";
}
}
CompiledMethod* candidate = find_candidate(start, call_frame);
if(!candidate) {
if(config().jit_inline_debug) {
log() << "JIT: unable to find candidate\n";
}
return;
}
assert(!candidate->backend_method()->parent());
if(candidate->backend_method()->call_count < 0) {
if(!start) return;
// Ignore it. compile this one.
candidate = start;
}
compile_soon(state, candidate);
}
示例3: test_enter_block
void test_enter_block() {
Symbol* meth = state->symbol("meth");
CompiledMethod* cm = CompiledMethod::create(state);
cm->name(state, meth);
Symbol* name = state->symbol("ModName");
Module* mod = Module::create(state);
mod->name(state, name);
state->shared.enable_profiling(state);
profiler::Profiler* prof = state->profiler();
profiler::MethodEntry* me1 = new profiler::MethodEntry(state, meth, mod, cm);
TS_ASSERT_EQUALS(prof->methods_.size(), 1U);
TS_ASSERT_EQUALS(me1->method_, prof->methods_.find(me1->method_->id())->second);
mod = G(object)->metaclass(state);
profiler::MethodEntry* me2 = new profiler::MethodEntry(state, meth, mod, cm);
TS_ASSERT_EQUALS(prof->methods_.size(), 2U);
TS_ASSERT_EQUALS(me2->method_, prof->methods_.find(me2->method_->id())->second);
delete me1;
delete me2;
}
示例4: test_specialize_transforms_ivars_to_slots
void test_specialize_transforms_ivars_to_slots() {
CompiledMethod* cm = CompiledMethod::create(state);
Tuple* tup = Tuple::from(state, 1, state->symbol("@blah"));
cm->literals(state, tup);
InstructionSequence* iseq = InstructionSequence::create(state, 3);
iseq->opcodes()->put(state, 0, Fixnum::from(InstructionSequence::insn_push_ivar));
iseq->opcodes()->put(state, 1, Fixnum::from(0));
iseq->opcodes()->put(state, 2, Fixnum::from(InstructionSequence::insn_push_nil));
cm->iseq(state, iseq);
VMMethod* vmm = new VMMethod(state, cm);
Object::Info ti(ObjectType);
ti.slots[state->symbol("@blah")->index()] = 5;
ti.slot_locations.resize(6);
ti.slot_locations[5] = 33;
vmm->specialize(state, cm, &ti);
TS_ASSERT_EQUALS(vmm->total, 3U);
TS_ASSERT_EQUALS(vmm->opcodes[0], static_cast<unsigned int>(InstructionSequence::insn_push_my_offset));
TS_ASSERT_EQUALS(vmm->opcodes[1], 33U);
TS_ASSERT_EQUALS(vmm->opcodes[2], static_cast<unsigned int>(InstructionSequence::insn_push_nil));
}
示例5: compile_method
void Compiler::compile_method(LLVMState* ls, BackgroundCompileRequest* req) {
CompiledMethod* cm = req->method();
if(ls->config().jit_inline_debug) {
struct timeval tv;
gettimeofday(&tv, NULL);
ls->log() << "JIT: compiling "
<< ls->enclosure_name(cm)
<< "#"
<< ls->symbol_debug_str(cm->name())
<< " (" << tv.tv_sec << "." << tv.tv_usec << ")\n";
}
JITMethodInfo info(ctx_, cm, cm->backend_method());
info.is_block = false;
if(Class* cls = req->receiver_class()) {
info.set_self_class(cls);
}
ctx_.set_root(&info);
jit::MethodBuilder work(ls, info);
work.setup();
compile_builder(ctx_, ls, info, work);
}
示例6: auto_visit
void CompiledMethod::Info::visit(Object* obj, ObjectVisitor& visit) {
auto_visit(obj, visit);
visit_inliners(obj, visit);
CompiledMethod* cm = as<CompiledMethod>(obj);
if(!cm->backend_method_) return;
VMMethod* vmm = cm->backend_method_;
#ifdef ENABLE_LLVM
if(cm->jit_data()) {
cm->jit_data()->visit_all(visit);
}
for(int i = 0; i < VMMethod::cMaxSpecializations; i++) {
if(vmm->specializations[i].jit_data) {
vmm->specializations[i].jit_data->visit_all(visit);
}
}
#endif
for(size_t i = 0; i < vmm->inline_cache_count(); i++) {
InlineCache* cache = &vmm->caches[i];
MethodCacheEntry* mce = cache->cache_;
if(mce) visit.call(mce);
for(int i = 0; i < cTrackedICHits; i++) {
Module* mod = cache->seen_classes_[i].klass();
if(mod) visit.call(mod);
}
}
}
示例7: test_set_breakpoint_flags
void test_set_breakpoint_flags() {
CompiledMethod* cm = CompiledMethod::create(state);
Tuple* tup = Tuple::from(state, 1, state->symbol("@blah"));
cm->literals(state, tup);
InstructionSequence* iseq = InstructionSequence::create(state, 3);
iseq->opcodes()->put(state, 0, Fixnum::from(InstructionSequence::insn_push_ivar));
iseq->opcodes()->put(state, 1, Fixnum::from(0));
iseq->opcodes()->put(state, 2, Fixnum::from(InstructionSequence::insn_push_nil));
cm->iseq(state, iseq);
VMMethod* vmm = new VMMethod(state, cm);
vmm->set_breakpoint_flags(state, 0, 1 << 24);
TS_ASSERT_EQUALS(vmm->opcodes[0], (1U << 24) | static_cast<unsigned int>(InstructionSequence::insn_push_ivar));
vmm->set_breakpoint_flags(state, 0, 7 << 24);
TS_ASSERT_EQUALS(vmm->opcodes[0], (7U << 24) | static_cast<unsigned int>(InstructionSequence::insn_push_ivar));
vmm->set_breakpoint_flags(state, 0, 0);
TS_ASSERT_EQUALS(vmm->opcodes[0], static_cast<unsigned int>(InstructionSequence::insn_push_ivar));
vmm->set_breakpoint_flags(state, 1, 1);
TS_ASSERT_EQUALS(vmm->opcodes[1], 0U);
}
示例8: auto_mark
void CompiledMethod::Info::mark(Object* obj, ObjectMark& mark) {
auto_mark(obj, mark);
mark_inliners(obj, mark);
CompiledMethod* cm = as<CompiledMethod>(obj);
if(!cm->backend_method_) return;
VMMethod* vmm = cm->backend_method_;
vmm->set_mark();
Object* tmp;
#ifdef ENABLE_LLVM
if(cm->jit_data()) {
cm->jit_data()->set_mark();
cm->jit_data()->mark_all(cm, mark);
}
for(int i = 0; i < VMMethod::cMaxSpecializations; i++) {
if(vmm->specializations[i].jit_data) {
vmm->specializations[i].jit_data->set_mark();
vmm->specializations[i].jit_data->mark_all(cm, mark);
}
}
#endif
for(size_t i = 0; i < vmm->inline_cache_count(); i++) {
InlineCache* cache = &vmm->caches[i];
MethodCacheEntry* mce = cache->cache_;
if(mce) {
tmp = mark.call(mce);
if(tmp) {
cache->cache_ = (MethodCacheEntry*)tmp;
mark.just_set(obj, tmp);
}
}
if(cache->call_unit_) {
tmp = mark.call(cache->call_unit_);
if(tmp) {
cache->call_unit_ = (CallUnit*)tmp;
mark.just_set(obj, tmp);
}
}
for(int i = 0; i < cTrackedICHits; i++) {
Module* mod = cache->seen_classes_[i].klass();
if(mod) {
tmp = mark.call(mod);
if(tmp) {
cache->seen_classes_[i].set_klass(force_as<Class>(tmp));
mark.just_set(obj, tmp);
}
}
}
}
}
示例9: specialized_executor
Object* CompiledMethod::specialized_executor(STATE, CallFrame* call_frame,
Executable* exec, Module* mod, Arguments& args)
{
CompiledMethod* cm = as<CompiledMethod>(exec);
Class* cls = args.recv()->class_object(state);
int id = cls->class_id();
VMMethod* v = cm->backend_method();
executor target = v->unspecialized;
for(int i = 0; i < VMMethod::cMaxSpecializations; i++) {
int c_id = v->specializations[i].class_id;
executor x = v->specializations[i].execute;
if(c_id == id && x != 0) {
target = x;
break;
}
}
// This is a bug. We should not have this setup if there are no
// specializations. FIX THIS BUG!
if(!target) target = v->fallback;
return target(state, call_frame, exec, mod, args);
}
示例10: execute
/* This is the execute implementation used by normal Ruby code,
* as opposed to Primitives or FFI functions.
* It prepares a Ruby method for execution.
* Here, +exec+ is a VMMethod instance accessed via the +vmm+ slot on
* CompiledMethod.
*/
ExecuteStatus VMMethod::execute(STATE, Task* task, Message& msg) {
CompiledMethod* cm = as<CompiledMethod>(msg.method);
MethodContext* ctx = MethodContext::create(state, msg.recv, cm);
VMMethod* vmm = cm->backend_method_;
// Copy in things we all need.
ctx->module(state, msg.module);
ctx->name(state, msg.name);
ctx->block(state, msg.block);
ctx->args = msg.args();
// If argument handling fails..
GenericArguments args;
if(args.call(state, vmm, ctx, msg) == false) {
// Clear the values from the caller
task->active()->clear_stack(msg.stack);
// TODO we've got full control here, we should just raise the exception
// in the runtime here rather than throwing a C++ exception and raising
// it later.
Exception::argument_error(state, vmm->required_args, msg.args());
// never reached!
}
#if 0
if(!probe_->nil_p()) {
probe_->start_method(this, msg);
}
#endif
// Clear the values from the caller
task->active()->clear_stack(msg.stack);
task->make_active(ctx);
if(unlikely(task->profiler)) {
profiler::Method* prof_meth;
if(MetaClass* mc = try_as<MetaClass>(msg.module)) {
Object* attached = mc->attached_instance();
if(Module* mod = try_as<Module>(attached)) {
prof_meth = task->profiler->enter_method(msg.name, mod->name(), profiler::kNormal);
} else {
prof_meth = task->profiler->enter_method(msg.name, attached->id(state), profiler::kNormal);
}
} else {
prof_meth = task->profiler->enter_method(msg.name, msg.module->name(), profiler::kSingleton);
}
if(!prof_meth->file()) {
prof_meth->set_position(cm->file(), cm->start_line(state));
}
}
return cExecuteRestart;
}
示例11: create
CompiledMethod* CompiledMethod::create(STATE) {
CompiledMethod* cm = state->new_object<CompiledMethod>(G(cmethod));
cm->local_count(state, Fixnum::from(0));
cm->set_executor(CompiledMethod::default_executor);
cm->backend_method_ = NULL;
return cm;
}
示例12: default_executor
Object* CompiledMethod::default_executor(STATE, CallFrame* call_frame, Dispatch& msg,
Arguments& args) {
CompiledMethod* cm = as<CompiledMethod>(msg.method);
cm->formalize(state, false);
// Refactor
cm->backend_method_->find_super_instructions();
return cm->execute(state, call_frame, msg, args);
}
示例13: top_method
int CompiledRFrame::cost() const {
CompiledMethod* nm = top_method()->code();
if (nm != NULL) {
return nm->insts_size();
} else {
return top_method()->code_size();
}
}
示例14: i
r_mint Env::method_id(rmethod meth) {
CompiledMethod* cm = i(meth);
if(VMMethod* vmm = cm->backend_method()) {
return (vmm->method_id() << 1) | 1;
}
return 0;
}
示例15: dup_cm
CompiledMethod* CompiledMethod::dup_cm(STATE) {
CompiledMethod* cm = CompiledMethod::create(state);
cm->copy_object(state, this);
cm->set_executor(CompiledMethod::default_executor);
cm->jit_data_ = NULL;
cm->backend_method_ = NULL;
return cm;
}