diff --git a/exp/CMakeLists.txt b/exp/CMakeLists.txt index fce739007..156de203f 100644 --- a/exp/CMakeLists.txt +++ b/exp/CMakeLists.txt @@ -18,6 +18,7 @@ endif() target_link_libraries(${EXECUTABLE} ${LEVELDB_LS}) if(EVMJIT) + target_link_libraries(${EXECUTABLE} evm) target_link_libraries(${EXECUTABLE} evmjit) endif() diff --git a/libethereum/CMakeLists.txt b/libethereum/CMakeLists.txt index cb2049886..6088525fb 100644 --- a/libethereum/CMakeLists.txt +++ b/libethereum/CMakeLists.txt @@ -28,6 +28,9 @@ endif() target_link_libraries(${EXECUTABLE} ${LEVELDB_LS}) target_link_libraries(${EXECUTABLE} ${CRYPTOPP_LS}) target_link_libraries(${EXECUTABLE} gmp) +if (EVMJIT) + target_link_libraries(${EXECUTABLE} evmjit) +endif() if("${TARGET_PLATFORM}" STREQUAL "w64") target_link_libraries(${EXECUTABLE} boost_system-mt-s) diff --git a/libethereum/Executive.cpp b/libethereum/Executive.cpp index f609c9c14..87e675e15 100644 --- a/libethereum/Executive.cpp +++ b/libethereum/Executive.cpp @@ -118,7 +118,7 @@ bool Executive::call(Address _receiveAddress, Address _senderAddress, u256 _valu if (m_s.addressHasCode(_receiveAddress)) { - m_vm = VMFace::create(VMFace::Interpreter, _gas).release(); + m_vm = VMFactory::create(VMFactory::Interpreter, _gas).release(); bytes const& c = m_s.code(_receiveAddress); m_ext = new ExtVM(m_s, _receiveAddress, _senderAddress, _originAddress, _value, _gasPrice, _data, &c, m_ms); } @@ -137,7 +137,7 @@ bool Executive::create(Address _sender, u256 _endowment, u256 _gasPrice, u256 _g m_s.m_cache[m_newAddress] = Account(m_s.balance(m_newAddress) + _endowment, Account::ContractConception); // Execute _init. - m_vm = VMFace::create(VMFace::Interpreter, _gas).release(); + m_vm = VMFactory::create(VMFactory::Interpreter, _gas).release(); m_ext = new ExtVM(m_s, m_newAddress, _sender, _origin, _endowment, _gasPrice, bytesConstRef(), _init, m_ms); return _init.empty(); } diff --git a/libethereum/State.cpp b/libethereum/State.cpp index 4e5f5226c..2f8f4063f 100644 --- a/libethereum/State.cpp +++ b/libethereum/State.cpp @@ -1214,7 +1214,7 @@ bool State::call(Address _receiveAddress, Address _codeAddress, Address _senderA } else if (addressHasCode(_codeAddress)) { - auto vmObj = VMFace::create(getVMKind(), *_gas); + auto vmObj = VMFactory::create(getVMKind(), *_gas); auto& vm = *vmObj; ExtVM evm(*this, _receiveAddress, _senderAddress, _originAddress, _value, _gasPrice, _data, &code(_codeAddress), o_ms, _level); bool revert = false; @@ -1274,7 +1274,7 @@ h160 State::create(Address _sender, u256 _endowment, u256 _gasPrice, u256* _gas, m_cache[newAddress] = Account(balance(newAddress) + _endowment, Account::ContractConception); // Execute init code. - auto vmObj = VMFace::create(getVMKind(), *_gas); + auto vmObj = VMFactory::create(getVMKind(), *_gas); auto& vm = *vmObj; ExtVM evm(*this, newAddress, _sender, _origin, _endowment, _gasPrice, bytesConstRef(), _code, o_ms, _level); bool revert = false; diff --git a/libethereum/State.h b/libethereum/State.h index 96d53bc9e..f7bc0d119 100644 --- a/libethereum/State.h +++ b/libethereum/State.h @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -39,6 +40,7 @@ #include "TransactionReceipt.h" #include "Executive.h" #include "AccountDiff.h" +#include "VMFactory.h" namespace dev { @@ -261,10 +263,10 @@ public: void cleanup(bool _fullCommit); /// Sets VM kind to be used by the state - void setVMKind(VMFace::Kind _kind) { m_vmKind = _kind; } + void setVMKind(VMFactory::Kind _kind) { m_vmKind = _kind; } /// Get the kind of VM used by the state - VMFace::Kind getVMKind() const { return m_vmKind; } + VMFactory::Kind getVMKind() const { return m_vmKind; } private: /// Undo the changes to the state for committing to mine. @@ -333,7 +335,7 @@ private: u256 m_blockReward; - VMFace::Kind m_vmKind = VMFace::Interpreter; ///< The kind of VM used by the state + VMFactory::Kind m_vmKind = VMFactory::Interpreter; ///< The kind of VM used by the state static std::string c_defaultPath; diff --git a/libevm/VM.h b/libevm/VM.h index b7a98d262..f39bc9d4f 100644 --- a/libevm/VM.h +++ b/libevm/VM.h @@ -36,6 +36,8 @@ namespace dev namespace eth { +class VMFactory; + /** */ class VM : public VMFace @@ -53,7 +55,7 @@ public: u256s const& stack() const { return m_stack; } private: - friend VMFace; + friend VMFactory; explicit VM(u256 _gas = 0): VMFace(_gas) {} template diff --git a/libevm/VMFace.cpp b/libevm/VMFace.cpp index 3313ee926..9f8c6549c 100644 --- a/libevm/VMFace.cpp +++ b/libevm/VMFace.cpp @@ -22,15 +22,7 @@ using namespace dev; using namespace dev::eth; -std::unique_ptr VMFace::create(VMFace::Kind _kind, u256 _gas) +void VMFace::reset(u256 _gas) noexcept { - std::unique_ptr vm; -#if ETH_EVMJIT - vm.reset(_kind == Kind::JIT ? static_cast(new jit::VM) : new VM); -#else - (void) _kind; // suppress unused var warning - vm.reset(new VM); -#endif - vm->reset(_gas); - return vm; + m_gas = _gas; } diff --git a/libevm/VMFace.h b/libevm/VMFace.h index 76dc8a219..6617db1da 100644 --- a/libevm/VMFace.h +++ b/libevm/VMFace.h @@ -62,16 +62,12 @@ public: VMFace(VMFace const&) = delete; void operator=(VMFace const&) = delete; - virtual void reset(u256 _gas = 0) noexcept { m_gas = _gas; } + virtual void reset(u256 _gas = 0) noexcept; virtual bytesConstRef go(ExtVMFace& _ext, OnOpFunc const& _onOp = {}, uint64_t _steps = (uint64_t)-1) = 0; u256 gas() const { return m_gas; } - enum Kind: bool { Interpreter, JIT }; - - static std::unique_ptr create(Kind, u256 _gas = 0); - protected: u256 m_gas = 0; }; diff --git a/libevmjit/VM.cpp b/libevmjit/VM.cpp index 9b60fccf1..b968008aa 100644 --- a/libevmjit/VM.cpp +++ b/libevmjit/VM.cpp @@ -2,6 +2,7 @@ #include "VM.h" #include +#include #include "ExecutionEngine.h" #include "Compiler.h" diff --git a/libevmjit/VM.h b/libevmjit/VM.h index 93b359cd7..1c6c71181 100644 --- a/libevmjit/VM.h +++ b/libevmjit/VM.h @@ -9,6 +9,9 @@ namespace dev { namespace eth { + +class VMFactory; + namespace jit { @@ -16,8 +19,11 @@ class VM: public VMFace { virtual bytesConstRef go(ExtVMFace& _ext, OnOpFunc const& _onOp = {}, uint64_t _steps = (uint64_t)-1) override final; + enum Kind: bool { Interpreter, JIT }; + static std::unique_ptr create(Kind, u256 _gas = 0); + private: - friend VMFace; + friend VMFactory; explicit VM(u256 _gas = 0): VMFace(_gas) {} bytes m_output; diff --git a/test/createRandomTest.cpp b/test/createRandomTest.cpp index f22e5c0aa..87bb13846 100644 --- a/test/createRandomTest.cpp +++ b/test/createRandomTest.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include "vm.h" @@ -128,7 +129,7 @@ void doMyTests(json_spirit::mValue& v) assert(o.count("exec") > 0); - auto vmObj = eth::VMFace::create(eth::VMFace::Interpreter); + auto vmObj = eth::VMFactory::create(eth::VMFactory::Interpreter); auto& vm = *vmObj; test::FakeExtVM fev; fev.importEnv(o["env"].get_obj()); diff --git a/test/vm.cpp b/test/vm.cpp index b34dc1829..ce0fe0808 100644 --- a/test/vm.cpp +++ b/test/vm.cpp @@ -22,6 +22,7 @@ #include #include +#include #include "vm.h" using namespace std; using namespace json_spirit; @@ -322,8 +323,11 @@ void doVMTests(json_spirit::mValue& v, bool _fillin) auto useJit = false; for (auto i = 0; i < argc && !useJit; ++i) useJit |= std::string(argv[i]) == "--jit"; - auto vmKind = useJit ? VMFace::JIT : VMFace::Interpreter; - +#if ETH_EVMJIT + auto vmKind = useJit ? VMFactory::JIT : VMFactory::Interpreter; +#else + auto vmKind == VMFactory::Interpreter; +#endif dev::test::FakeExtVM fev; fev.importEnv(o["env"].get_obj()); @@ -339,7 +343,7 @@ void doVMTests(json_spirit::mValue& v, bool _fillin) fev.code = fev.thisTxCode; } - auto vm = VMFace::create(vmKind, fev.gas); + auto vm = VMFactory::create(vmKind, fev.gas); bytes output; auto startTime = std::chrono::high_resolution_clock::now();