mirror of
https://github.com/corda/corda.git
synced 2025-01-23 04:48:09 +00:00
bugfixes; enums test now succeeds
This commit is contained in:
parent
8ebff705d6
commit
d6c3b2327f
@ -3436,8 +3436,8 @@ compile(MyThread* t, Frame* initialFrame, unsigned ip,
|
|||||||
c->cmp(4, c->constant(top), key);
|
c->cmp(4, c->constant(top), key);
|
||||||
c->jg(defaultCase);
|
c->jg(defaultCase);
|
||||||
|
|
||||||
c->sub(4, c->constant(bottom), key);
|
c->jmp(c->memory(start, 0, c->sub(4, c->constant(bottom), key),
|
||||||
c->jmp(c->memory(start, 0, key, BytesPerWord));
|
BytesPerWord));
|
||||||
|
|
||||||
c->mark(defaultCase);
|
c->mark(defaultCase);
|
||||||
c->jmp(frame->machineIp(defaultIp));
|
c->jmp(frame->machineIp(defaultIp));
|
||||||
@ -3870,11 +3870,11 @@ finish(MyThread* t, Context* context)
|
|||||||
strcmp
|
strcmp
|
||||||
(reinterpret_cast<const char*>
|
(reinterpret_cast<const char*>
|
||||||
(&byteArrayBody(t, className(t, methodClass(t, context->method)), 0)),
|
(&byteArrayBody(t, className(t, methodClass(t, context->method)), 0)),
|
||||||
"Enums$Suit") == 0 and
|
"Enums") == 0 and
|
||||||
strcmp
|
strcmp
|
||||||
(reinterpret_cast<const char*>
|
(reinterpret_cast<const char*>
|
||||||
(&byteArrayBody(t, methodName(t, context->method), 0)),
|
(&byteArrayBody(t, methodName(t, context->method), 0)),
|
||||||
"<clinit>") == 0)
|
"main") == 0)
|
||||||
{
|
{
|
||||||
asm("int3");
|
asm("int3");
|
||||||
}
|
}
|
||||||
|
109
src/compiler.cpp
109
src/compiler.cpp
@ -89,7 +89,10 @@ class LogicalInstruction {
|
|||||||
public:
|
public:
|
||||||
Event* firstEvent;
|
Event* firstEvent;
|
||||||
Event* lastEvent;
|
Event* lastEvent;
|
||||||
|
LogicalInstruction* immediatePredecessor;
|
||||||
|
Stack* stack;
|
||||||
unsigned machineOffset;
|
unsigned machineOffset;
|
||||||
|
bool stackSaved;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Register {
|
class Register {
|
||||||
@ -138,8 +141,8 @@ class Read {
|
|||||||
|
|
||||||
class Value: public Compiler::Operand {
|
class Value: public Compiler::Operand {
|
||||||
public:
|
public:
|
||||||
Value(Site* site, Site* target):
|
Value(Site* site):
|
||||||
reads(0), lastRead(0), sites(site), source(0), target(target)
|
reads(0), lastRead(0), sites(site), source(0), target(site)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
Read* reads;
|
Read* reads;
|
||||||
@ -315,13 +318,14 @@ class Event {
|
|||||||
i->lastEvent = this;
|
i->lastEvent = this;
|
||||||
|
|
||||||
if (c->stackReset) {
|
if (c->stackReset) {
|
||||||
|
// fprintf(stderr, "stack reset\n");
|
||||||
c->stackReset = false;
|
c->stackReset = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Event(Context*, Event* previous, Event* next):
|
Event(Context*, unsigned sequence, Stack* stack):
|
||||||
next(0), stack(next->stack), promises(0), reads(0),
|
next(0), stack(stack), promises(0), reads(0),
|
||||||
sequence(previous->sequence), stackReset(false)
|
sequence(sequence), stackReset(false)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
virtual ~Event() { }
|
virtual ~Event() { }
|
||||||
@ -330,7 +334,7 @@ class Event {
|
|||||||
|
|
||||||
virtual void compile(Context* c) = 0;
|
virtual void compile(Context* c) = 0;
|
||||||
|
|
||||||
virtual bool needStackSync() { return true; };
|
virtual bool isBranch() { return false; };
|
||||||
|
|
||||||
Event* next;
|
Event* next;
|
||||||
Stack* stack;
|
Stack* stack;
|
||||||
@ -528,7 +532,7 @@ void
|
|||||||
increment(Context* c, int r)
|
increment(Context* c, int r)
|
||||||
{
|
{
|
||||||
if (DebugRegisters) {
|
if (DebugRegisters) {
|
||||||
fprintf(stderr, "increment %d\n", r);
|
fprintf(stderr, "increment %d to %d\n", r, c->registers[r].refCount + 1);
|
||||||
}
|
}
|
||||||
++ c->registers[r].refCount;
|
++ c->registers[r].refCount;
|
||||||
}
|
}
|
||||||
@ -539,7 +543,7 @@ decrement(Context* c, int r)
|
|||||||
assert(c, c->registers[r].refCount > 0);
|
assert(c, c->registers[r].refCount > 0);
|
||||||
assert(c, c->registers[r].refCount > 1 or (not c->registers[r].reserved));
|
assert(c, c->registers[r].refCount > 1 or (not c->registers[r].reserved));
|
||||||
if (DebugRegisters) {
|
if (DebugRegisters) {
|
||||||
fprintf(stderr, "decrement %d\n", r);
|
fprintf(stderr, "decrement %d to %d\n", r, c->registers[r].refCount - 1);
|
||||||
}
|
}
|
||||||
-- c->registers[r].refCount;
|
-- c->registers[r].refCount;
|
||||||
}
|
}
|
||||||
@ -879,7 +883,7 @@ apply(Context* c, BinaryOperation op, unsigned size, Site* a, Site* b)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
insertRead(Context* c, Event* thisEvent, Event* previousEvent, Value* v,
|
insertRead(Context* c, Event* thisEvent, int sequence, Value* v,
|
||||||
unsigned size, Site* target)
|
unsigned size, Site* target)
|
||||||
{
|
{
|
||||||
Read* r = new (c->zone->allocate(sizeof(Read)))
|
Read* r = new (c->zone->allocate(sizeof(Read)))
|
||||||
@ -888,9 +892,9 @@ insertRead(Context* c, Event* thisEvent, Event* previousEvent, Value* v,
|
|||||||
|
|
||||||
// fprintf(stderr, "add read %p to %p\n", r, v);
|
// fprintf(stderr, "add read %p to %p\n", r, v);
|
||||||
|
|
||||||
if (previousEvent) {
|
if (sequence >= 0) {
|
||||||
for (Read** p = &(v->reads); *p;) {
|
for (Read** p = &(v->reads); *p;) {
|
||||||
if ((*p)->event->sequence > previousEvent->sequence) {
|
if ((*p)->event->sequence > static_cast<unsigned>(sequence)) {
|
||||||
r->next = *p;
|
r->next = *p;
|
||||||
*p = r;
|
*p = r;
|
||||||
break;
|
break;
|
||||||
@ -913,7 +917,7 @@ insertRead(Context* c, Event* thisEvent, Event* previousEvent, Value* v,
|
|||||||
void
|
void
|
||||||
addRead(Context* c, Value* v, unsigned size, Site* target)
|
addRead(Context* c, Value* v, unsigned size, Site* target)
|
||||||
{
|
{
|
||||||
insertRead(c, c->logicalCode[c->logicalIp].lastEvent, 0, v, size, target);
|
insertRead(c, c->logicalCode[c->logicalIp].lastEvent, -1, v, size, target);
|
||||||
}
|
}
|
||||||
|
|
||||||
Site*
|
Site*
|
||||||
@ -1145,7 +1149,11 @@ class MoveEvent: public Event {
|
|||||||
|
|
||||||
nextRead(c, src);
|
nextRead(c, src);
|
||||||
|
|
||||||
if (dst->reads) addSite(c, stack, size, dst, target);
|
if (dst->reads) {
|
||||||
|
addSite(c, stack, size, dst, target);
|
||||||
|
} else {
|
||||||
|
removeSite(c, dst, target);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BinaryOperation type;
|
BinaryOperation type;
|
||||||
@ -1368,16 +1376,10 @@ stack(Context* c, Value* value, unsigned size, unsigned index, Stack* next)
|
|||||||
Stack(value, size, index, next);
|
Stack(value, size, index, next);
|
||||||
}
|
}
|
||||||
|
|
||||||
Value*
|
|
||||||
value(Context* c, Site* site, Site* target)
|
|
||||||
{
|
|
||||||
return new (c->zone->allocate(sizeof(Value))) Value(site, target);
|
|
||||||
}
|
|
||||||
|
|
||||||
Value*
|
Value*
|
||||||
value(Context* c, Site* site = 0)
|
value(Context* c, Site* site = 0)
|
||||||
{
|
{
|
||||||
return value(c, site, site);
|
return new (c->zone->allocate(sizeof(Value))) Value(site);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -1460,13 +1462,13 @@ class StackSyncEvent: public Event {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
StackSyncEvent(Context* c, Event* previous, Event* next):
|
StackSyncEvent(Context* c, unsigned sequence, Stack* stack):
|
||||||
Event(c, previous, next)
|
Event(c, sequence, stack)
|
||||||
{
|
{
|
||||||
unsigned i = 0;
|
unsigned i = 0;
|
||||||
for (Stack* s = stack; s; s = s->next) {
|
for (Stack* s = stack; s; s = s->next) {
|
||||||
s->syncSite = stackSyncSite(c, i, s->size);
|
s->syncSite = stackSyncSite(c, i, s->size);
|
||||||
insertRead(c, this, previous, s->value, s->size * BytesPerWord,
|
insertRead(c, this, sequence, s->value, s->size * BytesPerWord,
|
||||||
s->syncSite);
|
s->syncSite);
|
||||||
if (s->pushEvent) s->pushEvent->active = false;
|
if (s->pushEvent) s->pushEvent->active = false;
|
||||||
i += s->size;
|
i += s->size;
|
||||||
@ -1494,8 +1496,6 @@ class StackSyncEvent: public Event {
|
|||||||
nextRead(c, r->value);
|
nextRead(c, r->value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool needStackSync() { return false; };
|
|
||||||
};
|
};
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -1526,7 +1526,7 @@ class BranchEvent: public Event {
|
|||||||
nextRead(c, address);
|
nextRead(c, address);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool needStackSync() { return false; };
|
virtual bool isBranch() { return true; };
|
||||||
|
|
||||||
UnaryOperation type;
|
UnaryOperation type;
|
||||||
Value* address;
|
Value* address;
|
||||||
@ -1660,13 +1660,16 @@ compile(Context* c)
|
|||||||
|
|
||||||
for (Event* e = li->firstEvent; e; e = e->next) {
|
for (Event* e = li->firstEvent; e; e = e->next) {
|
||||||
if (e->stackReset) {
|
if (e->stackReset) {
|
||||||
|
// fprintf(stderr, "stack reset\n");
|
||||||
for (Stack* s = e->stack; s; s = s->next) {
|
for (Stack* s = e->stack; s; s = s->next) {
|
||||||
|
if (s->value->sites) {
|
||||||
assert(c, s->value->sites->next == 0);
|
assert(c, s->value->sites->next == 0);
|
||||||
if (s->value->reads) {
|
if (s->value->reads) {
|
||||||
s->value->sites->acquire(c, 0, 0, s->value);
|
s->value->sites->acquire(c, 0, 0, s->value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
e->prepare(c);
|
e->prepare(c);
|
||||||
|
|
||||||
@ -1702,9 +1705,20 @@ pushState(Context* c)
|
|||||||
State(c->state);
|
State(c->state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
saveStack(Context* c)
|
||||||
|
{
|
||||||
|
if (c->logicalIp >= 0 and not c->logicalCode[c->logicalIp].stackSaved) {
|
||||||
|
c->logicalCode[c->logicalIp].stackSaved = true;
|
||||||
|
c->logicalCode[c->logicalIp].stack = c->state->stack;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
popState(Context* c)
|
popState(Context* c)
|
||||||
{
|
{
|
||||||
|
saveStack(c);
|
||||||
|
|
||||||
c->state = new (c->zone->allocate(sizeof(State)))
|
c->state = new (c->zone->allocate(sizeof(State)))
|
||||||
State(c->state->next);
|
State(c->state->next);
|
||||||
|
|
||||||
@ -1744,19 +1758,11 @@ updateJunctions(Context* c)
|
|||||||
{
|
{
|
||||||
for (Junction* j = c->junctions; j; j = j->next) {
|
for (Junction* j = c->junctions; j; j = j->next) {
|
||||||
LogicalInstruction* i = c->logicalCode + j->logicalIp;
|
LogicalInstruction* i = c->logicalCode + j->logicalIp;
|
||||||
|
LogicalInstruction* p = i->immediatePredecessor;
|
||||||
|
|
||||||
for (int ip = j->logicalIp - 1; ip >= 0; --ip) {
|
|
||||||
LogicalInstruction* p = c->logicalCode + ip;
|
|
||||||
if (p->lastEvent) {
|
|
||||||
// fprintf(stderr, "update junction at %d, predecessor %d\n", j->logicalIp, ip);
|
|
||||||
if (p->lastEvent->needStackSync()) {
|
|
||||||
p->lastEvent = p->lastEvent->next
|
p->lastEvent = p->lastEvent->next
|
||||||
= new (c->zone->allocate(sizeof(StackSyncEvent)))
|
= new (c->zone->allocate(sizeof(StackSyncEvent)))
|
||||||
StackSyncEvent(c, p->lastEvent, i->firstEvent);
|
StackSyncEvent(c, p->lastEvent->sequence, p->stack);
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1812,6 +1818,18 @@ freeRegisterExcept(Context* c, int except, bool allowAcquired)
|
|||||||
abort(c);
|
abort(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
visit(Context* c, unsigned logicalIp)
|
||||||
|
{
|
||||||
|
assert(c, logicalIp < c->logicalCodeLength);
|
||||||
|
|
||||||
|
if (c->logicalIp >= 0 and (not c->stackReset)) {
|
||||||
|
assert(c, c->logicalCode[logicalIp].immediatePredecessor == 0);
|
||||||
|
c->logicalCode[logicalIp].immediatePredecessor
|
||||||
|
= c->logicalCode + c->logicalIp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
freeRegister(Context* c, bool allowAcquired)
|
freeRegister(Context* c, bool allowAcquired)
|
||||||
{
|
{
|
||||||
@ -1878,15 +1896,25 @@ class MyCompiler: public Compiler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
virtual void visitLogicalIp(unsigned logicalIp) {
|
virtual void visitLogicalIp(unsigned logicalIp) {
|
||||||
|
visit(&c, logicalIp);
|
||||||
|
|
||||||
c.stackReset = false;
|
c.stackReset = false;
|
||||||
|
|
||||||
|
if (c.logicalCode[logicalIp].immediatePredecessor) {
|
||||||
c.junctions = new (c.zone->allocate(sizeof(Junction)))
|
c.junctions = new (c.zone->allocate(sizeof(Junction)))
|
||||||
Junction(logicalIp, c.junctions);
|
Junction(logicalIp, c.junctions);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
virtual void startLogicalIp(unsigned logicalIp) {
|
virtual void startLogicalIp(unsigned logicalIp) {
|
||||||
if (DebugAppend) {
|
if (DebugAppend) {
|
||||||
fprintf(stderr, " -- ip: %d\n", logicalIp);
|
fprintf(stderr, " -- ip: %d\n", logicalIp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
visit(&c, logicalIp);
|
||||||
|
|
||||||
|
saveStack(&c);
|
||||||
|
|
||||||
c.logicalIp = logicalIp;
|
c.logicalIp = logicalIp;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1922,11 +1950,11 @@ class MyCompiler: public Compiler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
virtual Operand* promiseConstant(Promise* value) {
|
virtual Operand* promiseConstant(Promise* value) {
|
||||||
return ::value(&c, ::constantSite(&c, value), 0);
|
return ::value(&c, ::constantSite(&c, value));
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual Operand* address(Promise* address) {
|
virtual Operand* address(Promise* address) {
|
||||||
return value(&c, ::addressSite(&c, address), 0);
|
return value(&c, ::addressSite(&c, address));
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual Operand* memory(Operand* base,
|
virtual Operand* memory(Operand* base,
|
||||||
@ -1971,7 +1999,7 @@ class MyCompiler: public Compiler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
virtual Operand* label() {
|
virtual Operand* label() {
|
||||||
return value(&c, ::constantSite(&c, static_cast<Promise*>(0)), 0);
|
return value(&c, ::constantSite(&c, static_cast<Promise*>(0)));
|
||||||
}
|
}
|
||||||
|
|
||||||
Promise* machineIp() {
|
Promise* machineIp() {
|
||||||
@ -2242,8 +2270,9 @@ class MyCompiler: public Compiler {
|
|||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (ConstantPoolNode* n = c.firstConstant; n; n = n->next) {
|
for (ConstantPoolNode* n = c.firstConstant; n; n = n->next) {
|
||||||
*reinterpret_cast<intptr_t*>(dst + pad(c.assembler->length()) + (i++))
|
*reinterpret_cast<intptr_t*>(dst + pad(c.assembler->length()) + i)
|
||||||
= n->promise->value();
|
= n->promise->value();
|
||||||
|
i += BytesPerWord;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -358,6 +358,14 @@ jumpC(Context* c, unsigned size UNUSED, Assembler::Constant* a)
|
|||||||
unconditional(c, 0xe9, a);
|
unconditional(c, 0xe9, a);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
jumpM(Context* c, unsigned size UNUSED, Assembler::Memory* a)
|
||||||
|
{
|
||||||
|
assert(c, size == BytesPerWord);
|
||||||
|
|
||||||
|
encode(c, 0xff, 4, a, false);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
jumpIfEqualC(Context* c, unsigned size UNUSED, Assembler::Constant* a)
|
jumpIfEqualC(Context* c, unsigned size UNUSED, Assembler::Constant* a)
|
||||||
{
|
{
|
||||||
@ -997,6 +1005,7 @@ populateTables()
|
|||||||
|
|
||||||
UnaryOperations[INDEX1(Jump, Register)] = CAST1(jumpR);
|
UnaryOperations[INDEX1(Jump, Register)] = CAST1(jumpR);
|
||||||
UnaryOperations[INDEX1(Jump, Constant)] = CAST1(jumpC);
|
UnaryOperations[INDEX1(Jump, Constant)] = CAST1(jumpC);
|
||||||
|
UnaryOperations[INDEX1(Jump, Memory)] = CAST1(jumpM);
|
||||||
|
|
||||||
UnaryOperations[INDEX1(JumpIfEqual, Constant)] = CAST1(jumpIfEqualC);
|
UnaryOperations[INDEX1(JumpIfEqual, Constant)] = CAST1(jumpIfEqualC);
|
||||||
UnaryOperations[INDEX1(JumpIfNotEqual, Constant)] = CAST1(jumpIfNotEqualC);
|
UnaryOperations[INDEX1(JumpIfNotEqual, Constant)] = CAST1(jumpIfNotEqualC);
|
||||||
|
@ -10,13 +10,13 @@ public class Misc {
|
|||||||
private long time;
|
private long time;
|
||||||
|
|
||||||
public Misc() {
|
public Misc() {
|
||||||
expect(! boolean1);
|
// expect(! boolean1);
|
||||||
expect(! boolean2);
|
// expect(! boolean2);
|
||||||
|
|
||||||
time = 0xffffffffffffffffL;
|
// time = 0xffffffffffffffffL;
|
||||||
|
|
||||||
expect(! boolean1);
|
// expect(! boolean1);
|
||||||
expect(! boolean2);
|
// expect(! boolean2);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String foo(String s) {
|
private String foo(String s) {
|
||||||
@ -101,17 +101,17 @@ public class Misc {
|
|||||||
|
|
||||||
// ClassLoader.getSystemClassLoader().toString();
|
// ClassLoader.getSystemClassLoader().toString();
|
||||||
|
|
||||||
// int a = 2;
|
int a = 2;
|
||||||
// int b = 2;
|
int b = 2;
|
||||||
// int c = a + b;
|
int c = a + b;
|
||||||
|
|
||||||
Misc m = new Misc();
|
Misc m = new Misc();
|
||||||
m.toString();
|
m.toString();
|
||||||
|
|
||||||
// String s = "hello";
|
String s = "hello";
|
||||||
// m.foo(s);
|
m.foo(s);
|
||||||
// m.bar(s);
|
m.bar(s);
|
||||||
// baz(s);
|
baz(s);
|
||||||
|
|
||||||
// m.sync();
|
// m.sync();
|
||||||
// syncStatic(false);
|
// syncStatic(false);
|
||||||
|
Loading…
Reference in New Issue
Block a user