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

This commit is contained in:
Joel Dice 2008-06-02 07:01:41 -06:00
commit 31c2ea7277
11 changed files with 6700 additions and 4118 deletions

View File

@ -43,7 +43,7 @@ ar = ar
ranlib = ranlib
objcopy = objcopy
vg = nice valgrind --num-callers=32 --db-attach=yes --freelist-vol=100000000
vg += --leak-check=full
vg += --leak-check=full --suppressions=valgrind.supp
db = gdb --args
javac = javac
jar = jar
@ -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

190
src/assembler.h Normal file
View File

@ -0,0 +1,190 @@
#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,
Swap,
Compare,
Add,
Subtract,
Multiply,
Divide,
Remainder,
ShiftLeft,
ShiftRight,
UnsignedShiftRight,
And,
Or,
Xor
};
const unsigned BinaryOperationCount = Xor + 1;
enum OperandType {
ConstantOperand,
AddressOperand,
RegisterOperand,
MemoryOperand
};
const unsigned OperandTypeCount = MemoryOperand + 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
(uint32_t mask = ~static_cast<uint32_t>(0)) = 0;
virtual void releaseTemporary(int r) = 0;
virtual void save(int r) = 0;
virtual void restore(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 void plan(UnaryOperation op, unsigned size, uint8_t* typeMask,
uint64_t* registerMask, bool* thunk) = 0;
virtual void plan(BinaryOperation op, unsigned size, uint8_t* aTypeMask,
uint64_t* aRegisterMask, uint8_t* bTypeMask,
uint64_t* bRegisterMask, bool* thunk) = 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,46 @@
#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 {
class Client {
public:
virtual ~TraceHandler() { }
virtual ~Client() { }
virtual void handleTrace(Promise* address) = 0;
virtual intptr_t getThunk(UnaryOperation op, unsigned size) = 0;
virtual intptr_t getThunk(BinaryOperation op, unsigned size) = 0;
};
static const unsigned Aligned = 1 << 0;
static const unsigned NoReturn = 1 << 1;
class Operand { };
virtual ~Compiler() { }
virtual void pushState() = 0;
virtual void popState() = 0;
virtual void saveStack() = 0;
virtual void resetStack() = 0;
virtual void init(unsigned logicalCodeSize, unsigned parameterFootprint,
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,104 +61,70 @@ 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, unsigned argumentCount, ...) = 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) = 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,
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 storeLocal(unsigned size, Operand* src, unsigned index) = 0;
virtual Operand* loadLocal(unsigned size, unsigned index) = 0;
virtual void prologue() = 0;
virtual void reserve(unsigned size) = 0;
virtual void epilogue() = 0;
virtual void checkBounds(Operand* object, unsigned lengthOffset,
Operand* index, intptr_t handler) = 0;
virtual void startLogicalIp(unsigned) = 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 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 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,
Compiler::Client* client);
} // namespace vm

44
src/thunks.cpp Normal file
View File

@ -0,0 +1,44 @@
THUNK(tryInitClass)
THUNK(findInterfaceMethodFromInstance)
THUNK(compareDoublesG)
THUNK(compareDoublesL)
THUNK(compareFloatsG)
THUNK(compareFloatsL)
THUNK(addDouble)
THUNK(subtractDouble)
THUNK(multiplyDouble)
THUNK(divideDouble)
THUNK(moduloDouble)
THUNK(negateDouble)
THUNK(doubleToFloat)
THUNK(doubleToInt)
THUNK(doubleToLong)
THUNK(addFloat)
THUNK(subtractFloat)
THUNK(multiplyFloat)
THUNK(divideFloat)
THUNK(moduloFloat)
THUNK(negateFloat)
THUNK(floatToDouble)
THUNK(floatToInt)
THUNK(floatToLong)
THUNK(intToDouble)
THUNK(intToFloat)
THUNK(longToDouble)
THUNK(longToFloat)
THUNK(divideLong)
THUNK(moduloLong)
THUNK(makeBlankObjectArray)
THUNK(makeBlankArray)
THUNK(lookUpAddress)
THUNK(setMaybeNull)
THUNK(acquireMonitorForObject)
THUNK(releaseMonitorForObject)
THUNK(makeMultidimensionalArray)
THUNK(throw_)
THUNK(checkCast)
THUNK(instanceOf)
THUNK(makeNewWeakReference)
THUNK(makeNew)
THUNK(set)
THUNK(gcIfNecessary)

2105
src/x86.cpp Normal file

File diff suppressed because it is too large Load Diff

View File

@ -32,5 +32,18 @@ public class Floats {
expect(divide(0.5d, 0.5d) == 1.0d);
expect(subtract(0.5d, 0.5d) == 0.0d);
double d = 1d;
expect(((int) d) == 1);
expect(Math.round(0.4f) == 0);
expect(Math.round(0.5f) == 1);
expect(Math.round(1.0f) == 1);
expect(Math.round(1.9f) == 2);
expect(Math.round(0.4d) == 0);
expect(Math.round(0.5d) == 1);
expect(Math.round(1.0d) == 1);
expect(Math.round(1.9d) == 2);
}
}

View File

