[pypy-svn] r79594 - in pypy/branch/jit-unroll-loops: . pypy pypy/config pypy/config/test pypy/doc pypy/doc/config pypy/interpreter pypy/interpreter/test pypy/jit pypy/jit/backend pypy/jit/backend/llgraph pypy/jit/backend/llsupport pypy/jit/backend/test pypy/jit/backend/x86 pypy/jit/backend/x86/test pypy/jit/codewriter pypy/jit/metainterp pypy/jit/metainterp/optimizeopt pypy/jit/metainterp/test pypy/jit/tool pypy/jit/tool/test pypy/module/__pypy__ pypy/module/__pypy__/test pypy/module/_pickle_support pypy/module/array/benchmark pypy/module/array/test pypy/module/cpyext/test pypy/module/itertools pypy/module/pypyjit pypy/module/pypyjit/test pypy/module/sys pypy/module/sys/test pypy/rlib pypy/rlib/test pypy/rpython/lltypesystem pypy/rpython/memory/gc pypy/rpython/memory/gc/test pypy/rpython/memory/test pypy/rpython/test pypy/tool pypy/tool/release pypy/tool/release/test pypy/translator pypy/translator/c pypy/translator/c/gcc pypy/translator/c/gcc/test pypy/translator/c/src pypy/translator/c/test pypy/translator/goal pypy/translator/goal/test2 pypy/translator/platform pypy/translator/tool site-packages

hakanardo at codespeak.net hakanardo at codespeak.net
Sat Nov 27 14:45:39 CET 2010


Author: hakanardo
Date: Sat Nov 27 14:45:32 2010
New Revision: 79594

Added:
   pypy/branch/jit-unroll-loops/pypy/doc/config/translation.jit_debug.txt
      - copied unchanged from r79592, pypy/branch/jit-unroll-loops/pypy/doc/config/translation.jit_debug.txt
Removed:
   pypy/branch/jit-unroll-loops/pypy/config/support.py
   pypy/branch/jit-unroll-loops/pypy/config/test/test_support.py
   pypy/branch/jit-unroll-loops/pypy/doc/release-1.4.0beta.txt
   pypy/branch/jit-unroll-loops/pypy/jit/metainterp/memmgr.py
   pypy/branch/jit-unroll-loops/pypy/jit/metainterp/test/test_memmgr.py
   pypy/branch/jit-unroll-loops/pypy/jit/tool/cpython.vmrss
   pypy/branch/jit-unroll-loops/pypy/jit/tool/log-template.gnumeric
   pypy/branch/jit-unroll-loops/pypy/jit/tool/log2gnumeric.py
   pypy/branch/jit-unroll-loops/pypy/jit/tool/test/test_log2gnumeric.py
   pypy/branch/jit-unroll-loops/pypy/jit/tool/test/test_loopcounter.py
   pypy/branch/jit-unroll-loops/pypy/module/__pypy__/interp_debug.py
   pypy/branch/jit-unroll-loops/pypy/module/__pypy__/test/test_debug.py
   pypy/branch/jit-unroll-loops/pypy/rpython/memory/gc/env.py
   pypy/branch/jit-unroll-loops/pypy/rpython/memory/gc/test/test_env.py
   pypy/branch/jit-unroll-loops/pypy/tool/debug_print.py
   pypy/branch/jit-unroll-loops/pypy/translator/c/src/asm_gcc_x86_64.h
Modified:
   pypy/branch/jit-unroll-loops/   (props changed)
   pypy/branch/jit-unroll-loops/pypy/   (props changed)
   pypy/branch/jit-unroll-loops/pypy/config/pypyoption.py
   pypy/branch/jit-unroll-loops/pypy/config/translationoption.py
   pypy/branch/jit-unroll-loops/pypy/conftest.py
   pypy/branch/jit-unroll-loops/pypy/doc/cpython_differences.txt
   pypy/branch/jit-unroll-loops/pypy/doc/faq.txt
   pypy/branch/jit-unroll-loops/pypy/doc/index.txt
   pypy/branch/jit-unroll-loops/pypy/doc/release-1.4.0.txt
   pypy/branch/jit-unroll-loops/pypy/interpreter/argument.py
   pypy/branch/jit-unroll-loops/pypy/interpreter/baseobjspace.py
   pypy/branch/jit-unroll-loops/pypy/interpreter/gateway.py
   pypy/branch/jit-unroll-loops/pypy/interpreter/generator.py
   pypy/branch/jit-unroll-loops/pypy/interpreter/test/test_argument.py
   pypy/branch/jit-unroll-loops/pypy/interpreter/test/test_gateway.py
   pypy/branch/jit-unroll-loops/pypy/jit/backend/llgraph/llimpl.py
   pypy/branch/jit-unroll-loops/pypy/jit/backend/llgraph/runner.py
   pypy/branch/jit-unroll-loops/pypy/jit/backend/llsupport/gc.py
   pypy/branch/jit-unroll-loops/pypy/jit/backend/model.py
   pypy/branch/jit-unroll-loops/pypy/jit/backend/test/runner_test.py
   pypy/branch/jit-unroll-loops/pypy/jit/backend/test/test_random.py
   pypy/branch/jit-unroll-loops/pypy/jit/backend/x86/assembler.py
   pypy/branch/jit-unroll-loops/pypy/jit/backend/x86/regalloc.py
   pypy/branch/jit-unroll-loops/pypy/jit/backend/x86/runner.py
   pypy/branch/jit-unroll-loops/pypy/jit/backend/x86/test/test_regalloc.py
   pypy/branch/jit-unroll-loops/pypy/jit/backend/x86/test/test_runner.py
   pypy/branch/jit-unroll-loops/pypy/jit/codewriter/jtransform.py
   pypy/branch/jit-unroll-loops/pypy/jit/codewriter/support.py
   pypy/branch/jit-unroll-loops/pypy/jit/conftest.py
   pypy/branch/jit-unroll-loops/pypy/jit/metainterp/compile.py
   pypy/branch/jit-unroll-loops/pypy/jit/metainterp/history.py
   pypy/branch/jit-unroll-loops/pypy/jit/metainterp/jitprof.py
   pypy/branch/jit-unroll-loops/pypy/jit/metainterp/optimizeopt/optimizer.py   (contents, props changed)
   pypy/branch/jit-unroll-loops/pypy/jit/metainterp/pyjitpl.py
   pypy/branch/jit-unroll-loops/pypy/jit/metainterp/test/test_basic.py
   pypy/branch/jit-unroll-loops/pypy/jit/metainterp/test/test_compile.py
   pypy/branch/jit-unroll-loops/pypy/jit/metainterp/test/test_exception.py
   pypy/branch/jit-unroll-loops/pypy/jit/metainterp/test/test_logger.py
   pypy/branch/jit-unroll-loops/pypy/jit/metainterp/test/test_optimizeopt.py
   pypy/branch/jit-unroll-loops/pypy/jit/metainterp/test/test_pyjitpl.py
   pypy/branch/jit-unroll-loops/pypy/jit/metainterp/test/test_recursive.py
   pypy/branch/jit-unroll-loops/pypy/jit/metainterp/test/test_send_nounroll.py   (props changed)
   pypy/branch/jit-unroll-loops/pypy/jit/metainterp/test/test_warmspot.py
   pypy/branch/jit-unroll-loops/pypy/jit/metainterp/test/test_warmstate.py
   pypy/branch/jit-unroll-loops/pypy/jit/metainterp/warmspot.py
   pypy/branch/jit-unroll-loops/pypy/jit/metainterp/warmstate.py
   pypy/branch/jit-unroll-loops/pypy/jit/tool/jitoutput.py
   pypy/branch/jit-unroll-loops/pypy/jit/tool/loopcounter.py
   pypy/branch/jit-unroll-loops/pypy/jit/tool/test/test_jitoutput.py
   pypy/branch/jit-unroll-loops/pypy/module/__pypy__/__init__.py
   pypy/branch/jit-unroll-loops/pypy/module/_pickle_support/maker.py
   pypy/branch/jit-unroll-loops/pypy/module/array/benchmark/Makefile   (props changed)
   pypy/branch/jit-unroll-loops/pypy/module/array/benchmark/intimg.c   (props changed)
   pypy/branch/jit-unroll-loops/pypy/module/array/benchmark/intimgtst.c   (props changed)
   pypy/branch/jit-unroll-loops/pypy/module/array/benchmark/intimgtst.py   (props changed)
   pypy/branch/jit-unroll-loops/pypy/module/array/benchmark/loop.c   (props changed)
   pypy/branch/jit-unroll-loops/pypy/module/array/benchmark/sum.c   (props changed)
   pypy/branch/jit-unroll-loops/pypy/module/array/benchmark/sumtst.c   (props changed)
   pypy/branch/jit-unroll-loops/pypy/module/array/benchmark/sumtst.py   (props changed)
   pypy/branch/jit-unroll-loops/pypy/module/array/test/test_array_old.py   (props changed)
   pypy/branch/jit-unroll-loops/pypy/module/cpyext/test/test_typeobject.py
   pypy/branch/jit-unroll-loops/pypy/module/itertools/interp_itertools.py
   pypy/branch/jit-unroll-loops/pypy/module/pypyjit/__init__.py
   pypy/branch/jit-unroll-loops/pypy/module/pypyjit/policy.py
   pypy/branch/jit-unroll-loops/pypy/module/pypyjit/test/test_policy.py
   pypy/branch/jit-unroll-loops/pypy/module/sys/state.py
   pypy/branch/jit-unroll-loops/pypy/module/sys/test/test_initialpath.py
   pypy/branch/jit-unroll-loops/pypy/rlib/debug.py
   pypy/branch/jit-unroll-loops/pypy/rlib/jit.py
   pypy/branch/jit-unroll-loops/pypy/rlib/libffi.py
   pypy/branch/jit-unroll-loops/pypy/rlib/rarithmetic.py
   pypy/branch/jit-unroll-loops/pypy/rlib/rerased.py   (props changed)
   pypy/branch/jit-unroll-loops/pypy/rlib/test/test_libffi.py
   pypy/branch/jit-unroll-loops/pypy/rlib/test/test_rerased.py   (props changed)
   pypy/branch/jit-unroll-loops/pypy/rpython/lltypesystem/ll2ctypes.py
   pypy/branch/jit-unroll-loops/pypy/rpython/memory/gc/base.py
   pypy/branch/jit-unroll-loops/pypy/rpython/memory/gc/generation.py
   pypy/branch/jit-unroll-loops/pypy/rpython/memory/gc/inspector.py
   pypy/branch/jit-unroll-loops/pypy/rpython/memory/gc/markcompact.py
   pypy/branch/jit-unroll-loops/pypy/rpython/memory/gc/minimark.py
   pypy/branch/jit-unroll-loops/pypy/rpython/memory/gc/semispace.py
   pypy/branch/jit-unroll-loops/pypy/rpython/memory/test/test_gc.py
   pypy/branch/jit-unroll-loops/pypy/rpython/test/test_rclass.py
   pypy/branch/jit-unroll-loops/pypy/rpython/test/test_rint.py
   pypy/branch/jit-unroll-loops/pypy/tool/logparser.py
   pypy/branch/jit-unroll-loops/pypy/tool/release/force-builds.py
   pypy/branch/jit-unroll-loops/pypy/tool/release/make_release.py
   pypy/branch/jit-unroll-loops/pypy/tool/release/package.py
   pypy/branch/jit-unroll-loops/pypy/tool/release/test/test_package.py
   pypy/branch/jit-unroll-loops/pypy/tool/terminal.py
   pypy/branch/jit-unroll-loops/pypy/translator/c/funcgen.py
   pypy/branch/jit-unroll-loops/pypy/translator/c/gcc/test/test_trackgcroot.py
   pypy/branch/jit-unroll-loops/pypy/translator/c/gcc/trackgcroot.py
   pypy/branch/jit-unroll-loops/pypy/translator/c/src/debug_alloc.h
   pypy/branch/jit-unroll-loops/pypy/translator/c/src/debug_print.h
   pypy/branch/jit-unroll-loops/pypy/translator/c/src/g_include.h
   pypy/branch/jit-unroll-loops/pypy/translator/c/src/mem.h
   pypy/branch/jit-unroll-loops/pypy/translator/c/test/test_newgc.py
   pypy/branch/jit-unroll-loops/pypy/translator/c/test/test_standalone.py
   pypy/branch/jit-unroll-loops/pypy/translator/driver.py
   pypy/branch/jit-unroll-loops/pypy/translator/goal/targetpypystandalone.py
   pypy/branch/jit-unroll-loops/pypy/translator/goal/test2/test_app_main.py
   pypy/branch/jit-unroll-loops/pypy/translator/platform/darwin.py
   pypy/branch/jit-unroll-loops/pypy/translator/platform/linux.py
   pypy/branch/jit-unroll-loops/pypy/translator/platform/posix.py
   pypy/branch/jit-unroll-loops/pypy/translator/tool/reftracker.py
   pypy/branch/jit-unroll-loops/site-packages/   (props changed)
Log:
Reverted merge, this branch curently does not play well with the freeing of old traces: svn merge -rHEAD:79592 .

Modified: pypy/branch/jit-unroll-loops/pypy/config/pypyoption.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/config/pypyoption.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/config/pypyoption.py	Sat Nov 27 14:45:32 2010
@@ -161,6 +161,7 @@
                suggests=[("objspace.allworkingmodules", False)]),
 
     BoolOption("geninterp", "specify whether geninterp should be used",
+               cmdline=None,
                default=True),
 
     BoolOption("logbytecodes",

Modified: pypy/branch/jit-unroll-loops/pypy/config/translationoption.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/config/translationoption.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/config/translationoption.py	Sat Nov 27 14:45:32 2010
@@ -3,7 +3,6 @@
 from pypy.config.config import OptionDescription, BoolOption, IntOption, ArbitraryOption, FloatOption
 from pypy.config.config import ChoiceOption, StrOption, to_optparse, Config
 from pypy.config.config import ConfigError
-from pypy.config.support import detect_number_of_processors
 
 DEFL_INLINE_THRESHOLD = 32.4    # just enough to inline add__Int_Int()
 # and just small enough to prevend inlining of some rlist functions.
@@ -114,6 +113,10 @@
     ChoiceOption("jit_backend", "choose the backend for the JIT",
                  ["auto", "x86", "x86-without-sse2", "llvm"],
                  default="auto", cmdline="--jit-backend"),
+    ChoiceOption("jit_debug", "the amount of debugging dumps made by the JIT",
+                 ["off", "profile", "steps", "detailed"],
+                 default="profile",      # XXX for now
+                 cmdline="--jit-debug"),
     ChoiceOption("jit_profiler", "integrate profiler support into the JIT",
                  ["off", "oprofile"],
                  default="off"),
@@ -168,7 +171,7 @@
                default=False, negation=False),
     IntOption("make_jobs", "Specify -j argument to make for compilation"
               " (C backend only)",
-              cmdline="--make-jobs", default=detect_number_of_processors()),
+              cmdline="--make-jobs", default=1),
 
     # Flags of the TranslationContext:
     BoolOption("simplifying", "Simplify flow graphs", default=True),

Modified: pypy/branch/jit-unroll-loops/pypy/conftest.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/conftest.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/conftest.py	Sat Nov 27 14:45:32 2010
@@ -336,15 +336,13 @@
         self.runtest_finish()
 
     def runtest_open(self):
-        if not getattr(self.obj, 'dont_track_allocations', False):
-            leakfinder.start_tracking_allocations()
+        leakfinder.start_tracking_allocations()
 
     def runtest_perform(self):
         super(PyPyTestFunction, self).runtest()
 
     def runtest_close(self):
-        if (not getattr(self.obj, 'dont_track_allocations', False)
-            and leakfinder.TRACK_ALLOCATIONS):
+        if leakfinder.TRACK_ALLOCATIONS:
             self._pypytest_leaks = leakfinder.stop_tracking_allocations(False)
         else:            # stop_tracking_allocations() already called
             self._pypytest_leaks = None

Modified: pypy/branch/jit-unroll-loops/pypy/doc/cpython_differences.txt
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/doc/cpython_differences.txt	(original)
+++ pypy/branch/jit-unroll-loops/pypy/doc/cpython_differences.txt	Sat Nov 27 14:45:32 2010
@@ -20,21 +20,16 @@
 
     __builtin__
     `__pypy__`_
-    _ast
-    _bisect
     _codecs
     _lsprof
     `_minimal_curses`_
     _random
     `_rawffi`_
-    _ssl
     _socket
     _sre
     _weakref
-    array
     bz2
     cStringIO
-    `cpyext`_
     crypt
     errno
     exceptions
@@ -77,7 +72,7 @@
 
 * Supported by being rewritten in pure Python (possibly using ``ctypes``):
   see the `lib_pypy/`_ directory.  Examples of modules that we
-  support this way: ``ctypes``, ``cPickle``,
+  support this way: ``ctypes``, ``array``, ``cPickle``,
   ``cStringIO``, ``cmath``, ``dbm`` (?), ``datetime``, ``binascii``...  
   Note that some modules are both in there and in the list above;
   by default, the built-in module is used (but can be disabled
@@ -85,13 +80,11 @@
 
 The extension modules (i.e. modules written in C, in the standard CPython)
 that are neither mentioned above nor in `lib_pypy/`_ are not available in PyPy.
-(You may have a chance to use them anyway with `cpyext`_.)
 
 .. the nonstandard modules are listed below...
 .. _`__pypy__`: __pypy__-module.html
 .. _`_rawffi`: ctypes-implementation.html
 .. _`_minimal_curses`: config/objspace.usemodules._minimal_curses.html
-.. _`cpyext`: http://morepypy.blogspot.com/2010/04/using-cpython-extension-modules-with.html
 .. _Stackless: stackless.html
 
 
@@ -136,10 +129,12 @@
 .. __: http://morepypy.blogspot.com/2008/02/python-finalizers-semantics-part-1.html
 .. __: http://morepypy.blogspot.com/2008/02/python-finalizers-semantics-part-2.html
 
-Using the default GC called ``minimark``, the built-in function ``id()``
-works like it does in CPython.  With other GCs it returns numbers that
-are not real addresses (because an object can move around several times)
-and calling it a lot can lead to performance problem.
+The built-in function ``id()`` returns numbers that are not addresses
+for most of PyPy's garbage collectors.
+This is most visible in the default repr: a typical PyPy object can
+pretend to be located ``at 0x00000009``.  This is just its ``id()``, not
+its real address (because an object can move around in some GCs). Calling
+``id`` a lot can lead to performance problem.
 
 Note that if you have a long chain of objects, each with a reference to
 the next one, and each with a __del__, PyPy's GC will perform badly.  On

Modified: pypy/branch/jit-unroll-loops/pypy/doc/faq.txt
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/doc/faq.txt	(original)
+++ pypy/branch/jit-unroll-loops/pypy/doc/faq.txt	Sat Nov 27 14:45:32 2010
@@ -47,7 +47,7 @@
 
 There is also an experimental support for CPython extension modules, so
 they'll run without change (from current observation, rather with little
-change) on trunk. It has been a part of 1.4 release, but support is still
+change) on trunk. It has been a part of 1.3 release, but support is still
 in alpha phase.
 
 .. _`extension modules`: cpython_differences.html#extension-modules

Modified: pypy/branch/jit-unroll-loops/pypy/doc/index.txt
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/doc/index.txt	(original)
+++ pypy/branch/jit-unroll-loops/pypy/doc/index.txt	Sat Nov 27 14:45:32 2010
@@ -8,7 +8,7 @@
 Getting into PyPy ... 
 =============================================
 
-* `Release 1.4`_: the latest official release
+* `Release 1.3`_: the latest official release
 
 * `PyPy Blog`_: news and status info about PyPy 
 
@@ -56,4 +56,4 @@
 .. _`Documentation`: docindex.html 
 .. _`Getting Started`: getting-started.html
 .. _papers: extradoc.html
-.. _`Release 1.4`: http://pypy.org/download.html
+.. _`Release 1.3`: http://pypy.org/download.html

Modified: pypy/branch/jit-unroll-loops/pypy/doc/release-1.4.0.txt
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/doc/release-1.4.0.txt	(original)
+++ pypy/branch/jit-unroll-loops/pypy/doc/release-1.4.0.txt	Sat Nov 27 14:45:32 2010
@@ -2,58 +2,27 @@
 PyPy 1.4: Ouroboros in practice
 ===============================
 
+Hello.
+
 We're pleased to announce the 1.4 release of PyPy. This is a major breakthrough
 in our long journey, as PyPy 1.4 is the first PyPy release that can translate
-itself faster than CPython.  Starting today, we are using PyPy more for
-our every-day development.  So may you :) You can download it here:
-
-    http://pypy.org/download.html
-
-What is PyPy
-============
-
-PyPy is a very compliant Python interpreter, almost a drop-in replacement
-for CPython. It's fast (`pypy 1.4 and cpython 2.6`_ comparison)
+itself faster than CPython. Starting today, we plan to start using PyPy for our
+own development.
 
-Among its new features, this release includes numerous performance improvements
-(which made fast self-hosting possible), a 64-bit JIT backend, as well
-as serious stabilization. As of now, we can consider the 32-bit and 64-bit
-linux versions of PyPy stable enough to run `in production`_.
-
-Numerous speed achievements are described on `our blog`_. Normalized speed
-charts comparing `pypy 1.4 and pypy 1.3`_ as well as `pypy 1.4 and cpython 2.6`_
-are available on benchmark website. For the impatient: yes, we got a lot faster!
+Among other features, this release includes numerous performance improvements
+(which made fast self-hosting possible), a 64-bit JIT backend, as well as serious
+stabilization. As of now, we can consider the 32-bit version of PyPy stable enough
+to run in production.
 
 More highlights
 ===============
 
-* PyPy's built-in Just-in-Time compiler is fully transparent and
-  automatically generated; it now also has very reasonable memory
-  requirements.  The total memory used by a very complex and
-  long-running process (translating PyPy itself) is within 1.5x to
-  at most 2x the memory needed by CPython, for a speed-up of 2x.
-
-* More compact instances.  All instances are as compact as if
-  they had ``__slots__``.  This can give programs a big gain in
-  memory.  (In the example of translation above, we already have
-  carefully placed ``__slots__``, so there is no extra win.)
-
-* `Virtualenv support`_: now PyPy is fully compatible with virtualenv_: note that
+* Virtualenv support: now PyPy is fully compatible with virtualenv_: note that
   to use it, you need a recent version of virtualenv (>= 1.5).
 
 * Faster (and JITted) regular expressions - huge boost in speeding up
-  the `re` module.
+  sre module.
 
-* Other speed improvements, like JITted calls to functions like map().
+* Faster (and JITted) calls to functions like map().
 
 .. _virtualenv: http://pypi.python.org/pypi/virtualenv
-.. _`Virtualenv support`: http://morepypy.blogspot.com/2010/08/using-virtualenv-with-pypy.html
-.. _`in production`: http://morepypy.blogspot.com/2010/11/running-large-radio-telescope-software.html
-.. _`our blog`: http://morepypy.blogspot.com
-.. _`pypy 1.4 and pypy 1.3`: http://speed.pypy.org/comparison/?exe=1%2B41,1%2B172&ben=1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20&env=1&hor=false&bas=1%2B41&chart=normal+bars
-.. _`pypy 1.4 and cpython 2.6`: http://speed.pypy.org/comparison/?exe=2%2B35,1%2B172&ben=1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20&env=1&hor=false&bas=2%2B35&chart=normal+bars
-
-Cheers,
-
-Carl Friedrich Bolz, Antonio Cuni, Maciej Fijalkowski,
-Amaury Forgeot d'Arc, Armin Rigo and the PyPy team

Modified: pypy/branch/jit-unroll-loops/pypy/interpreter/argument.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/interpreter/argument.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/interpreter/argument.py	Sat Nov 27 14:45:32 2010
@@ -402,10 +402,9 @@
         space = self.space
         w_args = space.newtuple(self.arguments_w)
         w_kwds = space.newdict()
-        if self.keywords is not None:
-            for i in range(len(self.keywords)):
-                space.setitem(w_kwds, space.wrap(self.keywords[i]),
-                                      self.keywords_w[i])
+        for i in range(len(self.keywords)):
+            space.setitem(w_kwds, space.wrap(self.keywords[i]),
+                                  self.keywords_w[i])
         return w_args, w_kwds
 
 class ArgumentsForTranslation(Arguments):

