Move the code cache into Environment, and out of knight/shared.

This commit is contained in:
David Anderson
2015-02-24 01:57:50 -08:00
parent 57ba8fd09b
commit c70e87d582
22 changed files with 51 additions and 1570 deletions
+27 -6
View File
@@ -26,7 +26,8 @@ Environment::Environment()
: debugger_(nullptr),
profiler_(nullptr),
jit_enabled_(true),
profiling_enabled_(false)
profiling_enabled_(false),
code_pool_(nullptr)
{
}
@@ -41,14 +42,14 @@ Environment::New()
if (sEnvironment)
return nullptr;
Environment *env = new Environment();
if (!env->Initialize()) {
delete env;
sEnvironment = new Environment();
if (!sEnvironment->Initialize()) {
delete sEnvironment;
sEnvironment = nullptr;
return nullptr;
}
sEnvironment = env;
return env;
return sEnvironment;
}
Environment *
@@ -64,6 +65,10 @@ Environment::Initialize()
api_v2_ = new SourcePawnEngine2();
watchdog_timer_ = new WatchdogTimer();
if ((code_pool_ = Knight::KE_CreateCodeCache()) == nullptr)
return false;
// Safe to initialize JIT now that we have the code cache.
if (!g_Jit.InitializeJIT())
return false;
@@ -75,6 +80,10 @@ Environment::Shutdown()
{
watchdog_timer_->Shutdown();
g_Jit.ShutdownJIT();
Knight::KE_DestroyCodeCache(code_pool_);
assert(sEnvironment == this);
sEnvironment = nullptr;
}
void
@@ -160,3 +169,15 @@ Environment::ReportError(PluginRuntime *runtime, int err, const char *errstr, ce
debugger_->OnContextExecuteError(runtime->GetDefaultContext(), &trace);
}
void *
Environment::AllocateCode(size_t size)
{
return Knight::KE_AllocCode(code_pool_, size);
}
void
Environment::FreeCode(void *code)
{
Knight::KE_FreeCode(code_pool_, code);
}