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. |