Modified: pypy/branch/jit-unroll-loops/pypy/interpreter/baseobjspace.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/interpreter/baseobjspace.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/interpreter/baseobjspace.py	Sat Nov 27 14:45:32 2010
@@ -147,7 +147,7 @@
 
     __already_enqueued_for_destruction = False
 
-    def _enqueue_for_destruction(self, space, call_user_del=True):
+    def _enqueue_for_destruction(self, space):
         """Put the object in the destructor queue of the space.
         At a later, safe point in time, UserDelAction will use
         space.userdel() to call the object's app-level __del__ method.
@@ -160,8 +160,7 @@
                 return
             self.__already_enqueued_for_destruction = True
         self.clear_all_weakrefs()
-        if call_user_del:
-            space.user_del_action.register_dying_object(self)
+        space.user_del_action.register_dying_object(self)
 
     def _call_builtin_destructor(self):
         pass     # method overridden in typedef.py

Modified: pypy/branch/jit-unroll-loops/pypy/interpreter/gateway.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/interpreter/gateway.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/interpreter/gateway.py	Sat Nov 27 14:45:32 2010
@@ -1083,7 +1083,7 @@
             # these decorators are known to return the same function
             # object, we may ignore them
             assert '\n' in source
-            source = source[source.find('\n') + 1:].lstrip()
+            source = source[source.find('\n') + 1:]
         assert source.startswith("def "), "can only transform functions" 
         source = source[4:]
     p = source.find('(')

Modified: pypy/branch/jit-unroll-loops/pypy/interpreter/generator.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/interpreter/generator.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/interpreter/generator.py	Sat Nov 27 14:45:32 2010
@@ -10,7 +10,7 @@
     
     def __init__(self, frame):
         self.space = frame.space
-        self.frame = frame     # turned into None when frame_finished_execution
+        self.frame = frame
         self.running = False
 
     def descr__reduce__(self, space):
@@ -19,13 +19,9 @@
         mod      = space.interp_w(MixedModule, w_mod)
         new_inst = mod.get('generator_new')
         w        = space.wrap
-        if self.frame:
-            w_frame = w(self.frame)
-        else:
-            w_frame = space.w_None
 
         tup = [
-            w_frame,
+            w(self.frame),
             w(self.running),
             ]
 
@@ -45,8 +41,7 @@
         if self.running:
             raise OperationError(space.w_ValueError,
                                  space.wrap('generator already executing'))
-        frame = self.frame
-        if frame is None:
+        if self.frame.frame_finished_execution:
             # xxx a bit ad-hoc, but we don't want to go inside
             # execute_generator_frame() if the frame is actually finished
             if operr is None:
@@ -54,7 +49,7 @@
             raise operr
         # XXX it's not clear that last_instr should be promoted at all
         # but as long as it is necessary for call_assembler, let's do it early
-        last_instr = jit.hint(frame.last_instr, promote=True)
+        last_instr = jit.hint(self.frame.last_instr, promote=True)
         if last_instr == -1:
             if w_arg and not space.is_w(w_arg, space.w_None):
                 msg = "can't send non-None value to a just-started generator"
@@ -65,19 +60,18 @@
         self.running = True
         try:
             try:
-                w_result = frame.execute_generator_frame(w_arg, operr)
+                w_result = self.frame.execute_generator_frame(w_arg, operr)
             except OperationError:
                 # errors finish a frame
-                self.frame = None
+                self.frame.frame_finished_execution = True
                 raise
             # if the frame is now marked as finished, it was RETURNed from
-            if frame.frame_finished_execution:
-                self.frame = None
+            if self.frame.frame_finished_execution:
                 raise OperationError(space.w_StopIteration, space.w_None) 
             else:
                 return w_result     # YIELDed
         finally:
-            frame.f_backref = jit.vref_None
+            self.frame.f_backref = jit.vref_None
             self.running = False
 
     def descr_throw(self, w_type, w_val=None, w_tb=None):
@@ -121,7 +115,7 @@
             raise OperationError(space.w_RuntimeError, space.wrap(msg))
 
     def descr_gi_frame(space, self):
-        if self.frame is not None and not self.frame.frame_finished_execution:
+        if not self.frame.frame_finished_execution:
             return self.frame
         else:
             return space.w_None
@@ -131,17 +125,15 @@
         applevel __del__, which is called at a safe point after the
         interp-level __del__ enqueued the object for destruction
         """
-        self.descr_close()
-
-    def __del__(self):
-        # Only bother enqueuing self to raise an exception if the frame is
-        # still not finished and finally or except blocks are present.
-        must_call_close = False
-        if self.frame is not None:
+        # Only bother raising an exception if the frame is still not
+        # finished and finally or except blocks are present.
+        if not self.frame.frame_finished_execution:
             block = self.frame.lastblock
             while block is not None:
                 if not isinstance(block, LoopBlock):
-                    must_call_close = True
-                    break
+                    self.descr_close()
+                    return
                 block = block.previous
-        self._enqueue_for_destruction(self.space, must_call_close)
+
+    def __del__(self):
+        self._enqueue_for_destruction(self.space)

Modified: pypy/branch/jit-unroll-loops/pypy/interpreter/test/test_argument.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/interpreter/test/test_argument.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/interpreter/test/test_argument.py	Sat Nov 27 14:45:32 2010
@@ -453,11 +453,7 @@
         assert set(args.keywords) == set(['a', 'b'])
         assert args.keywords_w[args.keywords.index('a')] == 2
         assert args.keywords_w[args.keywords.index('b')] == 3        
-
-        args = Arguments(space, [1])
-        w_args, w_kwds = args.topacked()
-        assert w_args == (1, )
-        assert not w_kwds
+                                 
 
 class TestErrorHandling(object):
     def test_missing_args(self):

Modified: pypy/branch/jit-unroll-loops/pypy/interpreter/test/test_gateway.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/interpreter/test/test_gateway.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/interpreter/test/test_gateway.py	Sat Nov 27 14:45:32 2010
@@ -578,11 +578,6 @@
         w_res = space.call_args(w_g, args)
         assert space.eq_w(w_res, space.wrap((-1, 0)))
 
-class AppTestPyTestMark:
-    @py.test.mark.unlikely_to_exist
-    def test_anything(self):
-        pass
-
 
 class TestPassThroughArguments:
     

Modified: pypy/branch/jit-unroll-loops/pypy/jit/backend/llgraph/llimpl.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/jit/backend/llgraph/llimpl.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/jit/backend/llgraph/llimpl.py	Sat Nov 27 14:45:32 2010
@@ -4,7 +4,6 @@
 when executing on top of the llinterpreter.
 """
 
-import weakref
 from pypy.objspace.flow.model import Variable, Constant
 from pypy.annotation import model as annmodel
 from pypy.jit.metainterp.history import (ConstInt, ConstPtr,
@@ -162,8 +161,6 @@
 # ____________________________________________________________
 
 class CompiledLoop(object):
-    has_been_freed = False
-
     def __init__(self):
         self.inputargs = []
         self.operations = []
@@ -288,11 +285,6 @@
     del _variables[:]
     return _to_opaque(CompiledLoop())
 
-def mark_as_free(loop):
-    loop = _from_opaque(loop)
-    assert not loop.has_been_freed
-    loop.has_been_freed = True
-
 def compile_start_int_var(loop):
     return compile_start_ref_var(loop, lltype.Signed)
 
@@ -325,7 +317,7 @@
         raise ValueError("CALL_ASSEMBLER not supported")
     loop = _from_opaque(loop)
     op = loop.operations[-1]
-    op.descr = weakref.ref(descr)
+    op.descr = descr
 
 def compile_add_var(loop, intvar):
     loop = _from_opaque(loop)
@@ -444,7 +436,6 @@
         verbose = True
         self.opindex = 0
         while True:
-            assert not self.loop.has_been_freed
             op = self.loop.operations[self.opindex]
             args = [self.getenv(v) for v in op.args]
             if not op.is_final():
@@ -456,10 +447,7 @@
                     _stats.exec_conditional_jumps += 1
                     if op.jump_target is not None:
                         # a patched guard, pointing to further code
-                        if op.fail_args:
-                            args = [self.getenv(v) for v in op.fail_args if v]
-                        else:
-                            args = []
+                        args = [self.getenv(v) for v in op.fail_args if v]
                         assert len(op.jump_target.inputargs) == len(args)
                         self.env = dict(zip(op.jump_target.inputargs, args))
                         self.loop = op.jump_target
@@ -858,22 +846,14 @@
         finally:
             self._may_force = -1
 
-    def op_call_assembler(self, wref_loop_token, *args):
-        if we_are_translated():
-            raise ValueError("CALL_ASSEMBLER not supported")
-        return self._do_call_assembler(wref_loop_token, *args)
-
-    def _do_call_assembler(self, wref_loop_token, *args):
+    def op_call_assembler(self, loop_token, *args):
         global _last_exception
-        loop_token = wref_loop_token()
-        assert loop_token, "CALL_ASSEMBLER to a target that already died"
-        ctl = loop_token.compiled_loop_token
-        if hasattr(ctl, 'redirected'):
-            return self._do_call_assembler(ctl.redirected, *args)
         assert not self._forced
+        loop_token = self.cpu._redirected_call_assembler.get(loop_token,
+                                                             loop_token)
         self._may_force = self.opindex
         try:
-            inpargs = _from_opaque(ctl.compiled_version).inputargs
+            inpargs = _from_opaque(loop_token._llgraph_compiled_version).inputargs
             for i, inparg in enumerate(inpargs):
                 TYPE = inparg.concretetype
                 if TYPE is lltype.Signed:
@@ -1566,13 +1546,10 @@
         do_setfield_gc_int(vable, fielddescr.ofs, 0)
 
 def redirect_call_assembler(cpu, oldlooptoken, newlooptoken):
-    oldclt = oldlooptoken.compiled_loop_token
-    newclt = newlooptoken.compiled_loop_token
-    OLD = _from_opaque(oldclt.compiled_version).getargtypes()
-    NEW = _from_opaque(newclt.compiled_version).getargtypes()
+    OLD = _from_opaque(oldlooptoken._llgraph_compiled_version).getargtypes()
+    NEW = _from_opaque(newlooptoken._llgraph_compiled_version).getargtypes()
     assert OLD == NEW
-    assert not hasattr(oldclt, 'redirected')
-    oldclt.redirected = weakref.ref(newlooptoken)
+    cpu._redirected_call_assembler[oldlooptoken] = newlooptoken
 
 # ____________________________________________________________
 
@@ -1640,7 +1617,6 @@
 setannotation(compile_add_fail, annmodel.SomeInteger())
 setannotation(compile_add_fail_arg, annmodel.s_None)
 setannotation(compile_redirect_fail, annmodel.s_None)
-setannotation(mark_as_free, annmodel.s_None)
 
 setannotation(new_frame, s_Frame)
 setannotation(frame_clear, annmodel.s_None)

Modified: pypy/branch/jit-unroll-loops/pypy/jit/backend/llgraph/runner.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/jit/backend/llgraph/runner.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/jit/backend/llgraph/runner.py	Sat Nov 27 14:45:32 2010
@@ -102,6 +102,7 @@
         llimpl._llinterp = LLInterpreter(self.rtyper)
         self._future_values = []
         self._descrs = {}
+        self._redirected_call_assembler = {}
 
     def _freeze_(self):
         assert self.translate_support_code
@@ -117,34 +118,22 @@
             self._descrs[key] = descr
             return descr
 
-    def compile_bridge(self, faildescr, inputargs, operations,
-                       original_loop_token, log=True):
+    def compile_bridge(self, faildescr, inputargs, operations, log=True):
         c = llimpl.compile_start()
-        clt = original_loop_token.compiled_loop_token
-        clt.loop_and_bridges.append(c)
-        clt.compiling_a_bridge()
         self._compile_loop_or_bridge(c, inputargs, operations)
         old, oldindex = faildescr._compiled_fail
         llimpl.compile_redirect_fail(old, oldindex, c)
 
-    def compile_loop(self, inputargs, operations, looptoken, log=True):
+    def compile_loop(self, inputargs, operations, loopdescr, log=True):
         """In a real assembler backend, this should assemble the given
         list of operations.  Here we just generate a similar CompiledLoop
         instance.  The code here is RPython, whereas the code in llimpl
         is not.
         """
         c = llimpl.compile_start()
-        clt = model.CompiledLoopToken(self, looptoken.number)
-        clt.loop_and_bridges = [c]
-        clt.compiled_version = c
-        looptoken.compiled_loop_token = clt
+        loopdescr._llgraph_compiled_version = c
         self._compile_loop_or_bridge(c, inputargs, operations)
 
-    def free_loop_and_bridges(self, compiled_loop_token):
-        for c in compiled_loop_token.loop_and_bridges:
-            llimpl.mark_as_free(c)
-        model.AbstractCPU.free_loop_and_bridges(self, compiled_loop_token)
-
     def _compile_loop_or_bridge(self, c, inputargs, operations):
         var2index = {}
         for box in inputargs:
@@ -226,7 +215,7 @@
         if op.getopnum() == rop.JUMP:
             targettoken = op.getdescr()
             assert isinstance(targettoken, history.LoopToken)
-            compiled_version = targettoken.compiled_loop_token.compiled_version
+            compiled_version = targettoken._llgraph_compiled_version
             llimpl.compile_add_jump_target(c, compiled_version)
         elif op.getopnum() == rop.FINISH:
             faildescr = op.getdescr()
@@ -236,7 +225,7 @@
             assert False, "unknown operation"
 
     def _execute_token(self, loop_token):
-        compiled_version = loop_token.compiled_loop_token.compiled_version
+        compiled_version = loop_token._llgraph_compiled_version
         frame = llimpl.new_frame(self.is_oo, self)
         # setup the frame
         llimpl.frame_clear(frame, compiled_version)

Modified: pypy/branch/jit-unroll-loops/pypy/jit/backend/llsupport/gc.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/jit/backend/llsupport/gc.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/jit/backend/llsupport/gc.py	Sat Nov 27 14:45:32 2010
@@ -254,7 +254,7 @@
     def _enlarge_gcmap(self):
         newlength = 250 + self._gcmap_maxlength * 2
         newgcmap = lltype.malloc(self.GCMAP_ARRAY, newlength, flavor='raw',
-                                 track_allocation=False)   # YYY leak
+                                 track_allocation=False)
         oldgcmap = self._gcmap
         for i in range(self._gcmap_curlength):
             newgcmap[i] = oldgcmap[i]
@@ -311,7 +311,7 @@
         length = len(shape)
         compressed = lltype.malloc(self.CALLSHAPE_ARRAY, length,
                                    flavor='raw',
-                                   track_allocation=False)   # YYY leak
+                                   track_allocation=False)   # memory leak
         for i in range(length):
             compressed[length-1-i] = rffi.cast(rffi.UCHAR, shape[i])
         return llmemory.cast_ptr_to_adr(compressed)

Modified: pypy/branch/jit-unroll-loops/pypy/jit/backend/model.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/jit/backend/model.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/jit/backend/model.py	Sat Nov 27 14:45:32 2010
@@ -1,4 +1,3 @@
-from pypy.rlib.debug import debug_start, debug_print, debug_stop
 from pypy.jit.metainterp import history, compile
 
 
@@ -8,27 +7,17 @@
     done_with_this_frame_int_v = -1
     done_with_this_frame_ref_v = -1
     done_with_this_frame_float_v = -1
-    total_compiled_loops = 0
-    total_compiled_bridges = 0
-    total_freed_loops = 0
-    total_freed_bridges = 0
 
     def __init__(self):
         self.fail_descr_list = []
-        self.fail_descr_free_list = []
 
     def get_fail_descr_number(self, descr):
         assert isinstance(descr, history.AbstractFailDescr)
         n = descr.index
         if n < 0:
             lst = self.fail_descr_list
-            if len(self.fail_descr_free_list) > 0:
-                n = self.fail_descr_free_list.pop()
-                assert lst[n] is None
-                lst[n] = descr
-            else:
-                n = len(lst)
-                lst.append(descr)
+            n = len(lst)
+            lst.append(descr)
             descr.index = n
         return n
 
@@ -46,14 +35,12 @@
 
     def compile_loop(self, inputargs, operations, looptoken, log=True):
         """Assemble the given loop.
-        Should create and attach a fresh CompiledLoopToken to
-        looptoken.compiled_loop_token and stick extra attributes
-        on it to point to the compiled loop in assembler.
+        Extra attributes should be put in the LoopToken to
+        point to the compiled loop in assembler.
         """
         raise NotImplementedError
 
-    def compile_bridge(self, faildescr, inputargs, operations,
-                       original_loop_token, log=True):
+    def compile_bridge(self, faildescr, inputargs, operations, log=True):
         """Assemble the bridge.
         The FailDescr is the descr of the original guard that failed.
         """
@@ -126,24 +113,6 @@
         oldlooptoken so that from now own they will call newlooptoken."""
         raise NotImplementedError
 
-    def free_loop_and_bridges(self, compiled_loop_token):
-        """This method is called to free resources (machine code,
-        references to resume guards, etc.) allocated by the compilation
-        of a loop and all bridges attached to it.  After this call, the
-        frontend cannot use this compiled loop any more; in fact, it
-        guarantees that at the point of the call to free_code_group(),
-        none of the corresponding assembler is currently running.
-        """
-        # The base class provides a limited implementation: freeing the
-        # resume descrs.  This is already quite helpful, because the
-        # resume descrs are the largest consumers of memory (about 3x
-        # more than the assembler, in the case of the x86 backend).
-        lst = self.fail_descr_list
-        for n in compiled_loop_token.faildescr_indices:
-            lst[n] = None
-        self.fail_descr_free_list.extend(compiled_loop_token.faildescr_indices)
-        # We expect 'compiled_loop_token' to be itself garbage-collected soon.
-
     @staticmethod
     def sizeof(S):
         raise NotImplementedError
@@ -268,37 +237,3 @@
 
     def force(self, force_token):
         raise NotImplementedError
-
-
-class CompiledLoopToken(object):
-    def __init__(self, cpu, number):
-        cpu.total_compiled_loops += 1
-        self.cpu = cpu
-        self.number = number
-        self.bridges_count = 0
-        # This growing list gives the 'descr_number' of all fail descrs
-        # that belong to this loop or to a bridge attached to it.
-        # Filled by the frontend calling record_faildescr_index().
-        self.faildescr_indices = []
-        debug_start("jit-mem-looptoken-alloc")
-        debug_print("allocating Loop #", self.number)
-        debug_stop("jit-mem-looptoken-alloc")
-
-    def record_faildescr_index(self, n):
-        self.faildescr_indices.append(n)
-
-    def compiling_a_bridge(self):
-        self.cpu.total_compiled_bridges += 1
-        self.bridges_count += 1
-        debug_start("jit-mem-looptoken-alloc")
-        debug_print("allocating Bridge #", self.bridges_count, "of Loop #", self.number)
-        debug_stop("jit-mem-looptoken-alloc")
-
-    def __del__(self):
-        debug_start("jit-mem-looptoken-free")
-        debug_print("freeing Loop #", self.number, 'with',
-                    self.bridges_count, 'attached bridges')
-        self.cpu.free_loop_and_bridges(self)
-        self.cpu.total_freed_loops += 1
-        self.cpu.total_freed_bridges += self.bridges_count
-        debug_stop("jit-mem-looptoken-free")

Modified: pypy/branch/jit-unroll-loops/pypy/jit/backend/test/runner_test.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/jit/backend/test/runner_test.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/jit/backend/test/runner_test.py	Sat Nov 27 14:45:32 2010
@@ -174,8 +174,6 @@
         assert not wr_i1() and not wr_guard()
 
     def test_compile_bridge(self):
-        self.cpu.total_compiled_loops = 0
-        self.cpu.total_compiled_bridges = 0
         i0 = BoxInt()
         i1 = BoxInt()
         i2 = BoxInt()
@@ -201,7 +199,7 @@
         ]
         bridge[1].setfailargs([i1b])
 
-        self.cpu.compile_bridge(faildescr1, [i1b], bridge, looptoken)
+        self.cpu.compile_bridge(faildescr1, [i1b], bridge)        
 
         self.cpu.set_future_value_int(0, 2)
         fail = self.cpu.execute_token(looptoken)
@@ -209,9 +207,6 @@
         res = self.cpu.get_latest_value_int(0)
         assert res == 20
 
-        assert self.cpu.total_compiled_loops == 1
-        assert self.cpu.total_compiled_bridges == 1
-
     def test_compile_bridge_with_holes(self):
         i0 = BoxInt()
         i1 = BoxInt()
@@ -238,7 +233,7 @@
         ]
         bridge[1].setfailargs([i1b])
 
-        self.cpu.compile_bridge(faildescr1, [i1b], bridge, looptoken)
+        self.cpu.compile_bridge(faildescr1, [i1b], bridge)        
 
         self.cpu.set_future_value_int(0, 2)
         fail = self.cpu.execute_token(looptoken)
@@ -1055,7 +1050,7 @@
             ResOperation(rop.JUMP, [f3] + fboxes2[1:], None, descr=looptoken),
         ]
 
-        self.cpu.compile_bridge(faildescr1, fboxes2, bridge, looptoken)
+        self.cpu.compile_bridge(faildescr1, fboxes2, bridge)
 
         for i in range(len(fboxes)):
             self.cpu.set_future_value_float(i, 13.5 + 6.73 * i)

Modified: pypy/branch/jit-unroll-loops/pypy/jit/backend/test/test_random.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/jit/backend/test/test_random.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/jit/backend/test/test_random.py	Sat Nov 27 14:45:32 2010
@@ -524,7 +524,7 @@
         self.prebuilt_ptr_consts = []
         self.r = r
         self.build_random_loop(cpu, builder_factory, r, startvars)
-
+        
     def build_random_loop(self, cpu, builder_factory, r, startvars):
 
         loop = TreeLoop('test_random_function')
@@ -685,12 +685,11 @@
             subloop.operations[-1] = jump_op
             self.guard_op = rl.guard_op
             self.prebuilt_ptr_consts += rl.prebuilt_ptr_consts
-            self.loop.token.record_jump_to(rl.loop.token)
             self.dont_generate_more = True
         if r.random() < .05:
             return False
         self.builder.cpu.compile_bridge(fail_descr, fail_args,
-                                        subloop.operations, self.loop.token)
+                                        subloop.operations)
         return True
 
 def check_random_function(cpu, BuilderClass, r, num=None, max=None):

Modified: pypy/branch/jit-unroll-loops/pypy/jit/backend/x86/assembler.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/jit/backend/x86/assembler.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/jit/backend/x86/assembler.py	Sat Nov 27 14:45:32 2010
@@ -7,7 +7,6 @@
 from pypy.rpython.lltypesystem.lloperation import llop
 from pypy.rpython.annlowlevel import llhelper
 from pypy.tool.uid import fixid
-from pypy.jit.backend.model import CompiledLoopToken
 from pypy.jit.backend.x86.regalloc import (RegAlloc, X86RegisterManager,
                                            X86XMMRegisterManager, get_ebp_ofs,
                                            _get_scale)
@@ -31,10 +30,10 @@
 from pypy.jit.backend.x86 import rx86, regloc, codebuf
 from pypy.jit.metainterp.resoperation import rop, ResOperation
 from pypy.jit.backend.x86.support import values_array
-from pypy.rlib.debug import debug_print, debug_start, debug_stop,\
-     have_debug_prints
+from pypy.rlib.debug import debug_print
 from pypy.rlib import rgc
 from pypy.jit.backend.x86.jump import remap_frame_layout
+from pypy.rlib.streamio import open_file_as_stream
 from pypy.jit.metainterp.history import ConstInt, BoxInt
 
 # darwin requires the stack to be 16 bytes aligned on calls. Same for gcc 4.5.0,
@@ -188,8 +187,6 @@
         self.setup_failure_recovery()
         self._debug = False
         self.debug_counter_descr = cpu.fielddescrof(DEBUG_COUNTER, 'i')
-        self.fail_boxes_count = 0
-        self._current_depths_cache = (0, 0)
 
     def leave_jitted_hook(self):
         ptrs = self.fail_boxes_ptr.ar
@@ -229,9 +226,12 @@
                 self._build_float_constants()
             if hasattr(gc_ll_descr, 'get_malloc_fixedsize_slowpath_addr'):
                 self._build_malloc_fixedsize_slowpath()
