diff --git a/evmjit/libevmjit-cpp/JitVM.cpp b/evmjit/libevmjit-cpp/JitVM.cpp index 84cc41dd1..7acbec5c1 100644 --- a/evmjit/libevmjit-cpp/JitVM.cpp +++ b/evmjit/libevmjit-cpp/JitVM.cpp @@ -32,9 +32,7 @@ bytesConstRef JitVM::go(ExtVMFace& _ext, OnOpFunc const& _onOp, uint64_t _step) if (rejected) { cwarn << "Execution rejected by EVM JIT (gas limit: " << m_gas << "), executing with interpreter"; - VMFactory::setKind(VMKind::Interpreter); - m_fallbackVM = VMFactory::create(m_gas); - VMFactory::setKind(VMKind::JIT); + m_fallbackVM = VMFactory::create(VMKind::Interpreter, m_gas); auto&& output = m_fallbackVM->go(_ext, _onOp, _step); m_gas = m_fallbackVM->gas(); // copy remaining gas, Executive expects it return output; diff --git a/libevm/VMFactory.cpp b/libevm/VMFactory.cpp index 1092906e4..f7d6267c7 100644 --- a/libevm/VMFactory.cpp +++ b/libevm/VMFactory.cpp @@ -29,7 +29,7 @@ namespace eth { namespace { - VMKind g_kind = VMKind::Interpreter; + auto g_kind = VMKind::Interpreter; } void VMFactory::setKind(VMKind _kind) @@ -38,11 +38,16 @@ void VMFactory::setKind(VMKind _kind) } std::unique_ptr VMFactory::create(u256 _gas) +{ + return create(g_kind, _gas); +} + +std::unique_ptr VMFactory::create(VMKind _kind, u256 _gas) { #if ETH_EVMJIT - return std::unique_ptr(g_kind == VMKind::JIT ? static_cast(new JitVM(_gas)) : static_cast(new VM(_gas))); + return std::unique_ptr(_kind == VMKind::JIT ? static_cast(new JitVM(_gas)) : static_cast(new VM(_gas))); #else - asserts(g_kind == VMKind::Interpreter && "JIT disabled in build configuration"); + asserts(_kind == VMKind::Interpreter && "JIT disabled in build configuration"); return std::unique_ptr(new VM(_gas)); #endif } diff --git a/libevm/VMFactory.h b/libevm/VMFactory.h index d0d02e0c4..ba78b85e9 100644 --- a/libevm/VMFactory.h +++ b/libevm/VMFactory.h @@ -26,7 +26,7 @@ namespace eth enum class VMKind: bool { Interpreter, - JIT + JIT, }; class VMFactory @@ -34,7 +34,13 @@ class VMFactory public: VMFactory() = delete; + /// Creates a VM instance of global kind (controlled by setKind() function). static std::unique_ptr create(u256 _gas); + + /// Creates a VM instance of kind provided. + static std::unique_ptr create(VMKind _kind, u256 _gas); + + /// Set global VM kind static void setKind(VMKind _kind); };