Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Lazily generate native type layout information #27620

Closed

Conversation

jkoritzinsky
Copy link
Member

Currently, the native layout information for every non-auto-layout type is generated at type-load time, even if managed code never uses the native type. This design has lead to a few limitations in our field marshaling validation, as well as forced field marshalling initialization code to run during method-table building, causing some odd initialization ordering designs because of what data is available at what time.

This PR changes native layout information to only ever be initialized when user code or runtime code requests the native layout of a type and the type is non-blittable. To enable this, the function IsFieldBlittable does a fast, metadata-based blittability check that doesn't need to run all of the marshaler classification logic. When the runtime requests native layout information from a MethodTable that is blittable, it falls back to the managed information. In other cases, it generates the native information and stores it in its LayoutEEClass for later use.

…ations out of the type loader. (Blittability is needed in the type loader, so we need to calculate it early).
…metadata (since if it is blittable, we'll never load the native type and do validation there).
…hal data initalization was in the type loader.
Get runtime and dac building with it. Crossgen needs some more updates to get fragile NGen working with the new design.
…native layout logic. The new logic doesn't support being run as part of type-load.
src/vm/mlinfo.cpp Outdated Show resolved Hide resolved
src/vm/methodtable.cpp Outdated Show resolved Hide resolved
src/vm/class.cpp Outdated Show resolved Hide resolved
src/vm/fieldmarshaler.h Outdated Show resolved Hide resolved
src/vm/class.cpp Outdated Show resolved Hide resolved
src/vm/class.cpp Outdated Show resolved Hide resolved
src/vm/classlayoutinfo.cpp Outdated Show resolved Hide resolved
src/vm/class.cpp Outdated Show resolved Hide resolved
@maryamariyan
Copy link
Member

Thank you for your contribution. As announced in dotnet/coreclr#27549 this repository will be moving to dotnet/runtime on November 13. If you would like to continue working on this PR after this date, the easiest way to move the change to dotnet/runtime is:

  1. In your coreclr repository clone, create patch by running git format-patch origin
  2. In your runtime repository clone, apply the patch by running git apply --directory src/coreclr <path to the patch created in step 1>

@jkoritzinsky jkoritzinsky added the post-consolidation PRs which will be hand ported to dotnet/runtime label Nov 6, 2019
@maryamariyan
Copy link
Member

Thank you for your contribution. As announced in #27549 the dotnet/runtime repository will be used going forward for changes to this code base. Closing this PR as no more changes will be accepted into master for this repository. If you’d like to continue working on this change please move it to dotnet/runtime.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-Interop post-consolidation PRs which will be hand ported to dotnet/runtime
Projects
None yet
3 participants