Skip to content

Commit 0139b30

Browse files
committed
CompilationOption for GarbageCollectionManager
Added a quick way to select between multiple implementations of GC available in the system. To use, the platform (currently only LPC1768) needs to have multiple concrete implementations of GarbageCollectionManager (see BoardConfigurations\LPC1768\Board\SystemServices\GarbageCollectionManager.cs as an example). Once done, in the .FrontEndConfig, you can specify the GC strategy by using: -CompilationOption System.String GarbageCollectionManager ConservativeMarkAndSweepCollector (Replace the last bit with the name of the concrete implementation as needed)
1 parent 4da60e2 commit 0139b30

File tree

47 files changed

+139
-154
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+139
-154
lines changed

Diff for: Samples/I2cTemperatureSensor/I2cTemperatureSensor/Native/mbed_simple_K64F.FrontEndConfig

-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
###
1919
### Add compilation phases, in order
2020
###
21-
-CompilationPhaseDisabled InitializeReferenceCountingGarbageCollection
22-
-CompilationPhaseDisabled EnableStrictReferenceCountingGarbageCollection
2321
#-CompilationPhaseDisabled ReduceNumberOfTemporaries
2422
#-CompilationPhaseDisabled TransformFinallyBlocksIntoTryBlocks
2523
#-CompilationPhaseDisabled ApplyClassExtensions

Diff for: Samples/I2cTemperatureSensor/I2cTemperatureSensor/Native/mbed_simple_LPC1768.FrontEndConfig

-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
###
1919
### Add compilation phases, in order
2020
###
21-
-CompilationPhaseDisabled InitializeReferenceCountingGarbageCollection
22-
-CompilationPhaseDisabled EnableStrictReferenceCountingGarbageCollection
2321
#-CompilationPhaseDisabled ReduceNumberOfTemporaries
2422
#-CompilationPhaseDisabled TransformFinallyBlocksIntoTryBlocks
2523
#-CompilationPhaseDisabled ApplyClassExtensions

Diff for: Samples/I2cTemperatureSensor/I2cTemperatureSensor/Native/mbed_simple_STM32L152.FrontEndConfig

-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
###
2020
### Add compilation phases, in order
2121
###
22-
-CompilationPhaseDisabled InitializeReferenceCountingGarbageCollection
23-
-CompilationPhaseDisabled EnableStrictReferenceCountingGarbageCollection
2422
#-CompilationPhaseDisabled ReduceNumberOfTemporaries
2523
#-CompilationPhaseDisabled TransformFinallyBlocksIntoTryBlocks
2624
#-CompilationPhaseDisabled ApplyClassExtensions

Diff for: Samples/SpiDisplay/SpiDisplay/Native/mbed_simple_K64F.FrontEndConfig

-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
###
1919
### Add compilation phases, in order
2020
###
21-
-CompilationPhaseDisabled InitializeReferenceCountingGarbageCollection
22-
-CompilationPhaseDisabled EnableStrictReferenceCountingGarbageCollection
2321
#-CompilationPhaseDisabled ReduceNumberOfTemporaries
2422
#-CompilationPhaseDisabled TransformFinallyBlocksIntoTryBlocks
2523
#-CompilationPhaseDisabled ApplyClassExtensions

Diff for: Samples/SpiDisplay/SpiDisplay/Native/mbed_simple_LPC1768.FrontEndConfig

-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
###
1919
### Add compilation phases, in order
2020
###
21-
-CompilationPhaseDisabled InitializeReferenceCountingGarbageCollection
22-
-CompilationPhaseDisabled EnableStrictReferenceCountingGarbageCollection
2321
#-CompilationPhaseDisabled ReduceNumberOfTemporaries
2422
#-CompilationPhaseDisabled TransformFinallyBlocksIntoTryBlocks
2523
#-CompilationPhaseDisabled ApplyClassExtensions

Diff for: Samples/SpiDisplay/SpiDisplay/Native/mbed_simple_STM32L152.FrontEndConfig

-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
###
2020
### Add compilation phases, in order
2121
###
22-
-CompilationPhaseDisabled InitializeReferenceCountingGarbageCollection
23-
-CompilationPhaseDisabled EnableStrictReferenceCountingGarbageCollection
2422
#-CompilationPhaseDisabled ReduceNumberOfTemporaries
2523
#-CompilationPhaseDisabled TransformFinallyBlocksIntoTryBlocks
2624
#-CompilationPhaseDisabled ApplyClassExtensions

