From 783faf03357a83a322bb9790cc079040b47a1bab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Strehovsk=C3=BD?= Date: Tue, 7 Mar 2023 12:30:07 +0900 Subject: [PATCH] Emit leaner cctor context for preinitialized types If a type is preinitialized, we shouldn't need the cctor pointer anymore. This was the only thing keeping around general-purpose comparers logic after @EgorBo's #83054. --- .../Compiler/DependencyAnalysis/NonGCStaticsNode.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/NonGCStaticsNode.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/NonGCStaticsNode.cs index 57659ca08e82ea..08ca5742e63cbc 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/NonGCStaticsNode.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/NonGCStaticsNode.cs @@ -167,19 +167,24 @@ protected override ObjectData GetDehydratableData(NodeFactory factory, bool relo builder.EmitZeros(classConstructorContextStorageSize - GetClassConstructorContextSize(_type.Context.Target)); // Emit the actual StaticClassConstructionContext - MethodDesc cctorMethod = _type.GetStaticConstructor(); - builder.EmitPointerReloc(factory.ExactCallableAddress(cctorMethod)); // If we're emitting the cctor context, but the type is actually preinitialized, emit the // cctor context as already executed. if (!HasLazyStaticConstructor) { + // Pointer to the cctor: we don't care - emit as zero + builder.EmitZeroPointer(); + // Constructor executed // TODO-NICE: introduce a named constant and also use it in the runner in CoreLib builder.EmitInt(1); } else { + // Emit pointer to the cctor + MethodDesc cctorMethod = _type.GetStaticConstructor(); + builder.EmitPointerReloc(factory.ExactCallableAddress(cctorMethod)); + // Constructor didn't execute builder.EmitInt(0); }