|
@ -20,18 +20,58 @@ |
|
|
*/ |
|
|
*/ |
|
|
|
|
|
|
|
|
#include "ExtVM.h" |
|
|
#include "ExtVM.h" |
|
|
|
|
|
#include <exception> |
|
|
|
|
|
#include <boost/thread.hpp> |
|
|
#include "Executive.h" |
|
|
#include "Executive.h" |
|
|
using namespace std; |
|
|
|
|
|
using namespace dev; |
|
|
using namespace dev; |
|
|
using namespace dev::eth; |
|
|
using namespace dev::eth; |
|
|
|
|
|
|
|
|
|
|
|
namespace |
|
|
|
|
|
{ |
|
|
|
|
|
static unsigned const c_depthLimit = 1024; |
|
|
|
|
|
static size_t const c_singleExecutionStackSize = 8 * 1024; |
|
|
|
|
|
static size_t const c_defaultStackSize = 512 * 1024; |
|
|
|
|
|
static unsigned const c_offloadPoint = c_defaultStackSize / c_singleExecutionStackSize; |
|
|
|
|
|
|
|
|
|
|
|
void goOnOffloadedStack(Executive& _e, OnOpFunc const& _onOp) |
|
|
|
|
|
{ |
|
|
|
|
|
cnote << "CALL OFFLOADING: offloading point " << c_offloadPoint; |
|
|
|
|
|
boost::thread::attributes attrs; |
|
|
|
|
|
attrs.set_stack_size((c_depthLimit - c_offloadPoint) * c_singleExecutionStackSize); |
|
|
|
|
|
|
|
|
|
|
|
std::exception_ptr exception; |
|
|
|
|
|
boost::thread{attrs, [&]{ |
|
|
|
|
|
cnote << "OFFLOADING thread"; |
|
|
|
|
|
try |
|
|
|
|
|
{ |
|
|
|
|
|
_e.go(_onOp); |
|
|
|
|
|
} |
|
|
|
|
|
catch (...) |
|
|
|
|
|
{ |
|
|
|
|
|
cnote << "!!!!!!!!!!! exception in offloading!!!!!!!!!!!!"; |
|
|
|
|
|
exception = std::current_exception(); |
|
|
|
|
|
} |
|
|
|
|
|
}}.join(); |
|
|
|
|
|
if (exception) |
|
|
|
|
|
std::rethrow_exception(exception); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void go(unsigned _depth, Executive& _e, OnOpFunc const& _onOp) |
|
|
|
|
|
{ |
|
|
|
|
|
if (_depth == c_offloadPoint) |
|
|
|
|
|
goOnOffloadedStack(_e, _onOp); |
|
|
|
|
|
else |
|
|
|
|
|
_e.go(_onOp); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
bool ExtVM::call(CallParameters& _p) |
|
|
bool ExtVM::call(CallParameters& _p) |
|
|
{ |
|
|
{ |
|
|
Executive e(m_s, lastHashes, depth + 1); |
|
|
Executive e(m_s, lastHashes, depth + 1); |
|
|
if (!e.call(_p, gasPrice, origin)) |
|
|
if (!e.call(_p, gasPrice, origin)) |
|
|
{ |
|
|
{ |
|
|
e.go(_p.onOp); |
|
|
go(depth, e, _p.onOp); |
|
|
e.accrueSubState(sub); |
|
|
e.accrueSubState(sub); |
|
|
} |
|
|
} |
|
|
_p.gas = e.gas(); |
|
|
_p.gas = e.gas(); |
|
@ -47,7 +87,7 @@ h160 ExtVM::create(u256 _endowment, u256& io_gas, bytesConstRef _code, OnOpFunc |
|
|
Executive e(m_s, lastHashes, depth + 1); |
|
|
Executive e(m_s, lastHashes, depth + 1); |
|
|
if (!e.create(myAddress, _endowment, gasPrice, io_gas, _code, origin)) |
|
|
if (!e.create(myAddress, _endowment, gasPrice, io_gas, _code, origin)) |
|
|
{ |
|
|
{ |
|
|
e.go(_onOp); |
|
|
go(depth, e, _onOp); |
|
|
e.accrueSubState(sub); |
|
|
e.accrueSubState(sub); |
|
|
} |
|
|
} |
|
|
io_gas = e.gas(); |
|
|
io_gas = e.gas(); |
|
|