Skip to content

gc.c: Ensure a gap of one byte before the finaliser table. #7722

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from

Conversation

jepler
Copy link
Contributor

@jepler jepler commented Aug 27, 2021

.. or, for !MICROPY_ENABLE_FINALISER, before the first block of the pool.

Closes: adafruit#5021
Closes: #7716

I tested this with a version of #7716 (comment) and there were no problems detected. I haven't tested it on our real HW yet. it also fixes the original problem on our real hw

jepler added 3 commits August 27, 2021 09:23
When you wish to use the valgrind memory analysis tool on micropython,
you can arrange to define MICROPY_DEBUG_VALGRIND to enable use of
special valgrind macros. For now, this only fixes `gc_get_ptr`
so that it never emits the diagnostic "Conditional jump or move depends
on uninitialised value(s)".

Signed-off-by: Jeff Epler <jepler@gmail.com>
.. or, for !MICROPY_ENABLE_FINALISER, before the first block of the pool.

Closes: adafruit#5021
Closes: micropython#7116
Signed-off-by: Jeff Epler <jepler@gmail.com>
@codecov-commenter
Copy link

codecov-commenter commented Aug 27, 2021

Codecov Report

Merging #7722 (c9bd52f) into master (8c4ba57) will decrease coverage by 0.02%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #7722      +/-   ##
==========================================
- Coverage   98.27%   98.24%   -0.03%     
==========================================
  Files         154      154              
  Lines       20077    20042      -35     
==========================================
- Hits        19730    19690      -40     
- Misses        347      352       +5     
Impacted Files Coverage Δ
py/gc.c 99.07% <100.00%> (ø)
py/obj.c 96.82% <0.00%> (-1.20%) ⬇️
py/bc.c 88.65% <0.00%> (-1.04%) ⬇️
py/objlist.c 99.23% <0.00%> (-0.39%) ⬇️
py/compile.c 99.93% <0.00%> (-0.01%) ⬇️
py/objtype.c 100.00% <0.00%> (ø)
py/emitnative.c 99.26% <0.00%> (+<0.01%) ⬆️
py/parse.c 99.20% <0.00%> (+0.02%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8c4ba57...c9bd52f. Read the comment docs.

@jepler
Copy link
Contributor Author

jepler commented Aug 27, 2021

Can someone let me know what's going on with this CI failure? I didn't immediately make sense of it.

The team named '~pybricks' has no PPA named 'ubuntu/ppa'

@dlech
Copy link
Contributor

dlech commented Aug 27, 2021

The team named '~pybricks' has no PPA named 'ubuntu/ppa'

This is a PPA to get a backported version of uncrustify for Ubuntu 20.04. It has been working for quite a while, so maybe there is an issue with the https://launchpad.net site where this is hosted?

@dpgeorge dpgeorge added the py-core Relates to py/ directory in source label Aug 28, 2021
Copy link
Member

@dpgeorge dpgeorge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it at all possible to make a test for this?

@jepler
Copy link
Contributor Author

jepler commented Sep 15, 2021

I've updated this PR:

  • the 1-byte gap is now named
  • it fixes a second bug that occurred when the gap byte was not initialized (Clear the buffer byte between ATB and FTB adafruit/circuitpython#5348)
  • it unifies two memset calls into one, slight flash savings
  • an assertion and a test were added. Before this PR, the test would hit the assertion error in the unix coverage build

@jepler
Copy link
Contributor Author

jepler commented Sep 15, 2021

CI is encountering difficulties:

Run source tools/ci.sh && ci_code_formatting_setup
'Error reading https://launchpad.net/api/devel/~pybricks/+archive/ubuntu/ppa?ws.op=getSigningKeyData (4 tries): Internal Server Error'
Error: Process completed with exit code 1.

This test must be separate from the "regular" coverage test, as it
destroys the gc heap, and must exit via exit() rather than returning
to python code.

This test fails due to adafruit#7716.

Signed-off-by: Jeff Epler <jepler@gmail.com>
@jepler jepler force-pushed the pool-fix-micropython branch from 078f6fb to b776383 Compare September 15, 2021 16:21
@jepler
Copy link
Contributor Author

jepler commented Sep 15, 2021

.. and the Windows (appveyor) build is failing with almost every test saying "FATAL: uncaught NLR", which could be some new problem I've introduced even though no effect on nlr was intended.

@jepler jepler force-pushed the pool-fix-micropython branch 2 times, most recently from 794c4ed to 347046d Compare September 15, 2021 18:51
Signed-off-by: Jeff Epler <jepler@gmail.com>
@jepler jepler force-pushed the pool-fix-micropython branch from 347046d to 1ea027e Compare September 15, 2021 19:05
@jepler jepler requested a review from dpgeorge September 15, 2021 20:05
@dpgeorge
Copy link
Member

@@ -118,7 +128,8 @@ void gc_init(void *start, void *end) {
// => T = A * (1 + BLOCKS_PER_ATB / BLOCKS_PER_FTB + BLOCKS_PER_ATB * BYTES_PER_BLOCK)
size_t total_byte_len = (byte *)end - (byte *)start;
#if MICROPY_ENABLE_FINALISER
MP_STATE_MEM(gc_alloc_table_byte_len) = total_byte_len * MP_BITS_PER_BYTE / (MP_BITS_PER_BYTE + MP_BITS_PER_BYTE * BLOCKS_PER_ATB / BLOCKS_PER_FTB + MP_BITS_PER_BYTE * BLOCKS_PER_ATB * BYTES_PER_BLOCK);
size_t gc_alloc_table_byte_len = (total_byte_len - ALLOC_TABLE_GAP_BYTE) * MP_BITS_PER_BYTE / (MP_BITS_PER_BYTE + MP_BITS_PER_BYTE * BLOCKS_PER_ATB / BLOCKS_PER_FTB + MP_BITS_PER_BYTE * BLOCKS_PER_ATB * BYTES_PER_BLOCK);
MP_STATE_MEM(gc_alloc_table_byte_len) = gc_alloc_table_byte_len;
#else
MP_STATE_MEM(gc_alloc_table_byte_len) = total_byte_len / (1 + MP_BITS_PER_BYTE / 2 * BYTES_PER_BLOCK);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be (total_byte_len - ALLOCA_TABLE_GAP_BYTE) ...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed this during merge.

heap_size++;
}
mp_printf(&mp_plat_print, "# end coverage.c gc test\n");
exit(0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is quite brutal, to exit so abruptly! I wonder if there's a better way to do it...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is a good way to do it because it prevents coverage/testing of the tear down and exiting of the executable.

Two options I can think of:

  1. save and then restore the mp_state_mem_t struct in mp_state_ctx_t at the start/end of this function, which should restore the original heap on exit of this function
  2. run this code at the start or end of main() (probably at the start, just before gc_init()).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did option (1) during merge.

@dpgeorge
Copy link
Member

dpgeorge commented Dec 8, 2022

I rebased this, fixed up things as described above, and merged in 8407159 through d75ff42

@dpgeorge dpgeorge closed this Dec 8, 2022
@dpgeorge
Copy link
Member

dpgeorge commented Dec 8, 2022

Thanks @jepler , this is an important fix.

@jepler
Copy link
Contributor Author

jepler commented Jan 1, 2023

Thanks! And thank you for fixing the test to be more appropriate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
py-core Relates to py/ directory in source
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Problem in gc_mark_subtree in specific circumstances MagTag Vaccination tracker crash in magtag.network.connect() between 7alpha3 and 7alpha4
4 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy