mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-11 23:32:02 +00:00
- destroy the jit runtime when all script functions are destroyed
This commit is contained in:
parent
9d68d43ce7
commit
e557e8fac0
3 changed files with 32 additions and 3 deletions
|
@ -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;
|
||||
|
|
|
@ -4,3 +4,4 @@
|
|||
#include "vmintern.h"
|
||||
|
||||
JitFuncPtr JitCompile(VMScriptFunction *func);
|
||||
void JitCleanUp(VMScriptFunction *func);
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue