mirror of
https://github.com/corda/corda.git
synced 2025-01-04 04:04:27 +00:00
move fixed allocator out of machine.h
This commit is contained in:
parent
f69f86b487
commit
b083f3df04
@ -23,6 +23,11 @@ public:
|
|||||||
virtual void NO_RETURN abort() = 0;
|
virtual void NO_RETURN abort() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
inline Aborter* getAborter(Aborter* a)
|
||||||
|
{
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
inline void NO_RETURN abort(T t) {
|
inline void NO_RETURN abort(T t) {
|
||||||
getAborter(t)->abort();
|
getAborter(t)->abort();
|
||||||
@ -44,7 +49,7 @@ inline void assert(T t, bool v) {
|
|||||||
expect(t, v);
|
expect(t, v);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
} // namespace util
|
} // namespace util
|
||||||
} // namespace avian
|
} // namespace avian
|
||||||
|
|
||||||
|
43
include/avian/util/fixed-allocator.h
Normal file
43
include/avian/util/fixed-allocator.h
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
/* Copyright (c) 2008-2013, Avian Contributors
|
||||||
|
|
||||||
|
Permission to use, copy, modify, and/or distribute this software
|
||||||
|
for any purpose with or without fee is hereby granted, provided
|
||||||
|
that the above copyright notice and this permission notice appear
|
||||||
|
in all copies.
|
||||||
|
|
||||||
|
There is NO WARRANTY for this software. See license.txt for
|
||||||
|
details. */
|
||||||
|
|
||||||
|
#ifndef AVIAN_UTIL_FIXED_ALLOCATOR_H
|
||||||
|
#define AVIAN_UTIL_FIXED_ALLOCATOR_H
|
||||||
|
|
||||||
|
#include "allocator.h"
|
||||||
|
#include "abort.h"
|
||||||
|
|
||||||
|
namespace avian {
|
||||||
|
namespace util {
|
||||||
|
|
||||||
|
class FixedAllocator : public Allocator {
|
||||||
|
public:
|
||||||
|
FixedAllocator(Aborter* a, uint8_t* base, unsigned capacity);
|
||||||
|
|
||||||
|
virtual void* tryAllocate(unsigned size);
|
||||||
|
|
||||||
|
void* allocate(unsigned size, unsigned padAlignment);
|
||||||
|
|
||||||
|
virtual void* allocate(unsigned size);
|
||||||
|
|
||||||
|
virtual void free(const void* p, unsigned size);
|
||||||
|
|
||||||
|
Aborter* a;
|
||||||
|
|
||||||
|
uint8_t* base;
|
||||||
|
unsigned capacity;
|
||||||
|
|
||||||
|
unsigned offset;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace util
|
||||||
|
} // namespace avian
|
||||||
|
|
||||||
|
#endif // AVIAN_UTIL_FIXED_ALLOCATOR_H
|
3
makefile
3
makefile
@ -1144,7 +1144,8 @@ compiler-sources = \
|
|||||||
$(wildcard $(src)/codegen/compiler/*.cpp) \
|
$(wildcard $(src)/codegen/compiler/*.cpp) \
|
||||||
$(src)/codegen/registers.cpp \
|
$(src)/codegen/registers.cpp \
|
||||||
$(src)/codegen/runtime.cpp \
|
$(src)/codegen/runtime.cpp \
|
||||||
$(src)/codegen/targets.cpp
|
$(src)/codegen/targets.cpp \
|
||||||
|
$(src)/util/fixed-allocator.cpp
|
||||||
|
|
||||||
x86-assembler-sources = $(wildcard $(src)/codegen/target/x86/*.cpp)
|
x86-assembler-sources = $(wildcard $(src)/codegen/target/x86/*.cpp)
|
||||||
|
|
||||||
|
@ -1793,43 +1793,6 @@ inline Aborter* getAborter(Thread* t) {
|
|||||||
return t->m->system;
|
return t->m->system;
|
||||||
}
|
}
|
||||||
|
|
||||||
class FixedAllocator: public Allocator {
|
|
||||||
public:
|
|
||||||
FixedAllocator(System* s, uint8_t* base, unsigned capacity):
|
|
||||||
s(s), base(base), offset(0), capacity(capacity)
|
|
||||||
{ }
|
|
||||||
|
|
||||||
virtual void* tryAllocate(unsigned size) {
|
|
||||||
return allocate(size);
|
|
||||||
}
|
|
||||||
|
|
||||||
void* allocate(unsigned size, unsigned padAlignment) {
|
|
||||||
unsigned paddedSize = pad(size, padAlignment);
|
|
||||||
expect(s, offset + paddedSize < capacity);
|
|
||||||
|
|
||||||
void* p = base + offset;
|
|
||||||
offset += paddedSize;
|
|
||||||
return p;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void* allocate(unsigned size) {
|
|
||||||
return allocate(size, BytesPerWord);
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void free(const void* p, unsigned size) {
|
|
||||||
if (p >= base and static_cast<const uint8_t*>(p) + size == base + offset) {
|
|
||||||
offset -= size;
|
|
||||||
} else {
|
|
||||||
abort(s);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
System* s;
|
|
||||||
uint8_t* base;
|
|
||||||
unsigned offset;
|
|
||||||
unsigned capacity;
|
|
||||||
};
|
|
||||||
|
|
||||||
inline bool
|
inline bool
|
||||||
ensure(Thread* t, unsigned sizeInBytes)
|
ensure(Thread* t, unsigned sizeInBytes)
|
||||||
{
|
{
|
||||||
|
@ -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/fixed-allocator.h>
|
||||||
|
|
||||||
using namespace vm;
|
using namespace vm;
|
||||||
|
|
||||||
@ -1347,8 +1348,7 @@ storeLocal(Context* context, unsigned footprint, Compiler::Operand* value,
|
|||||||
(footprint, value, translateLocalIndex(context, footprint, index));
|
(footprint, value, translateLocalIndex(context, footprint, index));
|
||||||
}
|
}
|
||||||
|
|
||||||
FixedAllocator*
|
avian::util::FixedAllocator* codeAllocator(MyThread* t);
|
||||||
codeAllocator(MyThread* t);
|
|
||||||
|
|
||||||
class Frame {
|
class Frame {
|
||||||
public:
|
public:
|
||||||
@ -10280,8 +10280,7 @@ setRoot(Thread* t, Root root, object value)
|
|||||||
ArrayBody + (root * BytesPerWord), value);
|
ArrayBody + (root * BytesPerWord), value);
|
||||||
}
|
}
|
||||||
|
|
||||||
FixedAllocator*
|
avian::util::FixedAllocator* codeAllocator(MyThread* t)
|
||||||
codeAllocator(MyThread* t)
|
|
||||||
{
|
{
|
||||||
return &(processor(t)->codeAllocator);
|
return &(processor(t)->codeAllocator);
|
||||||
}
|
}
|
||||||
|
53
src/util/fixed-allocator.cpp
Normal file
53
src/util/fixed-allocator.cpp
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
/* Copyright (c) 2008-2013, Avian Contributors
|
||||||
|
|
||||||
|
Permission to use, copy, modify, and/or distribute this software
|
||||||
|
for any purpose with or without fee is hereby granted, provided
|
||||||
|
that the above copyright notice and this permission notice appear
|
||||||
|
in all copies.
|
||||||
|
|
||||||
|
There is NO WARRANTY for this software. See license.txt for
|
||||||
|
details. */
|
||||||
|
|
||||||
|
#include <avian/util/fixed-allocator.h>
|
||||||
|
|
||||||
|
#include <avian/common.h>
|
||||||
|
|
||||||
|
namespace avian {
|
||||||
|
namespace util {
|
||||||
|
|
||||||
|
FixedAllocator::FixedAllocator(Aborter* a, uint8_t* base, unsigned capacity)
|
||||||
|
: a(a), base(base), capacity(capacity), offset(0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void* FixedAllocator::tryAllocate(unsigned size)
|
||||||
|
{
|
||||||
|
return allocate(size);
|
||||||
|
}
|
||||||
|
|
||||||
|
void* FixedAllocator::allocate(unsigned size, unsigned padAlignment)
|
||||||
|
{
|
||||||
|
unsigned paddedSize = vm::pad(size, padAlignment);
|
||||||
|
expect(a, offset + paddedSize < capacity);
|
||||||
|
|
||||||
|
void* p = base + offset;
|
||||||
|
offset += paddedSize;
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
void* FixedAllocator::allocate(unsigned size)
|
||||||
|
{
|
||||||
|
return allocate(size, vm::BytesPerWord);
|
||||||
|
}
|
||||||
|
|
||||||
|
void FixedAllocator::free(const void* p, unsigned size)
|
||||||
|
{
|
||||||
|
if (p >= base and static_cast<const uint8_t*>(p) + size == base + offset) {
|
||||||
|
offset -= size;
|
||||||
|
} else {
|
||||||
|
abort(a);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace util
|
||||||
|
} // namespace avian
|
Loading…
Reference in New Issue
Block a user