mirror of
https://github.com/corda/corda.git
synced 2025-01-05 20:54:13 +00:00
remove context argument from Allocator::tryAllocate and Allocator::allocate, since we aren't using it after all
This commit is contained in:
parent
2d042616d0
commit
2f83468b80
@ -8,8 +8,8 @@ namespace vm {
|
||||
class Allocator {
|
||||
public:
|
||||
virtual ~Allocator() { }
|
||||
virtual void* tryAllocate(void* context, unsigned size, bool executable) = 0;
|
||||
virtual void* allocate(void* context, unsigned size, bool executable) = 0;
|
||||
virtual void* tryAllocate(unsigned size, bool executable) = 0;
|
||||
virtual void* allocate(unsigned size, bool executable) = 0;
|
||||
virtual void free(const void* p, unsigned size, bool executable) = 0;
|
||||
};
|
||||
|
||||
|
@ -124,7 +124,7 @@ Java_java_lang_ClassLoader_defineClass
|
||||
ENTER(t, Thread::ActiveState);
|
||||
|
||||
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);
|
||||
object c = parseClass(t, buffer, length);
|
||||
t->m->heap->free(buffer, length, false);
|
||||
|
@ -439,27 +439,27 @@ class Context {
|
||||
|
||||
Context(MyThread* t, object method, uint8_t* indirectCaller):
|
||||
t(t),
|
||||
zone(t->m->system, t->m->heap, t, false, 16 * 1024),
|
||||
c(makeCompiler(t->m->system, t->m->heap, t, &zone, indirectCaller)),
|
||||
zone(t->m->system, t->m->heap, false, 16 * 1024),
|
||||
c(makeCompiler(t->m->system, t->m->heap, &zone, indirectCaller)),
|
||||
method(method),
|
||||
objectPool(0),
|
||||
traceLog(0),
|
||||
visitTable(makeVisitTable(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)
|
||||
{ }
|
||||
|
||||
Context(MyThread* t):
|
||||
t(t),
|
||||
zone(t->m->system, t->m->heap, t, false, LikelyPageSizeInBytes),
|
||||
c(makeCompiler(t->m->system, t->m->heap, t, &zone, 0)),
|
||||
zone(t->m->system, t->m->heap, false, LikelyPageSizeInBytes),
|
||||
c(makeCompiler(t->m->system, t->m->heap, &zone, 0)),
|
||||
method(0),
|
||||
objectPool(0),
|
||||
traceLog(0),
|
||||
visitTable(0),
|
||||
rootTable(0),
|
||||
eventLog(t->m->system, t->m->heap, t, 0),
|
||||
eventLog(t->m->system, t->m->heap, 0),
|
||||
protector(this)
|
||||
{ }
|
||||
|
||||
@ -4360,13 +4360,13 @@ class MyProcessor: public Processor {
|
||||
addressCount(0),
|
||||
indirectCaller(0),
|
||||
indirectCallerSize(0),
|
||||
codeAllocator(s, allocator, 0, true, 64 * 1024)
|
||||
codeAllocator(s, allocator, true, 64 * 1024)
|
||||
{ }
|
||||
|
||||
virtual Thread*
|
||||
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);
|
||||
t->init();
|
||||
return t;
|
||||
@ -4506,7 +4506,7 @@ class MyProcessor: public Processor {
|
||||
MyThread* t = static_cast<MyThread*>(vmt);
|
||||
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));
|
||||
|
||||
return &(r->target);
|
||||
@ -4809,7 +4809,7 @@ namespace vm {
|
||||
Processor*
|
||||
makeProcessor(System* system, Allocator* allocator)
|
||||
{
|
||||
return new (allocator->allocate(0, sizeof(MyProcessor), false))
|
||||
return new (allocator->allocate(sizeof(MyProcessor), false))
|
||||
MyProcessor(system, allocator);
|
||||
}
|
||||
|
||||
|
@ -137,12 +137,11 @@ class RegisterData {
|
||||
|
||||
class Context {
|
||||
public:
|
||||
Context(System* s, Allocator* allocator, void* allocatorContext, Zone* zone,
|
||||
void* indirectCaller):
|
||||
Context(System* s, Allocator* allocator, Zone* zone, void* indirectCaller):
|
||||
s(s),
|
||||
constantPool(s, allocator, allocatorContext, BytesPerWord * 32),
|
||||
plan(s, allocator, allocatorContext, 1024),
|
||||
code(s, allocator, allocatorContext, 1024),
|
||||
constantPool(s, allocator, BytesPerWord * 32),
|
||||
plan(s, allocator, 1024),
|
||||
code(s, allocator, 1024),
|
||||
zone(zone),
|
||||
indirectCaller(reinterpret_cast<intptr_t>(indirectCaller)),
|
||||
segmentTable(0),
|
||||
@ -2382,9 +2381,9 @@ writeCode(Context* c)
|
||||
|
||||
class MyCompiler: public Compiler {
|
||||
public:
|
||||
MyCompiler(System* s, Allocator* allocator, void* allocatorContext,
|
||||
Zone* zone, void* indirectCaller):
|
||||
c(s, allocator, allocatorContext, zone, indirectCaller)
|
||||
MyCompiler(System* s, Allocator* allocator, Zone* zone,
|
||||
void* indirectCaller):
|
||||
c(s, allocator, zone, indirectCaller)
|
||||
{ }
|
||||
|
||||
virtual Promise* machineIp(unsigned logicalIp) {
|
||||
@ -2870,11 +2869,11 @@ MyPromise::value(Compiler* compiler)
|
||||
namespace vm {
|
||||
|
||||
Compiler*
|
||||
makeCompiler(System* system, Allocator* allocator, void* allocatorContext,
|
||||
Zone* zone, void* indirectCaller)
|
||||
makeCompiler(System* system, Allocator* allocator, Zone* zone,
|
||||
void* indirectCaller)
|
||||
{
|
||||
return new (zone->allocate(sizeof(MyCompiler)))
|
||||
MyCompiler(system, allocator, allocatorContext, zone, indirectCaller);
|
||||
MyCompiler(system, allocator, zone, indirectCaller);
|
||||
}
|
||||
|
||||
} // namespace v
|
||||
|
@ -141,8 +141,8 @@ class Compiler {
|
||||
};
|
||||
|
||||
Compiler*
|
||||
makeCompiler(System* system, Allocator* allocator, void* allocatorContext,
|
||||
Zone* zone, void* indirectCaller);
|
||||
makeCompiler(System* system, Allocator* allocator, Zone* zone,
|
||||
void* indirectCaller);
|
||||
|
||||
} // namespace vm
|
||||
|
||||
|
37
src/heap.cpp
37
src/heap.cpp
@ -52,8 +52,7 @@ void assert(Context*, bool);
|
||||
#endif
|
||||
|
||||
System* system(Context*);
|
||||
void* tryAllocate(Context* c, void* clientContext, unsigned size,
|
||||
bool executable);
|
||||
void* tryAllocate(Context* c, unsigned size, bool executable);
|
||||
void free(Context* c, const void* p, unsigned size, bool executable);
|
||||
|
||||
inline void*
|
||||
@ -310,7 +309,7 @@ class Segment {
|
||||
while (data == 0) {
|
||||
data = static_cast<uintptr_t*>
|
||||
(tryAllocate
|
||||
(context, 0, (footprint(capacity_)) * BytesPerWord, false));
|
||||
(context, (footprint(capacity_)) * BytesPerWord, false));
|
||||
|
||||
if (data == 0) {
|
||||
if (capacity_ > minimum) {
|
||||
@ -1612,15 +1611,10 @@ collect(Context* c)
|
||||
}
|
||||
}
|
||||
|
||||
void* tryAllocate(Context* c, void* clientContext, unsigned size,
|
||||
bool executable)
|
||||
void* tryAllocate(Context* c, unsigned size, bool executable)
|
||||
{
|
||||
ACQUIRE(c->lock);
|
||||
|
||||
if (clientContext and size + c->count >= c->limit) {
|
||||
c->client->collect(clientContext, Heap::MajorCollection);
|
||||
}
|
||||
|
||||
if (size + c->count < c->limit) {
|
||||
void* p = c->system->tryAllocate(size, executable);
|
||||
if (p) {
|
||||
@ -1654,14 +1648,12 @@ class MyHeap: public Heap {
|
||||
c.client = client;
|
||||
}
|
||||
|
||||
virtual void* tryAllocate(void* clientContext, unsigned size,
|
||||
bool executable)
|
||||
{
|
||||
return ::tryAllocate(&c, clientContext, size, executable);
|
||||
virtual void* tryAllocate(unsigned size, bool executable) {
|
||||
return ::tryAllocate(&c, size, executable);
|
||||
}
|
||||
|
||||
virtual void* allocate(void* clientContext, unsigned size, bool executable) {
|
||||
void* p = ::tryAllocate(&c, clientContext, size, executable);
|
||||
virtual void* allocate(unsigned size, bool executable) {
|
||||
void* p = ::tryAllocate(&c, size, executable);
|
||||
expect(c.system, p);
|
||||
return p;
|
||||
}
|
||||
@ -1677,21 +1669,20 @@ class MyHeap: public Heap {
|
||||
::collect(&c);
|
||||
}
|
||||
|
||||
virtual void* allocateFixed(Allocator* allocator, void* clientContext,
|
||||
unsigned sizeInWords, bool objectMask,
|
||||
unsigned* totalInBytes)
|
||||
virtual void* allocateFixed(Allocator* allocator, unsigned sizeInWords,
|
||||
bool objectMask, unsigned* totalInBytes)
|
||||
{
|
||||
*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();
|
||||
}
|
||||
|
||||
virtual void* allocateImmortal(Allocator* allocator, void* clientContext,
|
||||
unsigned sizeInWords, bool executable,
|
||||
bool objectMask, unsigned* totalInBytes)
|
||||
virtual void* allocateImmortal(Allocator* allocator, unsigned sizeInWords,
|
||||
bool executable, bool objectMask,
|
||||
unsigned* totalInBytes)
|
||||
{
|
||||
*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();
|
||||
}
|
||||
|
||||
|
11
src/heap.h
11
src/heap.h
@ -47,12 +47,11 @@ class Heap: public Allocator {
|
||||
virtual ~Heap() { }
|
||||
virtual void setClient(Client* client) = 0;
|
||||
virtual void collect(CollectionType type, unsigned footprint) = 0;
|
||||
virtual void* allocateFixed(Allocator* allocator, void* context,
|
||||
unsigned sizeInWords, bool objectMask,
|
||||
unsigned* totalInBytes) = 0;
|
||||
virtual void* allocateImmortal(Allocator* allocator, void* context,
|
||||
unsigned sizeInWords, bool executable,
|
||||
bool objectMask, unsigned* totalInBytes) = 0;
|
||||
virtual void* allocateFixed(Allocator* allocator, unsigned sizeInWords,
|
||||
bool objectMask, unsigned* totalInBytes) = 0;
|
||||
virtual void* allocateImmortal(Allocator* allocator, unsigned sizeInWords,
|
||||
bool executable, bool objectMask,
|
||||
unsigned* totalInBytes) = 0;
|
||||
virtual bool needsMark(void* p) = 0;
|
||||
virtual void mark(void* p, unsigned offset, unsigned count) = 0;
|
||||
virtual void pad(void* p) = 0;
|
||||
|
@ -2819,7 +2819,7 @@ class MyProcessor: public Processor {
|
||||
virtual vm::Thread*
|
||||
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);
|
||||
t->init();
|
||||
return t;
|
||||
@ -3034,7 +3034,7 @@ namespace vm {
|
||||
Processor*
|
||||
makeProcessor(System* system, Allocator* allocator)
|
||||
{
|
||||
return new (allocator->allocate(0, sizeof(MyProcessor), false))
|
||||
return new (allocator->allocate(sizeof(MyProcessor), false))
|
||||
MyProcessor(system, allocator);
|
||||
}
|
||||
|
||||
|
@ -91,7 +91,7 @@ GetStringUTFChars(Thread* t, jstring s, jboolean* isCopy)
|
||||
ENTER(t, Thread::ActiveState);
|
||||
|
||||
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);
|
||||
|
||||
if (isCopy) *isCopy = true;
|
||||
@ -1109,7 +1109,7 @@ NewGlobalRef(Thread* t, jobject o)
|
||||
ACQUIRE(t, t->m->referenceLock);
|
||||
|
||||
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));
|
||||
|
||||
return &(r->target);
|
||||
@ -1254,7 +1254,7 @@ GetBooleanArrayElements(Thread* t, jbooleanArray array, jboolean* isCopy)
|
||||
ENTER(t, Thread::ActiveState);
|
||||
|
||||
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) {
|
||||
memcpy(p, &booleanArrayBody(t, *array, 0), size);
|
||||
}
|
||||
@ -1272,7 +1272,7 @@ GetByteArrayElements(Thread* t, jbyteArray array, jboolean* isCopy)
|
||||
ENTER(t, Thread::ActiveState);
|
||||
|
||||
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) {
|
||||
memcpy(p, &byteArrayBody(t, *array, 0), size);
|
||||
}
|
||||
@ -1290,7 +1290,7 @@ GetCharArrayElements(Thread* t, jcharArray array, jboolean* isCopy)
|
||||
ENTER(t, Thread::ActiveState);
|
||||
|
||||
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) {
|
||||
memcpy(p, &charArrayBody(t, *array, 0), size);
|
||||
}
|
||||
@ -1308,7 +1308,7 @@ GetShortArrayElements(Thread* t, jshortArray array, jboolean* isCopy)
|
||||
ENTER(t, Thread::ActiveState);
|
||||
|
||||
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) {
|
||||
memcpy(p, &shortArrayBody(t, *array, 0), size);
|
||||
}
|
||||
@ -1326,7 +1326,7 @@ GetIntArrayElements(Thread* t, jintArray array, jboolean* isCopy)
|
||||
ENTER(t, Thread::ActiveState);
|
||||
|
||||
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) {
|
||||
memcpy(p, &intArrayBody(t, *array, 0), size);
|
||||
}
|
||||
@ -1344,7 +1344,7 @@ GetLongArrayElements(Thread* t, jlongArray array, jboolean* isCopy)
|
||||
ENTER(t, Thread::ActiveState);
|
||||
|
||||
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) {
|
||||
memcpy(p, &longArrayBody(t, *array, 0), size);
|
||||
}
|
||||
@ -1362,7 +1362,7 @@ GetFloatArrayElements(Thread* t, jfloatArray array, jboolean* isCopy)
|
||||
ENTER(t, Thread::ActiveState);
|
||||
|
||||
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) {
|
||||
memcpy(p, &floatArrayBody(t, *array, 0), size);
|
||||
}
|
||||
@ -1380,7 +1380,7 @@ GetDoubleArrayElements(Thread* t, jdoubleArray array, jboolean* isCopy)
|
||||
ENTER(t, Thread::ActiveState);
|
||||
|
||||
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) {
|
||||
memcpy(p, &doubleArrayBody(t, *array, 0), size);
|
||||
}
|
||||
@ -1994,7 +1994,7 @@ JNI_CreateJavaVM(Machine** m, Thread** t, void* args)
|
||||
Finder* f = makeFinder(s, classpath);
|
||||
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) {
|
||||
for (const char** p = a->properties; *p; ++p) {
|
||||
|
@ -766,7 +766,7 @@ parsePool(Thread* t, Stream& s)
|
||||
|
||||
if (count) {
|
||||
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) {
|
||||
index[i] = s.position();
|
||||
@ -1778,7 +1778,7 @@ Machine::Machine(System* system, Heap* heap, Finder* finder,
|
||||
Processor* processor):
|
||||
vtable(&javaVMVTable),
|
||||
system(system),
|
||||
heapClient(new (heap->allocate(0, sizeof(HeapClient), false))
|
||||
heapClient(new (heap->allocate(sizeof(HeapClient), false))
|
||||
HeapClient(this)),
|
||||
heap(heap),
|
||||
finder(finder),
|
||||
@ -1869,7 +1869,7 @@ Thread::Thread(Machine* m, object javaThread, Thread* parent):
|
||||
protector(0),
|
||||
runnable(this),
|
||||
defaultHeap(static_cast<uintptr_t*>
|
||||
(m->heap->allocate(parent, HeapSizeInBytes, false))),
|
||||
(m->heap->allocate(HeapSizeInBytes, false))),
|
||||
heap(defaultHeap)
|
||||
#ifdef VM_STRESS
|
||||
, stress(false)
|
||||
@ -2185,7 +2185,7 @@ allocate3(Thread* t, Allocator* allocator, Machine::AllocationType type,
|
||||
t->heap = 0;
|
||||
if (t->m->heapPoolIndex < Machine::HeapPoolSize) {
|
||||
t->heap = static_cast<uintptr_t*>
|
||||
(t->m->heap->tryAllocate(0, Thread::HeapSizeInBytes, false));
|
||||
(t->m->heap->tryAllocate(Thread::HeapSizeInBytes, false));
|
||||
if (t->heap) {
|
||||
t->m->heapPool[t->m->heapPoolIndex++] = t->heap;
|
||||
t->heapOffset += t->heapIndex;
|
||||
@ -2208,7 +2208,7 @@ allocate3(Thread* t, Allocator* allocator, Machine::AllocationType type,
|
||||
unsigned total;
|
||||
object o = static_cast<object>
|
||||
(t->m->heap->allocateFixed
|
||||
(allocator, t, ceiling(sizeInBytes, BytesPerWord), objectMask, &total));
|
||||
(allocator, ceiling(sizeInBytes, BytesPerWord), objectMask, &total));
|
||||
|
||||
cast<uintptr_t>(o, 0) = FixedMark;
|
||||
|
||||
@ -2221,7 +2221,7 @@ allocate3(Thread* t, Allocator* allocator, Machine::AllocationType type,
|
||||
unsigned total;
|
||||
object o = static_cast<object>
|
||||
(t->m->heap->allocateImmortal
|
||||
(allocator, t, ceiling(sizeInBytes, BytesPerWord),
|
||||
(allocator, ceiling(sizeInBytes, BytesPerWord),
|
||||
executable, objectMask, &total));
|
||||
|
||||
cast<uintptr_t>(o, 0) = FixedMark;
|
||||
|
@ -7,11 +7,9 @@ namespace vm {
|
||||
|
||||
class Vector {
|
||||
public:
|
||||
Vector(System* s, Allocator* allocator, void* context,
|
||||
unsigned minimumCapacity):
|
||||
Vector(System* s, Allocator* allocator, unsigned minimumCapacity):
|
||||
s(s),
|
||||
allocator(allocator),
|
||||
context(context),
|
||||
data(0),
|
||||
position(0),
|
||||
capacity(0),
|
||||
@ -44,7 +42,7 @@ class Vector {
|
||||
unsigned newCapacity = max
|
||||
(position + space, max(minimumCapacity, capacity * 2));
|
||||
uint8_t* newData = static_cast<uint8_t*>
|
||||
(allocator->allocate(context, newCapacity, false));
|
||||
(allocator->allocate(newCapacity, false));
|
||||
if (data) {
|
||||
memcpy(newData, data, position);
|
||||
allocator->free(data, capacity, false);
|
||||
@ -134,7 +132,6 @@ class Vector {
|
||||
|
||||
System* s;
|
||||
Allocator* allocator;
|
||||
void* context;
|
||||
uint8_t* data;
|
||||
unsigned position;
|
||||
unsigned capacity;
|
||||
|
19
src/zone.h
19
src/zone.h
@ -17,11 +17,10 @@ class Zone: public Allocator {
|
||||
uint8_t data[0];
|
||||
};
|
||||
|
||||
Zone(System* s, Allocator* allocator, void* context, bool executable,
|
||||
Zone(System* s, Allocator* allocator, bool executable,
|
||||
unsigned minimumFootprint):
|
||||
s(s),
|
||||
allocator(allocator),
|
||||
context(context),
|
||||
executable(executable),
|
||||
segment(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) {
|
||||
unsigned size = max
|
||||
(space, max
|
||||
@ -51,10 +50,10 @@ class Zone: public Allocator {
|
||||
size = (size + (LikelyPageSizeInBytes - 1))
|
||||
& ~(LikelyPageSizeInBytes - 1);
|
||||
|
||||
void* p = allocator->tryAllocate(context, size, executable);
|
||||
void* p = allocator->tryAllocate(size, executable);
|
||||
if (p == 0) {
|
||||
size = space + sizeof(Segment);
|
||||
void* p = allocator->tryAllocate(context, size, executable);
|
||||
void* p = allocator->tryAllocate(size, executable);
|
||||
if (p == 0) {
|
||||
return false;
|
||||
}
|
||||
@ -66,11 +65,11 @@ class Zone: public Allocator {
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual void* tryAllocate(void* context, unsigned size, bool executable) {
|
||||
virtual void* tryAllocate(unsigned size, bool executable) {
|
||||
assert(s, executable == this->executable);
|
||||
|
||||
size = pad(size);
|
||||
if (ensure(context, size, executable)) {
|
||||
if (ensure(size, executable)) {
|
||||
void* r = segment->data + position;
|
||||
position += size;
|
||||
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);
|
||||
|
||||
void* p = tryAllocate(context, size, executable);
|
||||
void* p = tryAllocate(size, executable);
|
||||
expect(s, p);
|
||||
return p;
|
||||
}
|
||||
@ -93,7 +92,7 @@ class Zone: public Allocator {
|
||||
}
|
||||
|
||||
void* allocate(unsigned size) {
|
||||
return allocate(context, size, executable);
|
||||
return allocate(size, executable);
|
||||
}
|
||||
|
||||
System* s;
|
||||
|
Loading…
Reference in New Issue
Block a user