Skip to content

Commit d6d20b1

Browse files
committed
Merge: eosvm eosvmoc
1 parent fcde0ee commit d6d20b1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+5206
-23
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,6 @@
3030
[submodule "libraries/wabt"]
3131
path = libraries/wabt
3232
url = https://github.com/EOSIO/wabt
33+
[submodule "libraries/eos-vm"]
34+
path = libraries/eos-vm
35+
url = https://github.com/eosio/eos-vm

CMakeLists.txt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,26 @@ endif()
9090
# * definition EOSIO_<RUNTIME>_RUNTIME_ENABLED defined in public libchain interface
9191
# * ctest entries with --runtime
9292
list(APPEND EOSIO_WASM_RUNTIMES wabt) #always enable wabt; it works everywhere and parts of eosio still assume it's always available
93+
if(CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32)
94+
list(APPEND EOSIO_WASM_RUNTIMES wavm)
95+
# WAVM requires LLVM, but move the check up here to a central location so that the EosioTester.cmakes
96+
# can be created with the exact version found
97+
find_package(LLVM REQUIRED CONFIG)
98+
if(LLVM_VERSION_MAJOR VERSION_LESS 7 OR LLVM_VERSION_MAJOR VERSION_GREATER 9)
99+
message(FATAL_ERROR "EOSIO requires an LLVM version 7.0 to 9.0")
100+
endif()
101+
102+
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux" AND "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64")
103+
list(APPEND EOSIO_WASM_RUNTIMES eos-vm-oc)
104+
endif()
105+
endif()
106+
107+
if(CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32)
108+
list(APPEND EOSIO_WASM_RUNTIMES eos-vm)
109+
if(CMAKE_SYSTEM_PROCESSOR STREQUAL x86_64)
110+
list(APPEND EOSIO_WASM_RUNTIMES eos-vm-jit)
111+
endif()
112+
endif()
93113

94114
if(UNIX)
95115
if(APPLE)
@@ -266,13 +286,16 @@ configure_file(${CMAKE_SOURCE_DIR}/libraries/fc/secp256k1/upstream/COPYING
266286
${CMAKE_BINARY_DIR}/licenses/eosio/LICENSE.secp256k1 COPYONLY)
267287
configure_file(${CMAKE_SOURCE_DIR}/libraries/fc/src/network/LICENSE.go
268288
${CMAKE_BINARY_DIR}/licenses/eosio/LICENSE.go COPYONLY)
289+
configure_file(${CMAKE_SOURCE_DIR}/libraries/eos-vm/LICENSE
290+
${CMAKE_BINARY_DIR}/licenses/eosio/LICENSE.eos-vm COPYONLY)
269291

270292
install(FILES LICENSE DESTINATION ${CMAKE_INSTALL_FULL_DATAROOTDIR}/licenses/eosio/)
271293
install(FILES libraries/wabt/LICENSE DESTINATION ${CMAKE_INSTALL_FULL_DATAROOTDIR}/licenses/eosio/ RENAME LICENSE.wabt)
272294
install(FILES libraries/softfloat/COPYING.txt DESTINATION ${CMAKE_INSTALL_FULL_DATAROOTDIR}/licenses/eosio/ RENAME LICENSE.softfloat)
273295
install(FILES libraries/wasm-jit/LICENSE DESTINATION ${CMAKE_INSTALL_FULL_DATAROOTDIR}/licenses/eosio/ RENAME LICENSE.wavm)
274296
install(FILES libraries/fc/secp256k1/upstream/COPYING DESTINATION ${CMAKE_INSTALL_FULL_DATAROOTDIR}/licenses/eosio/ RENAME LICENSE.secp256k1)
275297
install(FILES libraries/fc/src/network/LICENSE.go DESTINATION ${CMAKE_INSTALL_FULL_DATAROOTDIR}/licenses/eosio/ )
298+
install(FILES libraries/eos-vm/LICENSE DESTINATION ${CMAKE_INSTALL_FULL_DATAROOTDIR}/licenses/eosio/ RENAME LICENSE.eos-vm COMPONENT base)
276299

277300
include(package)
278301
include(doxygen)

libraries/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@ set(BUILD_TOOLS OFF CACHE BOOL "Build wabt tools")
1313
set(RUN_RE2C OFF CACHE BOOL "Run re2c")
1414
set(WITH_EXCEPTIONS ON CACHE BOOL "Build with exceptions enabled" FORCE)
1515
add_subdirectory( wabt )
16+
if(eos-vm IN_LIST EOSIO_WASM_RUNTIMES OR eos-vm-jit IN_LIST EOSIO_WASM_RUNTIMES)
17+
add_subdirectory( eos-vm )
18+
endif()

