RefPtr<MethodInfo> PluginRuntime::AcquireMethod(cell_t pcode_offset) { FunctionMap::Insert p = function_map_.findForAdd(pcode_offset); if (p.found()) return p->value; // Do some quick validation to make sure this is a valid offset. The only // real reason to do this is so we don't fill the hash set with bogus // methods. if (pcode_offset < 0 || size_t(pcode_offset) >= code_.length || !IsAligned(pcode_offset, sizeof(cell_t))) { return nullptr; } const cell_t* address = reinterpret_cast<const cell_t*>(code_.bytes + pcode_offset); if (*address != OP_PROC) return nullptr; RefPtr<MethodInfo> method = new MethodInfo(this, pcode_offset); if (!function_map_.add(p, pcode_offset, method)) return nullptr; // Grab the lock before linking code in, since the watchdog timer will look // at this list on another thread. { ke::AutoLock lock(Environment::get()->lock()); if (!methods_.append(method)) return nullptr; } return method; }
void PluginRuntime::AddJittedFunction(CompiledFunction *fn) { m_JitFunctions.append(fn); ucell_t pcode_offset = fn->GetCodeOffset(); { FunctionMap::Insert p = function_map_.findForAdd(pcode_offset); assert(!p.found()); function_map_.add(p, pcode_offset, fn); } }