Diff for: VisualStudio/LlilumProjectType/LlilumApplication/LlilumApplication.ProjectTemplate/LlilumNative/mbed_simple_K64F.FrontEndConfig

-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
###
1919
### Add compilation phases, in order
2020
###
21-
-CompilationPhaseDisabled InitializeReferenceCountingGarbageCollection
22-
-CompilationPhaseDisabled EnableStrictReferenceCountingGarbageCollection
2321
#-CompilationPhaseDisabled ReduceNumberOfTemporaries
2422
#-CompilationPhaseDisabled TransformFinallyBlocksIntoTryBlocks
2523
#-CompilationPhaseDisabled ApplyClassExtensions

Diff for: VisualStudio/LlilumProjectType/LlilumApplication/LlilumApplication.ProjectTemplate/LlilumNative/mbed_simple_LPC1768.FrontEndConfig

-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
###
1919
### Add compilation phases, in order
2020
###
21-
-CompilationPhaseDisabled InitializeReferenceCountingGarbageCollection
22-
-CompilationPhaseDisabled EnableStrictReferenceCountingGarbageCollection
2321
#-CompilationPhaseDisabled ReduceNumberOfTemporaries
2422
#-CompilationPhaseDisabled TransformFinallyBlocksIntoTryBlocks
2523
#-CompilationPhaseDisabled ApplyClassExtensions

Diff for: VisualStudio/LlilumProjectType/LlilumApplication/LlilumApplication.ProjectTemplate/LlilumNative/mbed_simple_STM32F091.FrontEndConfig

-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
###
1919
### Add compilation phases, in order
2020
###
21-
-CompilationPhaseDisabled InitializeReferenceCountingGarbageCollection
22-
-CompilationPhaseDisabled EnableStrictReferenceCountingGarbageCollection
2321
#-CompilationPhaseDisabled ReduceNumberOfTemporaries
2422
#-CompilationPhaseDisabled TransformFinallyBlocksIntoTryBlocks
2523
#-CompilationPhaseDisabled ApplyClassExtensions

Diff for: VisualStudio/LlilumProjectType/LlilumApplication/LlilumApplication.ProjectTemplate/LlilumNative/mbed_simple_STM32F401.FrontEndConfig

-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
###
1919
### Add compilation phases, in order
2020
###
21-
-CompilationPhaseDisabled InitializeReferenceCountingGarbageCollection
22-
-CompilationPhaseDisabled EnableStrictReferenceCountingGarbageCollection
2321
#-CompilationPhaseDisabled ReduceNumberOfTemporaries
2422
#-CompilationPhaseDisabled TransformFinallyBlocksIntoTryBlocks
2523
#-CompilationPhaseDisabled ApplyClassExtensions

Diff for: VisualStudio/LlilumProjectType/LlilumApplication/LlilumApplication.ProjectTemplate/LlilumNative/mbed_simple_STM32F411.FrontEndConfig

-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
###
1919
### Add compilation phases, in order
2020
###
21-
-CompilationPhaseDisabled InitializeReferenceCountingGarbageCollection
22-
-CompilationPhaseDisabled EnableStrictReferenceCountingGarbageCollection
2321
#-CompilationPhaseDisabled ReduceNumberOfTemporaries
2422
#-CompilationPhaseDisabled TransformFinallyBlocksIntoTryBlocks
2523
#-CompilationPhaseDisabled ApplyClassExtensions

Diff for: VisualStudio/LlilumProjectType/LlilumApplication/LlilumApplication.ProjectTemplate/LlilumNative/mbed_simple_STM32L152.FrontEndConfig

-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
###
1919
### Add compilation phases, in order
2020
###
21-
-CompilationPhaseDisabled InitializeReferenceCountingGarbageCollection
22-
-CompilationPhaseDisabled EnableStrictReferenceCountingGarbageCollection
2321
#-CompilationPhaseDisabled ReduceNumberOfTemporaries
2422
#-CompilationPhaseDisabled TransformFinallyBlocksIntoTryBlocks
2523
#-CompilationPhaseDisabled ApplyClassExtensions

