mirror of
https://github.com/corda/corda.git
synced 2025-01-05 20:54:13 +00:00
Merge pull request #292 from joshuawarner32/executable-allocator
Various improvements
This commit is contained in:
commit
84ad3c2392
@ -20,7 +20,7 @@ class Zone;
|
||||
namespace avian {
|
||||
|
||||
namespace util {
|
||||
class Allocator;
|
||||
class Alloc;
|
||||
}
|
||||
|
||||
namespace codegen {
|
||||
@ -143,7 +143,7 @@ class Architecture {
|
||||
unsigned cSize,
|
||||
OperandMask& cMask) = 0;
|
||||
|
||||
virtual Assembler* makeAssembler(util::Allocator*, vm::Zone*) = 0;
|
||||
virtual Assembler* makeAssembler(util::Alloc*, vm::Zone*) = 0;
|
||||
|
||||
virtual void acquire() = 0;
|
||||
virtual void release() = 0;
|
||||
|
@ -35,11 +35,6 @@ class Type {
|
||||
Float,
|
||||
Address,
|
||||
|
||||
// Represents individual halves of two-word types
|
||||
// (double/long on 32-bit systems)
|
||||
// TODO: remove when possible
|
||||
Half,
|
||||
|
||||
// Represents the lack of a return value
|
||||
// TODO: remove when possible
|
||||
Void,
|
||||
|
@ -118,7 +118,7 @@ class OffsetPromise : public Promise {
|
||||
|
||||
class ListenPromise : public Promise {
|
||||
public:
|
||||
ListenPromise(vm::System* s, util::Allocator* allocator)
|
||||
ListenPromise(vm::System* s, util::AllocOnly* allocator)
|
||||
: s(s), allocator(allocator), listener(0)
|
||||
{
|
||||
}
|
||||
@ -142,7 +142,7 @@ class ListenPromise : public Promise {
|
||||
}
|
||||
|
||||
vm::System* s;
|
||||
util::Allocator* allocator;
|
||||
util::AllocOnly* allocator;
|
||||
Listener* listener;
|
||||
Promise* promise;
|
||||
};
|
||||
@ -150,7 +150,7 @@ class ListenPromise : public Promise {
|
||||
class DelayedPromise : public ListenPromise {
|
||||
public:
|
||||
DelayedPromise(vm::System* s,
|
||||
util::Allocator* allocator,
|
||||
util::AllocOnly* allocator,
|
||||
Promise* basis,
|
||||
DelayedPromise* next)
|
||||
: ListenPromise(s, allocator), basis(basis), next(next)
|
||||
|
@ -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;
|
||||
|
49
include/avian/system/memory.h
Normal file
49
include/avian/system/memory.h
Normal file
@ -0,0 +1,49 @@
|
||||
/* Copyright (c) 2008-2014, 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_SYSTEM_MEMORY_H
|
||||
#define AVIAN_SYSTEM_MEMORY_H
|
||||
|
||||
#include <avian/util/slice.h>
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
namespace avian {
|
||||
namespace system {
|
||||
|
||||
class Memory {
|
||||
public:
|
||||
enum Permissions {
|
||||
Read = 1 << 0,
|
||||
Write = 1 << 1,
|
||||
Execute = 1 << 2,
|
||||
|
||||
// Utility munged constants
|
||||
ReadWrite = Read | Write,
|
||||
ReadExecute = Read | Execute,
|
||||
ReadWriteExecute = Read | Write | Execute
|
||||
};
|
||||
|
||||
static const size_t PageSize;
|
||||
|
||||
// Allocate a contiguous range of pages.
|
||||
static util::Slice<uint8_t> allocate(size_t sizeInBytes, Permissions perms = ReadWrite);
|
||||
|
||||
// Free a contiguous range of pages.
|
||||
static void free(util::Slice<uint8_t> pages);
|
||||
|
||||
// TODO: In the future:
|
||||
// static void setPermissions(util::Slice<uint8_t> pages, Permissions perms);
|
||||
};
|
||||
|
||||
} // namespace system
|
||||
} // namespace avian
|
||||
|
||||
#endif
|
@ -113,10 +113,6 @@ class System : public avian::util::Aborter {
|
||||
virtual bool success(Status) = 0;
|
||||
virtual void* tryAllocate(unsigned sizeInBytes) = 0;
|
||||
virtual void free(const void* p) = 0;
|
||||
#if !defined(AVIAN_AOT_ONLY)
|
||||
virtual void* tryAllocateExecutable(unsigned sizeInBytes) = 0;
|
||||
virtual void freeExecutable(const void* p, unsigned sizeInBytes) = 0;
|
||||
#endif
|
||||
virtual Status attach(Runnable*) = 0;
|
||||
virtual Status start(Runnable*) = 0;
|
||||
virtual Status make(Mutex**) = 0;
|
||||
@ -134,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;
|
||||
|
@ -16,18 +16,25 @@
|
||||
namespace avian {
|
||||
namespace util {
|
||||
|
||||
class Allocator {
|
||||
class AllocOnly {
|
||||
public:
|
||||
// TODO: use size_t instead of unsigned
|
||||
virtual void* tryAllocate(unsigned size) = 0;
|
||||
virtual void* allocate(unsigned size) = 0;
|
||||
virtual void free(const void* p, unsigned size) = 0;
|
||||
virtual void* allocate(size_t size) = 0;
|
||||
};
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
} // namespace util
|
||||
} // namespace avian
|
||||
|
||||
inline void* operator new(size_t size, avian::util::Allocator* allocator)
|
||||
inline void* operator new(size_t size, avian::util::AllocOnly* allocator)
|
||||
{
|
||||
return allocator->allocate(size);
|
||||
}
|
||||
|
@ -20,17 +20,17 @@ 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);
|
||||
|
||||
virtual void* tryAllocate(unsigned size);
|
||||
virtual void* tryAllocate(size_t size);
|
||||
|
||||
void* allocate(unsigned size, unsigned padAlignment);
|
||||
void* allocate(size_t size, unsigned padAlignment);
|
||||
|
||||
virtual void* allocate(unsigned size);
|
||||
virtual void* allocate(size_t size);
|
||||
|
||||
virtual void free(const void* p, unsigned size);
|
||||
virtual void free(const void* p, size_t size);
|
||||
|
||||
Aborter* a;
|
||||
Slice<uint8_t> memory;
|
||||
|
@ -69,12 +69,12 @@ class Slice {
|
||||
return Slice<T>(this->begin() + begin, count);
|
||||
}
|
||||
|
||||
static Slice<T> alloc(Allocator* a, size_t count)
|
||||
static Slice<T> alloc(AllocOnly* a, size_t count)
|
||||
{
|
||||
return Slice<T>((T*)a->allocate(sizeof(T) * count), count);
|
||||
}
|
||||
|
||||
static Slice<T> allocAndSet(Allocator* a, size_t count, const T& item)
|
||||
static Slice<T> allocAndSet(AllocOnly* a, size_t count, const T& item)
|
||||
{
|
||||
Slice<T> slice(alloc(a, count));
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
@ -83,14 +83,14 @@ class Slice {
|
||||
return slice;
|
||||
}
|
||||
|
||||
Slice<T> clone(Allocator* a, size_t newCount)
|
||||
Slice<T> clone(AllocOnly* a, size_t newCount)
|
||||
{
|
||||
T* newItems = (T*)a->allocate(newCount * sizeof(T));
|
||||
memcpy(newItems, items, min(count, newCount) * sizeof(T));
|
||||
return Slice<T>(newItems, newCount);
|
||||
}
|
||||
|
||||
Slice<T> cloneAndSet(Allocator* a, size_t newCount, const T& item)
|
||||
Slice<T> cloneAndSet(AllocOnly* a, size_t newCount, const T& item)
|
||||
{
|
||||
Slice<T> slice(clone(a, newCount));
|
||||
for (size_t i = count; i < newCount; i++) {
|
||||
@ -99,7 +99,7 @@ class Slice {
|
||||
return slice;
|
||||
}
|
||||
|
||||
void resize(Allocator* a, size_t newCount)
|
||||
void resize(Alloc* a, size_t newCount)
|
||||
{
|
||||
Slice<T> slice(clone(a, newCount));
|
||||
a->free(items, count);
|
||||
|
@ -30,38 +30,6 @@ class String {
|
||||
}
|
||||
};
|
||||
|
||||
class Tokenizer {
|
||||
public:
|
||||
Tokenizer(const char* s, char delimiter)
|
||||
: s(s), limit(0), delimiter(delimiter)
|
||||
{
|
||||
}
|
||||
|
||||
Tokenizer(String str, char delimiter)
|
||||
: s(str.text), limit(str.text + str.length), delimiter(delimiter)
|
||||
{
|
||||
}
|
||||
|
||||
bool hasMore()
|
||||
{
|
||||
while (s != limit and *s == delimiter)
|
||||
++s;
|
||||
return s != limit and *s != 0;
|
||||
}
|
||||
|
||||
String next()
|
||||
{
|
||||
const char* p = s;
|
||||
while (s != limit and *s and *s != delimiter)
|
||||
++s;
|
||||
return String(p, s - p);
|
||||
}
|
||||
|
||||
const char* s;
|
||||
const char* limit;
|
||||
char delimiter;
|
||||
};
|
||||
|
||||
} // namespace util
|
||||
} // namespace avain
|
||||
|
||||
|
54
include/avian/util/tokenizer.h
Normal file
54
include/avian/util/tokenizer.h
Normal file
@ -0,0 +1,54 @@
|
||||
/* Copyright (c) 2008-2014, 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_TOKENIZER_H
|
||||
#define AVIAN_UTIL_TOKENIZER_H
|
||||
|
||||
#include "string.h"
|
||||
|
||||
namespace avian {
|
||||
namespace util {
|
||||
|
||||
class Tokenizer {
|
||||
public:
|
||||
Tokenizer(const char* s, char delimiter)
|
||||
: s(s), limit(0), delimiter(delimiter)
|
||||
{
|
||||
}
|
||||
|
||||
Tokenizer(String str, char delimiter)
|
||||
: s(str.text), limit(str.text + str.length), delimiter(delimiter)
|
||||
{
|
||||
}
|
||||
|
||||
bool hasMore()
|
||||
{
|
||||
while (s != limit and *s == delimiter)
|
||||
++s;
|
||||
return s != limit and *s != 0;
|
||||
}
|
||||
|
||||
String next()
|
||||
{
|
||||
const char* p = s;
|
||||
while (s != limit and *s and *s != delimiter)
|
||||
++s;
|
||||
return String(p, s - p);
|
||||
}
|
||||
|
||||
const char* s;
|
||||
const char* limit;
|
||||
char delimiter;
|
||||
};
|
||||
|
||||
} // namespace util
|
||||
} // namespace avain
|
||||
|
||||
#endif // AVIAN_UTIL_TOKENIZER_H
|
7
makefile
7
makefile
@ -754,10 +754,6 @@ openjdk-extra-cflags += $(classpath-extra-cflags)
|
||||
|
||||
find-tool = $(shell if ( command -v "$(1)$(2)" >/dev/null ); then (echo "$(1)$(2)") else (echo "$(2)"); fi)
|
||||
|
||||
ifeq ($(build-platform),windows)
|
||||
static-on-windows = -static
|
||||
endif
|
||||
|
||||
ifeq ($(platform),windows)
|
||||
target-format = pe
|
||||
|
||||
@ -787,6 +783,7 @@ ifeq ($(platform),windows)
|
||||
strip = $(prefix)strip --strip-all
|
||||
else
|
||||
build-system = windows
|
||||
static-on-windows = -static
|
||||
common-cflags += "-I$(JAVA_HOME)/include/win32"
|
||||
build-cflags = $(common-cflags) -I$(src) -I$(inc) -mthreads
|
||||
openjdk-extra-cflags =
|
||||
@ -1138,6 +1135,7 @@ vm-depends := $(generated-code) \
|
||||
vm-sources = \
|
||||
$(src)/system/$(system).cpp \
|
||||
$(src)/system/$(system)/signal.cpp \
|
||||
$(src)/system/$(system)/memory.cpp \
|
||||
$(src)/finder.cpp \
|
||||
$(src)/machine.cpp \
|
||||
$(src)/util.cpp \
|
||||
@ -1273,6 +1271,7 @@ generator-sources = \
|
||||
$(src)/tools/type-generator/main.cpp \
|
||||
$(src)/system/$(build-system).cpp \
|
||||
$(src)/system/$(build-system)/signal.cpp \
|
||||
$(src)/system/$(build-system)/memory.cpp \
|
||||
$(src)/finder.cpp \
|
||||
$(src)/util/arg-parser.cpp
|
||||
|
||||
|
@ -26,7 +26,7 @@ namespace vm {
|
||||
class Vector {
|
||||
public:
|
||||
Vector(avian::util::Aborter* a,
|
||||
avian::util::Allocator* allocator,
|
||||
avian::util::Alloc* allocator,
|
||||
size_t minimumCapacity)
|
||||
: a(a),
|
||||
allocator(allocator),
|
||||
@ -175,7 +175,7 @@ class Vector {
|
||||
}
|
||||
|
||||
avian::util::Aborter* a;
|
||||
avian::util::Allocator* allocator;
|
||||
avian::util::Alloc* allocator;
|
||||
avian::util::Slice<uint8_t> data;
|
||||
size_t position;
|
||||
size_t minimumCapacity;
|
||||
|
@ -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));
|
||||
|
@ -13,6 +13,7 @@
|
||||
|
||||
#include <avian/util/string.h>
|
||||
#include <avian/util/runtime-array.h>
|
||||
#include <avian/util/tokenizer.h>
|
||||
|
||||
using namespace avian::util;
|
||||
|
||||
|
@ -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);
|
||||
|
||||
|
@ -15,20 +15,20 @@
|
||||
|
||||
namespace avian {
|
||||
namespace util {
|
||||
class Allocator;
|
||||
class AllocOnly;
|
||||
}
|
||||
}
|
||||
|
||||
namespace vm {
|
||||
|
||||
uint8_t* decodeLZMA(System* s,
|
||||
avian::util::Allocator* a,
|
||||
avian::util::AllocOnly* a,
|
||||
uint8_t* in,
|
||||
unsigned inSize,
|
||||
unsigned* outSize);
|
||||
|
||||
uint8_t* encodeLZMA(System* s,
|
||||
avian::util::Allocator* a,
|
||||
avian::util::AllocOnly* a,
|
||||
uint8_t* in,
|
||||
unsigned inSize,
|
||||
unsigned* outSize);
|
||||
|
@ -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);
|
||||
|
@ -17,7 +17,7 @@
|
||||
|
||||
namespace vm {
|
||||
|
||||
class Zone : public avian::util::Allocator {
|
||||
class Zone : public avian::util::AllocOnly {
|
||||
public:
|
||||
class Segment {
|
||||
public:
|
||||
@ -31,9 +31,8 @@ class Zone : public avian::util::Allocator {
|
||||
uint8_t data[0];
|
||||
};
|
||||
|
||||
Zone(System* s, Allocator* allocator, unsigned minimumFootprint)
|
||||
: s(s),
|
||||
allocator(allocator),
|
||||
Zone(avian::util::Allocator* allocator, size_t minimumFootprint)
|
||||
: allocator(allocator),
|
||||
segment(0),
|
||||
minimumFootprint(minimumFootprint < sizeof(Segment)
|
||||
? 0
|
||||
@ -56,6 +55,46 @@ class Zone : public avian::util::Allocator {
|
||||
segment = 0;
|
||||
}
|
||||
|
||||
virtual void* allocate(size_t size)
|
||||
{
|
||||
size = pad(size);
|
||||
void* p = tryAllocate(size);
|
||||
if (p) {
|
||||
return p;
|
||||
} else {
|
||||
ensure(size);
|
||||
void* r = segment->data + segment->position;
|
||||
segment->position += size;
|
||||
return r;
|
||||
}
|
||||
}
|
||||
|
||||
void* peek(size_t size)
|
||||
{
|
||||
size = pad(size);
|
||||
Segment* s = segment;
|
||||
while (s->position < size) {
|
||||
size -= s->position;
|
||||
s = s->next;
|
||||
}
|
||||
return s->data + (s->position - size);
|
||||
}
|
||||
|
||||
void pop(size_t size)
|
||||
{
|
||||
size = pad(size);
|
||||
Segment* s = segment;
|
||||
while (s->position < size) {
|
||||
size -= s->position;
|
||||
Segment* next = s->next;
|
||||
allocator->free(s, sizeof(Segment) + s->size);
|
||||
s = next;
|
||||
}
|
||||
s->position -= size;
|
||||
segment = s;
|
||||
}
|
||||
|
||||
private:
|
||||
static unsigned padToPage(unsigned size)
|
||||
{
|
||||
return (size + (LikelyPageSizeInBytes - 1)) & ~(LikelyPageSizeInBytes - 1);
|
||||
@ -95,7 +134,7 @@ class Zone : public avian::util::Allocator {
|
||||
}
|
||||
}
|
||||
|
||||
virtual void* tryAllocate(unsigned size)
|
||||
void* tryAllocate(size_t size)
|
||||
{
|
||||
size = pad(size);
|
||||
if (tryEnsure(size)) {
|
||||
@ -107,54 +146,7 @@ class Zone : public avian::util::Allocator {
|
||||
}
|
||||
}
|
||||
|
||||
virtual void* allocate(unsigned size)
|
||||
{
|
||||
size = pad(size);
|
||||
void* p = tryAllocate(size);
|
||||
if (p) {
|
||||
return p;
|
||||
} else {
|
||||
ensure(size);
|
||||
void* r = segment->data + segment->position;
|
||||
segment->position += size;
|
||||
return r;
|
||||
}
|
||||
}
|
||||
|
||||
void* peek(unsigned size)
|
||||
{
|
||||
size = pad(size);
|
||||
Segment* s = segment;
|
||||
while (s->position < size) {
|
||||
size -= s->position;
|
||||
s = s->next;
|
||||
}
|
||||
return s->data + (s->position - size);
|
||||
}
|
||||
|
||||
void pop(unsigned size)
|
||||
{
|
||||
size = pad(size);
|
||||
Segment* s = segment;
|
||||
while (s->position < size) {
|
||||
size -= s->position;
|
||||
Segment* next = s->next;
|
||||
allocator->free(s, sizeof(Segment) + s->size);
|
||||
s = next;
|
||||
}
|
||||
s->position -= size;
|
||||
segment = s;
|
||||
}
|
||||
|
||||
virtual void free(const void*, unsigned)
|
||||
{
|
||||
// not supported
|
||||
abort(s);
|
||||
}
|
||||
|
||||
System* s;
|
||||
Allocator* allocator;
|
||||
void* context;
|
||||
avian::util::Allocator* allocator;
|
||||
Segment* segment;
|
||||
unsigned minimumFootprint;
|
||||
};
|
||||
|
@ -1309,7 +1309,6 @@ unsigned typeFootprint(Context* c, ir::Type type)
|
||||
return type.rawSize() / 4;
|
||||
case ir::Type::Object:
|
||||
case ir::Type::Address:
|
||||
case ir::Type::Half:
|
||||
return 1;
|
||||
case ir::Type::Void:
|
||||
return 0;
|
||||
|
@ -619,7 +619,7 @@ class MyArchitecture : public Architecture {
|
||||
}
|
||||
}
|
||||
|
||||
virtual Assembler* makeAssembler(Allocator* allocator, Zone* zone);
|
||||
virtual Assembler* makeAssembler(Alloc* allocator, Zone* zone);
|
||||
|
||||
virtual void acquire()
|
||||
{
|
||||
@ -639,7 +639,7 @@ class MyArchitecture : public Architecture {
|
||||
|
||||
class MyAssembler : public Assembler {
|
||||
public:
|
||||
MyAssembler(System* s, Allocator* a, Zone* zone, MyArchitecture* arch)
|
||||
MyAssembler(System* s, Alloc* a, Zone* zone, MyArchitecture* arch)
|
||||
: con(s, a, zone), arch_(arch)
|
||||
{
|
||||
}
|
||||
@ -1075,7 +1075,7 @@ class MyAssembler : public Assembler {
|
||||
MyArchitecture* arch_;
|
||||
};
|
||||
|
||||
Assembler* MyArchitecture::makeAssembler(Allocator* allocator, Zone* zone)
|
||||
Assembler* MyArchitecture::makeAssembler(Alloc* allocator, Zone* zone)
|
||||
{
|
||||
return new (zone) MyAssembler(this->con.s, allocator, zone, this);
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ namespace avian {
|
||||
namespace codegen {
|
||||
namespace arm {
|
||||
|
||||
Context::Context(vm::System* s, util::Allocator* a, vm::Zone* zone)
|
||||
Context::Context(vm::System* s, util::Alloc* a, vm::Zone* zone)
|
||||
: s(s),
|
||||
zone(zone),
|
||||
client(0),
|
||||
|
@ -24,7 +24,7 @@ namespace avian {
|
||||
|
||||
namespace util {
|
||||
class Aborter;
|
||||
class Allocator;
|
||||
class Alloc;
|
||||
} // namespace util
|
||||
|
||||
namespace codegen {
|
||||
@ -37,7 +37,7 @@ class ConstantPoolEntry;
|
||||
|
||||
class Context {
|
||||
public:
|
||||
Context(vm::System* s, util::Allocator* a, vm::Zone* zone);
|
||||
Context(vm::System* s, util::Alloc* a, vm::Zone* zone);
|
||||
|
||||
vm::System* s;
|
||||
vm::Zone* zone;
|
||||
|
@ -887,7 +887,7 @@ class MyArchitecture : public Architecture {
|
||||
}
|
||||
}
|
||||
|
||||
virtual Assembler* makeAssembler(util::Allocator* allocator, Zone* zone);
|
||||
virtual Assembler* makeAssembler(util::Alloc* allocator, Zone* zone);
|
||||
|
||||
virtual void acquire()
|
||||
{
|
||||
@ -908,7 +908,7 @@ class MyArchitecture : public Architecture {
|
||||
|
||||
class MyAssembler : public Assembler {
|
||||
public:
|
||||
MyAssembler(System* s, util::Allocator* a, Zone* zone, MyArchitecture* arch)
|
||||
MyAssembler(System* s, util::Alloc* a, Zone* zone, MyArchitecture* arch)
|
||||
: c(s, a, zone, &(arch->c)), arch_(arch)
|
||||
{
|
||||
}
|
||||
@ -1273,7 +1273,7 @@ class MyAssembler : public Assembler {
|
||||
MyArchitecture* arch_;
|
||||
};
|
||||
|
||||
Assembler* MyArchitecture::makeAssembler(util::Allocator* allocator, Zone* zone)
|
||||
Assembler* MyArchitecture::makeAssembler(util::Alloc* allocator, Zone* zone)
|
||||
{
|
||||
return new (zone) MyAssembler(c.s, allocator, zone, this);
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ ArchitectureContext::ArchitectureContext(vm::System* s, bool useNativeFeatures)
|
||||
}
|
||||
|
||||
Context::Context(vm::System* s,
|
||||
util::Allocator* a,
|
||||
util::Alloc* a,
|
||||
vm::Zone* zone,
|
||||
ArchitectureContext* ac)
|
||||
: s(s),
|
||||
|
@ -26,7 +26,7 @@
|
||||
|
||||
namespace vm {
|
||||
class System;
|
||||
class Allocator;
|
||||
class Alloc;
|
||||
class Zone;
|
||||
} // namespace vm
|
||||
|
||||
@ -80,7 +80,7 @@ class ArchitectureContext {
|
||||
class Context {
|
||||
public:
|
||||
Context(vm::System* s,
|
||||
util::Allocator* a,
|
||||
util::Alloc* a,
|
||||
vm::Zone* zone,
|
||||
ArchitectureContext* ac);
|
||||
|
||||
|
@ -15,6 +15,8 @@
|
||||
#include "avian/target.h"
|
||||
#include "avian/arch.h"
|
||||
|
||||
#include <avian/system/memory.h>
|
||||
|
||||
#include <avian/codegen/assembler.h>
|
||||
#include <avian/codegen/architecture.h>
|
||||
#include <avian/codegen/compiler.h>
|
||||
@ -1156,7 +1158,7 @@ class Context {
|
||||
|
||||
Context(MyThread* t, BootContext* bootContext, GcMethod* method)
|
||||
: thread(t),
|
||||
zone(t->m->system, t->m->heap, InitialZoneCapacityInBytes),
|
||||
zone(t->m->heap, InitialZoneCapacityInBytes),
|
||||
assembler(t->arch->makeAssembler(t->m->heap, &zone)),
|
||||
client(t),
|
||||
compiler(makeCompiler(t->m->system, assembler, &zone, &client)),
|
||||
@ -1189,7 +1191,7 @@ class Context {
|
||||
|
||||
Context(MyThread* t)
|
||||
: thread(t),
|
||||
zone(t->m->system, t->m->heap, InitialZoneCapacityInBytes),
|
||||
zone(t->m->heap, InitialZoneCapacityInBytes),
|
||||
assembler(t->arch->makeAssembler(t->m->heap, &zone)),
|
||||
client(t),
|
||||
compiler(0),
|
||||
@ -1262,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;
|
||||
@ -3741,8 +3743,7 @@ class Stack {
|
||||
Stack* s;
|
||||
};
|
||||
|
||||
Stack(MyThread* t)
|
||||
: thread(t), zone(t->m->system, t->m->heap, 0), resource(this)
|
||||
Stack(MyThread* t) : thread(t), zone(t->m->heap, 0), resource(this)
|
||||
{
|
||||
}
|
||||
|
||||
@ -8842,8 +8843,7 @@ class MyProcessor : public Processor {
|
||||
{
|
||||
if (codeAllocator.memory.begin()) {
|
||||
#if !defined(AVIAN_AOT_ONLY)
|
||||
s->freeExecutable(codeAllocator.memory.begin(),
|
||||
codeAllocator.memory.count);
|
||||
Memory::free(codeAllocator.memory);
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -9023,12 +9023,10 @@ class MyProcessor : public Processor {
|
||||
{
|
||||
#if !defined(AVIAN_AOT_ONLY)
|
||||
if (codeAllocator.memory.begin() == 0) {
|
||||
codeAllocator.memory.items = static_cast<uint8_t*>(
|
||||
s->tryAllocateExecutable(ExecutableAreaSizeInBytes));
|
||||
codeAllocator.memory = Memory::allocate(ExecutableAreaSizeInBytes,
|
||||
Memory::ReadWriteExecute);
|
||||
|
||||
expect(t, codeAllocator.memory.items);
|
||||
|
||||
codeAllocator.memory.count = ExecutableAreaSizeInBytes;
|
||||
expect(t, codeAllocator.memory.begin());
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include <avian/util/runtime-array.h>
|
||||
#include <avian/util/list.h>
|
||||
#include <avian/util/hash.h>
|
||||
#include <avian/util/tokenizer.h>
|
||||
|
||||
#include "avian/zlib-custom.h"
|
||||
#include "avian/finder.h"
|
||||
@ -55,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),
|
||||
@ -112,7 +113,7 @@ class DirectoryElement : public Element {
|
||||
}
|
||||
|
||||
System* s;
|
||||
Allocator* allocator;
|
||||
Alloc* allocator;
|
||||
const char* name;
|
||||
unsigned skip;
|
||||
System::Directory* directory;
|
||||
@ -120,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),
|
||||
@ -187,7 +188,7 @@ class DirectoryElement : public Element {
|
||||
}
|
||||
|
||||
System* s;
|
||||
Allocator* allocator;
|
||||
Alloc* allocator;
|
||||
const char* originalName;
|
||||
const char* name;
|
||||
const char* urlPrefix_;
|
||||
@ -197,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)
|
||||
@ -228,7 +229,7 @@ class PointerRegion : public System::Region {
|
||||
}
|
||||
|
||||
System* s;
|
||||
Allocator* allocator;
|
||||
Alloc* allocator;
|
||||
const uint8_t* start_;
|
||||
size_t length_;
|
||||
bool freePointer;
|
||||
@ -236,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)
|
||||
{
|
||||
}
|
||||
@ -257,7 +258,7 @@ class DataRegion : public System::Region {
|
||||
}
|
||||
|
||||
System* s;
|
||||
Allocator* allocator;
|
||||
Alloc* allocator;
|
||||
size_t length_;
|
||||
uint8_t data[0];
|
||||
};
|
||||
@ -276,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),
|
||||
@ -287,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);
|
||||
|
||||
@ -437,7 +438,7 @@ class JarIndex {
|
||||
}
|
||||
|
||||
System* s;
|
||||
Allocator* allocator;
|
||||
Alloc* allocator;
|
||||
unsigned capacity;
|
||||
unsigned position;
|
||||
|
||||
@ -449,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)
|
||||
{
|
||||
}
|
||||
@ -471,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),
|
||||
@ -494,7 +495,7 @@ class JarElement : public Element {
|
||||
}
|
||||
|
||||
JarElement(System* s,
|
||||
Allocator* allocator,
|
||||
Alloc* allocator,
|
||||
const uint8_t* jarData,
|
||||
unsigned jarLength)
|
||||
: s(s),
|
||||
@ -598,7 +599,7 @@ class JarElement : public Element {
|
||||
}
|
||||
|
||||
System* s;
|
||||
Allocator* allocator;
|
||||
Alloc* allocator;
|
||||
const char* originalName;
|
||||
const char* name;
|
||||
const char* urlPrefix_;
|
||||
@ -610,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),
|
||||
@ -710,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);
|
||||
@ -718,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,
|
||||
@ -755,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)
|
||||
{
|
||||
@ -851,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)
|
||||
@ -903,7 +904,7 @@ void add(System* s,
|
||||
}
|
||||
|
||||
Element* parsePath(System* s,
|
||||
Allocator* allocator,
|
||||
Alloc* allocator,
|
||||
const char* path,
|
||||
const char* bootLibrary)
|
||||
{
|
||||
@ -920,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),
|
||||
@ -955,7 +956,7 @@ class MyIterator : public Finder::IteratorImp {
|
||||
}
|
||||
|
||||
System* s;
|
||||
Allocator* allocator;
|
||||
Alloc* allocator;
|
||||
Element* e;
|
||||
Element::Iterator* it;
|
||||
};
|
||||
@ -963,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),
|
||||
@ -974,7 +975,7 @@ class MyFinder : public Finder {
|
||||
}
|
||||
|
||||
MyFinder(System* system,
|
||||
Allocator* allocator,
|
||||
Alloc* allocator,
|
||||
const uint8_t* jarData,
|
||||
unsigned jarLength)
|
||||
: system(system),
|
||||
@ -1070,7 +1071,7 @@ class MyFinder : public Finder {
|
||||
}
|
||||
|
||||
System* system;
|
||||
Allocator* allocator;
|
||||
Alloc* allocator;
|
||||
Element* path_;
|
||||
const char* pathString;
|
||||
};
|
||||
@ -1080,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)
|
||||
{
|
||||
@ -1088,7 +1089,7 @@ AVIAN_EXPORT Finder* makeFinder(System* s,
|
||||
}
|
||||
|
||||
Finder* makeFinder(System* s,
|
||||
Allocator* a,
|
||||
Alloc* a,
|
||||
const uint8_t* jarData,
|
||||
unsigned jarLength)
|
||||
{
|
||||
|
@ -60,10 +60,10 @@ class Context;
|
||||
|
||||
Aborter* getAborter(Context* c);
|
||||
|
||||
void* tryAllocate(Context* c, unsigned size);
|
||||
void* allocate(Context* c, unsigned size);
|
||||
void* allocate(Context* c, unsigned size, bool limit);
|
||||
void free(Context* c, const void* p, unsigned size);
|
||||
void* tryAllocate(Context* c, size_t size);
|
||||
void* allocate(Context* c, size_t size);
|
||||
void* allocate(Context* c, size_t size, bool limit);
|
||||
void free(Context* c, const void* p, size_t size);
|
||||
|
||||
#ifdef USE_ATOMIC_OPERATIONS
|
||||
inline void markBitAtomic(uintptr_t* map, unsigned i)
|
||||
@ -1863,7 +1863,7 @@ void collect(Context* c)
|
||||
}
|
||||
}
|
||||
|
||||
void* allocate(Context* c, unsigned size, bool limit)
|
||||
void* allocate(Context* c, size_t size, bool limit)
|
||||
{
|
||||
ACQUIRE(c->lock);
|
||||
|
||||
@ -1888,12 +1888,12 @@ void* allocate(Context* c, unsigned size, bool limit)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void* tryAllocate(Context* c, unsigned size)
|
||||
void* tryAllocate(Context* c, size_t size)
|
||||
{
|
||||
return allocate(c, size, true);
|
||||
}
|
||||
|
||||
void* allocate(Context* c, unsigned size)
|
||||
void* allocate(Context* c, size_t size)
|
||||
{
|
||||
void* p = allocate(c, size, false);
|
||||
expect(c->system, p);
|
||||
@ -1901,7 +1901,7 @@ void* allocate(Context* c, unsigned size)
|
||||
return p;
|
||||
}
|
||||
|
||||
void free(Context* c, const void* p, unsigned size)
|
||||
void free(Context* c, const void* p, size_t size)
|
||||
{
|
||||
ACQUIRE(c->lock);
|
||||
|
||||
@ -1925,7 +1925,7 @@ void free(Context* c, const void* p, unsigned size)
|
||||
c->count -= size;
|
||||
}
|
||||
|
||||
void free_(Context* c, const void* p, unsigned size)
|
||||
void free_(Context* c, const void* p, size_t size)
|
||||
{
|
||||
free(c, p, size);
|
||||
}
|
||||
@ -1963,17 +1963,17 @@ class MyHeap : public Heap {
|
||||
return local::limitExceeded(&c, pendingAllocation);
|
||||
}
|
||||
|
||||
virtual void* tryAllocate(unsigned size)
|
||||
virtual void* tryAllocate(size_t size)
|
||||
{
|
||||
return local::tryAllocate(&c, size);
|
||||
}
|
||||
|
||||
virtual void* allocate(unsigned size)
|
||||
virtual void* allocate(size_t size)
|
||||
{
|
||||
return local::allocate(&c, size);
|
||||
}
|
||||
|
||||
virtual void free(const void* p, unsigned size)
|
||||
virtual void free(const void* p, size_t size)
|
||||
{
|
||||
free_(&c, p, size);
|
||||
}
|
||||
@ -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)
|
||||
{
|
||||
|
@ -27,7 +27,7 @@ int32_t read4(const uint8_t* in)
|
||||
namespace vm {
|
||||
|
||||
uint8_t* decodeLZMA(System* s,
|
||||
avian::util::Allocator* a,
|
||||
avian::util::AllocOnly* a,
|
||||
uint8_t* in,
|
||||
unsigned inSize,
|
||||
unsigned* outSize)
|
||||
|
@ -25,7 +25,7 @@ SRes myProgress(void*, UInt64, UInt64)
|
||||
namespace vm {
|
||||
|
||||
uint8_t* encodeLZMA(System* s,
|
||||
Allocator* a,
|
||||
AllocOnly* a,
|
||||
uint8_t* in,
|
||||
unsigned inSize,
|
||||
unsigned* outSize)
|
||||
|
@ -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)
|
||||
|
13
src/main.cpp
13
src/main.cpp
@ -62,27 +62,22 @@ 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(unsigned size)
|
||||
virtual void* allocate(size_t size)
|
||||
{
|
||||
return s->tryAllocate(size);
|
||||
}
|
||||
|
||||
virtual void* allocate(unsigned size)
|
||||
{
|
||||
void* p = tryAllocate(size);
|
||||
void* p = s->tryAllocate(size);
|
||||
if (p == 0) {
|
||||
abort(s);
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
virtual void free(const void* p, unsigned)
|
||||
virtual void free(const void* p, size_t)
|
||||
{
|
||||
s->free(p);
|
||||
}
|
||||
|
@ -54,6 +54,7 @@ typedef struct ucontext {
|
||||
|
||||
#include <avian/system/system.h>
|
||||
#include <avian/system/signal.h>
|
||||
#include <avian/system/memory.h>
|
||||
#include <avian/util/math.h>
|
||||
|
||||
#define ACQUIRE(x) MutexResource MAKE_NAME(mutexResource_)(x)
|
||||
@ -664,39 +665,7 @@ class MySystem : public System {
|
||||
::free(const_cast<void*>(p));
|
||||
}
|
||||
|
||||
virtual void* tryAllocateExecutable(unsigned sizeInBytes)
|
||||
{
|
||||
#ifdef MAP_32BIT
|
||||
// map to the lower 32 bits of memory when possible so as to avoid
|
||||
// expensive relative jumps
|
||||
const unsigned Extra = MAP_32BIT;
|
||||
#else
|
||||
const unsigned Extra = 0;
|
||||
#endif
|
||||
|
||||
void* p = mmap(0,
|
||||
sizeInBytes,
|
||||
PROT_EXEC | PROT_READ | PROT_WRITE,
|
||||
MAP_PRIVATE | MAP_ANON | Extra,
|
||||
-1,
|
||||
0);
|
||||
|
||||
if (p == MAP_FAILED) {
|
||||
return 0;
|
||||
} else {
|
||||
// fprintf(stderr, "executable from %p to %p\n", p,
|
||||
// static_cast<uint8_t*>(p) + sizeInBytes);
|
||||
return static_cast<uint8_t*>(p);
|
||||
}
|
||||
}
|
||||
|
||||
virtual void freeExecutable(const void* p, unsigned sizeInBytes)
|
||||
{
|
||||
munmap(const_cast<void*>(p), sizeInBytes);
|
||||
}
|
||||
|
||||
virtual bool success(Status s)
|
||||
{
|
||||
virtual bool success(Status s) {
|
||||
return s == 0;
|
||||
}
|
||||
|
||||
@ -887,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);
|
||||
|
63
src/system/posix/memory.cpp
Normal file
63
src/system/posix/memory.cpp
Normal file
@ -0,0 +1,63 @@
|
||||
/* Copyright (c) 2008-2014, 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/system/memory.h>
|
||||
|
||||
#include <avian/util/assert.h>
|
||||
|
||||
#include "sys/mman.h"
|
||||
|
||||
namespace avian {
|
||||
namespace system {
|
||||
|
||||
const size_t Memory::PageSize = 1 << 12;
|
||||
|
||||
util::Slice<uint8_t> Memory::allocate(size_t sizeInBytes,
|
||||
Permissions perms)
|
||||
{
|
||||
unsigned prot = 0;
|
||||
if(perms & Read) {
|
||||
prot |= PROT_READ;
|
||||
}
|
||||
if(perms & Write) {
|
||||
prot |= PROT_WRITE;
|
||||
}
|
||||
if(perms & Execute) {
|
||||
prot |= PROT_EXEC;
|
||||
}
|
||||
#ifdef MAP_32BIT
|
||||
// map to the lower 32 bits of memory when possible so as to avoid
|
||||
// expensive relative jumps
|
||||
const unsigned Extra = MAP_32BIT;
|
||||
#else
|
||||
const unsigned Extra = 0;
|
||||
#endif
|
||||
|
||||
void* p = mmap(0,
|
||||
sizeInBytes,
|
||||
prot,
|
||||
MAP_PRIVATE | MAP_ANON | Extra,
|
||||
-1,
|
||||
0);
|
||||
|
||||
if (p == MAP_FAILED) {
|
||||
return util::Slice<uint8_t>(0, 0);
|
||||
} else {
|
||||
return util::Slice<uint8_t>(static_cast<uint8_t*>(p), sizeInBytes);
|
||||
}
|
||||
}
|
||||
|
||||
void Memory::free(util::Slice<uint8_t> pages)
|
||||
{
|
||||
munmap(const_cast<uint8_t*>(pages.begin()), pages.count);
|
||||
}
|
||||
|
||||
} // namespace system
|
||||
} // namespace avian
|
@ -675,22 +675,7 @@ class MySystem : public System {
|
||||
::free(const_cast<void*>(p));
|
||||
}
|
||||
|
||||
#if !defined(AVIAN_AOT_ONLY)
|
||||
virtual void* tryAllocateExecutable(unsigned sizeInBytes)
|
||||
{
|
||||
return VirtualAlloc(
|
||||
0, sizeInBytes, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);
|
||||
}
|
||||
|
||||
virtual void freeExecutable(const void* p, unsigned)
|
||||
{
|
||||
int r UNUSED = VirtualFree(const_cast<void*>(p), 0, MEM_RELEASE);
|
||||
assertT(this, r);
|
||||
}
|
||||
#endif
|
||||
|
||||
virtual bool success(Status s)
|
||||
{
|
||||
virtual bool success(Status s) {
|
||||
return s == 0;
|
||||
}
|
||||
|
||||
@ -908,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)
|
||||
|
55
src/system/windows/memory.cpp
Normal file
55
src/system/windows/memory.cpp
Normal file
@ -0,0 +1,55 @@
|
||||
/* Copyright (c) 2008-2014, 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/system/memory.h>
|
||||
|
||||
#include <avian/util/assert.h>
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
namespace avian {
|
||||
namespace system {
|
||||
|
||||
const size_t Memory::PageSize = 1 << 12;
|
||||
|
||||
util::Slice<uint8_t> Memory::allocate(size_t sizeInBytes,
|
||||
Permissions perms)
|
||||
{
|
||||
unsigned prot;
|
||||
switch(perms) {
|
||||
case Read:
|
||||
prot = PAGE_READONLY;
|
||||
break;
|
||||
case ReadWrite:
|
||||
prot = PAGE_READWRITE;
|
||||
break;
|
||||
case ReadExecute:
|
||||
prot = PAGE_EXECUTE_READ;
|
||||
break;
|
||||
case ReadWriteExecute:
|
||||
prot = PAGE_EXECUTE_READWRITE;
|
||||
break;
|
||||
default:
|
||||
UNREACHABLE_;
|
||||
}
|
||||
void* ret = VirtualAlloc(
|
||||
0, sizeInBytes, MEM_COMMIT | MEM_RESERVE, prot);
|
||||
return util::Slice<uint8_t>((uint8_t*)ret, sizeInBytes);
|
||||
}
|
||||
|
||||
void Memory::free(util::Slice<uint8_t> pages)
|
||||
{
|
||||
int r = VirtualFree(pages.begin(), 0, MEM_RELEASE);
|
||||
(void) r;
|
||||
ASSERT(r);
|
||||
}
|
||||
|
||||
} // namespace system
|
||||
} // namespace avian
|
@ -1431,7 +1431,7 @@ void writeBootImage2(Thread* t,
|
||||
// sequence point, for gc (don't recombine statements)
|
||||
roots(t)->setOutOfMemoryError(t, throwable);
|
||||
|
||||
Zone zone(t->m->system, t->m->heap, 64 * 1024);
|
||||
Zone zone(t->m->heap, 64 * 1024);
|
||||
|
||||
class MyCompilationHandler : public Processor::CompilationHandler {
|
||||
public:
|
||||
|
@ -1630,27 +1630,22 @@ 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(unsigned size)
|
||||
virtual void* allocate(size_t size)
|
||||
{
|
||||
return s->tryAllocate(size);
|
||||
}
|
||||
|
||||
virtual void* allocate(unsigned size)
|
||||
{
|
||||
void* p = tryAllocate(size);
|
||||
void* p = s->tryAllocate(size);
|
||||
if (p == 0) {
|
||||
abort(s);
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
virtual void free(const void* p, unsigned)
|
||||
virtual void free(const void* p, size_t)
|
||||
{
|
||||
s->free(p);
|
||||
}
|
||||
|
@ -20,14 +20,14 @@ FixedAllocator::FixedAllocator(Aborter* a, Slice<uint8_t> memory)
|
||||
{
|
||||
}
|
||||
|
||||
void* FixedAllocator::tryAllocate(unsigned size)
|
||||
void* FixedAllocator::tryAllocate(size_t size)
|
||||
{
|
||||
return allocate(size);
|
||||
}
|
||||
|
||||
void* FixedAllocator::allocate(unsigned size, unsigned padAlignment)
|
||||
void* FixedAllocator::allocate(size_t size, unsigned padAlignment)
|
||||
{
|
||||
unsigned paddedSize = vm::pad(size, padAlignment);
|
||||
size_t paddedSize = vm::pad(size, padAlignment);
|
||||
expect(a, offset + paddedSize < memory.count);
|
||||
|
||||
void* p = memory.begin() + offset;
|
||||
@ -35,12 +35,12 @@ void* FixedAllocator::allocate(unsigned size, unsigned padAlignment)
|
||||
return p;
|
||||
}
|
||||
|
||||
void* FixedAllocator::allocate(unsigned size)
|
||||
void* FixedAllocator::allocate(size_t size)
|
||||
{
|
||||
return allocate(size, vm::BytesPerWord);
|
||||
}
|
||||
|
||||
void FixedAllocator::free(const void* p, unsigned size)
|
||||
void FixedAllocator::free(const void* p, size_t size)
|
||||
{
|
||||
if (p >= memory.begin()
|
||||
and static_cast<const uint8_t*>(p) + size == memory.begin() + offset) {
|
||||
|
@ -52,7 +52,7 @@ class Asm {
|
||||
Assembler* a;
|
||||
|
||||
Asm(BasicEnv& env)
|
||||
: zone(env.s, env.heap, 8192), a(env.arch->makeAssembler(env.heap, &zone))
|
||||
: zone(env.heap, 8192), a(env.arch->makeAssembler(env.heap, &zone))
|
||||
{
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user