libraries/chain/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@ foreach(RUNTIME ${EOSIO_WASM_RUNTIMES})
125125
target_compile_definitions(eosio_chain PUBLIC "EOSIO_${RUNTIMEUC}_RUNTIME_ENABLED")
126126
endforeach()
127127

128+
if(EOSVMOC_ENABLE_DEVELOPER_OPTIONS)
129+
message(WARNING "EOS VM OC Developer Options are enabled; these are NOT supported")
130+
target_compile_definitions(eosio_chain PUBLIC EOSIO_EOS_VM_OC_DEVELOPER)
131+
endif()
128132

129133
install( TARGETS eosio_chain
130134
RUNTIME DESTINATION ${CMAKE_INSTALL_FULL_BINDIR}

libraries/chain/controller.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,10 @@ struct controller_impl {
158158
map< account_name, map<handler_key, apply_handler> > apply_handlers;
159159
platform_timer timer;
160160

161+
#if defined(EOSIO_EOS_VM_RUNTIME_ENABLED) || defined(EOSIO_EOS_VM_JIT_RUNTIME_ENABLED)
162+
vm::wasm_allocator wasm_alloc;
163+
#endif
164+
161165
/**
162166
* Transactions that were undone by pop_block or abort_block, transactions
163167
* are removed from this list if they are re-applied in other blocks. Producers
@@ -199,7 +203,7 @@ struct controller_impl {
199203
cfg.reversible_cache_size ),
200204
blog( cfg.blocks_dir ),
201205
fork_db( cfg.state_dir ),
202-
wasmif( cfg.wasm_runtime, db ),
206+
wasmif( cfg.wasm_runtime, cfg.eosvmoc_tierup, db, cfg.state_dir, cfg.eosvmoc_config ),
203207
resource_limits( db ),
204208
authorization( s, db ),
205209
conf( cfg ),
@@ -244,10 +248,7 @@ struct controller_impl {
244248
template<typename Signal, typename Arg>
245249
void emit( const Signal& s, Arg&& a ) {
246250
try {
247-
s( std::forward<Arg>( a ));
248-
} catch (std::bad_alloc& e) {
249-
wlog( "std::bad_alloc" );
250-
throw e;
251+
s(std::forward<Arg>(a));
251252
} catch (boost::interprocess::bad_alloc& e) {
252253
wlog( "bad alloc" );
253254
throw e;
@@ -767,6 +768,7 @@ struct controller_impl {
767768
return enc.result();
768769
}
769770

771+
770772
/**
771773
* Sets fork database head to the genesis state.
772774
*/
@@ -2857,4 +2859,10 @@ void controller::set_upo(uint32_t target_block_num) {
28572859
}
28582860
}
28592861

2862+
#if defined(EOSIO_EOS_VM_RUNTIME_ENABLED) || defined(EOSIO_EOS_VM_JIT_RUNTIME_ENABLED)
2863+
vm::wasm_allocator& controller::get_wasm_allocator() {
2864+
return my->wasm_alloc;
2865+
}
2866+
#endif
2867+
28602868
} } /// eosio::chain

libraries/chain/include/eosio/chain/controller.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <eosio/chain/abi_serializer.hpp>
88
#include <eosio/chain/account_object.hpp>
99
#include <eosio/chain/snapshot.hpp>
10+
#include <eosio/chain/webassembly/eos-vm-oc/config.hpp>
1011

1112
namespace chainbase {
1213
class database;
@@ -98,6 +99,9 @@ namespace eosio { namespace chain {
9899

99100
genesis_state genesis;
100101
wasm_interface::vm_type wasm_runtime = chain::config::default_wasm_runtime;
102+
eosvmoc::config eosvmoc_config;
103+
bool eosvmoc_tierup = false;
104+
101105

102106
db_read_mode read_mode = db_read_mode::SPECULATIVE;
103107
validation_mode block_validation_mode = validation_mode::FULL;
@@ -296,6 +300,9 @@ namespace eosio { namespace chain {
296300
void reset_pbft_my_prepare();
297301
void reset_pbft_prepared();
298302
void maybe_switch_forks();
303+
#if defined(EOSIO_EOS_VM_RUNTIME_ENABLED) || defined(EOSIO_EOS_VM_JIT_RUNTIME_ENABLED)
304+
vm::wasm_allocator& get_wasm_allocator();
305+
#endif
299306

300307
signal<void(const signed_block_ptr&)> pre_accepted_block;
301308
signal<void(const block_state_ptr&)> accepted_block_header;

libraries/chain/include/eosio/chain/wasm_interface.hpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
#include <eosio/chain/types.hpp>
33
#include <eosio/chain/whitelisted_intrinsics.hpp>
44
#include <eosio/chain/exceptions.hpp>
5+
#if defined(EOSIO_EOS_VM_RUNTIME_ENABLED) || defined(EOSIO_EOS_VM_JIT_RUNTIME_ENABLED)
6+
#include <eosio/vm/allocator.hpp>
7+
#endif
58
#include "Runtime/Linker.h"
69
#include "Runtime/Runtime.h"
710

@@ -10,6 +13,8 @@ namespace eosio { namespace chain {
1013
class apply_context;
1114
class wasm_runtime_interface;
1215
class controller;
16+
namespace eosvmoc { struct config; }
17+
1318
struct wasm_exit {
1419
int32_t code = 0;
1520
};
@@ -71,10 +76,13 @@ namespace eosio { namespace chain {
7176
public:
7277
enum class vm_type {
7378
wavm,
74-
wabt
79+
wabt,
80+
eos_vm,
81+
eos_vm_jit,
82+
eos_vm_oc
7583
};
7684

77-
wasm_interface(vm_type vm, const chainbase::database& d);
85+
wasm_interface(vm_type vm, bool eosvmoc_tierup, const chainbase::database& d, const boost::filesystem::path data_dir, const eosvmoc::config& eosvmoc_config);
7886
~wasm_interface();
7987

8088
//call before dtor to skip what can be minutes of dtor overhead with some runtimes; can cause leaks
@@ -106,4 +114,4 @@ namespace eosio{ namespace chain {
106114
std::istream& operator>>(std::istream& in, wasm_interface::vm_type& runtime);
107115
}}
108116

109-
FC_REFLECT_ENUM( eosio::chain::wasm_interface::vm_type, (wavm)(wabt) )
117+
FC_REFLECT_ENUM( eosio::chain::wasm_interface::vm_type, (wavm)(wabt)(eos_vm)(eos_vm_jit)(eos_vm_oc) )

libraries/chain/include/eosio/chain/wasm_interface_private.hpp

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
#include <eosio/chain/wasm_interface.hpp>
44
#include <eosio/chain/webassembly/wavm.hpp>
55
#include <eosio/chain/webassembly/wabt.hpp>
6+
#ifdef EOSIO_EOS_VM_OC_RUNTIME_ENABLED
7+
#include <eosio/chain/webassembly/eos-vm-oc.hpp>
8+
#else
9+
#define _REGISTER_EOSVMOC_INTRINSIC(CLS, MOD, METHOD, WASM_SIG, NAME, SIG)
10+
#endif
11+
#include <eosio/chain/webassembly/eos-vm.hpp>
612
#include <eosio/chain/webassembly/runtime_interface.hpp>
713
#include <eosio/chain/wasm_eosio_injection.hpp>
814
#include <eosio/chain/transaction_context.hpp>
@@ -16,6 +22,10 @@
1622
#include "WAST/WAST.h"
1723
#include "IR/Validate.h"
1824

25+
#if defined(EOSIO_EOS_VM_RUNTIME_ENABLED) || defined(EOSIO_EOS_VM_JIT_RUNTIME_ENABLED)
26+
#include <eosio/vm/allocator.hpp>
27+
#endif
28+
1929
using namespace fc;
2030
using namespace eosio::chain::webassembly;
2131
using namespace IR;
@@ -25,6 +35,8 @@ using boost::multi_index_container;
2535

2636
namespace eosio { namespace chain {
2737

38+
namespace eosvmoc { struct config; }
39+
2840
struct wasm_interface_impl {
2941
struct wasm_cache_entry {
3042
digest_type code_hash;
@@ -38,15 +50,44 @@ namespace eosio { namespace chain {
3850
struct by_first_block_num;
3951
struct by_last_block_num;
4052

41-
wasm_interface_impl(wasm_interface::vm_type vm, const chainbase::database& d) : db(d), wasm_runtime_time(vm) {
53+
#ifdef EOSIO_EOS_VM_OC_RUNTIME_ENABLED
54+
struct eosvmoc_tier {
55+
eosvmoc_tier(const boost::filesystem::path& d, const eosvmoc::config& c, const chainbase::database& db) : cc(d, c, db), exec(cc) {}
56+
eosvmoc::code_cache_async cc;
57+
eosvmoc::executor exec;
58+
eosvmoc::memory mem;
59+
};
60+
#endif
61+
62+
wasm_interface_impl(wasm_interface::vm_type vm, bool eosvmoc_tierup, const chainbase::database& d, const boost::filesystem::path data_dir, const eosvmoc::config& eosvmoc_config) : db(d), wasm_runtime_time(vm) {
4263
#ifdef EOSIO_WAVM_RUNTIME_ENABLED
4364
if(vm == wasm_interface::vm_type::wavm)
4465
runtime_interface = std::make_unique<webassembly::wavm::wavm_runtime>();
4566
#endif
4667
if(vm == wasm_interface::vm_type::wabt)
4768
runtime_interface = std::make_unique<webassembly::wabt_runtime::wabt_runtime>();
69+
#ifdef EOSIO_EOS_VM_RUNTIME_ENABLED
70+
if(vm == wasm_interface::vm_type::eos_vm)
71+
runtime_interface = std::make_unique<webassembly::eos_vm_runtime::eos_vm_runtime<eosio::vm::interpreter>>();
72+
#endif
73+
#ifdef EOSIO_EOS_VM_JIT_RUNTIME_ENABLED
74+
if(vm == wasm_interface::vm_type::eos_vm_jit)
75+
runtime_interface = std::make_unique<webassembly::eos_vm_runtime::eos_vm_runtime<eosio::vm::jit>>();
76+
#endif
77+
#ifdef EOSIO_EOS_VM_OC_RUNTIME_ENABLED
78+
if(vm == wasm_interface::vm_type::eos_vm_oc)
79+
runtime_interface = std::make_unique<webassembly::eosvmoc::eosvmoc_runtime>(data_dir, eosvmoc_config, d);
80+
#endif
4881
if(!runtime_interface)
4982
EOS_THROW(wasm_exception, "${r} wasm runtime not supported on this platform and/or configuration", ("r", vm));
83+
84+
#ifdef EOSIO_EOS_VM_OC_RUNTIME_ENABLED
85+
if(eosvmoc_tierup) {
86+
EOS_ASSERT(vm != wasm_interface::vm_type::wavm, wasm_exception, "WAVM is incompatible with EOS VM OC");
87+
EOS_ASSERT(vm != wasm_interface::vm_type::eos_vm_oc, wasm_exception, "You can't use EOS VM OC as the base runtime when tier up is activated");
88+
eosvmoc.emplace(data_dir, eosvmoc_config, d);
89+
}
90+
#endif
5091
}
5192

5293
~wasm_interface_impl() {
@@ -87,6 +128,10 @@ namespace eosio { namespace chain {
87128
//anything last used before or on the LIB can be evicted
88129
const auto first_it = wasm_instantiation_cache.get<by_last_block_num>().begin();
89130
const auto last_it = wasm_instantiation_cache.get<by_last_block_num>().upper_bound(lib);
131+
#ifdef EOSIO_EOS_VM_OC_RUNTIME_ENABLED
132+
if(eosvmoc) for(auto it = first_it; it != last_it; it++)
133+
eosvmoc->cc.free_code(it->code_hash, it->vm_version);
134+
#endif
90135
wasm_instantiation_cache.get<by_last_block_num>().erase(first_it, last_it);
91136
}
92137

@@ -174,6 +219,9 @@ namespace eosio { namespace chain {
174219
const chainbase::database& db;
175220
const wasm_interface::vm_type wasm_runtime_time;
176221

222+
#ifdef EOSIO_EOS_VM_OC_RUNTIME_ENABLED
223+
fc::optional<eosvmoc_tier> eosvmoc;
224+
#endif
177225
};
178226

179227
#define _ADD_PAREN_1(...) ((__VA_ARGS__)) _ADD_PAREN_2
@@ -184,7 +232,9 @@ namespace eosio { namespace chain {
184232

185233
#define _REGISTER_INTRINSIC_EXPLICIT(CLS, MOD, METHOD, WASM_SIG, NAME, SIG)\
186234
_REGISTER_WAVM_INTRINSIC(CLS, MOD, METHOD, WASM_SIG, NAME, SIG) \
187-
_REGISTER_WABT_INTRINSIC(CLS, MOD, METHOD, WASM_SIG, NAME, SIG)
235+
_REGISTER_WABT_INTRINSIC(CLS, MOD, METHOD, WASM_SIG, NAME, SIG) \
236+
_REGISTER_EOS_VM_INTRINSIC(CLS, MOD, METHOD, WASM_SIG, NAME, SIG) \
237+
_REGISTER_EOSVMOC_INTRINSIC(CLS, MOD, METHOD, WASM_SIG, NAME, SIG)
188238

189239
#define _REGISTER_INTRINSIC4(CLS, MOD, METHOD, WASM_SIG, NAME, SIG)\
190240
_REGISTER_INTRINSIC_EXPLICIT(CLS, MOD, METHOD, WASM_SIG, NAME, SIG )

0 commit comments

Comments
 (0)