Browse Source

Free memory data, place Runtime in ExecutionEngine

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

15
libevmjit/ExecutionEngine.cpp

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

11
libevmjit/Runtime.cpp

@ -1,5 +1,7 @@
#include "Runtime.h" #include "Runtime.h"
#include <cstdlib>
#include <iostream>
#include <cassert> #include <cassert>
namespace dev namespace dev
@ -15,6 +17,15 @@ void Runtime::init(RuntimeData* _data, Env* _env)
m_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 bytes_ref Runtime::getReturnData() const
{ {
auto data = m_data->callData; auto data = m_data->callData;

4
libevmjit/Runtime.h

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

Loading…
Cancel
Save