Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@kumpera
Copy link
Contributor

@kumpera kumpera commented Jun 27, 2017

This is not ready for review, tons of line damage, debug spew and half done changes.

@kumpera
Copy link
Contributor Author

kumpera commented Jul 13, 2017

@alexrp the PR is read for review / merge.
I don't expect to work further on the runtime side for now.
Further work will happen in the managed library to integrate my local tests.

Copy link
Contributor

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?

Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

@alexrp alexrp Jul 14, 2017

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 LogHeapRootSource would be a better name, since e.g. Threading is 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 -> Marshal for consistency with the rest of .NET.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

Copy link
Contributor

Choose a reason for hiding this comment

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

Should be HeapRootUnregister.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Renamed

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

Copy link
Contributor

@alexrp alexrp Jul 14, 2017

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, reorganized

Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Odd, but fixed

Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

garbage, removed.

@alexrp
Copy link
Contributor

alexrp commented Jul 14, 2017

null-gc.c will need to be updated for some of these changes.

Copy link
Contributor

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?

Copy link
Contributor Author

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.

@alexrp
Copy link
Contributor

alexrp commented Jul 14, 2017

@BrzVlad could you review the SGen parts?

@alexrp alexrp requested a review from BrzVlad July 14, 2017 11:42
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Contributor

@alexrp alexrp Jul 14, 2017

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.

Copy link
Contributor Author

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*

Copy link
Contributor

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.

Copy link
Contributor Author

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. :(

Copy link
Contributor

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, and gc_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_register should be typed as const mono_byte *start, uintptr_t size, MonoGCRootSource source, const void *key, const char *msg for consistency with the rest of the events.
  • gc_root_unregister should be typed as const mono_byte *start.
  • gc_roots should be typed as uint64_t count, const mono_byte *const *addresses, MonoObject *const *objects.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed the signature

@alexrp
Copy link
Contributor

alexrp commented Jul 14, 2017

The comments for MonoGCRootSource in mono/metadata/mono-gc.h should be updated since we use these values differently than I originally planned to.

@kumpera
Copy link
Contributor Author

kumpera commented Jul 14, 2017

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.

@alexrp
Copy link
Contributor

alexrp commented Jul 14, 2017

I think it's ok that the null-gc.c gets no profiling support, I don't think it needs anything else.

I was referring to the changed signature of mono_gc_register_root.

@kumpera kumpera requested a review from luhenry as a code owner July 14, 2017 23:28
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.
@kumpera kumpera force-pushed the gc_roots_experiments branch from e6b7b16 to 129ca06 Compare July 17, 2017 23:22
@kumpera
Copy link
Contributor Author

kumpera commented Jul 17, 2017

close

@kumpera
Copy link
Contributor Author

kumpera commented Jul 17, 2017

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,
Copy link
Contributor

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;
Copy link
Contributor

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))
Copy link
Contributor

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
Copy link
Contributor

luhenry commented Oct 5, 2017

@kumpera I created kumpera#4 for merging master in this PR to resolve all the conflicts. What else would block it getting merged?

@kumpera
Copy link
Contributor Author

kumpera commented Oct 5, 2017

@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.

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.

6 participants