mirror of
https://github.com/corda/corda.git
synced 2025-01-07 13:38:47 +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 avian {
|
||||||
|
|
||||||
namespace util {
|
namespace util {
|
||||||
class Allocator;
|
class Alloc;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace codegen {
|
namespace codegen {
|
||||||
@ -143,7 +143,7 @@ class Architecture {
|
|||||||
unsigned cSize,
|
unsigned cSize,
|
||||||
OperandMask& cMask) = 0;
|
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 acquire() = 0;
|
||||||
virtual void release() = 0;
|
virtual void release() = 0;
|
||||||
|
@ -35,11 +35,6 @@ class Type {
|
|||||||
Float,
|
Float,
|
||||||
Address,
|
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
|
// Represents the lack of a return value
|
||||||
// TODO: remove when possible
|
// TODO: remove when possible
|
||||||
Void,
|
Void,
|
||||||
|
@ -118,7 +118,7 @@ class OffsetPromise : public Promise {
|
|||||||
|
|
||||||
class ListenPromise : public Promise {
|
class ListenPromise : public Promise {
|
||||||
public:
|
public:
|
||||||
ListenPromise(vm::System* s, util::Allocator* allocator)
|
ListenPromise(vm::System* s, util::AllocOnly* allocator)
|
||||||
: s(s), allocator(allocator), listener(0)
|
: s(s), allocator(allocator), listener(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -142,7 +142,7 @@ class ListenPromise : public Promise {
|
|||||||
}
|
}
|
||||||
|
|
||||||
vm::System* s;
|
vm::System* s;
|
||||||
util::Allocator* allocator;
|
util::AllocOnly* allocator;
|
||||||
Listener* listener;
|
Listener* listener;
|
||||||
Promise* promise;
|
Promise* promise;
|
||||||
};
|
};
|
||||||
@ -150,7 +150,7 @@ class ListenPromise : public Promise {
|
|||||||
class DelayedPromise : public ListenPromise {
|
class DelayedPromise : public ListenPromise {
|
||||||
public:
|
public:
|
||||||
DelayedPromise(vm::System* s,
|
DelayedPromise(vm::System* s,
|
||||||
util::Allocator* allocator,
|
util::AllocOnly* allocator,
|
||||||
Promise* basis,
|
Promise* basis,
|
||||||
DelayedPromise* next)
|
DelayedPromise* next)
|
||||||
: ListenPromise(s, allocator), basis(basis), next(next)
|
: ListenPromise(s, allocator), basis(basis), next(next)
|
||||||
|
@ -58,10 +58,10 @@ class Heap : public avian::util::Allocator {
|
|||||||
unsigned footprint,
|
unsigned footprint,
|
||||||
int pendingAllocation) = 0;
|
int pendingAllocation) = 0;
|
||||||
virtual unsigned fixedFootprint(unsigned sizeInWords, bool objectMask) = 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,
|
unsigned sizeInWords,
|
||||||
bool objectMask) = 0;
|
bool objectMask) = 0;
|
||||||
virtual void* allocateImmortalFixed(avian::util::Allocator* allocator,
|
virtual void* allocateImmortalFixed(avian::util::Alloc* allocator,
|
||||||
unsigned sizeInWords,
|
unsigned sizeInWords,
|
||||||
bool objectMask) = 0;
|
bool objectMask) = 0;
|
||||||
virtual void mark(void* p, unsigned offset, unsigned count) = 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 bool success(Status) = 0;
|
||||||
virtual void* tryAllocate(unsigned sizeInBytes) = 0;
|
virtual void* tryAllocate(unsigned sizeInBytes) = 0;
|
||||||
virtual void free(const void* p) = 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 attach(Runnable*) = 0;
|
||||||
virtual Status start(Runnable*) = 0;
|
virtual Status start(Runnable*) = 0;
|
||||||
virtual Status make(Mutex**) = 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 Status load(Library**, const char* name) = 0;
|
||||||
virtual char pathSeparator() = 0;
|
virtual char pathSeparator() = 0;
|
||||||
virtual char fileSeparator() = 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;
|
const char* name) = 0;
|
||||||
virtual int64_t now() = 0;
|
virtual int64_t now() = 0;
|
||||||
virtual void yield() = 0;
|
virtual void yield() = 0;
|
||||||
|
@ -16,18 +16,25 @@
|
|||||||
namespace avian {
|
namespace avian {
|
||||||
namespace util {
|
namespace util {
|
||||||
|
|
||||||
class Allocator {
|
class AllocOnly {
|
||||||
public:
|
public:
|
||||||
// TODO: use size_t instead of unsigned
|
virtual void* allocate(size_t size) = 0;
|
||||||
virtual void* tryAllocate(unsigned size) = 0;
|
};
|
||||||
virtual void* allocate(unsigned size) = 0;
|
|
||||||
virtual void free(const void* p, unsigned 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 util
|
||||||
} // namespace avian
|
} // 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);
|
return allocator->allocate(size);
|
||||||
}
|
}
|
||||||
|
@ -20,17 +20,17 @@ namespace util {
|
|||||||
|
|
||||||
// An Allocator that allocates, bump-pointer style, out of a pre-defined chunk
|
// An Allocator that allocates, bump-pointer style, out of a pre-defined chunk
|
||||||
// of memory.
|
// of memory.
|
||||||
class FixedAllocator : public Allocator {
|
class FixedAllocator : public Alloc {
|
||||||
public:
|
public:
|
||||||
FixedAllocator(Aborter* a, Slice<uint8_t> memory);
|
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;
|
Aborter* a;
|
||||||
Slice<uint8_t> memory;
|
Slice<uint8_t> memory;
|
||||||
|
@ -69,12 +69,12 @@ class Slice {
|
|||||||
return Slice<T>(this->begin() + begin, count);
|
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);
|
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));
|
Slice<T> slice(alloc(a, count));
|
||||||
for (size_t i = 0; i < count; i++) {
|
for (size_t i = 0; i < count; i++) {
|
||||||
@ -83,14 +83,14 @@ class Slice {
|
|||||||
return 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));
|
T* newItems = (T*)a->allocate(newCount * sizeof(T));
|
||||||
memcpy(newItems, items, min(count, newCount) * sizeof(T));
|
memcpy(newItems, items, min(count, newCount) * sizeof(T));
|
||||||
return Slice<T>(newItems, newCount);
|
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));
|
Slice<T> slice(clone(a, newCount));
|
||||||
for (size_t i = count; i < newCount; i++) {
|
for (size_t i = count; i < newCount; i++) {
|
||||||
@ -99,7 +99,7 @@ class Slice {
|
|||||||
return slice;
|
return slice;
|
||||||
}
|
}
|
||||||
|
|
||||||
void resize(Allocator* a, size_t newCount)
|
void resize(Alloc* a, size_t newCount)
|
||||||
{
|
{
|
||||||
Slice<T> slice(clone(a, newCount));
|
Slice<T> slice(clone(a, newCount));
|
||||||
a->free(items, count);
|
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 util
|
||||||
} // namespace avain
|
} // 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)
|
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)
|
ifeq ($(platform),windows)
|
||||||
target-format = pe
|
target-format = pe
|
||||||
|
|
||||||
@ -787,6 +783,7 @@ ifeq ($(platform),windows)
|
|||||||
strip = $(prefix)strip --strip-all
|
strip = $(prefix)strip --strip-all
|
||||||
else
|
else
|
||||||
build-system = windows
|
build-system = windows
|
||||||
|
static-on-windows = -static
|
||||||
common-cflags += "-I$(JAVA_HOME)/include/win32"
|
common-cflags += "-I$(JAVA_HOME)/include/win32"
|
||||||
build-cflags = $(common-cflags) -I$(src) -I$(inc) -mthreads
|
build-cflags = $(common-cflags) -I$(src) -I$(inc) -mthreads
|
||||||
openjdk-extra-cflags =
|
openjdk-extra-cflags =
|
||||||
@ -1138,6 +1135,7 @@ vm-depends := $(generated-code) \
|
|||||||
vm-sources = \
|
vm-sources = \
|
||||||
$(src)/system/$(system).cpp \
|
$(src)/system/$(system).cpp \
|
||||||
$(src)/system/$(system)/signal.cpp \
|
$(src)/system/$(system)/signal.cpp \
|
||||||
|
$(src)/system/$(system)/memory.cpp \
|
||||||
$(src)/finder.cpp \
|
$(src)/finder.cpp \
|
||||||
$(src)/machine.cpp \
|
$(src)/machine.cpp \
|
||||||
$(src)/util.cpp \
|
$(src)/util.cpp \
|
||||||
@ -1273,6 +1271,7 @@ generator-sources = \
|
|||||||
$(src)/tools/type-generator/main.cpp \
|
$(src)/tools/type-generator/main.cpp \
|
||||||
$(src)/system/$(build-system).cpp \
|
$(src)/system/$(build-system).cpp \
|
||||||
$(src)/system/$(build-system)/signal.cpp \
|
$(src)/system/$(build-system)/signal.cpp \
|
||||||
|
$(src)/system/$(build-system)/memory.cpp \
|
||||||
$(src)/finder.cpp \
|
$(src)/finder.cpp \
|
||||||
$(src)/util/arg-parser.cpp
|
$(src)/util/arg-parser.cpp
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ namespace vm {
|
|||||||
class Vector {
|
class Vector {
|
||||||
public:
|
public:
|
||||||
Vector(avian::util::Aborter* a,
|
Vector(avian::util::Aborter* a,
|
||||||
avian::util::Allocator* allocator,
|
avian::util::Alloc* allocator,
|
||||||
size_t minimumCapacity)
|
size_t minimumCapacity)
|
||||||
: a(a),
|
: a(a),
|
||||||
allocator(allocator),
|
allocator(allocator),
|
||||||
@ -175,7 +175,7 @@ class Vector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
avian::util::Aborter* a;
|
avian::util::Aborter* a;
|
||||||
avian::util::Allocator* allocator;
|
avian::util::Alloc* allocator;
|
||||||
avian::util::Slice<uint8_t> data;
|
avian::util::Slice<uint8_t> data;
|
||||||
size_t position;
|
size_t position;
|
||||||
size_t minimumCapacity;
|
size_t minimumCapacity;
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
namespace vm {
|
namespace vm {
|
||||||
|
|
||||||
inline const char* append(avian::util::Allocator* allocator,
|
inline const char* append(avian::util::AllocOnly* allocator,
|
||||||
const char* a,
|
const char* a,
|
||||||
const char* b,
|
const char* b,
|
||||||
const char* c)
|
const char* c)
|
||||||
@ -31,7 +31,7 @@ inline const char* append(avian::util::Allocator* allocator,
|
|||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const char* append(avian::util::Allocator* allocator,
|
inline const char* append(avian::util::AllocOnly* allocator,
|
||||||
const char* a,
|
const char* a,
|
||||||
const char* b)
|
const char* b)
|
||||||
{
|
{
|
||||||
@ -43,7 +43,7 @@ inline const char* append(avian::util::Allocator* allocator,
|
|||||||
return p;
|
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);
|
unsigned al = strlen(a);
|
||||||
char* p = static_cast<char*>(allocator->allocate(al + 1));
|
char* p = static_cast<char*>(allocator->allocate(al + 1));
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
|
|
||||||
#include <avian/util/string.h>
|
#include <avian/util/string.h>
|
||||||
#include <avian/util/runtime-array.h>
|
#include <avian/util/runtime-array.h>
|
||||||
|
#include <avian/util/tokenizer.h>
|
||||||
|
|
||||||
using namespace avian::util;
|
using namespace avian::util;
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
namespace avian {
|
namespace avian {
|
||||||
namespace util {
|
namespace util {
|
||||||
class Allocator;
|
class Alloc;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -202,12 +202,12 @@ class Finder {
|
|||||||
};
|
};
|
||||||
|
|
||||||
AVIAN_EXPORT Finder* makeFinder(System* s,
|
AVIAN_EXPORT Finder* makeFinder(System* s,
|
||||||
avian::util::Allocator* a,
|
avian::util::Alloc* a,
|
||||||
const char* path,
|
const char* path,
|
||||||
const char* bootLibrary);
|
const char* bootLibrary);
|
||||||
|
|
||||||
Finder* makeFinder(System* s,
|
Finder* makeFinder(System* s,
|
||||||
avian::util::Allocator* a,
|
avian::util::Alloc* a,
|
||||||
const uint8_t* jarData,
|
const uint8_t* jarData,
|
||||||
unsigned jarLength);
|
unsigned jarLength);
|
||||||
|
|
||||||
|
@ -15,20 +15,20 @@
|
|||||||
|
|
||||||
namespace avian {
|
namespace avian {
|
||||||
namespace util {
|
namespace util {
|
||||||
class Allocator;
|
class AllocOnly;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace vm {
|
namespace vm {
|
||||||
|
|
||||||
uint8_t* decodeLZMA(System* s,
|
uint8_t* decodeLZMA(System* s,
|
||||||
avian::util::Allocator* a,
|
avian::util::AllocOnly* a,
|
||||||
uint8_t* in,
|
uint8_t* in,
|
||||||
unsigned inSize,
|
unsigned inSize,
|
||||||
unsigned* outSize);
|
unsigned* outSize);
|
||||||
|
|
||||||
uint8_t* encodeLZMA(System* s,
|
uint8_t* encodeLZMA(System* s,
|
||||||
avian::util::Allocator* a,
|
avian::util::AllocOnly* a,
|
||||||
uint8_t* in,
|
uint8_t* in,
|
||||||
unsigned inSize,
|
unsigned inSize,
|
||||||
unsigned* outSize);
|
unsigned* outSize);
|
||||||
|
@ -1596,7 +1596,7 @@ inline bool ensure(Thread* t, unsigned sizeInBytes)
|
|||||||
object allocate2(Thread* t, unsigned sizeInBytes, bool objectMask);
|
object allocate2(Thread* t, unsigned sizeInBytes, bool objectMask);
|
||||||
|
|
||||||
object allocate3(Thread* t,
|
object allocate3(Thread* t,
|
||||||
Allocator* allocator,
|
Alloc* allocator,
|
||||||
Machine::AllocationType type,
|
Machine::AllocationType type,
|
||||||
unsigned sizeInBytes,
|
unsigned sizeInBytes,
|
||||||
bool objectMask);
|
bool objectMask);
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
namespace vm {
|
namespace vm {
|
||||||
|
|
||||||
class Zone : public avian::util::Allocator {
|
class Zone : public avian::util::AllocOnly {
|
||||||
public:
|
public:
|
||||||
class Segment {
|
class Segment {
|
||||||
public:
|
public:
|
||||||
@ -31,9 +31,8 @@ class Zone : public avian::util::Allocator {
|
|||||||
uint8_t data[0];
|
uint8_t data[0];
|
||||||
};
|
};
|
||||||
|
|
||||||
Zone(System* s, Allocator* allocator, unsigned minimumFootprint)
|
Zone(avian::util::Allocator* allocator, size_t minimumFootprint)
|
||||||
: s(s),
|
: allocator(allocator),
|
||||||
allocator(allocator),
|
|
||||||
segment(0),
|
segment(0),
|
||||||
minimumFootprint(minimumFootprint < sizeof(Segment)
|
minimumFootprint(minimumFootprint < sizeof(Segment)
|
||||||
? 0
|
? 0
|
||||||
@ -56,6 +55,46 @@ class Zone : public avian::util::Allocator {
|
|||||||
segment = 0;
|
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)
|
static unsigned padToPage(unsigned size)
|
||||||
{
|
{
|
||||||
return (size + (LikelyPageSizeInBytes - 1)) & ~(LikelyPageSizeInBytes - 1);
|
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);
|
size = pad(size);
|
||||||
if (tryEnsure(size)) {
|
if (tryEnsure(size)) {
|
||||||
@ -107,54 +146,7 @@ class Zone : public avian::util::Allocator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void* allocate(unsigned size)
|
avian::util::Allocator* allocator;
|
||||||
{
|
|
||||||
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;
|
|
||||||
Segment* segment;
|
Segment* segment;
|
||||||
unsigned minimumFootprint;
|
unsigned minimumFootprint;
|
||||||
};
|
};
|
||||||
|
@ -1309,7 +1309,6 @@ unsigned typeFootprint(Context* c, ir::Type type)
|
|||||||
return type.rawSize() / 4;
|
return type.rawSize() / 4;
|
||||||
case ir::Type::Object:
|
case ir::Type::Object:
|
||||||
case ir::Type::Address:
|
case ir::Type::Address:
|
||||||
case ir::Type::Half:
|
|
||||||
return 1;
|
return 1;
|
||||||
case ir::Type::Void:
|
case ir::Type::Void:
|
||||||
return 0;
|
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()
|
virtual void acquire()
|
||||||
{
|
{
|
||||||
@ -639,7 +639,7 @@ class MyArchitecture : public Architecture {
|
|||||||
|
|
||||||
class MyAssembler : public Assembler {
|
class MyAssembler : public Assembler {
|
||||||
public:
|
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)
|
: con(s, a, zone), arch_(arch)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -1075,7 +1075,7 @@ class MyAssembler : public Assembler {
|
|||||||
MyArchitecture* arch_;
|
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);
|
return new (zone) MyAssembler(this->con.s, allocator, zone, this);
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ namespace avian {
|
|||||||
namespace codegen {
|
namespace codegen {
|
||||||
namespace arm {
|
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),
|
: s(s),
|
||||||
zone(zone),
|
zone(zone),
|
||||||
client(0),
|
client(0),
|
||||||
|
@ -24,7 +24,7 @@ namespace avian {
|
|||||||
|
|
||||||
namespace util {
|
namespace util {
|
||||||
class Aborter;
|
class Aborter;
|
||||||
class Allocator;
|
class Alloc;
|
||||||
} // namespace util
|
} // namespace util
|
||||||
|
|
||||||
namespace codegen {
|
namespace codegen {
|
||||||
@ -37,7 +37,7 @@ class ConstantPoolEntry;
|
|||||||
|
|
||||||
class Context {
|
class Context {
|
||||||
public:
|
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::System* s;
|
||||||
vm::Zone* zone;
|
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()
|
virtual void acquire()
|
||||||
{
|
{
|
||||||
@ -908,7 +908,7 @@ class MyArchitecture : public Architecture {
|
|||||||
|
|
||||||
class MyAssembler : public Assembler {
|
class MyAssembler : public Assembler {
|
||||||
public:
|
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)
|
: c(s, a, zone, &(arch->c)), arch_(arch)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -1273,7 +1273,7 @@ class MyAssembler : public Assembler {
|
|||||||
MyArchitecture* arch_;
|
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);
|
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,
|
Context::Context(vm::System* s,
|
||||||
util::Allocator* a,
|
util::Alloc* a,
|
||||||
vm::Zone* zone,
|
vm::Zone* zone,
|
||||||
ArchitectureContext* ac)
|
ArchitectureContext* ac)
|
||||||
: s(s),
|
: s(s),
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
|
|
||||||
namespace vm {
|
namespace vm {
|
||||||
class System;
|
class System;
|
||||||
class Allocator;
|
class Alloc;
|
||||||
class Zone;
|
class Zone;
|
||||||
} // namespace vm
|
} // namespace vm
|
||||||
|
|
||||||
@ -80,7 +80,7 @@ class ArchitectureContext {
|
|||||||
class Context {
|
class Context {
|
||||||
public:
|
public:
|
||||||
Context(vm::System* s,
|
Context(vm::System* s,
|
||||||
util::Allocator* a,
|
util::Alloc* a,
|
||||||
vm::Zone* zone,
|
vm::Zone* zone,
|
||||||
ArchitectureContext* ac);
|
ArchitectureContext* ac);
|
||||||
|
|
||||||
|
@ -15,6 +15,8 @@
|
|||||||
#include "avian/target.h"
|
#include "avian/target.h"
|
||||||
#include "avian/arch.h"
|
#include "avian/arch.h"
|
||||||
|
|
||||||
|
#include <avian/system/memory.h>
|
||||||
|
|
||||||
#include <avian/codegen/assembler.h>
|
#include <avian/codegen/assembler.h>
|
||||||
#include <avian/codegen/architecture.h>
|
#include <avian/codegen/architecture.h>
|
||||||
#include <avian/codegen/compiler.h>
|
#include <avian/codegen/compiler.h>
|
||||||
@ -1156,7 +1158,7 @@ class Context {
|
|||||||
|
|
||||||
Context(MyThread* t, BootContext* bootContext, GcMethod* method)
|
Context(MyThread* t, BootContext* bootContext, GcMethod* method)
|
||||||
: thread(t),
|
: thread(t),
|
||||||
zone(t->m->system, t->m->heap, InitialZoneCapacityInBytes),
|
zone(t->m->heap, InitialZoneCapacityInBytes),
|
||||||
assembler(t->arch->makeAssembler(t->m->heap, &zone)),
|
assembler(t->arch->makeAssembler(t->m->heap, &zone)),
|
||||||
client(t),
|
client(t),
|
||||||
compiler(makeCompiler(t->m->system, assembler, &zone, &client)),
|
compiler(makeCompiler(t->m->system, assembler, &zone, &client)),
|
||||||
@ -1189,7 +1191,7 @@ class Context {
|
|||||||
|
|
||||||
Context(MyThread* t)
|
Context(MyThread* t)
|
||||||
: thread(t),
|
: thread(t),
|
||||||
zone(t->m->system, t->m->heap, InitialZoneCapacityInBytes),
|
zone(t->m->heap, InitialZoneCapacityInBytes),
|
||||||
assembler(t->arch->makeAssembler(t->m->heap, &zone)),
|
assembler(t->arch->makeAssembler(t->m->heap, &zone)),
|
||||||
client(t),
|
client(t),
|
||||||
compiler(0),
|
compiler(0),
|
||||||
@ -1262,7 +1264,7 @@ class Context {
|
|||||||
TraceElement* traceLog;
|
TraceElement* traceLog;
|
||||||
Slice<uint16_t> visitTable;
|
Slice<uint16_t> visitTable;
|
||||||
Slice<uintptr_t> rootTable;
|
Slice<uintptr_t> rootTable;
|
||||||
Allocator* executableAllocator;
|
Alloc* executableAllocator;
|
||||||
void* executableStart;
|
void* executableStart;
|
||||||
unsigned executableSize;
|
unsigned executableSize;
|
||||||
unsigned objectPoolCount;
|
unsigned objectPoolCount;
|
||||||
@ -3741,8 +3743,7 @@ class Stack {
|
|||||||
Stack* s;
|
Stack* s;
|
||||||
};
|
};
|
||||||
|
|
||||||
Stack(MyThread* t)
|
Stack(MyThread* t) : thread(t), zone(t->m->heap, 0), resource(this)
|
||||||
: thread(t), zone(t->m->system, t->m->heap, 0), resource(this)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -8842,8 +8843,7 @@ class MyProcessor : public Processor {
|
|||||||
{
|
{
|
||||||
if (codeAllocator.memory.begin()) {
|
if (codeAllocator.memory.begin()) {
|
||||||
#if !defined(AVIAN_AOT_ONLY)
|
#if !defined(AVIAN_AOT_ONLY)
|
||||||
s->freeExecutable(codeAllocator.memory.begin(),
|
Memory::free(codeAllocator.memory);
|
||||||
codeAllocator.memory.count);
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -9023,12 +9023,10 @@ class MyProcessor : public Processor {
|
|||||||
{
|
{
|
||||||
#if !defined(AVIAN_AOT_ONLY)
|
#if !defined(AVIAN_AOT_ONLY)
|
||||||
if (codeAllocator.memory.begin() == 0) {
|
if (codeAllocator.memory.begin() == 0) {
|
||||||
codeAllocator.memory.items = static_cast<uint8_t*>(
|
codeAllocator.memory = Memory::allocate(ExecutableAreaSizeInBytes,
|
||||||
s->tryAllocateExecutable(ExecutableAreaSizeInBytes));
|
Memory::ReadWriteExecute);
|
||||||
|
|
||||||
expect(t, codeAllocator.memory.items);
|
expect(t, codeAllocator.memory.begin());
|
||||||
|
|
||||||
codeAllocator.memory.count = ExecutableAreaSizeInBytes;
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -13,6 +13,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/hash.h>
|
#include <avian/util/hash.h>
|
||||||
|
#include <avian/util/tokenizer.h>
|
||||||
|
|
||||||
#include "avian/zlib-custom.h"
|
#include "avian/zlib-custom.h"
|
||||||
#include "avian/finder.h"
|
#include "avian/finder.h"
|
||||||
@ -55,7 +56,7 @@ class DirectoryElement : public Element {
|
|||||||
public:
|
public:
|
||||||
class Iterator : public Element::Iterator {
|
class Iterator : public Element::Iterator {
|
||||||
public:
|
public:
|
||||||
Iterator(System* s, Allocator* allocator, const char* name, unsigned skip)
|
Iterator(System* s, Alloc* allocator, const char* name, unsigned skip)
|
||||||
: s(s),
|
: s(s),
|
||||||
allocator(allocator),
|
allocator(allocator),
|
||||||
name(name),
|
name(name),
|
||||||
@ -112,7 +113,7 @@ class DirectoryElement : public Element {
|
|||||||
}
|
}
|
||||||
|
|
||||||
System* s;
|
System* s;
|
||||||
Allocator* allocator;
|
Alloc* allocator;
|
||||||
const char* name;
|
const char* name;
|
||||||
unsigned skip;
|
unsigned skip;
|
||||||
System::Directory* directory;
|
System::Directory* directory;
|
||||||
@ -120,7 +121,7 @@ class DirectoryElement : public Element {
|
|||||||
Iterator* it;
|
Iterator* it;
|
||||||
};
|
};
|
||||||
|
|
||||||
DirectoryElement(System* s, Allocator* allocator, const char* name)
|
DirectoryElement(System* s, Alloc* allocator, const char* name)
|
||||||
: s(s),
|
: s(s),
|
||||||
allocator(allocator),
|
allocator(allocator),
|
||||||
originalName(name),
|
originalName(name),
|
||||||
@ -187,7 +188,7 @@ class DirectoryElement : public Element {
|
|||||||
}
|
}
|
||||||
|
|
||||||
System* s;
|
System* s;
|
||||||
Allocator* allocator;
|
Alloc* allocator;
|
||||||
const char* originalName;
|
const char* originalName;
|
||||||
const char* name;
|
const char* name;
|
||||||
const char* urlPrefix_;
|
const char* urlPrefix_;
|
||||||
@ -197,7 +198,7 @@ class DirectoryElement : public Element {
|
|||||||
class PointerRegion : public System::Region {
|
class PointerRegion : public System::Region {
|
||||||
public:
|
public:
|
||||||
PointerRegion(System* s,
|
PointerRegion(System* s,
|
||||||
Allocator* allocator,
|
Alloc* allocator,
|
||||||
const uint8_t* start,
|
const uint8_t* start,
|
||||||
size_t length,
|
size_t length,
|
||||||
bool freePointer = false)
|
bool freePointer = false)
|
||||||
@ -228,7 +229,7 @@ class PointerRegion : public System::Region {
|
|||||||
}
|
}
|
||||||
|
|
||||||
System* s;
|
System* s;
|
||||||
Allocator* allocator;
|
Alloc* allocator;
|
||||||
const uint8_t* start_;
|
const uint8_t* start_;
|
||||||
size_t length_;
|
size_t length_;
|
||||||
bool freePointer;
|
bool freePointer;
|
||||||
@ -236,7 +237,7 @@ class PointerRegion : public System::Region {
|
|||||||
|
|
||||||
class DataRegion : public System::Region {
|
class DataRegion : public System::Region {
|
||||||
public:
|
public:
|
||||||
DataRegion(System* s, Allocator* allocator, size_t length)
|
DataRegion(System* s, Alloc* allocator, size_t length)
|
||||||
: s(s), allocator(allocator), length_(length)
|
: s(s), allocator(allocator), length_(length)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -257,7 +258,7 @@ class DataRegion : public System::Region {
|
|||||||
}
|
}
|
||||||
|
|
||||||
System* s;
|
System* s;
|
||||||
Allocator* allocator;
|
Alloc* allocator;
|
||||||
size_t length_;
|
size_t length_;
|
||||||
uint8_t data[0];
|
uint8_t data[0];
|
||||||
};
|
};
|
||||||
@ -276,7 +277,7 @@ class JarIndex {
|
|||||||
const uint8_t* entry;
|
const uint8_t* entry;
|
||||||
};
|
};
|
||||||
|
|
||||||
JarIndex(System* s, Allocator* allocator, unsigned capacity)
|
JarIndex(System* s, Alloc* allocator, unsigned capacity)
|
||||||
: s(s),
|
: s(s),
|
||||||
allocator(allocator),
|
allocator(allocator),
|
||||||
capacity(capacity),
|
capacity(capacity),
|
||||||
@ -287,14 +288,14 @@ class JarIndex {
|
|||||||
memset(table, 0, sizeof(List<Entry>*) * capacity);
|
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)
|
return new (allocator->allocate(sizeof(JarIndex)
|
||||||
+ (sizeof(List<Entry>*) * capacity)))
|
+ (sizeof(List<Entry>*) * capacity)))
|
||||||
JarIndex(s, allocator, 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);
|
JarIndex* index = make(s, allocator, 32);
|
||||||
|
|
||||||
@ -437,7 +438,7 @@ class JarIndex {
|
|||||||
}
|
}
|
||||||
|
|
||||||
System* s;
|
System* s;
|
||||||
Allocator* allocator;
|
Alloc* allocator;
|
||||||
unsigned capacity;
|
unsigned capacity;
|
||||||
unsigned position;
|
unsigned position;
|
||||||
|
|
||||||
@ -449,7 +450,7 @@ class JarElement : public Element {
|
|||||||
public:
|
public:
|
||||||
class Iterator : public Element::Iterator {
|
class Iterator : public Element::Iterator {
|
||||||
public:
|
public:
|
||||||
Iterator(System* s, Allocator* allocator, JarIndex* index)
|
Iterator(System* s, Alloc* allocator, JarIndex* index)
|
||||||
: s(s), allocator(allocator), index(index), position(0)
|
: s(s), allocator(allocator), index(index), position(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -471,13 +472,13 @@ class JarElement : public Element {
|
|||||||
}
|
}
|
||||||
|
|
||||||
System* s;
|
System* s;
|
||||||
Allocator* allocator;
|
Alloc* allocator;
|
||||||
JarIndex* index;
|
JarIndex* index;
|
||||||
unsigned position;
|
unsigned position;
|
||||||
};
|
};
|
||||||
|
|
||||||
JarElement(System* s,
|
JarElement(System* s,
|
||||||
Allocator* allocator,
|
Alloc* allocator,
|
||||||
const char* name,
|
const char* name,
|
||||||
bool canonicalizePath = true)
|
bool canonicalizePath = true)
|
||||||
: s(s),
|
: s(s),
|
||||||
@ -494,7 +495,7 @@ class JarElement : public Element {
|
|||||||
}
|
}
|
||||||
|
|
||||||
JarElement(System* s,
|
JarElement(System* s,
|
||||||
Allocator* allocator,
|
Alloc* allocator,
|
||||||
const uint8_t* jarData,
|
const uint8_t* jarData,
|
||||||
unsigned jarLength)
|
unsigned jarLength)
|
||||||
: s(s),
|
: s(s),
|
||||||
@ -598,7 +599,7 @@ class JarElement : public Element {
|
|||||||
}
|
}
|
||||||
|
|
||||||
System* s;
|
System* s;
|
||||||
Allocator* allocator;
|
Alloc* allocator;
|
||||||
const char* originalName;
|
const char* originalName;
|
||||||
const char* name;
|
const char* name;
|
||||||
const char* urlPrefix_;
|
const char* urlPrefix_;
|
||||||
@ -610,7 +611,7 @@ class JarElement : public Element {
|
|||||||
class BuiltinElement : public JarElement {
|
class BuiltinElement : public JarElement {
|
||||||
public:
|
public:
|
||||||
BuiltinElement(System* s,
|
BuiltinElement(System* s,
|
||||||
Allocator* allocator,
|
Alloc* allocator,
|
||||||
const char* name,
|
const char* name,
|
||||||
const char* libraryName)
|
const char* libraryName)
|
||||||
: JarElement(s, allocator, name, false),
|
: JarElement(s, allocator, name, false),
|
||||||
@ -710,7 +711,7 @@ unsigned baseName(const char* name, char fileSeparator)
|
|||||||
void add(System* s,
|
void add(System* s,
|
||||||
Element** first,
|
Element** first,
|
||||||
Element** last,
|
Element** last,
|
||||||
Allocator* allocator,
|
Alloc* allocator,
|
||||||
const char* name,
|
const char* name,
|
||||||
unsigned nameLength,
|
unsigned nameLength,
|
||||||
const char* bootLibrary);
|
const char* bootLibrary);
|
||||||
@ -718,7 +719,7 @@ void add(System* s,
|
|||||||
void addTokens(System* s,
|
void addTokens(System* s,
|
||||||
Element** first,
|
Element** first,
|
||||||
Element** last,
|
Element** last,
|
||||||
Allocator* allocator,
|
Alloc* allocator,
|
||||||
const char* jarName,
|
const char* jarName,
|
||||||
unsigned jarNameBase,
|
unsigned jarNameBase,
|
||||||
const char* tokens,
|
const char* tokens,
|
||||||
@ -755,7 +756,7 @@ bool continuationLine(const uint8_t* base,
|
|||||||
void addJar(System* s,
|
void addJar(System* s,
|
||||||
Element** first,
|
Element** first,
|
||||||
Element** last,
|
Element** last,
|
||||||
Allocator* allocator,
|
Alloc* allocator,
|
||||||
const char* name,
|
const char* name,
|
||||||
const char* bootLibrary)
|
const char* bootLibrary)
|
||||||
{
|
{
|
||||||
@ -851,7 +852,7 @@ void addJar(System* s,
|
|||||||
void add(System* s,
|
void add(System* s,
|
||||||
Element** first,
|
Element** first,
|
||||||
Element** last,
|
Element** last,
|
||||||
Allocator* allocator,
|
Alloc* allocator,
|
||||||
const char* token,
|
const char* token,
|
||||||
unsigned tokenLength,
|
unsigned tokenLength,
|
||||||
const char* bootLibrary)
|
const char* bootLibrary)
|
||||||
@ -903,7 +904,7 @@ void add(System* s,
|
|||||||
}
|
}
|
||||||
|
|
||||||
Element* parsePath(System* s,
|
Element* parsePath(System* s,
|
||||||
Allocator* allocator,
|
Alloc* allocator,
|
||||||
const char* path,
|
const char* path,
|
||||||
const char* bootLibrary)
|
const char* bootLibrary)
|
||||||
{
|
{
|
||||||
@ -920,7 +921,7 @@ Element* parsePath(System* s,
|
|||||||
|
|
||||||
class MyIterator : public Finder::IteratorImp {
|
class MyIterator : public Finder::IteratorImp {
|
||||||
public:
|
public:
|
||||||
MyIterator(System* s, Allocator* allocator, Element* path)
|
MyIterator(System* s, Alloc* allocator, Element* path)
|
||||||
: s(s),
|
: s(s),
|
||||||
allocator(allocator),
|
allocator(allocator),
|
||||||
e(path ? path->next : 0),
|
e(path ? path->next : 0),
|
||||||
@ -955,7 +956,7 @@ class MyIterator : public Finder::IteratorImp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
System* s;
|
System* s;
|
||||||
Allocator* allocator;
|
Alloc* allocator;
|
||||||
Element* e;
|
Element* e;
|
||||||
Element::Iterator* it;
|
Element::Iterator* it;
|
||||||
};
|
};
|
||||||
@ -963,7 +964,7 @@ class MyIterator : public Finder::IteratorImp {
|
|||||||
class MyFinder : public Finder {
|
class MyFinder : public Finder {
|
||||||
public:
|
public:
|
||||||
MyFinder(System* system,
|
MyFinder(System* system,
|
||||||
Allocator* allocator,
|
Alloc* allocator,
|
||||||
const char* path,
|
const char* path,
|
||||||
const char* bootLibrary)
|
const char* bootLibrary)
|
||||||
: system(system),
|
: system(system),
|
||||||
@ -974,7 +975,7 @@ class MyFinder : public Finder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
MyFinder(System* system,
|
MyFinder(System* system,
|
||||||
Allocator* allocator,
|
Alloc* allocator,
|
||||||
const uint8_t* jarData,
|
const uint8_t* jarData,
|
||||||
unsigned jarLength)
|
unsigned jarLength)
|
||||||
: system(system),
|
: system(system),
|
||||||
@ -1070,7 +1071,7 @@ class MyFinder : public Finder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
System* system;
|
System* system;
|
||||||
Allocator* allocator;
|
Alloc* allocator;
|
||||||
Element* path_;
|
Element* path_;
|
||||||
const char* pathString;
|
const char* pathString;
|
||||||
};
|
};
|
||||||
@ -1080,7 +1081,7 @@ class MyFinder : public Finder {
|
|||||||
namespace vm {
|
namespace vm {
|
||||||
|
|
||||||
AVIAN_EXPORT Finder* makeFinder(System* s,
|
AVIAN_EXPORT Finder* makeFinder(System* s,
|
||||||
Allocator* a,
|
Alloc* a,
|
||||||
const char* path,
|
const char* path,
|
||||||
const char* bootLibrary)
|
const char* bootLibrary)
|
||||||
{
|
{
|
||||||
@ -1088,7 +1089,7 @@ AVIAN_EXPORT Finder* makeFinder(System* s,
|
|||||||
}
|
}
|
||||||
|
|
||||||
Finder* makeFinder(System* s,
|
Finder* makeFinder(System* s,
|
||||||
Allocator* a,
|
Alloc* a,
|
||||||
const uint8_t* jarData,
|
const uint8_t* jarData,
|
||||||
unsigned jarLength)
|
unsigned jarLength)
|
||||||
{
|
{
|
||||||
|
@ -60,10 +60,10 @@ class Context;
|
|||||||
|
|
||||||
Aborter* getAborter(Context* c);
|
Aborter* getAborter(Context* c);
|
||||||
|
|
||||||
void* tryAllocate(Context* c, unsigned size);
|
void* tryAllocate(Context* c, size_t size);
|
||||||
void* allocate(Context* c, unsigned size);
|
void* allocate(Context* c, size_t size);
|
||||||
void* allocate(Context* c, unsigned size, bool limit);
|
void* allocate(Context* c, size_t size, bool limit);
|
||||||
void free(Context* c, const void* p, unsigned size);
|
void free(Context* c, const void* p, size_t size);
|
||||||
|
|
||||||
#ifdef USE_ATOMIC_OPERATIONS
|
#ifdef USE_ATOMIC_OPERATIONS
|
||||||
inline void markBitAtomic(uintptr_t* map, unsigned i)
|
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);
|
ACQUIRE(c->lock);
|
||||||
|
|
||||||
@ -1888,12 +1888,12 @@ void* allocate(Context* c, unsigned size, bool limit)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void* tryAllocate(Context* c, unsigned size)
|
void* tryAllocate(Context* c, size_t size)
|
||||||
{
|
{
|
||||||
return allocate(c, size, true);
|
return allocate(c, size, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void* allocate(Context* c, unsigned size)
|
void* allocate(Context* c, size_t size)
|
||||||
{
|
{
|
||||||
void* p = allocate(c, size, false);
|
void* p = allocate(c, size, false);
|
||||||
expect(c->system, p);
|
expect(c->system, p);
|
||||||
@ -1901,7 +1901,7 @@ void* allocate(Context* c, unsigned size)
|
|||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
void free(Context* c, const void* p, unsigned size)
|
void free(Context* c, const void* p, size_t size)
|
||||||
{
|
{
|
||||||
ACQUIRE(c->lock);
|
ACQUIRE(c->lock);
|
||||||
|
|
||||||
@ -1925,7 +1925,7 @@ void free(Context* c, const void* p, unsigned size)
|
|||||||
c->count -= 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);
|
free(c, p, size);
|
||||||
}
|
}
|
||||||
@ -1963,17 +1963,17 @@ class MyHeap : public Heap {
|
|||||||
return local::limitExceeded(&c, pendingAllocation);
|
return local::limitExceeded(&c, pendingAllocation);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void* tryAllocate(unsigned size)
|
virtual void* tryAllocate(size_t size)
|
||||||
{
|
{
|
||||||
return local::tryAllocate(&c, size);
|
return local::tryAllocate(&c, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void* allocate(unsigned size)
|
virtual void* allocate(size_t size)
|
||||||
{
|
{
|
||||||
return local::allocate(&c, 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);
|
free_(&c, p, size);
|
||||||
}
|
}
|
||||||
@ -1994,7 +1994,7 @@ class MyHeap : public Heap {
|
|||||||
return Fixie::totalSize(sizeInWords, objectMask);
|
return Fixie::totalSize(sizeInWords, objectMask);
|
||||||
}
|
}
|
||||||
|
|
||||||
void* allocateFixed(Allocator* allocator,
|
void* allocateFixed(Alloc* allocator,
|
||||||
unsigned sizeInWords,
|
unsigned sizeInWords,
|
||||||
bool objectMask,
|
bool objectMask,
|
||||||
Fixie** handle,
|
Fixie** handle,
|
||||||
@ -2011,7 +2011,7 @@ class MyHeap : public Heap {
|
|||||||
->body();
|
->body();
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void* allocateFixed(Allocator* allocator,
|
virtual void* allocateFixed(Alloc* allocator,
|
||||||
unsigned sizeInWords,
|
unsigned sizeInWords,
|
||||||
bool objectMask)
|
bool objectMask)
|
||||||
{
|
{
|
||||||
@ -2019,7 +2019,7 @@ class MyHeap : public Heap {
|
|||||||
allocator, sizeInWords, objectMask, &(c.fixies), false);
|
allocator, sizeInWords, objectMask, &(c.fixies), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void* allocateImmortalFixed(Allocator* allocator,
|
virtual void* allocateImmortalFixed(Alloc* allocator,
|
||||||
unsigned sizeInWords,
|
unsigned sizeInWords,
|
||||||
bool objectMask)
|
bool objectMask)
|
||||||
{
|
{
|
||||||
|
@ -27,7 +27,7 @@ int32_t read4(const uint8_t* in)
|
|||||||
namespace vm {
|
namespace vm {
|
||||||
|
|
||||||
uint8_t* decodeLZMA(System* s,
|
uint8_t* decodeLZMA(System* s,
|
||||||
avian::util::Allocator* a,
|
avian::util::AllocOnly* a,
|
||||||
uint8_t* in,
|
uint8_t* in,
|
||||||
unsigned inSize,
|
unsigned inSize,
|
||||||
unsigned* outSize)
|
unsigned* outSize)
|
||||||
|
@ -25,7 +25,7 @@ SRes myProgress(void*, UInt64, UInt64)
|
|||||||
namespace vm {
|
namespace vm {
|
||||||
|
|
||||||
uint8_t* encodeLZMA(System* s,
|
uint8_t* encodeLZMA(System* s,
|
||||||
Allocator* a,
|
AllocOnly* a,
|
||||||
uint8_t* in,
|
uint8_t* in,
|
||||||
unsigned inSize,
|
unsigned inSize,
|
||||||
unsigned* outSize)
|
unsigned* outSize)
|
||||||
|
@ -4175,7 +4175,7 @@ object allocate2(Thread* t, unsigned sizeInBytes, bool objectMask)
|
|||||||
}
|
}
|
||||||
|
|
||||||
object allocate3(Thread* t,
|
object allocate3(Thread* t,
|
||||||
Allocator* allocator,
|
Alloc* allocator,
|
||||||
Machine::AllocationType type,
|
Machine::AllocationType type,
|
||||||
unsigned sizeInBytes,
|
unsigned sizeInBytes,
|
||||||
bool objectMask)
|
bool objectMask)
|
||||||
|
13
src/main.cpp
13
src/main.cpp
@ -62,27 +62,22 @@ const char* mainClass(const char* jar)
|
|||||||
|
|
||||||
System* system = makeSystem();
|
System* system = makeSystem();
|
||||||
|
|
||||||
class MyAllocator : public avian::util::Allocator {
|
class MyAllocator : public avian::util::Alloc {
|
||||||
public:
|
public:
|
||||||
MyAllocator(System* s) : s(s)
|
MyAllocator(System* s) : s(s)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void* tryAllocate(unsigned size)
|
virtual void* allocate(size_t size)
|
||||||
{
|
{
|
||||||
return s->tryAllocate(size);
|
void* p = s->tryAllocate(size);
|
||||||
}
|
|
||||||
|
|
||||||
virtual void* allocate(unsigned size)
|
|
||||||
{
|
|
||||||
void* p = tryAllocate(size);
|
|
||||||
if (p == 0) {
|
if (p == 0) {
|
||||||
abort(s);
|
abort(s);
|
||||||
}
|
}
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void free(const void* p, unsigned)
|
virtual void free(const void* p, size_t)
|
||||||
{
|
{
|
||||||
s->free(p);
|
s->free(p);
|
||||||
}
|
}
|
||||||
|
@ -54,6 +54,7 @@ typedef struct ucontext {
|
|||||||
|
|
||||||
#include <avian/system/system.h>
|
#include <avian/system/system.h>
|
||||||
#include <avian/system/signal.h>
|
#include <avian/system/signal.h>
|
||||||
|
#include <avian/system/memory.h>
|
||||||
#include <avian/util/math.h>
|
#include <avian/util/math.h>
|
||||||
|
|
||||||
#define ACQUIRE(x) MutexResource MAKE_NAME(mutexResource_)(x)
|
#define ACQUIRE(x) MutexResource MAKE_NAME(mutexResource_)(x)
|
||||||
@ -664,39 +665,7 @@ class MySystem : public System {
|
|||||||
::free(const_cast<void*>(p));
|
::free(const_cast<void*>(p));
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void* tryAllocateExecutable(unsigned sizeInBytes)
|
virtual bool success(Status s) {
|
||||||
{
|
|
||||||
#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)
|
|
||||||
{
|
|
||||||
return s == 0;
|
return s == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -887,7 +856,7 @@ class MySystem : public System {
|
|||||||
return SO_SUFFIX;
|
return SO_SUFFIX;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual const char* toAbsolutePath(Allocator* allocator, const char* name)
|
virtual const char* toAbsolutePath(AllocOnly* allocator, const char* name)
|
||||||
{
|
{
|
||||||
if (name[0] == '/') {
|
if (name[0] == '/') {
|
||||||
return copy(allocator, name);
|
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));
|
::free(const_cast<void*>(p));
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !defined(AVIAN_AOT_ONLY)
|
virtual bool success(Status s) {
|
||||||
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)
|
|
||||||
{
|
|
||||||
return s == 0;
|
return s == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -908,7 +893,7 @@ class MySystem : public System {
|
|||||||
return SO_SUFFIX;
|
return SO_SUFFIX;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual const char* toAbsolutePath(avian::util::Allocator* allocator,
|
virtual const char* toAbsolutePath(avian::util::AllocOnly* allocator,
|
||||||
const char* name)
|
const char* name)
|
||||||
{
|
{
|
||||||
#if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
|
#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)
|
// sequence point, for gc (don't recombine statements)
|
||||||
roots(t)->setOutOfMemoryError(t, throwable);
|
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 {
|
class MyCompilationHandler : public Processor::CompilationHandler {
|
||||||
public:
|
public:
|
||||||
|
@ -1630,27 +1630,22 @@ int main(int ac, char** av)
|
|||||||
|
|
||||||
System* system = makeSystem();
|
System* system = makeSystem();
|
||||||
|
|
||||||
class MyAllocator : public avian::util::Allocator {
|
class MyAllocator : public avian::util::Alloc {
|
||||||
public:
|
public:
|
||||||
MyAllocator(System* s) : s(s)
|
MyAllocator(System* s) : s(s)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void* tryAllocate(unsigned size)
|
virtual void* allocate(size_t size)
|
||||||
{
|
{
|
||||||
return s->tryAllocate(size);
|
void* p = s->tryAllocate(size);
|
||||||
}
|
|
||||||
|
|
||||||
virtual void* allocate(unsigned size)
|
|
||||||
{
|
|
||||||
void* p = tryAllocate(size);
|
|
||||||
if (p == 0) {
|
if (p == 0) {
|
||||||
abort(s);
|
abort(s);
|
||||||
}
|
}
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void free(const void* p, unsigned)
|
virtual void free(const void* p, size_t)
|
||||||
{
|
{
|
||||||
s->free(p);
|
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);
|
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);
|
expect(a, offset + paddedSize < memory.count);
|
||||||
|
|
||||||
void* p = memory.begin() + offset;
|
void* p = memory.begin() + offset;
|
||||||
@ -35,12 +35,12 @@ void* FixedAllocator::allocate(unsigned size, unsigned padAlignment)
|
|||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
void* FixedAllocator::allocate(unsigned size)
|
void* FixedAllocator::allocate(size_t size)
|
||||||
{
|
{
|
||||||
return allocate(size, vm::BytesPerWord);
|
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()
|
if (p >= memory.begin()
|
||||||
and static_cast<const uint8_t*>(p) + size == memory.begin() + offset) {
|
and static_cast<const uint8_t*>(p) + size == memory.begin() + offset) {
|
||||||
|
@ -52,7 +52,7 @@ class Asm {
|
|||||||
Assembler* a;
|
Assembler* a;
|
||||||
|
|
||||||
Asm(BasicEnv& env)
|
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