@ -66,34 +66,156 @@ public class Misc {
return super.toString();
}
private static int zap() {
return 42;
}
private static int zip() {
return 5 + zap();
}
private static int zup() {
return zap() + 5;
}
private static class Foo {
public int a;
public int b;
public int c;
public int[] array;
}
private static int bar(int a, int b, int c) {
return a + b + c;
}
private static long roundUp(long a, long b) {
a += b - 1L;
return a - (a % b);
}
public static void main(String[] args) {
expect(roundUp(156, 2) == 156);
{ Foo foo = new Foo();
int x = foo.a + foo.b + foo.c;
bar(foo.a, foo.b, foo.c);
}
{ int get_buffer = 2144642881;
int bits_left = 30;
int l = 9;
int code = (((get_buffer >> (bits_left -= (l)))) & ((1<<(l))-1));
expect(code == 510);
}
{ int width = 8;
int height = 8;
int depth = 24;
int scanlinePad = 4;
int bytesPerLine = (((width * depth + 7) / 8) + (scanlinePad - 1))
/ scanlinePad * scanlinePad;
expect(bytesPerLine == 24);
}
{ int a = -5;
int b = 2;
expect(a >> b == -5 >> 2);
expect(a >>> b == -5 >>> 2);
expect(a << b == -5 << 2);
expect(a + b == -5 + 2);
expect(a - b == -5 - 2);
expect(a * b == -5 * 2);
expect(a / b == -5 / 2);
expect(a % b == -5 % 2);
expect((a & b) == (-5 & 2));
expect((a | b) == (-5 | 2));
expect((a ^ b) == (-5 ^ 2));
expect(-a == 5);
expect(~a == ~-5);
a = 5;
b = 2;
expect(a >> b == 5 >> 2);
expect(a >>> b == 5 >>> 2);
expect(a << b == 5 << 2);
expect(a + b == 5 + 2);
expect(a - b == 5 - 2);
expect(a * b == 5 * 2);
expect(a / b == 5 / 2);
expect(a % b == 5 % 2);
expect((a & b) == (5 & 2));
expect((a | b) == (5 | 2));
expect((a ^ b) == (5 ^ 2));
expect(-a == -5);
expect(~a == ~5);
}
{ long a = -5;
long b = 2;
expect(a >> b == -5L >> 2);
expect(a >>> b == -5L >>> 2);
expect(a << b == -5L << 2);
expect(a + b == -5L + 2L);
expect(a - b == -5L - 2L);
expect(a * b == -5L * 2L);
expect(a / b == -5L / 2L);
expect(a % b == -5L % 2L);
expect((a & b) == (-5L & 2L));
expect((a | b) == (-5L | 2L));
expect((a ^ b) == (-5L ^ 2L));
expect(-a == 5L);
expect(~a == ~-5L);
a = 5;
b = 2;
expect(a >> b == 5L >> 2);
expect(a >>> b == 5L >>> 2);
expect(a << b == 5L << 2);
expect(a + b == 5L + 2L);
expect(a - b == 5L - 2L);
expect(a * b == 5L * 2L);
expect(a / b == 5L / 2L);
expect(a % b == 5L % 2L);
expect((a & b) == (5L & 2L));
expect((a | b) == (5L | 2L));
expect((a ^ b) == (5L ^ 2L));
expect(-a == -5L);
expect(~a == ~5L);
}
byte2 = 0;
expect(byte2 == 0);
Misc m = new Misc();
m.toString();
expect(Long.valueOf(231L) == 231L);
long x = 231;
expect((x >> 32) == 0);
expect((x >>> 32) == 0);
expect((x << 32) == 992137445376L);
{ 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);
int shift = 32;
expect((x >> shift) == 0);
expect((x >>> shift) == 0);
expect((x << shift) == 992137445376L);
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);
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);
@ -104,32 +226,103 @@ public class Misc {
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 a = 2;
int b = 2;
int c = a + b;
}
int d = alpha;
beta = 42;
alpha = 43;
int e = beta;
int f = alpha;
m.gamma = 44;
{ Misc m = new Misc();
m.toString();
expect(beta == 42);
expect(alpha == 43);
expect(m.gamma == 44);
expect(m.time == 0xffffffffffffffffL);
long t = m.time;
expect(t == 0xffffffffffffffffL);
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(zip() == 47);
expect(zup() == 47);
{ int[] array = new int[0];
Exception exception = null;
try {
int x = array[0];
} catch (ArrayIndexOutOfBoundsException e) {
exception = e;
}
expect(exception != null);
}
{ int[] array = new int[3];
int i = 0;
array[i++] = 1;
array[i++] = 2;
array[i++] = 3;
expect(array[--i] == 3);
expect(array[--i] == 2);
expect(array[--i] == 1);
}
{ Object[][] array = new Object[1][1];
expect(array.length == 1);
expect(array[0].length == 1);
}
{
Object a = new Object();
Object b = new Object();
expect(a != b);
Object c = a;
Object d = b;
expect(c != d);
c = (c == a) ? b : a;
d = (d == a) ? b : a;
expect(c != d);
}
{ Foo foo = new Foo();
foo.array = new int[3];
foo.a = (foo.a + 1) % foo.array.length;
}
{ int j = 0;
byte[] decodeTable = new byte[256];
for (int i = 'A'; i <= 'Z'; ++i) decodeTable[i] = (byte) j++;
for (int i = 'a'; i <= 'z'; ++i) decodeTable[i] = (byte) j++;
for (int i = '0'; i <= '9'; ++i) decodeTable[i] = (byte) j++;
decodeTable['+'] = (byte) j++;
decodeTable['/'] = (byte) j++;
decodeTable['='] = 0;
expect(decodeTable['a'] != 0);
}
}
}

View File

@ -5,6 +5,12 @@
obj:/lib/ld-2.3.6.so
}
{
<insert a suppression name here>
Memcheck:Cond
obj:/lib/ld-2.6.so
}
{
<insert a suppression name here>
Memcheck:Addr4