re-enable tests in Misc and get them working

This commit is contained in:
Joel Dice
2008-04-28 09:53:48 -06:00
parent 5e45475f36
commit 1b5f14d847
5 changed files with 261 additions and 91 deletions

View File

@ -552,12 +552,18 @@ class Frame {
} }
~Frame() { ~Frame() {
if (level > 1 and t->exception == 0) { if (t->exception == 0) {
if (level > 0) {
c->saveStack();
c->popState(); c->popState();
c->resetStack();
}
if (level > 1) {
context->eventLog.append(PopEvent); context->eventLog.append(PopEvent);
} }
} }
}
Compiler::Operand* append(object o) { Compiler::Operand* append(object o) {
Promise* p = c->poolAppend(0); Promise* p = c->poolAppend(0);
@ -2913,17 +2919,25 @@ compile(MyThread* t, Frame* initialFrame, unsigned ip,
Compiler::Operand* b = frame->popLong(); Compiler::Operand* b = frame->popLong();
c->cmp(8, a, b); c->cmp(8, a, b);
c->jl(less); c->jl(less);
c->pushState();
c->jg(greater); c->jg(greater);
c->pushState();
c->push(4, c->constant(0)); c->push(4, c->constant(0));
c->jmp(next); c->jmp(next);
c->popState();
c->mark(less); c->mark(less);
c->push(4, c->constant(-1)); c->push(4, c->constant(-1));
c->jmp(next); c->jmp(next);
c->popState();
c->mark(greater); c->mark(greater);
c->push(4, c->constant(1)); c->push(4, c->constant(1));
c->mark(next); c->mark(next);
@ -3085,13 +3099,13 @@ compile(MyThread* t, Frame* initialFrame, unsigned ip,
} return; } return;
case lshl: { case lshl: {
Compiler::Operand* a = frame->popLong(); Compiler::Operand* a = frame->popInt();
Compiler::Operand* b = frame->popLong(); Compiler::Operand* b = frame->popLong();
frame->pushLong(c->shl(8, a, b)); frame->pushLong(c->shl(8, a, b));
} break; } break;
case lshr: { case lshr: {
Compiler::Operand* a = frame->popLong(); Compiler::Operand* a = frame->popInt();
Compiler::Operand* b = frame->popLong(); Compiler::Operand* b = frame->popLong();
frame->pushLong(c->shr(8, a, b)); frame->pushLong(c->shr(8, a, b));
} break; } break;
@ -3128,7 +3142,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned ip,
} break; } break;
case lushr: { case lushr: {
Compiler::Operand* a = frame->popLong(); Compiler::Operand* a = frame->popInt();
Compiler::Operand* b = frame->popLong(); Compiler::Operand* b = frame->popLong();
frame->pushLong(c->ushr(8, a, b)); frame->pushLong(c->ushr(8, a, b));
} break; } break;
@ -3861,11 +3875,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)),
"java/lang/Class") == 0 and "java/nio/ByteBuffer") == 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)),
"replace") == 0) "checkPut") == 0)
{ {
asm("int3"); asm("int3");
} }

View File

