- destroy the jit runtime when all script functions are destroyed

This commit is contained in:
Magnus Norddahl 2018-08-18 17:50:47 +02:00
parent 9d68d43ce7
commit e557e8fac0
3 changed files with 32 additions and 3 deletions

View file

@ -35,7 +35,26 @@ public:
}
};
static asmjit::JitRuntime jit;
static asmjit::JitRuntime *jit;
static int jitRefCount = 0;
asmjit::JitRuntime *JitGetRuntime()
{
if (!jit)
jit = new asmjit::JitRuntime;
jitRefCount++;
return jit;
}
void JitCleanUp(VMScriptFunction *func)
{
jitRefCount--;
if (jitRefCount == 0)
{
delete jit;
jit = nullptr;
}
}
#define A (pc[0].a)
#define B (pc[0].b)
@ -286,10 +305,12 @@ JitFuncPtr JitCompile(VMScriptFunction *sfunc)
using namespace asmjit;
try
{
auto *jit = JitGetRuntime();
ThrowingErrorHandler errorHandler;
//FileLogger logger(stdout);
CodeHolder code;
code.init(jit.getCodeInfo());
code.init(jit->getCodeInfo());
code.setErrorHandler(&errorHandler);
//code.setLogger(&logger);
@ -1723,7 +1744,7 @@ JitFuncPtr JitCompile(VMScriptFunction *sfunc)
cc.finalize();
JitFuncPtr fn = nullptr;
Error err = jit.add(&fn, &code);
Error err = jit->add(&fn, &code);
if (err)
I_FatalError("JitRuntime::add failed: %d", err);
return fn;

View file

@ -4,3 +4,4 @@
#include "vmintern.h"
JitFuncPtr JitCompile(VMScriptFunction *func);
void JitCleanUp(VMScriptFunction *func);

View file

@ -40,6 +40,7 @@
#include "templates.h"
#include "vmintern.h"
#include "types.h"
#include "jit.h"
cycle_t VMCycles[10];
int VMCalls[10];
@ -77,6 +78,12 @@ VMScriptFunction::VMScriptFunction(FName name)
VMScriptFunction::~VMScriptFunction()
{
if (JitFunc)
{
JitCleanUp(this);
JitFunc = nullptr;
}
if (Code != NULL)
{
if (KonstS != NULL)