-            debug_start('jit-backend-counts')
-            self.set_debug(have_debug_prints())
-            debug_stop('jit-backend-counts')
+            s = os.environ.get('PYPYLOG')
+            if s:
+                if s.find(':') != -1:
+                    s = s.split(':')[-1]
+                self.set_debug(True)
+                self._output_loop_log = s + ".count"
             # Intialize here instead of __init__ to prevent
             # pending_guard_tokens from being considered a prebuilt object,
             # which sometimes causes memory leaks since the prebuilt list is
@@ -241,11 +241,13 @@
 
     def finish_once(self):
         if self._debug:
-            debug_start('jit-backend-counts')
+            output_log = self._output_loop_log
+            assert output_log is not None
+            f = open_file_as_stream(output_log, "w")
             for i in range(len(self.loop_run_counters)):
                 name, struct = self.loop_run_counters[i]
-                debug_print(str(name) + ':' + str(struct.i))
-            debug_stop('jit-backend-counts')
+                f.write(str(name) + ":" +  str(struct.i) + "\n")
+            f.close()
 
     def _build_float_constants(self):
         # 44 bytes: 32 bytes for the data, and up to 12 bytes for alignment
@@ -303,8 +305,6 @@
                _x86_arglocs
                _x86_debug_checksum
         """
-        looptoken.compiled_loop_token = CompiledLoopToken(self.cpu,
-                                                          looptoken.number)
         if not we_are_translated():
             # Arguments should be unique
             assert len(set(inputargs)) == len(inputargs)
@@ -409,9 +409,8 @@
 
     def _register_counter(self):
         if self._debug:
-            # YYY leak -- just put it in self.mc instead
             struct = lltype.malloc(DEBUG_COUNTER, flavor='raw',
-                                   track_allocation=False)
+                                   track_allocation=False)   # known to leak
             struct.i = 0
             self.loop_run_counters.append((len(self.loop_run_counters), struct))
         

Modified: pypy/branch/jit-unroll-loops/pypy/jit/backend/x86/regalloc.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/jit/backend/x86/regalloc.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/jit/backend/x86/regalloc.py	Sat Nov 27 14:45:32 2010
@@ -70,7 +70,7 @@
     def _get_new_array(self):
         n = self.BASE_CONSTANT_SIZE
         # known to leak
-        self.cur_array = lltype.malloc(rffi.CArray(lltype.Float), n, # YYY leak
+        self.cur_array = lltype.malloc(rffi.CArray(lltype.Float), n,
                                        flavor='raw', track_allocation=False)
         self.cur_array_free = n
     _get_new_array._dont_inline_ = True
@@ -320,22 +320,11 @@
     def locs_for_fail(self, guard_op):
         return [self.loc(v) for v in guard_op.getfailargs()]
 
-    def get_current_depth(self):
-        # return (self.fm.frame_depth, self.param_depth), but trying to share
-        # the resulting tuple among several calls
-        arg0 = self.fm.frame_depth
-        arg1 = self.param_depth
-        result = self.assembler._current_depths_cache
-        if result[0] != arg0 or result[1] != arg1:
-            result = (arg0, arg1)
-            self.assembler._current_depths_cache = result
-        return result
-
     def perform_with_guard(self, op, guard_op, arglocs, result_loc):
         faillocs = self.locs_for_fail(guard_op)
         self.rm.position += 1
         self.xrm.position += 1
-        current_depths = self.get_current_depth()
+        current_depths = (self.fm.frame_depth, self.param_depth)
         self.assembler.regalloc_perform_with_guard(op, guard_op, faillocs,
                                                    arglocs, result_loc,
                                                    current_depths)
@@ -351,7 +340,7 @@
                                                       arglocs))
             else:
                 self.assembler.dump('%s(%s)' % (guard_op, arglocs))
-        current_depths = self.get_current_depth()
+        current_depths = (self.fm.frame_depth, self.param_depth)                
         self.assembler.regalloc_perform_guard(guard_op, faillocs, arglocs,
                                               result_loc,
                                               current_depths)

Modified: pypy/branch/jit-unroll-loops/pypy/jit/backend/x86/runner.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/jit/backend/x86/runner.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/jit/backend/x86/runner.py	Sat Nov 27 14:45:32 2010
@@ -53,10 +53,7 @@
         self.assembler.assemble_loop(inputargs, operations, looptoken,
                                      log=log)
 
-    def compile_bridge(self, faildescr, inputargs, operations,
-                       original_loop_token, log=True):
-        clt = original_loop_token.compiled_loop_token
-        clt.compiling_a_bridge()
+    def compile_bridge(self, faildescr, inputargs, operations, log=True):
         self.assembler.assemble_bridge(faildescr, inputargs, operations,
                                        log=log)
 
@@ -168,14 +165,17 @@
 CPU = CPU386
 
 # silence warnings
+
 history.LoopToken._x86_param_depth = 0
 history.LoopToken._x86_arglocs = (None, None)
 history.LoopToken._x86_frame_depth = 0
 history.LoopToken._x86_bootstrap_code = 0
 history.LoopToken._x86_direct_bootstrap_code = 0
+history.LoopToken._x86_failure_recovery_bytecode = 0
 history.LoopToken._x86_loop_code = 0
-history.LoopToken._x86_debug_checksum = 0
-compile.AbstractFailDescr._x86_current_depths = (0, 0)
-compile.AbstractFailDescr._x86_failure_recovery_bytecode = 0
-compile.AbstractFailDescr._x86_adr_jump_offset = 0
-compile.AbstractFailDescr._x86_adr_recovery_stub = 0
+history.LoopToken._x86_current_depths = (0, 0)
+
+compile._DoneWithThisFrameDescr._x86_current_depths = (0, 0)
+compile._DoneWithThisFrameDescr._x86_failure_recovery_bytecode = 0
+compile._DoneWithThisFrameDescr._x86_adr_jump_offset = 0
+

Modified: pypy/branch/jit-unroll-loops/pypy/jit/backend/x86/test/test_regalloc.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/jit/backend/x86/test/test_regalloc.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/jit/backend/x86/test/test_regalloc.py	Sat Nov 27 14:45:32 2010
@@ -166,8 +166,7 @@
         assert ([box.type for box in bridge.inputargs] ==
                 [box.type for box in guard_op.getfailargs()])
         faildescr = guard_op.getdescr()
-        self.cpu.compile_bridge(faildescr, bridge.inputargs, bridge.operations,
-                                loop.token)
+        self.cpu.compile_bridge(faildescr, bridge.inputargs, bridge.operations)
         return bridge
 
     def run(self, loop):

Modified: pypy/branch/jit-unroll-loops/pypy/jit/backend/x86/test/test_runner.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/jit/backend/x86/test/test_runner.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/jit/backend/x86/test/test_runner.py	Sat Nov 27 14:45:32 2010
@@ -338,7 +338,6 @@
         faildescr1 = BasicFailDescr(1)
         faildescr2 = BasicFailDescr(2)
         looptoken = LoopToken()
-        looptoken.number = 17
         class FakeString(object):
             def __init__(self, val):
                 self.val = val
@@ -357,7 +356,7 @@
         operations[3].setfailargs([i1])
         self.cpu.compile_loop(inputargs, operations, looptoken)
         name, loopaddress, loopsize = agent.functions[0]
-        assert name == "Loop # 17: hello"
+        assert name == "Loop # 0: hello"
         assert loopaddress <= looptoken._x86_loop_code
         assert loopsize >= 40 # randomish number
 
@@ -371,7 +370,7 @@
         ]
         bridge[1].setfailargs([i1b])
 
-        self.cpu.compile_bridge(faildescr1, [i1b], bridge, looptoken)
+        self.cpu.compile_bridge(faildescr1, [i1b], bridge)        
         name, address, size = agent.functions[1]
         assert name == "Bridge # 0: bye"
         # Would be exactly ==, but there are some guard failure recovery
@@ -496,9 +495,6 @@
             os.environ['PYPYLOG'] = self.pypylog
 
     def test_debugger_on(self):
-        from pypy.tool.logparser import parse_log_file, extract_category
-        from pypy.rlib import debug
-        
         loop = """
         [i0]
         debug_merge_point('xyz', 0)
@@ -508,20 +504,17 @@
         jump(i1)
         """
         ops = parse(loop)
-        debug._log = dlog = debug.DebugLog()
-        try:
-            self.cpu.assembler.set_debug(True)
-            self.cpu.compile_loop(ops.inputargs, ops.operations, ops.token)
-            self.cpu.set_future_value_int(0, 0)
-            self.cpu.execute_token(ops.token)
-            # check debugging info
-            name, struct = self.cpu.assembler.loop_run_counters[0]
-            assert name == 0       # 'xyz'
-            assert struct.i == 10
-            self.cpu.finish_once()
-        finally:
-            debug._log = None
-        assert ('jit-backend-counts', [('debug_print', '0:10')]) in dlog
+        self.cpu.assembler.set_debug(True)
+        self.cpu.compile_loop(ops.inputargs, ops.operations, ops.token)
+        self.cpu.set_future_value_int(0, 0)
+        self.cpu.execute_token(ops.token)
+        # check debugging info
+        name, struct = self.cpu.assembler.loop_run_counters[0]
+        assert name == 0       # 'xyz'
+        assert struct.i == 10
+        self.cpu.finish_once()
+        lines = py.path.local(self.logfile + ".count").readlines()
+        assert lines[0] == '0:10\n'  # '10      xyz\n'
 
     def test_debugger_checksum(self):
         loop = """

Modified: pypy/branch/jit-unroll-loops/pypy/jit/codewriter/jtransform.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/jit/codewriter/jtransform.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/jit/codewriter/jtransform.py	Sat Nov 27 14:45:32 2010
@@ -398,7 +398,6 @@
     rewrite_op_int_lshift_ovf  = _do_builtin_call
     rewrite_op_int_abs         = _do_builtin_call
     rewrite_op_gc_identityhash = _do_builtin_call
-    rewrite_op_gc_id           = _do_builtin_call
 
     # ----------
     # getfield/setfield/mallocs etc.
@@ -844,16 +843,9 @@
             "general mix-up of jitdrivers?")
         ops = self.promote_greens(op.args[2:], jitdriver)
         num_green_args = len(jitdriver.greens)
-        redlists = self.make_three_lists(op.args[2+num_green_args:])
-        for redlist in redlists:
-            for v in redlist:
-                assert isinstance(v, Variable), (
-                    "Constant specified red in jit_merge_point()")
-            assert len(dict.fromkeys(redlist)) == len(list(redlist)), (
-                "duplicate red variable on jit_merge_point()")
         args = ([Constant(self.portal_jd.index, lltype.Signed)] +
                 self.make_three_lists(op.args[2:2+num_green_args]) +
-                redlists)
+                self.make_three_lists(op.args[2+num_green_args:]))
         op1 = SpaceOperation('jit_merge_point', args, None)
         op2 = SpaceOperation('-live-', [], None)
         # ^^^ we need a -live- for the case of do_recursive_call()

Modified: pypy/branch/jit-unroll-loops/pypy/jit/codewriter/support.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/jit/codewriter/support.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/jit/codewriter/support.py	Sat Nov 27 14:45:32 2010
@@ -168,9 +168,6 @@
 def _ll_1_gc_identityhash(x):
     return lltype.identityhash(x)
 
-def _ll_1_gc_id(ptr):
-    return llop.gc_id(lltype.Signed, ptr)
-
 def _ll_1_jit_force_virtual(inst):
     return llop.jit_force_virtual(lltype.typeOf(inst), inst)
 
@@ -551,9 +548,6 @@
 def get_identityhash_oopspec(op):
     return 'gc_identityhash', op.args
 
