diff --git a/include/avian/heap/heap.h b/include/avian/heap/heap.h index e4e5ba929f..53dc343141 100644 --- a/include/avian/heap/heap.h +++ b/include/avian/heap/heap.h @@ -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; diff --git a/include/avian/system/system.h b/include/avian/system/system.h index 058d6d1fcd..304112dfe8 100644 --- a/include/avian/system/system.h +++ b/include/avian/system/system.h @@ -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; diff --git a/include/avian/util/allocator.h b/include/avian/util/allocator.h index 8b5b1b9232..2e1fe30587 100644 --- a/include/avian/util/allocator.h +++ b/include/avian/util/allocator.h @@ -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 diff --git a/include/avian/util/fixed-allocator.h b/include/avian/util/fixed-allocator.h index 0d3898bcb1..220bd5b1db 100644 --- a/include/avian/util/fixed-allocator.h +++ b/include/avian/util/fixed-allocator.h @@ -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 memory); diff --git a/src/avian/append.h b/src/avian/append.h index 22a8854d59..2a0be10151 100644 --- a/src/avian/append.h +++ b/src/avian/append.h @@ -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(allocator->allocate(al + 1)); diff --git a/src/avian/finder.h b/src/avian/finder.h index cb37d2789b..fe0e34e888 100644 --- a/src/avian/finder.h +++ b/src/avian/finder.h @@ -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); diff --git a/src/avian/machine.h b/src/avian/machine.h index c4ec3360fa..36f65ee868 100644 --- a/src/avian/machine.h +++ b/src/avian/machine.h @@ -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); diff --git a/src/compile.cpp b/src/compile.cpp index ead6942a1e..bd5234db04 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -1264,7 +1264,7 @@ class Context { TraceElement* traceLog; Slice visitTable; Slice rootTable; - Allocator* executableAllocator; + Alloc* executableAllocator; void* executableStart; unsigned executableSize; unsigned objectPoolCount; diff --git a/src/finder.cpp b/src/finder.cpp index 28ea5bd14d..59479a2534 100644 --- a/src/finder.cpp +++ b/src/finder.cpp @@ -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*) * 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*) * 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) { diff --git a/src/heap/heap.cpp b/src/heap/heap.cpp index dfd6eb855a..c4b8ff35a7 100644 --- a/src/heap/heap.cpp +++ b/src/heap/heap.cpp @@ -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) { diff --git a/src/machine.cpp b/src/machine.cpp index f8e312ebc2..519d7ff01f 100644 --- a/src/machine.cpp +++ b/src/machine.cpp @@ -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) diff --git a/src/main.cpp b/src/main.cpp index 4471879ae8..fdfd52d864 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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); } diff --git a/src/system/posix.cpp b/src/system/posix.cpp index cf77851414..9dd2c7c016 100644 --- a/src/system/posix.cpp +++ b/src/system/posix.cpp @@ -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); diff --git a/src/system/windows.cpp b/src/system/windows.cpp index b713da966e..54fa952321 100644 --- a/src/system/windows.cpp +++ b/src/system/windows.cpp @@ -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) diff --git a/src/tools/type-generator/main.cpp b/src/tools/type-generator/main.cpp index b9bb30c84e..ccb2464650 100644 --- a/src/tools/type-generator/main.cpp +++ b/src/tools/type-generator/main.cpp @@ -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); }