Skip to content

runtime: ctxt field scanned even if it is junk #7244

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
randall77 opened this issue Jan 31, 2014 · 11 comments
Closed

runtime: ctxt field scanned even if it is junk #7244

randall77 opened this issue Jan 31, 2014 · 11 comments
Milestone

Comments

@randall77
Copy link
Contributor

The ctxt argument to a function is saved unconditionally in
pkg/runtime/asm_*.s:runtime.morestack.

We queue it to be scanned in pkg/runtime/mgc0.c:addstackroots.

On functions which do not take a context argument (most of them), the context argument
contains junk.  It gets saved and then scanned as if it was a pointer.

This is imprecise for garbage collection.  We should either have different versions of
morestack for functions with and without context args, or have a flag in a Func
somewhere that tells us whether a function has a context arg.
@davecheney
Copy link
Contributor

Comment 1:

Could we arrange to have the context set to nil in these cases ? This wouldn't save the
overhead of adding it as a stack root, but it might be an improvement over scanning a
random value as a root.

@randall77
Copy link
Contributor Author

Comment 2:

That would be fine.  That's what I meant by "different version of morestack", one which
saves DX (or the arm equivalent) to ctxt and one which saves nil to ctxt.

@davecheney
Copy link
Contributor

Comment 3:

Thanks for your reply Keith. I probably don't understand the subtleties here but why is
the context argument that morestack copies junk in the first place? Is it possible to
address the problem at the source. FWIW introducing morestack variants sounds like the
better fix.

@randall77
Copy link
Contributor Author

Comment 4:

(x86-centric for a moment)
When a function takes a context, it gets passed in the register DX.  When it doesn't
take a context, DX contains some arbitrary junk.  Morestack unconditionally saves DX to
the ctxt field.  It doesn't know if it is being called from a context-taking function or
not.

@davecheney
Copy link
Contributor

Comment 5:

Can the compiler arrange for DX to be nil if there is no context field or would that
require that the caller must save DX on every function invocation ?

@randall77
Copy link
Contributor Author

Comment 6:

It would mean a MOV $0, DX in almost every function prologue (or almost every call
site), and I think that's too expensive.  Probably best to have morestack_clearDX
versions that clear DX and then jump to the regular morestacks.
It needs a better name than morestack_clearDX...

@davecheney
Copy link
Contributor

Comment 7:

I see. Thank you for helping me understand.

@davecheney
Copy link
Contributor

Comment 8:

Labels changed: added repo-main.

Status changed to Accepted.

@rsc
Copy link
Contributor

rsc commented Feb 12, 2014

Comment 9:

MOVL $0, DX is two bytes of code, and on Intel chips it is free, because it handled
during register renaming and not actually "executed". I think I'd rather do that than
double the set of morestack functions we have.

@rsc
Copy link
Contributor

rsc commented Mar 4, 2014

Comment 10:

I've started on the "double the morestacks" approach. I don't know what's causing the
finalizer flakiness so I am just grasping at straws addressing all the imprecise things
I know about.

Labels changed: added release-go1.3, removed release-go1.3maybe.

Status changed to Started.

@rsc
Copy link
Contributor

rsc commented Mar 4, 2014

Comment 11:

This issue was closed by revision c2dd33a.

Status changed to Fixed.

@rsc rsc added this to the Go1.3 milestone Apr 14, 2015
@rsc rsc removed the release-go1.3 label Apr 14, 2015
@golang golang locked and limited conversation to collaborators Jun 25, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants