-
Notifications
You must be signed in to change notification settings - Fork 3.8k
[profiler] GC roots revamp. #5126
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
Conversation
79b2960 to
4e24dc9
Compare
|
@alexrp the PR is read for review / merge. |
mono/profiler/log.c
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doesn't this need a MLPD version bump?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We already bumped it in master and haven't shipped it yet AFAIK.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
mono/metadata/boehm-gc.c
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should raise these events in Boehm since we don't report roots anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did it out of completeness. Boehm doesn't really matter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few things:
- Please add a comment above the enum that points to the C enum (as for the others here).
- I think
LogHeapRootSourcewould be a better name, since e.g.Threadingis not a kind, it's the subsystem of the runtime (source) it comes from. - I prefer to use explicit enum values when we're mapping to a C enum, especially if that C enum is using explicit values too.
- I think we should use singular names here, i.e.
StaticVariable,GCHandle, etc. Marshalling->Marshalfor consistency with the rest of .NET.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be HeapRootUnregister.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed
mono/metadata/gc-internals.h
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't forget that this will require changes in the products.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How so? I don't think they use mono_gc_register_root directly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right. For some reason, I was under the impression that they did. Why on earth are these MONO_API then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe they use in a sneaky way, I'll check more carefully before merging.
mono/metadata/marshal.c
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor point: 0 -> NULL for clarity.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No separate source value for critical finalizers?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if it matters, the distinction today exists as each get a separate pseudo-address when their roots get registered.
Given that the vast majority of C# users don't know that critical finalizers exists, I think it's ok to keep them all on the sabe basket until it turns to be an issue.
mono/profiler/log.h
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be TYPE_HEAP_ROOT_REGISTER and TYPE_HEAP_ROOT_UNREGISTER.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
mono/profiler/log.h
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line should go in the changelog for the profiler version, not the data version, further up the file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
mono/profiler/log.h
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should document specifically which event it used to be emitted after and which one we emit it after now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, reorganized
mono/profiler/log.h
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, indentation is off. We use spaces here for whatever reason.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Odd, but fixed
mono/profiler/log.c
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A bit of line damage here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
mono/profiler/log.c
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing TYPE_HEAP_ROOT_UNREGISTER.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
mono/metadata/profiler.h
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's up with this one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
garbage, removed.
|
null-gc.c will need to be updated for some of these changes. |
mono/metadata/sgen-mono.c
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't the handle stack allocated with mono_gc_alloc_fixed or something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it uses g_malloc.
|
@BrzVlad could you review the SGen parts? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor point: You could use object initializers for these.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
mono/metadata/threads.c
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This cast looks wrong. In the thread_started event above, we pass the result of MONO_NATIVE_THREAD_ID_TO_UINT (tid) (see the call site of this function), but here, we convert it back to native thread ID before passing it.
Same for most of this file. We should be consistent about passing one kind of TID.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, it's messy. I'll see if I can just pass in a void*
mono/metadata/object.c
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In what situations do we expect thread->internal_thread to not be set here? I'm not too familiar with this code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
During attach/detach all goes. It's defensive programing. :(
mono/metadata/profiler-events.h
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- I generally try to keep these events 'namespaced', so these should be
gc_roots,gc_root_register, andgc_root_unregister. - They should also be in the section above with the other
gc_*events. GcRoots2->GCRoots, especially since we're just removing the old event entirely.gc_root_registershould be typed asconst mono_byte *start, uintptr_t size, MonoGCRootSource source, const void *key, const char *msgfor consistency with the rest of the events.gc_root_unregistershould be typed asconst mono_byte *start.gc_rootsshould be typed asuint64_t count, const mono_byte *const *addresses, MonoObject *const *objects.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed the signature
|
The comments for |
|
The comments on MonoGCRootSource are still correct. I updated the comments that those values now leak into the profiler API. I think it's ok that the null-gc.c gets no profiling support, I don't think it needs anything else. Reduced the amount of casting in threads.c around tid. |
I was referring to the changed signature of |
This change re-implement GC roots reporting in a way that allows users to correctly track the source of a GC root. The new design is based on emitting GC root information upfront and only report addresses during heap dumps. When a GC root is registered we emit an event that is an address range, the root kind, a key and a text description. A decoder can use this information to match a reported root address with all registration addresses to figure out what they mean. A GC Root key is used to further its meaning. For example, if kind is thread, key is a tid, if kind is static variables, key is the class pointer and so on. The build of the change is introducing this key argument across all root registration code and rework our root reporting code to encode their addresses. Some roots use pseudo-addresses when they are not registrable. This is the case of thread stacks/registers and the finalizer queue. Finally, root reporting was changed to happen only once per collection and at the end, leading to correct and useful data being produced.
e6b7b16 to
129ca06
Compare
|
close |
|
build profiler stress |
| gc_root_register (MonoProfiler *prof, const mono_byte *start, size_t size, MonoGCRootSource kind, const void *key, const char *msg) | ||
| { | ||
| int msg_len = msg ? strlen (msg) + 1 : 0; | ||
| ENTER_LOG (&heap_roots_ctr, logbuffer, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I forgot to mention this in my last review: Each kind of event should have its own kind of counter, so you'll want to add one for root register and root unregister events.
| if (profile_roots) | ||
| notify_gc_roots (&major_root_report); | ||
| if (!MONO_PROFILER_ENABLED (gc_roots)) | ||
| return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be a good idea to put a TODO comment here so it isn't forgotten.
| void | ||
| sgen_client_pinning_end (void) | ||
| { | ||
| if (!MONO_PROFILER_ENABLED (gc_roots)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's unclear what purpose this check serves.
|
@luhenry if you're interested in working on it, rebase and resubmit it. I don't think merge commits with tons of changes is something we want. I don't remember what was missing from this PR beyond what's stated on it. |
This is not ready for review, tons of line damage, debug spew and half done changes.