-def get_gcid_oopspec(op):
-    return 'gc_id', op.args
-
 
 RENAMED_ADT_NAME = {
     'list': {
@@ -584,8 +578,6 @@
         return get_oostring_oopspec(op)
     elif op.opname == 'gc_identityhash':
         return get_identityhash_oopspec(op)
-    elif op.opname == 'gc_id':
-        return get_gcid_oopspec(op)
     else:
         raise ValueError(op.opname)
 

Modified: pypy/branch/jit-unroll-loops/pypy/jit/conftest.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/jit/conftest.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/jit/conftest.py	Sat Nov 27 14:45:32 2010
@@ -1,5 +1,7 @@
 import py
 
+option = py.test.config.option
+
 def pytest_addoption(parser):
     group = parser.getgroup("JIT options")
     group.addoption('--slow', action="store_true",

Modified: pypy/branch/jit-unroll-loops/pypy/jit/metainterp/compile.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/jit/metainterp/compile.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/jit/metainterp/compile.py	Sat Nov 27 14:45:32 2010
@@ -1,4 +1,4 @@
-import weakref
+
 from pypy.rpython.lltypesystem import lltype
 from pypy.rpython.ootypesystem import ootype
 from pypy.objspace.flow.model import Constant, Variable
@@ -46,32 +46,6 @@
     loop_token.outermost_jitdriver_sd = jitdriver_sd
     return loop_token
 
-def record_loop_or_bridge(loop):
-    """Do post-backend recordings and cleanups on 'loop'.
-    """
-    # get the original loop token (corresponding to 'loop', or if that is
-    # a bridge, to the loop that this bridge belongs to)
-    looptoken = loop.token
-    assert looptoken is not None
-    wref = weakref.ref(looptoken)
-    for op in loop.operations:
-        descr = op.getdescr()
-        if isinstance(descr, ResumeDescr):
-            descr.wref_original_loop_token = wref   # stick it there
-            n = descr.index
-            if n >= 0:       # we also record the resumedescr number
-                looptoken.compiled_loop_token.record_faildescr_index(n)
-        elif isinstance(descr, LoopToken):
-            # for a JUMP or a CALL_ASSEMBLER: record it as a potential jump.
-            # (the following test is not enough to prevent more complicated
-            # cases of cycles, but at least it helps in simple tests of
-            # test_memgr.py)
-            if descr is not looptoken:
-                looptoken.record_jump_to(descr)
-            op.setdescr(None)    # clear reference, mostly for tests
-    # mostly for tests: make sure we don't keep a reference to the LoopToken
-    loop.token = None
-
 # ____________________________________________________________
 
 def compile_new_loop(metainterp, old_loop_tokens, greenkey, start):
@@ -107,16 +81,13 @@
 
     if loop.preamble.operations is not None:
         send_loop_to_backend(metainterp_sd, loop, "loop")
-        record_loop_or_bridge(loop)
         send_loop_to_backend(metainterp_sd, loop.preamble, "entry bridge")
-        record_loop_or_bridge(loop.preamble)
         insert_loop_token(old_loop_tokens, loop.preamble.token)
         jitdriver_sd.warmstate.attach_unoptimized_bridge_from_interp(
             greenkey, loop.preamble.token)
         return loop.preamble.token
     else:
         send_loop_to_backend(metainterp_sd, loop, "loop")
-        record_loop_or_bridge(loop.preamble)
         insert_loop_token(old_loop_tokens, loop_token)
         jitdriver_sd.warmstate.attach_unoptimized_bridge_from_interp(
             greenkey, loop.token)
@@ -160,11 +131,8 @@
         else:
             loop._ignore_during_counting = True
     metainterp_sd.log("compiled new " + type)
-    if metainterp_sd.warmrunnerdesc is not None:    # for tests
-        metainterp_sd.warmrunnerdesc.memory_manager.keep_loop_alive(loop.token)
 
-def send_bridge_to_backend(metainterp_sd, faildescr, inputargs, operations,
-                           original_loop_token):
+def send_bridge_to_backend(metainterp_sd, faildescr, inputargs, operations):
     n = metainterp_sd.cpu.get_fail_descr_number(faildescr)
     metainterp_sd.logger_ops.log_bridge(inputargs, operations, n)
     if not we_are_translated():
@@ -173,8 +141,7 @@
     metainterp_sd.profiler.start_backend()
     debug_start("jit-backend")
     try:
-        metainterp_sd.cpu.compile_bridge(faildescr, inputargs, operations,
-                                         original_loop_token)
+        metainterp_sd.cpu.compile_bridge(faildescr, inputargs, operations)
     finally:
         debug_stop("jit-backend")
     metainterp_sd.profiler.end_backend()
@@ -271,6 +238,9 @@
     CNT_FLOAT = -0x60000000
     CNT_MASK  =  0x1FFFFFFF
 
+    def __init__(self, metainterp_sd):
+        self.metainterp_sd = metainterp_sd
+
     def store_final_boxes(self, guard_op, boxes):
         guard_op.setfailargs(boxes)
         self.guard_opnum = guard_op.getopnum()
@@ -355,14 +325,12 @@
 
     def compile_and_attach(self, metainterp, new_loop):
         # We managed to create a bridge.  Attach the new operations
-        # to the corresponding guard_op and compile from there
-        assert metainterp.resumekey_original_loop_token is not None
-        new_loop.token = metainterp.resumekey_original_loop_token
+        # to the corrsponding guard_op and compile from there
         inputargs = metainterp.history.inputargs
         if not we_are_translated():
             self._debug_suboperations = new_loop.operations
         send_bridge_to_backend(metainterp.staticdata, self, inputargs,
-                               new_loop.operations, new_loop.token)
+                               new_loop.operations)
 
     def copy_all_attrbutes_into(self, res):
         # XXX a bit ugly to have to list them all here
@@ -374,14 +342,14 @@
         res.rd_pendingfields = self.rd_pendingfields
 
     def _clone_if_mutable(self):
-        res = ResumeGuardDescr()
+        res = ResumeGuardDescr(self.metainterp_sd)
         self.copy_all_attrbutes_into(res)
         return res
 
 class ResumeGuardForcedDescr(ResumeGuardDescr):
 
     def __init__(self, metainterp_sd, jitdriver_sd):
-        self.metainterp_sd = metainterp_sd
+        ResumeGuardDescr.__init__(self, metainterp_sd)
         self.jitdriver_sd = jitdriver_sd
 
     def handle_fail(self, metainterp_sd, jitdriver_sd):
@@ -525,8 +493,6 @@
         metainterp_sd = metainterp.staticdata
         jitdriver_sd = metainterp.jitdriver_sd
         redargs = new_loop.inputargs
-        # We make a new LoopToken for this entry bridge, and stick it
-        # to every guard in the loop.
         new_loop_token = make_loop_token(len(redargs), jitdriver_sd)
         new_loop.token = new_loop_token
         send_loop_to_backend(metainterp_sd, new_loop, "entry bridge")
@@ -534,14 +500,12 @@
         jitdriver_sd.warmstate.attach_unoptimized_bridge_from_interp(
             self.original_greenkey,
             new_loop_token)
-        # store the new loop in compiled_merge_points_wref too
+        # store the new loop in compiled_merge_points too
         old_loop_tokens = metainterp.get_compiled_merge_points(
             self.original_greenkey)
         # it always goes at the end of the list, as it is the most
         # general loop token
         old_loop_tokens.append(new_loop_token)
-        metainterp.set_compiled_merge_points(self.original_greenkey,
-                                             old_loop_tokens)
 
     def reset_counter_from_failure(self):
         pass
@@ -576,7 +540,6 @@
         # know exactly what we must do (ResumeGuardDescr/ResumeFromInterpDescr)
         prepare_last_operation(new_loop, target_loop_token)
         resumekey.compile_and_attach(metainterp, new_loop)
-        record_loop_or_bridge(new_loop)
         compile_known_target_bridges(metainterp, new_loop)
     return target_loop_token
 
@@ -592,14 +555,13 @@
                 jmp = ResOperation(rop.JUMP, mini.inputargs[:], None, target)
                 mini.operations = [jmp]
                 descr = op.getdescr()
-                assert isinstance(descr, ResumeGuardDescr)
                 
                 #descr.compile_and_attach(metainterp, mini)
                 if not we_are_translated():
                     descr._debug_suboperations = mini.operations
                 send_bridge_to_backend(metainterp.staticdata, descr,
                                        mini.inputargs, mini.operations)
-                record_loop_or_bridge(mini)
+
 
 def prepare_last_operation(new_loop, target_loop_token):
     op = new_loop.operations[-1]
@@ -626,8 +588,7 @@
 
 propagate_exception_descr = PropagateExceptionDescr()
 
-def compile_tmp_callback(cpu, jitdriver_sd, greenboxes, redboxes,
-                         memory_manager=None):
+def compile_tmp_callback(cpu, jitdriver_sd, greenboxes, redboxes):
     """Make a LoopToken that corresponds to assembler code that just
     calls back the interpreter.  Used temporarily: a fully compiled
     version of the code may end up replacing it.
@@ -667,6 +628,4 @@
         ]
     operations[1].setfailargs([])
     cpu.compile_loop(inputargs, operations, loop_token, log=False)
-    if memory_manager is not None:    # for tests
-        memory_manager.keep_loop_alive(loop_token)
     return loop_token

Modified: pypy/branch/jit-unroll-loops/pypy/jit/metainterp/history.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/jit/metainterp/history.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/jit/metainterp/history.py	Sat Nov 27 14:45:32 2010
@@ -4,7 +4,8 @@
 from pypy.rpython.ootypesystem import ootype
 from pypy.rlib.objectmodel import we_are_translated, r_dict, Symbolic
 from pypy.rlib.objectmodel import compute_hash, compute_unique_id
-from pypy.rlib.rarithmetic import intmask, r_int64
+from pypy.rlib.rarithmetic import intmask
+from pypy.tool.uid import uid
 from pypy.conftest import option
 
 from pypy.jit.metainterp.resoperation import ResOperation, rop
@@ -744,28 +745,14 @@
     terminating = False # see TerminatingLoopToken in compile.py
     outermost_jitdriver_sd = None
     # and more data specified by the backend when the loop is compiled
-    number = -1
-    generation = r_int64(0)
-    # one purpose of LoopToken is to keep alive the CompiledLoopToken
-    # returned by the backend.  When the LoopToken goes away, the
-    # CompiledLoopToken has its __del__ called, which frees the assembler
-    # memory and the ResumeGuards.
-    compiled_loop_token = None
+    number = 0
 
-    def __init__(self):
-        # For memory management of assembled loops
-        self._keepalive_target_looktokens = {}      # set of other LoopTokens
-
-    def record_jump_to(self, target_loop_token):
-        self._keepalive_target_looktokens[target_loop_token] = None
-
-    def __repr__(self):
-        return '<Loop %d, gen=%d>' % (self.number, self.generation)
+    def __init__(self, number=0):
+        self.number = number
 
     def repr_of_descr(self):
         return '<Loop%d>' % self.number
 
-
 class TreeLoop(object):
     inputargs = None
     operations = None

Modified: pypy/branch/jit-unroll-loops/pypy/jit/metainterp/jitprof.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/jit/metainterp/jitprof.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/jit/metainterp/jitprof.py	Sat Nov 27 14:45:32 2010
@@ -2,9 +2,9 @@
 """ A small helper module for profiling JIT
 """
 
+import os
 import time
-from pypy.rlib.debug import debug_print, debug_start, debug_stop
-from pypy.rlib.debug import have_debug_prints
+from pypy.rlib.debug import debug_print
 from pypy.jit.metainterp.jitexc import JitException
 
 counters="""
@@ -24,10 +24,6 @@
 NVIRTUALS
 NVHOLES
 NVREUSED
-TOTAL_COMPILED_LOOPS
-TOTAL_COMPILED_BRIDGES
-TOTAL_FREED_LOOPS
-TOTAL_FREED_BRIDGES
 """
 
 def _setup():
@@ -39,7 +35,6 @@
 _setup()
 
 JITPROF_LINES = ncounters + 1 + 1 # one for TOTAL, 1 for calls, update if needed
-_CPU_LINES = 4       # the last 4 lines are stored on the cpu
 
 class BaseProfiler(object):
     pass
@@ -53,6 +48,9 @@
     def finish(self):
         pass
 
+    def set_printing(self, printing):
+        pass
+
     def start_tracing(self):
         pass
 
@@ -92,19 +90,23 @@
     counters = None
     calls = 0
     current = None
-    cpu = None
+    printing = True
 
     def start(self):
         self.starttime = self.timer()
         self.t1 = self.starttime
         self.times = [0, 0]
-        self.counters = [0] * (ncounters - _CPU_LINES)
+        self.counters = [0] * ncounters
         self.calls = 0
         self.current = []
 
     def finish(self):
         self.tk = self.timer()
-        self.print_stats()
+        if self.printing:
+            self.print_stats()
+
+    def set_printing(self, printing):
+        self.printing = printing
 
     def _start(self, event):
         t0 = self.t1
@@ -152,12 +154,6 @@
             self.calls += 1
 
     def print_stats(self):
-        debug_start("jit-summary")
-        if have_debug_prints():
-            self._print_stats()
-        debug_stop("jit-summary")
-
-    def _print_stats(self):
         cnt = self.counters
         tim = self.times
         calls = self.calls
@@ -165,8 +161,8 @@
         self._print_line_time("Backend", cnt[BACKEND],   tim[BACKEND])
         self._print_intline("Running asm", cnt[RUNNING])
         self._print_intline("Blackhole", cnt[BLACKHOLE])
-        line = "TOTAL:      \t\t%f" % (self.tk - self.starttime, )
-        debug_print(line)
+        line = "TOTAL:      \t\t%f\n" % (self.tk - self.starttime, )
+        os.write(2, line)
         self._print_intline("ops", cnt[OPS])
         self._print_intline("recorded ops", cnt[RECORDED_OPS])
         self._print_intline("  calls", calls)
@@ -180,26 +176,17 @@
         self._print_intline("nvirtuals", cnt[NVIRTUALS])
         self._print_intline("nvholes", cnt[NVHOLES])
         self._print_intline("nvreused", cnt[NVREUSED])
-        cpu = self.cpu
-        if cpu is not None:   # for some tests
-            self._print_intline("Total # of loops",
-                                cpu.total_compiled_loops)
-            self._print_intline("Total # of bridges",
-                                cpu.total_compiled_bridges)
-            self._print_intline("Freed # of loops",
-                                cpu.total_freed_loops)
-            self._print_intline("Freed # of bridges",
-                                cpu.total_freed_bridges)
 
     def _print_line_time(self, string, i, tim):
-        final = "%s:%s\t%d\t%f" % (string, " " * max(0, 13-len(string)), i, tim)
-        debug_print(final)
+        final = "%s:%s\t%d\t%f\n" % (string, " " * max(0, 13-len(string)), i, tim)
+        os.write(2, final)
 
     def _print_intline(self, string, i):
         final = string + ':' + " " * max(0, 16-len(string))
-        final += '\t' + str(i)
-        debug_print(final)
-
+        final += '\t' + str(i) + '\n'
+        os.write(2, final)
+        
+        
 
 class BrokenProfilerData(JitException):
     pass

Modified: pypy/branch/jit-unroll-loops/pypy/jit/metainterp/optimizeopt/optimizer.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/jit/metainterp/optimizeopt/optimizer.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/jit/metainterp/optimizeopt/optimizer.py	Sat Nov 27 14:45:32 2010
@@ -373,10 +373,6 @@
             return CVAL_ZERO
 
     def propagate_all_forward(self):
-        self.exception_might_have_happened = True
-        # ^^^ at least at the start of bridges.  For loops, we could set
-        # it to False, but we probably don't care
-        self.newoperations = []
         self.i = 0
         while self.i < len(self.loop.operations):
             op = self.loop.operations[self.i]

Modified: pypy/branch/jit-unroll-loops/pypy/jit/metainterp/pyjitpl.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/jit/metainterp/pyjitpl.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/jit/metainterp/pyjitpl.py	Sat Nov 27 14:45:32 2010
@@ -14,10 +14,11 @@
 from pypy.jit.metainterp.logger import Logger
 from pypy.jit.metainterp.jitprof import EmptyProfiler
 from pypy.jit.metainterp.jitprof import GUARDS, RECORDED_OPS, ABORT_ESCAPE
-from pypy.jit.metainterp.jitprof import ABORT_TOO_LONG, ABORT_BRIDGE
+from pypy.jit.metainterp.jitprof import ABORT_TOO_LONG
 from pypy.jit.metainterp.jitexc import JitException, get_llexception
 from pypy.rlib.rarithmetic import intmask
 from pypy.rlib.objectmodel import specialize
+from pypy.rlib.jit import DEBUG_OFF, DEBUG_PROFILE, DEBUG_STEPS, DEBUG_DETAILED
 from pypy.jit.codewriter.jitcode import JitCode, SwitchDictDescr
 from pypy.jit.codewriter import heaptracker
 
@@ -93,18 +94,6 @@
             else: raise AssertionError(argcode)
             outvalue[startindex+i] = reg
 
-    def _put_back_list_of_boxes(self, outvalue, startindex, position):
-        code = self.bytecode
-        length = ord(code[position])
-        position += 1
-        for i in range(length):
-            index = ord(code[position+i])
-            box = outvalue[startindex+i]
-            if   box.type == history.INT:   self.registers_i[index] = box
-            elif box.type == history.REF:   self.registers_r[index] = box
-            elif box.type == history.FLOAT: self.registers_f[index] = box
-            else: raise AssertionError(box.type)
-
     def get_current_position_info(self):
         return self.jitcode.get_live_vars_info(self.pc)
 
@@ -825,9 +814,8 @@
         for i in range(num_green_args):
             assert isinstance(varargs[i], Const)
 
-    @arguments("orgpc", "int", "boxes3", "jitcode_position", "boxes3")
-    def opimpl_jit_merge_point(self, orgpc, jdindex, greenboxes,
-                               jcposition, redboxes):
+    @arguments("orgpc", "int", "boxes3", "boxes3")
+    def opimpl_jit_merge_point(self, orgpc, jdindex, greenboxes, redboxes):
         any_operation = len(self.metainterp.history.operations) > 0
         jitdriver_sd = self.metainterp.staticdata.jitdrivers_sd[jdindex]
         self.verify_green_args(jitdriver_sd, greenboxes)
@@ -855,10 +843,6 @@
             self.pc = orgpc
             self.metainterp.reached_loop_header(greenboxes, redboxes)
             self.pc = saved_pc
-            # no exception, which means that the jit_merge_point did not
-            # close the loop.  We have to put the possibly-modified list
-            # 'redboxes' back into the registers where it comes from.
-            put_back_list_of_boxes3(self, jcposition, redboxes)
         else:
             # warning! careful here.  We have to return from the current
             # frame containing the jit_merge_point, and then use
@@ -1068,7 +1052,7 @@
             resumedescr = compile.ResumeGuardForcedDescr(metainterp_sd,
                                                    metainterp.jitdriver_sd)
         else:
-            resumedescr = compile.ResumeGuardDescr()
+            resumedescr = compile.ResumeGuardDescr(metainterp_sd)
         guard_op = metainterp.history.record(opnum, moreargs, None,
                                              descr=resumedescr)
         virtualizable_boxes = None
@@ -1222,7 +1206,6 @@
         self.logger_ops = Logger(self, guard_number=True)
 
         self.profiler = ProfilerClass()
-        self.profiler.cpu = cpu
         self.warmrunnerdesc = warmrunnerdesc
 
         backendmodule = self.cpu.__module__
@@ -1341,11 +1324,6 @@
                     return jitcode
             return None
 
-    def try_to_free_some_loops(self):
-        # Increase here the generation recorded by the memory manager.
-        if self.warmrunnerdesc is not None:       # for tests
-            self.warmrunnerdesc.memory_manager.next_generation()
-
     # ---------------- logging ------------------------
 
     def log(self, msg):
@@ -1642,7 +1620,6 @@
         self.staticdata._setup_once()
         self.staticdata.profiler.start_tracing()
         assert jitdriver_sd is self.jitdriver_sd
-        self.staticdata.try_to_free_some_loops()
         self.create_empty_history()
         try:
             original_boxes = self.initialize_original_boxes(jitdriver_sd, *args)
@@ -1671,15 +1648,10 @@
         debug_start('jit-tracing')
         self.staticdata.profiler.start_tracing()
         assert isinstance(key, compile.ResumeGuardDescr)
-        # store the resumekey.wref_original_loop_token() on 'self' to make
-        # sure that it stays alive as long as this MetaInterp
-        self.resumekey_original_loop_token = key.wref_original_loop_token()
-        self.staticdata.try_to_free_some_loops()
         self.initialize_state_from_guard_failure(key)
         try:
             return self._handle_guard_failure(key)
         finally:
-            self.resumekey_original_loop_token = None
             self.staticdata.profiler.end_tracing()
             debug_stop('jit-tracing')
 
@@ -1689,8 +1661,6 @@
         self.seen_loop_header_for_jdindex = -1
         try:
             self.prepare_resume_from_failure(key.guard_opnum)
-            if self.resumekey_original_loop_token is None:   # very rare case
-                raise SwitchToBlackhole(ABORT_BRIDGE)
             self.interpret()
         except GenerateMergePoint, gmp:
             return self.designate_target_loop(gmp)
@@ -1811,15 +1781,10 @@
             raise NotImplementedError(opname[opnum])
 
     def get_compiled_merge_points(self, greenkey):
-        """Get the list of looptokens corresponding to the greenkey.
-        Turns the (internal) list of weakrefs into regular refs.
-        """
         cell = self.jitdriver_sd.warmstate.jit_cell_at_key(greenkey)
-        return cell.get_compiled_merge_points()
-
-    def set_compiled_merge_points(self, greenkey, looptokens):
-        cell = self.jitdriver_sd.warmstate.jit_cell_at_key(greenkey)
-        cell.set_compiled_merge_points(looptokens)
+        if cell.compiled_merge_points is None:
+            cell.compiled_merge_points = []
+        return cell.compiled_merge_points
 
     def compile(self, original_boxes, live_arg_boxes, start):
         num_green_args = self.jitdriver_sd.num_green_args
@@ -1830,7 +1795,6 @@
         loop_token = compile.compile_new_loop(self, old_loop_tokens,
                                               greenkey, start)
         if loop_token is not None: # raise if it *worked* correctly
-            self.set_compiled_merge_points(greenkey, old_loop_tokens)
             raise GenerateMergePoint(live_arg_boxes, loop_token)
         self.history.operations.pop()     # remove the JUMP
 
@@ -2321,8 +2285,6 @@
                 else:
                     raise AssertionError("bad argcode")
                 position += 1
-            elif argtype == "jitcode_position":
-                value = position
             else:
                 raise AssertionError("bad argtype: %r" % (argtype,))
             args += (value,)
@@ -2367,15 +2329,3 @@
     argtypes = unrolling_iterable(unboundmethod.argtypes)
     handler.func_name = 'handler_' + name
     return handler
-
-def put_back_list_of_boxes3(frame, position, newvalue):
-    code = frame.bytecode
-    length1 = ord(code[position])
-    position2 = position + 1 + length1
-    length2 = ord(code[position2])
-    position3 = position2 + 1 + length2
-    length3 = ord(code[position3])
-    assert len(newvalue) == length1 + length2 + length3
-    frame._put_back_list_of_boxes(newvalue, 0, position)
-    frame._put_back_list_of_boxes(newvalue, length1, position2)
-    frame._put_back_list_of_boxes(newvalue, length1 + length2, position3)

Modified: pypy/branch/jit-unroll-loops/pypy/jit/metainterp/test/test_basic.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/jit/metainterp/test/test_basic.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/jit/metainterp/test/test_basic.py	Sat Nov 27 14:45:32 2010
@@ -19,11 +19,7 @@
     from pypy.jit.metainterp import simple_optimize
 
     class FakeJitCell:
-        __compiled_merge_points = []
-        def get_compiled_merge_points(self):
-            return self.__compiled_merge_points[:]
-        def set_compiled_merge_points(self, lst):
-            self.__compiled_merge_points = lst
+        compiled_merge_points = None
 
     class FakeWarmRunnerState:
         def attach_unoptimized_bridge_from_interp(self, greenkey, newloop):
@@ -39,6 +35,7 @@
         optimize_bridge = staticmethod(simple_optimize.optimize_bridge)
 
         trace_limit = sys.maxint
+        debug_level = 2
 
     func._jit_unroll_safe_ = True
     rtyper = support.annotate(func, values, type_system=type_system)
@@ -1869,29 +1866,6 @@
         res = self.meta_interp(f, [5, 2])
         assert 4 < res < 14
 
-    def test_compute_identity_hash(self):
-        from pypy.rlib.objectmodel import compute_identity_hash
-        class A(object):
-            pass
-        def f():
-            a = A()
-            return compute_identity_hash(a) == compute_identity_hash(a)
-        res = self.interp_operations(f, [])
-        assert res
-        # a "did not crash" kind of test
-
-    def test_compute_unique_id(self):
-        from pypy.rlib.objectmodel import compute_unique_id
-        class A(object):
-            pass
-        def f():
-            a1 = A()
-            a2 = A()
-            return (compute_unique_id(a1) == compute_unique_id(a1) and
-                    compute_unique_id(a1) != compute_unique_id(a2))
-        res = self.interp_operations(f, [])
-        assert res
-
 
 class TestOOtype(BasicTests, OOJitMixin):
 

Modified: pypy/branch/jit-unroll-loops/pypy/jit/metainterp/test/test_compile.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/jit/metainterp/test/test_compile.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/jit/metainterp/test/test_compile.py	Sat Nov 27 14:45:32 2010
@@ -39,6 +39,7 @@
 
 class FakeState:
     optimize_loop = staticmethod(nounroll_optimize.optimize_loop)
+    debug_level = 0
 
     def attach_unoptimized_bridge_from_interp(*args):
         pass
@@ -53,7 +54,6 @@
 
     stats = Stats()
     profiler = jitprof.EmptyProfiler()
-    warmrunnerdesc = None
     def log(self, msg, event_kind=None):
         pass
 
@@ -207,12 +207,14 @@
         class ExitFrameWithExceptionRef(Exception):
             pass
     FakeMetaInterpSD.cpu = cpu
+    class FakeJitDriverSD:
+        pass
     cpu.set_future_value_int(0, -156)
     cpu.set_future_value_int(1, -178)
     cpu.set_future_value_int(2, -190)
     fail_descr = cpu.execute_token(loop_token)
     try:
-        fail_descr.handle_fail(FakeMetaInterpSD(), None)
+        fail_descr.handle_fail(FakeMetaInterpSD(), FakeJitDriverSD())
     except FakeMetaInterpSD.ExitFrameWithExceptionRef, e:
         assert lltype.cast_opaque_ptr(lltype.Ptr(EXC), e.args[1]) == llexc
     else:

Modified: pypy/branch/jit-unroll-loops/pypy/jit/metainterp/test/test_exception.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/jit/metainterp/test/test_exception.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/jit/metainterp/test/test_exception.py	Sat Nov 27 14:45:32 2010
@@ -1,6 +1,6 @@
 import py, sys
 from pypy.jit.metainterp.test.test_basic import LLJitMixin, OOJitMixin
-from pypy.rlib.jit import JitDriver, OPTIMIZER_SIMPLE, dont_look_inside
+from pypy.rlib.jit import JitDriver, OPTIMIZER_SIMPLE
 from pypy.rlib.rarithmetic import ovfcheck, LONG_BIT, intmask
 from pypy.jit.codewriter.policy import StopAtXPolicy
 
@@ -587,33 +587,6 @@
         res = self.interp_operations(f, [99])
         assert res == 21
 
-    def test_bug_exc1_noexc_exc2(self):
-        myjitdriver = JitDriver(greens=[], reds=['i'])
-        @dont_look_inside
-        def rescall(i):
-            if i < 10:
-                raise KeyError
-            if i < 20:
-                return None
-            raise ValueError
-        def f(i):
-            while i < 30:
-                myjitdriver.can_enter_jit(i=i)
-                myjitdriver.jit_merge_point(i=i)
-                try:
-                    rescall(i)
-                except KeyError:
-                    assert i < 10
-                except ValueError:
-                    assert i >= 20
-                else:
-                    assert 10 <= i < 20
-                i += 1
-            return i
-        res = self.meta_interp(f, [0], inline=True)
-        assert res == 30
-
-
 class MyError(Exception):
     def __init__(self, n):
         self.n = n

Modified: pypy/branch/jit-unroll-loops/pypy/jit/metainterp/test/test_logger.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/jit/metainterp/test/test_logger.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/jit/metainterp/test/test_logger.py	Sat Nov 27 14:45:32 2010
@@ -14,20 +14,11 @@
 
 def capturing(func, *args, **kwds):
     log_stream = StringIO()
-    class MyDebugLog:
-        def debug_print(self, *args):
-            for arg in args:
-                print >> log_stream, arg,
-            print >> log_stream
-        def debug_start(self, *args):
-            pass
-        def debug_stop(self, *args):
-            pass
+    debug._stderr = log_stream
     try:
-        debug._log = MyDebugLog()
         func(*args, **kwds)
     finally:
-        debug._log = None
+        debug._stderr = sys.stderr
     return log_stream.getvalue()
 
 class Logger(logger.Logger):
@@ -121,8 +112,7 @@
         equaloplists(loop.operations, oloop.operations)
 
     def test_jump(self):
-        namespace = {'target': LoopToken()}
-        namespace['target'].number = 3
+        namespace = {'target': LoopToken(3)}
         inp = '''
         [i0]
         jump(i0, descr=target)

Modified: pypy/branch/jit-unroll-loops/pypy/jit/metainterp/test/test_optimizeopt.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/jit/metainterp/test/test_optimizeopt.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/jit/metainterp/test/test_optimizeopt.py	Sat Nov 27 14:45:32 2010
@@ -34,7 +34,7 @@
     b1 = BoxInt()
     opt = optimizeopt.Optimizer(FakeMetaInterpStaticData(LLtypeMixin.cpu),
                                 None)
-    fdescr = ResumeGuardDescr()
+    fdescr = ResumeGuardDescr(None)
     op = ResOperation(rop.GUARD_TRUE, ['dummy'], None, descr=fdescr)
     # setup rd data
     fi0 = resume.FrameInfo(None, "code0", 11)
@@ -846,12 +846,8 @@
         i3 = call(i2, descr=nonwritedescr)
         jump(i1)       # the exception is considered lost when we loop back
         """
-        # note that 'guard_no_exception' at the very start must be kept
-        # around: bridges may start with one.  (In case of loops we could
-        # remove it, but we probably don't care.)
         expected = """
         [i]
-        guard_no_exception() []
         i1 = int_add(i, 3)
         i2 = call(i1, descr=nonwritedescr)
         guard_no_exception() [i1, i2]

Modified: pypy/branch/jit-unroll-loops/pypy/jit/metainterp/test/test_pyjitpl.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/jit/metainterp/test/test_pyjitpl.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/jit/metainterp/test/test_pyjitpl.py	Sat Nov 27 14:45:32 2010
@@ -17,7 +17,6 @@
     portal.setup(None)
     class FakeStaticData:
         cpu = None
-        warmrunnerdesc = None
 
     metainterp = pyjitpl.MetaInterp(FakeStaticData(), None)
     metainterp.framestack = []
@@ -54,7 +53,6 @@
 def test_remove_consts_and_duplicates():
     class FakeStaticData:
         cpu = None
-        warmrunnerdesc = None
     def is_another_box_like(box, referencebox):
         assert box is not referencebox
         assert isinstance(box, referencebox.clonebox().__class__)

Modified: pypy/branch/jit-unroll-loops/pypy/jit/metainterp/test/test_recursive.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/jit/metainterp/test/test_recursive.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/jit/metainterp/test/test_recursive.py	Sat Nov 27 14:45:32 2010
@@ -1142,19 +1142,6 @@
             res = self.meta_interp(main, [], inline=True, trace_limit=tlimit)
             assert ''.join(res.chars) == 'ABCDEFGHIabcdefghijJ' * 5
 
-    def test_no_duplicates_bug(self):
-        driver = JitDriver(greens = ['codeno'], reds = ['i'],
-                           get_printable_location = lambda codeno: str(codeno))
-        def portal(codeno, i):
-            while i > 0:
-                driver.can_enter_jit(codeno=codeno, i=i)
-                driver.jit_merge_point(codeno=codeno, i=i)
-                if codeno > 0:
-                    break
-                portal(i, i)
-                i -= 1
-        self.meta_interp(portal, [0, 10], inline=True)
-
 
 class TestLLtype(RecursiveTests, LLJitMixin):
     pass

Modified: pypy/branch/jit-unroll-loops/pypy/jit/metainterp/test/test_warmspot.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/jit/metainterp/test/test_warmspot.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/jit/metainterp/test/test_warmspot.py	Sat Nov 27 14:45:32 2010
@@ -132,6 +132,91 @@
         assert state.optimize_loop is optimize.optimize_loop
         assert state.optimize_bridge is optimize.optimize_bridge
 
+    def test_static_debug_level(self, capfd):
+        py.test.skip("debug_level is being deprecated")
+        from pypy.rlib.jit import DEBUG_PROFILE, DEBUG_OFF, DEBUG_STEPS
+        from pypy.jit.metainterp.jitprof import EmptyProfiler, Profiler
+        
+        myjitdriver = JitDriver(greens = [], reds = ['n'])
+        def f(n):
+            while n > 0:
+                myjitdriver.can_enter_jit(n=n)
+                myjitdriver.jit_merge_point(n=n)
+                n -= 1
+            return n
+
+        capfd.readouterr()
+        self.meta_interp(f, [10], debug_level=DEBUG_OFF,
+                                  ProfilerClass=Profiler)
+        out, err = capfd.readouterr()
+        assert not 'ENTER' in err
+        assert not 'LEAVE' in err
+        assert not "Running asm" in err
+        self.meta_interp(f, [10], debug_level=DEBUG_PROFILE,
+                                  ProfilerClass=Profiler)
+        out, err = capfd.readouterr()
+        assert not 'ENTER' in err
+        assert not 'LEAVE' in err
+        assert not 'compiled new' in err
+        assert "Running asm" in err
+
+        self.meta_interp(f, [10], debug_level=DEBUG_STEPS,
+                                  ProfilerClass=Profiler)
+        out, err = capfd.readouterr()
+        assert 'ENTER' in err
+        assert 'LEAVE' in err
+        assert "Running asm" in err
+
+        self.meta_interp(f, [10], debug_level=DEBUG_STEPS,
+                                  ProfilerClass=EmptyProfiler)
+        out, err = capfd.readouterr()
+        assert 'ENTER' in err
+        assert 'LEAVE' in err
+        assert not "Running asm" in err
+
+    def test_set_param_debug(self):
+        py.test.skip("debug_level is being deprecated")
+        from pypy.rlib.jit import DEBUG_PROFILE, DEBUG_OFF, DEBUG_STEPS
+        from pypy.jit.metainterp.jitprof import EmptyProfiler, Profiler
+        
+        myjitdriver = JitDriver(greens = [], reds = ['n'])
+        def f(n):
+            while n > 0:
+                myjitdriver.can_enter_jit(n=n)
+                myjitdriver.jit_merge_point(n=n)
+                n -= 1
+            return n
+
+        def main(n, debug):
+            myjitdriver.set_param("debug", debug)
+            print f(n)
+
+        outerr = py.io.StdCaptureFD()
+        self.meta_interp(main, [10, DEBUG_OFF], debug_level=DEBUG_STEPS,
+                                                ProfilerClass=Profiler)
+        out, errf = outerr.done()
+        err = errf.read()
+        assert not 'ENTER' in err
+        assert not 'LEAVE' in err
+        assert not "Running asm" in err
+        outerr = py.io.StdCaptureFD()
+        self.meta_interp(main, [10, DEBUG_PROFILE], debug_level=DEBUG_STEPS,
+                                                    ProfilerClass=Profiler)
+        out, errf = outerr.done()
+        err = errf.read()
+        assert not 'ENTER' in err
+        assert not 'LEAVE' in err
+        assert not 'compiled new' in err
+        assert "Running asm" in err
+        outerr = py.io.StdCaptureFD()
+        self.meta_interp(main, [10, DEBUG_STEPS], debug_level=DEBUG_OFF,
+                                                  ProfilerClass=Profiler)
+        out, errf = outerr.done()
+        err = errf.read()
+        assert 'ENTER' in err
+        assert 'LEAVE' in err
+        assert "Running asm" in err
+
     def test_unwanted_loops(self):
         mydriver = JitDriver(reds = ['n', 'total', 'm'], greens = [])
 
@@ -293,30 +378,23 @@
         exc_vtable = lltype.malloc(OBJECT_VTABLE, immortal=True)
         cls.exc_vtable = exc_vtable
 
-        class FakeLoopToken:
+        class FakeFailDescr(object):
             def __init__(self, no):
                 self.no = no
-                self.generation = 0
-
-        class FakeFailDescr(object):
-            def __init__(self, looptoken):
-                assert isinstance(looptoken, FakeLoopToken)
-                self.looptoken = looptoken
             
             def handle_fail(self, metainterp_sd, jitdrivers_sd):
-                no = self.looptoken.no
-                if no == 0:
+                if self.no == 0:
                     raise metainterp_sd.warmrunnerdesc.DoneWithThisFrameInt(3)
-                if no == 1:
+                if self.no == 1:
                     raise metainterp_sd.warmrunnerdesc.ContinueRunningNormally(
                         [0], [], [], [1], [], [])
-                if no == 3:
+                if self.no == 3:
                     exc = lltype.malloc(OBJECT)
                     exc.typeptr = exc_vtable
                     raise metainterp_sd.warmrunnerdesc.ExitFrameWithExceptionRef(
                         metainterp_sd.cpu,
                         lltype.cast_opaque_ptr(llmemory.GCREF, exc))
-                return self.looptoken
+                return self.no
 
         class FakeDescr:
             def as_vtable_size_descr(self):
@@ -341,11 +419,11 @@
             sizeof       = nodescr
 
             def get_fail_descr_from_number(self, no):
-                return FakeFailDescr(FakeLoopToken(no))
+                return FakeFailDescr(no)
 
             def execute_token(self, token):
-                assert token.no == 2
-                return FakeFailDescr(FakeLoopToken(1))
+                assert token == 2
+                return FakeFailDescr(1)
 
         driver = JitDriver(reds = ['red'], greens = ['green'])
         

Modified: pypy/branch/jit-unroll-loops/pypy/jit/metainterp/test/test_warmstate.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/jit/metainterp/test/test_warmstate.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/jit/metainterp/test/test_warmstate.py	Sat Nov 27 14:45:32 2010
@@ -99,8 +99,6 @@
                                          lltype.Float], lltype.Void))
     class FakeWarmRunnerDesc:
         rtyper = FakeRTyper()
-        cpu = None
-        memory_manager = None
     class FakeJitDriverSD:
         _get_jitcell_at_ptr = llhelper(GETTER, getter)
         _set_jitcell_at_ptr = llhelper(SETTER, setter)
@@ -128,7 +126,6 @@
             future_values[j] = "float", value
     class FakeWarmRunnerDesc:
         cpu = FakeCPU()
-        memory_manager = None
     class FakeJitDriverSD:
         _red_args_types = ["int", "float"]
         virtualizable_info = None
@@ -157,20 +154,16 @@
         _get_jitcell_at_ptr = None
     state = WarmEnterState(None, FakeJitDriverSD())
     get_jitcell = state.make_jitcell_getter()
-    class FakeLoopToken(object):
-        pass
-    looptoken = FakeLoopToken()
     state.attach_unoptimized_bridge_from_interp([ConstInt(5),
                                                  ConstFloat(2.25)],
-                                                looptoken)
+                                                "entry loop token")
     cell1 = get_jitcell(True, 5, 2.25)
     assert cell1.counter < 0
-    assert cell1.get_entry_loop_token() is looptoken
+    assert cell1.entry_loop_token == "entry loop token"
 
 def test_make_jitdriver_callbacks_1():
     class FakeWarmRunnerDesc:
         cpu = None
-        memory_manager = None
     class FakeJitDriverSD:
         _green_args_spec = [lltype.Signed, lltype.Float]
         _get_printable_location_ptr = None
@@ -196,7 +189,6 @@
     class FakeWarmRunnerDesc:
         rtyper = None
         cpu = None
-        memory_manager = None
     class FakeJitDriverSD:
         _green_args_spec = [lltype.Signed, lltype.Float]
         _get_printable_location_ptr = llhelper(GET_LOCATION, get_location)
@@ -219,7 +211,6 @@
     class FakeWarmRunnerDesc:
         rtyper = None
         cpu = None
-        memory_manager = None
     class FakeJitDriverSD:
         _green_args_spec = [lltype.Signed, lltype.Float]
         _get_printable_location_ptr = None
@@ -242,7 +233,6 @@
     class FakeWarmRunnerDesc:
         rtyper = None
         cpu = None
-        memory_manager = None
     class FakeJitDriverSD:
         _green_args_spec = [lltype.Signed, lltype.Float]
         _get_printable_location_ptr = None

Modified: pypy/branch/jit-unroll-loops/pypy/jit/metainterp/warmspot.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/jit/metainterp/warmspot.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/jit/metainterp/warmspot.py	Sat Nov 27 14:45:32 2010
@@ -12,12 +12,11 @@
 from pypy.rlib.unroll import unrolling_iterable
 from pypy.rlib.rarithmetic import r_uint, intmask
 from pypy.rlib.debug import debug_print, fatalerror
-from pypy.rlib.debug import debug_start, debug_stop
 from pypy.rpython.lltypesystem.lloperation import llop
 from pypy.translator.simplify import get_funcobj, get_functype
 from pypy.translator.unsimplify import call_final_function
 
-from pypy.jit.metainterp import history, pyjitpl, gc, memmgr
+from pypy.jit.metainterp import history, pyjitpl, gc
 from pypy.jit.metainterp.pyjitpl import MetaInterpStaticData, MetaInterp
 from pypy.jit.metainterp.typesystem import LLTypeHelper, OOTypeHelper
 from pypy.jit.metainterp.jitprof import Profiler, EmptyProfiler
@@ -25,17 +24,21 @@
 from pypy.jit.metainterp.jitdriver import JitDriverStaticData
 from pypy.jit.codewriter import support, codewriter
 from pypy.jit.codewriter.policy import JitPolicy
+from pypy.rlib.jit import DEBUG_STEPS, DEBUG_DETAILED, DEBUG_OFF, DEBUG_PROFILE
 
 # ____________________________________________________________
 # Bootstrapping
 
-def apply_jit(translator, backend_name="auto", inline=False, **kwds):
+def apply_jit(translator, backend_name="auto", debug_level=DEBUG_STEPS,
+              inline=False,
+              **kwds):
     if 'CPUClass' not in kwds:
         from pypy.jit.backend.detect_cpu import getcpuclass
         kwds['CPUClass'] = getcpuclass(backend_name)
-    ProfilerClass = Profiler
-    # Always use Profiler here, which should have a very low impact.
-    # Otherwise you can try with ProfilerClass = EmptyProfiler.
+    if debug_level > DEBUG_OFF:
+        ProfilerClass = Profiler
+    else:
+        ProfilerClass = EmptyProfiler
     warmrunnerdesc = WarmRunnerDesc(translator,
                                     translate_support_code=True,
                                     listops=True,
@@ -44,6 +47,7 @@
                                     **kwds)
     for jd in warmrunnerdesc.jitdrivers_sd:
         jd.warmstate.set_param_inlining(inline)
+        jd.warmstate.set_param_debug(debug_level)
     warmrunnerdesc.finish()
     translator.warmrunnerdesc = warmrunnerdesc    # for later debugging
 
@@ -62,7 +66,7 @@
 
 def jittify_and_run(interp, graph, args, repeat=1,
                     backendopt=False, trace_limit=sys.maxint,
-                    inline=False, loop_longevity=0, **kwds):
+                    debug_level=DEBUG_STEPS, inline=False, **kwds):
     from pypy.config.config import ConfigError
     translator = interp.typer.annotator.translator
     try:
@@ -79,7 +83,7 @@
         jd.warmstate.set_param_trace_eagerness(2)    # for tests
         jd.warmstate.set_param_trace_limit(trace_limit)
         jd.warmstate.set_param_inlining(inline)
-        jd.warmstate.set_param_loop_longevity(loop_longevity)
+        jd.warmstate.set_param_debug(debug_level)
     warmrunnerdesc.finish()
     res = interp.eval_graph(graph, args)
     if not kwds.get('translate_support_code', False):
@@ -147,7 +151,6 @@
                  optimizer=None, ProfilerClass=EmptyProfiler, **kwds):
         pyjitpl._warmrunnerdesc = self   # this is a global for debugging only!
         self.set_translator(translator)
-        self.memory_manager = memmgr.MemoryManager()
         self.build_cpu(CPUClass, **kwds)
         self.find_portals()
         self.codewriter = codewriter.CodeWriter(self.cpu, self.jitdrivers_sd)
@@ -710,7 +713,7 @@
                     loop_token = fail_descr.handle_fail(self.metainterp_sd, jd)
                 except JitException, e:
                     return handle_jitexception(e)
-                fail_descr = self.execute_token(loop_token)
+                fail_descr = self.cpu.execute_token(loop_token)
 
         jd._assembler_call_helper = assembler_call_helper # for debugging
         jd._assembler_helper_ptr = self.helper_func(
@@ -804,10 +807,3 @@
             py.test.skip("rewrite_force_virtual: port it to ootype")
         all_graphs = self.translator.graphs
         vrefinfo.replace_force_virtual_with_call(all_graphs)
-
-    # ____________________________________________________________
-
-    def execute_token(self, loop_token):
-        fail_descr = self.cpu.execute_token(loop_token)
-        self.memory_manager.keep_loop_alive(loop_token)
-        return fail_descr

Modified: pypy/branch/jit-unroll-loops/pypy/jit/metainterp/warmstate.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/jit/metainterp/warmstate.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/jit/metainterp/warmstate.py	Sat Nov 27 14:45:32 2010
@@ -1,4 +1,4 @@
-import sys, weakref
+import sys
 from pypy.rpython.lltypesystem import lltype, llmemory, rstr, rffi
 from pypy.rpython.ootypesystem import ootype
 from pypy.rpython.annlowlevel import hlstr, llstr, cast_base_ptr_to_instance
@@ -9,6 +9,7 @@
 from pypy.rlib.unroll import unrolling_iterable
 from pypy.rlib.jit import (PARAMETERS, OPTIMIZER_SIMPLE, OPTIMIZER_FULL,
                            OPTIMIZER_NO_UNROLL)
+from pypy.rlib.jit import DEBUG_PROFILE
 from pypy.rlib.jit import BaseJitCell
 from pypy.rlib.debug import debug_start, debug_stop, debug_print
 from pypy.jit.metainterp import history
@@ -149,34 +150,9 @@
     #     counter == -1: there is an entry bridge for this cell
     #     counter == -2: tracing is currently going on for this cell
     counter = 0
-    compiled_merge_points_wref = None    # list of weakrefs to LoopToken
+    compiled_merge_points = None
     dont_trace_here = False
-    wref_entry_loop_token = None         # (possibly) one weakref to LoopToken
-
-    def get_compiled_merge_points(self):
-        result = []
-        if self.compiled_merge_points_wref is not None:
-            for wref in self.compiled_merge_points_wref:
-                looptoken = wref()
-                if looptoken is not None:
-                    result.append(looptoken)
-        return result
-
-    def set_compiled_merge_points(self, looptokens):
-        self.compiled_merge_points_wref = [self._makeref(token)
-                                           for token in looptokens]
-
-    def get_entry_loop_token(self):
-        if self.wref_entry_loop_token is not None:
-            return self.wref_entry_loop_token()
-        return None
-
-    def set_entry_loop_token(self, looptoken):
-        self.wref_entry_loop_token = self._makeref(looptoken)
-
-    def _makeref(self, looptoken):
-        assert looptoken is not None
-        return weakref.ref(looptoken)
+    entry_loop_token = None
 
 # ____________________________________________________________
 
@@ -189,8 +165,6 @@
         "NOT_RPYTHON"
         self.warmrunnerdesc = warmrunnerdesc
         self.jitdriver_sd = jitdriver_sd
-        if warmrunnerdesc is not None:       # for tests
-            self.cpu = warmrunnerdesc.cpu
         try:
             self.profiler = warmrunnerdesc.metainterp_sd.profiler
         except AttributeError:       # for tests
@@ -202,7 +176,7 @@
             meth(default_value)
 
     def set_param_threshold(self, threshold):
-        if threshold <= 0:
+        if threshold < 0:
             self.increment_threshold = 0   # never reach the THRESHOLD_LIMIT
             return
         if threshold < 2:
@@ -235,11 +209,10 @@
         else:
             raise ValueError("unknown optimizer")
 
-    def set_param_loop_longevity(self, value):
-        # note: it's a global parameter, not a per-jitdriver one
-        if (self.warmrunnerdesc is not None and
-            self.warmrunnerdesc.memory_manager is not None):   # all for tests
-            self.warmrunnerdesc.memory_manager.set_max_age(value)
+    def set_param_debug(self, value):
+        self.debug_level = value
+        if self.profiler is not None:
+            self.profiler.set_printing(value >= DEBUG_PROFILE)
 
     def disable_noninlinable_function(self, greenkey):
         cell = self.jit_cell_at_key(greenkey)
@@ -252,15 +225,12 @@
     def attach_unoptimized_bridge_from_interp(self, greenkey,
                                               entry_loop_token):
         cell = self.jit_cell_at_key(greenkey)
-        old_token = cell.get_entry_loop_token()
-        cell.set_entry_loop_token(entry_loop_token)
-        cell.counter = -1       # valid entry bridge attached
+        cell.counter = -1
+        old_token = cell.entry_loop_token
+        cell.entry_loop_token = entry_loop_token
         if old_token is not None:
-            self.cpu.redirect_call_assembler(old_token, entry_loop_token)
-            # entry_loop_token is also kept alive by any loop that used
-            # to point to old_token.  Actually freeing old_token early
-            # is a pointless optimization (it is tiny).
-            old_token.record_jump_to(entry_loop_token)
+            cpu = self.warmrunnerdesc.cpu
+            cpu.redirect_call_assembler(old_token, entry_loop_token)
 
     # ----------
 
@@ -269,8 +239,7 @@
         if hasattr(self, 'maybe_compile_and_run'):
             return self.maybe_compile_and_run
 
-        warmrunnerdesc = self.warmrunnerdesc
-        metainterp_sd = warmrunnerdesc.metainterp_sd
+        metainterp_sd = self.warmrunnerdesc.metainterp_sd
         jitdriver_sd = self.jitdriver_sd
         vinfo = jitdriver_sd.virtualizable_info
         index_of_virtualizable = jitdriver_sd.index_of_virtualizable
@@ -328,27 +297,23 @@
                 assert cell.counter == -1
                 if not confirm_enter_jit(*args):
                     return
-                loop_token = cell.get_entry_loop_token()
-                if loop_token is None:   # it was a weakref that has been freed
-                    cell.counter = 0
-                    return
                 # machine code was already compiled for these greenargs
                 # get the assembler and fill in the boxes
                 set_future_values(*args[num_green_args:])
+                loop_token = cell.entry_loop_token
 
             # ---------- execute assembler ----------
             while True:     # until interrupted by an exception
                 metainterp_sd.profiler.start_running()
                 debug_start("jit-running")
-                fail_descr = warmrunnerdesc.execute_token(loop_token)
+                fail_descr = metainterp_sd.cpu.execute_token(loop_token)
                 debug_stop("jit-running")
                 metainterp_sd.profiler.end_running()
-                loop_token = None     # for test_memmgr
                 if vinfo is not None:
                     vinfo.reset_vable_token(virtualizable)
                 loop_token = fail_descr.handle_fail(metainterp_sd,
                                                     jitdriver_sd)
-
+       
         maybe_compile_and_run._dont_inline_ = True
         self.maybe_compile_and_run = maybe_compile_and_run
         return maybe_compile_and_run
@@ -494,7 +459,7 @@
 
         warmrunnerdesc = self.warmrunnerdesc
         jitdriver_sd   = self.jitdriver_sd
-        cpu = self.cpu
+        cpu = warmrunnerdesc.cpu
         vinfo = jitdriver_sd.virtualizable_info
         red_args_types = unrolling_iterable(jitdriver_sd._red_args_types)
         #
@@ -543,11 +508,10 @@
         if hasattr(self, 'get_location_str'):
             return
         #
-        warmrunnerdesc = self.warmrunnerdesc
         unwrap_greenkey = self.make_unwrap_greenkey()
         jit_getter = self.make_jitcell_getter()
         jd = self.jitdriver_sd
-        cpu = self.cpu
+        cpu = self.warmrunnerdesc.cpu
 
         def can_inline_greenargs(*greenargs):
             if can_never_inline(*greenargs):
@@ -565,16 +529,11 @@
         def get_assembler_token(greenkey, redboxes):
             # 'redboxes' is only used to know the types of red arguments
             cell = self.jit_cell_at_key(greenkey)
-            entry_loop_token = cell.get_entry_loop_token()
-            if entry_loop_token is None:
+            if cell.entry_loop_token is None:
                 from pypy.jit.metainterp.compile import compile_tmp_callback
-                if cell.counter == -1:    # used to be a valid entry bridge,
-                    cell.counter = 0      # but was freed in the meantime.
-                memmgr = warmrunnerdesc.memory_manager
-                entry_loop_token = compile_tmp_callback(cpu, jd, greenkey,
-                                                        redboxes, memmgr)
-                cell.set_entry_loop_token(entry_loop_token)
-            return entry_loop_token
+                cell.entry_loop_token = compile_tmp_callback(cpu, jd, greenkey,
+                                                             redboxes)
+            return cell.entry_loop_token
         self.get_assembler_token = get_assembler_token
         
         #

Modified: pypy/branch/jit-unroll-loops/pypy/jit/tool/jitoutput.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/jit/tool/jitoutput.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/jit/tool/jitoutput.py	Sat Nov 27 14:45:32 2010
@@ -27,10 +27,6 @@
     (('nvirtuals',), '^nvirtuals:\s+(\d+)$'),
     (('nvholes',), '^nvholes:\s+(\d+)$'),
     (('nvreused',), '^nvreused:\s+(\d+)$'),
-    (('total_compiled_loops',),   '^Total # of loops:\s+(\d+)$'),
-    (('total_compiled_bridges',), '^Total # of bridges:\s+(\d+)$'),
-    (('total_freed_loops',),      '^Freed # of loops:\s+(\d+)$'),
-    (('total_freed_bridges',),    '^Freed # of bridges:\s+(\d+)$'),
     ]
 
 class Ops(object):

Modified: pypy/branch/jit-unroll-loops/pypy/jit/tool/loopcounter.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/jit/tool/loopcounter.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/jit/tool/loopcounter.py	Sat Nov 27 14:45:32 2010
@@ -7,41 +7,32 @@
 import py
 import sys
 import optparse
-import re
 
 def get_timestamp(line):
+    import re
     match = re.match(r'\[([0-9a-f]*)\] .*', line)
     return int(match.group(1), 16)
 
-def count_loops_and_bridges(log):
+def main(logfile, options):
+    log = open(logfile)
     loops = 0
     bridges = 0
     time0 = None
-    lines = iter(log)
-    for line in lines:
+    print 'timestamp,total,loops,bridges'
+    for line in log:
         if time0 is None and line.startswith('['):
             time0 = get_timestamp(line)
-        if '{jit-mem-looptoken-' in line:
-            time_now = get_timestamp(line) - time0
-            text = lines.next()
-            if text.startswith('allocating Loop #'):
+        if '{jit-log-opt-' in line:
+            time_now = get_timestamp(line)
+            if '{jit-log-opt-loop' in line:
                 loops += 1
-            elif text.startswith('allocating Bridge #'):
+            elif '{jit-log-opt-bridge' in line:
                 bridges += 1
-            elif text.startswith('freeing Loop #'):
-                match = re.match('freeing Loop # .* with ([0-9]*) attached bridges\n', text)
-                loops -=1
-                bridges -= int(match.group(1))
             else:
-                assert False, 'unknown line' % line
+                assert False, 'unknown category %s' % line
             total = loops+bridges
-            yield (time_now, total, loops, bridges)
-
-def main(logfile, options):
-    print 'timestamp,total,loops,bridges'
-    log = open(logfile)
-    for timestamp, total, loops, bridges in count_loops_and_bridges(log):
-        print '%d,%d,%d,%d' % (timestamp, total, loops, bridges)        
+            timestamp = time_now - time0
+            print '%d,%d,%d,%d' % (timestamp, total, loops, bridges)
 
 if __name__ == '__main__':
     parser = optparse.OptionParser(usage="%prog loopfile [options]")
@@ -49,4 +40,5 @@
     if len(args) != 1:
         parser.print_help()
         sys.exit(2)
+
     main(args[0], options)

Modified: pypy/branch/jit-unroll-loops/pypy/jit/tool/test/test_jitoutput.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/jit/tool/test/test_jitoutput.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/jit/tool/test/test_jitoutput.py	Sat Nov 27 14:45:32 2010
@@ -1,11 +1,10 @@
 
 import py
 from pypy.jit.metainterp.warmspot import ll_meta_interp
-from pypy.rlib.jit import JitDriver
+from pypy.rlib.jit import JitDriver, DEBUG_PROFILE
 from pypy.jit.backend.llgraph import runner
 from pypy.jit.metainterp.jitprof import Profiler, JITPROF_LINES
 from pypy.jit.tool.jitoutput import parse_prof
-from pypy.tool.logparser import parse_log, extract_category
 
 def test_really_run():
     """ This test checks whether output of jitprof did not change.
@@ -22,15 +21,13 @@
     cap = py.io.StdCaptureFD()
     try:
         ll_meta_interp(f, [10], CPUClass=runner.LLtypeCPU, type_system='lltype',
-                       ProfilerClass=Profiler)
+                       ProfilerClass=Profiler, debug_level=DEBUG_PROFILE)
     finally:
         out, err = cap.reset()
-
-    log = parse_log(err.splitlines(True))
-    err_sections = list(extract_category(log, 'jit-summary'))
-    [err1] = err_sections    # there should be exactly one jit-summary
-    assert err1.count("\n") == JITPROF_LINES
-    info = parse_prof(err1)
+    err = "\n".join(err.splitlines()[-JITPROF_LINES:])
+    print err
+    assert err.count("\n") == JITPROF_LINES - 1
+    info = parse_prof(err)
     # assert did not crash
     # asserts below are a bit delicate, possibly they might be deleted
     assert info.tracing_no == 1
@@ -63,10 +60,6 @@
 nvirtuals:              13
 nvholes:                14
 nvreused:               15
-Total # of loops:       100
-Total # of bridges:     300
-Freed # of loops:       99
-Freed # of bridges:     299
 '''
 
 def test_parse():

Modified: pypy/branch/jit-unroll-loops/pypy/module/__pypy__/__init__.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/module/__pypy__/__init__.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/module/__pypy__/__init__.py	Sat Nov 27 14:45:32 2010
@@ -11,10 +11,6 @@
         'internal_repr'             : 'interp_magic.internal_repr',
         'bytebuffer'                : 'bytebuffer.bytebuffer',
         'identity_dict'             : 'interp_identitydict.W_IdentityDict',
-        'debug_start'               : 'interp_debug.debug_start',
-        'debug_print'               : 'interp_debug.debug_print',
-        'debug_stop'                : 'interp_debug.debug_stop',
-        'debug_print_once'          : 'interp_debug.debug_print_once',
     }
 
     def setup_after_space_initialization(self):

Modified: pypy/branch/jit-unroll-loops/pypy/module/_pickle_support/maker.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/module/_pickle_support/maker.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/module/_pickle_support/maker.py	Sat Nov 27 14:45:32 2010
@@ -67,12 +67,11 @@
     return space.wrap(tb)
 traceback_new.unwrap_spec = [ObjSpace]
 
-def generator_new(space, w_frame, running):
-    frame = space.interp_w(PyFrame, w_frame, can_be_None=True)
+def generator_new(space, frame, running):
     new_generator = GeneratorIterator(frame)
     new_generator.running = running
     return space.wrap(new_generator)
-generator_new.unwrap_spec = [ObjSpace, W_Root, int]
+generator_new.unwrap_spec = [ObjSpace, PyFrame, int]
 
 def xrangeiter_new(space, current, remaining, step):
     from pypy.module.__builtin__.functional import W_XRangeIterator

Modified: pypy/branch/jit-unroll-loops/pypy/module/cpyext/test/test_typeobject.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/module/cpyext/test/test_typeobject.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/module/cpyext/test/test_typeobject.py	Sat Nov 27 14:45:32 2010
@@ -206,7 +206,6 @@
         del obj.x
         assert obj.z == prop
 
-    @py.test.mark.dont_track_allocations
     def test_tp_dict(self):
         foo = self.import_module("foo")
         module = self.import_extension('test', [

Modified: pypy/branch/jit-unroll-loops/pypy/module/itertools/interp_itertools.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/module/itertools/interp_itertools.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/module/itertools/interp_itertools.py	Sat Nov 27 14:45:32 2010
@@ -391,8 +391,7 @@
         self.iterators_w = iterators_w
         self.current_iterator = 0
         self.num_iterators = len(iterators_w)
-        if self.num_iterators > 0:
-            self.w_it = iterators_w[0]
+        self.started = False
 
     def iter_w(self):
         return self.space.wrap(self)
@@ -400,23 +399,26 @@
     def next_w(self):
         if self.current_iterator >= self.num_iterators:
             raise OperationError(self.space.w_StopIteration, self.space.w_None)
-        try:
-            return self.space.next(self.w_it)
-        except OperationError, e:
-            return self._handle_error(e)
+        if not self.started:
+            self.current_iterator = 0
+            self.w_it = self.iterators_w[self.current_iterator]
+            self.started = True
 
-    def _handle_error(self, e):
         while True:
-            if not e.match(self.space, self.space.w_StopIteration):
-                raise e
-            self.current_iterator += 1
-            if self.current_iterator >= self.num_iterators:
-                raise e
-            self.w_it = self.iterators_w[self.current_iterator]
             try:
-                return self.space.next(self.w_it)
+                w_obj = self.space.next(self.w_it)
             except OperationError, e:
-                pass   # loop back to the start of _handle_error(e)
+                if e.match(self.space, self.space.w_StopIteration):
+                    self.current_iterator += 1
+                    if self.current_iterator >= self.num_iterators:
+                        raise OperationError(self.space.w_StopIteration, self.space.w_None)
+                    else:
+                        self.w_it = self.iterators_w[self.current_iterator]
+                else:
+                    raise
+            else:
+                break
+        return w_obj
 
 def W_Chain___new__(space, w_subtype, args_w):
     return space.wrap(W_Chain(space, args_w))
@@ -444,10 +446,8 @@
 
     def __init__(self, space, w_fun, args_w):
         self.space = space
-        if self.space.is_w(w_fun, space.w_None):
-            self.w_fun = None
-        else:
-            self.w_fun = w_fun
+        self.identity_fun = (self.space.is_w(w_fun, space.w_None))
+        self.w_fun = w_fun
 
         iterators_w = []
         i = 0
@@ -470,26 +470,12 @@
         return self.space.wrap(self)
 
     def next_w(self):
-        # common case: 1 or 2 arguments
-        iterators_w = self.iterators_w
-        length = len(iterators_w)
-        if length == 1:
-            objects = [self.space.next(iterators_w[0])]
-        elif length == 2:
-            objects = [self.space.next(iterators_w[0]),
-                       self.space.next(iterators_w[1])]
-        else:
-            objects = self._get_objects()
-        w_objects = self.space.newtuple(objects)
-        if self.w_fun is None:
+        w_objects = self.space.newtuple([self.space.next(w_it) for w_it in self.iterators_w])
+        if self.identity_fun:
             return w_objects
         else:
             return self.space.call(self.w_fun, w_objects)
 
-    def _get_objects(self):
-        # the loop is out of the way of the JIT
-        return [self.space.next(w_elem) for w_elem in self.iterators_w]
-
 
 def W_IMap___new__(space, w_subtype, w_fun, args_w):
     if len(args_w) == 0:
@@ -783,7 +769,15 @@
             raise OperationError(self.space.w_StopIteration, self.space.w_None)
 
         if not self.new_group:
-            self._consume_unwanted_input()
+            # Consume unwanted input until we reach the next group
+            try:
+                while True:
+                    self.group_next(self.index)
+
+            except StopIteration:
+                pass
+            if self.exhausted:
+                raise OperationError(self.space.w_StopIteration, self.space.w_None)
 
         if not self.started:
             self.started = True
@@ -805,16 +799,6 @@
         w_iterator = self.space.wrap(W_GroupByIterator(self.space, self.index, self))
         return self.space.newtuple([self.w_key, w_iterator])
 
-    def _consume_unwanted_input(self):
-        # Consume unwanted input until we reach the next group
-        try:
-            while True:
-                self.group_next(self.index)
-        except StopIteration:
-            pass
-        if self.exhausted:
-            raise OperationError(self.space.w_StopIteration, self.space.w_None)
-
     def group_next(self, group_index):
         if group_index < self.index:
             raise StopIteration

Modified: pypy/branch/jit-unroll-loops/pypy/module/pypyjit/__init__.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/module/pypyjit/__init__.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/module/pypyjit/__init__.py	Sat Nov 27 14:45:32 2010
@@ -15,5 +15,6 @@
         # add the 'defaults' attribute
         from pypy.rlib.jit import PARAMETERS
         space = self.space
+        # XXX this is not really the default compiled into a pypy-c-jit XXX
         w_obj = space.wrap(PARAMETERS)
         space.setattr(space.wrap(self), space.wrap('defaults'), w_obj)

Modified: pypy/branch/jit-unroll-loops/pypy/module/pypyjit/policy.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/module/pypyjit/policy.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/module/pypyjit/policy.py	Sat Nov 27 14:45:32 2010
@@ -12,13 +12,19 @@
         if '.' in modname:
             modname, _ = modname.split('.', 1)
         if modname in ['pypyjit', 'signal', 'micronumpy', 'math', 'exceptions',
-                       'imp', 'sys', 'array', '_ffi', 'itertools', 'operator']:
+                       'imp', 'sys', 'array', '_ffi']:
             return True
         return False
 
     def look_inside_function(self, func):
+        # this function should never actually return True directly
+        # but instead call the base implementation
         mod = func.__module__ or '?'
 
+        if mod.startswith('pypy.objspace.'):
+            # gc_id operation
+            if func.__name__ == 'id__ANY':
+                return False
         if mod == 'pypy.rlib.rbigint' or mod == 'pypy.rlib.rlocale':
             return False
         if '_geninterp_' in func.func_globals: # skip all geninterped stuff

Modified: pypy/branch/jit-unroll-loops/pypy/module/pypyjit/test/test_policy.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/module/pypyjit/test/test_policy.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/module/pypyjit/test/test_policy.py	Sat Nov 27 14:45:32 2010
@@ -4,7 +4,7 @@
 
 def test_id_any():
     from pypy.objspace.std.default import id__ANY
-    assert pypypolicy.look_inside_function(id__ANY)
+    assert not pypypolicy.look_inside_function(id__ANY)
 
 def test_bigint():
     from pypy.rlib.rbigint import rbigint

Modified: pypy/branch/jit-unroll-loops/pypy/module/sys/state.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/module/sys/state.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/module/sys/state.py	Sat Nov 27 14:45:32 2010
@@ -33,8 +33,6 @@
         raise OSError(errno.ENOTDIR, path)
 
 
-platform = sys.platform
-
 def getinitialpath(prefix):
     from pypy.module.sys.version import CPYTHON_VERSION
     dirname = '%d.%d.%d' % (CPYTHON_VERSION[0],
@@ -53,15 +51,6 @@
     importlist.append(lib_pypy)
     importlist.append(python_std_lib_modified)
     importlist.append(python_std_lib)
-    #
-    # List here the extra platform-specific paths.
-    if platform != 'win32':
-        importlist.append(os.path.join(python_std_lib, 'plat-'+platform))
-    if platform == 'darwin':
-        platmac = os.path.join(python_std_lib, 'plat-mac')
-        importlist.append(platmac)
-        importlist.append(os.path.join(platmac, 'lib-scriptpackages'))
-    #
     return importlist
 
 def pypy_initial_path(space, srcdir):

Modified: pypy/branch/jit-unroll-loops/pypy/module/sys/test/test_initialpath.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/module/sys/test/test_initialpath.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/module/sys/test/test_initialpath.py	Sat Nov 27 14:45:32 2010
@@ -15,5 +15,4 @@
 def test_stdlib_in_prefix(tmpdir):
     dirs = build_hierarchy(tmpdir)
     path = getinitialpath(str(tmpdir))
-    # we get at least 'dirs', and maybe more (e.g. plat-linux2)
-    assert path[:len(dirs)] == map(str, dirs)
+    assert path == map(str, dirs)

Modified: pypy/branch/jit-unroll-loops/pypy/rlib/debug.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/rlib/debug.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/rlib/debug.py	Sat Nov 27 14:45:32 2010
@@ -53,11 +53,13 @@
 
 _log = None       # patched from tests to be an object of class DebugLog
                   # or compatible
+_stderr = sys.stderr   # alternatively, this is patched from tests
+                       # (redirects debug_print(), but not debug_start/stop)
 
 def debug_print(*args):
     for arg in args:
-        print >> sys.stderr, arg,
-    print >> sys.stderr
+        print >> _stderr, arg,
+    print >> _stderr
     if _log is not None:
         _log.debug_print(*args)
 
@@ -85,15 +87,13 @@
     _stop_colors = ""
 
 def debug_start(category):
-    c = int(time.clock() * 100)
-    print >> sys.stderr, '%s[%x] {%s%s' % (_start_colors_1, c,
+    print >> sys.stderr, '%s[%s] {%s%s' % (_start_colors_1, time.clock(),
                                            category, _stop_colors)
     if _log is not None:
         _log.debug_start(category)
 
 def debug_stop(category):
-    c = int(time.clock() * 100)
-    print >> sys.stderr, '%s[%x] %s}%s' % (_start_colors_2, c,
+    print >> sys.stderr, '%s[%s] %s}%s' % (_start_colors_2, time.clock(),
                                            category, _stop_colors)
     if _log is not None:
         _log.debug_stop(category)

Modified: pypy/branch/jit-unroll-loops/pypy/rlib/jit.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/rlib/jit.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/rlib/jit.py	Sat Nov 27 14:45:32 2010
@@ -260,6 +260,11 @@
 OPTIMIZER_NO_UNROLL = 1
 OPTIMIZER_FULL = 2
 
+DEBUG_OFF = 0
+DEBUG_PROFILE = 1
+DEBUG_STEPS = 2
+DEBUG_DETAILED = 3
+
 PARAMETERS = {'threshold': 1000,
               'trace_eagerness': 200,
               'trace_limit': 10000,
@@ -267,7 +272,6 @@
               'optimizer': OPTIMIZER_FULL,
               #'optimizer': OPTIMIZER_NO_UNROLL,
               'debug' : DEBUG_STEPS,
-              'loop_longevity': 1000,
               }
 unroll_parameters = unrolling_iterable(PARAMETERS.keys())
 

Modified: pypy/branch/jit-unroll-loops/pypy/rlib/libffi.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/rlib/libffi.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/rlib/libffi.py	Sat Nov 27 14:45:32 2010
@@ -178,9 +178,6 @@
         # the optimizer will fail to recognize the pattern and won't turn it
         # into a fast CALL.  Note that "arg = arg.next" is optimized away,
         # assuming that archain is completely virtual.
-        if argchain.numargs != len(self.argtypes):
-            raise TypeError, 'Wrong number of arguments: %d expected, got %d' %\
-                (argchain.numargs, len(self.argtypes))
         ll_args = self._prepare()
         i = 0
         arg = argchain.first

Modified: pypy/branch/jit-unroll-loops/pypy/rlib/rarithmetic.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/rlib/rarithmetic.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/rlib/rarithmetic.py	Sat Nov 27 14:45:32 2010
@@ -389,11 +389,6 @@
 r_longlong = build_int('r_longlong', True, 64)
 r_ulonglong = build_int('r_ulonglong', False, 64)
 
-if r_longlong is not r_int:
-    r_int64 = r_longlong
-else:
-    r_int64 = int
-
 
 # float as string  -> sign, beforept, afterpt, exponent
 

Modified: pypy/branch/jit-unroll-loops/pypy/rlib/test/test_libffi.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/rlib/test/test_libffi.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/rlib/test/test_libffi.py	Sat Nov 27 14:45:32 2010
@@ -262,24 +262,3 @@
         #
         res = self.call(get_dummy, [], rffi.LONG)
         assert res == initval+1
-
-    def test_wrong_number_of_arguments(self):
-        from pypy.rpython.llinterp import LLException
-        libfoo = self.get_libfoo() 
-        func = (libfoo, 'sum_xy', [types.sint, types.double], types.sint)
-
-        glob = globals()
-        loc = locals()
-        def my_raises(s):
-            try:
-                exec s in glob, loc
-            except TypeError:
-                pass
-            except LLException, e:
-                if str(e) != "<LLException 'TypeError'>":
-                    raise
-            else:
-                assert False, 'Did not raise'
-
-        my_raises("self.call(func, [38], rffi.LONG)") # one less
-        my_raises("self.call(func, [38, 12.3, 42], rffi.LONG)") # one more

Modified: pypy/branch/jit-unroll-loops/pypy/rpython/lltypesystem/ll2ctypes.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/rpython/lltypesystem/ll2ctypes.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/rpython/lltypesystem/ll2ctypes.py	Sat Nov 27 14:45:32 2010
@@ -442,9 +442,6 @@
                             "not allocated from RPython at all")
         self._storage = None
 
-    def _getid(self):
-        return self._addressof_storage()
-
     def __eq__(self, other):
         if isinstance(other, _llgcopaque):
             addressof_other = other.intval

Modified: pypy/branch/jit-unroll-loops/pypy/rpython/memory/gc/base.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/rpython/memory/gc/base.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/rpython/memory/gc/base.py	Sat Nov 27 14:45:32 2010
@@ -5,6 +5,7 @@
 from pypy.rpython.memory.support import get_address_stack, get_address_deque
 from pypy.rpython.memory.support import AddressDict
 from pypy.rpython.lltypesystem.llmemory import NULL, raw_malloc_usage
+from pypy.rlib.rarithmetic import r_uint
 
 TYPEID_MAP = lltype.GcStruct('TYPEID_MAP', ('count', lltype.Signed),
                              ('size', lltype.Signed),
@@ -18,7 +19,6 @@
     malloc_zero_filled = False
     prebuilt_gc_objects_are_static_roots = True
     object_minimal_size = 0
-    gcflag_extra = 0   # or a real GC flag that is always 0 when not collecting
 
     def __init__(self, config, chunk_size=DEFAULT_CHUNK_SIZE,
                  translated_to_c=True):
@@ -410,6 +410,42 @@
     GCClass = getattr(module, classname)
     return GCClass, GCClass.TRANSLATION_PARAMS
 
+def _read_float_and_factor_from_env(varname):
+    import os
+    value = os.environ.get(varname)
+    if value:
+        if len(value) > 1 and value[-1] in 'bB':
+            value = value[:-1]
+        realvalue = value[:-1]
+        if value[-1] in 'kK':
+            factor = 1024
+        elif value[-1] in 'mM':
+            factor = 1024*1024
+        elif value[-1] in 'gG':
+            factor = 1024*1024*1024
+        else:
+            factor = 1
+            realvalue = value
+        try:
+            return (float(realvalue), factor)
+        except ValueError:
+            pass
+    return (0.0, 0)
+
+def read_from_env(varname):
+    value, factor = _read_float_and_factor_from_env(varname)
+    return int(value * factor)
+
+def read_uint_from_env(varname):
+    value, factor = _read_float_and_factor_from_env(varname)
+    return r_uint(value * factor)
+
+def read_float_from_env(varname):
+    value, factor = _read_float_and_factor_from_env(varname)
+    if factor != 1:
+        return 0.0
+    return value
+
 def _convert_callback_formats(callback):
     callback = getattr(callback, 'im_func', callback)
     if callback not in _converted_callback_formats:

Modified: pypy/branch/jit-unroll-loops/pypy/rpython/memory/gc/generation.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/rpython/memory/gc/generation.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/rpython/memory/gc/generation.py	Sat Nov 27 14:45:32 2010
@@ -2,7 +2,7 @@
 from pypy.rpython.memory.gc.semispace import SemiSpaceGC
 from pypy.rpython.memory.gc.semispace import GCFLAG_EXTERNAL, GCFLAG_FORWARDED
 from pypy.rpython.memory.gc.semispace import GC_HASH_TAKEN_ADDR
-from pypy.rpython.memory.gc import env
+from pypy.rpython.memory.gc.base import read_from_env
 from pypy.rpython.lltypesystem.llmemory import NULL, raw_malloc_usage
 from pypy.rpython.lltypesystem import lltype, llmemory, llarena
 from pypy.rlib.objectmodel import free_non_gc_object
@@ -93,7 +93,7 @@
         if self.auto_nursery_size:
             newsize = nursery_size_from_env()
             if newsize <= 0:
-                newsize = env.estimate_best_nursery_size()
+                newsize = estimate_best_nursery_size()
             if newsize > 0:
                 self.set_nursery_size(newsize)
 
@@ -633,5 +633,139 @@
 
 # ____________________________________________________________
 
+import os
+
 def nursery_size_from_env():
-    return env.read_from_env('PYPY_GENERATIONGC_NURSERY')
+    return read_from_env('PYPY_GENERATIONGC_NURSERY')
+
+def best_nursery_size_for_L2cache(L2cache):
+    # Heuristically, the best nursery size to choose is about half
+    # of the L2 cache.  XXX benchmark some more.
+    return L2cache // 2
+
+
+if sys.platform == 'linux2':
+    def estimate_best_nursery_size():
+        """Try to estimate the best nursery size at run-time, depending
+        on the machine we are running on.
+        """
+        debug_start("gc-L2cache")
+        L2cache = sys.maxint
+        try:
+            fd = os.open('/proc/cpuinfo', os.O_RDONLY, 0644)
+            try:
+                data = []
+                while True:
+                    buf = os.read(fd, 4096)
+                    if not buf:
+                        break
+                    data.append(buf)
+            finally:
+                os.close(fd)
+        except OSError:
+            pass
+        else:
+            data = ''.join(data)
+            linepos = 0
+            while True:
+                start = findend(data, '\ncache size', linepos)
+                if start < 0:
+                    break    # done
+                linepos = findend(data, '\n', start)
+                if linepos < 0:
+                    break    # no end-of-line??
+                # *** data[start:linepos] == "   : 2048 KB\n"
+                start = skipspace(data, start)
+                if data[start] != ':':
+                    continue
+                # *** data[start:linepos] == ": 2048 KB\n"
+                start = skipspace(data, start + 1)
+                # *** data[start:linepos] == "2048 KB\n"
+                end = start
+                while '0' <= data[end] <= '9':
+                    end += 1
+                # *** data[start:end] == "2048"
+                if start == end:
+                    continue
+                number = int(data[start:end])
+                # *** data[end:linepos] == " KB\n"
+                end = skipspace(data, end)
+                if data[end] not in ('K', 'k'):    # assume kilobytes for now
+                    continue
+                number = number * 1024
+                # for now we look for the smallest of the L2 caches of the CPUs
+                if number < L2cache:
+                    L2cache = number
+
+        debug_print("L2cache =", L2cache)
+        debug_stop("gc-L2cache")
+
+        if L2cache < sys.maxint:
+            return best_nursery_size_for_L2cache(L2cache)
+        else:
+            # Print a top-level warning even in non-debug builds
+            llop.debug_print(lltype.Void,
+                "Warning: cannot find your CPU L2 cache size in /proc/cpuinfo")
+            return -1
+
+    def findend(data, pattern, pos):
+        pos = data.find(pattern, pos)
+        if pos < 0:
+            return -1
+        return pos + len(pattern)
+
+    def skipspace(data, pos):
+        while data[pos] in (' ', '\t'):
+            pos += 1
+        return pos
+
+elif sys.platform == 'darwin':
+    from pypy.rpython.lltypesystem import rffi
+
+    sysctlbyname = rffi.llexternal('sysctlbyname',
+                                   [rffi.CCHARP, rffi.VOIDP, rffi.SIZE_TP,
+                                    rffi.VOIDP, rffi.SIZE_T],
+                                   rffi.INT,
+                                   sandboxsafe=True)
+
+    def estimate_best_nursery_size():
+        """Try to estimate the best nursery size at run-time, depending
+        on the machine we are running on.
+        """
+        debug_start("gc-L2cache")
+        L2cache = 0
+        l2cache_p = lltype.malloc(rffi.LONGLONGP.TO, 1, flavor='raw')
+        try:
+            len_p = lltype.malloc(rffi.SIZE_TP.TO, 1, flavor='raw')
+            try:
+                size = rffi.sizeof(rffi.LONGLONG)
+                l2cache_p[0] = rffi.cast(rffi.LONGLONG, 0)
+                len_p[0] = rffi.cast(rffi.SIZE_T, size)
+                # XXX a hack for llhelper not being robust-enough
+                result = sysctlbyname("hw.l2cachesize",
+                                      rffi.cast(rffi.VOIDP, l2cache_p),
+                                      len_p,
+                                      lltype.nullptr(rffi.VOIDP.TO), 
+                                      rffi.cast(rffi.SIZE_T, 0))
+                if (rffi.cast(lltype.Signed, result) == 0 and
+                    rffi.cast(lltype.Signed, len_p[0]) == size):
+                    L2cache = rffi.cast(lltype.Signed, l2cache_p[0])
+                    if rffi.cast(rffi.LONGLONG, L2cache) != l2cache_p[0]:
+                        L2cache = 0    # overflow!
+            finally:
+                lltype.free(len_p, flavor='raw')
+        finally:
+            lltype.free(l2cache_p, flavor='raw')
+        debug_print("L2cache =", L2cache)
+        debug_stop("gc-L2cache")
+        if L2cache > 0:
+            return best_nursery_size_for_L2cache(L2cache)
+        else:
+            # Print a top-level warning even in non-debug builds
+            llop.debug_print(lltype.Void,
+                "Warning: cannot find your CPU L2 cache size with sysctl()")
+            return -1
+
+else:
+    def estimate_best_nursery_size():
+        return -1     # XXX implement me for other platforms

Modified: pypy/branch/jit-unroll-loops/pypy/rpython/memory/gc/inspector.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/rpython/memory/gc/inspector.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/rpython/memory/gc/inspector.py	Sat Nov 27 14:45:32 2010
@@ -107,18 +107,15 @@
 
     def __init__(self, gc, fd):
         self.gc = gc
-        self.gcflag = gc.gcflag_extra
         self.fd = rffi.cast(rffi.INT, fd)
         self.writebuffer = lltype.malloc(rffi.LONGP.TO, self.BUFSIZE,
                                          flavor='raw')
         self.buf_count = 0
-        if self.gcflag == 0:
-            self.seen = AddressDict()
+        self.seen = AddressDict()
         self.pending = AddressStack()
 
     def delete(self):
-        if self.gcflag == 0:
-            self.seen.delete()
+        self.seen.delete()
         self.pending.delete()
         lltype.free(self.writebuffer, flavor='raw')
         free_non_gc_object(self)
@@ -143,8 +140,6 @@
             self.flush()
     write._always_inline_ = True
 
-    # ----------
-
     def write_marker(self):
         self.write(0)
         self.write(0)
@@ -166,15 +161,9 @@
         self.add(obj)
 
     def add(self, obj):
-        if self.gcflag == 0:
-            if not self.seen.contains(obj):
-                self.seen.setitem(obj, obj)
-                self.pending.append(obj)
-        else:
-            hdr = self.gc.header(obj)
-            if (hdr.tid & self.gcflag) == 0:
-                hdr.tid |= self.gcflag
-                self.pending.append(obj)
+        if not self.seen.contains(obj):
+            self.seen.setitem(obj, obj)
+            self.pending.append(obj)
 
     def add_roots(self):
         self.gc.enumerate_all_roots(_hd_add_root, self)
@@ -188,50 +177,14 @@
         while pending.non_empty():
             self.writeobj(pending.pop())
 
-    # ----------
-    # A simplified copy of the above, to make sure we walk again all the
-    # objects to clear the 'gcflag'.
-
-    def unwriteobj(self, obj):
-        gc = self.gc
-        gc.trace(obj, self._unwriteref, None)
-
-    def _unwriteref(self, pointer, _):
-        obj = pointer.address[0]
-        self.unadd(obj)
-
-    def unadd(self, obj):
-        assert self.gcflag != 0
-        hdr = self.gc.header(obj)
-        if (hdr.tid & self.gcflag) != 0:
-            hdr.tid &= ~self.gcflag
-            self.pending.append(obj)
-
-    def clear_gcflag_again(self):
-        self.gc.enumerate_all_roots(_hd_unadd_root, self)
-        pendingroots = self.pending
-        self.pending = AddressStack()
-        self.unwalk(pendingroots)
-        pendingroots.delete()
-
-    def unwalk(self, pending):
-        while pending.non_empty():
-            self.unwriteobj(pending.pop())
-
 def _hd_add_root(obj, heap_dumper):
     heap_dumper.add(obj)
 
-def _hd_unadd_root(obj, heap_dumper):
-    heap_dumper.unadd(obj)
-
 def dump_rpy_heap(gc, fd):
     heapdumper = HeapDumper(gc, fd)
     heapdumper.add_roots()
     heapdumper.walk(heapdumper.pending)
     heapdumper.flush()
-    if heapdumper.gcflag != 0:
-        heapdumper.clear_gcflag_again()
-        heapdumper.unwalk(heapdumper.pending)
     heapdumper.delete()
     return True
 

Modified: pypy/branch/jit-unroll-loops/pypy/rpython/memory/gc/markcompact.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/rpython/memory/gc/markcompact.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/rpython/memory/gc/markcompact.py	Sat Nov 27 14:45:32 2010
@@ -1,6 +1,5 @@
 from pypy.rpython.lltypesystem import lltype, llmemory, llarena, llgroup
-from pypy.rpython.memory.gc.base import MovingGCBase
-from pypy.rpython.memory.gc import env
+from pypy.rpython.memory.gc.base import MovingGCBase, read_from_env
 from pypy.rlib.debug import ll_assert, have_debug_prints
 from pypy.rlib.debug import debug_print, debug_start, debug_stop
 from pypy.rpython.memory.support import get_address_stack, get_address_deque
@@ -111,10 +110,10 @@
         return next
 
     def setup(self):
-        envsize = env.read_from_env('PYPY_MARKCOMPACTGC_MAX')
+        envsize = read_from_env('PYPY_MARKCOMPACTGC_MAX')
         if envsize >= 4096:
             self.space_size = envsize & ~4095
-        mincollect = env.read_from_env('PYPY_MARKCOMPACTGC_MIN')
+        mincollect = read_from_env('PYPY_MARKCOMPACTGC_MIN')
         if mincollect >= 4096:
             self.min_next_collect_after = mincollect
 

Modified: pypy/branch/jit-unroll-loops/pypy/rpython/memory/gc/minimark.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/rpython/memory/gc/minimark.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/rpython/memory/gc/minimark.py	Sat Nov 27 14:45:32 2010
@@ -12,7 +12,7 @@
                         collection.
 
  PYPY_GC_GROWTH         Major collection threshold's max growth rate.
-                        Default is '1.4'.  Useful to collect more often
+                        Default is '1.3'.  Useful to collect more often
                         than normally on sudden memory growth, e.g. when
                         there is a temporary peak in memory usage.
 
@@ -22,12 +22,6 @@
                         crash the program with a fatal error.  Try values
                         like '1.6GB'.
 
- PYPY_GC_MAX_DELTA      The major collection threshold will never be set
-                        to more than PYPY_GC_MAX_DELTA the amount really
-                        used after a collection.  Defaults to 1/8th of the
-                        total RAM size (which is constrained to be at most
-                        2/3/4GB on 32-bit systems).  Try values like '200MB'.
-
  PYPY_GC_MIN            Don't collect while the memory size is below this
                         limit.  Useful to avoid spending all the time in
                         the GC in very small programs.  Defaults to 8
@@ -42,7 +36,7 @@
 from pypy.rpython.lltypesystem.lloperation import llop
 from pypy.rpython.lltypesystem.llmemory import raw_malloc_usage
 from pypy.rpython.memory.gc.base import GCBase, MovingGCBase
-from pypy.rpython.memory.gc import minimarkpage, env
+from pypy.rpython.memory.gc import minimarkpage, base, generation
 from pypy.rlib.rarithmetic import ovfcheck, LONG_BIT, intmask, r_uint
 from pypy.rlib.rarithmetic import LONG_BIT_SHIFT
 from pypy.rlib.debug import ll_assert, debug_print, debug_start, debug_stop
@@ -102,7 +96,6 @@
     needs_write_barrier = True
     prebuilt_gc_objects_are_static_roots = False
     malloc_zero_filled = True    # xxx experiment with False
-    gcflag_extra = GCFLAG_FINALIZATION_ORDERING
 
     # All objects start with a HDR, i.e. with a field 'tid' which contains
     # a word.  This word is divided in two halves: the lower half contains
@@ -161,7 +154,7 @@
         # grow at most by the following factor from one collection to the
         # next.  Used e.g. when there is a sudden, temporary peak in memory
         # usage; this avoids that the upper bound grows too fast.
-        "growth_rate_max": 1.4,
+        "growth_rate_max": 1.3,
 
         # The number of array indices that are mapped to a single bit in
         # write_barrier_from_array().  Must be a power of two.  The default
@@ -205,7 +198,6 @@
         self.min_heap_size = 0.0
         self.max_heap_size = 0.0
         self.max_heap_size_already_raised = False
-        self.max_delta = float(r_uint(-1))
         #
         self.card_page_indices = card_page_indices
         if self.card_page_indices > 0:
@@ -290,42 +282,36 @@
             #
             # From there on, the GC is fully initialized and the code
             # below can use it
-            newsize = env.read_from_env('PYPY_GC_NURSERY')
+            newsize = base.read_from_env('PYPY_GC_NURSERY')
             # PYPY_GC_NURSERY=1 forces a minor collect for every malloc.
             # Useful to debug external factors, like trackgcroot or the
             # handling of the write barrier.
             self.debug_always_do_minor_collect = newsize == 1
             if newsize <= 0:
-                newsize = env.estimate_best_nursery_size()
+                newsize = generation.estimate_best_nursery_size()
                 if newsize <= 0:
                     newsize = defaultsize
             newsize = max(newsize, minsize)
             #
-            major_coll = env.read_float_from_env('PYPY_GC_MAJOR_COLLECT')
+            major_coll = base.read_float_from_env('PYPY_GC_MAJOR_COLLECT')
             if major_coll > 1.0:
                 self.major_collection_threshold = major_coll
             #
-            growth = env.read_float_from_env('PYPY_GC_GROWTH')
+            growth = base.read_float_from_env('PYPY_GC_GROWTH')
             if growth > 1.0:
                 self.growth_rate_max = growth
             #
-            min_heap_size = env.read_uint_from_env('PYPY_GC_MIN')
+            min_heap_size = base.read_uint_from_env('PYPY_GC_MIN')
             if min_heap_size > 0:
                 self.min_heap_size = float(min_heap_size)
             else:
                 # defaults to 8 times the nursery
                 self.min_heap_size = newsize * 8
             #
-            max_heap_size = env.read_uint_from_env('PYPY_GC_MAX')
+            max_heap_size = base.read_uint_from_env('PYPY_GC_MAX')
             if max_heap_size > 0:
                 self.max_heap_size = float(max_heap_size)
             #
-            max_delta = env.read_uint_from_env('PYPY_GC_MAX_DELTA')
-            if max_delta > 0:
-                self.max_delta = float(max_delta)
-            else:
-                self.max_delta = 0.125 * env.get_total_memory()
-            #
             self.minor_collection()    # to empty the nursery
             llarena.arena_free(self.nursery)
             self.nursery_size = newsize
@@ -1219,6 +1205,10 @@
         self.collect_roots()
         self.visit_all_objects()
         #
+        # Weakref support: clear the weak pointers to dying objects
+        if self.old_objects_with_weakrefs.non_empty():
+            self.invalidate_old_weakrefs()
+        #
         # Finalizer support: adds the flag GCFLAG_VISITED to all objects
         # with a finalizer and all objects reachable from there (and also
         # moves some objects from 'objects_with_finalizers' to
@@ -1228,10 +1218,6 @@
         #
         self.objects_to_trace.delete()
         #
-        # Weakref support: clear the weak pointers to dying objects
-        if self.old_objects_with_weakrefs.non_empty():
-            self.invalidate_old_weakrefs()
-        #
         # Walk all rawmalloced objects and free the ones that don't
         # have the GCFLAG_VISITED flag.
         self.free_unvisited_rawmalloc_objects()
@@ -1259,12 +1245,9 @@
         #
         # Set the threshold for the next major collection to be when we
         # have allocated 'major_collection_threshold' times more than
-        # we currently have -- but no more than 'max_delta' more than
         # we currently have.
-        total_memory_used = float(self.get_total_memory_used())
         bounded = self.set_major_threshold_from(
-            min(total_memory_used * self.major_collection_threshold,
-                total_memory_used + self.max_delta),
+            self.get_total_memory_used() * self.major_collection_threshold,
             reserving_size)
         #
         # Max heap size: gives an upper bound on the threshold.  If we

Modified: pypy/branch/jit-unroll-loops/pypy/rpython/memory/gc/semispace.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/rpython/memory/gc/semispace.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/rpython/memory/gc/semispace.py	Sat Nov 27 14:45:32 2010
@@ -42,7 +42,6 @@
     inline_simple_malloc_varsize = True
     malloc_zero_filled = True
     first_unused_gcflag = first_gcflag << 5
-    gcflag_extra = GCFLAG_FINALIZATION_ORDERING
 
     HDR = lltype.Struct('header', ('tid', lltype.Signed))   # XXX or rffi.INT?
     typeid_is_in_field = 'tid'
@@ -267,10 +266,10 @@
         if self.run_finalizers.non_empty():
             self.update_run_finalizers()
         scan = self.scan_copied(scan)
-        if self.objects_with_finalizers.non_empty():
-            scan = self.deal_with_objects_with_finalizers(scan)
         if self.objects_with_weakrefs.non_empty():
             self.invalidate_weakrefs()
+        if self.objects_with_finalizers.non_empty():
+            scan = self.deal_with_objects_with_finalizers(scan)
         self.update_objects_with_id()
         self.finished_full_collect()
         self.debug_check_consistency()

Modified: pypy/branch/jit-unroll-loops/pypy/rpython/memory/test/test_gc.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/rpython/memory/test/test_gc.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/rpython/memory/test/test_gc.py	Sat Nov 27 14:45:32 2010
@@ -304,7 +304,7 @@
         a = A()
         class B(object):
             def __del__(self):
-                # when __del__ is called, the weakref to c should be dead
+                # when __del__ is called, the weakref should have been cleared
                 if self.ref() is None:
                     a.count += 10  # ok
                 else:
@@ -333,10 +333,8 @@
         a = A()
         class B(object):
             def __del__(self):
-                # when __del__ is called, the weakref to myself is still valid
-                # in RPython (at least with most GCs; this test might be
-                # skipped for specific GCs)
-                if self.ref() is self:
+                # when __del__ is called, the weakref should have been cleared
+                if self.ref() is None:
                     a.count += 10  # ok
                 else:
                     a.count = 666  # not ok
@@ -354,29 +352,6 @@
         res = self.interpret(f, [])
         assert res == 11
 
-    def test_weakref_bug_1(self):
-        import weakref
-        class A(object):
-            pass
-        class B(object):
-            def __del__(self):
-                self.wref().x += 1
-        def g(a):
-            b = B()
-            b.wref = weakref.ref(a)
-            # the only way to reach this weakref is via B, which is an
-            # object with finalizer (but the weakref itself points to
-            # a, which does not go away but will move during the next
-            # gc.collect)
-        def f():
-            a = A()
-            a.x = 10
-            g(a)
-            llop.gc__collect(lltype.Void)
-            return a.x
-        res = self.interpret(f, [])
-        assert res == 11
-
     def test_id(self):
         class A(object):
             pass
@@ -734,9 +709,6 @@
 class TestMarkSweepGC(GCTest):
     from pypy.rpython.memory.gc.marksweep import MarkSweepGC as GCClass
 
-    def test_weakref_to_object_with_finalizer_ordering(self):
-        py.test.skip("Does not work")
-
 class TestSemiSpaceGC(GCTest, snippet.SemiSpaceGCTests):
     from pypy.rpython.memory.gc.semispace import SemiSpaceGC as GCClass
     GC_CAN_MOVE = True
@@ -759,6 +731,9 @@
     def test_finalizer_order(self):
         py.test.skip("Not implemented yet")
 
+    def test_weakref_to_object_with_finalizer_ordering(self):
+        py.test.skip("Not implemented yet")
+
 class TestHybridGC(TestGenerationalGC):
     from pypy.rpython.memory.gc.hybrid import HybridGC as GCClass
     GC_CAN_MALLOC_NONMOVABLE = True

Modified: pypy/branch/jit-unroll-loops/pypy/rpython/test/test_rclass.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/rpython/test/test_rclass.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/rpython/test/test_rclass.py	Sat Nov 27 14:45:32 2010
@@ -917,7 +917,6 @@
         assert destrptr is not None
     
     def test_del_inheritance(self):
-        from pypy.rlib import rgc
         class State:
             pass
         s = State()
@@ -938,7 +937,6 @@
             A()
             B()
             C()
-            rgc.collect()
             return s.a_dels * 10 + s.b_dels
         res = f()
         assert res == 42
@@ -1069,7 +1067,6 @@
         assert meth.finalizer
 
     def test_del_inheritance(self):
-        from pypy.rlib import rgc
         class State:
             pass
         s = State()
@@ -1090,7 +1087,6 @@
             A()
             B()
             C()
-            rgc.collect()
             return s.a_dels * 10 + s.b_dels
         res = f()
         assert res == 42

Modified: pypy/branch/jit-unroll-loops/pypy/rpython/test/test_rint.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/rpython/test/test_rint.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/rpython/test/test_rint.py	Sat Nov 27 14:45:32 2010
@@ -4,9 +4,14 @@
 from pypy.annotation import model as annmodel
 from pypy.rpython.test import snippet
 from pypy.rlib.rarithmetic import r_int, r_uint, r_longlong, r_ulonglong
-from pypy.rlib.rarithmetic import ovfcheck, r_int64
+from pypy.rlib.rarithmetic import ovfcheck
 from pypy.rpython.test.tool import BaseRtypingTest, LLRtypeMixin, OORtypeMixin
 
+if r_longlong is not r_int:
+    int64 = r_longlong
+else:
+    int64 = int
+
 
 class TestSnippet(object):
 
@@ -105,10 +110,10 @@
         def f(i):
             return str(i)
 
-        res = self.interpret(f, [r_int64(0)])
+        res = self.interpret(f, [int64(0)])
         assert self.ll_to_string(res) == '0'
 
-        res = self.interpret(f, [r_int64(413974738222117)])
+        res = self.interpret(f, [int64(413974738222117)])
         assert self.ll_to_string(res) == '413974738222117'
 
     def test_unsigned(self):
@@ -130,7 +135,7 @@
         f._annspecialcase_ = "specialize:argtype(0)"
         def g(n):
             if n > 0:
-                return f(r_int64(0))
+                return f(int64(0))
             else:
                 return f(0)
         res = self.interpret(g, [0])
@@ -142,7 +147,7 @@
     def test_downcast_int(self):
         def f(i):
             return int(i)
-        res = self.interpret(f, [r_int64(0)])
+        res = self.interpret(f, [int64(0)])
         assert res == 0
 
     def test_isinstance_vs_int_types(self):
@@ -152,7 +157,7 @@
                     return [None]
                 if isinstance(x, str):
                     return x
-                if isinstance(x, r_int64):
+                if isinstance(x, int64):
                     return int(x)
                 return "XXX"
             wrap._annspecialcase_ = 'specialize:argtype(0)'
@@ -160,7 +165,7 @@
         space = FakeSpace()
         def wrap(x):
             return space.wrap(x)
-        res = self.interpret(wrap, [r_int64(0)])
+        res = self.interpret(wrap, [int64(0)])
         assert res == 0
 
     def test_truediv(self):
@@ -173,25 +178,25 @@
     def test_float_conversion(self):
         def f(ii):
             return float(ii)
-        res = self.interpret(f, [r_int64(100000000)])
+        res = self.interpret(f, [int64(100000000)])
         assert type(res) is float
         assert res == 100000000.
-        res = self.interpret(f, [r_int64(1234567890123456789)])
+        res = self.interpret(f, [int64(1234567890123456789)])
         assert type(res) is float
         assert self.float_eq(res, 1.2345678901234568e+18)
 
     def test_float_conversion_implicit(self):
         def f(ii):
             return 1.0 + ii
-        res = self.interpret(f, [r_int64(100000000)])
+        res = self.interpret(f, [int64(100000000)])
         assert type(res) is float
         assert res == 100000001.
-        res = self.interpret(f, [r_int64(1234567890123456789)])
+        res = self.interpret(f, [int64(1234567890123456789)])
         assert type(res) is float
         assert self.float_eq(res, 1.2345678901234568e+18)
 
     def test_rarithmetic(self):
-        inttypes = [int, r_uint, r_int64, r_ulonglong]
+        inttypes = [int, r_uint, int64, r_ulonglong]
         for inttype in inttypes:
             c = inttype()
             def f():
@@ -226,16 +231,16 @@
             res = self.interpret(f, [int(-1<<(r_int.BITS-1))])
             assert res == 0
 
-            res = self.interpret(f, [r_int64(-1)])
+            res = self.interpret(f, [int64(-1)])
             assert res == 1
-            res = self.interpret(f, [r_int64(-1)<<(r_longlong.BITS-1)])
+            res = self.interpret(f, [int64(-1)<<(r_longlong.BITS-1)])
             assert res == 0
 
     div_mod_iteration_count = 1000
     def test_div_mod(self):
         import random
 
-        for inttype in (int, r_int64):
+        for inttype in (int, int64):
 
             def d(x, y):
                 return x/y
@@ -298,7 +303,7 @@
             except ZeroDivisionError:
                 return 84
 
-        for inttype in (int, r_int64):
+        for inttype in (int, int64):
 
             args = [( 5, 2), (-5, 2), ( 5,-2), (-5,-2),
                     ( 6, 2), (-6, 2), ( 6,-2), (-6,-2),

Modified: pypy/branch/jit-unroll-loops/pypy/tool/logparser.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/tool/logparser.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/tool/logparser.py	Sat Nov 27 14:45:32 2010
@@ -12,6 +12,14 @@
 from pypy.tool import progressbar
 
 def parse_log_file(filename, verbose=True):
+    r_start = re.compile(r"\[([0-9a-fA-F]+)\] \{([\w-]+)$")
+    r_stop  = re.compile(r"\[([0-9a-fA-F]+)\] ([\w-]+)\}$")
+    lasttime = 0
+    log = DebugLog()
+    time_decrase = False
+    performance_log = True
+    nested = 0
+    #
     f = open(filename, 'r')
     if f.read(2) == 'BZ':
         f.close()
@@ -22,33 +30,19 @@
     lines = f.readlines()
     f.close()
     #
-    return parse_log(lines, verbose=verbose)
-
-def parse_log(lines, verbose=False):
-    color = "(?:\x1b.*?m)?"
-    r_start = re.compile(color + r"\[([0-9a-fA-F]+)\] \{([\w-]+)" + color + "$")
-    r_stop  = re.compile(color + r"\[([0-9a-fA-F]+)\] ([\w-]+)\}" + color + "$")
-    lasttime = 0
-    log = DebugLog()
-    time_decrase = False
-    performance_log = True
-    nested = 0
-    #
-    if verbose and sys.stdout.isatty():
+    if sys.stdout.isatty():
         progress = progressbar.ProgressBar(color='green')
-        counter = 0
-    else:
-        progress = None
     single_percent = len(lines) / 100
     if verbose:
-        vnext = 0
+        vnext = single_percent
     else:
-        vnext = -1
+        vnext = len(lines)
+    counter = 0
     for i, line in enumerate(lines):
         if i == vnext:
-            if progress is not None:
+            counter += 1
+            if sys.stdout.isatty():
                 progress.render(counter)
-                counter += 1
                 vnext += single_percent
             else:
                 sys.stderr.write('%d%%..' % int(100.0*i/len(lines)))

Modified: pypy/branch/jit-unroll-loops/pypy/tool/release/force-builds.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/tool/release/force-builds.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/tool/release/force-builds.py	Sat Nov 27 14:45:32 2010
@@ -20,12 +20,11 @@
     'own-linux-x86-32',
     'own-linux-x86-64',
 #    'own-macosx-x86-32',
-#    'pypy-c-app-level-linux-x86-32',
-#    'pypy-c-app-level-linux-x86-64',
+    'pypy-c-app-level-linux-x86-32',
+    'pypy-c-app-level-linux-x86-64',
     'pypy-c-stackless-app-level-linux-x86-32',
     'pypy-c-app-level-win-x86-32',
     'pypy-c-jit-linux-x86-32',
-    'pypy-c-jit-linux-x86-64',
 #    'pypy-c-jit-macosx-x86-32',
     'pypy-c-jit-win-x86-32',
 ]

Modified: pypy/branch/jit-unroll-loops/pypy/tool/release/make_release.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/tool/release/make_release.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/tool/release/make_release.py	Sat Nov 27 14:45:32 2010
@@ -4,7 +4,7 @@
 into release packages. Note: you must run apropriate buildbots first and
 make sure there are no failures. Use force-builds.py from the same directory.
 
-Usage: make_release.py release/<release name> release_version
+Usage: make_release.py release/<release name>
 """
 
 import autopath
@@ -30,8 +30,7 @@
     else:
         xml = override_xml
     dom = minidom.parseString(xml)
-    refs = [node.getAttribute('href') for node in dom.getElementsByTagName('a')
-            if 'pypy' in node.getAttribute('href')]
+    refs = [node.getAttribute('href') for node in dom.getElementsByTagName('a')]
     # all refs are of form: pypy-{type}-{revision}-{platform}.tar.bz2
     r = re.compile('pypy-c-([\w\d]+)-(\d+)-([\w\d]+).tar.bz2$')
     d = {}
@@ -77,7 +76,7 @@
                 t.add('pypy-%s' % release)
                 alltars.append(name)
                 t.close()
-                shutil.rmtree(str(tmpdir.join('pypy-' + release)))
+                shutil.rmtree(str(tmpdir.join('pypy-1.3')))
         for name in alltars:
             print "Uploading %s" % name
             os.system('scp %s codespeak.net:/www/pypy.org/htdocs/download' % name)
@@ -85,8 +84,8 @@
         os.chdir(olddir)
 
 if __name__ == '__main__':
-    if len(sys.argv) != 3:
+    if len(sys.argv) != 2:
         print __doc__
         sys.exit(1)
-    main(sys.argv[1], release=sys.argv[2])
+    main(sys.argv[1], release='1.3')
     

Modified: pypy/branch/jit-unroll-loops/pypy/tool/release/package.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/tool/release/package.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/tool/release/package.py	Sat Nov 27 14:45:32 2010
@@ -1,12 +1,8 @@
 #!/usr/bin/env python
 """ A sample script that packages PyPy, provided that it's already built.
-It uses 'pypy/translator/goal/pypy-c' and parts of the rest of the working
-copy.  Usage:
+Usage:
 
-    package.py root-pypy-dir [name-of-archive] [name-of-pypy-c]
-
-Usually you would do:   package.py ../../.. pypy-VER-PLATFORM.
-The output is found in the directory /tmp/usession-YOURNAME/build/.
+package.py pypydir [name-of-archive] [name-of-pypy-c]
 """
 
 import autopath
@@ -36,7 +32,7 @@
 class PyPyCNotFound(Exception):
     pass
 
-def package(basedir, name='pypy-nightly', rename_pypy_c='pypy',
+def package(basedir, name='pypy-nightly', rename_pypy_c='pypy-c',
             copy_to_dir = None, override_pypy_c = None):
     basedir = py.path.local(basedir)
     if sys.platform == 'win32':
@@ -68,10 +64,6 @@
     headers = includedir.listdir('*.h') + includedir.listdir('*.inl')
     for n in headers:
         shutil.copy(str(n), str(pypydir.join('include')))
-    #
-    spdir = pypydir.ensure('site-packages', dir=True)
-    shutil.copy(str(basedir.join('site-packages', 'README')), str(spdir))
-    #
     pypydir.ensure('bin', dir=True)
     archive_pypy_c = pypydir.join('bin', rename_pypy_c)
     shutil.copy(str(pypy_c), str(archive_pypy_c))

Modified: pypy/branch/jit-unroll-loops/pypy/tool/release/test/test_package.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/tool/release/test/test_package.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/tool/release/test/test_package.py	Sat Nov 27 14:45:32 2010
@@ -18,7 +18,7 @@
         prefix = builddir.join(test)
         cpyver = '%d.%d.%d' % CPYTHON_VERSION[:3]
         assert prefix.join('lib-python', cpyver, 'test').check()
-        assert prefix.join('bin', 'pypy').check()
+        assert prefix.join('bin', 'pypy-c').check()
         assert prefix.join('lib_pypy', 'syslog.py').check()
         assert not prefix.join('lib_pypy', 'py').check()
         assert not prefix.join('lib_pypy', 'ctypes_configure').check()

Modified: pypy/branch/jit-unroll-loops/pypy/tool/terminal.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/tool/terminal.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/tool/terminal.py	Sat Nov 27 14:45:32 2010
@@ -62,10 +62,9 @@
     for control in CONTROLS:
         # Set the control escape sequence
         setattr(MODULE, control, curses.tigetstr(CONTROLS[control]) or '')
-    if hasattr(curses, 'tigetnum'):
-        for value in VALUES:
-            # Set terminal related values
-            setattr(MODULE, value, curses.tigetnum(VALUES[value]))
+    for value in VALUES:
+        # Set terminal related values
+        setattr(MODULE, value, curses.tigetnum(VALUES[value]))
 
 def render(text):
     """Helper function to apply controls easily
@@ -75,16 +74,7 @@
     return text % MODULE.__dict__
 
 try:
-    if '__pypy__' in sys.builtin_module_names:
-        # this is not really the whole curses, but our _minimal_curses it's
-        # better than nothing
-        import _minimal_curses as curses
-        # a bit of a hack: we have tigetstr but not tigetnum, so we call
-        # default() to have default values, then setup() will overwrite the
-        # ones it can
-        default()
-    else:
-        import curses
+    import curses
     setup()
 except Exception, e:
     # There is a failure; set all attributes to default

Modified: pypy/branch/jit-unroll-loops/pypy/translator/c/funcgen.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/translator/c/funcgen.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/translator/c/funcgen.py	Sat Nov 27 14:45:32 2010
@@ -1,4 +1,3 @@
-import sys
 from pypy.translator.c.support import USESLOTS # set to False if necessary while refactoring
 from pypy.translator.c.support import cdecl
 from pypy.translator.c.support import llvalue_from_constant, gen_assignments
@@ -758,16 +757,6 @@
                 format.append('%s')
                 argv.append('(%s) ? "True" : "False"' % self.expr(arg))
                 continue
-            elif T == SignedLongLong:
-                if sys.platform == 'win32':
-                    format.append('%I64d')
-                else:
-                    format.append('%lld')
-            elif T == UnsignedLongLong:
-                if sys.platform == 'win32':
-                    format.append('%I64u')
-                else:
-                    format.append('%llu')
             else:
                 raise Exception("don't know how to debug_print %r" % (T,))
             argv.append(self.expr(arg))
@@ -776,20 +765,17 @@
             "if (PYPY_HAVE_DEBUG_PRINTS) { fprintf(PYPY_DEBUG_FILE, %s); %s}"
             % (', '.join(argv), free_line))
 
-    def _op_debug(self, opname, arg):
-        if isinstance(arg, Constant):
-            string_literal = c_string_constant(''.join(arg.value.chars))
-            return "%s(%s);" % (opname, string_literal)
-        else:
-            x = "%s(RPyString_AsCharP(%s));\n" % (opname, self.expr(arg))
-            x += "RPyString_FreeCache();"
-            return x
-
     def OP_DEBUG_START(self, op):
-        return self._op_debug('PYPY_DEBUG_START', op.args[0])
+        arg = op.args[0]
+        assert isinstance(arg, Constant)
+        return "PYPY_DEBUG_START(%s);" % (
+            c_string_constant(''.join(arg.value.chars)),)
 
     def OP_DEBUG_STOP(self, op):
-        return self._op_debug('PYPY_DEBUG_STOP', op.args[0])
+        arg = op.args[0]
+        assert isinstance(arg, Constant)
+        return "PYPY_DEBUG_STOP(%s);" % (
+            c_string_constant(''.join(arg.value.chars)),)
 
     def OP_DEBUG_ASSERT(self, op):
         return 'RPyAssert(%s, %s);' % (self.expr(op.args[0]),

Modified: pypy/branch/jit-unroll-loops/pypy/translator/c/gcc/test/test_trackgcroot.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/translator/c/gcc/test/test_trackgcroot.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/translator/c/gcc/test/test_trackgcroot.py	Sat Nov 27 14:45:32 2010
@@ -98,13 +98,14 @@
 """
     lines = source.splitlines(True)
     parts = list(DarwinAssemblerParser().find_functions(iter(lines)))
-    assert len(parts) == 6
+    assert len(parts) == 7
     assert parts[0] == (False, lines[:3])
     assert parts[1] == (True,  lines[3:7])
     assert parts[2] == (True,  lines[7:11])
-    assert parts[3] == (True,  lines[11:18])
-    assert parts[4] == (True,  lines[18:20])
-    assert parts[5] == (False, lines[20:])
+    assert parts[3] == (True,  lines[11:13])
+    assert parts[4] == (False, lines[13:18])
+    assert parts[5] == (True,  lines[18:20])
+    assert parts[6] == (False, lines[20:])
  
 def test_computegcmaptable():
     tests = []

Modified: pypy/branch/jit-unroll-loops/pypy/translator/c/gcc/trackgcroot.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/translator/c/gcc/trackgcroot.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/translator/c/gcc/trackgcroot.py	Sat Nov 27 14:45:32 2010
@@ -1107,7 +1107,7 @@
     format = 'darwin64'
     function_names_prefix = '_'
 
-    LABEL = ElfFunctionGcRootTracker64.LABEL
+    LABEL = ElfFunctionGcRootTracker32.LABEL
     r_jmptable_item = re.compile(r"\t.(?:long|quad)\t"+LABEL+"(-\"?[A-Za-z0-9$]+\"?)?\s*$")
 
     r_functionstart = re.compile(r"_(\w+):\s*$")
@@ -1406,7 +1406,6 @@
                      'const_data'
                      ]
     r_sectionstart = re.compile(r"\t\.("+'|'.join(OTHERSECTIONS)+").*$")
-    sections_doesnt_end_function = {'cstring': True, 'const': True}
 
     def find_functions(self, iterlines):
         functionlines = []
@@ -1414,20 +1413,20 @@
         in_function = False
         for n, line in enumerate(iterlines):
             if self.r_textstart.match(line):
+                assert not in_text, "unexpected repeated .text start: %d" % n
                 in_text = True
             elif self.r_sectionstart.match(line):
-                sectionname = self.r_sectionstart.match(line).group(1)
-                if (in_function and
-                    sectionname not in self.sections_doesnt_end_function):
+                if in_function:
                     yield in_function, functionlines
                     functionlines = []
-                    in_function = False
                 in_text = False
+                in_function = False
             elif in_text and self.FunctionGcRootTracker.r_functionstart.match(line):
                 yield in_function, functionlines
                 functionlines = []
                 in_function = True
             functionlines.append(line)
+
         if functionlines:
             yield in_function, functionlines
 
@@ -1444,6 +1443,23 @@
     format = "mingw32"
     FunctionGcRootTracker = Mingw32FunctionGcRootTracker
 
+    def find_functions(self, iterlines):
+        functionlines = []
+        in_text = False
+        in_function = False
+        for n, line in enumerate(iterlines):
+            if self.r_textstart.match(line):
+                in_text = True
+            elif self.r_sectionstart.match(line):
+                in_text = False
+            elif in_text and self.FunctionGcRootTracker.r_functionstart.match(line):
+                yield in_function, functionlines
+                functionlines = []
+                in_function = True
+            functionlines.append(line)
+        if functionlines:
+            yield in_function, functionlines
+
 class MsvcAssemblerParser(AssemblerParser):
     format = "msvc"
     FunctionGcRootTracker = MsvcFunctionGcRootTracker

Modified: pypy/branch/jit-unroll-loops/pypy/translator/c/src/debug_alloc.h
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/translator/c/src/debug_alloc.h	(original)
+++ pypy/branch/jit-unroll-loops/pypy/translator/c/src/debug_alloc.h	Sat Nov 27 14:45:32 2010
@@ -1,5 +1,5 @@
 /**************************************************************/
-/***  tracking raw mallocs and frees for debugging          ***/
+ /***  tracking raw mallocs and frees for debugging          ***/
 
 #ifndef RPY_ASSERT
 
@@ -62,8 +62,8 @@
     count++;
   if (count > 0)
     {
-      char *env = getenv("PYPY_ALLOC");
       fprintf(stderr, "debug_alloc.h: %ld mallocs left", count);
+      char *env = getenv("PYPY_ALLOC");
       if (env && *env)
         {
           fprintf(stderr, " (most recent first):\n");

Modified: pypy/branch/jit-unroll-loops/pypy/translator/c/src/debug_print.h
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/translator/c/src/debug_print.h	(original)
+++ pypy/branch/jit-unroll-loops/pypy/translator/c/src/debug_print.h	Sat Nov 27 14:45:32 2010
@@ -10,7 +10,6 @@
                      but not any nested debug_print
    :fname         full logging
    prefix:fname   conditional logging
-   prefix1,prefix2:fname   conditional logging with multiple selections
 
    Conditional logging means that it only includes the debug_start/debug_stop
    sections whose name match 'prefix'.  Other sections are ignored, including
@@ -71,12 +70,6 @@
 static void pypy_debug_open(void)
 {
   char *filename = getenv("PYPYLOG");
-  if (filename)
-#ifndef MS_WINDOWS
-    unsetenv("PYPYLOG");   /* don't pass it to subprocesses */
-#else
-    putenv("PYPYLOG=");    /* don't pass it to subprocesses */
-#endif
   if (filename && filename[0])
     {
       char *colon = strchr(filename, ':');
@@ -146,22 +139,12 @@
 #endif
 
 
-static bool_t startswithoneof(const char *str, const char *substr)
+static bool_t startswith(const char *str, const char *substr)
 {
-  const char *p = str;
-  for (; *substr; substr++)
-    {
-      if (*substr != ',')
-        {
-          if (p && *p++ != *substr)
-            p = NULL;   /* mismatch */
-        }
-      else if (p != NULL)
-        return 1;   /* match */
-      else
-        p = str;    /* mismatched, retry with the next */
-    }
-  return p != NULL;
+  while (*substr)
+    if (*str++ != *substr++)
+      return 0;
+  return 1;
 }
 
 #if defined(_MSC_VER) || defined(__MINGW32__)
@@ -192,7 +175,7 @@
   if (!debug_profile)
     {
       /* non-profiling version */
-      if (!debug_prefix || !startswithoneof(category, debug_prefix))
+      if (!debug_prefix || !startswith(category, debug_prefix))
         {
           /* wrong section name, or no PYPYLOG at all, skip it */
           return;

Modified: pypy/branch/jit-unroll-loops/pypy/translator/c/src/g_include.h
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/translator/c/src/g_include.h	(original)
+++ pypy/branch/jit-unroll-loops/pypy/translator/c/src/g_include.h	Sat Nov 27 14:45:32 2010
@@ -43,10 +43,6 @@
 #  include "src/asm_gcc_x86.h"
 #endif
 
-#if defined(__GNUC__) && defined(__amd64__)
-#  include "src/asm_gcc_x86_64.h"
-#endif
-
 #if defined(__GNUC__) && defined(__ppc__)
 #  include "src/asm_ppc.h"
 #endif

Modified: pypy/branch/jit-unroll-loops/pypy/translator/c/src/mem.h
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/translator/c/src/mem.h	(original)
+++ pypy/branch/jit-unroll-loops/pypy/translator/c/src/mem.h	Sat Nov 27 14:45:32 2010
@@ -233,4 +233,4 @@
 #define OP_GC_GET_RPY_MEMORY_USAGE(x, r) r = -1
 #define OP_GC_GET_RPY_TYPE_INDEX(x, r)   r = -1
 #define OP_GC_IS_RPY_INSTANCE(x, r)      r = 0
-#define OP_GC_DUMP_RPY_HEAP(fd, r)       r = 0
+#define OP_GC_DUMP_RPY_HEAP(r)           r = 0

Modified: pypy/branch/jit-unroll-loops/pypy/translator/c/test/test_newgc.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/translator/c/test/test_newgc.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/translator/c/test/test_newgc.py	Sat Nov 27 14:45:32 2010
@@ -1064,16 +1064,14 @@
     def test_get_rpy_type_index(self):
         self.run("get_rpy_type_index")
 
-    filename1_dump = str(udir.join('test_dump_rpy_heap.1'))
-    filename2_dump = str(udir.join('test_dump_rpy_heap.2'))
+    filename_dump = str(udir.join('test_dump_rpy_heap'))
     def define_dump_rpy_heap(self):
         U = lltype.GcForwardReference()
         U.become(lltype.GcStruct('U', ('next', lltype.Ptr(U)),
                                  ('x', lltype.Signed)))
         S = lltype.GcStruct('S', ('u', lltype.Ptr(U)))
         A = lltype.GcArray(lltype.Ptr(S))
-        filename1 = self.filename1_dump
-        filename2 = self.filename2_dump
+        filename = self.filename_dump
 
         def fn():
             s = lltype.malloc(S)
@@ -1083,31 +1081,20 @@
             a = lltype.malloc(A, 1000)
             s2 = lltype.malloc(S)
             #
-            fd1 = os.open(filename1, os.O_WRONLY | os.O_CREAT, 0666)
-            fd2 = os.open(filename2, os.O_WRONLY | os.O_CREAT, 0666)
-            rgc.dump_rpy_heap(fd1)
-            rgc.dump_rpy_heap(fd2)      # try twice in a row
+            fd = os.open(filename, os.O_WRONLY | os.O_CREAT, 0666)
+            rgc.dump_rpy_heap(fd)
             keepalive_until_here(s2)
             keepalive_until_here(s)
             keepalive_until_here(a)
-            os.close(fd1)
-            os.close(fd2)
+            os.close(fd)
             return 0
 
         return fn
 
     def test_dump_rpy_heap(self):
         self.run("dump_rpy_heap")
-        for fn in [self.filename1_dump, self.filename2_dump]:
-            assert os.path.exists(fn)
-            assert os.path.getsize(fn) > 64
-        f = open(self.filename1_dump)
-        data1 = f.read()
-        f.close()
-        f = open(self.filename2_dump)
-        data2 = f.read()
-        f.close()
-        assert data1 == data2
+        assert os.path.exists(self.filename_dump)
+        assert os.path.getsize(self.filename_dump) > 64
 
     filename_dump_typeids_z = str(udir.join('test_typeids_z'))
     def define_write_typeids_z(self):

Modified: pypy/branch/jit-unroll-loops/pypy/translator/c/test/test_standalone.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/translator/c/test/test_standalone.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/translator/c/test/test_standalone.py	Sat Nov 27 14:45:32 2010
@@ -272,7 +272,7 @@
             x = "got:"
             debug_start  ("mycat")
             if have_debug_prints(): x += "b"
-            debug_print    ("foo", r_longlong(2), "bar", 3)
+            debug_print    ("foo", 2, "bar", 3)
             debug_start      ("cat2")
             if have_debug_prints(): x += "c"
             debug_print        ("baz")
@@ -368,27 +368,12 @@
         assert not err
         assert path.check(file=1)
         data = path.read()
-        assert 'toplevel' in data
-        assert 'mycat' not in data
-        assert 'foo 2 bar 3' not in data
+        assert 'toplevel' in path.read()
+        assert 'mycat' not in path.read()
+        assert 'foo 2 bar 3' not in path.read()
         assert 'cat2' in data
         assert 'baz' in data
         assert 'bok' not in data
-        # check with PYPYLOG=myc,cat2:somefilename   (includes mycat and cat2)
-        path = udir.join('test_debug_xxx_myc_cat2.log')
-        out, err = cbuilder.cmdexec("", err=True,
-                                    env={'PYPYLOG': 'myc,cat2:%s' % path})
-        assert out.strip() == 'got:bcda.'
-        assert not err
-        assert path.check(file=1)
-        data = path.read()
-        assert 'toplevel' in data
-        assert '{mycat' in data
-        assert 'mycat}' in data
-        assert 'foo 2 bar 3' in data
-        assert 'cat2' in data
-        assert 'baz' in data
-        assert 'bok' in data
         #
         # finally, check compiling with logging disabled
         from pypy.config.pypyoption import get_pypy_config
@@ -403,20 +388,6 @@
         assert not err
         assert path.check(file=0)
 
-    def test_debug_print_start_stop_nonconst(self):
-        def entry_point(argv):
-            debug_start(argv[1])
-            debug_print(argv[2])
-            debug_stop(argv[1])
-            return 0
-        t, cbuilder = self.compile(entry_point)
-        out, err = cbuilder.cmdexec("foo bar", err=True, env={'PYPYLOG': ':-'})
-        lines = err.splitlines()
-        assert '{foo' in lines[0]
-        assert 'bar' == lines[1]
-        assert 'foo}' in lines[2]
-
-
     def test_fatal_error(self):
         def g(x):
             if x == 1:

Modified: pypy/branch/jit-unroll-loops/pypy/translator/driver.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/translator/driver.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/translator/driver.py	Sat Nov 27 14:45:32 2010
@@ -11,7 +11,7 @@
 from pypy.annotation import policy as annpolicy
 import optparse
 from pypy.tool.udir import udir
-from pypy.tool.debug_print import debug_start, debug_print, debug_stop
+from pypy.rlib.jit import DEBUG_OFF, DEBUG_DETAILED, DEBUG_PROFILE, DEBUG_STEPS
 from pypy.rlib.entrypoint import secondary_entrypoints
 
 import py
@@ -37,6 +37,13 @@
     'c': 'lltype',
 }
 
+JIT_DEBUG = {
+    'off' : DEBUG_OFF,
+    'profile' : DEBUG_PROFILE,
+    'steps' : DEBUG_STEPS,
+    'detailed' : DEBUG_DETAILED,
+}
+
 def backend_to_typesystem(backend):
     return _BACKEND_TO_TYPESYSTEM.get(backend, 'ootype')
 
@@ -276,8 +283,6 @@
             return
         else:
             self.log.info("%s..." % title)
-        debug_start('translation-task')
-        debug_print('starting', goal)
         self.timer.start_event(goal)
         try:
             instrument = False
@@ -295,13 +300,11 @@
                 assert False, 'we should not get here'
         finally:
             try:
-                debug_stop('translation-task')
                 self.timer.end_event(goal)
             except (KeyboardInterrupt, SystemExit):
                 raise
             except:
                 pass
-        #import gc; gc.dump_rpy_heap('rpyheap-after-%s.dump' % goal)
         return res
 
     def task_annotate(self):
@@ -396,6 +399,7 @@
         #
         from pypy.jit.metainterp.warmspot import apply_jit
         apply_jit(self.translator, policy=self.jitpolicy,
+                  debug_level=JIT_DEBUG[self.config.translation.jit_debug],
                   backend_name=self.config.translation.jit_backend, inline=True)
         #
         self.log.info("the JIT compiler was generated")
@@ -413,6 +417,7 @@
         #
         from pypy.jit.metainterp.warmspot import apply_jit
         apply_jit(self.translator, policy=self.jitpolicy,
+                  debug_level=JIT_DEBUG[self.config.translation.jit_debug],
                   backend_name='cli', inline=True) #XXX
         #
         self.log.info("the JIT compiler was generated")

Modified: pypy/branch/jit-unroll-loops/pypy/translator/goal/targetpypystandalone.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/translator/goal/targetpypystandalone.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/translator/goal/targetpypystandalone.py	Sat Nov 27 14:45:32 2010
@@ -28,14 +28,9 @@
     w_call_finish_gateway = space.wrap(gateway.interp2app(call_finish))
     w_call_startup_gateway = space.wrap(gateway.interp2app(call_startup))
     w_os = setup_nanos(space)
-    withjit = space.config.objspace.usemodules.pypyjit
 
     def entry_point(argv):
         space.timer.start("Entrypoint")
-        if withjit:
-            from pypy.jit.backend.hlinfo import highleveljitinfo
-            highleveljitinfo.sys_executable = argv[0]
-
         #debug("entry point starting") 
         #for arg in argv: 
         #    debug(" argv -> " + arg)

Modified: pypy/branch/jit-unroll-loops/pypy/translator/goal/test2/test_app_main.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/translator/goal/test2/test_app_main.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/translator/goal/test2/test_app_main.py	Sat Nov 27 14:45:32 2010
@@ -534,8 +534,7 @@
             newpath = app_main.get_library_path('/tmp/pypy-c') # stdlib not found
             assert newpath == sys.path
             newpath = app_main.get_library_path(self.fake_exe)
-            # we get at least 'expected_path', and maybe more (e.g.plat-linux2)
-            assert newpath[:len(self.expected_path)] == self.expected_path
+            assert newpath == self.expected_path
         finally:
             sys.path.pop()
 
@@ -548,9 +547,7 @@
             app_main.os = os
             pypy_c = os.path.join(self.trunkdir, 'pypy', 'translator', 'goal', 'pypy-c')
             newpath = app_main.get_library_path(pypy_c)
-            # we get at least lib_pypy, lib-python/modified-X.Y.Z,
-            # lib-python/X.Y.Z, and maybe more (e.g. plat-linux2)
-            assert len(newpath) >= 3
+            assert len(newpath) == 3
             for p in newpath:
                 assert p.startswith(self.trunkdir)
         finally:

Modified: pypy/branch/jit-unroll-loops/pypy/translator/platform/darwin.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/translator/platform/darwin.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/translator/platform/darwin.py	Sat Nov 27 14:45:32 2010
@@ -12,14 +12,12 @@
 
     so_ext = 'so'
     
-    default_cc = 'gcc'
-
     def __init__(self, cc=None):
         if cc is None:
             try:
                 cc = os.environ['CC']
             except KeyError:
-                cc = self.default_cc
+                cc = 'gcc'
         self.cc = cc
 
     def _args_for_shared(self, args):
@@ -87,4 +85,3 @@
     link_flags = ('-arch', 'x86_64', '-mmacosx-version-min=10.4')
     cflags = ('-arch', 'x86_64', '-O3', '-fomit-frame-pointer',
               '-mmacosx-version-min=10.4')
-    default_cc = 'gcc-4.0'

Modified: pypy/branch/jit-unroll-loops/pypy/translator/platform/linux.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/translator/platform/linux.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/translator/platform/linux.py	Sat Nov 27 14:45:32 2010
@@ -27,8 +27,6 @@
 
 
 class Linux(BaseLinux):
-    shared_only = ()    # it seems that on 32-bit linux, compiling with -fPIC
-                        # gives assembler that asmgcc is not happy about.
     def library_dirs_for_libffi_a(self):
         # places where we need to look for libffi.a
         return self.library_dirs_for_libffi() + ['/usr/lib']

Modified: pypy/branch/jit-unroll-loops/pypy/translator/platform/posix.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/translator/platform/posix.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/translator/platform/posix.py	Sat Nov 27 14:45:32 2010
@@ -104,10 +104,12 @@
         else:
             target_name = exe_name.basename
 
-        if shared:
-            cflags = self.cflags + self.shared_only
-        else:
-            cflags = self.cflags + self.standalone_only
+        cflags = self.cflags
+        if sys.maxint > 2147483647:   # XXX XXX XXX sort this out
+            if shared:
+                cflags = self.cflags + self.shared_only
+            else:
+                cflags = self.cflags + self.standalone_only
 
         m = GnuMakefile(path)
         m.exe_name = exe_name

Modified: pypy/branch/jit-unroll-loops/pypy/translator/tool/reftracker.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/translator/tool/reftracker.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/translator/tool/reftracker.py	Sat Nov 27 14:45:32 2010
@@ -3,7 +3,7 @@
 Usage: call track(obj).
 """
 
-import autopath, sys, os, types
+import autopath, sys, os
 import gc
 from pypy.translator.tool.graphpage import GraphPage, DotGen
 from pypy.tool.uid import uid
@@ -39,7 +39,7 @@
                 if o2 is None:
                     continue
                 addedge(objectlist[i], o2)
-                id2typename[uid(o2)] = self.shortrepr(o2)
+                id2typename[uid(o2)] = type(o2).__name__
                 del o2
             for o2 in self.get_referrers(objectlist[i]):
                 if o2 is None:
@@ -47,7 +47,7 @@
                 if type(o2) is list and o2 and o2[0] is MARKER:
                     continue
                 addedge(o2, objectlist[i])
-                id2typename[uid(o2)] = self.shortrepr(o2)
+                id2typename[uid(o2)] = type(o2).__name__
                 del o2
 
         for ids, label in edges.items():
@@ -82,23 +82,13 @@
         return self.newpage(objectlist)
 
     def formatobject(self, o):
-        header = self.shortrepr(o, compact=False)
-        secondline = repr(o.__class__)
-        return header, secondline, repr(o)
-
-    def shortrepr(self, o, compact=True):
-        t = type(o)
-        if t is types.FrameType:
-            if compact:
-                return 'frame %r' % (o.f_code.co_name,)
-            else:
-                return 'frame %r' % (o.f_code,)
         s = repr(o)
         if len(s) > 50:
+            linktext = s
             s = s[:20] + ' ... ' + s[-20:]
-        if s.startswith('<') and s.endswith('>'):
-            s = s[1:-1]
-        return s
+        else:
+            linktext = ''
+        return type(o).__name__, s, linktext
 
     def edgelabel(self, o1, o2):
         return ''



More information about the Pypy-commit mailing list