various fixes to get invokevirtual working

This commit is contained in:
Joel Dice 2008-03-10 16:37:21 -06:00
parent 0fe748c3a1
commit 9e2e614a15
4 changed files with 83 additions and 9 deletions

View File

@ -1439,8 +1439,9 @@ resultSize(MyThread* t, unsigned code)
bool
emptyMethod(MyThread* t, object method)
{
object code = methodCode(t, method);
return (codeLength(t, code) == 1 and codeBody(t, code, 0) == return_);
return ((methodFlags(t, method) & ACC_NATIVE) == 0)
and (codeLength(t, methodCode(t, method)) == 1)
and (codeBody(t, methodCode(t, method), 0) == return_);
}
void
@ -2475,7 +2476,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned ip)
(instance, 0, 0, 1, frame->trace(0, false))), offset, 0, 1),
0,
0,
frame->trace(0, true),
frame->trace(target, true),
rSize,
0);

View File

@ -485,7 +485,10 @@ class StackValue: public Value {
virtual OperandType type(Context* c) { abort(c); }
virtual RegisterValue* toRegister(Context* c) {
abort(c);
return MemoryValue
(c->assembler->base(), (c->stackOffset + stack->index) * BytesPerWord,
NoRegister, 0, 0)
.toRegister(c);
}
virtual Stack* stackPosition(Context*) { return stack; }
@ -636,7 +639,7 @@ syncStack(Context* c, Stack* start, unsigned count)
for (unsigned i = 0; i < count; ++i) {
Stack* s = segment[i];
s->operand->value->release(c, s->operand);
apply(c, Push, s->size, s->operand->value);
apply(c, Push, s->size * BytesPerWord, s->operand->value);
s->operand->value = stackValue(c, s);
}
}
@ -1105,17 +1108,24 @@ class CombineEvent: public Event {
if (a->target == 0) a->target = target(c, a);
if (b->target == 0) b->target = target(c, b);
a->value->release(c, a);
b->value->release(c, b);
b->value->acquire(c, stack, result);
if (b->target == 0) {
b->target = freeRegister(c, BytesPerWord);
}
if (a->target and not a->target->equals(c, a->value)) {
a->value->release(c, a);
apply(c, Move, size, a->value, a->target);
a->value = a->target;
}
if (b->target and not b->target->equals(c, b->value)) {
b->value->release(c, b);
apply(c, Move, size, b->value, b->target);
b->value = b->target;
}
b->value->acquire(c, stack, result);
apply(c, type, size, a->value, b->value);
result->value = b->value;

View File

@ -314,6 +314,14 @@ callR(Context* c, unsigned size UNUSED, Assembler::Register* a)
c->code.append(0xd0 | a->low);
}
void
callM(Context* c, unsigned size UNUSED, Assembler::Memory* a)
{
assert(c, size == BytesPerWord);
encode(c, 0xff, 2, a, false);
}
void
jumpR(Context* c, unsigned size UNUSED, Assembler::Register* a)
{
@ -336,6 +344,21 @@ pushR(Context* c, unsigned size, Assembler::Register* a)
}
}
void
pushM(Context* c, unsigned size, Assembler::Memory* a)
{
if (BytesPerWord == 4 and size == 8) {
Assembler::Memory ah(a->base, a->offset + 4, a->index, a->scale);
pushM(c, 4, &ah);
pushM(c, 4, a);
} else {
assert(c, BytesPerWord == 4 or size == 8);
encode(c, 0xff, 6, a, false);
}
}
void
move4To8RR(Context* c, unsigned size, Assembler::Register* a,
Assembler::Register* b);
@ -549,6 +572,42 @@ addRM(Context* c, unsigned size UNUSED, Assembler::Register* a,
encode(c, 0x01, a->low, b, true);
}
void
andCR(Context* c, unsigned size UNUSED, Assembler::Constant* a,
Assembler::Register* b)
{
assert(c, BytesPerWord == 8 or size == 4);
rex(c);
if (isInt8(a->value->value())) {
c->code.append(0x83);
c->code.append(0xe0 | b->low);
c->code.append(a->value->value());
} else {
assert(c, isInt32(a->value->value()));
c->code.append(0x81);
c->code.append(0xe0 | b->low);
c->code.append(a->value->value());
}
}
void
andCM(Context* c, unsigned size UNUSED, Assembler::Constant* a,
Assembler::Memory* b)
{
assert(c, BytesPerWord == 8 or size == 4);
encode(c, isInt8(a->value->value()) ? 0x83 : 0x81, 4, b, true);
if (isInt8(a->value->value())) {
c->code.append(a->value->value());
} else if (isInt32(a->value->value())) {
c->code.append4(a->value->value());
} else {
abort(c);
}
}
void
populateTables()
{
@ -557,8 +616,10 @@ populateTables()
UnaryOperations[INDEX1(Call, Constant)] = CAST1(callC);
UnaryOperations[INDEX1(AlignedCall, Constant)] = CAST1(alignedCallC);
UnaryOperations[INDEX1(Call, Register)] = CAST1(callR);
UnaryOperations[INDEX1(Call, Memory)] = CAST1(callM);
UnaryOperations[INDEX1(Jump, Register)] = CAST1(jumpR);
UnaryOperations[INDEX1(Push, Register)] = CAST1(pushR);
UnaryOperations[INDEX1(Push, Memory)] = CAST1(pushM);
UnaryOperations[INDEX1(Pop, Register)] = CAST1(popR);
UnaryOperations[INDEX1(Pop, Memory)] = CAST1(popM);
@ -574,6 +635,8 @@ populateTables()
BinaryOperations[INDEX2(Add, Constant, Register)] = CAST2(addCR);
BinaryOperations[INDEX2(Add, Register, Register)] = CAST2(addRR);
BinaryOperations[INDEX2(Add, Register, Memory)] = CAST2(addRM);
BinaryOperations[INDEX2(And, Constant, Register)] = CAST2(andCR);
BinaryOperations[INDEX2(And, Constant, Memory)] = CAST2(andCM);
}
class MyAssembler: public Assembler {

View File

@ -91,7 +91,7 @@ public class Misc {
// int c = a + b;
Misc m = new Misc();
// m.toString();
m.toString();
// String s = "hello";
// m.foo(s);