Skip to content

py: Move all global state (variables) to a common place. #1017

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 2 commits into from

Conversation

dpgeorge
Copy link
Member

This is allows to keep track of where all the global variables are, and will help if we ever want to have a global state object to pass to each function. Although code size was not a reason for doing this, the change actually gives some savings of code size: about 60 bytes on x64, and 200 bytes (!) on stmhal.

This is for review only, and is still a bit messy. It also includes a partial move away from Plan 9 style header includes.

Comments welcome!

This is allows to keep track of where all the global variables are.
@pfalcon
Copy link
Contributor

pfalcon commented Dec 20, 2014

This is apparently good change, especially if it leads to code savings. Would need to review in more detail regarding what's included and what's not.

Some things to think about alongside this change:

  1. This change apparently mandates architecture that each VM would have own heap. Maybe worth supporting shared heap, i.e. have a separate structure for heap variables?
  2. Can we also think about optimzing gc roots scanning? Current scanning of entire .bss is sub-ideal - for example, having a static heap array puts it into .bss and then there's no real gc.

@dpgeorge
Copy link
Member Author

Glad you agree this is a good path to follow. The PR is messy, but the idea is there.

This change apparently mandates architecture that each VM would have own heap. Maybe worth supporting shared heap, i.e. have a separate structure for heap variables?

Yes, we can have a (sub)struct for heap/gc variables.

Can we also think about optimzing gc roots scanning? Current scanning of entire .bss is sub-ideal - for example, having a static heap array puts it into .bss and then there's no real gc.

Yes, definitely. It was on my agenda to have different structs for data, bss, and bss-containing-root-pointers. Just didn't know the cleanest way to do it yet.

@stinos
Copy link
Contributor

stinos commented Dec 21, 2014

It also includes a partial move away from Plan 9 style header includes

That might become a messy git log afterwards which becomes harder to investigate due to mixing (sort of) seperate issues. If the plan is to move away from Plan 9 anyway, consider doing that in one single commit and then build upon that?

For the rest: there should be only benefits to reducing the amount of global state so this is definitely a good thing

@dpgeorge
Copy link
Member Author

If the plan is to move away from Plan 9 anyway, consider doing that in one single commit and then build upon that?

Yeah, ok. I'll do a separate PR for that.

@dpgeorge
Copy link
Member Author

Note that, to support proper globals/locals context switching when calling functions, we should have an "outer" global state object which is small, easy to fit on the stack, and easy to change globals/locals. Something like:

struct mpy_ctx_t {
    mp_obj_dict_t *globals, *locals;
    mp_heap_state_t *heap_state;
    mp_interp_state_t *interp_state;
};

Possibly don't need to separate heap_state and interp_state here.

@dpgeorge
Copy link
Member Author

This PR is now waiting on #1022.

@dpgeorge
Copy link
Member Author

dpgeorge commented Jan 1, 2015

Superseded by #1032.

@dpgeorge dpgeorge closed this Jan 1, 2015
@dpgeorge dpgeorge deleted the global-state branch January 21, 2015 23:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants