Skip to content
This repository was archived by the owner on Nov 13, 2026. It is now read-only.

Emit GCDescs - #1212

Merged
MichalStrehovsky merged 12 commits into
dotnet:masterfrom
MichalStrehovsky:gcDesc
May 3, 2016
Merged

MichalStrehovsky merged 12 commits into
dotnet:masterfrom
MichalStrehovsky:gcDesc

Conversation

@MichalStrehovsky

@MichalStrehovsky MichalStrehovsky commented Apr 29, 2016 •

Copy link
Copy Markdown
Member
  • Data structure to hold pointer maps
  • Generate instance field pointer map
  • Generate GC static field pointer map
  • Generate thread static field pointer map
  • Serialize pointer maps into the GCDesc format understood by the GC for types
  • Serialize pointer maps into the GCDesc format understood by the GC for GC statics and thread statics.

_numCells = numCells;
}

public static GCPointerMap FromInstanceLayout(DefType type)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@davidwrighton pointed out we might want to cache value type pointer maps and just blindly apply them when they're needed because of an instance field. This method will have to leave the core type system because we don't have a good place to cache it (unless I can put it on the TypeSystemContext) :(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

For compiler, I doubt that the caching would make a difference. You have to go through all bits at the end anyway, and so this cache would not improve the complexity of the algorithm.

For the eventual runtime case, we may get the GCMap from the value type EETypes that act as natural cache in this case.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Cool, I pulled out the algorithm part in a side file so that it doesn't get in the way for consumers who don't want it. The type system algorithm will not try to cache then!

@MichalStrehovsky

Copy link
Copy Markdown
Member Author

Pushed an update that attempts to emit GCDescs for normal types. I have some confidence for normal types, but very little confidence for arrays.

I feel like I need to spend some time adding a unit test for ILCompiler.Compiler (including yet another unit testing fake base class library(?)) so that I can actually write tests for this.

{
get
{
if (GCDescSize == 0)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This symbol is not really needed by anything, but not defining a symbol at offset 0 of a Node trips up the object writer. This might be an ObjectWriter bug, but I didn't try to understand what's going on yet.

For reference, the line that gets tripped up is:

// First entry is the node (entry point) name.
_currentNodeName = _offsetToDefName[0][0];

MichalStrehovsky added a commit to MichalStrehovsky/corert that referenced this pull request May 1, 2016
I hit this in dotnet#1212 when I started prefixing EEType nodes with GCDesc.
We can either emit a useless symbol for the GCDesc, or merge this
change.
MichalStrehovsky added a commit that referenced this pull request May 1, 2016
#1225)

I hit this in #1212 when I started prefixing EEType nodes with GCDesc.
We can either emit a useless symbol for the GCDesc, or merge this
change.
@MichalStrehovsky MichalStrehovsky changed the title [WIP] Emit GCDescs Emit GCDescs May 2, 2016
@MichalStrehovsky

Copy link
Copy Markdown
Member Author

@jkotas Removed the [WIP] tag.

What's still left (and I would like to do in a separate pull request) is refactoring the GCStaticEETypeNode and EETypeNode so that they can share the GCDesc emission logic.

if (elementType.IsObjRef)
{
OutputStandardGCDesc(ref builder,
new GCPointerMap(new[] { 1 << 2 }, 3),

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

These numbers make little sense to me but it results in an EEType of the same shape that .NET Native for UWP produces for reference type arrays, so meh.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It would make more sense to me if the map argument is new GCPointerMap(new[] { 1 }, 1) here. Also, this needs a fudge factor for the multidimensional arrays.

Ideally, I would make this OutputArrayGCDesc(new GCPointerMap(new[] { 1 }, 1), multiDimmArrayDelta); and done the check for the shortcut as the first thing in OutputArrayGCDesc - if all bits in the GCDesc are set, use the standard encoding (just emit the right 3 words to make it understandable).

E.g. array of struct Foo {object a,b,c;} can use the standard encoding just fine.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

if all bits in the GCDesc are set, use the standard encoding (just emit the right 3 words to make it understandable).

I would rather avoid trying optimizations that are not present in .NET Native for UWP at this point. I have trouble validating that this code is not bogus as is. Troubleshooting GC holes is the last thing I would want to do.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could you please at least structure the code so that enabling this optimization is just about uncommenting a line - and add TODO comment next to it to?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

(We are going to have a bunch of GC holes to trace down either way - one more or less is not going to make a huge difference...)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Could you please at least structure the code so that enabling this optimization is just about uncommenting a line - and add TODO comment next to it to?

I'm making OutputArrayGCDesc take the extra int argument so that I can do the right thing for MDArrays. That should be enough, I suppose.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Also, the check for whether the standard desc can be used for arrays should be moved inside OutputArrayGCDesc.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Moving that there means the computation of GCDescSize becomes more complicated, since it mirrors the structure of OutputGCDesc. My point is trying to avoid the complexities and increasing my test matrix. I can't introduce unit tests for this at this point without making @nattress life miserable.

(Plus for many of these I don't know what the "expected" values are which makes writing tests more complicated. For someone who doesn't know how the GC operates (me), the GCDescs structures are super confusing.)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ok, I will take care of it later.

@jkotas

jkotas commented May 3, 2016

Copy link
Copy Markdown
Member

You should be able to remove the large GC budget for Windows + RyuJIT codegen as part of this change.

@MichalStrehovsky

Copy link
Copy Markdown
Member Author

You should be able to remove the large GC budget for Windows + RyuJIT codegen as part of this change

Can we remove that once we validate we can survive at least one GC? I didn't do any validations around that.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants