Browse Source

Allow selecting VM kind manually

cl-refactor
Paweł Bylica 10 years ago
parent
commit
1e6659d1a9
  1. 4
      evmjit/libevmjit-cpp/JitVM.cpp
  2. 11
      libevm/VMFactory.cpp
  3. 8
      libevm/VMFactory.h

4
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;

11
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<VMFace> VMFactory::create(u256 _gas)
{
return create(g_kind, _gas);
}
std::unique_ptr<VMFace> VMFactory::create(VMKind _kind, u256 _gas)
{
#if ETH_EVMJIT
return std::unique_ptr<VMFace>(g_kind == VMKind::JIT ? static_cast<VMFace*>(new JitVM(_gas)) : static_cast<VMFace*>(new VM(_gas)));
return std::unique_ptr<VMFace>(_kind == VMKind::JIT ? static_cast<VMFace*>(new JitVM(_gas)) : static_cast<VMFace*>(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<VMFace>(new VM(_gas));
#endif
}

8
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<VMFace> create(u256 _gas);
/// Creates a VM instance of kind provided.
static std::unique_ptr<VMFace> create(VMKind _kind, u256 _gas);
/// Set global VM kind
static void setKind(VMKind _kind);
};

Loading…
Cancel
Save