go back to earlier approach of doing full GC collection every n compilations as the GCSETP approach doesn't work

gccjit-ravi534
Dibyendu Majumdar 7 years ago
parent a8c04341cf
commit 7ed629bdfe

@ -447,9 +447,8 @@ class RaviJITState {
// May slow down compilation
unsigned int validation_ : 1;
// Flag to control calls to GCSTEP
// For some tests we need to disable these calls
unsigned int gcstep_ : 1;
// Flag to control calls to collect
int gcstep_;
// min code size for compilation
int min_code_size_;
@ -509,7 +508,9 @@ class RaviJITState {
int get_validation() const { return validation_; }
void set_validation(bool value) { validation_ = value; }
int get_gcstep() const { return gcstep_; }
void set_gcstep(bool value) { gcstep_ = value; }
void set_gcstep(int value) {
gcstep_ = value > 0 ? value : gcstep_;
}
bool is_tracehook_enabled() const { return tracehook_enabled_; }
void set_tracehook_enabled(bool value) { tracehook_enabled_ = value; }
void incr_allocated_modules() { allocated_modules_++; }

@ -81,7 +81,7 @@ void raviV_setvalidation(struct lua_State *L, int enabled);
int raviV_getvalidation(struct lua_State *L);
/* Enable calls to GCSTEP */
void raviV_setgcstep(struct lua_State *L, int enabled);
void raviV_setgcstep(struct lua_State *L, int value);
int raviV_getgcstep(struct lua_State *L);
/* Enable or disable trace hook */

@ -150,9 +150,9 @@ end
report"gc.lua"
local f = assert(loadfile('gc.lua'))
if ravi then ravi.gcstep(false) end
if ravi then ravi.gcstep(0) end
f()
if ravi then ravi.gcstep(true) end
if ravi then ravi.gcstep(300) end
if not ravi or not ravi.auto() or ravi.tracehook() then
-- in JIT mode we need tracehook enabled
dofile('db.lua')

@ -1324,6 +1324,23 @@ bool RaviCodeGenerator::compile(lua_State *L, Proto *p,
// Set flag so we can avoid recursive calls
module->owner()->set_compiling_flag(true);
// The Lua GC doesn't know about memory allocated by the JIT
// compiler; this means that if lots of functions are being compiled
// such as in the test cases, then memory usage can grow very large
// as the GC is blissfully unaware of the actual memory in use
// To workaround this issue we tell the GC that we increased
// memory usage by approximately n kbytes where n is the
// number of bytecodes in the function compiled
int gcstep = this->jitState_->get_gcstep();
if (gcstep > 0 && (id_ % gcstep) == 0) {
// The unlock/lock sequence below is to satisfy ltests
// If the lock allowed recursion then this would not be
// required. In real code the locking is no-op.
lua_unlock(L);
lua_gc(L, LUA_GCCOLLECT, 0);
lua_lock(L);
}
// The functions constants
TValue *k = p->k;
@ -1914,21 +1931,7 @@ bool RaviCodeGenerator::compile(lua_State *L, Proto *p,
fprintf(stderr, "LLVM Code Verification failed\n");
exit(1);
}
// The Lua GC doesn't know about memory allocated by the JIT
// compiler; this means that if lots of functions are being compiled
// such as in the test cases, then memory usage can grow very large
// as the GC is blissfully unaware of the actual memory in use
// To workaround this issue we tell the GC that we increased
// memory usage by approximately n kbytes where n is the
// number of bytecodes in the function compiled
if (module->owner()->get_gcstep()) {
// The unlock/lock sequence below is to satisfy ltests
// If the lock allowed recursion then this would not be
// required. In real code the locking is no-op.
lua_unlock(L);
lua_gc(L, LUA_GCSTEP, n); // nKbytes?
lua_lock(L);
}
ravi::RaviJITFunction *llvm_func = f.release();
p->ravi_jit.jit_data = reinterpret_cast<void *>(llvm_func);
p->ravi_jit.jit_function = nullptr;

@ -124,7 +124,7 @@ RaviJITState::RaviJITState()
verbosity_(0),
tracehook_enabled_(false),
validation_(false),
gcstep_(true),
gcstep_(300),
min_code_size_(150),
min_exec_count_(50),
allocated_modules_(0),
@ -859,7 +859,7 @@ int raviV_getvalidation(lua_State *L) {
void raviV_setgcstep(lua_State *L, int value) {
global_State *G = G(L);
if (!G->ravi_state) return;
G->ravi_state->jit->set_gcstep(value != 0);
G->ravi_state->jit->set_gcstep(value);
}
int raviV_getgcstep(lua_State *L) {
global_State *G = G(L);

@ -196,7 +196,7 @@ static int ravi_validation(lua_State *L) {
int n = lua_gettop(L);
int oldvalue = raviV_getvalidation(L);
if (n == 1) {
int value = lua_tointeger(L, 1);
int value = lua_toboolean(L, 1);
raviV_setvalidation(L, value);
}
lua_pushboolean(L, oldvalue);

Loading…
Cancel
Save