Skip to content
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

Make the CastCache table rooted by a managed static field. #676

Closed
wants to merge 3 commits into from

Conversation

VSadov
Copy link
Member

@VSadov VSadov commented Dec 8, 2019

This makes managing the cast table a bit simpler (no handles).

Also a prerequisite to accessing the cast cache directly from managed code (re: https://github.com/dotnet/coreclr/issues/27931)

@jkotas
Copy link
Member

jkotas commented Dec 8, 2019

a bit simpler (no handles)

I agree that this is prep work for fully managed casting cache impl, but it is not simpler than the implementation with handles. It is more lines of code and it has several hundred bytes larger footprint due to an extra type loaded.

@VSadov
Copy link
Member Author

VSadov commented Dec 8, 2019

Conceptually working with a pointer is simpler than working with a GC handle. But having to load an extra managed class probably balances that out.

I guess opening this to managed code is more important goal here. For that sharing a static field is more convenient than sharing a handle.

@jkotas
Copy link
Member

jkotas commented Dec 9, 2019

It may be best to fold this into a change that actually moves the casting logic to managed code so that it is an net improvement. It is a tiny change, so there is no significant upside in factoring it into a separate PR.

@@ -136,7 +139,7 @@ TypeHandle::CastResult CastCache::TryGet(TADDR source, TADDR target)
}
CONTRACTL_END;

BASEARRAYREF table = (BASEARRAYREF)ObjectFromHandle(s_cache);
BASEARRAYREF table = *s_pTableRef;

// we use NULL as a sentinel for a rare case when a table could not be allocated
// because we avoid OOMs in conversions
Copy link
Member

Choose a reason for hiding this comment

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

Nit:

Suggested change
// because we avoid OOMs in conversions
// because we avoid OOMs

Casting is not conversion. IIRC, we had discussion about this on the original PR and most places were fixed, but it looks like this one was missed.

@VSadov
Copy link
Member Author

VSadov commented Dec 9, 2019

I needed feedback on whether this is something we would be ok with doing.
And to see if it passes tests. R2R and stuff like that - to be sure the type loading part is not causing trouble.

The change is self-contained, so it could be an independent step from the rest, but it is indeed a fairly small change.

@VSadov VSadov closed this Dec 9, 2019
@ghost ghost locked as resolved and limited conversation to collaborators Dec 11, 2020
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.

2 participants