19 #include <unordered_map> 33 struct JitInfo: LogChannel {
static const char*
name() {
return "JIT"; };
static const int verbosity = 11; };
35 using HitMap = std::unordered_map<h256, uint64_t>;
39 static HitMap s_hitMap;
49 static JitTask createStopSentinel() {
return JitTask(); }
53 assert((!code.empty() || !
codeHash) &&
"'empty code => empty hash' invariant failed");
65 clog(JitInfo) <<
"JIT worker started.";
67 while (!(task = m_queue.pop()).isStopSentinel())
69 clog(JitInfo) <<
"Compilation... " << task.codeHash;
70 JitVM::compile(task.mode, {task.code.data(), task.code.size()}, task.codeHash);
71 clog(JitInfo) <<
" ...finished " << task.codeHash;
73 clog(JitInfo) <<
"JIT worker finished.";
77 JitWorker() noexcept:
m_worker([
this]{ work(); })
82 push(JitTask::createStopSentinel());
86 void push(JitTask&& _task) { m_queue.push(std::move(_task)); }
100 else if (!_ext.
code.empty())
102 static JitWorker s_worker;
105 static const uint64_t c_hitTreshold = 2;
106 auto& hits = getHitMap()[_ext.
codeHash];
108 if (hits == c_hitTreshold)
Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c Origi...
assert(len-trim+(2 *lenIndices)<=WIDTH)
static void compile(evm_mode _mode, bytesConstRef _code, h256 _codeHash)
static std::unique_ptr< VMFace > create()
Creates a VM instance of global kind (controlled by setKind() function).
h256 codeHash
SHA3 hash of the executing code.
concurrent_queue< JitTask > m_queue
owning_bytes_ref exec(u256 &io_gas, ExtVMFace &_ext, OnOpFunc const &_onOp) overridefinal
VM implementation.
std::vector< byte > bytes
std::function< void(uint64_t, uint64_t, Instruction, bigint, bigint, bigint, VM *, ExtVMFace const *)> OnOpFunc
boost::multiprecision::number< boost::multiprecision::cpp_int_backend< 256, 256, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void >> u256
evm_mode
EVM compatibility mode aka chain mode.
Interface and null implementation of the class for specifying VM externalities.
bytes code
Current code that is executing.
static bool isCodeReady(evm_mode _mode, h256 _codeHash)
Reference to a slice of buffer that also owns the buffer.
virtual EVMSchedule const & evmSchedule() const
Return the EVM gas-price schedule for this execution context.
static evm_mode scheduleToMode(EVMSchedule const &_schedule)