@ -556,11 +556,11 @@ increment(Context* c, int r)
void void
decrement(Context* c, int r) decrement(Context* c, int r)
{ {
assert(c, c->registers[r].refCount > 0);
assert(c, c->registers[r].refCount > 1 or (not c->registers[r].reserved));
if (DebugRegisters) { if (DebugRegisters) {
fprintf(stderr, "decrement %d to %d\n", r, c->registers[r].refCount - 1); fprintf(stderr, "decrement %d to %d\n", r, c->registers[r].refCount - 1);
} }
assert(c, c->registers[r].refCount > 0);
assert(c, c->registers[r].refCount > 1 or (not c->registers[r].reserved));
-- c->registers[r].refCount; -- c->registers[r].refCount;
} }
@ -1783,6 +1783,13 @@ count(Stack* s)
void void
pushState(Context* c) pushState(Context* c)
{ {
if (DebugAppend) {
unsigned count = 0; for (State* s = c->state; s; s = s->next) ++ count;
fprintf(stderr, "push at level %d\n", count);
count = 0; for (Stack* s = c->state->stack; s; s = s->next) ++ count;
fprintf(stderr, "stack count: %d\n", count);
}
c->state = new (c->zone->allocate(sizeof(State))) c->state = new (c->zone->allocate(sizeof(State)))
State(c->state, c->state->stack); State(c->state, c->state->stack);
} }
@ -1793,18 +1800,27 @@ saveStack(Context* c)
if (c->logicalIp >= 0 and not c->logicalCode[c->logicalIp].stackSaved) { if (c->logicalIp >= 0 and not c->logicalCode[c->logicalIp].stackSaved) {
c->logicalCode[c->logicalIp].stackSaved = true; c->logicalCode[c->logicalIp].stackSaved = true;
c->logicalCode[c->logicalIp].stack = c->state->stack; c->logicalCode[c->logicalIp].stack = c->state->stack;
if (DebugAppend) {
unsigned count = 0;
for (Stack* s = c->state->stack; s; s = s->next) ++ count;
fprintf(stderr, "stack count after ip %d: %d\n", c->logicalIp, count);
}
} }
} }
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->next, c->state->next->stack); State(c->state->next->next, c->state->next->stack);
resetStack(c); if (DebugAppend) {
unsigned count = 0; for (State* s = c->state; s; s = s->next) ++ count;
fprintf(stderr, "pop to level %d\n", count);
count = 0; for (Stack* s = c->state->stack; s; s = s->next) ++ count;
fprintf(stderr, "stack count: %d\n", count);
}
} }
Stack* Stack*
@ -1984,6 +2000,14 @@ class MyCompiler: public Compiler {
::popState(&c); ::popState(&c);
} }
virtual void saveStack() {
::saveStack(&c);
}
virtual void resetStack() {
::resetStack(&c);
}
virtual void init(unsigned logicalCodeLength, unsigned stackOffset) { virtual void init(unsigned logicalCodeLength, unsigned stackOffset) {
c.logicalCodeLength = logicalCodeLength; c.logicalCodeLength = logicalCodeLength;
c.stackOffset = stackOffset; c.stackOffset = stackOffset;
@ -2010,7 +2034,7 @@ class MyCompiler: public Compiler {
visit(&c, logicalIp); visit(&c, logicalIp);
saveStack(&c); ::saveStack(&c);
c.logicalIp = logicalIp; c.logicalIp = logicalIp;
} }
@ -2110,7 +2134,7 @@ class MyCompiler: public Compiler {
virtual void mark(Operand* label) { virtual void mark(Operand* label) {
appendStackSync(&c); appendStackSync(&c);
resetStack(&c); ::resetStack(&c);
for (Site* s = static_cast<Value*>(label)->sites; s; s = s->next) { for (Site* s = static_cast<Value*>(label)->sites; s; s = s->next) {
if (s->type(&c) == ConstantOperand) { if (s->type(&c) == ConstantOperand) {

View File

@ -28,6 +28,8 @@ class Compiler {
virtual void pushState() = 0; virtual void pushState() = 0;
virtual void popState() = 0; virtual void popState() = 0;
virtual void saveStack() = 0;
virtual void resetStack() = 0;
virtual void init(unsigned logicalCodeSize, unsigned localFootprint) = 0; virtual void init(unsigned logicalCodeSize, unsigned localFootprint) = 0;

View File

@ -575,14 +575,45 @@ moveCR(Context* c, unsigned size UNUSED, Assembler::Constant* a,
} }
void void
moveCM(Context* c, unsigned size UNUSED, Assembler::Constant* a, moveCM(Context* c, unsigned size, Assembler::Constant* a,
Assembler::Memory* b) Assembler::Memory* b)
{ {
assert(c, isInt32(a->value->value())); // todo int64_t v = a->value->value();
assert(c, BytesPerWord == 8 or size == 4); // todo
if (BytesPerWord == 4 and size == 8) {
ResolvedPromise high((v >> 32) & 0xFFFFFFFF);
Assembler::Constant ah(&high);
ResolvedPromise low(v & 0xFFFFFFFF);
Assembler::Constant al(&low);
Assembler::Memory bh(b->base, b->offset + 4, b->index, b->scale);
moveCM(c, 4, &al, b);
moveCM(c, 4, &ah, &bh);
} else if (BytesPerWord == 8 and size == 4) {
encode(c, 0xc7, 0, b, false);
c->code.append4(a->value->value());
} else {
switch (size) {
case 1:
encode(c, 0xc6, 0, b, false);
c->code.append(a->value->value());
break;
case 2:
encode2(c, 0x66c7, 0, b, false);
c->code.append2(a->value->value());
break;
case BytesPerWord:
encode(c, 0xc7, 0, b, true); encode(c, 0xc7, 0, b, true);
c->code.append4(a->value->value()); c->code.append4(a->value->value());
break;
default: abort(c);
}
}
} }
void void
@ -1103,7 +1134,7 @@ andCR(Context* c, unsigned size UNUSED, Assembler::Constant* a,
} else { } else {
c->code.append(0x81); c->code.append(0x81);
c->code.append(0xe0 | b->low); c->code.append(0xe0 | b->low);
c->code.append(v); c->code.append4(v);
} }
} else { } else {
Assembler::Register tmp(c->client->acquireTemporary()); Assembler::Register tmp(c->client->acquireTemporary());
@ -1131,6 +1162,17 @@ andCM(Context* c, unsigned size UNUSED, Assembler::Constant* a,
} }
} }
void
orRR(Context* c, unsigned size UNUSED, Assembler::Register* a,
Assembler::Register* b)
{
assert(c, BytesPerWord == 8 or size == 4); // todo
rex(c);
c->code.append(0x09);
c->code.append(0xc0 | (a->low << 3) | b->low);
}
void void
xorRR(Context* c, unsigned size UNUSED, Assembler::Register* a, xorRR(Context* c, unsigned size UNUSED, Assembler::Register* a,
Assembler::Register* b) Assembler::Register* b)
@ -1171,20 +1213,31 @@ xorCR(Context* c, unsigned size UNUSED, Assembler::Constant* a,
} }
void void
shiftLeftCR(Context* c, unsigned size UNUSED, Assembler::Constant* a, shift(Context* c, int type, Assembler::Register* a, Assembler::Register* b) {
Assembler::Register* b) if (a->low == rcx) {
{ rex(c);
assert(c, BytesPerWord == 8 or size == 4); c->code.append(0xd3);
c->code.append(type | b->low);
} else {
Assembler::Register cx(c->client->acquireTemporary(rcx));
moveRR(c, BytesPerWord, a, &cx);
shift(c, type, &cx, b);
c->client->releaseTemporary(cx.low);
}
}
void
shift(Context* c, int type, Assembler::Constant* a, Assembler::Register* b)
{
int64_t v = a->value->value(); int64_t v = a->value->value();
rex(c); rex(c);
if (v == 1) { if (v == 1) {
c->code.append(0xd1); c->code.append(0xd1);
c->code.append(0xe0 | b->low); c->code.append(type | b->low);
} else if (isInt8(v)) { } else if (isInt8(v)) {
c->code.append(0xc1); c->code.append(0xc1);
c->code.append(0xe0 | b->low); c->code.append(type | b->low);
c->code.append(v); c->code.append(v);
} else { } else {
abort(c); abort(c);
@ -1192,25 +1245,57 @@ shiftLeftCR(Context* c, unsigned size UNUSED, Assembler::Constant* a,
} }
void void
compareCR(Context* c, unsigned size UNUSED, Assembler::Constant* a, shiftLeftRR(Context* c, unsigned size UNUSED, Assembler::Register* a,
Assembler::Register* b) Assembler::Register* b)
{ {
assert(c, BytesPerWord == 8 or size == 4); assert(c, BytesPerWord == 8 or size == 4);
int64_t v = a->value->value(); shift(c, 0xe0, a, b);
if (size == 8) rex(c);
if (isInt8(v)) {
c->code.append(0x83);
c->code.append(0xf8 | b->low);
c->code.append(v);
} else if (isInt32(v)) {
c->code.append(0x81);
c->code.append(0xf8 | b->low);
c->code.append4(v);
} else {
abort(c);
} }
void
shiftLeftCR(Context* c, unsigned size UNUSED, Assembler::Constant* a,
Assembler::Register* b)
{
assert(c, BytesPerWord == 8 or size == 4);
shift(c, 0xe0, a, b);
}
void
shiftRightRR(Context* c, unsigned size UNUSED, Assembler::Register* a,
Assembler::Register* b)
{
assert(c, BytesPerWord == 8 or size == 4);
shift(c, 0xf8, a, b);
}
void
shiftRightCR(Context* c, unsigned size UNUSED, Assembler::Constant* a,
Assembler::Register* b)
{
assert(c, BytesPerWord == 8 or size == 4);
shift(c, 0xf8, a, b);
}
void
unsignedShiftRightRR(Context* c, unsigned size UNUSED, Assembler::Register* a,
Assembler::Register* b)
{
assert(c, BytesPerWord == 8 or size == 4);
shift(c, 0xe8, a, b);
}
void
unsignedShiftRightCR(Context* c, unsigned size UNUSED, Assembler::Constant* a,
Assembler::Register* b)
{
assert(c, BytesPerWord == 8 or size == 4);
shift(c, 0xe8, a, b);
} }
void void
@ -1237,6 +1322,33 @@ compareRR(Context* c, unsigned size UNUSED, Assembler::Register* a,
} }
} }
void
compareCR(Context* c, unsigned size UNUSED, Assembler::Constant* a,
Assembler::Register* b)
{
assert(c, BytesPerWord == 8 or size == 4);
int64_t v = a->value->value();
if (isInt32(v)) {
if (size == 8) rex(c);
if (isInt8(v)) {
c->code.append(0x83);
c->code.append(0xf8 | b->low);
c->code.append(v);
} else {
c->code.append(0x81);
c->code.append(0xf8 | b->low);
c->code.append4(v);
}
} else {
Assembler::Register tmp(c->client->acquireTemporary());
moveCR(c, size, a, &tmp);
compareRR(c, size, &tmp, b);
c->client->releaseTemporary(tmp.low);
}
}
void void
compareCM(Context* c, unsigned size UNUSED, Assembler::Constant* a, compareCM(Context* c, unsigned size UNUSED, Assembler::Constant* a,
Assembler::Memory* b) Assembler::Memory* b)
@ -1356,11 +1468,24 @@ populateTables()
BinaryOperations[INDEX2(And, Constant, Register)] = CAST2(andCR); BinaryOperations[INDEX2(And, Constant, Register)] = CAST2(andCR);
BinaryOperations[INDEX2(And, Constant, Memory)] = CAST2(andCM); BinaryOperations[INDEX2(And, Constant, Memory)] = CAST2(andCM);
BinaryOperations[INDEX2(Or, Register, Register)] = CAST2(orRR);
BinaryOperations[INDEX2(Xor, Register, Register)] = CAST2(xorRR); BinaryOperations[INDEX2(Xor, Register, Register)] = CAST2(xorRR);
BinaryOperations[INDEX2(Xor, Constant, Register)] = CAST2(xorCR); BinaryOperations[INDEX2(Xor, Constant, Register)] = CAST2(xorCR);
BinaryOperations[INDEX2(ShiftLeft, Register, Register)] = CAST2(shiftLeftRR);
BinaryOperations[INDEX2(ShiftLeft, Constant, Register)] = CAST2(shiftLeftCR); BinaryOperations[INDEX2(ShiftLeft, Constant, Register)] = CAST2(shiftLeftCR);
BinaryOperations[INDEX2(ShiftRight, Register, Register)]
= CAST2(shiftRightRR);
BinaryOperations[INDEX2(ShiftRight, Constant, Register)]
= CAST2(shiftRightCR);
BinaryOperations[INDEX2(UnsignedShiftRight, Register, Register)]
= CAST2(unsignedShiftRightRR);
BinaryOperations[INDEX2(UnsignedShiftRight, Constant, Register)]
= CAST2(unsignedShiftRightCR);
BinaryOperations[INDEX2(Subtract, Constant, Register)] = CAST2(subtractCR); BinaryOperations[INDEX2(Subtract, Constant, Register)] = CAST2(subtractCR);
BinaryOperations[INDEX2(Subtract, Register, Register)] = CAST2(subtractRR); BinaryOperations[INDEX2(Subtract, Register, Register)] = CAST2(subtractRR);

View File

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