Skip to content
This repository has been archived by the owner on Nov 1, 2020. It is now read-only.

Add support for eager static constructors #889

Merged
merged 1 commit into from
Feb 19, 2016

Conversation

MichalStrehovsky
Copy link
Member

This looks like a lot of code just to support a rarely used feature,
but a lot of this is plumbing that will let me delete some existing code
in a subsequent commit. Some of this will also be needed to support
the various preinitialized data attributes/general type preinitialization.

  • Redirecting uses of HasStaticConstructor to go through the TypeInitialization class (exposing higher level APIs "HasLazyCctor" and "HasEagerCctor")
  • Emitting a new table with an array of eager class constructors
  • Augmenting GC/nonGC/ThreadStatic and Method nodes to depend on an entry in the eager cctor table if the owning type has a cctor
  • Startup code addition to iterate over the list of eager cctors and call them one by one

Reusable code:

  • ArrayOfEmbeddedPointers: we have a buch of places where we just want an array of pointers. This will let us e.g. delete StringIndirectionNode.

Missing features: ordering the eager cctors. I want to think a bit about
how we parse custom attribute blobs before I implement that.

Fixes #471.

@@ -18,6 +20,7 @@ internal static class StartupCodeHelpers
internal static void Initialize()
{
InitializeStringTable();
RunEagerClassConstructors();
RuntimeImports.RhEnableShutdownFinalization(0xffffffffu);
Copy link
Member Author

Choose a reason for hiding this comment

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

We will be able to get rid of the RhEnableShutdownFinalization line and switch to the Project N plan (this will be triggered from the eager cctor of the Environment class).

Copy link
Member

Choose a reason for hiding this comment

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

We got rid of the shutdown finalization for .NET Core (https://github.com/dotnet/corefx/issues/5205 has the long story), so it would be more appropriate to delete the RhEnableShutdownFinalization here and keep the CORERT ifdef in Environment.cs as a reminder to clean it up for UWP as well.

The shutdown finalization as implemented in Redhawk runtime does not really work because of it does not suspend foreground threads like in full .NET. We never noticed because of UWP apps do not ever shutdown, and small unit tests do not highlight the problems.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure! I'll send another pull request to delete it. I don't want to convolute this one with unrelated things.

This looks like a lot of code just to support a rarely used feature,
but a lot of this is plumbing that will let me delete some existing code
in a subsequent commit. Some of this will also be needed to support
the various preinitialized data attributes/general type preinitialization.

* Redirecting uses of HasStaticConstructor to go through the TypeInitialization class (exposing higher level APIs "HasLazyCctor" and "HasEagerCctor")
* Emitting a new table with an array of eager class constructors
* Augmenting GC/nonGC/ThreadStatic and Method nodes to depend on an entry in the eager cctor table if the owning type has a cctor
* Startup code addition to iterate over the list of eager cctors and call them one by one

Reusable code:
* ArrayOfEmbeddedPointers: we have a buch of places where we just want an array of pointers. This will let us e.g. delete StringIndirectionNode.

Missing features: ordering the eager cctors. I want to think a bit about
how we parse custom attribute blobs before I implement that.

Fixes dotnet#471.
@jkotas
Copy link
Member

jkotas commented Feb 19, 2016

Missing features: ordering the eager cctors.

It also needs some thinking about how it should actually work without global view/analysis...

@jkotas
Copy link
Member

jkotas commented Feb 19, 2016

LGTM

MichalStrehovsky added a commit that referenced this pull request Feb 19, 2016
Add support for eager static constructors
@MichalStrehovsky MichalStrehovsky merged commit 4d5c647 into dotnet:master Feb 19, 2016
@MichalStrehovsky MichalStrehovsky deleted the eagercctors branch February 19, 2016 17:55
MichalStrehovsky added a commit to MichalStrehovsky/corert that referenced this pull request Feb 19, 2016
Shutdown finalization was abandoned for .NET core.

See discussion in pull request dotnet#889 and dotnet/corefx#5205.
MichalStrehovsky added a commit to MichalStrehovsky/corert that referenced this pull request Feb 19, 2016
Shutdown finalization was abandoned for .NET core.

See discussion in pull request dotnet#889 and dotnet/corefx#5205.
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