/
rejit.cs
130 lines (109 loc) · 4.09 KB
/
rejit.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System;
using System.Runtime.CompilerServices;
namespace Profiler.Tests
{
class RejitWithInlining //: ProfilerTest
{
static readonly Guid ReJitProfilerGuid = new Guid("66F7A9DF-8858-4A32-9CFF-3AD0787E0186");
[MethodImplAttribute(MethodImplOptions.NoInlining)]
private static int MaxInlining()
{
// Jit everything normally
TriggerDirectInlining();
CallMethodWithoutInlining();
TriggerInliningChain();
TriggerReJIT();
// TriggerInliningChain triggers a ReJIT, now this time we should call
// in to the ReJITted code
TriggerDirectInlining();
CallMethodWithoutInlining();
TriggerInliningChain();
TriggerRevert();
TriggerDirectInlining();
CallMethodWithoutInlining();
TriggerInliningChain();
return 100;
}
[MethodImplAttribute(MethodImplOptions.NoInlining)]
private static void TriggerReJIT()
{
Console.WriteLine("ReJIT should be triggered after this method...");
}
[MethodImplAttribute(MethodImplOptions.NoInlining)]
private static void TriggerRevert()
{
Console.WriteLine("Revert should be triggered after this method...");
}
[MethodImplAttribute(MethodImplOptions.NoInlining)]
private static void TriggerInliningChain()
{
Console.WriteLine("TriggerInlining");
// Test Inlining through another method
InlineeChain1();
}
[MethodImplAttribute(MethodImplOptions.NoInlining)]
private static void TriggerDirectInlining()
{
Console.WriteLine("TriggerDirectInlining");
InlineeTarget();
}
[MethodImplAttribute(MethodImplOptions.NoInlining)]
private static void CallMethodWithoutInlining()
{
Console.WriteLine("CallMethodWithoutInlining");
Action callMethod = InlineeTarget;
callMethod();
}
[MethodImplAttribute(MethodImplOptions.AggressiveInlining)]
private static void InlineeChain1()
{
Console.WriteLine("Inline.InlineeChain1");
InlineeTarget();
}
[MethodImplAttribute(MethodImplOptions.AggressiveInlining)]
public static void InlineeTarget()
{
Console.WriteLine("Inline.InlineeTarget");
}
public static int RunTest(string[] args)
{
Console.WriteLine("maxinlining");
return MaxInlining();
}
public static int Main(string[] args)
{
if (args.Length > 0 && args[0].Equals("RunTest", StringComparison.OrdinalIgnoreCase))
{
return RunTest(args);
}
return ProfilerTestRunner.Run(profileePath: System.Reflection.Assembly.GetExecutingAssembly().Location,
testName: "ReJITWithInlining",
profilerClsid: ReJitProfilerGuid,
profileeOptions: ProfileeOptions.OptimizationSensitive);
}
}
public class SeparateClassNeverLoaded
{
[MethodImplAttribute(MethodImplOptions.NoInlining)]
private static void TriggerInliningChain()
{
Console.WriteLine("TriggerInlining");
// Test Inlining through another method
InlineeChain1();
}
[MethodImplAttribute(MethodImplOptions.NoInlining)]
private static void TriggerDirectInlining()
{
Console.WriteLine("TriggerDirectInlining");
RejitWithInlining.InlineeTarget();
}
[MethodImplAttribute(MethodImplOptions.AggressiveInlining)]
private static void InlineeChain1()
{
Console.WriteLine("Inline.InlineeChain1");
RejitWithInlining.InlineeTarget();
}
}
}