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.

------------------------------------------------------------------------------
SOLARIS 10 is the OS for Data Centers - provides features such as DTrace,
Predictive Self Healing and Award Winning ZFS. Get Solaris 10 NOW
http://p.sf.net/sfu/solaris-dev2dev
_______________________________________________
Jnode-svn-commits mailing list
Jnode-svn-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jnode-svn-commits

Reply via email to