remove context argument from Allocator::tryAllocate and Allocator::allocate, since we aren't using it after all

This commit is contained in:
Joel Dice 2008-01-14 16:37:24 -07:00
parent 2d042616d0
commit 2f83468b80
12 changed files with 74 additions and 89 deletions

View File

@ -8,8 +8,8 @@ namespace vm {
class Allocator { class Allocator {
public: public:
virtual ~Allocator() { } virtual ~Allocator() { }
virtual void* tryAllocate(void* context, unsigned size, bool executable) = 0; virtual void* tryAllocate(unsigned size, bool executable) = 0;
virtual void* allocate(void* context, unsigned size, bool executable) = 0; virtual void* allocate(unsigned size, bool executable) = 0;
virtual void free(const void* p, unsigned size, bool executable) = 0; virtual void free(const void* p, unsigned size, bool executable) = 0;
}; };

View File

@ -124,7 +124,7 @@ Java_java_lang_ClassLoader_defineClass
ENTER(t, Thread::ActiveState); ENTER(t, Thread::ActiveState);
uint8_t* buffer = static_cast<uint8_t*> uint8_t* buffer = static_cast<uint8_t*>
(t->m->heap->allocate(t, length, false)); (t->m->heap->allocate(length, false));
memcpy(buffer, &byteArrayBody(t, *b, offset), length); memcpy(buffer, &byteArrayBody(t, *b, offset), length);
object c = parseClass(t, buffer, length); object c = parseClass(t, buffer, length);
t->m->heap->free(buffer, length, false); t->m->heap->free(buffer, length, false);

View File

@ -439,27 +439,27 @@ class Context {
Context(MyThread* t, object method, uint8_t* indirectCaller): Context(MyThread* t, object method, uint8_t* indirectCaller):
t(t), t(t),
zone(t->m->system, t->m->heap, t, false, 16 * 1024), zone(t->m->system, t->m->heap, false, 16 * 1024),
c(makeCompiler(t->m->system, t->m->heap, t, &zone, indirectCaller)), c(makeCompiler(t->m->system, t->m->heap, &zone, indirectCaller)),
method(method), method(method),
objectPool(0), objectPool(0),
traceLog(0), traceLog(0),
visitTable(makeVisitTable(t, &zone, method)), visitTable(makeVisitTable(t, &zone, method)),
rootTable(makeRootTable(t, &zone, method)), rootTable(makeRootTable(t, &zone, method)),
eventLog(t->m->system, t->m->heap, t, 1024), eventLog(t->m->system, t->m->heap, 1024),
protector(this) protector(this)
{ } { }
Context(MyThread* t): Context(MyThread* t):
t(t), t(t),
zone(t->m->system, t->m->heap, t, false, LikelyPageSizeInBytes), zone(t->m->system, t->m->heap, false, LikelyPageSizeInBytes),
c(makeCompiler(t->m->system, t->m->heap, t, &zone, 0)), c(makeCompiler(t->m->system, t->m->heap, &zone, 0)),
method(0), method(0),
objectPool(0), objectPool(0),
traceLog(0), traceLog(0),
visitTable(0), visitTable(0),
rootTable(0), rootTable(0),
eventLog(t->m->system, t->m->heap, t, 0), eventLog(t->m->system, t->m->heap, 0),
protector(this) protector(this)
{ } { }
@ -4360,13 +4360,13 @@ class MyProcessor: public Processor {
addressCount(0), addressCount(0),
indirectCaller(0), indirectCaller(0),
indirectCallerSize(0), indirectCallerSize(0),
codeAllocator(s, allocator, 0, true, 64 * 1024) codeAllocator(s, allocator, true, 64 * 1024)
{ } { }
virtual Thread* virtual Thread*
makeThread(Machine* m, object javaThread, Thread* parent) makeThread(Machine* m, object javaThread, Thread* parent)
{ {
MyThread* t = new (m->heap->allocate(parent, sizeof(MyThread), false)) MyThread* t = new (m->heap->allocate(sizeof(MyThread), false))
MyThread(m, javaThread, parent); MyThread(m, javaThread, parent);
t->init(); t->init();
return t; return t;
@ -4506,7 +4506,7 @@ class MyProcessor: public Processor {
MyThread* t = static_cast<MyThread*>(vmt); MyThread* t = static_cast<MyThread*>(vmt);
PROTECT(t, o); PROTECT(t, o);
Reference* r = new (t->m->heap->allocate(t, sizeof(Reference), false)) Reference* r = new (t->m->heap->allocate(sizeof(Reference), false))
Reference(o, &(t->reference)); Reference(o, &(t->reference));
return &(r->target); return &(r->target);
@ -4809,7 +4809,7 @@ namespace vm {
Processor* Processor*
makeProcessor(System* system, Allocator* allocator) makeProcessor(System* system, Allocator* allocator)
{ {
return new (allocator->allocate(0, sizeof(MyProcessor), false)) return new (allocator->allocate(sizeof(MyProcessor), false))
MyProcessor(system, allocator); MyProcessor(system, allocator);
} }

View File

@ -137,12 +137,11 @@ class RegisterData {
class Context { class Context {
public: public:
Context(System* s, Allocator* allocator, void* allocatorContext, Zone* zone, Context(System* s, Allocator* allocator, Zone* zone, void* indirectCaller):
void* indirectCaller):
s(s), s(s),
constantPool(s, allocator, allocatorContext, BytesPerWord * 32), constantPool(s, allocator, BytesPerWord * 32),
plan(s, allocator, allocatorContext, 1024), plan(s, allocator, 1024),
code(s, allocator, allocatorContext, 1024), code(s, allocator, 1024),
zone(zone), zone(zone),
indirectCaller(reinterpret_cast<intptr_t>(indirectCaller)), indirectCaller(reinterpret_cast<intptr_t>(indirectCaller)),
segmentTable(0), segmentTable(0),
@ -2382,9 +2381,9 @@ writeCode(Context* c)
class MyCompiler: public Compiler { class MyCompiler: public Compiler {
public: public:
MyCompiler(System* s, Allocator* allocator, void* allocatorContext, MyCompiler(System* s, Allocator* allocator, Zone* zone,
Zone* zone, void* indirectCaller): void* indirectCaller):
c(s, allocator, allocatorContext, zone, indirectCaller) c(s, allocator, zone, indirectCaller)
{ } { }
virtual Promise* machineIp(unsigned logicalIp) { virtual Promise* machineIp(unsigned logicalIp) {
@ -2870,11 +2869,11 @@ MyPromise::value(Compiler* compiler)
namespace vm { namespace vm {
Compiler* Compiler*
makeCompiler(System* system, Allocator* allocator, void* allocatorContext, makeCompiler(System* system, Allocator* allocator, Zone* zone,
Zone* zone, void* indirectCaller) void* indirectCaller)
{ {
return new (zone->allocate(sizeof(MyCompiler))) return new (zone->allocate(sizeof(MyCompiler)))
MyCompiler(system, allocator, allocatorContext, zone, indirectCaller); MyCompiler(system, allocator, zone, indirectCaller);
} }
} // namespace v } // namespace v

View File

@ -141,8 +141,8 @@ class Compiler {
}; };
Compiler* Compiler*
makeCompiler(System* system, Allocator* allocator, void* allocatorContext, makeCompiler(System* system, Allocator* allocator, Zone* zone,
Zone* zone, void* indirectCaller); void* indirectCaller);
} // namespace vm } // namespace vm

View File

@ -52,8 +52,7 @@ void assert(Context*, bool);
#endif #endif
System* system(Context*); System* system(Context*);
void* tryAllocate(Context* c, void* clientContext, unsigned size, void* tryAllocate(Context* c, unsigned size, bool executable);
bool executable);
void free(Context* c, const void* p, unsigned size, bool executable); void free(Context* c, const void* p, unsigned size, bool executable);
inline void* inline void*
@ -310,7 +309,7 @@ class Segment {
while (data == 0) { while (data == 0) {
data = static_cast<uintptr_t*> data = static_cast<uintptr_t*>
(tryAllocate (tryAllocate
(context, 0, (footprint(capacity_)) * BytesPerWord, false)); (context, (footprint(capacity_)) * BytesPerWord, false));
if (data == 0) { if (data == 0) {
if (capacity_ > minimum) { if (capacity_ > minimum) {
@ -1612,15 +1611,10 @@ collect(Context* c)
} }
} }
void* tryAllocate(Context* c, void* clientContext, unsigned size, void* tryAllocate(Context* c, unsigned size, bool executable)
bool executable)
{ {
ACQUIRE(c->lock); ACQUIRE(c->lock);
if (clientContext and size + c->count >= c->limit) {
c->client->collect(clientContext, Heap::MajorCollection);
}
if (size + c->count < c->limit) { if (size + c->count < c->limit) {
void* p = c->system->tryAllocate(size, executable); void* p = c->system->tryAllocate(size, executable);
if (p) { if (p) {
@ -1654,14 +1648,12 @@ class MyHeap: public Heap {
c.client = client; c.client = client;
} }
virtual void* tryAllocate(void* clientContext, unsigned size, virtual void* tryAllocate(unsigned size, bool executable) {
bool executable) return ::tryAllocate(&c, size, executable);
{
return ::tryAllocate(&c, clientContext, size, executable);
} }
virtual void* allocate(void* clientContext, unsigned size, bool executable) { virtual void* allocate(unsigned size, bool executable) {
void* p = ::tryAllocate(&c, clientContext, size, executable); void* p = ::tryAllocate(&c, size, executable);
expect(c.system, p); expect(c.system, p);
return p; return p;
} }
@ -1677,21 +1669,20 @@ class MyHeap: public Heap {
::collect(&c); ::collect(&c);
} }
virtual void* allocateFixed(Allocator* allocator, void* clientContext, virtual void* allocateFixed(Allocator* allocator, unsigned sizeInWords,
unsigned sizeInWords, bool objectMask, bool objectMask, unsigned* totalInBytes)
unsigned* totalInBytes)
{ {
*totalInBytes = Fixie::totalSize(sizeInWords, objectMask); *totalInBytes = Fixie::totalSize(sizeInWords, objectMask);
return (new (allocator->allocate(clientContext, *totalInBytes, false)) return (new (allocator->allocate(*totalInBytes, false))
Fixie(sizeInWords, objectMask, &(c.fixies), false))->body(); Fixie(sizeInWords, objectMask, &(c.fixies), false))->body();
} }
virtual void* allocateImmortal(Allocator* allocator, void* clientContext, virtual void* allocateImmortal(Allocator* allocator, unsigned sizeInWords,
unsigned sizeInWords, bool executable, bool executable, bool objectMask,
bool objectMask, unsigned* totalInBytes) unsigned* totalInBytes)
{ {
*totalInBytes = Fixie::totalSize(sizeInWords, objectMask); *totalInBytes = Fixie::totalSize(sizeInWords, objectMask);
return (new (allocator->allocate(clientContext, *totalInBytes, executable)) return (new (allocator->allocate(*totalInBytes, executable))
Fixie(sizeInWords, objectMask, &(c.tenuredFixies), true))->body(); Fixie(sizeInWords, objectMask, &(c.tenuredFixies), true))->body();
} }

View File

@ -47,12 +47,11 @@ class Heap: public Allocator {
virtual ~Heap() { } virtual ~Heap() { }
virtual void setClient(Client* client) = 0; virtual void setClient(Client* client) = 0;
virtual void collect(CollectionType type, unsigned footprint) = 0; virtual void collect(CollectionType type, unsigned footprint) = 0;
virtual void* allocateFixed(Allocator* allocator, void* context, virtual void* allocateFixed(Allocator* allocator, unsigned sizeInWords,
unsigned sizeInWords, bool objectMask, bool objectMask, unsigned* totalInBytes) = 0;
unsigned* totalInBytes) = 0; virtual void* allocateImmortal(Allocator* allocator, unsigned sizeInWords,
virtual void* allocateImmortal(Allocator* allocator, void* context, bool executable, bool objectMask,
unsigned sizeInWords, bool executable, unsigned* totalInBytes) = 0;
bool objectMask, unsigned* totalInBytes) = 0;
virtual bool needsMark(void* p) = 0; virtual bool needsMark(void* p) = 0;
virtual void mark(void* p, unsigned offset, unsigned count) = 0; virtual void mark(void* p, unsigned offset, unsigned count) = 0;
virtual void pad(void* p) = 0; virtual void pad(void* p) = 0;

View File

@ -2819,7 +2819,7 @@ class MyProcessor: public Processor {
virtual vm::Thread* virtual vm::Thread*
makeThread(Machine* m, object javaThread, vm::Thread* parent) makeThread(Machine* m, object javaThread, vm::Thread* parent)
{ {
Thread* t = new (m->heap->allocate(parent, sizeof(Thread), false)) Thread* t = new (m->heap->allocate(sizeof(Thread), false))
Thread(m, javaThread, parent); Thread(m, javaThread, parent);
t->init(); t->init();
return t; return t;
@ -3034,7 +3034,7 @@ namespace vm {
Processor* Processor*
makeProcessor(System* system, Allocator* allocator) makeProcessor(System* system, Allocator* allocator)
{ {
return new (allocator->allocate(0, sizeof(MyProcessor), false)) return new (allocator->allocate(sizeof(MyProcessor), false))
MyProcessor(system, allocator); MyProcessor(system, allocator);
} }

View File

@ -91,7 +91,7 @@ GetStringUTFChars(Thread* t, jstring s, jboolean* isCopy)
ENTER(t, Thread::ActiveState); ENTER(t, Thread::ActiveState);
char* chars = static_cast<char*> char* chars = static_cast<char*>
(t->m->heap->allocate(t, stringLength(t, *s) + 1, false)); (t->m->heap->allocate(stringLength(t, *s) + 1, false));
stringChars(t, *s, chars); stringChars(t, *s, chars);
if (isCopy) *isCopy = true; if (isCopy) *isCopy = true;
@ -1109,7 +1109,7 @@ NewGlobalRef(Thread* t, jobject o)
ACQUIRE(t, t->m->referenceLock); ACQUIRE(t, t->m->referenceLock);
if (o) { if (o) {
Reference* r = new (t->m->heap->allocate(t, sizeof(Reference), false)) Reference* r = new (t->m->heap->allocate(sizeof(Reference), false))
Reference(*o, &(t->m->jniReferences)); Reference(*o, &(t->m->jniReferences));
return &(r->target); return &(r->target);
@ -1254,7 +1254,7 @@ GetBooleanArrayElements(Thread* t, jbooleanArray array, jboolean* isCopy)
ENTER(t, Thread::ActiveState); ENTER(t, Thread::ActiveState);
unsigned size = booleanArrayLength(t, *array) * sizeof(jboolean); unsigned size = booleanArrayLength(t, *array) * sizeof(jboolean);
jboolean* p = static_cast<jboolean*>(t->m->heap->allocate(t, size, false)); jboolean* p = static_cast<jboolean*>(t->m->heap->allocate(size, false));
if (size) { if (size) {
memcpy(p, &booleanArrayBody(t, *array, 0), size); memcpy(p, &booleanArrayBody(t, *array, 0), size);
} }
@ -1272,7 +1272,7 @@ GetByteArrayElements(Thread* t, jbyteArray array, jboolean* isCopy)
ENTER(t, Thread::ActiveState); ENTER(t, Thread::ActiveState);
unsigned size = byteArrayLength(t, *array) * sizeof(jbyte); unsigned size = byteArrayLength(t, *array) * sizeof(jbyte);
jbyte* p = static_cast<jbyte*>(t->m->heap->allocate(t, size, false)); jbyte* p = static_cast<jbyte*>(t->m->heap->allocate(size, false));
if (size) { if (size) {
memcpy(p, &byteArrayBody(t, *array, 0), size); memcpy(p, &byteArrayBody(t, *array, 0), size);
} }
@ -1290,7 +1290,7 @@ GetCharArrayElements(Thread* t, jcharArray array, jboolean* isCopy)
ENTER(t, Thread::ActiveState); ENTER(t, Thread::ActiveState);
unsigned size = charArrayLength(t, *array) * sizeof(jchar); unsigned size = charArrayLength(t, *array) * sizeof(jchar);
jchar* p = static_cast<jchar*>(t->m->heap->allocate(t, size, false)); jchar* p = static_cast<jchar*>(t->m->heap->allocate(size, false));
if (size) { if (size) {
memcpy(p, &charArrayBody(t, *array, 0), size); memcpy(p, &charArrayBody(t, *array, 0), size);
} }
@ -1308,7 +1308,7 @@ GetShortArrayElements(Thread* t, jshortArray array, jboolean* isCopy)
ENTER(t, Thread::ActiveState); ENTER(t, Thread::ActiveState);
unsigned size = shortArrayLength(t, *array) * sizeof(jshort); unsigned size = shortArrayLength(t, *array) * sizeof(jshort);
jshort* p = static_cast<jshort*>(t->m->heap->allocate(t, size, false)); jshort* p = static_cast<jshort*>(t->m->heap->allocate(size, false));
if (size) { if (size) {
memcpy(p, &shortArrayBody(t, *array, 0), size); memcpy(p, &shortArrayBody(t, *array, 0), size);
} }
@ -1326,7 +1326,7 @@ GetIntArrayElements(Thread* t, jintArray array, jboolean* isCopy)
ENTER(t, Thread::ActiveState); ENTER(t, Thread::ActiveState);
unsigned size = intArrayLength(t, *array) * sizeof(jint); unsigned size = intArrayLength(t, *array) * sizeof(jint);
jint* p = static_cast<jint*>(t->m->heap->allocate(t, size, false)); jint* p = static_cast<jint*>(t->m->heap->allocate(size, false));
if (size) { if (size) {
memcpy(p, &intArrayBody(t, *array, 0), size); memcpy(p, &intArrayBody(t, *array, 0), size);
} }
@ -1344,7 +1344,7 @@ GetLongArrayElements(Thread* t, jlongArray array, jboolean* isCopy)
ENTER(t, Thread::ActiveState); ENTER(t, Thread::ActiveState);
unsigned size = longArrayLength(t, *array) * sizeof(jlong); unsigned size = longArrayLength(t, *array) * sizeof(jlong);
jlong* p = static_cast<jlong*>(t->m->heap->allocate(t, size, false)); jlong* p = static_cast<jlong*>(t->m->heap->allocate(size, false));
if (size) { if (size) {
memcpy(p, &longArrayBody(t, *array, 0), size); memcpy(p, &longArrayBody(t, *array, 0), size);
} }
@ -1362,7 +1362,7 @@ GetFloatArrayElements(Thread* t, jfloatArray array, jboolean* isCopy)
ENTER(t, Thread::ActiveState); ENTER(t, Thread::ActiveState);
unsigned size = floatArrayLength(t, *array) * sizeof(jfloat); unsigned size = floatArrayLength(t, *array) * sizeof(jfloat);
jfloat* p = static_cast<jfloat*>(t->m->heap->allocate(t, size, false)); jfloat* p = static_cast<jfloat*>(t->m->heap->allocate(size, false));
if (size) { if (size) {
memcpy(p, &floatArrayBody(t, *array, 0), size); memcpy(p, &floatArrayBody(t, *array, 0), size);
} }
@ -1380,7 +1380,7 @@ GetDoubleArrayElements(Thread* t, jdoubleArray array, jboolean* isCopy)
ENTER(t, Thread::ActiveState); ENTER(t, Thread::ActiveState);
unsigned size = doubleArrayLength(t, *array) * sizeof(jdouble); unsigned size = doubleArrayLength(t, *array) * sizeof(jdouble);
jdouble* p = static_cast<jdouble*>(t->m->heap->allocate(t, size, false)); jdouble* p = static_cast<jdouble*>(t->m->heap->allocate(size, false));
if (size) { if (size) {
memcpy(p, &doubleArrayBody(t, *array, 0), size); memcpy(p, &doubleArrayBody(t, *array, 0), size);
} }
@ -1994,7 +1994,7 @@ JNI_CreateJavaVM(Machine** m, Thread** t, void* args)
Finder* f = makeFinder(s, classpath); Finder* f = makeFinder(s, classpath);
Processor* p = makeProcessor(s, h); Processor* p = makeProcessor(s, h);
*m = new (h->allocate(0, sizeof(Machine), false)) Machine(s, h, f, p); *m = new (h->allocate(sizeof(Machine), false)) Machine(s, h, f, p);
if (a->properties) { if (a->properties) {
for (const char** p = a->properties; *p; ++p) { for (const char** p = a->properties; *p; ++p) {

View File

@ -766,7 +766,7 @@ parsePool(Thread* t, Stream& s)
if (count) { if (count) {
uint32_t* index = static_cast<uint32_t*> uint32_t* index = static_cast<uint32_t*>
(t->m->heap->allocate(t, count * 4, false)); (t->m->heap->allocate(count * 4, false));
for (unsigned i = 0; i < count; ++i) { for (unsigned i = 0; i < count; ++i) {
index[i] = s.position(); index[i] = s.position();
@ -1778,7 +1778,7 @@ Machine::Machine(System* system, Heap* heap, Finder* finder,
Processor* processor): Processor* processor):
vtable(&javaVMVTable), vtable(&javaVMVTable),
system(system), system(system),
heapClient(new (heap->allocate(0, sizeof(HeapClient), false)) heapClient(new (heap->allocate(sizeof(HeapClient), false))
HeapClient(this)), HeapClient(this)),
heap(heap), heap(heap),
finder(finder), finder(finder),
@ -1869,7 +1869,7 @@ Thread::Thread(Machine* m, object javaThread, Thread* parent):
protector(0), protector(0),
runnable(this), runnable(this),
defaultHeap(static_cast<uintptr_t*> defaultHeap(static_cast<uintptr_t*>
(m->heap->allocate(parent, HeapSizeInBytes, false))), (m->heap->allocate(HeapSizeInBytes, false))),
heap(defaultHeap) heap(defaultHeap)
#ifdef VM_STRESS #ifdef VM_STRESS
, stress(false) , stress(false)
@ -2185,7 +2185,7 @@ allocate3(Thread* t, Allocator* allocator, Machine::AllocationType type,
t->heap = 0; t->heap = 0;
if (t->m->heapPoolIndex < Machine::HeapPoolSize) { if (t->m->heapPoolIndex < Machine::HeapPoolSize) {
t->heap = static_cast<uintptr_t*> t->heap = static_cast<uintptr_t*>
(t->m->heap->tryAllocate(0, Thread::HeapSizeInBytes, false)); (t->m->heap->tryAllocate(Thread::HeapSizeInBytes, false));
if (t->heap) { if (t->heap) {
t->m->heapPool[t->m->heapPoolIndex++] = t->heap; t->m->heapPool[t->m->heapPoolIndex++] = t->heap;
t->heapOffset += t->heapIndex; t->heapOffset += t->heapIndex;
@ -2208,7 +2208,7 @@ allocate3(Thread* t, Allocator* allocator, Machine::AllocationType type,
unsigned total; unsigned total;
object o = static_cast<object> object o = static_cast<object>
(t->m->heap->allocateFixed (t->m->heap->allocateFixed
(allocator, t, ceiling(sizeInBytes, BytesPerWord), objectMask, &total)); (allocator, ceiling(sizeInBytes, BytesPerWord), objectMask, &total));
cast<uintptr_t>(o, 0) = FixedMark; cast<uintptr_t>(o, 0) = FixedMark;
@ -2221,7 +2221,7 @@ allocate3(Thread* t, Allocator* allocator, Machine::AllocationType type,
unsigned total; unsigned total;
object o = static_cast<object> object o = static_cast<object>
(t->m->heap->allocateImmortal (t->m->heap->allocateImmortal
(allocator, t, ceiling(sizeInBytes, BytesPerWord), (allocator, ceiling(sizeInBytes, BytesPerWord),
executable, objectMask, &total)); executable, objectMask, &total));
cast<uintptr_t>(o, 0) = FixedMark; cast<uintptr_t>(o, 0) = FixedMark;

View File

@ -7,11 +7,9 @@ namespace vm {
class Vector { class Vector {
public: public:
Vector(System* s, Allocator* allocator, void* context, Vector(System* s, Allocator* allocator, unsigned minimumCapacity):
unsigned minimumCapacity):
s(s), s(s),
allocator(allocator), allocator(allocator),
context(context),
data(0), data(0),
position(0), position(0),
capacity(0), capacity(0),
@ -44,7 +42,7 @@ class Vector {
unsigned newCapacity = max unsigned newCapacity = max
(position + space, max(minimumCapacity, capacity * 2)); (position + space, max(minimumCapacity, capacity * 2));
uint8_t* newData = static_cast<uint8_t*> uint8_t* newData = static_cast<uint8_t*>
(allocator->allocate(context, newCapacity, false)); (allocator->allocate(newCapacity, false));
if (data) { if (data) {
memcpy(newData, data, position); memcpy(newData, data, position);
allocator->free(data, capacity, false); allocator->free(data, capacity, false);
@ -134,7 +132,6 @@ class Vector {
System* s; System* s;
Allocator* allocator; Allocator* allocator;
void* context;
uint8_t* data; uint8_t* data;
unsigned position; unsigned position;
unsigned capacity; unsigned capacity;

View File

@ -17,11 +17,10 @@ class Zone: public Allocator {
uint8_t data[0]; uint8_t data[0];
}; };
Zone(System* s, Allocator* allocator, void* context, bool executable, Zone(System* s, Allocator* allocator, bool executable,
unsigned minimumFootprint): unsigned minimumFootprint):
s(s), s(s),
allocator(allocator), allocator(allocator),
context(context),
executable(executable), executable(executable),
segment(0), segment(0),
position(0), position(0),
@ -40,7 +39,7 @@ class Zone: public Allocator {
} }
} }
bool ensure(void* context, unsigned space, bool executable) { bool ensure(unsigned space, bool executable) {
if (segment == 0 or position + space > segment->size) { if (segment == 0 or position + space > segment->size) {
unsigned size = max unsigned size = max
(space, max (space, max
@ -51,10 +50,10 @@ class Zone: public Allocator {
size = (size + (LikelyPageSizeInBytes - 1)) size = (size + (LikelyPageSizeInBytes - 1))
& ~(LikelyPageSizeInBytes - 1); & ~(LikelyPageSizeInBytes - 1);
void* p = allocator->tryAllocate(context, size, executable); void* p = allocator->tryAllocate(size, executable);
if (p == 0) { if (p == 0) {
size = space + sizeof(Segment); size = space + sizeof(Segment);
void* p = allocator->tryAllocate(context, size, executable); void* p = allocator->tryAllocate(size, executable);
if (p == 0) { if (p == 0) {
return false; return false;
} }
@ -66,11 +65,11 @@ class Zone: public Allocator {
return true; return true;
} }
virtual void* tryAllocate(void* context, unsigned size, bool executable) { virtual void* tryAllocate(unsigned size, bool executable) {
assert(s, executable == this->executable); assert(s, executable == this->executable);
size = pad(size); size = pad(size);
if (ensure(context, size, executable)) { if (ensure(size, executable)) {
void* r = segment->data + position; void* r = segment->data + position;
position += size; position += size;
return r; return r;
@ -79,10 +78,10 @@ class Zone: public Allocator {
} }
} }
virtual void* allocate(void* context, unsigned size, bool executable) { virtual void* allocate(unsigned size, bool executable) {
assert(s, executable == this->executable); assert(s, executable == this->executable);
void* p = tryAllocate(context, size, executable); void* p = tryAllocate(size, executable);
expect(s, p); expect(s, p);
return p; return p;
} }
@ -93,7 +92,7 @@ class Zone: public Allocator {
} }
void* allocate(unsigned size) { void* allocate(unsigned size) {
return allocate(context, size, executable); return allocate(size, executable);
} }
System* s; System* s;