Make Allocator chunk size customizable and don't free the initial chunk upon reset (521881, r=dvander).

This commit is contained in:
Andreas Gal 2009-10-12 14:52:07 -07:00
parent 8f9daae9e4
commit e42ed339d4
4 changed files with 33 additions and 17 deletions

View File

@ -2462,7 +2462,7 @@ TraceRecorder::~TraceRecorder()
TrashTree(cx, whichTreesToTrash[i]);
/* Purge the tempAlloc used during recording. */
tempAlloc.reset();
tempAlloc.reset(true);
traceMonitor->lirbuf->clear();
forgetGuardedShapes();
@ -7482,8 +7482,8 @@ js_InitJIT(JSTraceMonitor *tm)
JS_ASSERT(!tm->dataAlloc && !tm->traceAlloc && !tm->codeAlloc);
tm->dataAlloc = new VMAllocator();
tm->traceAlloc = new VMAllocator();
tm->tempAlloc = new VMAllocator();
tm->reTempAlloc = new VMAllocator();
tm->tempAlloc = new VMAllocator(65536);
tm->reTempAlloc = new VMAllocator(65536);
tm->codeAlloc = new CodeAlloc();
tm->frameCache = new FrameInfoCache(tm->dataAlloc);
tm->flush();

View File

@ -495,7 +495,9 @@ class VMAllocator : public nanojit::Allocator
{
public:
VMAllocator() : mOutOfMemory(false), mSize(0)
/* Use a chunk size slightly smaller than a page in case malloc wants a header. */
VMAllocator(size_t minChunk = 4088) :
nanojit::Allocator(minChunk), mOutOfMemory(false), mSize(0)
{}
size_t size() {
@ -753,7 +755,6 @@ struct InterpState
// Used to communicate the location of the return value in case of a deep bail.
double* deepBailSp;
// Used when calling natives from trace to root the vp vector.
uintN nativeVpLen;
jsval *nativeVp;

View File

@ -43,8 +43,9 @@
namespace nanojit
{
Allocator::Allocator()
: current_chunk(NULL)
Allocator::Allocator(size_t minChunk)
: minChunk(minChunk)
, current_chunk(NULL)
, current_top(NULL)
, current_limit(NULL)
{ }
@ -54,17 +55,17 @@ namespace nanojit
reset();
}
void Allocator::reset()
void Allocator::reset(bool keepFirst)
{
Chunk *c = current_chunk;
while (c) {
Chunk *prev = c->prev;
if (keepFirst && !prev)
break;
freeChunk(c);
c = prev;
}
current_chunk = NULL;
current_top = NULL;
current_limit = NULL;
setChunk(c);
postReset();
}
@ -78,18 +79,28 @@ namespace nanojit
return p;
}
void Allocator::setChunk(Chunk* chunk)
{
if (chunk) {
current_chunk = chunk;
current_top = (char*)chunk->data;
current_limit = (char*)chunk + chunk->size;
} else {
current_chunk = NULL;
current_top = current_limit = NULL;
}
}
void Allocator::fill(size_t nbytes)
{
const size_t minChunk = 2000;
if (nbytes < minChunk)
nbytes = minChunk;
size_t chunkbytes = sizeof(Chunk) + nbytes - sizeof(int64_t);
void* mem = allocChunk(chunkbytes);
Chunk* chunk = (Chunk*) mem;
chunk->prev = current_chunk;
current_chunk = chunk;
current_top = (char*)chunk->data;
current_limit = (char*)mem + chunkbytes;
chunk->size = chunkbytes;
setChunk(chunk);
}
}

View File

@ -51,10 +51,11 @@ namespace nanojit
* proceed.
*/
class Allocator {
size_t minChunk;
public:
Allocator();
Allocator(size_t minChunk = 2000);
~Allocator();
void reset();
void reset(bool keepFirst = false);
/** alloc memory, never return null. */
void* alloc(size_t nbytes) {
@ -74,9 +75,12 @@ namespace nanojit
class Chunk {
public:
Chunk* prev;
size_t size;
int64_t data[1]; // int64_t forces 8-byte alignment.
};
void setChunk(Chunk* chunk);
Chunk* current_chunk;
char* current_top;
char* current_limit;