bugfixes and new instructions in compile.cpp

This commit is contained in:
Joel Dice
2007-10-16 19:21:35 -06:00
parent 29b5e81aed
commit 5fb1495f4d
2 changed files with 132 additions and 35 deletions

View File

@ -34,7 +34,7 @@ src = src
classpath = classpath classpath = classpath
test = test test = test
input = $(cls)/Tree.class input = $(cls)/Memory.class
cxx = g++ cxx = g++
cc = gcc cc = gcc
@ -65,9 +65,9 @@ ifeq ($(mode),stress-major)
cflags += -O0 -g3 -DVM_STRESS -DVM_STRESS_MAJOR cflags += -O0 -g3 -DVM_STRESS -DVM_STRESS_MAJOR
endif endif
ifeq ($(mode),fast) ifeq ($(mode),fast)
cflags += -g3 -O3 -DNDEBUG cflags += -O3 -DNDEBUG
#strip = strip strip = strip
#show-size = ls -l show-size = ls -l
endif endif
cpp-objects = $(foreach x,$(1),$(patsubst $(2)/%.cpp,$(bld)/%.o,$(x))) cpp-objects = $(foreach x,$(1),$(patsubst $(2)/%.cpp,$(bld)/%.o,$(x)))

View File

@ -389,17 +389,20 @@ class StackMapper {
++ sp; ++ sp;
break; break;
case DuplicateX1: case DuplicateX1: {
assert(t, sp + 1 <= mapSize()); assert(t, sp + 1 <= mapSize());
assert(t, sp - 2 >= localSize()); assert(t, sp - 2 >= localSize());
if (getBit(map, sp - 2)) { unsigned b2 = getBit(map, sp - 2);
unsigned b1 = getBit(map, sp - 1);
if (b2) {
markBit(map, sp - 1); markBit(map, sp - 1);
} else { } else {
clearBit(map, sp - 1); clearBit(map, sp - 1);
} }
if (getBit(map, sp - 1)) { if (b1) {
markBit(map, sp - 2); markBit(map, sp - 2);
markBit(map, sp); markBit(map, sp);
} else { } else {
@ -407,25 +410,29 @@ class StackMapper {
} }
++ sp; ++ sp;
break; } break;
case DuplicateX2: case DuplicateX2: {
assert(t, sp + 1 <= mapSize()); assert(t, sp + 1 <= mapSize());
assert(t, sp - 3 >= localSize()); assert(t, sp - 3 >= localSize());
if (getBit(map, sp - 3)) { unsigned b3 = getBit(map, sp - 3);
unsigned b2 = getBit(map, sp - 2);
unsigned b1 = getBit(map, sp - 1);
if (b3) {
markBit(map, sp - 2); markBit(map, sp - 2);
} else { } else {
clearBit(map, sp - 2); clearBit(map, sp - 2);
} }
if (getBit(map, sp - 2)) { if (b2) {
markBit(map, sp - 1); markBit(map, sp - 1);
} else { } else {
clearBit(map, sp - 1); clearBit(map, sp - 1);
} }
if (getBit(map, sp - 1)) { if (b1) {
markBit(map, sp - 3); markBit(map, sp - 3);
markBit(map, sp); markBit(map, sp);
} else { } else {
@ -433,41 +440,48 @@ class StackMapper {
} }
++ sp; ++ sp;
break; } break;
case Duplicate2: case Duplicate2: {
assert(t, sp + 2 <= mapSize()); assert(t, sp + 2 <= mapSize());
assert(t, sp - 2 >= localSize()); assert(t, sp - 2 >= localSize());
if (getBit(map, sp - 2)) { unsigned b2 = getBit(map, sp - 2);
unsigned b1 = getBit(map, sp - 1);
if (b2) {
markBit(map, sp); markBit(map, sp);
} }
if (getBit(map, sp - 1)) { if (b1) {
markBit(map, sp + 1); markBit(map, sp + 1);
} }
sp += 2; sp += 2;
break; } break;
case Duplicate2X1: case Duplicate2X1: {
assert(t, sp + 2 <= mapSize()); assert(t, sp + 2 <= mapSize());
assert(t, sp - 3 >= localSize()); assert(t, sp - 3 >= localSize());
if (getBit(map, sp - 3)) { unsigned b3 = getBit(map, sp - 3);
unsigned b2 = getBit(map, sp - 2);
unsigned b1 = getBit(map, sp - 1);
if (b3) {
markBit(map, sp - 1); markBit(map, sp - 1);
} else { } else {
clearBit(map, sp - 1); clearBit(map, sp - 1);
} }
if (getBit(map, sp - 2)) { if (b2) {
markBit(map, sp - 3); markBit(map, sp - 3);
markBit(map, sp); markBit(map, sp);
} else { } else {
clearBit(map, sp - 3); clearBit(map, sp - 3);
} }
if (getBit(map, sp - 1)) { if (b1) {
markBit(map, sp - 2); markBit(map, sp - 2);
markBit(map, sp + 1); markBit(map, sp + 1);
} else { } else {
@ -475,32 +489,37 @@ class StackMapper {
} }
sp += 2; sp += 2;
break; } break;
case Duplicate2X2: case Duplicate2X2: {
assert(t, sp + 2 <= mapSize()); assert(t, sp + 2 <= mapSize());
assert(t, sp - 4 >= localSize()); assert(t, sp - 4 >= localSize());
if (getBit(map, sp - 4)) { unsigned b4 = getBit(map, sp - 4);
unsigned b3 = getBit(map, sp - 3);
unsigned b2 = getBit(map, sp - 2);
unsigned b1 = getBit(map, sp - 1);
if (b4) {
markBit(map, sp - 2); markBit(map, sp - 2);
} else { } else {
clearBit(map, sp - 2); clearBit(map, sp - 2);
} }
if (getBit(map, sp - 3)) { if (b3) {
markBit(map, sp - 1); markBit(map, sp - 1);
} else { } else {
clearBit(map, sp - 1); clearBit(map, sp - 1);
} }
if (getBit(map, sp - 2)) { if (b2) {
markBit(map, sp - 4); markBit(map, sp - 4);
markBit(map, sp); markBit(map, sp);
} else { } else {
clearBit(map, sp - 4); clearBit(map, sp - 4);
} }
if (getBit(map, sp - 1)) { if (b1) {
markBit(map, sp - 3); markBit(map, sp - 3);
markBit(map, sp + 1); markBit(map, sp + 1);
} else { } else {
@ -508,7 +527,7 @@ class StackMapper {
} }
sp += 2; sp += 2;
break; } break;
case Pop: { case Pop: {
unsigned count = log.get(i++); unsigned count = log.get(i++);
@ -999,6 +1018,12 @@ frameStackMap(MyThread* t, void* frame)
} }
} }
fprintf(stderr, "%d not found in ", ip);
for (unsigned i = 0; i < compiledStackMapCount(t, code); ++i) {
fprintf(stderr, "%"LD" ", *compiledStackMap(t, code, i));
}
fprintf(stderr, "\n");
abort(t); abort(t);
} }
@ -1585,6 +1610,11 @@ class Assembler {
offsetInstruction(0xbf, 0, 0x40, 0x80, dst, src, srcOffset); offsetInstruction(0xbf, 0, 0x40, 0x80, dst, src, srcOffset);
} }
void movs4(Register src, int32_t srcOffset, Register dst) {
rex();
offsetInstruction(0x63, 0, 0x40, 0x80, dst, src, srcOffset);
}
void mov4(Register src, int32_t srcOffset, Register dst) { void mov4(Register src, int32_t srcOffset, Register dst) {
offsetInstruction(0x8b, 0, 0x40, 0x80, dst, src, srcOffset); offsetInstruction(0x8b, 0, 0x40, 0x80, dst, src, srcOffset);
} }
@ -1662,7 +1692,7 @@ class Assembler {
void push4(Register reg, int32_t offset) { void push4(Register reg, int32_t offset) {
if (BytesPerWord == 8) { if (BytesPerWord == 8) {
mov4(reg, offset, rsi); movs4(reg, offset, rsi);
push(rsi); push(rsi);
} else { } else {
push(reg, offset); push(reg, offset);
@ -1771,6 +1801,11 @@ class Assembler {
code.append(0xc0 | (src << 3) | dst); code.append(0xc0 | (src << 3) | dst);
} }
void or_(Register src, Register dst, unsigned dstOffset) {
rex();
offsetInstruction(0x09, 0, 0x40, 0x80, src, dst, dstOffset);
}
void or_(int32_t v, Register dst) { void or_(int32_t v, Register dst) {
assert(code.s, isByte(v)); // todo assert(code.s, isByte(v)); // todo
@ -1786,6 +1821,11 @@ class Assembler {
code.append(0xc0 | (src << 3) | dst); code.append(0xc0 | (src << 3) | dst);
} }
void and_(Register src, Register dst, unsigned dstOffset) {
rex();
offsetInstruction(0x21, 0, 0x40, 0x80, src, dst, dstOffset);
}
void and_(int32_t v, Register dst) { void and_(int32_t v, Register dst) {
assert(code.s, isByte(v)); // todo assert(code.s, isByte(v)); // todo
@ -1807,6 +1847,18 @@ class Assembler {
} }
} }
void shl4_cl(Register dst, unsigned dstOffset) {
offsetInstruction(0xd3, 0x20, 0x60, 0xa0, rax, dst, dstOffset);
}
void sar4_cl(Register dst, unsigned dstOffset) {
offsetInstruction(0xd3, 0x38, 0x7d, 0xb8, rax, dst, dstOffset);
}
void shr4_cl(Register dst, unsigned dstOffset) {
offsetInstruction(0xd3, 0x28, 0x6d, 0xa8, rax, dst, dstOffset);
}
void ret() { void ret() {
code.append(0xc3); code.append(0xc3);
} }
@ -3313,6 +3365,11 @@ class JavaCompiler: public Compiler {
pushInt(rax); pushInt(rax);
break; break;
case iand:
popInt(rax);
and_(rax, rsp, 0);
break;
case iconst_m1: case iconst_m1:
pushInt(-1); pushInt(-1);
break; break;
@ -3341,6 +3398,14 @@ class JavaCompiler: public Compiler {
pushInt(5); pushInt(5);
break; break;
case vm::idiv:
popInt(rcx);
popInt(rax);
cqo();
Assembler::idiv(rcx);
pushInt(rax);
break;
case if_acmpeq: { case if_acmpeq: {
int16_t offset = codeReadInt16(t, code, ip); int16_t offset = codeReadInt16(t, code, ip);
@ -3672,6 +3737,19 @@ class JavaCompiler: public Compiler {
pushReturnValue(methodReturnCode(t, target)); pushReturnValue(methodReturnCode(t, target));
} break; } break;
case ior:
popInt(rax);
or_(rax, rsp, 0);
break;
case irem:
popInt(rcx);
popInt(rax);
cqo();
Assembler::idiv(rcx);
pushInt(rdx);
break;
case ireturn: case ireturn:
case freturn: case freturn:
popInt(rax); popInt(rax);
@ -3681,6 +3759,16 @@ class JavaCompiler: public Compiler {
stackMapper.exited(); stackMapper.exited();
break; break;
case ishl:
popInt(rcx);
shl4_cl(rsp, 0);
break;
case ishr:
popInt(rcx);
sar4_cl(rsp, 0);
break;
case istore: case istore:
case fstore: case fstore:
storeInt(codeBody(t, code, ip++)); storeInt(codeBody(t, code, ip++));
@ -3711,6 +3799,11 @@ class JavaCompiler: public Compiler {
sub(rax, rsp, 0); sub(rax, rsp, 0);
break; break;
case iushr:
popInt(rcx);
shr4_cl(rsp, 0);
break;
case l2i: case l2i:
if (BytesPerWord == 8) { if (BytesPerWord == 8) {
popInt(); popInt();
@ -4408,12 +4501,16 @@ compileMethod2(MyThread* t, object method)
compiledCode(code) + compiledCodeLength(code)); compiledCode(code) + compiledCodeLength(code));
} }
// if (strcmp(reinterpret_cast<const char*> if (false and
// (&byteArrayBody(t, methodName(t, method), 0)), strcmp(reinterpret_cast<const char*>
// "find") == 0) (&byteArrayBody(t, className(t, methodClass(t, method)), 0)),
// { "java/util/HashMap") == 0 and
// noop(); strcmp(reinterpret_cast<const char*>
// } (&byteArrayBody(t, methodName(t, method), 0)),
"nextPowerOfTwo") == 0)
{
noop();
}
object pool = c.makePool(); object pool = c.makePool();
set(t, methodCode(t, method), pool); set(t, methodCode(t, method), pool);