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

JIT: Support custom ClassLayout instances with GC pointers in them #112064

Merged
merged 15 commits into from
Feb 5, 2025

Conversation

jakobbotsch
Copy link
Member

@jakobbotsch jakobbotsch commented Feb 1, 2025

  • Add a ClassLayoutBuilder that can be used to build new ClassLayout instances with arbitrary GC pointers
  • Add support for GC types to LCL_FLD stress to test some of this new support

Subsumes #111942
Fixes #103362

As future work I also want to add a StructSegments into ClassLayout so that all layouts carry information about padding/non-padding. Once that is done we should be able to switch object stack allocation to use custom layouts without any regressions. That should allow us to remove getHeapClassSize and getTypeForBoxOnStack JIT-EE functions (in addition to follow up work to support promoted arrays of types that may have GC pointers).

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Feb 1, 2025
@jakobbotsch
Copy link
Member Author

/azp run runtime-coreclr jitstress, runtime-coreclr libraries-jitstress

Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@jakobbotsch
Copy link
Member Author

/azp run runtime-coreclr jitstress, runtime-coreclr libraries-jitstress

Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@jakobbotsch
Copy link
Member Author

A number of "Inconsistent profile errors" assertions in the jitstress runs, and also an AV crash on x86. Need to look at those first.

@jakobbotsch jakobbotsch marked this pull request as draft February 3, 2025 20:13
@jakobbotsch
Copy link
Member Author

cc @dotnet/jit-contrib PTAL @AndyAyersMS

The libraries-jitstress failures are being fixed by #112147. Will rerun the CI once that is merged.
I was not able to repro the x86 libraries-jitstress failure, but I suspect it's not related.

Copy link
Member

@AndyAyersMS AndyAyersMS left a comment

Choose a reason for hiding this comment

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

This looks good

unsigned hash = key.Size;
if (key.GCPtrTypes != nullptr)
{
hash ^= 0xc4cfbb2a + (hash << 19) + (hash >> 13);
Copy link
Member

Choose a reason for hiding this comment

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

Is there any science to these hex values?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, I just picked two random values here

Copy link
Member Author

Choose a reason for hiding this comment

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

To be clear, the constant used below (0x9e3779b9) is a common one I've seen in hash functions. But here I wanted the hash to always include some information about GCPtrTypes != nullptr or GCPtrTypes == nullptr, so this is folded <random constant> + 0x9e3779b9 for those two cases.

{
assert(slot < GetSlotCount());
BYTE* ptrs = GetOrCreateGCPtrs();
if (ptrs[slot] != TYPE_GC_NONE)
Copy link
Member

Choose a reason for hiding this comment

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

Should it be an error to "un gc" a slot?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't have a strong opinion.. I figured it wasn't that hard to support any potential use pattern here. But would be ok with asserting here also.

Copy link
Member Author

Choose a reason for hiding this comment

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

Going to merge as is, but let me know if you prefer the opposite and I can switch it in a follow-up.

@jakobbotsch
Copy link
Member Author

/azp run runtime-coreclr jitstress, runtime-coreclr libraries-jitstress

Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@jakobbotsch
Copy link
Member Author

Another win-x86 failure... Will have to dig deeper.

@jakobbotsch
Copy link
Member Author

Trying to collect some more failures... cannot repro the failure locally after trying for a while in a loop.

@jakobbotsch
Copy link
Member Author

/azp run runtime-coreclr libraries-jitstress

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@jakobbotsch
Copy link
Member Author

I think I tracked down what the problem is: LCL_FLD stress would sometimes turn pinned GC pointers into structs and thus break the pinning. Pushed a fix.

@jakobbotsch
Copy link
Member Author

/azp run runtime-coreclr libraries-jitstress

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@jakobbotsch
Copy link
Member Author

Failing job has a console log that actually looks like it succeeded.

@jakobbotsch jakobbotsch merged commit fae05be into dotnet:main Feb 5, 2025
117 of 119 checks passed
@jakobbotsch jakobbotsch deleted the class-layout-builder branch February 5, 2025 21:28
This was referenced Feb 5, 2025
grendello added a commit to grendello/runtime that referenced this pull request Feb 6, 2025
* main: (23 commits)
  add important remarks to NrbfDecoder (dotnet#111286)
  docs: fix spelling grammar and missing words in clr-code-guide.md (dotnet#112222)
  Consider type declaration order in MethodImpls (dotnet#111998)
  Add a feature flag to not use GVM in Linq Select (dotnet#109978)
  [cDAC] Implement ISOSDacInterface::GetMethodDescPtrFromIp (dotnet#110755)
  Restructure JSImport/JSExport generators to share more code and utilize more Microsoft.Interop.SourceGeneration shared code (dotnet#107769)
  Add more detailed explanations to control-flow RegexOpcode values (dotnet#112170)
  Add repo-specific condition to labeling workflows (dotnet#112169)
  Fix bad assembly when a nested exported type is marked via link.xml (dotnet#107945)
  Make `CalculateAssemblyAction` virtual. (dotnet#112154)
  JIT: Enable reusing profile-aware DFS trees between phases (dotnet#112198)
  Add support for LDAPTLS_CACERTDIR \ TrustedCertificateDirectory (dotnet#111877)
  JIT: Support custom `ClassLayout` instances with GC pointers in them (dotnet#112064)
  Factor positive lookaheads better into find optimizations (dotnet#112107)
  Add ImmutableCollectionsMarshal.AsMemory (dotnet#112177)
  [mono] ILStrip write directly to the output filestream (dotnet#112142)
  Allow the NativeAOT runtime pack to be specified as the ILC runtime package (dotnet#111876)
  JIT: some reworking for conditional escape analysis (dotnet#112194)
  Replace HELPER_METHOD_FRAME with DynamicHelperFrame in patchpoints (dotnet#112025)
  [Android] Decouple runtime initialization and entry point execution for Android sample (dotnet#111742)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

JIT should support custom ClassLayout instances with GC refs
2 participants