Merge branch 'compiler' of oss.readytalk.com:/var/local/git/avian

This commit is contained in:
Joel Dice 2008-04-16 11:16:36 -06:00
commit df4a56d40c
9 changed files with 4571 additions and 3881 deletions

View File

@ -164,7 +164,9 @@ vm-depends = \
$(src)/jnienv.h \
$(src)/machine.h \
$(src)/util.h \
$(src)/zone.h
$(src)/zone.h \
$(src)/assembler.h \
$(src)/compiler.h
vm-sources = \
$(src)/$(system).cpp \
@ -175,7 +177,8 @@ vm-sources = \
$(src)/$(process).cpp \
$(src)/builtin.cpp \
$(src)/jnienv.cpp \
$(src)/process.cpp
$(src)/process.cpp \
$(src)/$(asm).cpp
vm-asm-sources = $(src)/$(asm).S

View File

@ -2,7 +2,7 @@ Quick Start
-----------
on Linux:
$ export JAVA_HOME=/usr/local/java # or wherever you have Java installed
$ export JAVA_HOME=/usr/local/java # or wherever you have the JDK installed
$ make
$ build/linux-i386-compile-fast/avian -cp build/test Hello

186
src/assembler.h Normal file
View File

@ -0,0 +1,186 @@
#ifndef ASSEMBLER_H
#define ASSEMBLER_H
#include "system.h"
#include "zone.h"
namespace vm {
enum Operation {
Return
};
const unsigned OperationCount = Return + 1;
enum UnaryOperation {
Push,
Pop,
Call,
AlignedCall,
Jump,
JumpIfLess,
JumpIfGreater,
JumpIfLessOrEqual,
JumpIfGreaterOrEqual,
JumpIfEqual,
JumpIfNotEqual,
Negate
};
const unsigned UnaryOperationCount = Negate + 1;
enum BinaryOperation {
LoadAddress,
Move,
MoveZ,
Move4To8,
Compare,
Add,
Subtract,
Multiply,
Divide,
Remainder,
ShiftLeft,
ShiftRight,
UnsignedShiftRight,
And,
Or,
Xor
};
const unsigned BinaryOperationCount = Xor + 1;
enum OperandType {
Constant,
Address,
Register,
Memory
};
const unsigned OperandTypeCount = Memory + 1;
const int NoRegister = -1;
const int AnyRegister = -2;
class Promise {
public:
virtual ~Promise() { }
virtual int64_t value() = 0;
virtual bool resolved() = 0;
};
class ResolvedPromise: public Promise {
public:
ResolvedPromise(int64_t value): value_(value) { }
virtual int64_t value() {
return value_;
}
virtual bool resolved() {
return true;
}
int64_t value_;
};
class TraceHandler {
public:
virtual ~TraceHandler() { }
virtual void handleTrace(Promise* address) = 0;
};
class Assembler {
public:
class Operand { };
class Constant: public Operand {
public:
Constant(Promise* value): value(value) { }
Promise* value;
};
class Address: public Operand {
public:
Address(Promise* address): address(address) { }
Promise* address;
};
class Register: public Operand {
public:
Register(int low, int high = NoRegister): low(low), high(high) { }
int low;
int high;
};
class Memory: public Operand {
public:
Memory(int base, int offset, int index = NoRegister, unsigned scale = 0):
base(base), offset(offset), index(index), scale(scale)
{ }
int base;
int offset;
int index;
unsigned scale;
};
class Client {
public:
virtual ~Client() { }
virtual int acquireTemporary(int r = NoRegister) = 0;
virtual void releaseTemporary(int r) = 0;
};
virtual ~Assembler() { }
virtual void setClient(Client* client) = 0;
virtual unsigned registerCount() = 0;
virtual int base() = 0;
virtual int stack() = 0;
virtual int thread() = 0;
virtual int returnLow() = 0;
virtual int returnHigh() = 0;
virtual unsigned argumentRegisterCount() = 0;
virtual int argumentRegister(unsigned index) = 0;
virtual int stackSyncRegister(unsigned index) = 0;
virtual void getTargets(UnaryOperation op, unsigned size,
Register* a) = 0;
virtual void getTargets(BinaryOperation op, unsigned size,
Register* a, Register* b) = 0;
virtual void apply(Operation op) = 0;
virtual void apply(UnaryOperation op, unsigned size, OperandType type,
Operand* operand) = 0;
virtual void apply(BinaryOperation op, unsigned size, OperandType aType,
Operand* a, OperandType bType, Operand* b) = 0;
virtual void writeTo(uint8_t* dst) = 0;
virtual unsigned length() = 0;
virtual void updateCall(void* returnAddress, void* newTarget) = 0;
virtual void dispose() = 0;
};
Assembler*
makeAssembler(System* system, Allocator* allocator, Zone* zone);
} // namespace vm
#endif//ASSEMBLER_H

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -13,41 +13,35 @@
#include "system.h"
#include "zone.h"
#include "assembler.h"
namespace vm {
class Operand { };
class Stack { };
class Compiler;
class Promise {
public:
virtual ~Promise() { }
virtual intptr_t value(Compiler*) = 0;
};
class Compiler {
public:
class TraceHandler {
public:
virtual ~TraceHandler() { }
static const unsigned Aligned = 1 << 0;
static const unsigned NoReturn = 1 << 1;
virtual void handleTrace(Promise* address) = 0;
};
class Operand { };
virtual ~Compiler() { }
virtual void pushState() = 0;
virtual void popState() = 0;
virtual void init(unsigned logicalCodeSize, unsigned localFootprint) = 0;
virtual void visitLogicalIp(unsigned logicalIp) = 0;
virtual void startLogicalIp(unsigned logicalIp) = 0;
virtual Promise* machineIp(unsigned logicalIp) = 0;
virtual Promise* poolAppend(intptr_t) = 0;
virtual Promise* poolAppendPromise(Promise*) = 0;
virtual Promise* poolAppend(intptr_t value) = 0;
virtual Promise* poolAppendPromise(Promise* value) = 0;
virtual Operand* constant(int64_t) = 0;
virtual Operand* promiseConstant(Promise*) = 0;
virtual Operand* absolute(Promise*) = 0;
virtual Operand* constant(int64_t value) = 0;
virtual Operand* promiseConstant(Promise* value) = 0;
virtual Operand* address(Promise* address) = 0;
virtual Operand* memory(Operand* base,
int displacement = 0,
Operand* index = 0,
@ -56,102 +50,64 @@ class Compiler {
virtual Operand* stack() = 0;
virtual Operand* base() = 0;
virtual Operand* thread() = 0;
virtual Operand* indirectTarget() = 0;
virtual Operand* temporary() = 0;
virtual Operand* result4() = 0;
virtual Operand* result8() = 0;
virtual void release(Operand*) = 0;
virtual bool isConstant(Operand* value) = 0;
virtual int64_t constantValue(Operand* value) = 0;
virtual Operand* label() = 0;
virtual void mark(Operand*) = 0;
virtual void mark(Operand* label) = 0;
virtual void indirectCall
(Operand* address, TraceHandler* traceHandler,
unsigned argumentCount, ...) = 0;
virtual void indirectCallNoReturn
(Operand* address, TraceHandler* traceHandler,
unsigned argumentCount, ...) = 0;
virtual void directCall
(Operand* address, unsigned argumentCount, ...) = 0;
virtual void push(unsigned size, Operand* value) = 0;
virtual Operand* pop(unsigned size) = 0;
virtual void pushed(unsigned count) = 0;
virtual void popped(unsigned count) = 0;
virtual Operand* peek(unsigned size, unsigned index) = 0;
virtual void call(Operand*, TraceHandler*) = 0;
virtual void alignedCall(Operand*, TraceHandler*) = 0;
virtual void return4(Operand*) = 0;
virtual void return8(Operand*) = 0;
virtual void ret() = 0;
virtual Operand* call(Operand* address,
void* indirection,
unsigned flags,
TraceHandler* traceHandler,
unsigned resultSize,
unsigned argumentCount,
...) = 0;
virtual Stack* push(Stack*, unsigned count) = 0;
virtual Stack* pushed(Stack*, unsigned count) = 0;
virtual Stack* pop(Stack*, unsigned count) = 0;
virtual Operand* stack(Stack*, unsigned) = 0;
virtual void return_(unsigned size, Operand* value) = 0;
virtual Stack* push1(Stack*, Operand*) = 0;
virtual Stack* push2(Stack*, Operand*) = 0;
virtual Stack* push2z(Stack*, Operand*) = 0;
virtual Stack* push4(Stack*, Operand*) = 0;
virtual Stack* push8(Stack*, Operand*) = 0;
virtual Stack* pop4(Stack*, Operand*) = 0;
virtual Stack* pop8(Stack*, Operand*) = 0;
virtual void mov1(Operand* src, Operand* dst) = 0;
virtual void mov2(Operand* src, Operand* dst) = 0;
virtual void mov4(Operand* src, Operand* dst) = 0;
virtual void mov8(Operand* src, Operand* dst) = 0;
virtual void mov1ToW(Operand* src, Operand* dst) = 0;
virtual void mov2ToW(Operand* src, Operand* dst) = 0;
virtual void mov2zToW(Operand* src, Operand* dst) = 0;
virtual void mov4To8(Operand* src, Operand* dst) = 0;
virtual void cmp4(Operand* subtrahend, Operand* minuend) = 0;
virtual void cmp8(Operand* subtrahend, Operand* minuend) = 0;
virtual void jl(Operand*) = 0;
virtual void jg(Operand*) = 0;
virtual void jle(Operand*) = 0;
virtual void jge(Operand*) = 0;
virtual void je(Operand*) = 0;
virtual void jne(Operand*) = 0;
virtual void jmp(Operand*) = 0;
virtual void add4(Operand* v, Operand* dst) = 0;
virtual void add8(Operand* v, Operand* dst) = 0;
virtual void sub4(Operand* v, Operand* dst) = 0;
virtual void sub8(Operand* v, Operand* dst) = 0;
virtual void mul4(Operand* v, Operand* dst) = 0;
virtual void mul8(Operand* v, Operand* dst) = 0;
virtual void div4(Operand* v, Operand* dst) = 0;
virtual void div8(Operand* v, Operand* dst) = 0;
virtual void rem4(Operand* v, Operand* dst) = 0;
virtual void rem8(Operand* v, Operand* dst) = 0;
virtual void shl4(Operand* v, Operand* dst) = 0;
virtual void shl8(Operand* v, Operand* dst) = 0;
virtual void shr4(Operand* v, Operand* dst) = 0;
virtual void shr8(Operand* v, Operand* dst) = 0;
virtual void ushr4(Operand* v, Operand* dst) = 0;
virtual void ushr8(Operand* v, Operand* dst) = 0;
virtual void and4(Operand* v, Operand* dst) = 0;
virtual void and8(Operand* v, Operand* dst) = 0;
virtual void or4(Operand* v, Operand* dst) = 0;
virtual void or8(Operand* v, Operand* dst) = 0;
virtual void xor4(Operand* v, Operand* dst) = 0;
virtual void xor8(Operand* v, Operand* dst) = 0;
virtual void neg4(Operand*) = 0;
virtual void neg8(Operand*) = 0;
virtual void store(unsigned size, Operand* src, Operand* dst) = 0;
virtual Operand* load(unsigned size, Operand* src) = 0;
virtual Operand* loadz(unsigned size, Operand* src) = 0;
virtual Operand* load4To8(Operand* src) = 0;
virtual Operand* dup(unsigned size, Operand* src) = 0;
virtual void cmp(unsigned size, Operand* a, Operand* b) = 0;
virtual void jl(Operand* address) = 0;
virtual void jg(Operand* address) = 0;
virtual void jle(Operand* address) = 0;
virtual void jge(Operand* address) = 0;
virtual void je(Operand* address) = 0;
virtual void jne(Operand* address) = 0;
virtual void jmp(Operand* address) = 0;
virtual Operand* add(unsigned size, Operand* a, Operand* b) = 0;
virtual Operand* sub(unsigned size, Operand* a, Operand* b) = 0;
virtual Operand* mul(unsigned size, Operand* a, Operand* b) = 0;
virtual Operand* div(unsigned size, Operand* a, Operand* b) = 0;
virtual Operand* rem(unsigned size, Operand* a, Operand* b) = 0;
virtual Operand* shl(unsigned size, Operand* a, Operand* b) = 0;
virtual Operand* shr(unsigned size, Operand* a, Operand* b) = 0;
virtual Operand* ushr(unsigned size, Operand* a, Operand* b) = 0;
virtual Operand* and_(unsigned size, Operand* a, Operand* b) = 0;
virtual Operand* or_(unsigned size, Operand* a, Operand* b) = 0;
virtual Operand* xor_(unsigned size, Operand* a, Operand* b) = 0;
virtual Operand* neg(unsigned size, Operand* a) = 0;
virtual void prologue() = 0;
virtual void reserve(unsigned size) = 0;
virtual void epilogue() = 0;
virtual void startLogicalIp(unsigned) = 0;
virtual unsigned codeSize() = 0;
virtual unsigned compile() = 0;
virtual unsigned poolSize() = 0;
virtual void writeTo(uint8_t*) = 0;
virtual void updateCall(void* returnAddress, void* newTarget) = 0;
virtual void writeTo(uint8_t* dst) = 0;
virtual void dispose() = 0;
};
Compiler*
makeCompiler(System* system, Allocator* allocator, Zone* zone,
void* indirectCaller);
makeCompiler(System* system, Assembler* assembler, Zone* zone);
} // namespace vm

View File

@ -29,7 +29,7 @@ const unsigned InitialTenuredFixieCeilingInBytes = 4 * 1024 * 1024;
const unsigned LowMemoryPaddingInBytes = 1024 * 1024;
const bool Verbose = false;
const bool Verbose = true;
const bool Verbose2 = false;
const bool Debug = false;
const bool DebugFixies = false;

1184
src/x86.cpp Normal file

File diff suppressed because it is too large Load Diff

View File

@ -67,69 +67,69 @@ public class Misc {
}
public static void main(String[] args) {
byte2 = 0;
expect(byte2 == 0);
// byte2 = 0;
// expect(byte2 == 0);
// expect(Long.valueOf(231L) == 231L);
// long x = 231;
// expect((x >> 32) == 0);
// expect((x >>> 32) == 0);
// expect((x << 32) == 992137445376L);
// long y = -231;
// expect((y >> 32) == 0xffffffffffffffffL);
// expect((y >>> 32) == 0xffffffffL);
// byte[] array = new byte[8];
// putLong(231, array, 0);
// expect((array[0] & 0xff) == 0);
// expect((array[1] & 0xff) == 0);
// expect((array[2] & 0xff) == 0);
// expect((array[3] & 0xff) == 0);
// expect((array[4] & 0xff) == 0);
// expect((array[5] & 0xff) == 0);
// expect((array[6] & 0xff) == 0);
// expect((array[7] & 0xff) == 231);
// java.nio.ByteBuffer buffer = java.nio.ByteBuffer.allocate(8);
// buffer.putLong(231);
// buffer.flip();
// expect(buffer.getLong() == 231);
// boolean v = Boolean.valueOf("true");
// ClassLoader.getSystemClassLoader().toString();
// int a = 2;
// int b = 2;
// int c = a + b;
Misc m = new Misc();
m.toString();
expect(Long.valueOf(231L) == 231L);
// String s = "hello";
// m.foo(s);
// m.bar(s);
// baz(s);
long x = 231;
expect((x >> 32) == 0);
expect((x >>> 32) == 0);
expect((x << 32) == 992137445376L);
// m.sync();
// syncStatic(false);
// try {
// syncStatic(true);
// } catch (RuntimeException e) {
// e.printStackTrace();
// }
long y = -231;
expect((y >> 32) == 0xffffffffffffffffL);
expect((y >>> 32) == 0xffffffffL);
// int d = alpha;
// beta = 42;
// alpha = 43;
// int e = beta;
// int f = alpha;
// m.gamma = 44;
byte[] array = new byte[8];
putLong(231, array, 0);
expect((array[0] & 0xff) == 0);
expect((array[1] & 0xff) == 0);
expect((array[2] & 0xff) == 0);
expect((array[3] & 0xff) == 0);
expect((array[4] & 0xff) == 0);
expect((array[5] & 0xff) == 0);
expect((array[6] & 0xff) == 0);
expect((array[7] & 0xff) == 231);
java.nio.ByteBuffer buffer = java.nio.ByteBuffer.allocate(8);
buffer.putLong(231);
buffer.flip();
expect(buffer.getLong() == 231);
boolean v = Boolean.valueOf("true");
ClassLoader.getSystemClassLoader().toString();
int a = 2;
int b = 2;
int c = a + b;
String s = "hello";
m.foo(s);
m.bar(s);
baz(s);
m.sync();
syncStatic(false);
try {
syncStatic(true);
} catch (RuntimeException e) {
e.printStackTrace();
}
int d = alpha;
beta = 42;
alpha = 43;
int e = beta;
int f = alpha;
m.gamma = 44;
expect(beta == 42);
expect(alpha == 43);
expect(m.gamma == 44);
// expect(beta == 42);
// expect(alpha == 43);
// expect(m.gamma == 44);
}
}