Commit Graph

56 Commits

Author SHA1 Message Date
Damien George 516b09efc3 py, gc: Further reduce heap fragmentation with new, faster gc alloc.
The heap allocation is now exactly as it was before the "faster gc
alloc" patch, but it's still nearly as fast.  It is fixed by being
careful to always update the "last free block" pointer whenever the heap
changes (eg free or realloc).

Tested on all tests by enabling EXTENSIVE_HEAP_PROFILING in py/gc.c:
old and new allocator have exactly the same behaviour, just the new one
is much faster.
2014-08-28 23:06:38 +01:00
Damien George b796e3d848 py: Reduce fragmentation of GC heap.
Recent speed up of GC allocation made the GC have a fragmented heap.
This patch restores "original fragmentation behaviour" whilst still
retaining relatively fast allocation.  This patch works because there is
always going to be a single block allocated now and then, which advances
the gc_last_free_atb_index pointer often enough so that the whole heap
doesn't need scanning.

Should address issue #836.
2014-08-28 10:18:40 +01:00
Damien George d5e7f6e37e py: Speed up GC allocation.
This simple patch gives a very significant speed up for memory allocation
with the GC.

Eg, on PYBv1.0:
tests/basics/dict_del.py: 3.55 seconds -> 1.19 seconds
tests/misc/rge_sm.py:     15.3 seconds -> 2.48 seconds
2014-08-22 18:17:02 +01:00
Damien George a1d3ee376c py: Fix bug where GC finaliser table was not completely zeroed out.
This was a nasty bug to track down.  It only had consequences when the
heap size was just the right size to expose the rounding error in the
calculation of the finaliser table size.  And, a script had to allocate
a small (1 or 2 cell) object at the very end of the heap.  And, this
object must not have a finaliser.  And, the initial state of the heap
must have been all bits set to 1.  All these conspire on the pyboard,
but only if your run the script fresh (so unused memory is all 1's),
and if your script allocates a lot of small objects (eg 2-char strings
that are not interned).
2014-08-08 12:33:49 +01:00
Damien George 40f3c02682 Rename machine_(u)int_t to mp_(u)int_t.
See discussion in issue #50.
2014-07-03 13:25:24 +01:00
Dave Hylands 2fe841d2fa Try not to cause a MemoryError when raising an exception during nterrupt handling.
Step 1 fixes #732
2014-06-30 22:49:21 -07:00
Paul Sokolovsky 59c675a64c py: Include mpconfig.h before all other includes.
It defines types used by all other headers.

Fixes #691.
2014-06-21 22:43:22 +03:00
stijn 9acb5e4cf0 gc: Turn off debugging info again 2014-06-18 12:29:03 +02:00
stijn def10cecd1 gc: Keep debug statements at beginning of scope where possible 2014-06-18 10:20:41 +02:00
stijn bbcea3f62b gc: More verbose debugging
Add more DEBUG_printf statements to trace gc behaviour
2014-06-16 12:43:35 +02:00
Damien George c037694957 py, gc: Revert ret_ptr to void*, casting to byte* for memset. 2014-06-13 22:33:31 +01:00
stijn f33385f56d gc: Use byte* pointers instead of void* for pointer arithmetic
void* is of unknown size
2014-06-13 20:42:06 +02:00
Paul Sokolovsky 755a55f507 modgc: Implement return value for gc.collect(), enable on Unix. 2014-06-05 22:48:02 +03:00
Damien George 0fb80c303a py: Compress a little the bytecode emitter structure. 2014-05-10 18:16:21 +01:00
Damien George 04b9147e15 Add license header to (almost) all files.
Blanket wide to all .c and .h files.  Some files originating from ST are
difficult to deal with (license wise) so it was left out of those.

Also merged modpyb.h, modos.h, modstm.h and modtime.h in stmhal/.
2014-05-03 23:27:38 +01:00
Damien George 32bef315be py, gc: Only zero out the extra bytes at the end of the heap chunk.
This is a small optimisation to zero out only the additional bytes that
the caller did not ask for.
2014-04-26 22:23:42 +01:00
Damien George c492cf1f44 Merge branch 'master' of github.com:micropython/micropython 2014-04-25 23:45:52 +01:00
Damien George daab651c5c py, gc: Zero out newly allocated blocks in the GC.
Also add some more debugging output to gc_dump_alloc_table().

Now that newly allocated heap is always zero'd, maybe we just make this
a policy for the uPy API to keep it simple (ie any new implementation of
memory allocation must zero all allocations).  This follows the D
language philosophy.

Before this patch, a previously used memory block which had pointers in
it may still retain those pointers if the new user of that block does
not actually use the entire block.  Eg, if I want 5 blocks worth of
heap, I actually get 8 (round up to nearest 4).  Then I never use the
last 3, so they keep their old values, which may be pointers pointing to
the heap, hence preventing GC.

In rare (or maybe not that rare) cases, this leads to long, unintentional
"linked lists" within the GC'd heap, filling it up completely.  It's
pretty rare, because you have to reuse exactly that memory which is part
of this "linked list", and reuse it in just the right way.

This should fix issue #522, and might have something to do with
issue #510.
2014-04-25 23:37:55 +01:00
Damien George 410f30772f py, gc: Fix old gc_realloc for case when NULL is passed in as ptr. 2014-04-25 11:44:53 +00:00
Paul Sokolovsky 5b991ae2d3 gc: gc_realloc(): Fix byte-to-block calculation. 2014-04-20 20:46:39 +03:00
Damien George dde739d364 py, gc: Further simplify coding-style of gc_realloc.
No logic changes, just coding style to make it easy to read.
2014-04-20 18:16:25 +01:00
Paul Sokolovsky c86889dafb gc: "new" gc_realloc: Rewrite in plain C, fixing bunch of bugs.
There were typos, various rounding errors trying to do concurrent counting
in bytes vs blocks, complex conditional paths, superfluous variables, etc.,
etc., all leading to obscure segfaults.
2014-04-20 13:08:33 +03:00
Paul Sokolovsky ed162b5ef2 gc: Recover simple gc_realloc implementation, make easier to switch between. 2014-04-20 13:08:33 +03:00
Paul Sokolovsky 03b9ad7b01 gc.c: Remove superfluous typedef (bute defined in misc.h). 2014-04-09 04:13:21 +03:00
Damien George 443e018a3f py: Improve GC locking/unlocking, and make it part of the API. 2014-04-08 11:31:21 +00:00
Damien George 12bab72d93 Improve GC finalisation code; add option to disable it. 2014-04-05 20:35:48 +01:00
Damien George 8123a3339d Merge pull request #425 from iabdalkader/del
Implement del
2014-04-05 18:49:39 +01:00
mux cc849f70f4 Move del to locals 2014-04-05 15:49:03 +02:00
mux 4f7e9f5c44 Implement del 2014-04-03 23:55:12 +02:00
Paul Sokolovsky e807fa8d60 gc: Uses uint defined in misc.h. 2014-04-02 20:36:32 +03:00
Damien George 70f33cde48 py: Fix up so that it can compile without float. 2014-04-02 17:06:05 +01:00
xbe efe3422394 py: Clean up includes.
Remove unnecessary includes. Add includes that improve portability.
2014-03-17 02:43:40 -07:00
Damien George 470184e2c3 py: Cosmetic changes. 2014-03-12 22:44:11 +00:00
mux 8782676514 Fix realloc 2014-03-12 21:00:23 +02:00
Damien George 6fc765c928 py: Revert to old gc_realloc for now. 2014-03-07 00:21:51 +00:00
Damien George f08ddef676 py: Add comments to new gc_realloc, it has some bugs. 2014-03-06 23:59:01 +00:00
Damien George 73d579354b py: Small cosmetic changes to gc_realloc. 2014-03-06 00:02:16 +00:00
mux fbaa1479f4 Fix gc_realloc to expand in place
* Issue #322
2014-03-05 23:23:04 +02:00
Damien George ce1162ab15 GC: Fix printf formats for debugging; add gc_dump_alloc_table. 2014-02-26 22:55:59 +00:00
Damien George 41eb6086b7 py: Remove more var arg names fro macros with var args. 2014-02-26 22:40:35 +00:00
Paul Sokolovsky 44739e280e Make DEBUG_printf() a proper function, implementation is port-dependent.
In particular, unix outputs to stderr, to allow to run testsuite against
micropython built with debug output (by redirecting stderr to /dev/null).
2014-02-16 18:20:49 +02:00
Paul Sokolovsky 520e2f58a5 Replace global "static" -> "STATIC", to allow "analysis builds". Part 2. 2014-02-12 18:31:30 +02:00
Paul Sokolovsky 723a6ed371 More GC debugging improvements. 2014-02-11 18:09:50 +02:00
Paul Sokolovsky c0a8374103 gc: Don't segfault if gc_realloc() fails. 2014-02-11 15:34:32 +02:00
Paul Sokolovsky af19cbd201 gc: Make debug output configurable, revamp test function.
Test function needs to be called by something else. Test heap size reduced so
its dump fits on a screenful of a typical terminal.
2014-02-11 02:31:28 +02:00
Damien George 0004a84ec0 Revert "Move gc_collect to py/gc.c"
This reverts commit a215b09c0d.
2014-01-24 22:54:09 +00:00
mux a215b09c0d Move gc_collect to py/gc.c
* Move gc_collect from main to py/gc.c
* Define GC's memory boundaries in linker script
* Issue #220
2014-01-24 21:33:19 +02:00
Paul Sokolovsky fc5aac82cb Move BITS_PER_BYTE, BITS_PER_WORD to mpconfig.h for reuse. 2014-01-12 22:04:20 +02:00
Damien George d3ebe4829d Factor and simplify Makefile's and mpconfig, part 2. 2014-01-07 15:20:33 +00:00
Damien d99b05282d Change object representation from 1 big union to individual structs.
A big change.  Micro Python objects are allocated as individual structs
with the first element being a pointer to the type information (which
is itself an object).  This scheme follows CPython.  Much more flexible,
not necessarily slower, uses same heap memory, and can allocate objects
statically.

Also change name prefix, from py_ to mp_ (mp for Micro Python).
2013-12-21 18:17:45 +00:00