Diff for: Zelig/BoardConfigurations/K64F/Configuration/K64F.FrontEndConfig

-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
###
2525
### Add compilation phases, in order
2626
###
27-
-CompilationPhaseDisabled InitializeReferenceCountingGarbageCollection
28-
-CompilationPhaseDisabled EnableStrictReferenceCountingGarbageCollection
2927
#-CompilationPhaseDisabled ReduceNumberOfTemporaries
3028
#-CompilationPhaseDisabled TransformFinallyBlocksIntoTryBlocks
3129
#-CompilationPhaseDisabled ApplyClassExtensions

Diff for: Zelig/BoardConfigurations/LPC1768/Board/SystemServices/GarbageCollectionManager.cs

+9-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,15 @@ namespace Microsoft.Llilum.LPC1768
77
using Chipset = Microsoft.CortexM3OnMBED;
88

99

10-
public sealed class GarbageCollectionManager : Chipset.GarbageCollectionManager
10+
public sealed class ReferenceCountingCollector : Microsoft.Zelig.Runtime.ReferenceCountingCollector
11+
{
12+
}
13+
14+
public sealed class StrictReferenceCountingCollector : Microsoft.Zelig.Runtime.StrictReferenceCountingCollector
15+
{
16+
}
17+
18+
public sealed class ConservativeMarkAndSweepCollector : Microsoft.Zelig.Runtime.ConservativeMarkAndSweepCollector
1119
{
1220
}
1321
}

Diff for: Zelig/BoardConfigurations/LPC1768/Configuration/LPC1768.FrontEndConfig

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
###
2424
### Add compilation phases, in order
2525
###
26-
-CompilationPhaseDisabled InitializeReferenceCountingGarbageCollection
27-
-CompilationPhaseDisabled EnableStrictReferenceCountingGarbageCollection
2826
#-CompilationPhaseDisabled ReduceNumberOfTemporaries
2927
#-CompilationPhaseDisabled TransformFinallyBlocksIntoTryBlocks
3028
#-CompilationPhaseDisabled ApplyClassExtensions
@@ -58,6 +56,8 @@
5856
#-CompilationPhaseDisabled GenerateImage
5957
#-CompilationPhaseDisabled Done
6058

59+
-CompilationOption System.String GarbageCollectionManager ConservativeMarkAndSweepCollector
60+
6161
###
6262
### The program to compile.
6363
###

Diff for: Zelig/BoardConfigurations/STM32F091/Configuration/STM32F091.FrontEndConfig

-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
###
2525
### Add compilation phases, in order
2626
###
27-
-CompilationPhaseDisabled InitializeReferenceCountingGarbageCollection
28-
-CompilationPhaseDisabled EnableStrictReferenceCountingGarbageCollection
2927
#-CompilationPhaseDisabled ReduceNumberOfTemporaries
3028
#-CompilationPhaseDisabled TransformFinallyBlocksIntoTryBlocks
3129
#-CompilationPhaseDisabled ApplyClassExtensions

Diff for: Zelig/BoardConfigurations/STM32F401/Configuration/STM32F401.FrontEndConfig

-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
###
2525
### Add compilation phases, in order
2626
###
27-
-CompilationPhaseDisabled InitializeReferenceCountingGarbageCollection
28-
-CompilationPhaseDisabled EnableStrictReferenceCountingGarbageCollection
2927
#-CompilationPhaseDisabled ReduceNumberOfTemporaries
3028
#-CompilationPhaseDisabled TransformFinallyBlocksIntoTryBlocks
3129
#-CompilationPhaseDisabled ApplyClassExtensions

Diff for: Zelig/BoardConfigurations/STM32F411/Configuration/STM32F411.FrontEndConfig

-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
###
2525
### Add compilation phases, in order
2626
###
27-
-CompilationPhaseDisabled InitializeReferenceCountingGarbageCollection
28-
-CompilationPhaseDisabled EnableStrictReferenceCountingGarbageCollection
2927
#-CompilationPhaseDisabled ReduceNumberOfTemporaries
3028
#-CompilationPhaseDisabled TransformFinallyBlocksIntoTryBlocks
3129
#-CompilationPhaseDisabled ApplyClassExtensions

Diff for: Zelig/BoardConfigurations/STM32L152/Configuration/STM32L152.FrontEndConfig

