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

Add an option to not generate precise GC info #75817

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions eng/testing/tests.singlefile.targets
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<Project>
<PropertyGroup>
<IlcUseConservativeGc>true</IlcUseConservativeGc>

<OutputType>Exe</OutputType>

<DefineConstants>$(DefineConstants);SINGLE_FILE_TEST_RUNNER</DefineConstants>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,9 @@ The .NET Foundation licenses this file to you under the MIT license.
<IlcArg Condition="'$(TrimmerDefaultAction)' == 'copyused' or '$(TrimmerDefaultAction)' == 'copy' or '$(TrimMode)' == 'partial'" Include="--defaultrooting" />
<IlcArg Include="--resilient" />

<IlcArg Condition="'$(IlcUseConservativeGc)' == 'true'" Include="--runtimeopt:gcConservative=1" />
<IlcArg Condition="'$(IlcUseConservativeGc)' == 'true'" Include="--noprecisegc" />

<IlcArg Condition="$(IlcDisableReflection) == 'true'" Include="--feature:System.Reflection.IsReflectionExecutionAvailable=false" />

<!-- Configure LINQ expressions - disable Emit everywhere -->
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/nativeaot/docs/optimizing.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Since `PublishTrimmed` is implied to be true with Native AOT, some framework fea
## Options related to metadata generation

* `<IlcGenerateStackTraceData>false</IlcGenerateStackTraceData>`: this disables generation of stack trace metadata that provides textual names in stack traces. This is for example the text string one gets by calling `Exception.ToString()` on a caught exception. With this option disabled, stack traces will still be generated, but will be based on reflection metadata alone (they might be less complete).
* `<IlcUseConservativeGc>`: if set to `true`, conservative GC stack scanning will be used and metadata related to GC stack reporting will not be generated. The generated executable file will be smaller, but the GC will be less efficient (garbage collection might take longer and keep objects alive for longer periods of time than usual).

## Options related to code generation
* `<IlcOptimizationPreference>Speed</IlcOptimizationPreference>`: when generating optimized code, favor code execution speed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public partial class CompilationBuilder
protected InstructionSetSupport _instructionSetSupport;
protected SecurityMitigationOptions _mitigationOptions;
protected bool _useDwarf5;
protected bool _isPreciseGc = true;

partial void InitializePartial()
{
Expand Down Expand Up @@ -108,6 +109,12 @@ public CompilationBuilder UseDwarf5(bool value)
return this;
}

public CompilationBuilder UseGCStackReporting(bool isPrecise)
{
_isPreciseGc = isPrecise;
return this;
}

protected PreinitializationManager GetPreinitializationManager()
{
if (_preinitializationManager == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ public void PublishUnwindInfo(ObjectNode node)
ehInfo = null;
}

if (gcInfo != null)
if (gcInfo != null && ((_options & ObjectWritingOptions.NoGcInfo) == 0))
{
EmitBlob(gcInfo);
gcInfo = null;
Expand Down Expand Up @@ -645,7 +645,7 @@ public void BuildCFIMap(NodeFactory factory, ObjectNode node)
ehInfo = null;
}

if (gcInfo != null)
if (gcInfo != null && ((_options & ObjectWritingOptions.NoGcInfo) == 0))
{
EmitBlob(gcInfo);
gcInfo = null;
Expand Down Expand Up @@ -1327,5 +1327,6 @@ public enum ObjectWritingOptions
GenerateDebugInfo = 0x01,
ControlFlowGuard = 0x02,
UseDwarf5 = 0x4,
NoGcInfo = 0x8,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ protected override void CompileInternal(string outputFile, ObjectDumper dumper)
if ((_compilationOptions & RyuJitCompilationOptions.ControlFlowGuardAnnotations) != 0)
options |= ObjectWritingOptions.ControlFlowGuard;

if ((_compilationOptions & RyuJitCompilationOptions.NoPreciseGc) != 0)
options |= ObjectWritingOptions.NoGcInfo;

ObjectWriter.EmitObject(outputFile, nodes, NodeFactory, options, dumper, _logger);
}

Expand Down Expand Up @@ -244,5 +247,6 @@ public enum RyuJitCompilationOptions
ControlFlowGuardAnnotations = 0x2,
UseDwarf5 = 0x4,
UseResilience = 0x8,
NoPreciseGc = 0x10,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ public override ICompilation ToCompilation()
if (_resilient)
options |= RyuJitCompilationOptions.UseResilience;

if (!_isPreciseGc)
options |= RyuJitCompilationOptions.NoPreciseGc;

var factory = new RyuJitNodeFactory(_context, _compilationGroup, _metadataManager, _interopStubManager, _nameMangler, _vtableSliceProvider, _dictionaryLayoutProvider, GetPreinitializationManager());

JitConfigProvider.Initialize(_context.Target, jitFlagBuilder.ToArray(), _ryujitOptions, _jitPath);
Expand Down
5 changes: 4 additions & 1 deletion src/coreclr/tools/aot/ILCompiler/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ internal sealed class Program
private bool _completeTypesMetadata;
private bool _scanReflection;
private bool _methodBodyFolding;
private bool _noPreciseGc;
private int _parallelism = Environment.ProcessorCount;
private string _instructionSet;
private string _guard;
Expand Down Expand Up @@ -221,6 +222,7 @@ private ArgumentSyntax ParseCommandLine(string[] args)
syntax.DefineOption("ildump", ref _ilDump, "Dump IL assembly listing for compiler-generated IL");
syntax.DefineOption("stacktracedata", ref _emitStackTraceData, "Emit data to support generating stack trace strings at runtime");
syntax.DefineOption("methodbodyfolding", ref _methodBodyFolding, "Fold identical method bodies");
syntax.DefineOption("noprecisegc", ref _noPreciseGc, "Do not generate precise stack GC information");
syntax.DefineOptionList("initassembly", ref _initAssemblies, "Assembly(ies) with a library initializer");
syntax.DefineOptionList("appcontextswitch", ref _appContextSwitches, "System.AppContext switches to set (format: 'Key=Value')");
syntax.DefineOptionList("feature", ref _featureSwitches, "Feature switches to apply (format: 'Namespace.Name=[true|false]'");
Expand Down Expand Up @@ -943,7 +945,8 @@ void RunScanner()
.UseOptimizationMode(_optimizationMode)
.UseSecurityMitigationOptions(securityMitigationOptions)
.UseDebugInfoProvider(debugInfoProvider)
.UseDwarf5(_useDwarf5);
.UseDwarf5(_useDwarf5)
.UseGCStackReporting(isPrecise: !_noPreciseGc);

builder.UseResilience(_resilient);

Expand Down
7 changes: 7 additions & 0 deletions src/tests/nativeaot/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\Directory.Build.props" />

<PropertyGroup>
<IlcUseConservativeGc>true</IlcUseConservativeGc>
</PropertyGroup>
</Project>