Browse Source

Free memory data, place Runtime in ExecutionEngine

cl-refactor
Paweł Bylica 10 years ago
parent
commit
307e37912b
  1. 15
      evmjit/libevmjit/ExecutionEngine.cpp
  2. 11
      evmjit/libevmjit/Runtime.cpp
  3. 4
      evmjit/libevmjit/Runtime.h

15
evmjit/libevmjit/ExecutionEngine.cpp

@ -117,8 +117,7 @@ ReturnCode ExecutionEngine::run(RuntimeData* _data, Env* _env)
static StatsCollector statsCollector;
auto mainFuncName = codeHash(_data->codeHash);
Runtime runtime;
runtime.init(_data, _env);
m_runtime.init(_data, _env);
auto entryFuncPtr = (EntryFuncPtr)ee->getFunctionAddress(mainFuncName);
if (!entryFuncPtr)
@ -148,23 +147,17 @@ ReturnCode ExecutionEngine::run(RuntimeData* _data, Env* _env)
return ReturnCode::LLVMLinkError;
listener->stateChanged(ExecState::Execution);
auto returnCode = entryFuncPtr(&runtime);
auto returnCode = entryFuncPtr(&m_runtime);
listener->stateChanged(ExecState::Return);
if (returnCode == ReturnCode::Return)
{
returnData = runtime.getReturnData(); // Save reference to return data
}
returnData = m_runtime.getReturnData(); // Save reference to return data
listener->stateChanged(ExecState::Finished);
if (g_stats)
statsCollector.stats.push_back(std::move(listener));
if (runtime.m_memData)
{
std::cerr << "MEM: " << (size_t) runtime.m_memData << " [" << runtime.m_memSize << ", " << runtime.m_memCap << "}\n";
}
return returnCode;
}

11
evmjit/libevmjit/Runtime.cpp

@ -1,5 +1,7 @@
#include "Runtime.h"
#include <cstdlib>
#include <iostream>
#include <cassert>
namespace dev
@ -15,6 +17,15 @@ void Runtime::init(RuntimeData* _data, Env* _env)
m_env = _env;
}
Runtime::~Runtime()
{
if (m_memData)
{
std::cerr << "MEM: " << (size_t)m_memData << " [" << m_memSize << "]\n";
std::free(m_memData);
}
}
bytes_ref Runtime::getReturnData() const
{
auto data = m_data->callData;

4
evmjit/libevmjit/Runtime.h

@ -14,6 +14,7 @@ class Runtime
{
public:
void init(RuntimeData* _data, Env* _env);
EXPORT ~Runtime();
bytes_ref getReturnData() const;
@ -22,8 +23,7 @@ private:
Env* m_env = nullptr; ///< Pointer to environment proxy. Expected by compiled contract.
byte* m_memoryData = nullptr;
i256 m_memorySize;
public:
byte* m_memData; // FIXME: Remember to free memory
byte* m_memData;
uint64_t m_memSize;
uint64_t m_memCap;
};

Loading…
Cancel
Save