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

View File

@ -389,17 +389,20 @@ class StackMapper {
++ sp;
break;
case DuplicateX1:
case DuplicateX1: {
assert(t, sp + 1 <= mapSize());
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);
} else {
clearBit(map, sp - 1);
}
if (getBit(map, sp - 1)) {
if (b1) {
markBit(map, sp - 2);
markBit(map, sp);
} else {
@ -407,25 +410,29 @@ class StackMapper {
}
++ sp;
break;
} break;
case DuplicateX2:
case DuplicateX2: {
assert(t, sp + 1 <= mapSize());
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);
} else {
clearBit(map, sp - 2);
}
if (getBit(map, sp - 2)) {
if (b2) {
markBit(map, sp - 1);
} else {
clearBit(map, sp - 1);
}
if (getBit(map, sp - 1)) {
if (b1) {
markBit(map, sp - 3);
markBit(map, sp);
} else {
@ -433,41 +440,48 @@ class StackMapper {
}
++ sp;
break;
} break;
case Duplicate2:
case Duplicate2: {
assert(t, sp + 2 <= mapSize());
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);
}
if (getBit(map, sp - 1)) {
if (b1) {
markBit(map, sp + 1);
}
sp += 2;
break;
} break;
case Duplicate2X1:
case Duplicate2X1: {
assert(t, sp + 2 <= mapSize());
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);
} else {
clearBit(map, sp - 1);
}
if (getBit(map, sp - 2)) {
if (b2) {
markBit(map, sp - 3);
markBit(map, sp);
} else {
clearBit(map, sp - 3);
}
if (getBit(map, sp - 1)) {
if (b1) {
markBit(map, sp - 2);
markBit(map, sp + 1);
} else {
@ -475,32 +489,37 @@ class StackMapper {
}
sp += 2;
break;
} break;
case Duplicate2X2:
case Duplicate2X2: {
assert(t, sp + 2 <= mapSize());
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);
} else {
clearBit(map, sp - 2);
}
if (getBit(map, sp - 3)) {
if (b3) {
markBit(map, sp - 1);
} else {
clearBit(map, sp - 1);
}
if (getBit(map, sp - 2)) {
if (b2) {
markBit(map, sp - 4);
markBit(map, sp);
} else {
clearBit(map, sp - 4);
}
if (getBit(map, sp - 1)) {
if (b1) {
markBit(map, sp - 3);
markBit(map, sp + 1);
} else {
@ -508,7 +527,7 @@ class StackMapper {
}
sp += 2;
break;
} break;
case Pop: {
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);
}
@ -1585,6 +1610,11 @@ class Assembler {
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) {
offsetInstruction(0x8b, 0, 0x40, 0x80, dst, src, srcOffset);
}
@ -1662,7 +1692,7 @@ class Assembler {
void push4(Register reg, int32_t offset) {
if (BytesPerWord == 8) {
mov4(reg, offset, rsi);
movs4(reg, offset, rsi);
push(rsi);
} else {
push(reg, offset);
@ -1771,6 +1801,11 @@ class Assembler {
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) {
assert(code.s, isByte(v)); // todo
@ -1786,6 +1821,11 @@ class Assembler {
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) {
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() {
code.append(0xc3);
}
@ -3313,6 +3365,11 @@ class JavaCompiler: public Compiler {
pushInt(rax);
break;
case iand:
popInt(rax);
and_(rax, rsp, 0);
break;
case iconst_m1:
pushInt(-1);
break;
@ -3341,6 +3398,14 @@ class JavaCompiler: public Compiler {
pushInt(5);
break;
case vm::idiv:
popInt(rcx);
popInt(rax);
cqo();
Assembler::idiv(rcx);
pushInt(rax);
break;
case if_acmpeq: {
int16_t offset = codeReadInt16(t, code, ip);
@ -3672,6 +3737,19 @@ class JavaCompiler: public Compiler {
pushReturnValue(methodReturnCode(t, target));
} 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 freturn:
popInt(rax);
@ -3681,6 +3759,16 @@ class JavaCompiler: public Compiler {
stackMapper.exited();
break;
case ishl:
popInt(rcx);
shl4_cl(rsp, 0);
break;
case ishr:
popInt(rcx);
sar4_cl(rsp, 0);
break;
case istore:
case fstore:
storeInt(codeBody(t, code, ip++));
@ -3711,6 +3799,11 @@ class JavaCompiler: public Compiler {
sub(rax, rsp, 0);
break;
case iushr:
popInt(rcx);
shr4_cl(rsp, 0);
break;
case l2i:
if (BytesPerWord == 8) {
popInt();
@ -4408,12 +4501,16 @@ compileMethod2(MyThread* t, object method)
compiledCode(code) + compiledCodeLength(code));
}
// if (strcmp(reinterpret_cast<const char*>
// (&byteArrayBody(t, methodName(t, method), 0)),
// "find") == 0)
// {
// noop();
// }
if (false and
strcmp(reinterpret_cast<const char*>
(&byteArrayBody(t, className(t, methodClass(t, method)), 0)),
"java/util/HashMap") == 0 and
strcmp(reinterpret_cast<const char*>
(&byteArrayBody(t, methodName(t, method), 0)),
"nextPowerOfTwo") == 0)
{
noop();
}
object pool = c.makePool();
set(t, methodCode(t, method), pool);