Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public enum ReadyToRunMethodLayoutAlgorithm
HotWarmCold,
CallFrequency,
PettisHansen,
Random,
}

public enum ReadyToRunFileLayoutAlgorithm
Expand Down Expand Up @@ -166,6 +167,17 @@ int ComputeHotWarmColdRegion(MethodWithGCInfo method)
methods = PettisHansenSort(methods);
break;

case ReadyToRunMethodLayoutAlgorithm.Random:
Random rand = new Random(0);
for (int i = 0; i < methods.Count - 1; i++)
{
int j = rand.Next(i, methods.Count);
MethodWithGCInfo temp = methods[i];
methods[i] = methods[j];
methods[j] = temp;
}
break;

default:
throw new NotImplementedException(_methodLayoutAlgorithm.ToString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,30 @@ public IEnumerable<IMethodNode> GetCompiledMethods(EcmaModule moduleToEnumerate,
{
if (!_sortedMethods)
{
TypeSystemComparer comparer = new TypeSystemComparer();
Comparison<IMethodNode> sortHelper = (x, y) => comparer.Compare(x.Method, y.Method);
CompilerComparer comparer = new CompilerComparer();
SortableDependencyNode.ObjectNodeComparer objectNodeComparer = new SortableDependencyNode.ObjectNodeComparer(comparer);
Comparison<IMethodNode> sortHelper = (x, y) =>
{
int nodeComparerResult = objectNodeComparer.Compare((SortableDependencyNode)x, (SortableDependencyNode)y);
#if DEBUG
int methodOnlyResult = comparer.Compare(x.Method, y.Method);

// Assert the two sorting techniques produce the same result unless there is a CustomSort applied
Debug.Assert((nodeComparerResult == methodOnlyResult) ||
((x is SortableDependencyNode sortableX && sortableX.CustomSort != Int32.MaxValue) ||
(y is SortableDependencyNode sortableY && sortableY.CustomSort != Int32.MaxValue)));
#endif
return nodeComparerResult;
};
Comparison<IMethodNode> sortHelperNoCustomSort = (x, y) => comparer.Compare(x, y);

List<PerModuleMethodsGenerated> perModuleDatas = new List<PerModuleMethodsGenerated>(_methodsGenerated.Values);
perModuleDatas.Sort((x, y) => x.Module.CompareTo(y.Module));

foreach (var perModuleData in perModuleDatas)
{
perModuleData.MethodsGenerated.MergeSort(sortHelper);
perModuleData.GenericMethodsGenerated.MergeSort(sortHelper);
perModuleData.MethodsGenerated.MergeSort(sortHelperNoCustomSort);
perModuleData.GenericMethodsGenerated.MergeSort(sortHelperNoCustomSort);
_completeSortedMethods.AddRange(perModuleData.MethodsGenerated);
_completeSortedMethods.AddRange(perModuleData.GenericMethodsGenerated);
_completeSortedGenericMethods.AddRange(perModuleData.GenericMethodsGenerated);
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/tools/aot/crossgen2/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ private void ProcessCommandLine(string[] args)
"hotwarmcold" => ReadyToRunMethodLayoutAlgorithm.HotWarmCold,
"callfrequency" => ReadyToRunMethodLayoutAlgorithm.CallFrequency,
"pettishansen" => ReadyToRunMethodLayoutAlgorithm.PettisHansen,
"random" => ReadyToRunMethodLayoutAlgorithm.Random,
_ => throw new CommandLineException(SR.InvalidMethodLayout)
};
}
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/tools/aot/crossgen2/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
<value>Method layout must be either DefaultSort or MethodOrder.</value>
</data>
<data name="InvalidMethodLayout" xml:space="preserve">
<value>Method layout must be either DefaultSort, ExclusiveWeight, HotCold, HotWarmCold, CallFrequency or PettisHansen.</value>
<value>Method layout must be either DefaultSort, ExclusiveWeight, HotCold, HotWarmCold, CallFrequency, PettisHansen, or Random.</value>
</data>
<data name="CompileNoMethodsOption" xml:space="preserve">
<value>True to skip compiling methods into the R2R image (default = false)</value>
Expand Down
1 change: 1 addition & 0 deletions src/tests/Common/CLRTest.CrossGen.targets
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ if defined RunCrossGen2 (
echo -o:!__OutputFile!>>!__ResponseFile!
echo --targetarch:$(TargetArchitecture)>>!__ResponseFile!
echo --verify-type-and-field-layout>>!__ResponseFile!
echo --method-layout:random>>!__ResponseFile!
echo -r:!CORE_ROOT!\System.*.dll>>!__ResponseFile!
echo -r:!CORE_ROOT!\Microsoft.*.dll>>!__ResponseFile!
echo -r:!CORE_ROOT!\mscorlib.dll>>!__ResponseFile!
Expand Down