From: <ls...@us...> - 2010-02-13 22:12:26
|
Revision: 5726 http://jnode.svn.sourceforge.net/jnode/?rev=5726&view=rev Author: lsantha Date: 2010-02-13 22:12:20 +0000 (Sat, 13 Feb 2010) Log Message: ----------- Fixed item recycling for better memory usage in L1a. Modified Paths: -------------- trunk/core/src/core/org/jnode/vm/x86/compiler/l1a/FPCompilerFPU.java trunk/core/src/core/org/jnode/vm/x86/compiler/l1a/InlinedMethodInfo.java trunk/core/src/core/org/jnode/vm/x86/compiler/l1a/ItemStack.java trunk/core/src/core/org/jnode/vm/x86/compiler/l1a/VirtualStack.java trunk/core/src/core/org/jnode/vm/x86/compiler/l1a/X86BytecodeVisitor.java Modified: trunk/core/src/core/org/jnode/vm/x86/compiler/l1a/FPCompilerFPU.java =================================================================== --- trunk/core/src/core/org/jnode/vm/x86/compiler/l1a/FPCompilerFPU.java 2010-02-13 21:42:53 UTC (rev 5725) +++ trunk/core/src/core/org/jnode/vm/x86/compiler/l1a/FPCompilerFPU.java 2010-02-13 22:12:20 UTC (rev 5726) @@ -70,7 +70,7 @@ final FPUStack fpuStack = vstack.fpuStack; final FPU reg = prepareForOperation(os, ec, vstack, fpuStack, v2, v1, true); final Item result = fpuStack.getItem(reg); - fpuStack.pop(); + fpuStack.pop(ec); // Calculate os.writeFADDP(reg); @@ -120,8 +120,8 @@ } // Pop fpu stack twice (FUCOMPP) - fpuStack.pop(); - fpuStack.pop(); + fpuStack.pop(ec); + fpuStack.pop(ec); final Label gtLabel = new Label(curInstrLabel + "gt"); final Label ltLabel = new Label(curInstrLabel + "lt"); @@ -211,7 +211,7 @@ final FPUStack fpuStack = vstack.fpuStack; final FPU reg = prepareForOperation(os, ec, vstack, fpuStack, v2, v1, false); final Item result = fpuStack.getItem(reg); - fpuStack.pop(); + fpuStack.pop(ec); // Calculate os.writeFDIVP(reg); @@ -283,7 +283,7 @@ final FPUStack fpuStack = vstack.fpuStack; final FPU reg = prepareForOperation(os, ec, vstack, fpuStack, v2, v1, true); final Item result = fpuStack.getItem(reg); - fpuStack.pop(); + fpuStack.pop(ec); // Calculate os.writeFMULP(reg); @@ -447,7 +447,7 @@ fxchST1(os, fpuStack, reg); // Pop the fpuStack.tos - fpuStack.pop(); + fpuStack.pop(ec); // Calculate os.writeFXCH(X86Register.ST1); @@ -482,7 +482,7 @@ final FPUStack fpuStack = vstack.fpuStack; final FPU reg = prepareForOperation(os, ec, vstack, fpuStack, v2, v1, false); final Item result = fpuStack.getItem(reg); - fpuStack.pop(); + fpuStack.pop(ec); // Calculate os.writeFSUBP(reg); Modified: trunk/core/src/core/org/jnode/vm/x86/compiler/l1a/InlinedMethodInfo.java =================================================================== --- trunk/core/src/core/org/jnode/vm/x86/compiler/l1a/InlinedMethodInfo.java 2010-02-13 21:42:53 UTC (rev 5725) +++ trunk/core/src/core/org/jnode/vm/x86/compiler/l1a/InlinedMethodInfo.java 2010-02-13 22:12:20 UTC (rev 5726) @@ -79,9 +79,10 @@ * Push the stack elements of the outer method stack and the exit stack. * * @param vstack + * @param eContext */ - final void pushExitStack(ItemFactory ifac, VirtualStack vstack) { - vstack.reset(); + final void pushExitStack(ItemFactory ifac, VirtualStack vstack, EmitterContext eContext) { + vstack.reset(eContext); //vstack.pushAll(outerMethodStack); vstack.pushAll(ifac, exitStack); } Modified: trunk/core/src/core/org/jnode/vm/x86/compiler/l1a/ItemStack.java =================================================================== --- trunk/core/src/core/org/jnode/vm/x86/compiler/l1a/ItemStack.java 2010-02-13 21:42:53 UTC (rev 5725) +++ trunk/core/src/core/org/jnode/vm/x86/compiler/l1a/ItemStack.java 2010-02-13 22:12:20 UTC (rev 5726) @@ -55,7 +55,8 @@ ItemStack(int expectedKind, int maxSize) { this.expectedKind = expectedKind; this.maxSize = maxSize; - reset(); + stack = new Item[Math.min(8, maxSize)]; + tos = 0; } // /** @@ -126,11 +127,14 @@ return (stack[tos - 1] == item); } - final void pop() { + final void pop(EmitterContext ec) { if (tos <= 0) { throw new Error("Stack is empty"); } tos--; + Item item = stack[tos]; + if (item.getKind() != 0) + item.release(ec); } final void pop(Item item) { @@ -162,8 +166,11 @@ /** * Reset this stack. The stack will be empty afterwards. */ - final void reset() { - stack = new Item[Math.min(8, maxSize)]; + final void reset(EmitterContext ec) { + while (tos != 0) { + pop(ec); + } + tos = 0; } Modified: trunk/core/src/core/org/jnode/vm/x86/compiler/l1a/VirtualStack.java =================================================================== --- trunk/core/src/core/org/jnode/vm/x86/compiler/l1a/VirtualStack.java 2010-02-13 21:42:53 UTC (rev 5725) +++ trunk/core/src/core/org/jnode/vm/x86/compiler/l1a/VirtualStack.java 2010-02-13 22:12:20 UTC (rev 5726) @@ -57,16 +57,18 @@ * Constructor; create and initialize stack with default size */ VirtualStack(X86Assembler os) { - this.operandStack = checkOperandStack ? new ItemStack(Item.Kind.STACK, - Integer.MAX_VALUE) : null; - reset(); + this.operandStack = checkOperandStack ? new ItemStack(Item.Kind.STACK, Integer.MAX_VALUE) : null; + stack = new Item[8]; + tos = 0; } - void reset() { - stack = new Item[8]; + void reset(EmitterContext ec) { + while (!isEmpty()) + pop().release(ec); + tos = 0; if (checkOperandStack) { - operandStack.reset(); + operandStack.reset(ec); } } Modified: trunk/core/src/core/org/jnode/vm/x86/compiler/l1a/X86BytecodeVisitor.java =================================================================== --- trunk/core/src/core/org/jnode/vm/x86/compiler/l1a/X86BytecodeVisitor.java 2010-02-13 21:42:53 UTC (rev 5725) +++ trunk/core/src/core/org/jnode/vm/x86/compiler/l1a/X86BytecodeVisitor.java 2010-02-13 22:12:20 UTC (rev 5726) @@ -527,7 +527,7 @@ this.inlineDepth--; // Push the types on the vstack - inlinedMethodInfo.pushExitStack(ifac, vstack); + inlinedMethodInfo.pushExitStack(ifac, vstack, eContext); // Push the return value inlinedMethodInfo.pushReturnValue(helper); @@ -1055,7 +1055,7 @@ BootLog.debug("-- Start of BB " + bb); } startOfBB = true; - this.vstack.reset(); + this.vstack.reset(eContext); eContext.getGPRPool().reset(os); // Push the result from the outer method stack on the vstack if (inlinedMethodInfo != null) { @@ -1064,6 +1064,10 @@ // Push the items on the vstack the result from a previous basic block. final TypeStack tstack = bb.getStartStack(); vstack.pushAll(ifac, tstack); + + //release constant local items + for (Item item : constLocals.values()) + item.release(eContext); // Clear all constant locals constLocals.clear(); @@ -2013,6 +2017,7 @@ final IntItem v = vstack.popInt(); if (v.isConstant()) { vstack.push(ifac.createIConst(eContext, (byte) v.getValue())); + v.release(eContext); } else { v.loadToBITS8GPR(eContext); final GPR r = v.getRegister(); @@ -2028,6 +2033,7 @@ final IntItem v = vstack.popInt(); if (v.isConstant()) { vstack.push(ifac.createIConst(eContext, (char) v.getValue())); + v.release(eContext); } else { v.load(eContext); final GPR r = v.getRegister(); @@ -2057,6 +2063,7 @@ final IntItem v = vstack.popInt(); if (v.isConstant()) { vstack.push(ifac.createLConst(eContext, v.getValue())); + v.release(eContext); } else { final X86RegisterPool pool = eContext.getGPRPool(); final LongItem result; @@ -2069,10 +2076,10 @@ result = (LongItem) ifac.createReg(eContext, JvmType.LONG, X86Register.EAX, X86Register.EDX); os.writeCDQ(BITS32); /* Sign extend EAX -> EDX:EAX */ - pool.transferOwnerTo(X86Register.EAX, result); + v.release(eContext); + pool.request(X86Register.EAX, result); pool.transferOwnerTo(X86Register.EDX, result); - // We do not release v, because its register (EAX) is re-used in - // result + // EAX is re-used in result } else { v.release(eContext); L1AHelper.requestRegister(eContext, X86Register.RAX); @@ -2094,6 +2101,7 @@ final IntItem v = vstack.popInt(); if (v.isConstant()) { vstack.push(ifac.createIConst(eContext, (short) v.getValue())); + v.release(eContext); } else { v.load(eContext); final GPR r = v.getRegister(); @@ -2479,7 +2487,9 @@ } // Local no longer constant - constLocals.remove(index); + Item item = constLocals.remove(index); + if (item != null) + item.release(eContext); } /** @@ -4416,10 +4426,14 @@ final boolean vconst = val.isConstant(); if (vconst) { // Store constant locals - constLocals.put(index, val.clone(eContext)); + Item item = constLocals.put(index, val.clone(eContext)); + if (item != null) + item.release(eContext); } else { // Not constant anymore, remove it - constLocals.remove(index); + Item item = constLocals.remove(index); + if (item != null) + item.release(eContext); } if (vconst && (jvmType == JvmType.INT)) { if (localEscapesBasicBlock(index)) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ls...@us...> - 2010-02-20 10:24:54
|
Revision: 5730 http://jnode.svn.sourceforge.net/jnode/?rev=5730&view=rev Author: lsantha Date: 2010-02-20 10:24:46 +0000 (Sat, 20 Feb 2010) Log Message: ----------- Fixed item recycling. Modified Paths: -------------- trunk/core/src/core/org/jnode/vm/x86/compiler/l1a/ItemFactory.java trunk/core/src/core/org/jnode/vm/x86/compiler/l1a/X86BytecodeVisitor.java Modified: trunk/core/src/core/org/jnode/vm/x86/compiler/l1a/ItemFactory.java =================================================================== --- trunk/core/src/core/org/jnode/vm/x86/compiler/l1a/ItemFactory.java 2010-02-19 20:58:45 UTC (rev 5729) +++ trunk/core/src/core/org/jnode/vm/x86/compiler/l1a/ItemFactory.java 2010-02-20 10:24:46 UTC (rev 5730) @@ -32,6 +32,7 @@ * @author Ewout Prangsma (ep...@us...) */ final class ItemFactory { + public static final boolean CHECK_BALANCED_ITEM_FACTORY = true; private static ThreadLocal itemFactory = new ThreadLocal(); @@ -47,8 +48,10 @@ private int createCount = 0; - protected int releaseCount = 0; + private int getOrCreateCount = 0; + private int releaseCount = 0; + /** * Create a constant item * @@ -217,7 +220,9 @@ */ @SuppressWarnings("unchecked") final <T extends Item> void release(T item) { - releaseCount++; + if (CHECK_BALANCED_ITEM_FACTORY) { + releaseCount++; + } if (Vm.VerifyAssertions) { Vm._assert(item.getKind() == 0, "Item is not yet released"); } @@ -240,6 +245,9 @@ * @return */ private Item getOrCreate(int jvmType) { + if (CHECK_BALANCED_ITEM_FACTORY) { + getOrCreateCount++; + } final ArrayList<? extends Item> list = getList(jvmType); final Item item; if (list.isEmpty()) { @@ -282,7 +290,9 @@ * @return */ private Item createNew(int jvmType) { - createCount++; + if (CHECK_BALANCED_ITEM_FACTORY) { + createCount++; + } switch (jvmType) { case JvmType.INT: return new IntItem(this); @@ -317,4 +327,12 @@ } return fac; } + + boolean isBalanced() { + return getOrCreateCount == releaseCount; + } + + void balance() { + getOrCreateCount = releaseCount = 0; + } } Modified: trunk/core/src/core/org/jnode/vm/x86/compiler/l1a/X86BytecodeVisitor.java =================================================================== --- trunk/core/src/core/org/jnode/vm/x86/compiler/l1a/X86BytecodeVisitor.java 2010-02-19 20:58:45 UTC (rev 5729) +++ trunk/core/src/core/org/jnode/vm/x86/compiler/l1a/X86BytecodeVisitor.java 2010-02-20 10:24:46 UTC (rev 5730) @@ -653,6 +653,17 @@ */ public void endMethod() { stackFrame.emitTrailer(typeSizeInfo, maxLocals); + //release constant local items + for (Item item : constLocals.values()) + item.release(eContext); + // Clear all constant locals + constLocals.clear(); + if (ItemFactory.CHECK_BALANCED_ITEM_FACTORY) { + if (!ifac.isBalanced()) { + System.out.println("WARNING: unbalanced item handling in " + currentMethod.getFullName()); + ifac.balance(); + } + } } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ls...@us...> - 2010-03-28 19:12:47
|
Revision: 5740 http://jnode.svn.sourceforge.net/jnode/?rev=5740&view=rev Author: lsantha Date: 2010-03-28 19:12:41 +0000 (Sun, 28 Mar 2010) Log Message: ----------- Fixed a bug where expected item was not at the top of the item stack. Modified Paths: -------------- trunk/core/src/core/org/jnode/vm/x86/compiler/l1a/ItemStack.java trunk/core/src/core/org/jnode/vm/x86/compiler/l1a/WordItem.java Modified: trunk/core/src/core/org/jnode/vm/x86/compiler/l1a/ItemStack.java =================================================================== --- trunk/core/src/core/org/jnode/vm/x86/compiler/l1a/ItemStack.java 2010-03-28 19:03:38 UTC (rev 5739) +++ trunk/core/src/core/org/jnode/vm/x86/compiler/l1a/ItemStack.java 2010-03-28 19:12:41 UTC (rev 5740) @@ -26,6 +26,7 @@ /** * @author Ewout Prangsma (ep...@us...) + * @author Levente S\u00e1ntha */ class ItemStack { @@ -129,6 +130,36 @@ return (stack[tos - 1] == item); } + /** + * Finds the position of the specified item on the stack starting from the top. + * + * @param item the item to find + * @return the position of the item or -1 if not found + */ + final int stackLocation(Item item) { + int ret = -1; + + int i = tos - 1; + while ((i >= 0) && (stack[i] != item)) + i--; + + if (i >= 0) + ret = tos - 1 - i; + + return ret; + } + + /** + * Exchanges the item at the specified position with the top item. + * + * @param pos the position of the item + */ + final void makeTop(int pos) { + Item tmp = stack[tos - 1]; + stack[tos - 1] = stack[tos - 1 - pos]; + stack[tos - 1 - pos] = tmp; + } + final void pop(EmitterContext ec) { if (tos <= 0) { throw new Error("Stack is empty"); Modified: trunk/core/src/core/org/jnode/vm/x86/compiler/l1a/WordItem.java =================================================================== --- trunk/core/src/core/org/jnode/vm/x86/compiler/l1a/WordItem.java 2010-03-28 19:03:38 UTC (rev 5739) +++ trunk/core/src/core/org/jnode/vm/x86/compiler/l1a/WordItem.java 2010-03-28 19:12:41 UTC (rev 5740) @@ -27,6 +27,7 @@ import org.jnode.assembler.x86.X86Register.GPR64; import org.jnode.vm.JvmType; import org.jnode.vm.Vm; +import org.jnode.vm.bytecode.StackException; import org.jnode.vm.x86.compiler.X86CompilerHelper; /** @@ -186,7 +187,22 @@ break; case Kind.STACK: - // TODO: make sure this is on top os stack + // TODO: make sure 'this' is on top of stack + // TODO: implemen it for 64 bits + if (!stack.operandStack.isTos(this)) { + + int stack_loc = stack.operandStack.stackLocation(this); + if (stack_loc < 0) + throw new StackException("Item not found on stack"); + + stack.operandStack.makeTop(stack_loc); + + //todo test it + os.writeMOV(org.jnode.vm.x86.compiler.X86CompilerConstants.BITS32, reg, helper.SP, helper.SLOTSIZE); + os.writeXCHG(helper.SP, org.jnode.vm.x86.compiler.X86CompilerConstants.BITS32 * stack_loc, reg); + os.writeMOV(org.jnode.vm.x86.compiler.X86CompilerConstants.BITS32, helper.SP, helper.SLOTSIZE, reg); + } + if (VirtualStack.checkOperandStack) { stack.operandStack.pop(this); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |