mirror of
https://github.com/corda/corda.git
synced 2025-02-07 19:40:25 +00:00
use Slice<uint8_t> in FixedAllocator
This commit is contained in:
parent
b083f3df04
commit
a807966143
@ -18,6 +18,7 @@ namespace util {
|
|||||||
|
|
||||||
class Allocator {
|
class Allocator {
|
||||||
public:
|
public:
|
||||||
|
// TODO: use size_t instead of unsigned
|
||||||
virtual void* tryAllocate(unsigned size) = 0;
|
virtual void* tryAllocate(unsigned size) = 0;
|
||||||
virtual void* allocate(unsigned size) = 0;
|
virtual void* allocate(unsigned size) = 0;
|
||||||
virtual void free(const void* p, unsigned size) = 0;
|
virtual void free(const void* p, unsigned size) = 0;
|
||||||
|
@ -13,13 +13,16 @@
|
|||||||
|
|
||||||
#include "allocator.h"
|
#include "allocator.h"
|
||||||
#include "abort.h"
|
#include "abort.h"
|
||||||
|
#include "slice.h"
|
||||||
|
|
||||||
namespace avian {
|
namespace avian {
|
||||||
namespace util {
|
namespace util {
|
||||||
|
|
||||||
|
// An Allocator that allocates, bump-pointer style, out of a pre-defined chunk
|
||||||
|
// of memory.
|
||||||
class FixedAllocator : public Allocator {
|
class FixedAllocator : public Allocator {
|
||||||
public:
|
public:
|
||||||
FixedAllocator(Aborter* a, uint8_t* base, unsigned capacity);
|
FixedAllocator(Aborter* a, Slice<uint8_t> memory);
|
||||||
|
|
||||||
virtual void* tryAllocate(unsigned size);
|
virtual void* tryAllocate(unsigned size);
|
||||||
|
|
||||||
@ -30,11 +33,8 @@ class FixedAllocator : public Allocator {
|
|||||||
virtual void free(const void* p, unsigned size);
|
virtual void free(const void* p, unsigned size);
|
||||||
|
|
||||||
Aborter* a;
|
Aborter* a;
|
||||||
|
Slice<uint8_t> memory;
|
||||||
uint8_t* base;
|
size_t offset;
|
||||||
unsigned capacity;
|
|
||||||
|
|
||||||
unsigned offset;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace util
|
} // namespace util
|
||||||
|
@ -23,6 +23,11 @@ namespace avian {
|
|||||||
namespace codegen {
|
namespace codegen {
|
||||||
class DelayedPromise;
|
class DelayedPromise;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace util {
|
||||||
|
template <class T>
|
||||||
|
class Slice;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace vm {
|
namespace vm {
|
||||||
@ -140,8 +145,8 @@ class Processor {
|
|||||||
virtual object
|
virtual object
|
||||||
getStackTrace(Thread* t, Thread* target) = 0;
|
getStackTrace(Thread* t, Thread* target) = 0;
|
||||||
|
|
||||||
virtual void
|
virtual void initialize(BootImage* image, avian::util::Slice<uint8_t> code)
|
||||||
initialize(BootImage* image, uint8_t* code, unsigned capacity) = 0;
|
= 0;
|
||||||
|
|
||||||
virtual void
|
virtual void
|
||||||
addCompilationHandler(CompilationHandler* handler) = 0;
|
addCompilationHandler(CompilationHandler* handler) = 0;
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
|
|
||||||
#include <avian/util/runtime-array.h>
|
#include <avian/util/runtime-array.h>
|
||||||
#include <avian/util/list.h>
|
#include <avian/util/list.h>
|
||||||
|
#include <avian/util/slice.h>
|
||||||
#include <avian/util/fixed-allocator.h>
|
#include <avian/util/fixed-allocator.h>
|
||||||
|
|
||||||
using namespace vm;
|
using namespace vm;
|
||||||
@ -1640,13 +1641,17 @@ class Frame {
|
|||||||
|
|
||||||
Value absoluteAddressOperand(avian::codegen::Promise* p) {
|
Value absoluteAddressOperand(avian::codegen::Promise* p) {
|
||||||
return context->bootContext
|
return context->bootContext
|
||||||
? c->binaryOp(lir::Add,
|
? c->binaryOp(
|
||||||
TargetBytesPerWord, c->memory
|
lir::Add,
|
||||||
(c->register_(t->arch->thread()), Compiler::AddressType,
|
TargetBytesPerWord,
|
||||||
TARGET_THREAD_CODEIMAGE), c->promiseConstant
|
c->memory(c->register_(t->arch->thread()),
|
||||||
(new(&context->zone)
|
Compiler::AddressType,
|
||||||
avian::codegen::OffsetPromise
|
TARGET_THREAD_CODEIMAGE),
|
||||||
(p, - reinterpret_cast<intptr_t>(codeAllocator(t)->base)),
|
c->promiseConstant(
|
||||||
|
new (&context->zone) avian::codegen::OffsetPromise(
|
||||||
|
p,
|
||||||
|
-reinterpret_cast<intptr_t>(
|
||||||
|
codeAllocator(t)->memory.begin())),
|
||||||
Compiler::AddressType))
|
Compiler::AddressType))
|
||||||
: addressOperand(p);
|
: addressOperand(p);
|
||||||
}
|
}
|
||||||
@ -3130,8 +3135,9 @@ useLongJump(MyThread* t, uintptr_t target)
|
|||||||
{
|
{
|
||||||
uintptr_t reach = t->arch->maximumImmediateJump();
|
uintptr_t reach = t->arch->maximumImmediateJump();
|
||||||
FixedAllocator* a = codeAllocator(t);
|
FixedAllocator* a = codeAllocator(t);
|
||||||
uintptr_t start = reinterpret_cast<uintptr_t>(a->base);
|
uintptr_t start = reinterpret_cast<uintptr_t>(a->memory.begin());
|
||||||
uintptr_t end = reinterpret_cast<uintptr_t>(a->base) + a->capacity;
|
uintptr_t end = reinterpret_cast<uintptr_t>(a->memory.begin())
|
||||||
|
+ a->memory.count;
|
||||||
assert(t, end - start < reach);
|
assert(t, end - start < reach);
|
||||||
|
|
||||||
return (target > end && (target - start) > reach)
|
return (target > end && (target - start) > reach)
|
||||||
@ -6963,8 +6969,7 @@ finish(MyThread* t, FixedAllocator* allocator, Context* context)
|
|||||||
|
|
||||||
// we must acquire the class lock here at the latest
|
// we must acquire the class lock here at the latest
|
||||||
|
|
||||||
unsigned codeSize = c->resolve
|
unsigned codeSize = c->resolve(allocator->memory.begin() + allocator->offset);
|
||||||
(allocator->base + allocator->offset);
|
|
||||||
|
|
||||||
unsigned total = pad(codeSize, TargetBytesPerWord)
|
unsigned total = pad(codeSize, TargetBytesPerWord)
|
||||||
+ pad(c->poolSize(), TargetBytesPerWord);
|
+ pad(c->poolSize(), TargetBytesPerWord);
|
||||||
@ -6983,7 +6988,7 @@ finish(MyThread* t, FixedAllocator* allocator, Context* context)
|
|||||||
FixedSizeOfArray + ((context->objectPoolCount + 1) * BytesPerWord),
|
FixedSizeOfArray + ((context->objectPoolCount + 1) * BytesPerWord),
|
||||||
true);
|
true);
|
||||||
|
|
||||||
context->executableSize = (allocator->base + allocator->offset)
|
context->executableSize = (allocator->memory.begin() + allocator->offset)
|
||||||
- static_cast<uint8_t*>(context->executableStart);
|
- static_cast<uint8_t*>(context->executableStart);
|
||||||
|
|
||||||
initArray(t, pool, context->objectPoolCount + 1);
|
initArray(t, pool, context->objectPoolCount + 1);
|
||||||
@ -8519,7 +8524,7 @@ class MyProcessor: public Processor {
|
|||||||
divideByZeroHandler(Machine::ArithmeticExceptionType,
|
divideByZeroHandler(Machine::ArithmeticExceptionType,
|
||||||
Machine::ArithmeticException,
|
Machine::ArithmeticException,
|
||||||
FixedSizeOfArithmeticException),
|
FixedSizeOfArithmeticException),
|
||||||
codeAllocator(s, 0, 0),
|
codeAllocator(s, Slice<uint8_t>(0, 0)),
|
||||||
callTableSize(0),
|
callTableSize(0),
|
||||||
useNativeFeatures(useNativeFeatures),
|
useNativeFeatures(useNativeFeatures),
|
||||||
compilationHandlers(0)
|
compilationHandlers(0)
|
||||||
@ -8922,9 +8927,10 @@ class MyProcessor: public Processor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
virtual void dispose() {
|
virtual void dispose() {
|
||||||
if (codeAllocator.base) {
|
if (codeAllocator.memory.begin()) {
|
||||||
#if !defined(AVIAN_AOT_ONLY)
|
#if !defined(AVIAN_AOT_ONLY)
|
||||||
s->freeExecutable(codeAllocator.base, codeAllocator.capacity);
|
s->freeExecutable(codeAllocator.memory.begin(),
|
||||||
|
codeAllocator.memory.count);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -9022,10 +9028,10 @@ class MyProcessor: public Processor {
|
|||||||
return visitor.trace ? visitor.trace : makeObjectArray(t, 0);
|
return visitor.trace ? visitor.trace : makeObjectArray(t, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void initialize(BootImage* image, uint8_t* code, unsigned capacity) {
|
virtual void initialize(BootImage* image, Slice<uint8_t> code)
|
||||||
|
{
|
||||||
bootImage = image;
|
bootImage = image;
|
||||||
codeAllocator.base = code;
|
codeAllocator.memory = code;
|
||||||
codeAllocator.capacity = capacity;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void addCompilationHandler(CompilationHandler* handler) {
|
virtual void addCompilationHandler(CompilationHandler* handler) {
|
||||||
@ -9060,7 +9066,7 @@ class MyProcessor: public Processor {
|
|||||||
{
|
{
|
||||||
if (wordArrayBody(t, root(t, VirtualThunks), i)) {
|
if (wordArrayBody(t, root(t, VirtualThunks), i)) {
|
||||||
wordArrayBody(t, root(t, VirtualThunks), i)
|
wordArrayBody(t, root(t, VirtualThunks), i)
|
||||||
-= reinterpret_cast<uintptr_t>(codeAllocator.base);
|
-= reinterpret_cast<uintptr_t>(codeAllocator.memory.begin());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -9077,11 +9083,11 @@ class MyProcessor: public Processor {
|
|||||||
for (object p = arrayBody(t, root(t, CallTable), i);
|
for (object p = arrayBody(t, root(t, CallTable), i);
|
||||||
p; p = callNodeNext(t, p))
|
p; p = callNodeNext(t, p))
|
||||||
{
|
{
|
||||||
table[index++] = targetVW
|
table[index++] = targetVW(
|
||||||
(callNodeAddress(t, p)
|
callNodeAddress(t, p)
|
||||||
- reinterpret_cast<uintptr_t>(codeAllocator.base));
|
- reinterpret_cast<uintptr_t>(codeAllocator.memory.begin()));
|
||||||
table[index++] = targetVW
|
table[index++] = targetVW(
|
||||||
(w->map()->find(callNodeTarget(t, p))
|
w->map()->find(callNodeTarget(t, p))
|
||||||
| (static_cast<unsigned>(callNodeFlags(t, p)) << TargetBootShift));
|
| (static_cast<unsigned>(callNodeFlags(t, p)) << TargetBootShift));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -9089,12 +9095,13 @@ class MyProcessor: public Processor {
|
|||||||
return table;
|
return table;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void boot(Thread* t, BootImage* image, uint8_t* code) {
|
virtual void boot(Thread* t, BootImage* image, uint8_t* code)
|
||||||
|
{
|
||||||
#if !defined(AVIAN_AOT_ONLY)
|
#if !defined(AVIAN_AOT_ONLY)
|
||||||
if (codeAllocator.base == 0) {
|
if (codeAllocator.memory.begin() == 0) {
|
||||||
codeAllocator.base = static_cast<uint8_t*>
|
codeAllocator.memory.items = static_cast<uint8_t*>(
|
||||||
(s->tryAllocateExecutable(ExecutableAreaSizeInBytes));
|
s->tryAllocateExecutable(ExecutableAreaSizeInBytes));
|
||||||
codeAllocator.capacity = ExecutableAreaSizeInBytes;
|
codeAllocator.memory.count = ExecutableAreaSizeInBytes;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -10032,7 +10039,7 @@ compileThunks(MyThread* t, FixedAllocator* allocator)
|
|||||||
BootImage* image = p->bootImage;
|
BootImage* image = p->bootImage;
|
||||||
|
|
||||||
if (image) {
|
if (image) {
|
||||||
uint8_t* imageBase = p->codeAllocator.base;
|
uint8_t* imageBase = p->codeAllocator.memory.begin();
|
||||||
|
|
||||||
image->thunks.default_ = thunkToThunk(p->thunks.default_, imageBase);
|
image->thunks.default_ = thunkToThunk(p->thunks.default_, imageBase);
|
||||||
image->thunks.defaultVirtual = thunkToThunk
|
image->thunks.defaultVirtual = thunkToThunk
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
#include <avian/util/runtime-array.h>
|
#include <avian/util/runtime-array.h>
|
||||||
#include <avian/util/list.h>
|
#include <avian/util/list.h>
|
||||||
|
#include <avian/util/slice.h>
|
||||||
|
|
||||||
using namespace vm;
|
using namespace vm;
|
||||||
using namespace avian::system;
|
using namespace avian::system;
|
||||||
@ -3205,7 +3206,8 @@ class MyProcessor: public Processor {
|
|||||||
return makeObjectArray(t, 0);
|
return makeObjectArray(t, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void initialize(BootImage*, uint8_t*, unsigned) {
|
virtual void initialize(BootImage*, avian::util::Slice<uint8_t>)
|
||||||
|
{
|
||||||
abort(s);
|
abort(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3235,7 +3237,6 @@ class MyProcessor: public Processor {
|
|||||||
expect(s, image == 0 and code == 0);
|
expect(s, image == 0 and code == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
virtual void callWithCurrentContinuation(vm::Thread*, object) {
|
virtual void callWithCurrentContinuation(vm::Thread*, object) {
|
||||||
abort(s);
|
abort(s);
|
||||||
}
|
}
|
||||||
|
@ -1919,7 +1919,7 @@ main(int ac, const char** av)
|
|||||||
|
|
||||||
uint8_t* code = static_cast<uint8_t*>(h->allocate(CodeCapacity));
|
uint8_t* code = static_cast<uint8_t*>(h->allocate(CodeCapacity));
|
||||||
BootImage image;
|
BootImage image;
|
||||||
p->initialize(&image, code, CodeCapacity);
|
p->initialize(&image, Slice<uint8_t>(code, CodeCapacity));
|
||||||
|
|
||||||
Machine* m = new (h->allocate(sizeof(Machine))) Machine
|
Machine* m = new (h->allocate(sizeof(Machine))) Machine
|
||||||
(s, h, f, 0, p, c, 0, 0, 0, 0, 128 * 1024);
|
(s, h, f, 0, p, c, 0, 0, 0, 0, 128 * 1024);
|
||||||
|
@ -15,8 +15,8 @@
|
|||||||
namespace avian {
|
namespace avian {
|
||||||
namespace util {
|
namespace util {
|
||||||
|
|
||||||
FixedAllocator::FixedAllocator(Aborter* a, uint8_t* base, unsigned capacity)
|
FixedAllocator::FixedAllocator(Aborter* a, Slice<uint8_t> memory)
|
||||||
: a(a), base(base), capacity(capacity), offset(0)
|
: a(a), memory(memory), offset(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -28,9 +28,9 @@ void* FixedAllocator::tryAllocate(unsigned size)
|
|||||||
void* FixedAllocator::allocate(unsigned size, unsigned padAlignment)
|
void* FixedAllocator::allocate(unsigned size, unsigned padAlignment)
|
||||||
{
|
{
|
||||||
unsigned paddedSize = vm::pad(size, padAlignment);
|
unsigned paddedSize = vm::pad(size, padAlignment);
|
||||||
expect(a, offset + paddedSize < capacity);
|
expect(a, offset + paddedSize < memory.count);
|
||||||
|
|
||||||
void* p = base + offset;
|
void* p = memory.begin() + offset;
|
||||||
offset += paddedSize;
|
offset += paddedSize;
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
@ -42,7 +42,8 @@ void* FixedAllocator::allocate(unsigned size)
|
|||||||
|
|
||||||
void FixedAllocator::free(const void* p, unsigned size)
|
void FixedAllocator::free(const void* p, unsigned size)
|
||||||
{
|
{
|
||||||
if (p >= base and static_cast<const uint8_t*>(p) + size == base + offset) {
|
if (p >= memory.begin() and static_cast<const uint8_t*>(p) + size
|
||||||
|
== memory.begin() + offset) {
|
||||||
offset -= size;
|
offset -= size;
|
||||||
} else {
|
} else {
|
||||||
abort(a);
|
abort(a);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user