diff --git a/classpath/java/util/Collections.java b/classpath/java/util/Collections.java index bbc4e60b3f..d4b295fd58 100644 --- a/classpath/java/util/Collections.java +++ b/classpath/java/util/Collections.java @@ -3,10 +3,10 @@ package java.util; public class Collections { private Collections() { } - static String toString(List l) { + static String toString(Collection c) { StringBuilder sb = new StringBuilder(); sb.append("["); - for (Iterator it = l.iterator(); it.hasNext();) { + for (Iterator it = c.iterator(); it.hasNext();) { sb.append(it.next()); if (it.hasNext()) { sb.append(","); diff --git a/classpath/java/util/TreeSet.java b/classpath/java/util/TreeSet.java index 47343c65d3..dbebe04fbc 100644 --- a/classpath/java/util/TreeSet.java +++ b/classpath/java/util/TreeSet.java @@ -17,6 +17,10 @@ public class TreeSet implements Collection { return new MyIterator(set.first()); } + public String toString() { + return Collections.toString(this); + } + public boolean add(T value) { PersistentSet.Path> p = set.find(new Cell(value, null)); if (p.fresh()) { diff --git a/makefile b/makefile index 76527ec251..1b5fdeb368 100644 --- a/makefile +++ b/makefile @@ -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))) diff --git a/src/compile.cpp b/src/compile.cpp index 009ab474f3..845079e73b 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -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 -// (&byteArrayBody(t, methodName(t, method), 0)), -// "find") == 0) -// { -// noop(); -// } + if (false and + strcmp(reinterpret_cast + (&byteArrayBody(t, className(t, methodClass(t, method)), 0)), + "java/util/HashMap") == 0 and + strcmp(reinterpret_cast + (&byteArrayBody(t, methodName(t, method), 0)), + "nextPowerOfTwo") == 0) + { + noop(); + } object pool = c.makePool(); set(t, methodCode(t, method), pool); diff --git a/src/machine.cpp b/src/machine.cpp index a8be17bd3a..72a7604c8e 100644 --- a/src/machine.cpp +++ b/src/machine.cpp @@ -758,8 +758,8 @@ parseFieldTable(Thread* t, Stream& s, object class_, object pool) if (flags & ACC_STATIC) { fieldOffset(t, field) = staticOffset++; } else { - unsigned excess = memberOffset % BytesPerWord; - if (excess and fieldCode(t, field) == ObjectField) { + unsigned excess = memberOffset % fieldSize(t, field); + if (excess) { memberOffset += BytesPerWord - excess; }