-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
###
2424
### Add compilation phases, in order
2525
###
26-
-CompilationPhaseDisabled InitializeReferenceCountingGarbageCollection
27-
-CompilationPhaseDisabled EnableStrictReferenceCountingGarbageCollection
2826
#-CompilationPhaseDisabled ReduceNumberOfTemporaries
2927
#-CompilationPhaseDisabled TransformFinallyBlocksIntoTryBlocks
3028
#-CompilationPhaseDisabled ApplyClassExtensions

Diff for: Zelig/BoardConfigurations/Win32/Configuration/Win32.FrontEndConfig

-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
###
2323
### Add compilation phases, in order
2424
###
25-
-CompilationPhaseDisabled InitializeReferenceCountingGarbageCollection
26-
-CompilationPhaseDisabled EnableStrictReferenceCountingGarbageCollection
2725
#-CompilationPhaseDisabled ReduceNumberOfTemporaries
2826
#-CompilationPhaseDisabled TransformFinallyBlocksIntoTryBlocks
2927
#-CompilationPhaseDisabled ApplyClassExtensions

Diff for: Zelig/Zelig/CompileTime/CodeGenerator/CodeTransformation/CodeTransformation.csproj

+1-4
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,7 @@
121121
<Compile Include="CompilationSteps\Phases\ComputeCallsClosure.cs" />
122122
<Compile Include="CompilationSteps\Phases\ConvertToSSA.cs" />
123123
<Compile Include="CompilationSteps\Phases\ConvertUnsupportedOperatorsToMethodCalls.cs" />
124-
<Compile Include="CompilationSteps\Phases\EnableStrictReferenceCountingGarbageCollection.cs" />
125124
<Compile Include="CompilationSteps\Phases\FuseOperators.cs" />
126-
<Compile Include="CompilationSteps\Phases\InitializeReferenceCountingGarbageCollection.cs" />
127125
<Compile Include="CompilationSteps\Phases\PrepareExternalMethods.cs" />
128126
<Compile Include="CompilationSteps\Phases\ReferenceCountingGarbageCollection.cs" />
129127
<Compile Include="CompilationSteps\Phases\ResourceManagerOptimizations.cs" />
@@ -166,13 +164,12 @@
166164
<Compile Include="ImageBuilders\CompilationState_Scheduling.cs" />
167165
<Compile Include="ImageBuilders\ImageAnnotations\ExternalDataRelocation.cs" />
168166
<Compile Include="ImageBuilders\ImageAnnotations\ExternMethodCallRelocation.cs" />
169-
170167
<Compile Include="LLVM\DebugInfoExtensions.cs" />
171168
<Compile Include="LLVM\InliningPathAnnotationExtensions.cs" />
172169
<Compile Include="LLVM\LLVMModuleManager.cs" />
173170
<Compile Include="LLVM\LLVMModuleManager_Types.cs" />
174171
<Compile Include="LLVM\ITargetSectionOptions.cs" />
175-
<Compile Include="LLVM\SectionNameProvider.cs" />
172+
<Compile Include="LLVM\SectionNameProvider.cs" />
176173
<Compile Include="LLVM\TypeField.cs" />
177174
<Compile Include="LLVM\ValueExtensions.cs" />
178175
<Compile Include="LLVM\_BasicBlock.cs" />

Diff for: Zelig/Zelig/CompileTime/CodeGenerator/CodeTransformation/CompilationSteps/PhaseDrivers/ComputeCallsClosure.cs

+4-12
Original file line numberDiff line numberDiff line change
@@ -567,19 +567,11 @@ private void Include( TypeRepresentation td )
567567
//
568568
if(td.HasBuildTimeFlag( TypeRepresentation.BuildTimeAttributes.ForceDevirtualization ))
569569
{
570-
foreach(TypeRepresentation td2 in m_owner.m_typeSystem.Types)
570+
var list = m_owner.m_typeSystem.CollectConcreteImplementations(td);
571+
572+
foreach (var td2 in list)
571573
{
572-
if(td2.IsAbstract == false)
573-
{
574-
for(TypeRepresentation td3 = td2; td3 != null; td3 = td3.Extends)
575-
{
576-
if(td3 == td)
577-
{
578-
CoverType( td2 );
579-
break;
580-
}
581-
}
582-
}
574+
CoverType(td2);
583575
}
584576
}
585577

