reduce Allocator interface

This commit is contained in:
Joshua Warner 2014-05-04 22:43:27 -06:00
parent 2d0ac3ac17
commit fa1e3d74c0
15 changed files with 58 additions and 64 deletions

View File

@ -58,10 +58,10 @@ class Heap : public avian::util::Allocator {
unsigned footprint,
int pendingAllocation) = 0;
virtual unsigned fixedFootprint(unsigned sizeInWords, bool objectMask) = 0;
virtual void* allocateFixed(avian::util::Allocator* allocator,
virtual void* allocateFixed(avian::util::Alloc* allocator,
unsigned sizeInWords,
bool objectMask) = 0;
virtual void* allocateImmortalFixed(avian::util::Allocator* allocator,
virtual void* allocateImmortalFixed(avian::util::Alloc* allocator,
unsigned sizeInWords,
bool objectMask) = 0;
virtual void mark(void* p, unsigned offset, unsigned count) = 0;

View File

@ -130,7 +130,7 @@ class System : public avian::util::Aborter {
virtual Status load(Library**, const char* name) = 0;
virtual char pathSeparator() = 0;
virtual char fileSeparator() = 0;
virtual const char* toAbsolutePath(avian::util::Allocator* allocator,
virtual const char* toAbsolutePath(avian::util::AllocOnly* allocator,
const char* name) = 0;
virtual int64_t now() = 0;
virtual void yield() = 0;

View File

@ -21,10 +21,14 @@ class AllocOnly {
virtual void* allocate(size_t size) = 0;
};
class Allocator : public AllocOnly {
class Alloc : public AllocOnly {
public:
virtual void free(const void* p, size_t size) = 0;
};
class Allocator : public Alloc {
public:
virtual void* tryAllocate(size_t size) = 0;
virtual void free(const void* p, size_t size) = 0;
};
} // namespace util

View File

@ -20,7 +20,7 @@ namespace util {
// An Allocator that allocates, bump-pointer style, out of a pre-defined chunk
// of memory.
class FixedAllocator : public Allocator {
class FixedAllocator : public Alloc {
public:
FixedAllocator(Aborter* a, Slice<uint8_t> memory);

View File

@ -16,7 +16,7 @@
namespace vm {
inline const char* append(avian::util::Allocator* allocator,
inline const char* append(avian::util::AllocOnly* allocator,
const char* a,
const char* b,
const char* c)
@ -31,7 +31,7 @@ inline const char* append(avian::util::Allocator* allocator,
return p;
}
inline const char* append(avian::util::Allocator* allocator,
inline const char* append(avian::util::AllocOnly* allocator,
const char* a,
const char* b)
{
@ -43,7 +43,7 @@ inline const char* append(avian::util::Allocator* allocator,
return p;
}
inline const char* copy(avian::util::Allocator* allocator, const char* a)
inline const char* copy(avian::util::AllocOnly* allocator, const char* a)
{
unsigned al = strlen(a);
char* p = static_cast<char*>(allocator->allocate(al + 1));

View File

@ -16,7 +16,7 @@
namespace avian {
namespace util {
class Allocator;
class Alloc;
}
}
@ -202,12 +202,12 @@ class Finder {
};
AVIAN_EXPORT Finder* makeFinder(System* s,
avian::util::Allocator* a,
avian::util::Alloc* a,
const char* path,
const char* bootLibrary);
Finder* makeFinder(System* s,
avian::util::Allocator* a,
avian::util::Alloc* a,
const uint8_t* jarData,
unsigned jarLength);

View File

@ -1596,7 +1596,7 @@ inline bool ensure(Thread* t, unsigned sizeInBytes)
object allocate2(Thread* t, unsigned sizeInBytes, bool objectMask);
object allocate3(Thread* t,
Allocator* allocator,
Alloc* allocator,
Machine::AllocationType type,
unsigned sizeInBytes,
bool objectMask);

View File

@ -1264,7 +1264,7 @@ class Context {
TraceElement* traceLog;
Slice<uint16_t> visitTable;
Slice<uintptr_t> rootTable;
Allocator* executableAllocator;
Alloc* executableAllocator;
void* executableStart;
unsigned executableSize;
unsigned objectPoolCount;

View File

@ -56,7 +56,7 @@ class DirectoryElement : public Element {
public:
class Iterator : public Element::Iterator {
public:
Iterator(System* s, Allocator* allocator, const char* name, unsigned skip)
Iterator(System* s, Alloc* allocator, const char* name, unsigned skip)
: s(s),
allocator(allocator),
name(name),
@ -113,7 +113,7 @@ class DirectoryElement : public Element {
}
System* s;
Allocator* allocator;
Alloc* allocator;
const char* name;
unsigned skip;
System::Directory* directory;
@ -121,7 +121,7 @@ class DirectoryElement : public Element {
Iterator* it;
};
DirectoryElement(System* s, Allocator* allocator, const char* name)
DirectoryElement(System* s, Alloc* allocator, const char* name)
: s(s),
allocator(allocator),
originalName(name),
@ -188,7 +188,7 @@ class DirectoryElement : public Element {
}
System* s;
Allocator* allocator;
Alloc* allocator;
const char* originalName;
const char* name;
const char* urlPrefix_;
@ -198,7 +198,7 @@ class DirectoryElement : public Element {
class PointerRegion : public System::Region {
public:
PointerRegion(System* s,
Allocator* allocator,
Alloc* allocator,
const uint8_t* start,
size_t length,
bool freePointer = false)
@ -229,7 +229,7 @@ class PointerRegion : public System::Region {
}
System* s;
Allocator* allocator;
Alloc* allocator;
const uint8_t* start_;
size_t length_;
bool freePointer;
@ -237,7 +237,7 @@ class PointerRegion : public System::Region {
class DataRegion : public System::Region {
public:
DataRegion(System* s, Allocator* allocator, size_t length)
DataRegion(System* s, Alloc* allocator, size_t length)
: s(s), allocator(allocator), length_(length)
{
}
@ -258,7 +258,7 @@ class DataRegion : public System::Region {
}
System* s;
Allocator* allocator;
Alloc* allocator;
size_t length_;
uint8_t data[0];
};
@ -277,7 +277,7 @@ class JarIndex {
const uint8_t* entry;
};
JarIndex(System* s, Allocator* allocator, unsigned capacity)
JarIndex(System* s, Alloc* allocator, unsigned capacity)
: s(s),
allocator(allocator),
capacity(capacity),
@ -288,14 +288,14 @@ class JarIndex {
memset(table, 0, sizeof(List<Entry>*) * capacity);
}
static JarIndex* make(System* s, Allocator* allocator, unsigned capacity)
static JarIndex* make(System* s, Alloc* allocator, unsigned capacity)
{
return new (allocator->allocate(sizeof(JarIndex)
+ (sizeof(List<Entry>*) * capacity)))
JarIndex(s, allocator, capacity);
}
static JarIndex* open(System* s, Allocator* allocator, System::Region* region)
static JarIndex* open(System* s, Alloc* allocator, System::Region* region)
{
JarIndex* index = make(s, allocator, 32);
@ -438,7 +438,7 @@ class JarIndex {
}
System* s;
Allocator* allocator;
Alloc* allocator;
unsigned capacity;
unsigned position;
@ -450,7 +450,7 @@ class JarElement : public Element {
public:
class Iterator : public Element::Iterator {
public:
Iterator(System* s, Allocator* allocator, JarIndex* index)
Iterator(System* s, Alloc* allocator, JarIndex* index)
: s(s), allocator(allocator), index(index), position(0)
{
}
@ -472,13 +472,13 @@ class JarElement : public Element {
}
System* s;
Allocator* allocator;
Alloc* allocator;
JarIndex* index;
unsigned position;
};
JarElement(System* s,
Allocator* allocator,
Alloc* allocator,
const char* name,
bool canonicalizePath = true)
: s(s),
@ -495,7 +495,7 @@ class JarElement : public Element {
}
JarElement(System* s,
Allocator* allocator,
Alloc* allocator,
const uint8_t* jarData,
unsigned jarLength)
: s(s),
@ -599,7 +599,7 @@ class JarElement : public Element {
}
System* s;
Allocator* allocator;
Alloc* allocator;
const char* originalName;
const char* name;
const char* urlPrefix_;
@ -611,7 +611,7 @@ class JarElement : public Element {
class BuiltinElement : public JarElement {
public:
BuiltinElement(System* s,
Allocator* allocator,
Alloc* allocator,
const char* name,
const char* libraryName)
: JarElement(s, allocator, name, false),
@ -711,7 +711,7 @@ unsigned baseName(const char* name, char fileSeparator)
void add(System* s,
Element** first,
Element** last,
Allocator* allocator,
Alloc* allocator,
const char* name,
unsigned nameLength,
const char* bootLibrary);
@ -719,7 +719,7 @@ void add(System* s,
void addTokens(System* s,
Element** first,
Element** last,
Allocator* allocator,
Alloc* allocator,
const char* jarName,
unsigned jarNameBase,
const char* tokens,
@ -756,7 +756,7 @@ bool continuationLine(const uint8_t* base,
void addJar(System* s,
Element** first,
Element** last,
Allocator* allocator,
Alloc* allocator,
const char* name,
const char* bootLibrary)
{
@ -852,7 +852,7 @@ void addJar(System* s,
void add(System* s,
Element** first,
Element** last,
Allocator* allocator,
Alloc* allocator,
const char* token,
unsigned tokenLength,
const char* bootLibrary)
@ -904,7 +904,7 @@ void add(System* s,
}
Element* parsePath(System* s,
Allocator* allocator,
Alloc* allocator,
const char* path,
const char* bootLibrary)
{
@ -921,7 +921,7 @@ Element* parsePath(System* s,
class MyIterator : public Finder::IteratorImp {
public:
MyIterator(System* s, Allocator* allocator, Element* path)
MyIterator(System* s, Alloc* allocator, Element* path)
: s(s),
allocator(allocator),
e(path ? path->next : 0),
@ -956,7 +956,7 @@ class MyIterator : public Finder::IteratorImp {
}
System* s;
Allocator* allocator;
Alloc* allocator;
Element* e;
Element::Iterator* it;
};
@ -964,7 +964,7 @@ class MyIterator : public Finder::IteratorImp {
class MyFinder : public Finder {
public:
MyFinder(System* system,
Allocator* allocator,
Alloc* allocator,
const char* path,
const char* bootLibrary)
: system(system),
@ -975,7 +975,7 @@ class MyFinder : public Finder {
}
MyFinder(System* system,
Allocator* allocator,
Alloc* allocator,
const uint8_t* jarData,
unsigned jarLength)
: system(system),
@ -1071,7 +1071,7 @@ class MyFinder : public Finder {
}
System* system;
Allocator* allocator;
Alloc* allocator;
Element* path_;
const char* pathString;
};
@ -1081,7 +1081,7 @@ class MyFinder : public Finder {
namespace vm {
AVIAN_EXPORT Finder* makeFinder(System* s,
Allocator* a,
Alloc* a,
const char* path,
const char* bootLibrary)
{
@ -1089,7 +1089,7 @@ AVIAN_EXPORT Finder* makeFinder(System* s,
}
Finder* makeFinder(System* s,
Allocator* a,
Alloc* a,
const uint8_t* jarData,
unsigned jarLength)
{

View File

@ -1994,7 +1994,7 @@ class MyHeap : public Heap {
return Fixie::totalSize(sizeInWords, objectMask);
}
void* allocateFixed(Allocator* allocator,
void* allocateFixed(Alloc* allocator,
unsigned sizeInWords,
bool objectMask,
Fixie** handle,
@ -2011,7 +2011,7 @@ class MyHeap : public Heap {
->body();
}
virtual void* allocateFixed(Allocator* allocator,
virtual void* allocateFixed(Alloc* allocator,
unsigned sizeInWords,
bool objectMask)
{
@ -2019,7 +2019,7 @@ class MyHeap : public Heap {
allocator, sizeInWords, objectMask, &(c.fixies), false);
}
virtual void* allocateImmortalFixed(Allocator* allocator,
virtual void* allocateImmortalFixed(Alloc* allocator,
unsigned sizeInWords,
bool objectMask)
{

View File

@ -4175,7 +4175,7 @@ object allocate2(Thread* t, unsigned sizeInBytes, bool objectMask)
}
object allocate3(Thread* t,
Allocator* allocator,
Alloc* allocator,
Machine::AllocationType type,
unsigned sizeInBytes,
bool objectMask)

View File

@ -62,20 +62,15 @@ const char* mainClass(const char* jar)
System* system = makeSystem();
class MyAllocator : public avian::util::Allocator {
class MyAllocator : public avian::util::Alloc {
public:
MyAllocator(System* s) : s(s)
{
}
virtual void* tryAllocate(size_t size)
{
return s->tryAllocate(size);
}
virtual void* allocate(size_t size)
{
void* p = tryAllocate(size);
void* p = s->tryAllocate(size);
if (p == 0) {
abort(s);
}

View File

@ -856,7 +856,7 @@ class MySystem : public System {
return SO_SUFFIX;
}
virtual const char* toAbsolutePath(Allocator* allocator, const char* name)
virtual const char* toAbsolutePath(AllocOnly* allocator, const char* name)
{
if (name[0] == '/') {
return copy(allocator, name);

View File

@ -893,7 +893,7 @@ class MySystem : public System {
return SO_SUFFIX;
}
virtual const char* toAbsolutePath(avian::util::Allocator* allocator,
virtual const char* toAbsolutePath(avian::util::AllocOnly* allocator,
const char* name)
{
#if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)

View File

@ -1630,20 +1630,15 @@ int main(int ac, char** av)
System* system = makeSystem();
class MyAllocator : public avian::util::Allocator {
class MyAllocator : public avian::util::Alloc {
public:
MyAllocator(System* s) : s(s)
{
}
virtual void* tryAllocate(size_t size)
{
return s->tryAllocate(size);
}
virtual void* allocate(size_t size)
{
void* p = tryAllocate(size);
void* p = s->tryAllocate(size);
if (p == 0) {
abort(s);
}