From d6f4b07a0743bbfae5873ee88d7a146074b9da7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Wed, 4 Mar 2015 14:37:10 +0100 Subject: [PATCH] Cache pointers for emited functions --- libevmjit/ExecutionEngine.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/libevmjit/ExecutionEngine.cpp b/libevmjit/ExecutionEngine.cpp index c9578b4ee..e1c0780d9 100644 --- a/libevmjit/ExecutionEngine.cpp +++ b/libevmjit/ExecutionEngine.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include "preprocessor/llvm_includes_start.h" #include @@ -119,7 +120,12 @@ ReturnCode ExecutionEngine::run(RuntimeData* _data, Env* _env) auto mainFuncName = codeHash(_data->codeHash); m_runtime.init(_data, _env); - auto entryFuncPtr = (EntryFuncPtr)ee->getFunctionAddress(mainFuncName); + EntryFuncPtr entryFuncPtr = nullptr; + static std::unordered_map funcCache; + auto it = funcCache.find(mainFuncName); + if (it != funcCache.end()) + entryFuncPtr = it->second; + if (!entryFuncPtr) { auto module = objectCache ? Cache::getObject(mainFuncName) : nullptr; @@ -146,6 +152,8 @@ ReturnCode ExecutionEngine::run(RuntimeData* _data, Env* _env) if (!CHECK(entryFuncPtr)) return ReturnCode::LLVMLinkError; + funcCache[mainFuncName] = entryFuncPtr; + listener->stateChanged(ExecState::Execution); auto returnCode = entryFuncPtr(&m_runtime); listener->stateChanged(ExecState::Return);