Diff for: Zelig/Zelig/CompileTime/CodeGenerator/CodeTransformation/CompilationSteps/Phases/ApplyConfigurationSettings.cs

+28
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,35 @@ public override PhaseDriver Run()
3232

3333
this.CallsDataBase.ExecuteInlining( this.TypeSystem );
3434

35+
ApplyGarbageCollectorConfiguration();
36+
3537
return this.NextPhase;
3638
}
39+
40+
private void ApplyGarbageCollectorConfiguration()
41+
{
42+
var wkt = TypeSystem.WellKnownTypes;
43+
44+
var gcImpls = TypeSystem.CollectConcreteImplementations(wkt.Microsoft_Zelig_Runtime_GarbageCollectionManager);
45+
46+
CHECKS.ASSERT(gcImpls.Count == 1, "There can only be 1 active garbage collection manager");
47+
48+
var gcImpl = gcImpls[0];
49+
50+
Console.WriteLine("Garbage collector selected: %s", gcImpl.FullName);
51+
52+
// Since ReferenceCountingCollector is done by code injection during compile time
53+
// (and the ReferenceCountingCollector class itself is only a dummy class with
54+
// empty implementations), we need to detect its selection here and enable the
55+
// code path for code injection here for the later phases.
56+
if (gcImpl.IsSubClassOf(wkt.Microsoft_Zelig_Runtime_ReferenceCountingCollector, null))
57+
{
58+
TypeSystem.ReferenceCountingGarbageCollectionStatus = TypeSystemForCodeTransformation.ReferenceCountingStatus.Enabled;
59+
}
60+
else if (gcImpl.IsSubClassOf(wkt.Microsoft_Zelig_Runtime_StrictReferenceCountingCollector, null))
61+
{
62+
TypeSystem.ReferenceCountingGarbageCollectionStatus = TypeSystemForCodeTransformation.ReferenceCountingStatus.EnabledStrict;
63+
}
64+
}
3765
}
3866
}

Diff for: Zelig/Zelig/CompileTime/CodeGenerator/CodeTransformation/CompilationSteps/Phases/EnableStrictReferenceCountingGarbageCollection.cs

-33
This file was deleted.

Diff for: Zelig/Zelig/CompileTime/CodeGenerator/CodeTransformation/CompilationSteps/Phases/InitializeReferenceCountingGarbageCollection.cs

-29
This file was deleted.

Diff for: Zelig/Zelig/CompileTime/CodeGenerator/CodeTransformation/CompilationSteps/Phases/ReduceNumberOfTemporaries.cs

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ namespace Microsoft.Zelig.CodeGeneration.IR.CompilationSteps.Phases
1010

1111
using Microsoft.Zelig.Runtime.TypeSystem;
1212

13-
[PhaseOrdering( ExecuteAfter = typeof( EnableStrictReferenceCountingGarbageCollection ) )]
1413
public sealed class ReduceNumberOfTemporaries : PhaseDriver
1514
{
1615
//

Diff for: Zelig/Zelig/CompileTime/CodeGenerator/CodeTransformation/TypeSystemForCodeTransformation.cs

+24
Original file line numberDiff line numberDiff line change
@@ -1069,6 +1069,30 @@ public List<TypeRepresentation> CollectConcreteImplementations( TypeRepresentati
10691069
{
10701070
lst.Remove( tdFallback );
10711071
}
1072+
1073+
// If there are still multiple implementations, we look in the configuration provider
1074+
// to see if one is specified using CompilationOption
1075+
if (lst.Count > 1)
1076+
{
1077+
var cfgProv = GetEnvironmentService<IConfigurationProvider>( );
1078+
1079+
object match;
1080+
if(cfgProv.GetValue( td.Name, out match ) && match is string)
1081+
{
1082+
string target = (string)match;
1083+
var newList = new List<TypeRepresentation>( );
1084+
1085+
foreach(var tdCandidate in lst)
1086+
{
1087+
if(tdCandidate.Name == target)
1088+
{
1089+
newList.Add( tdCandidate );
1090+
}
1091+
}
1092+
1093+
lst = newList;
1094+
}
1095+
}
10721096
}
10731097

10741098
return lst;

0 commit comments

Comments
 (0)