mirror of
https://github.com/corda/corda.git
synced 2025-01-19 11:16:54 +00:00
Merge pull request #180 from joshuawarner32/move-allocator
Move allocator & Slice into util
This commit is contained in:
commit
1cd822b23e
@ -12,11 +12,15 @@
|
|||||||
#define AVIAN_CODEGEN_ARCHITECTURE_H
|
#define AVIAN_CODEGEN_ARCHITECTURE_H
|
||||||
|
|
||||||
namespace vm {
|
namespace vm {
|
||||||
class Allocator;
|
|
||||||
class Zone;
|
class Zone;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace avian {
|
namespace avian {
|
||||||
|
|
||||||
|
namespace util {
|
||||||
|
class Allocator;
|
||||||
|
}
|
||||||
|
|
||||||
namespace codegen {
|
namespace codegen {
|
||||||
|
|
||||||
class Assembler;
|
class Assembler;
|
||||||
@ -125,7 +129,7 @@ virtual void planDestination
|
|||||||
unsigned bSize, const OperandMask& bMask,
|
unsigned bSize, const OperandMask& bMask,
|
||||||
unsigned cSize, OperandMask& cMask) = 0;
|
unsigned cSize, OperandMask& cMask) = 0;
|
||||||
|
|
||||||
virtual Assembler* makeAssembler(vm::Allocator*, vm::Zone*) = 0;
|
virtual Assembler* makeAssembler(util::Allocator*, vm::Zone*) = 0;
|
||||||
|
|
||||||
virtual void acquire() = 0;
|
virtual void acquire() = 0;
|
||||||
virtual void release() = 0;
|
virtual void release() = 0;
|
||||||
|
@ -11,7 +11,9 @@
|
|||||||
#ifndef AVIAN_CODEGEN_PROMISE_H
|
#ifndef AVIAN_CODEGEN_PROMISE_H
|
||||||
#define AVIAN_CODEGEN_PROMISE_H
|
#define AVIAN_CODEGEN_PROMISE_H
|
||||||
|
|
||||||
#include "avian/allocator.h"
|
#include <avian/util/allocator.h>
|
||||||
|
#include <avian/util/abort.h>
|
||||||
|
#include <avian/system/system.h>
|
||||||
|
|
||||||
namespace avian {
|
namespace avian {
|
||||||
namespace codegen {
|
namespace codegen {
|
||||||
@ -102,8 +104,8 @@ class OffsetPromise: public Promise {
|
|||||||
|
|
||||||
class ListenPromise: public Promise {
|
class ListenPromise: public Promise {
|
||||||
public:
|
public:
|
||||||
ListenPromise(vm::System* s, vm::Allocator* allocator):
|
ListenPromise(vm::System* s, util::Allocator* allocator)
|
||||||
s(s), allocator(allocator), listener(0)
|
: s(s), allocator(allocator), listener(0)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
virtual int64_t value() {
|
virtual int64_t value() {
|
||||||
@ -122,16 +124,18 @@ class ListenPromise: public Promise {
|
|||||||
}
|
}
|
||||||
|
|
||||||
vm::System* s;
|
vm::System* s;
|
||||||
vm::Allocator* allocator;
|
util::Allocator* allocator;
|
||||||
Listener* listener;
|
Listener* listener;
|
||||||
Promise* promise;
|
Promise* promise;
|
||||||
};
|
};
|
||||||
|
|
||||||
class DelayedPromise: public ListenPromise {
|
class DelayedPromise: public ListenPromise {
|
||||||
public:
|
public:
|
||||||
DelayedPromise(vm::System* s, vm::Allocator* allocator, Promise* basis,
|
DelayedPromise(vm::System* s,
|
||||||
DelayedPromise* next):
|
util::Allocator* allocator,
|
||||||
ListenPromise(s, allocator), basis(basis), next(next)
|
Promise* basis,
|
||||||
|
DelayedPromise* next)
|
||||||
|
: ListenPromise(s, allocator), basis(basis), next(next)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
virtual int64_t value() {
|
virtual int64_t value() {
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
#define HEAP_H
|
#define HEAP_H
|
||||||
|
|
||||||
#include <avian/system/system.h>
|
#include <avian/system/system.h>
|
||||||
#include "avian/allocator.h"
|
#include <avian/util/allocator.h>
|
||||||
|
|
||||||
namespace vm {
|
namespace vm {
|
||||||
|
|
||||||
@ -22,7 +22,7 @@ const unsigned TenureThreshold = 3;
|
|||||||
|
|
||||||
const unsigned FixieTenureThreshold = TenureThreshold + 2;
|
const unsigned FixieTenureThreshold = TenureThreshold + 2;
|
||||||
|
|
||||||
class Heap: public Allocator {
|
class Heap : public avian::util::Allocator {
|
||||||
public:
|
public:
|
||||||
enum CollectionType {
|
enum CollectionType {
|
||||||
MinorCollection,
|
MinorCollection,
|
||||||
@ -65,9 +65,10 @@ class Heap: public Allocator {
|
|||||||
virtual void collect(CollectionType type, unsigned footprint,
|
virtual void collect(CollectionType type, 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(Allocator* allocator, unsigned sizeInWords,
|
virtual void* allocateFixed(avian::util::Allocator* allocator,
|
||||||
|
unsigned sizeInWords,
|
||||||
bool objectMask) = 0;
|
bool objectMask) = 0;
|
||||||
virtual void* allocateImmortalFixed(Allocator* allocator,
|
virtual void* allocateImmortalFixed(avian::util::Allocator* 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;
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
#define SYSTEM_H
|
#define SYSTEM_H
|
||||||
|
|
||||||
#include "avian/common.h"
|
#include "avian/common.h"
|
||||||
#include "avian/allocator.h"
|
#include <avian/util/allocator.h>
|
||||||
#include <avian/util/abort.h>
|
#include <avian/util/abort.h>
|
||||||
|
|
||||||
namespace vm {
|
namespace vm {
|
||||||
@ -137,7 +137,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(Allocator* allocator,
|
virtual const char* toAbsolutePath(avian::util::Allocator* 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;
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include <avian/util/string.h>
|
#include <avian/util/string.h>
|
||||||
|
#include <avian/util/slice.h>
|
||||||
|
|
||||||
#include "avian/environment.h"
|
#include "avian/environment.h"
|
||||||
|
|
||||||
@ -73,50 +74,31 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
class Slice {
|
class DynamicArray : public util::Slice<T> {
|
||||||
public:
|
|
||||||
T* items;
|
|
||||||
size_t count;
|
|
||||||
|
|
||||||
inline Slice(T* items, size_t count):
|
|
||||||
items(items),
|
|
||||||
count(count) {}
|
|
||||||
|
|
||||||
inline Slice(const Slice<T>& copy):
|
|
||||||
items(copy.items),
|
|
||||||
count(copy.count) {}
|
|
||||||
|
|
||||||
inline T* begin() {
|
|
||||||
return items;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline T* end() {
|
|
||||||
return items + count;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template<class T>
|
|
||||||
class DynamicArray : public Slice<T> {
|
|
||||||
public:
|
public:
|
||||||
size_t capacity;
|
size_t capacity;
|
||||||
|
|
||||||
DynamicArray():
|
DynamicArray() : util::Slice<T>((T*)malloc(10 * sizeof(T)), 0), capacity(10)
|
||||||
Slice<T>((T*)malloc(10 * sizeof(T)), 0),
|
{
|
||||||
capacity(10) {}
|
}
|
||||||
~DynamicArray() {
|
~DynamicArray()
|
||||||
free(Slice<T>::items);
|
{
|
||||||
|
free(util::Slice<T>::items);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ensure(size_t more) {
|
void ensure(size_t more)
|
||||||
if(Slice<T>::count + more > capacity) {
|
{
|
||||||
|
if (util::Slice<T>::count + more > capacity) {
|
||||||
capacity = capacity * 2 + more;
|
capacity = capacity * 2 + more;
|
||||||
Slice<T>::items = (T*)realloc(Slice<T>::items, capacity * sizeof(T));
|
util::Slice<T>::items
|
||||||
|
= (T*)realloc(util::Slice<T>::items, capacity * sizeof(T));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void add(const T& item) {
|
void add(const T& item)
|
||||||
|
{
|
||||||
ensure(1);
|
ensure(1);
|
||||||
Slice<T>::items[Slice<T>::count++] = item;
|
util::Slice<T>::items[util::Slice<T>::count++] = item;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -175,7 +157,11 @@ public:
|
|||||||
Executable = 1 << 1
|
Executable = 1 << 1
|
||||||
};
|
};
|
||||||
|
|
||||||
virtual bool writeObject(OutputStream* out, Slice<SymbolInfo> symbols, Slice<const uint8_t> data, unsigned accessFlags, unsigned alignment) = 0;
|
virtual bool writeObject(OutputStream* out,
|
||||||
|
util::Slice<SymbolInfo> symbols,
|
||||||
|
util::Slice<const uint8_t> data,
|
||||||
|
unsigned accessFlags,
|
||||||
|
unsigned alignment) = 0;
|
||||||
|
|
||||||
static Platform* getPlatform(PlatformInfo info);
|
static Platform* getPlatform(PlatformInfo info);
|
||||||
};
|
};
|
||||||
|
@ -11,6 +11,10 @@
|
|||||||
#ifndef AVIAN_UTIL_ABORT_H
|
#ifndef AVIAN_UTIL_ABORT_H
|
||||||
#define AVIAN_UTIL_ABORT_H
|
#define AVIAN_UTIL_ABORT_H
|
||||||
|
|
||||||
|
// TODO: remove reference back into the source directory!
|
||||||
|
// Note: this is needed for UNLIKELY
|
||||||
|
#include <avian/common.h>
|
||||||
|
|
||||||
namespace avian {
|
namespace avian {
|
||||||
namespace util {
|
namespace util {
|
||||||
|
|
||||||
@ -19,6 +23,11 @@ public:
|
|||||||
virtual void NO_RETURN abort() = 0;
|
virtual void NO_RETURN abort() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
inline Aborter* getAborter(Aborter* a)
|
||||||
|
{
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
inline void NO_RETURN abort(T t) {
|
inline void NO_RETURN abort(T t) {
|
||||||
getAborter(t)->abort();
|
getAborter(t)->abort();
|
||||||
|
35
include/avian/util/allocator.h
Normal file
35
include/avian/util/allocator.h
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
/* Copyright (c) 2008-2013, Avian Contributors
|
||||||
|
|
||||||
|
Permission to use, copy, modify, and/or distribute this software
|
||||||
|
for any purpose with or without fee is hereby granted, provided
|
||||||
|
that the above copyright notice and this permission notice appear
|
||||||
|
in all copies.
|
||||||
|
|
||||||
|
There is NO WARRANTY for this software. See license.txt for
|
||||||
|
details. */
|
||||||
|
|
||||||
|
#ifndef AVIAN_UTIL_ALLOCATOR_H
|
||||||
|
#define AVIAN_UTIL_ALLOCATOR_H
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
namespace avian {
|
||||||
|
namespace util {
|
||||||
|
|
||||||
|
class Allocator {
|
||||||
|
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;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace util
|
||||||
|
} // namespace avian
|
||||||
|
|
||||||
|
inline void* operator new(size_t size, avian::util::Allocator* allocator)
|
||||||
|
{
|
||||||
|
return allocator->allocate(size);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // AVIAN_UTIL_ALLOCATOR_H
|
43
include/avian/util/fixed-allocator.h
Normal file
43
include/avian/util/fixed-allocator.h
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
/* Copyright (c) 2008-2013, Avian Contributors
|
||||||
|
|
||||||
|
Permission to use, copy, modify, and/or distribute this software
|
||||||
|
for any purpose with or without fee is hereby granted, provided
|
||||||
|
that the above copyright notice and this permission notice appear
|
||||||
|
in all copies.
|
||||||
|
|
||||||
|
There is NO WARRANTY for this software. See license.txt for
|
||||||
|
details. */
|
||||||
|
|
||||||
|
#ifndef AVIAN_UTIL_FIXED_ALLOCATOR_H
|
||||||
|
#define AVIAN_UTIL_FIXED_ALLOCATOR_H
|
||||||
|
|
||||||
|
#include "allocator.h"
|
||||||
|
#include "abort.h"
|
||||||
|
#include "slice.h"
|
||||||
|
|
||||||
|
namespace avian {
|
||||||
|
namespace util {
|
||||||
|
|
||||||
|
// An Allocator that allocates, bump-pointer style, out of a pre-defined chunk
|
||||||
|
// of memory.
|
||||||
|
class FixedAllocator : public Allocator {
|
||||||
|
public:
|
||||||
|
FixedAllocator(Aborter* a, Slice<uint8_t> memory);
|
||||||
|
|
||||||
|
virtual void* tryAllocate(unsigned size);
|
||||||
|
|
||||||
|
void* allocate(unsigned size, unsigned padAlignment);
|
||||||
|
|
||||||
|
virtual void* allocate(unsigned size);
|
||||||
|
|
||||||
|
virtual void free(const void* p, unsigned size);
|
||||||
|
|
||||||
|
Aborter* a;
|
||||||
|
Slice<uint8_t> memory;
|
||||||
|
size_t offset;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace util
|
||||||
|
} // namespace avian
|
||||||
|
|
||||||
|
#endif // AVIAN_UTIL_FIXED_ALLOCATOR_H
|
@ -11,6 +11,11 @@
|
|||||||
#ifndef AVIAN_UTIL_LIST_H
|
#ifndef AVIAN_UTIL_LIST_H
|
||||||
#define AVIAN_UTIL_LIST_H
|
#define AVIAN_UTIL_LIST_H
|
||||||
|
|
||||||
|
#include "allocator.h"
|
||||||
|
|
||||||
|
namespace avian {
|
||||||
|
namespace util {
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
class List {
|
class List {
|
||||||
public:
|
public:
|
||||||
@ -32,4 +37,7 @@ public:
|
|||||||
List<T>* next;
|
List<T>* next;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace util
|
||||||
|
} // namespace avian
|
||||||
|
|
||||||
#endif // AVIAN_UTIL_LIST_H
|
#endif // AVIAN_UTIL_LIST_H
|
||||||
|
74
include/avian/util/slice.h
Normal file
74
include/avian/util/slice.h
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
/* Copyright (c) 2008-2013, Avian Contributors
|
||||||
|
|
||||||
|
Permission to use, copy, modify, and/or distribute this software
|
||||||
|
for any purpose with or without fee is hereby granted, provided
|
||||||
|
that the above copyright notice and this permission notice appear
|
||||||
|
in all copies.
|
||||||
|
|
||||||
|
There is NO WARRANTY for this software. See license.txt for
|
||||||
|
details. */
|
||||||
|
|
||||||
|
#ifndef AVIAN_UTIL_SLICE_H
|
||||||
|
#define AVIAN_UTIL_SLICE_H
|
||||||
|
|
||||||
|
#include "allocator.h"
|
||||||
|
#include "math.h"
|
||||||
|
|
||||||
|
namespace avian {
|
||||||
|
namespace util {
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
class Slice {
|
||||||
|
public:
|
||||||
|
T* items;
|
||||||
|
size_t count;
|
||||||
|
|
||||||
|
inline Slice(T* items, size_t count) : items(items), count(count)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
inline Slice(const Slice<T>& copy) : items(copy.items), count(copy.count)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
inline T& operator[](size_t index)
|
||||||
|
{
|
||||||
|
return items[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
inline T* begin()
|
||||||
|
{
|
||||||
|
return items;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline T* end()
|
||||||
|
{
|
||||||
|
return items + count;
|
||||||
|
}
|
||||||
|
|
||||||
|
static Slice<T> alloc(Allocator* a, size_t count)
|
||||||
|
{
|
||||||
|
return Slice<T>((T*)a->allocate(sizeof(T) * count), count);
|
||||||
|
}
|
||||||
|
|
||||||
|
Slice<T> clone(Allocator* a)
|
||||||
|
{
|
||||||
|
Slice<T> ret((T*)a->allocate(count * sizeof(T)), count);
|
||||||
|
memcpy(ret.items, items, count * sizeof(T));
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
void resize(Allocator* a, size_t newCount)
|
||||||
|
{
|
||||||
|
T* newItems = (T*)a->allocate(newCount * sizeof(T));
|
||||||
|
memcpy(newItems, items, min(count, newCount));
|
||||||
|
a->free(items, count);
|
||||||
|
items = newItems;
|
||||||
|
count = newCount;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace util
|
||||||
|
} // namespace avian
|
||||||
|
|
||||||
|
#endif // AVIAN_UTIL_SLICE_H
|
3
makefile
3
makefile
@ -1144,7 +1144,8 @@ compiler-sources = \
|
|||||||
$(wildcard $(src)/codegen/compiler/*.cpp) \
|
$(wildcard $(src)/codegen/compiler/*.cpp) \
|
||||||
$(src)/codegen/registers.cpp \
|
$(src)/codegen/registers.cpp \
|
||||||
$(src)/codegen/runtime.cpp \
|
$(src)/codegen/runtime.cpp \
|
||||||
$(src)/codegen/targets.cpp
|
$(src)/codegen/targets.cpp \
|
||||||
|
$(src)/util/fixed-allocator.cpp
|
||||||
|
|
||||||
x86-assembler-sources = $(wildcard $(src)/codegen/target/x86/*.cpp)
|
x86-assembler-sources = $(wildcard $(src)/codegen/target/x86/*.cpp)
|
||||||
|
|
||||||
|
@ -11,10 +11,12 @@
|
|||||||
#ifndef VECTOR_H
|
#ifndef VECTOR_H
|
||||||
#define VECTOR_H
|
#define VECTOR_H
|
||||||
|
|
||||||
#include <avian/system/system.h>
|
#include <avian/target.h>
|
||||||
#include "avian/target.h"
|
|
||||||
|
|
||||||
#include <avian/util/math.h>
|
#include <avian/util/math.h>
|
||||||
|
#include <avian/util/abort.h>
|
||||||
|
#include <avian/util/slice.h>
|
||||||
|
#include <avian/util/allocator.h>
|
||||||
|
|
||||||
#undef max
|
#undef max
|
||||||
#undef min
|
#undef min
|
||||||
@ -23,12 +25,13 @@ namespace vm {
|
|||||||
|
|
||||||
class Vector {
|
class Vector {
|
||||||
public:
|
public:
|
||||||
Vector(System* s, Allocator* allocator, unsigned minimumCapacity):
|
Vector(avian::util::Aborter* a,
|
||||||
s(s),
|
avian::util::Allocator* allocator,
|
||||||
|
size_t minimumCapacity)
|
||||||
|
: a(a),
|
||||||
allocator(allocator),
|
allocator(allocator),
|
||||||
data(0),
|
data(0, 0),
|
||||||
position(0),
|
position(0),
|
||||||
capacity(0),
|
|
||||||
minimumCapacity(minimumCapacity)
|
minimumCapacity(minimumCapacity)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
@ -37,61 +40,56 @@ class Vector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void dispose() {
|
void dispose() {
|
||||||
if (data and minimumCapacity >= 0) {
|
if (data.items and minimumCapacity > 0) {
|
||||||
allocator->free(data, capacity);
|
allocator->free(data.items, data.count);
|
||||||
data = 0;
|
data.items = 0;
|
||||||
|
data.count = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void wrap(uint8_t* data, unsigned capacity) {
|
void ensure(size_t space)
|
||||||
dispose();
|
{
|
||||||
|
if (position + space > data.count) {
|
||||||
|
assert(a, minimumCapacity > 0);
|
||||||
|
|
||||||
this->data = data;
|
size_t newCapacity = avian::util::max(
|
||||||
this->position = 0;
|
position + space, avian::util::max(minimumCapacity, data.count * 2));
|
||||||
this->capacity = capacity;
|
if (data.begin()) {
|
||||||
this->minimumCapacity = -1;
|
data.resize(allocator, newCapacity);
|
||||||
|
} else {
|
||||||
|
data = avian::util::Slice<uint8_t>::alloc(allocator, newCapacity);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ensure(unsigned space) {
|
|
||||||
if (position + space > capacity) {
|
|
||||||
assert(s, minimumCapacity >= 0);
|
|
||||||
|
|
||||||
unsigned newCapacity = avian::util::max
|
|
||||||
(position + space, avian::util::max(minimumCapacity, capacity * 2));
|
|
||||||
uint8_t* newData = static_cast<uint8_t*>
|
|
||||||
(allocator->allocate(newCapacity));
|
|
||||||
if (data) {
|
|
||||||
memcpy(newData, data, position);
|
|
||||||
allocator->free(data, capacity);
|
|
||||||
}
|
|
||||||
data = newData;
|
|
||||||
capacity = newCapacity;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void get(unsigned offset, void* dst, unsigned size) {
|
void get(size_t offset, void* dst, size_t size)
|
||||||
assert(s, offset + size <= position);
|
{
|
||||||
memcpy(dst, data + offset, size);
|
assert(a, offset + size <= position);
|
||||||
|
memcpy(dst, data.begin() + offset, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
void set(unsigned offset, const void* src, unsigned size) {
|
void set(size_t offset, const void* src, size_t size)
|
||||||
assert(s, offset + size <= position);
|
{
|
||||||
memcpy(data + offset, src, size);
|
assert(a, offset + size <= position);
|
||||||
|
memcpy(data.begin() + offset, src, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
void pop(void* dst, unsigned size) {
|
void pop(void* dst, size_t size)
|
||||||
|
{
|
||||||
get(position - size, dst, size);
|
get(position - size, dst, size);
|
||||||
position -= size;
|
position -= size;
|
||||||
}
|
}
|
||||||
|
|
||||||
void* allocate(unsigned size) {
|
void* allocate(size_t size)
|
||||||
|
{
|
||||||
ensure(size);
|
ensure(size);
|
||||||
void* r = data + position;
|
void* r = data.begin() + position;
|
||||||
position += size;
|
position += size;
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
void* append(const void* p, unsigned size) {
|
void* append(const void* p, size_t size)
|
||||||
|
{
|
||||||
void* r = allocate(size);
|
void* r = allocate(size);
|
||||||
memcpy(r, p, size);
|
memcpy(r, p, size);
|
||||||
return r;
|
return r;
|
||||||
@ -121,47 +119,53 @@ class Vector {
|
|||||||
append(&v, BytesPerWord);
|
append(&v, BytesPerWord);
|
||||||
}
|
}
|
||||||
|
|
||||||
void set2(unsigned offset, uint16_t v) {
|
void set2(size_t offset, uint16_t v)
|
||||||
assert(s, offset <= position - 2);
|
{
|
||||||
memcpy(data + offset, &v, 2);
|
assert(a, offset <= position - 2);
|
||||||
|
memcpy(data.begin() + offset, &v, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned get(unsigned offset) {
|
size_t get(size_t offset)
|
||||||
|
{
|
||||||
uint8_t v; get(offset, &v, 1);
|
uint8_t v; get(offset, &v, 1);
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned get2(unsigned offset) {
|
size_t get2(size_t offset)
|
||||||
|
{
|
||||||
uint16_t v; get(offset, &v, 2);
|
uint16_t v; get(offset, &v, 2);
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned get4(unsigned offset) {
|
size_t get4(size_t offset)
|
||||||
|
{
|
||||||
uint32_t v; get(offset, &v, 4);
|
uint32_t v; get(offset, &v, 4);
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
uintptr_t getAddress(unsigned offset) {
|
uintptr_t getAddress(size_t offset)
|
||||||
|
{
|
||||||
uintptr_t v; get(offset, &v, BytesPerWord);
|
uintptr_t v; get(offset, &v, BytesPerWord);
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned length() {
|
size_t length()
|
||||||
|
{
|
||||||
return position;
|
return position;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
T* peek(unsigned offset) {
|
T* peek(size_t offset)
|
||||||
assert(s, offset + sizeof(T) <= position);
|
{
|
||||||
return reinterpret_cast<T*>(data + offset);
|
assert(a, offset + sizeof(T) <= position);
|
||||||
|
return reinterpret_cast<T*>(data.begin() + offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
System* s;
|
avian::util::Aborter* a;
|
||||||
Allocator* allocator;
|
avian::util::Allocator* allocator;
|
||||||
uint8_t* data;
|
avian::util::Slice<uint8_t> data;
|
||||||
unsigned position;
|
size_t position;
|
||||||
unsigned capacity;
|
size_t minimumCapacity;
|
||||||
int minimumCapacity;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace vm
|
} // namespace vm
|
||||||
|
@ -8,22 +8,18 @@
|
|||||||
There is NO WARRANTY for this software. See license.txt for
|
There is NO WARRANTY for this software. See license.txt for
|
||||||
details. */
|
details. */
|
||||||
|
|
||||||
#ifndef ALLOCATOR_H
|
#ifndef APPEND_H
|
||||||
#define ALLOCATOR_H
|
#define APPEND_H
|
||||||
|
|
||||||
#include "avian/common.h"
|
#include <avian/common.h>
|
||||||
|
#include <avian/util/allocator.h>
|
||||||
|
|
||||||
namespace vm {
|
namespace vm {
|
||||||
|
|
||||||
class Allocator {
|
inline const char* append(avian::util::Allocator* allocator,
|
||||||
public:
|
const char* a,
|
||||||
virtual void* tryAllocate(unsigned size) = 0;
|
const char* b,
|
||||||
virtual void* allocate(unsigned size) = 0;
|
const char* c)
|
||||||
virtual void free(const void* p, unsigned size) = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
inline const char*
|
|
||||||
append(Allocator* allocator, const char* a, const char* b, const char* c)
|
|
||||||
{
|
{
|
||||||
unsigned al = strlen(a);
|
unsigned al = strlen(a);
|
||||||
unsigned bl = strlen(b);
|
unsigned bl = strlen(b);
|
||||||
@ -35,8 +31,9 @@ append(Allocator* allocator, const char* a, const char* b, const char* c)
|
|||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const char*
|
inline const char* append(avian::util::Allocator* allocator,
|
||||||
append(Allocator* allocator, const char* a, const char* b)
|
const char* a,
|
||||||
|
const char* b)
|
||||||
{
|
{
|
||||||
unsigned al = strlen(a);
|
unsigned al = strlen(a);
|
||||||
unsigned bl = strlen(b);
|
unsigned bl = strlen(b);
|
||||||
@ -46,8 +43,7 @@ append(Allocator* allocator, const char* a, const char* b)
|
|||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const char*
|
inline const char* copy(avian::util::Allocator* allocator, const char* a)
|
||||||
copy(Allocator* 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));
|
||||||
@ -57,8 +53,4 @@ copy(Allocator* allocator, const char* a)
|
|||||||
|
|
||||||
} // namespace vm
|
} // namespace vm
|
||||||
|
|
||||||
inline void* operator new (size_t size, vm::Allocator* allocator) {
|
#endif // APPEND_H
|
||||||
return allocator->allocate(size);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif//ALLOCATOR_H
|
|
@ -13,7 +13,12 @@
|
|||||||
|
|
||||||
#include "avian/common.h"
|
#include "avian/common.h"
|
||||||
#include <avian/system/system.h>
|
#include <avian/system/system.h>
|
||||||
#include "avian/allocator.h"
|
|
||||||
|
namespace avian {
|
||||||
|
namespace util {
|
||||||
|
class Allocator;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
namespace vm {
|
namespace vm {
|
||||||
|
|
||||||
@ -174,11 +179,14 @@ class Finder {
|
|||||||
virtual void dispose() = 0;
|
virtual void dispose() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
AVIAN_EXPORT Finder*
|
AVIAN_EXPORT Finder* makeFinder(System* s,
|
||||||
makeFinder(System* s, Allocator* a, const char* path, const char* bootLibrary);
|
avian::util::Allocator* a,
|
||||||
|
const char* path,
|
||||||
|
const char* bootLibrary);
|
||||||
|
|
||||||
Finder*
|
Finder* makeFinder(System* s,
|
||||||
makeFinder(System* s, Allocator* a, const uint8_t* jarData,
|
avian::util::Allocator* a,
|
||||||
|
const uint8_t* jarData,
|
||||||
unsigned jarLength);
|
unsigned jarLength);
|
||||||
|
|
||||||
} // namespace vm
|
} // namespace vm
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
#include "avian/lzma.h"
|
#include "avian/lzma.h"
|
||||||
#include "C/Types.h"
|
#include "C/Types.h"
|
||||||
#include <avian/system/system.h>
|
#include <avian/system/system.h>
|
||||||
#include "avian/allocator.h"
|
#include "avian/util/allocator.h"
|
||||||
|
|
||||||
namespace vm {
|
namespace vm {
|
||||||
|
|
||||||
|
@ -12,16 +12,25 @@
|
|||||||
#define LZMA_H
|
#define LZMA_H
|
||||||
|
|
||||||
#include <avian/system/system.h>
|
#include <avian/system/system.h>
|
||||||
#include "avian/allocator.h"
|
|
||||||
|
namespace avian {
|
||||||
|
namespace util {
|
||||||
|
class Allocator;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
namespace vm {
|
namespace vm {
|
||||||
|
|
||||||
uint8_t*
|
uint8_t* decodeLZMA(System* s,
|
||||||
decodeLZMA(System* s, Allocator* a, uint8_t* in, unsigned inSize,
|
avian::util::Allocator* a,
|
||||||
|
uint8_t* in,
|
||||||
|
unsigned inSize,
|
||||||
unsigned* outSize);
|
unsigned* outSize);
|
||||||
|
|
||||||
uint8_t*
|
uint8_t* encodeLZMA(System* s,
|
||||||
encodeLZMA(System* s, Allocator* a, uint8_t* in, unsigned inSize,
|
avian::util::Allocator* a,
|
||||||
|
uint8_t* in,
|
||||||
|
unsigned inSize,
|
||||||
unsigned* outSize);
|
unsigned* outSize);
|
||||||
|
|
||||||
} // namespace vm
|
} // namespace vm
|
||||||
|
@ -1793,43 +1793,6 @@ inline Aborter* getAborter(Thread* t) {
|
|||||||
return t->m->system;
|
return t->m->system;
|
||||||
}
|
}
|
||||||
|
|
||||||
class FixedAllocator: public Allocator {
|
|
||||||
public:
|
|
||||||
FixedAllocator(System* s, uint8_t* base, unsigned capacity):
|
|
||||||
s(s), base(base), offset(0), capacity(capacity)
|
|
||||||
{ }
|
|
||||||
|
|
||||||
virtual void* tryAllocate(unsigned size) {
|
|
||||||
return allocate(size);
|
|
||||||
}
|
|
||||||
|
|
||||||
void* allocate(unsigned size, unsigned padAlignment) {
|
|
||||||
unsigned paddedSize = pad(size, padAlignment);
|
|
||||||
expect(s, offset + paddedSize < capacity);
|
|
||||||
|
|
||||||
void* p = base + offset;
|
|
||||||
offset += paddedSize;
|
|
||||||
return p;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void* allocate(unsigned size) {
|
|
||||||
return allocate(size, BytesPerWord);
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void free(const void* p, unsigned size) {
|
|
||||||
if (p >= base and static_cast<const uint8_t*>(p) + size == base + offset) {
|
|
||||||
offset -= size;
|
|
||||||
} else {
|
|
||||||
abort(s);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
System* s;
|
|
||||||
uint8_t* base;
|
|
||||||
unsigned offset;
|
|
||||||
unsigned capacity;
|
|
||||||
};
|
|
||||||
|
|
||||||
inline bool
|
inline bool
|
||||||
ensure(Thread* t, unsigned sizeInBytes)
|
ensure(Thread* t, unsigned sizeInBytes)
|
||||||
{
|
{
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
#include "avian/common.h"
|
#include "avian/common.h"
|
||||||
#include <avian/system/system.h>
|
#include <avian/system/system.h>
|
||||||
#include <avian/heap/heap.h>
|
#include <avian/heap/heap.h>
|
||||||
|
#include <avian/util/allocator.h>
|
||||||
#include "bootimage.h"
|
#include "bootimage.h"
|
||||||
#include "avian/heapwalk.h"
|
#include "avian/heapwalk.h"
|
||||||
#include "avian/zone.h"
|
#include "avian/zone.h"
|
||||||
@ -22,6 +23,11 @@ namespace avian {
|
|||||||
namespace codegen {
|
namespace codegen {
|
||||||
class DelayedPromise;
|
class DelayedPromise;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace util {
|
||||||
|
template <class T>
|
||||||
|
class Slice;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace vm {
|
namespace vm {
|
||||||
@ -139,8 +145,8 @@ class Processor {
|
|||||||
virtual object
|
virtual object
|
||||||
getStackTrace(Thread* t, Thread* target) = 0;
|
getStackTrace(Thread* t, Thread* target) = 0;
|
||||||
|
|
||||||
virtual void
|
virtual void initialize(BootImage* image, avian::util::Slice<uint8_t> code)
|
||||||
initialize(BootImage* image, uint8_t* code, unsigned capacity) = 0;
|
= 0;
|
||||||
|
|
||||||
virtual void
|
virtual void
|
||||||
addCompilationHandler(CompilationHandler* handler) = 0;
|
addCompilationHandler(CompilationHandler* handler) = 0;
|
||||||
@ -209,7 +215,7 @@ class Processor {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Processor* makeProcessor(System* system,
|
Processor* makeProcessor(System* system,
|
||||||
Allocator* allocator,
|
avian::util::Allocator* allocator,
|
||||||
const char* crashDumpDirectory,
|
const char* crashDumpDirectory,
|
||||||
bool useNativeFeatures);
|
bool useNativeFeatures);
|
||||||
|
|
||||||
|
@ -12,13 +12,12 @@
|
|||||||
#define ZONE_H
|
#define ZONE_H
|
||||||
|
|
||||||
#include <avian/system/system.h>
|
#include <avian/system/system.h>
|
||||||
#include "avian/allocator.h"
|
#include <avian/util/allocator.h>
|
||||||
|
|
||||||
#include <avian/util/math.h>
|
#include <avian/util/math.h>
|
||||||
|
|
||||||
namespace vm {
|
namespace vm {
|
||||||
|
|
||||||
class Zone: public Allocator {
|
class Zone : public avian::util::Allocator {
|
||||||
public:
|
public:
|
||||||
class Segment {
|
class Segment {
|
||||||
public:
|
public:
|
||||||
|
@ -814,7 +814,9 @@ class MyAssembler: public Assembler {
|
|||||||
unsigned blockOffset = 0;
|
unsigned blockOffset = 0;
|
||||||
for (PoolEvent* e = b->poolEventHead; e; e = e->next) {
|
for (PoolEvent* e = b->poolEventHead; e; e = e->next) {
|
||||||
unsigned size = e->offset - blockOffset;
|
unsigned size = e->offset - blockOffset;
|
||||||
memcpy(dst + dstOffset, con.code.data + b->offset + blockOffset, size);
|
memcpy(dst + dstOffset,
|
||||||
|
con.code.data.begin() + b->offset + blockOffset,
|
||||||
|
size);
|
||||||
blockOffset = e->offset;
|
blockOffset = e->offset;
|
||||||
dstOffset += size;
|
dstOffset += size;
|
||||||
|
|
||||||
@ -857,7 +859,7 @@ class MyAssembler: public Assembler {
|
|||||||
unsigned size = b->size - blockOffset;
|
unsigned size = b->size - blockOffset;
|
||||||
|
|
||||||
memcpy(dst + dstOffset,
|
memcpy(dst + dstOffset,
|
||||||
con.code.data + b->offset + blockOffset,
|
con.code.data.begin() + b->offset + blockOffset,
|
||||||
size);
|
size);
|
||||||
|
|
||||||
dstOffset += size;
|
dstOffset += size;
|
||||||
|
@ -15,12 +15,21 @@ namespace avian {
|
|||||||
namespace codegen {
|
namespace codegen {
|
||||||
namespace arm {
|
namespace arm {
|
||||||
|
|
||||||
Context::Context(vm::System* s, vm::Allocator* a, vm::Zone* zone):
|
Context::Context(vm::System* s, util::Allocator* a, vm::Zone* zone)
|
||||||
s(s), zone(zone), client(0), code(s, a, 1024), tasks(0), result(0),
|
: s(s),
|
||||||
|
zone(zone),
|
||||||
|
client(0),
|
||||||
|
code(s, a, 1024),
|
||||||
|
tasks(0),
|
||||||
|
result(0),
|
||||||
firstBlock(new (zone) MyBlock(this, 0)),
|
firstBlock(new (zone) MyBlock(this, 0)),
|
||||||
lastBlock(firstBlock), poolOffsetHead(0), poolOffsetTail(0),
|
lastBlock(firstBlock),
|
||||||
constantPool(0), constantPoolCount(0)
|
poolOffsetHead(0),
|
||||||
{ }
|
poolOffsetTail(0),
|
||||||
|
constantPool(0),
|
||||||
|
constantPoolCount(0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace arm
|
} // namespace arm
|
||||||
} // namespace codegen
|
} // namespace codegen
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
|
|
||||||
namespace vm {
|
namespace vm {
|
||||||
class System;
|
class System;
|
||||||
class Allocator;
|
|
||||||
class Zone;
|
class Zone;
|
||||||
} // namespace vm
|
} // namespace vm
|
||||||
|
|
||||||
@ -25,6 +24,7 @@ namespace avian {
|
|||||||
|
|
||||||
namespace util {
|
namespace util {
|
||||||
class Aborter;
|
class Aborter;
|
||||||
|
class Allocator;
|
||||||
} // namespace util
|
} // namespace util
|
||||||
|
|
||||||
namespace codegen {
|
namespace codegen {
|
||||||
@ -37,7 +37,7 @@ class ConstantPoolEntry;
|
|||||||
|
|
||||||
class Context {
|
class Context {
|
||||||
public:
|
public:
|
||||||
Context(vm::System* s, vm::Allocator* a, vm::Zone* zone);
|
Context(vm::System* s, util::Allocator* a, vm::Zone* zone);
|
||||||
|
|
||||||
vm::System* s;
|
vm::System* s;
|
||||||
vm::Zone* zone;
|
vm::Zone* zone;
|
||||||
|
@ -1065,9 +1065,10 @@ void branchLong(Context* con, lir::TernaryOperation op, lir::Operand* al,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (next) {
|
if (next) {
|
||||||
updateOffset
|
updateOffset(con->s,
|
||||||
(con->s, con->code.data + next, reinterpret_cast<intptr_t>
|
con->code.data.begin() + next,
|
||||||
(con->code.data + con->code.length()));
|
reinterpret_cast<intptr_t>(con->code.data.begin()
|
||||||
|
+ con->code.length()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -586,7 +586,7 @@ class MyArchitecture: public Architecture {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual Assembler* makeAssembler(Allocator* allocator, Zone* zone);
|
virtual Assembler* makeAssembler(util::Allocator* allocator, Zone* zone);
|
||||||
|
|
||||||
virtual void acquire() {
|
virtual void acquire() {
|
||||||
++ referenceCount;
|
++ referenceCount;
|
||||||
@ -604,8 +604,8 @@ 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, util::Allocator* a, Zone* zone, MyArchitecture* arch)
|
||||||
c(s, a, zone), arch_(arch)
|
: c(s, a, zone), arch_(arch)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
virtual void setClient(Client* client) {
|
virtual void setClient(Client* client) {
|
||||||
@ -869,7 +869,9 @@ class MyAssembler: public Assembler {
|
|||||||
unsigned blockOffset = 0;
|
unsigned blockOffset = 0;
|
||||||
for (JumpEvent* e = b->jumpEventHead; e; e = e->next) {
|
for (JumpEvent* e = b->jumpEventHead; e; e = e->next) {
|
||||||
unsigned size = e->offset - blockOffset;
|
unsigned size = e->offset - blockOffset;
|
||||||
memcpy(dst + dstOffset, c.code.data + b->offset + blockOffset, size);
|
memcpy(dst + dstOffset,
|
||||||
|
c.code.data.begin() + b->offset + blockOffset,
|
||||||
|
size);
|
||||||
blockOffset = e->offset;
|
blockOffset = e->offset;
|
||||||
dstOffset += size;
|
dstOffset += size;
|
||||||
|
|
||||||
@ -903,9 +905,8 @@ class MyAssembler: public Assembler {
|
|||||||
|
|
||||||
unsigned size = b->size - blockOffset;
|
unsigned size = b->size - blockOffset;
|
||||||
|
|
||||||
memcpy(dst + dstOffset,
|
memcpy(
|
||||||
c.code.data + b->offset + blockOffset,
|
dst + dstOffset, c.code.data.begin() + b->offset + blockOffset, size);
|
||||||
size);
|
|
||||||
|
|
||||||
dstOffset += size;
|
dstOffset += size;
|
||||||
}
|
}
|
||||||
@ -992,7 +993,8 @@ class MyAssembler: public Assembler {
|
|||||||
MyArchitecture* arch_;
|
MyArchitecture* arch_;
|
||||||
};
|
};
|
||||||
|
|
||||||
Assembler* MyArchitecture::makeAssembler(Allocator* allocator, Zone* zone) {
|
Assembler* MyArchitecture::makeAssembler(util::Allocator* allocator, Zone* zone)
|
||||||
|
{
|
||||||
return new(zone) MyAssembler(this->c.s, allocator, zone, this);
|
return new(zone) MyAssembler(this->c.s, allocator, zone, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,13 +16,21 @@ namespace avian {
|
|||||||
namespace codegen {
|
namespace codegen {
|
||||||
namespace powerpc {
|
namespace powerpc {
|
||||||
|
|
||||||
|
Context::Context(vm::System* s, util::Allocator* a, vm::Zone* zone)
|
||||||
Context::Context(vm::System* s, vm::Allocator* a, vm::Zone* zone):
|
: s(s),
|
||||||
s(s), zone(zone), client(0), code(s, a, 1024), tasks(0), result(0),
|
zone(zone),
|
||||||
|
client(0),
|
||||||
|
code(s, a, 1024),
|
||||||
|
tasks(0),
|
||||||
|
result(0),
|
||||||
firstBlock(new (zone) MyBlock(this, 0)),
|
firstBlock(new (zone) MyBlock(this, 0)),
|
||||||
lastBlock(firstBlock), jumpOffsetHead(0), jumpOffsetTail(0),
|
lastBlock(firstBlock),
|
||||||
constantPool(0), constantPoolCount(0)
|
jumpOffsetHead(0),
|
||||||
{ }
|
jumpOffsetTail(0),
|
||||||
|
constantPool(0),
|
||||||
|
constantPoolCount(0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace powerpc
|
} // namespace powerpc
|
||||||
} // namespace codegen
|
} // namespace codegen
|
||||||
|
@ -20,12 +20,16 @@
|
|||||||
|
|
||||||
namespace vm {
|
namespace vm {
|
||||||
class System;
|
class System;
|
||||||
class Allocator;
|
|
||||||
class Zone;
|
class Zone;
|
||||||
} // namespace vm
|
} // namespace vm
|
||||||
|
|
||||||
|
|
||||||
namespace avian {
|
namespace avian {
|
||||||
|
|
||||||
|
namespace util {
|
||||||
|
class Allocator;
|
||||||
|
}
|
||||||
|
|
||||||
namespace codegen {
|
namespace codegen {
|
||||||
namespace powerpc {
|
namespace powerpc {
|
||||||
|
|
||||||
@ -36,7 +40,7 @@ class MyBlock;
|
|||||||
|
|
||||||
class Context {
|
class Context {
|
||||||
public:
|
public:
|
||||||
Context(vm::System* s, vm::Allocator* a, vm::Zone* zone);
|
Context(vm::System* s, util::Allocator* a, vm::Zone* zone);
|
||||||
|
|
||||||
vm::System* s;
|
vm::System* s;
|
||||||
vm::Zone* zone;
|
vm::Zone* zone;
|
||||||
|
@ -924,9 +924,12 @@ void branchLong(Context* c, lir::TernaryOperation op, lir::Operand* al,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (next) {
|
if (next) {
|
||||||
updateOffset
|
updateOffset(
|
||||||
(c->s, c->code.data + next, true, reinterpret_cast<intptr_t>
|
c->s,
|
||||||
(c->code.data + c->code.length()), 0);
|
c->code.data.begin() + next,
|
||||||
|
true,
|
||||||
|
reinterpret_cast<intptr_t>(c->code.data.begin() + c->code.length()),
|
||||||
|
0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
#include "avian/target.h"
|
#include "avian/target.h"
|
||||||
#include "avian/alloc-vector.h"
|
#include "avian/alloc-vector.h"
|
||||||
#include "avian/common.h"
|
#include "avian/common.h"
|
||||||
#include "avian/allocator.h"
|
#include "avian/util/allocator.h"
|
||||||
#include "avian/zone.h"
|
#include "avian/zone.h"
|
||||||
|
|
||||||
#include <avian/util/runtime-array.h>
|
#include <avian/util/runtime-array.h>
|
||||||
@ -790,7 +790,7 @@ class MyArchitecture: public Architecture {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual Assembler* makeAssembler(Allocator* allocator, Zone* zone);
|
virtual Assembler* makeAssembler(util::Allocator* allocator, Zone* zone);
|
||||||
|
|
||||||
virtual void acquire() {
|
virtual void acquire() {
|
||||||
++ referenceCount;
|
++ referenceCount;
|
||||||
@ -809,8 +809,8 @@ 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, util::Allocator* a, Zone* zone, MyArchitecture* arch)
|
||||||
c(s, a, zone, &(arch->c)), arch_(arch)
|
: c(s, a, zone, &(arch->c)), arch_(arch)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
virtual void setClient(Client* client) {
|
virtual void setClient(Client* client) {
|
||||||
@ -1084,7 +1084,7 @@ class MyAssembler: public Assembler {
|
|||||||
unsigned size = p->offset - b->offset - index;
|
unsigned size = p->offset - b->offset - index;
|
||||||
|
|
||||||
memcpy(dst + b->start + index + padding,
|
memcpy(dst + b->start + index + padding,
|
||||||
c.code.data + b->offset + index,
|
c.code.data.begin() + b->offset + index,
|
||||||
size);
|
size);
|
||||||
|
|
||||||
index += size;
|
index += size;
|
||||||
@ -1098,7 +1098,7 @@ class MyAssembler: public Assembler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
memcpy(dst + b->start + index + padding,
|
memcpy(dst + b->start + index + padding,
|
||||||
c.code.data + b->offset + index,
|
c.code.data.begin() + b->offset + index,
|
||||||
b->size - index);
|
b->size - index);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1142,7 +1142,8 @@ class MyAssembler: public Assembler {
|
|||||||
MyArchitecture* arch_;
|
MyArchitecture* arch_;
|
||||||
};
|
};
|
||||||
|
|
||||||
Assembler* MyArchitecture::makeAssembler(Allocator* allocator, Zone* zone) {
|
Assembler* MyArchitecture::makeAssembler(util::Allocator* allocator, Zone* zone)
|
||||||
|
{
|
||||||
return
|
return
|
||||||
new(zone) MyAssembler(c.s, allocator, zone, this);
|
new(zone) MyAssembler(c.s, allocator, zone, this);
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
There is NO WARRANTY for this software. See license.txt for
|
There is NO WARRANTY for this software. See license.txt for
|
||||||
details. */
|
details. */
|
||||||
|
|
||||||
#include "avian/allocator.h"
|
#include "avian/util/allocator.h"
|
||||||
#include "avian/zone.h"
|
#include "avian/zone.h"
|
||||||
|
|
||||||
#include "context.h"
|
#include "context.h"
|
||||||
@ -22,11 +22,21 @@ ArchitectureContext::ArchitectureContext(vm::System* s, bool useNativeFeatures):
|
|||||||
s(s), useNativeFeatures(useNativeFeatures)
|
s(s), useNativeFeatures(useNativeFeatures)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
Context::Context(vm::System* s, vm::Allocator* a, vm::Zone* zone, ArchitectureContext* ac):
|
Context::Context(vm::System* s,
|
||||||
s(s), zone(zone), client(0), code(s, a, 1024), tasks(0), result(0),
|
util::Allocator* a,
|
||||||
|
vm::Zone* zone,
|
||||||
|
ArchitectureContext* ac)
|
||||||
|
: s(s),
|
||||||
|
zone(zone),
|
||||||
|
client(0),
|
||||||
|
code(s, a, 1024),
|
||||||
|
tasks(0),
|
||||||
|
result(0),
|
||||||
firstBlock(new (zone) MyBlock(0)),
|
firstBlock(new (zone) MyBlock(0)),
|
||||||
lastBlock(firstBlock), ac(ac)
|
lastBlock(firstBlock),
|
||||||
{ }
|
ac(ac)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace x86
|
} // namespace x86
|
||||||
} // namespace codegen
|
} // namespace codegen
|
||||||
|
@ -75,7 +75,10 @@ class ArchitectureContext {
|
|||||||
|
|
||||||
class Context {
|
class Context {
|
||||||
public:
|
public:
|
||||||
Context(vm::System* s, vm::Allocator* a, vm::Zone* zone, ArchitectureContext* ac);
|
Context(vm::System* s,
|
||||||
|
util::Allocator* a,
|
||||||
|
vm::Zone* zone,
|
||||||
|
ArchitectureContext* ac);
|
||||||
|
|
||||||
vm::System* s;
|
vm::System* s;
|
||||||
vm::Zone* zone;
|
vm::Zone* zone;
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "avian/allocator.h"
|
#include "avian/util/allocator.h"
|
||||||
#include "avian/alloc-vector.h"
|
#include "avian/alloc-vector.h"
|
||||||
#include "avian/common.h"
|
#include "avian/common.h"
|
||||||
#include "avian/zone.h"
|
#include "avian/zone.h"
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
#include "avian/target.h"
|
#include "avian/target.h"
|
||||||
#include "avian/alloc-vector.h"
|
#include "avian/alloc-vector.h"
|
||||||
#include "avian/allocator.h"
|
#include "avian/util/allocator.h"
|
||||||
#include "avian/zone.h"
|
#include "avian/zone.h"
|
||||||
|
|
||||||
#include <avian/util/abort.h>
|
#include <avian/util/abort.h>
|
||||||
|
@ -24,6 +24,8 @@
|
|||||||
|
|
||||||
#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/slice.h>
|
||||||
|
#include <avian/util/fixed-allocator.h>
|
||||||
|
|
||||||
using namespace vm;
|
using namespace vm;
|
||||||
|
|
||||||
@ -1347,8 +1349,7 @@ storeLocal(Context* context, unsigned footprint, Compiler::Operand* value,
|
|||||||
(footprint, value, translateLocalIndex(context, footprint, index));
|
(footprint, value, translateLocalIndex(context, footprint, index));
|
||||||
}
|
}
|
||||||
|
|
||||||
FixedAllocator*
|
avian::util::FixedAllocator* codeAllocator(MyThread* t);
|
||||||
codeAllocator(MyThread* t);
|
|
||||||
|
|
||||||
class Frame {
|
class Frame {
|
||||||
public:
|
public:
|
||||||
@ -1640,13 +1641,17 @@ class Frame {
|
|||||||
|
|
||||||
Value absoluteAddressOperand(avian::codegen::Promise* p) {
|
Value absoluteAddressOperand(avian::codegen::Promise* p) {
|
||||||
return context->bootContext
|
return context->bootContext
|
||||||
? c->binaryOp(lir::Add,
|
? c->binaryOp(
|
||||||
TargetBytesPerWord, c->memory
|
lir::Add,
|
||||||
(c->register_(t->arch->thread()), Compiler::AddressType,
|
TargetBytesPerWord,
|
||||||
TARGET_THREAD_CODEIMAGE), c->promiseConstant
|
c->memory(c->register_(t->arch->thread()),
|
||||||
(new(&context->zone)
|
Compiler::AddressType,
|
||||||
avian::codegen::OffsetPromise
|
TARGET_THREAD_CODEIMAGE),
|
||||||
(p, - reinterpret_cast<intptr_t>(codeAllocator(t)->base)),
|
c->promiseConstant(
|
||||||
|
new (&context->zone) avian::codegen::OffsetPromise(
|
||||||
|
p,
|
||||||
|
-reinterpret_cast<intptr_t>(
|
||||||
|
codeAllocator(t)->memory.begin())),
|
||||||
Compiler::AddressType))
|
Compiler::AddressType))
|
||||||
: addressOperand(p);
|
: addressOperand(p);
|
||||||
}
|
}
|
||||||
@ -3130,8 +3135,9 @@ useLongJump(MyThread* t, uintptr_t target)
|
|||||||
{
|
{
|
||||||
uintptr_t reach = t->arch->maximumImmediateJump();
|
uintptr_t reach = t->arch->maximumImmediateJump();
|
||||||
FixedAllocator* a = codeAllocator(t);
|
FixedAllocator* a = codeAllocator(t);
|
||||||
uintptr_t start = reinterpret_cast<uintptr_t>(a->base);
|
uintptr_t start = reinterpret_cast<uintptr_t>(a->memory.begin());
|
||||||
uintptr_t end = reinterpret_cast<uintptr_t>(a->base) + a->capacity;
|
uintptr_t end = reinterpret_cast<uintptr_t>(a->memory.begin())
|
||||||
|
+ a->memory.count;
|
||||||
assert(t, end - start < reach);
|
assert(t, end - start < reach);
|
||||||
|
|
||||||
return (target > end && (target - start) > reach)
|
return (target > end && (target - start) > reach)
|
||||||
@ -6963,8 +6969,7 @@ finish(MyThread* t, FixedAllocator* allocator, Context* context)
|
|||||||
|
|
||||||
// we must acquire the class lock here at the latest
|
// we must acquire the class lock here at the latest
|
||||||
|
|
||||||
unsigned codeSize = c->resolve
|
unsigned codeSize = c->resolve(allocator->memory.begin() + allocator->offset);
|
||||||
(allocator->base + allocator->offset);
|
|
||||||
|
|
||||||
unsigned total = pad(codeSize, TargetBytesPerWord)
|
unsigned total = pad(codeSize, TargetBytesPerWord)
|
||||||
+ pad(c->poolSize(), TargetBytesPerWord);
|
+ pad(c->poolSize(), TargetBytesPerWord);
|
||||||
@ -6983,7 +6988,7 @@ finish(MyThread* t, FixedAllocator* allocator, Context* context)
|
|||||||
FixedSizeOfArray + ((context->objectPoolCount + 1) * BytesPerWord),
|
FixedSizeOfArray + ((context->objectPoolCount + 1) * BytesPerWord),
|
||||||
true);
|
true);
|
||||||
|
|
||||||
context->executableSize = (allocator->base + allocator->offset)
|
context->executableSize = (allocator->memory.begin() + allocator->offset)
|
||||||
- static_cast<uint8_t*>(context->executableStart);
|
- static_cast<uint8_t*>(context->executableStart);
|
||||||
|
|
||||||
initArray(t, pool, context->objectPoolCount + 1);
|
initArray(t, pool, context->objectPoolCount + 1);
|
||||||
@ -8518,7 +8523,7 @@ class MyProcessor: public Processor {
|
|||||||
divideByZeroHandler(Machine::ArithmeticExceptionType,
|
divideByZeroHandler(Machine::ArithmeticExceptionType,
|
||||||
Machine::ArithmeticException,
|
Machine::ArithmeticException,
|
||||||
FixedSizeOfArithmeticException),
|
FixedSizeOfArithmeticException),
|
||||||
codeAllocator(s, 0, 0),
|
codeAllocator(s, Slice<uint8_t>(0, 0)),
|
||||||
callTableSize(0),
|
callTableSize(0),
|
||||||
useNativeFeatures(useNativeFeatures),
|
useNativeFeatures(useNativeFeatures),
|
||||||
compilationHandlers(0)
|
compilationHandlers(0)
|
||||||
@ -8921,9 +8926,10 @@ class MyProcessor: public Processor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
virtual void dispose() {
|
virtual void dispose() {
|
||||||
if (codeAllocator.base) {
|
if (codeAllocator.memory.begin()) {
|
||||||
#if !defined(AVIAN_AOT_ONLY)
|
#if !defined(AVIAN_AOT_ONLY)
|
||||||
s->freeExecutable(codeAllocator.base, codeAllocator.capacity);
|
s->freeExecutable(codeAllocator.memory.begin(),
|
||||||
|
codeAllocator.memory.count);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -9021,10 +9027,10 @@ class MyProcessor: public Processor {
|
|||||||
return visitor.trace ? visitor.trace : makeObjectArray(t, 0);
|
return visitor.trace ? visitor.trace : makeObjectArray(t, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void initialize(BootImage* image, uint8_t* code, unsigned capacity) {
|
virtual void initialize(BootImage* image, Slice<uint8_t> code)
|
||||||
|
{
|
||||||
bootImage = image;
|
bootImage = image;
|
||||||
codeAllocator.base = code;
|
codeAllocator.memory = code;
|
||||||
codeAllocator.capacity = capacity;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void addCompilationHandler(CompilationHandler* handler) {
|
virtual void addCompilationHandler(CompilationHandler* handler) {
|
||||||
@ -9059,7 +9065,7 @@ class MyProcessor: public Processor {
|
|||||||
{
|
{
|
||||||
if (wordArrayBody(t, root(t, VirtualThunks), i)) {
|
if (wordArrayBody(t, root(t, VirtualThunks), i)) {
|
||||||
wordArrayBody(t, root(t, VirtualThunks), i)
|
wordArrayBody(t, root(t, VirtualThunks), i)
|
||||||
-= reinterpret_cast<uintptr_t>(codeAllocator.base);
|
-= reinterpret_cast<uintptr_t>(codeAllocator.memory.begin());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -9076,11 +9082,11 @@ class MyProcessor: public Processor {
|
|||||||
for (object p = arrayBody(t, root(t, CallTable), i);
|
for (object p = arrayBody(t, root(t, CallTable), i);
|
||||||
p; p = callNodeNext(t, p))
|
p; p = callNodeNext(t, p))
|
||||||
{
|
{
|
||||||
table[index++] = targetVW
|
table[index++] = targetVW(
|
||||||
(callNodeAddress(t, p)
|
callNodeAddress(t, p)
|
||||||
- reinterpret_cast<uintptr_t>(codeAllocator.base));
|
- reinterpret_cast<uintptr_t>(codeAllocator.memory.begin()));
|
||||||
table[index++] = targetVW
|
table[index++] = targetVW(
|
||||||
(w->map()->find(callNodeTarget(t, p))
|
w->map()->find(callNodeTarget(t, p))
|
||||||
| (static_cast<unsigned>(callNodeFlags(t, p)) << TargetBootShift));
|
| (static_cast<unsigned>(callNodeFlags(t, p)) << TargetBootShift));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -9088,12 +9094,13 @@ class MyProcessor: public Processor {
|
|||||||
return table;
|
return table;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void boot(Thread* t, BootImage* image, uint8_t* code) {
|
virtual void boot(Thread* t, BootImage* image, uint8_t* code)
|
||||||
|
{
|
||||||
#if !defined(AVIAN_AOT_ONLY)
|
#if !defined(AVIAN_AOT_ONLY)
|
||||||
if (codeAllocator.base == 0) {
|
if (codeAllocator.memory.begin() == 0) {
|
||||||
codeAllocator.base = static_cast<uint8_t*>
|
codeAllocator.memory.items = static_cast<uint8_t*>(
|
||||||
(s->tryAllocateExecutable(ExecutableAreaSizeInBytes));
|
s->tryAllocateExecutable(ExecutableAreaSizeInBytes));
|
||||||
codeAllocator.capacity = ExecutableAreaSizeInBytes;
|
codeAllocator.memory.count = ExecutableAreaSizeInBytes;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -10031,7 +10038,7 @@ compileThunks(MyThread* t, FixedAllocator* allocator)
|
|||||||
BootImage* image = p->bootImage;
|
BootImage* image = p->bootImage;
|
||||||
|
|
||||||
if (image) {
|
if (image) {
|
||||||
uint8_t* imageBase = p->codeAllocator.base;
|
uint8_t* imageBase = p->codeAllocator.memory.begin();
|
||||||
|
|
||||||
image->thunks.default_ = thunkToThunk(p->thunks.default_, imageBase);
|
image->thunks.default_ = thunkToThunk(p->thunks.default_, imageBase);
|
||||||
image->thunks.defaultVirtual = thunkToThunk
|
image->thunks.defaultVirtual = thunkToThunk
|
||||||
@ -10279,8 +10286,7 @@ setRoot(Thread* t, Root root, object value)
|
|||||||
ArrayBody + (root * BytesPerWord), value);
|
ArrayBody + (root * BytesPerWord), value);
|
||||||
}
|
}
|
||||||
|
|
||||||
FixedAllocator*
|
avian::util::FixedAllocator* codeAllocator(MyThread* t)
|
||||||
codeAllocator(MyThread* t)
|
|
||||||
{
|
{
|
||||||
return &(processor(t)->codeAllocator);
|
return &(processor(t)->codeAllocator);
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
#include "avian/zlib-custom.h"
|
#include "avian/zlib-custom.h"
|
||||||
#include "avian/finder.h"
|
#include "avian/finder.h"
|
||||||
#include "avian/lzma.h"
|
#include "avian/lzma.h"
|
||||||
|
#include "avian/append.h"
|
||||||
|
|
||||||
using namespace vm;
|
using namespace vm;
|
||||||
using namespace avian::util;
|
using namespace avian::util;
|
||||||
|
@ -19,6 +19,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/slice.h>
|
||||||
|
|
||||||
using namespace vm;
|
using namespace vm;
|
||||||
using namespace avian::system;
|
using namespace avian::system;
|
||||||
@ -3204,7 +3205,8 @@ class MyProcessor: public Processor {
|
|||||||
return makeObjectArray(t, 0);
|
return makeObjectArray(t, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void initialize(BootImage*, uint8_t*, unsigned) {
|
virtual void initialize(BootImage*, avian::util::Slice<uint8_t>)
|
||||||
|
{
|
||||||
abort(s);
|
abort(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3234,7 +3236,6 @@ class MyProcessor: public Processor {
|
|||||||
expect(s, image == 0 and code == 0);
|
expect(s, image == 0 and code == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
virtual void callWithCurrentContinuation(vm::Thread*, object) {
|
virtual void callWithCurrentContinuation(vm::Thread*, object) {
|
||||||
abort(s);
|
abort(s);
|
||||||
}
|
}
|
||||||
|
@ -61,7 +61,7 @@ mainClass(const char* jar)
|
|||||||
|
|
||||||
System* system = makeSystem();
|
System* system = makeSystem();
|
||||||
|
|
||||||
class MyAllocator: public Allocator {
|
class MyAllocator : public avian::util::Allocator {
|
||||||
public:
|
public:
|
||||||
MyAllocator(System* s): s(s) { }
|
MyAllocator(System* s): s(s) { }
|
||||||
|
|
||||||
|
@ -48,7 +48,9 @@
|
|||||||
#include "stdint.h"
|
#include "stdint.h"
|
||||||
#include "dirent.h"
|
#include "dirent.h"
|
||||||
#include "sched.h"
|
#include "sched.h"
|
||||||
#include "avian/arch.h"
|
|
||||||
|
#include <avian/arch.h>
|
||||||
|
#include <avian/append.h>
|
||||||
|
|
||||||
#include <avian/system/system.h>
|
#include <avian/system/system.h>
|
||||||
#include <avian/system/signal.h>
|
#include <avian/system/signal.h>
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
#include <avian/system/system.h>
|
#include <avian/system/system.h>
|
||||||
#include <avian/system/signal.h>
|
#include <avian/system/signal.h>
|
||||||
#include <avian/util/runtime-array.h>
|
#include <avian/util/runtime-array.h>
|
||||||
|
#include <avian/append.h>
|
||||||
|
|
||||||
#if defined(WINAPI_FAMILY)
|
#if defined(WINAPI_FAMILY)
|
||||||
|
|
||||||
@ -836,7 +837,9 @@ class MySystem: public System {
|
|||||||
return SO_SUFFIX;
|
return SO_SUFFIX;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual const char* toAbsolutePath(Allocator* allocator, const char* name) {
|
virtual const char* toAbsolutePath(avian::util::Allocator* allocator,
|
||||||
|
const char* name)
|
||||||
|
{
|
||||||
#if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
|
#if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
|
||||||
if (strncmp(name, "//", 2) == 0
|
if (strncmp(name, "//", 2) == 0
|
||||||
or strncmp(name, "\\\\", 2) == 0
|
or strncmp(name, "\\\\", 2) == 0
|
||||||
|
@ -38,6 +38,7 @@ void operator delete(void*) { abort(); }
|
|||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
using namespace avian::tools;
|
using namespace avian::tools;
|
||||||
|
using namespace avian::util;
|
||||||
|
|
||||||
bool
|
bool
|
||||||
writeObject(uint8_t* data, size_t size, OutputStream* out, const char* startName,
|
writeObject(uint8_t* data, size_t size, OutputStream* out, const char* startName,
|
||||||
|
@ -1917,9 +1917,9 @@ main(int ac, const char** av)
|
|||||||
const unsigned CodeCapacity = 30 * 1024 * 1024;
|
const unsigned CodeCapacity = 30 * 1024 * 1024;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
uint8_t* code = static_cast<uint8_t*>(h->allocate(CodeCapacity));
|
Slice<uint8_t> code = Slice<uint8_t>::alloc(h, CodeCapacity);
|
||||||
BootImage image;
|
BootImage image;
|
||||||
p->initialize(&image, code, CodeCapacity);
|
p->initialize(&image, code);
|
||||||
|
|
||||||
Machine* m = new (h->allocate(sizeof(Machine))) Machine
|
Machine* m = new (h->allocate(sizeof(Machine))) Machine
|
||||||
(s, h, f, 0, p, c, 0, 0, 0, 0, 128 * 1024);
|
(s, h, f, 0, p, c, 0, 0, 0, 0, 128 * 1024);
|
||||||
@ -1940,11 +1940,10 @@ main(int ac, const char** av)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
uintptr_t arguments[] = {
|
uintptr_t arguments[] = {reinterpret_cast<uintptr_t>(&bootimageOutput),
|
||||||
reinterpret_cast<uintptr_t>(&bootimageOutput),
|
|
||||||
reinterpret_cast<uintptr_t>(&codeOutput),
|
reinterpret_cast<uintptr_t>(&codeOutput),
|
||||||
reinterpret_cast<uintptr_t>(&image),
|
reinterpret_cast<uintptr_t>(&image),
|
||||||
reinterpret_cast<uintptr_t>(code),
|
reinterpret_cast<uintptr_t>(code.begin()),
|
||||||
reinterpret_cast<uintptr_t>(args.entryClass),
|
reinterpret_cast<uintptr_t>(args.entryClass),
|
||||||
reinterpret_cast<uintptr_t>(args.entryMethod),
|
reinterpret_cast<uintptr_t>(args.entryMethod),
|
||||||
reinterpret_cast<uintptr_t>(args.entrySpec),
|
reinterpret_cast<uintptr_t>(args.entrySpec),
|
||||||
@ -1952,8 +1951,7 @@ main(int ac, const char** av)
|
|||||||
reinterpret_cast<uintptr_t>(args.bootimageEnd),
|
reinterpret_cast<uintptr_t>(args.bootimageEnd),
|
||||||
reinterpret_cast<uintptr_t>(args.codeimageStart),
|
reinterpret_cast<uintptr_t>(args.codeimageStart),
|
||||||
reinterpret_cast<uintptr_t>(args.codeimageEnd),
|
reinterpret_cast<uintptr_t>(args.codeimageEnd),
|
||||||
static_cast<uintptr_t>(args.useLZMA)
|
static_cast<uintptr_t>(args.useLZMA)};
|
||||||
};
|
|
||||||
|
|
||||||
run(t, writeBootImage, arguments);
|
run(t, writeBootImage, arguments);
|
||||||
|
|
||||||
|
@ -1943,7 +1943,7 @@ main(int ac, char** av)
|
|||||||
|
|
||||||
System* system = makeSystem();
|
System* system = makeSystem();
|
||||||
|
|
||||||
class MyAllocator: public Allocator {
|
class MyAllocator : public avian::util::Allocator {
|
||||||
public:
|
public:
|
||||||
MyAllocator(System* s): s(s) { }
|
MyAllocator(System* s): s(s) { }
|
||||||
|
|
||||||
|
54
src/util/fixed-allocator.cpp
Normal file
54
src/util/fixed-allocator.cpp
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
/* Copyright (c) 2008-2013, Avian Contributors
|
||||||
|
|
||||||
|
Permission to use, copy, modify, and/or distribute this software
|
||||||
|
for any purpose with or without fee is hereby granted, provided
|
||||||
|
that the above copyright notice and this permission notice appear
|
||||||
|
in all copies.
|
||||||
|
|
||||||
|
There is NO WARRANTY for this software. See license.txt for
|
||||||
|
details. */
|
||||||
|
|
||||||
|
#include <avian/util/fixed-allocator.h>
|
||||||
|
|
||||||
|
#include <avian/common.h>
|
||||||
|
|
||||||
|
namespace avian {
|
||||||
|
namespace util {
|
||||||
|
|
||||||
|
FixedAllocator::FixedAllocator(Aborter* a, Slice<uint8_t> memory)
|
||||||
|
: a(a), memory(memory), offset(0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void* FixedAllocator::tryAllocate(unsigned size)
|
||||||
|
{
|
||||||
|
return allocate(size);
|
||||||
|
}
|
||||||
|
|
||||||
|
void* FixedAllocator::allocate(unsigned size, unsigned padAlignment)
|
||||||
|
{
|
||||||
|
unsigned paddedSize = vm::pad(size, padAlignment);
|
||||||
|
expect(a, offset + paddedSize < memory.count);
|
||||||
|
|
||||||
|
void* p = memory.begin() + offset;
|
||||||
|
offset += paddedSize;
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
void* FixedAllocator::allocate(unsigned size)
|
||||||
|
{
|
||||||
|
return allocate(size, vm::BytesPerWord);
|
||||||
|
}
|
||||||
|
|
||||||
|
void FixedAllocator::free(const void* p, unsigned size)
|
||||||
|
{
|
||||||
|
if (p >= memory.begin() and static_cast<const uint8_t*>(p) + size
|
||||||
|
== memory.begin() + offset) {
|
||||||
|
offset -= size;
|
||||||
|
} else {
|
||||||
|
abort(a);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace util
|
||||||
|
} // namespace avian
|
@ -11,3 +11,4 @@ if [ -z "${openjdk}" ]; then
|
|||||||
make ${flags} bootimage=true test
|
make ${flags} bootimage=true test
|
||||||
fi
|
fi
|
||||||
make ${flags} tails=true continuations=true test
|
make ${flags} tails=true continuations=true test
|
||||||
|
make ${flags} codegen-targets=all
|
||||||
|
Loading…
Reference in New Issue
Block a user