From: <zy...@us...> - 2009-06-06 13:07:41
|
Revision: 6459 http://jython.svn.sourceforge.net/jython/?rev=6459&view=rev Author: zyasoft Date: 2009-06-06 13:07:39 +0000 (Sat, 06 Jun 2009) Log Message: ----------- Now nulls out arrays allocated by CodeCompiler#makeArray where it will be not be potentially kept (__call__ is the one case where this is not definitively known at the callsite, in certain corner cases). This allows for more immediate GC and fixes weakref issues seen in the commit for r6450. Bumped bytecode magic. Modified Paths: -------------- trunk/jython/Lib/test/test_weakref.py trunk/jython/src/org/python/compiler/CodeCompiler.java trunk/jython/src/org/python/core/imp.java Modified: trunk/jython/Lib/test/test_weakref.py =================================================================== --- trunk/jython/Lib/test/test_weakref.py 2009-06-06 07:20:33 UTC (rev 6458) +++ trunk/jython/Lib/test/test_weakref.py 2009-06-06 13:07:39 UTC (rev 6459) @@ -337,19 +337,8 @@ ref2 = weakref.ref(o, self.callback) del ref2 extra_collect() - if test_support.is_jython: - # XXX: Jython bug: the compiler creates a hard reference to - # the following inline declared [ref1] during - # 'weakref.getweakrefs(o) == [ref1]'. See - # CodeCompiler.makeArray for more info - ref1_list = [ref1] - self.assert_(weakref.getweakrefs(o) == ref1_list, - #self.assert_(weakref.getweakrefs(o) == [ref1], - "list of refs does not match") - del ref1_list - else: - self.assert_(weakref.getweakrefs(o) == [ref1], - "list of refs does not match") + self.assert_(weakref.getweakrefs(o) == [ref1], + "list of refs does not match") del ref1 extra_collect() Modified: trunk/jython/src/org/python/compiler/CodeCompiler.java =================================================================== --- trunk/jython/src/org/python/compiler/CodeCompiler.java 2009-06-06 07:20:33 UTC (rev 6458) +++ trunk/jython/src/org/python/compiler/CodeCompiler.java 2009-06-06 13:07:39 UTC (rev 6459) @@ -356,6 +356,14 @@ return array; } + // nulls out an array of references + public void freeArray(int array) { + code.aload(array); + code.aconst_null(); + code.invokestatic("java/util/Arrays", "fill", "(" + $objArr + $obj + ")V"); + code.freeLocal(array); + } + public void getDocString(java.util.List<stmt> suite) throws Exception { if (suite.size() > 0 && suite.get(0) instanceof Expr && ((Expr) suite.get(0)).getInternalValue() instanceof Str) @@ -403,6 +411,8 @@ ScopeInfo scope = module.getScopeInfo(node); + // NOTE: this is attached to the constructed PyFunction, so it cannot be nulled out + // with freeArray, unlike other usages of makeArray here int defaults = makeArray(scope.ac.getDefaults()); code.new_("org/python/core/PyFunction"); @@ -429,7 +439,6 @@ applyDecorators(node.getInternalDecorator_list()); set(new Name(node,node.getInternalName(), expr_contextType.Store)); - //doDecorators(node,node.getInternalDecorator_list(), node.getInternalName()); return null; } @@ -1668,7 +1677,7 @@ code.aload(argArray); code.freeLocal(argArray); stackConsume(2); // target + ts - code.invokevirtual("org/python/core/PyObject", "__call__", "(" + $threadState + $pyObjArr + ")" + $pyObj); + code.invokevirtual("org/python/core/PyObject", "__call__", "(" + $threadState + $pyObjArr + ")" + $pyObj);// freeArray(argArray); break; } } @@ -1774,8 +1783,8 @@ code.new_("org/python/core/PyTuple"); code.dup(); code.aload(dims); - code.freeLocal(dims); code.invokespecial("org/python/core/PyTuple", "<init>", "(" + $pyObjArr + ")V"); + freeArray(dims); return null; } @@ -1852,8 +1861,8 @@ code.dup(); code.aload(content); - code.freeLocal(content); code.invokespecial("org/python/core/PyTuple", "<init>", "(" + $pyObjArr + ")V"); + freeArray(content); return null; } @@ -1867,8 +1876,8 @@ code.new_("org/python/core/PyList"); code.dup(); code.aload(content); - code.freeLocal(content); code.invokespecial("org/python/core/PyList", "<init>", "(" + $pyObjArr + ")V"); + freeArray(content); return null; } @@ -1926,8 +1935,8 @@ code.new_("org/python/core/PyDictionary"); code.dup(); code.aload(content); - code.freeLocal(content); code.invokespecial("org/python/core/PyDictionary", "<init>", "(" + $pyObjArr + ")V"); + freeArray(content); return null; } @@ -1974,7 +1983,6 @@ } else { code.invokespecial("org/python/core/PyFunction", "<init>", "(" + $pyObj + $pyObjArr + $pyCode + $pyObjArr + ")V"); } - return null; } @@ -2016,7 +2024,6 @@ code.ldc(name); code.aload(baseArray); - code.freeLocal(baseArray); ScopeInfo scope = module.getScopeInfo(node); @@ -2041,6 +2048,7 @@ //Assign this new class to the given name set(new Name(node,node.getInternalName(), expr_contextType.Store)); //doDecorators(node,node.getInternalDecorator_list(), node.getInternalName()); + freeArray(baseArray); return null; } @@ -2207,8 +2215,6 @@ int emptyArray = makeArray(new ArrayList<expr>()); code.aload(emptyArray); - code.freeLocal(emptyArray); - scope.setup_closure(); scope.dump(); @@ -2254,6 +2260,7 @@ loadThreadState(); code.swap(); code.invokevirtual("org/python/core/PyObject", "__call__", "(" + $threadState + $pyObj + ")" + $pyObj); + freeArray(emptyArray); return null; } Modified: trunk/jython/src/org/python/core/imp.java =================================================================== --- trunk/jython/src/org/python/core/imp.java 2009-06-06 07:20:33 UTC (rev 6458) +++ trunk/jython/src/org/python/core/imp.java 2009-06-06 13:07:39 UTC (rev 6459) @@ -20,7 +20,7 @@ private static final String UNKNOWN_SOURCEFILE = "<unknown>"; - public static final int APIVersion = 21; + public static final int APIVersion = 22; public static final int NO_MTIME = -1; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |