move Allocator to include, properly namespaced

This commit is contained in:
Joshua Warner 2014-02-25 11:32:17 -07:00 committed by Joshua Warner
parent d95a8a9626
commit 52b23b8a6a
31 changed files with 214 additions and 107 deletions

View File

@ -12,11 +12,15 @@
#define AVIAN_CODEGEN_ARCHITECTURE_H
namespace vm {
class Allocator;
class Zone;
}
namespace avian {
namespace util {
class Allocator;
}
namespace codegen {
class Assembler;
@ -125,7 +129,7 @@ virtual void planDestination
unsigned bSize, const OperandMask& bMask,
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 release() = 0;

View File

@ -11,7 +11,9 @@
#ifndef 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 codegen {
@ -102,8 +104,8 @@ class OffsetPromise: public Promise {
class ListenPromise: public Promise {
public:
ListenPromise(vm::System* s, vm::Allocator* allocator):
s(s), allocator(allocator), listener(0)
ListenPromise(vm::System* s, util::Allocator* allocator)
: s(s), allocator(allocator), listener(0)
{ }
virtual int64_t value() {
@ -122,16 +124,18 @@ class ListenPromise: public Promise {
}
vm::System* s;
vm::Allocator* allocator;
util::Allocator* allocator;
Listener* listener;
Promise* promise;
};
class DelayedPromise: public ListenPromise {
public:
DelayedPromise(vm::System* s, vm::Allocator* allocator, Promise* basis,
DelayedPromise* next):
ListenPromise(s, allocator), basis(basis), next(next)
DelayedPromise(vm::System* s,
util::Allocator* allocator,
Promise* basis,
DelayedPromise* next)
: ListenPromise(s, allocator), basis(basis), next(next)
{ }
virtual int64_t value() {

View File

@ -12,7 +12,7 @@
#define HEAP_H
#include <avian/system/system.h>
#include "avian/allocator.h"
#include <avian/util/allocator.h>
namespace vm {
@ -22,7 +22,7 @@ const unsigned TenureThreshold = 3;
const unsigned FixieTenureThreshold = TenureThreshold + 2;
class Heap: public Allocator {
class Heap : public avian::util::Allocator {
public:
enum CollectionType {
MinorCollection,
@ -65,9 +65,10 @@ class Heap: public Allocator {
virtual void collect(CollectionType type, unsigned footprint,
int pendingAllocation) = 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;
virtual void* allocateImmortalFixed(Allocator* allocator,
virtual void* allocateImmortalFixed(avian::util::Allocator* allocator,
unsigned sizeInWords,
bool objectMask) = 0;
virtual void mark(void* p, unsigned offset, unsigned count) = 0;

View File

@ -12,7 +12,7 @@
#define SYSTEM_H
#include "avian/common.h"
#include "avian/allocator.h"
#include <avian/util/allocator.h>
#include <avian/util/abort.h>
namespace vm {
@ -139,7 +139,7 @@ class System : public avian::util::Aborter {
virtual Status load(Library**, const char* name) = 0;
virtual char pathSeparator() = 0;
virtual char fileSeparator() = 0;
virtual const char* toAbsolutePath(Allocator* allocator,
virtual const char* toAbsolutePath(avian::util::Allocator* allocator,
const char* name) = 0;
virtual int64_t now() = 0;
virtual void yield() = 0;

View File

@ -11,6 +11,10 @@
#ifndef 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 util {

View File

@ -0,0 +1,34 @@
/* 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:
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

View File

@ -11,6 +11,11 @@
#ifndef AVIAN_UTIL_LIST_H
#define AVIAN_UTIL_LIST_H
#include "allocator.h"
namespace avian {
namespace util {
template <class T>
class List {
public:
@ -32,4 +37,7 @@ public:
List<T>* next;
};
#endif // AVIAN_UTIL_LIST_H
} // namespace util
} // namespace avian
#endif // AVIAN_UTIL_LIST_H

View File

@ -15,6 +15,7 @@
#include "avian/target.h"
#include <avian/util/math.h>
#include <avian/util/allocator.h>
#undef max
#undef min
@ -23,13 +24,13 @@ namespace vm {
class Vector {
public:
Vector(System* s, Allocator* allocator, unsigned minimumCapacity):
s(s),
allocator(allocator),
data(0),
position(0),
capacity(0),
minimumCapacity(minimumCapacity)
Vector(System* s, avian::util::Allocator* allocator, unsigned minimumCapacity)
: s(s),
allocator(allocator),
data(0),
position(0),
capacity(0),
minimumCapacity(minimumCapacity)
{ }
~Vector() {
@ -157,7 +158,7 @@ class Vector {
}
System* s;
Allocator* allocator;
avian::util::Allocator* allocator;
uint8_t* data;
unsigned position;
unsigned capacity;

View File

@ -8,22 +8,18 @@
There is NO WARRANTY for this software. See license.txt for
details. */
#ifndef ALLOCATOR_H
#define ALLOCATOR_H
#ifndef APPEND_H
#define APPEND_H
#include "avian/common.h"
#include <avian/common.h>
#include <avian/util/allocator.h>
namespace vm {
class Allocator {
public:
virtual void* tryAllocate(unsigned size) = 0;
virtual void* allocate(unsigned size) = 0;
virtual void free(const void* p, unsigned size) = 0;
};
inline const char*
append(Allocator* allocator, const char* a, const char* b, const char* c)
inline const char* append(avian::util::Allocator* allocator,
const char* a,
const char* b,
const char* c)
{
unsigned al = strlen(a);
unsigned bl = strlen(b);
@ -35,8 +31,9 @@ append(Allocator* allocator, const char* a, const char* b, const char* c)
return p;
}
inline const char*
append(Allocator* allocator, const char* a, const char* b)
inline const char* append(avian::util::Allocator* allocator,
const char* a,
const char* b)
{
unsigned al = strlen(a);
unsigned bl = strlen(b);
@ -46,8 +43,7 @@ append(Allocator* allocator, const char* a, const char* b)
return p;
}
inline const char*
copy(Allocator* allocator, const char* a)
inline const char* copy(avian::util::Allocator* allocator, const char* a)
{
unsigned al = strlen(a);
char* p = static_cast<char*>(allocator->allocate(al + 1));
@ -55,10 +51,6 @@ copy(Allocator* allocator, const char* a)
return p;
}
} // namespace vm
} // namespace vm
inline void* operator new (size_t size, vm::Allocator* allocator) {
return allocator->allocate(size);
}
#endif//ALLOCATOR_H
#endif // APPEND_H

View File

@ -13,7 +13,12 @@
#include "avian/common.h"
#include <avian/system/system.h>
#include "avian/allocator.h"
namespace avian {
namespace util {
class Allocator;
}
}
namespace vm {
@ -174,12 +179,15 @@ class Finder {
virtual void dispose() = 0;
};
AVIAN_EXPORT Finder*
makeFinder(System* s, Allocator* a, const char* path, const char* bootLibrary);
AVIAN_EXPORT Finder* makeFinder(System* s,
avian::util::Allocator* a,
const char* path,
const char* bootLibrary);
Finder*
makeFinder(System* s, Allocator* a, const uint8_t* jarData,
unsigned jarLength);
Finder* makeFinder(System* s,
avian::util::Allocator* a,
const uint8_t* jarData,
unsigned jarLength);
} // namespace vm

View File

@ -14,7 +14,7 @@
#include "avian/lzma.h"
#include "C/Types.h"
#include <avian/system/system.h>
#include "avian/allocator.h"
#include "avian/util/allocator.h"
namespace vm {

View File

@ -12,17 +12,26 @@
#define LZMA_H
#include <avian/system/system.h>
#include "avian/allocator.h"
namespace avian {
namespace util {
class Allocator;
}
}
namespace vm {
uint8_t*
decodeLZMA(System* s, Allocator* a, uint8_t* in, unsigned inSize,
unsigned* outSize);
uint8_t* decodeLZMA(System* s,
avian::util::Allocator* a,
uint8_t* in,
unsigned inSize,
unsigned* outSize);
uint8_t*
encodeLZMA(System* s, Allocator* a, uint8_t* in, unsigned inSize,
unsigned* outSize);
uint8_t* encodeLZMA(System* s,
avian::util::Allocator* a,
uint8_t* in,
unsigned inSize,
unsigned* outSize);
} // namespace vm

View File

@ -14,6 +14,7 @@
#include "avian/common.h"
#include <avian/system/system.h>
#include <avian/heap/heap.h>
#include <avian/util/allocator.h>
#include "bootimage.h"
#include "avian/heapwalk.h"
#include "avian/zone.h"
@ -209,7 +210,7 @@ class Processor {
};
Processor* makeProcessor(System* system,
Allocator* allocator,
avian::util::Allocator* allocator,
const char* crashDumpDirectory,
bool useNativeFeatures);

View File

@ -12,13 +12,12 @@
#define ZONE_H
#include <avian/system/system.h>
#include "avian/allocator.h"
#include <avian/util/allocator.h>
#include <avian/util/math.h>
namespace vm {
class Zone: public Allocator {
class Zone : public avian::util::Allocator {
public:
class Segment {
public:

View File

@ -38,14 +38,14 @@ namespace isa {
// HARDWARE FLAGS
bool vfpSupported() {
// TODO: Use at runtime detection
#if defined(__ARM_PCS_VFP)
#if defined(__ARM_PCS_VFP)
// armhf
return true;
#else
// armel
// TODO: allow VFP use for -mfloat-abi=softfp armel builds.
// GCC -mfloat-abi=softfp flag allows use of VFP while remaining compatible
// with soft-float code.
// with soft-float code.
return false;
#endif
}
@ -793,7 +793,7 @@ class MyAssembler: public Assembler {
assert(&con, b.size == c.size);
assert(&con, b.type == lir::RegisterOperand);
assert(&con, c.type == lir::RegisterOperand);
arch_->con.ternaryOperations[index(&(arch_->con), op, a.type)]
(&con, b.size, a.operand, b.operand, c.operand);
}

View File

@ -15,12 +15,21 @@ namespace avian {
namespace codegen {
namespace arm {
Context::Context(vm::System* s, vm::Allocator* a, vm::Zone* zone):
s(s), zone(zone), client(0), code(s, a, 1024), tasks(0), result(0),
firstBlock(new(zone) MyBlock(this, 0)),
lastBlock(firstBlock), poolOffsetHead(0), poolOffsetTail(0),
constantPool(0), constantPoolCount(0)
{ }
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),
firstBlock(new (zone) MyBlock(this, 0)),
lastBlock(firstBlock),
poolOffsetHead(0),
poolOffsetTail(0),
constantPool(0),
constantPoolCount(0)
{
}
} // namespace arm
} // namespace codegen

View File

@ -17,7 +17,6 @@
namespace vm {
class System;
class Allocator;
class Zone;
} // namespace vm
@ -25,6 +24,7 @@ namespace avian {
namespace util {
class Aborter;
class Allocator;
} // namespace util
namespace codegen {
@ -37,7 +37,7 @@ class ConstantPoolEntry;
class Context {
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::Zone* zone;

View File

@ -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() {
++ referenceCount;
@ -604,8 +604,8 @@ class MyArchitecture: public Architecture {
class MyAssembler: public Assembler {
public:
MyAssembler(System* s, Allocator* a, Zone* zone, MyArchitecture* arch):
c(s, a, zone), arch_(arch)
MyAssembler(System* s, util::Allocator* a, Zone* zone, MyArchitecture* arch)
: c(s, a, zone), arch_(arch)
{ }
virtual void setClient(Client* client) {
@ -992,7 +992,8 @@ class MyAssembler: public Assembler {
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);
}

View File

@ -16,13 +16,21 @@ namespace avian {
namespace codegen {
namespace powerpc {
Context::Context(vm::System* s, vm::Allocator* a, vm::Zone* zone):
s(s), zone(zone), client(0), code(s, a, 1024), tasks(0), result(0),
firstBlock(new(zone) MyBlock(this, 0)),
lastBlock(firstBlock), jumpOffsetHead(0), jumpOffsetTail(0),
constantPool(0), constantPoolCount(0)
{ }
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),
firstBlock(new (zone) MyBlock(this, 0)),
lastBlock(firstBlock),
jumpOffsetHead(0),
jumpOffsetTail(0),
constantPool(0),
constantPoolCount(0)
{
}
} // namespace powerpc
} // namespace codegen

View File

@ -20,12 +20,16 @@
namespace vm {
class System;
class Allocator;
class Zone;
} // namespace vm
namespace avian {
namespace util {
class Allocator;
}
namespace codegen {
namespace powerpc {
@ -36,7 +40,7 @@ class MyBlock;
class Context {
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::Zone* zone;

View File

@ -15,7 +15,7 @@
#include "avian/target.h"
#include "avian/alloc-vector.h"
#include "avian/common.h"
#include "avian/allocator.h"
#include "avian/util/allocator.h"
#include "avian/zone.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() {
++ referenceCount;
@ -809,8 +809,8 @@ class MyArchitecture: public Architecture {
class MyAssembler: public Assembler {
public:
MyAssembler(System* s, Allocator* a, Zone* zone, MyArchitecture* arch):
c(s, a, zone, &(arch->c)), arch_(arch)
MyAssembler(System* s, util::Allocator* a, Zone* zone, MyArchitecture* arch)
: c(s, a, zone, &(arch->c)), arch_(arch)
{ }
virtual void setClient(Client* client) {
@ -1142,7 +1142,8 @@ class MyAssembler: public Assembler {
MyArchitecture* arch_;
};
Assembler* MyArchitecture::makeAssembler(Allocator* allocator, Zone* zone) {
Assembler* MyArchitecture::makeAssembler(util::Allocator* allocator, Zone* zone)
{
return
new(zone) MyAssembler(c.s, allocator, zone, this);
}

View File

@ -8,7 +8,7 @@
There is NO WARRANTY for this software. See license.txt for
details. */
#include "avian/allocator.h"
#include "avian/util/allocator.h"
#include "avian/zone.h"
#include "context.h"
@ -22,11 +22,21 @@ ArchitectureContext::ArchitectureContext(vm::System* s, bool useNativeFeatures):
s(s), useNativeFeatures(useNativeFeatures)
{ }
Context::Context(vm::System* s, vm::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)),
lastBlock(firstBlock), ac(ac)
{ }
Context::Context(vm::System* s,
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)),
lastBlock(firstBlock),
ac(ac)
{
}
} // namespace x86
} // namespace codegen

View File

@ -75,7 +75,10 @@ class ArchitectureContext {
class Context {
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::Zone* zone;

View File

@ -10,7 +10,7 @@
#include <string.h>
#include "avian/allocator.h"
#include "avian/util/allocator.h"
#include "avian/alloc-vector.h"
#include "avian/common.h"
#include "avian/zone.h"

View File

@ -10,7 +10,7 @@
#include "avian/target.h"
#include "avian/alloc-vector.h"
#include "avian/allocator.h"
#include "avian/util/allocator.h"
#include "avian/zone.h"
#include <avian/util/abort.h>

View File

@ -16,7 +16,7 @@
#include "avian/zlib-custom.h"
#include "avian/finder.h"
#include "avian/lzma.h"
#include "avian/append.h"
using namespace vm;
using namespace avian::util;

View File

@ -61,7 +61,7 @@ mainClass(const char* jar)
System* system = makeSystem();
class MyAllocator: public Allocator {
class MyAllocator : public avian::util::Allocator {
public:
MyAllocator(System* s): s(s) { }

View File

@ -48,7 +48,9 @@
#include "stdint.h"
#include "dirent.h"
#include "sched.h"
#include "avian/arch.h"
#include <avian/arch.h>
#include <avian/append.h>
#include <avian/system/system.h>
#include <avian/system/signal.h>

View File

@ -26,6 +26,7 @@
#include <avian/system/system.h>
#include <avian/system/signal.h>
#include <avian/util/runtime-array.h>
#include <avian/append.h>
#if defined(WINAPI_FAMILY)
@ -842,7 +843,9 @@ class MySystem: public System {
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 (strncmp(name, "//", 2) == 0
or strncmp(name, "\\\\", 2) == 0

View File

@ -38,6 +38,7 @@ void operator delete(void*) { abort(); }
namespace {
using namespace avian::tools;
using namespace avian::util;
bool
writeObject(uint8_t* data, size_t size, OutputStream* out, const char* startName,

View File

@ -1943,7 +1943,7 @@ main(int ac, char** av)
System* system = makeSystem();
class MyAllocator: public Allocator {
class MyAllocator : public avian::util::Allocator {
public:
MyAllocator(System* s): s(s) { }