From c66a7e49d3d7159d337a8cdd613e039727317410 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Fri, 15 May 2015 17:05:11 +0200 Subject: [PATCH] Fix cache mode handling. --- libevmjit/Cache.cpp | 17 ++++++++++++++--- libevmjit/Cache.h | 2 +- libevmjit/ExecutionEngine.cpp | 6 +----- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/libevmjit/Cache.cpp b/libevmjit/Cache.cpp index aa316d51d..464912104 100644 --- a/libevmjit/Cache.cpp +++ b/libevmjit/Cache.cpp @@ -40,12 +40,23 @@ namespace } } -ObjectCache* Cache::getObjectCache(CacheMode _mode, ExecutionEngineListener* _listener) +ObjectCache* Cache::init(CacheMode _mode, ExecutionEngineListener* _listener) { - static ObjectCache objectCache; g_mode = _mode; g_listener = _listener; - return &objectCache; + + if (g_mode == CacheMode::clear) + { + Cache::clear(); + g_mode = CacheMode::off; + } + + if (g_mode != CacheMode::off) + { + static ObjectCache objectCache; + return &objectCache; + } + return nullptr; } void Cache::clear() diff --git a/libevmjit/Cache.h b/libevmjit/Cache.h index 6b8457f4b..ef4a0bac7 100644 --- a/libevmjit/Cache.h +++ b/libevmjit/Cache.h @@ -45,7 +45,7 @@ public: class Cache { public: - static ObjectCache* getObjectCache(CacheMode _mode, ExecutionEngineListener* _listener); + static ObjectCache* init(CacheMode _mode, ExecutionEngineListener* _listener); static std::unique_ptr getObject(std::string const& id); /// Clears cache storage diff --git a/libevmjit/ExecutionEngine.cpp b/libevmjit/ExecutionEngine.cpp index a96ac700c..736946079 100644 --- a/libevmjit/ExecutionEngine.cpp +++ b/libevmjit/ExecutionEngine.cpp @@ -108,9 +108,6 @@ ExecutionEngine::ExecutionEngine() parseOptions(); - if (g_cache == CacheMode::clear) - Cache::clear(); - bool preloadCache = g_cache == CacheMode::preload; if (preloadCache) g_cache = CacheMode::on; @@ -133,8 +130,7 @@ ExecutionEngine::ExecutionEngine() g_ee = (builder.create()); // TODO: Update cache listener - auto objectCache = (g_cache != CacheMode::off && g_cache != CacheMode::clear) ? Cache::getObjectCache(g_cache, nullptr) : nullptr; - g_ee->setObjectCache(objectCache); + g_ee->setObjectCache(Cache::init(g_cache, nullptr)); // FIXME: Disabled during API changes //if (preloadCache)