Skip to content

Commit

Permalink
Preparing for precision garbase collection (#1250)
Browse files Browse the repository at this point in the history
* - Preparing for SafePoints

* - Preparing for SafePoints

* - Preparing for SafePoints

* - Preparing for SafePoints

* Merge branch 'master' of https://github.com/mosa/MOSA-Project into 511-safepoints

# Conflicts:
#	Source/Mosa.Compiler.Framework/Stages/SafePointStage.cs
  • Loading branch information
tgiphil authored Dec 1, 2024
1 parent d95db0a commit 1d63e48
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 6 deletions.
16 changes: 16 additions & 0 deletions Source/Data/IR-Instructions.json
Original file line number Diff line number Diff line change
Expand Up @@ -1501,6 +1501,22 @@
"IgnoreDuringCodeGeneration": "true",
"UnspecifiedSideEffect": "true"
},
{
"Name": "UnstableRegionStart",
"FamilyName": "IR",
"ResultCount": 0,
"OperandCount": 0,
"IgnoreDuringCodeGeneration": "true",
"UnspecifiedSideEffect": "true"
},
{
"Name": "UnstableRegionEnd",
"FamilyName": "IR",
"ResultCount": 0,
"OperandCount": 0,
"IgnoreDuringCodeGeneration": "true",
"UnspecifiedSideEffect": "true"
},
{
"Name": "Rethrow",
"FamilyName": "IR",
Expand Down
18 changes: 14 additions & 4 deletions Source/Docs/mosa-runtime-tables.dot
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ digraph "MOSA Runtime Tables"
];

"NameString" [
label = "<f0>String Object|<f1>Object Header|<f2>Pointer to Method Table|<f3>String Length|<f4>Unicode String"
label = "<f0>Internal String Object|<f1>Object Header|<f2>Pointer to Method Table|<f3>String Length|<f4>Unicode String"
shape = "record"
color = "red"
];
Expand Down Expand Up @@ -209,7 +209,7 @@ digraph "MOSA Runtime Tables"
];

"MethodDefinition" [
label = "<f0>Method Definition|<f1>Pointer to Method Name|<f2>~Pointer to Custom Attributes|<f3>Method Attributes|<f4>Local & Parameter Stack Size|<f5>Pointer to Method|<f6>Pointer to Return Type Definition|<f7>~Pointer to Protected Region Table|<f8>Pointer to SafePoint Table|<f9>Number of Parameters|<f10>Pointer to Parameter Definition 1|...|Pointer to Parameter Definition N"
label = "<f0>Method Definition|<f1>Pointer to Method Name|<f2>~Pointer to Custom Attributes|<f3>Method Attributes|<f4>Local & Parameter Stack Size|<f5>Pointer to Method|<f6>Pointer to Return Type Definition|<f7>~Pointer to Protected Region Table|<f8>Pointer to Method GC Data|<f9>Number of Parameters|<f10>Pointer to Parameter Definition 1|...|Pointer to Parameter Definition N"
shape = "record"
color = "purple"
];
Expand All @@ -232,7 +232,7 @@ digraph "MOSA Runtime Tables"
color = "blue"
];

"MethodDefinition":f8 -> "SafePointTable":f0 [
"MethodDefinition":f8 -> "Method GC Data":f0 [
id = 0
];

Expand All @@ -258,14 +258,24 @@ digraph "MOSA Runtime Tables"
id = 0
color = "blue"
];

"Method GC Data" [
label = "<f0>Method GC Data|<f1>Pointer to SafePoint Table|<f2>Pointer to Method GC Stack Data"
shape = "record"
];

"Method GC Data":f1 -> "SafePoint":f0 [
id = 0
style = "dotted"
];

"SafePointTable" [
label = "<f0>SafePoint Table|<f1>Number of SafePoints|<f2>SafePoint 1|..|SafePoint N"
shape = "record"
];

"SafePoint" [
label = "<f0>SafePoint|<f1>Address Offset|<f2>Address Range (signed)|<f3>Breakpoint Indicator|<f4>CPU Registers Bitmap (64 bit)"
label = "<f0>SafePoint|<f1>Address Offset|<f2>Address Range (signed)|<f3>Breakpoint Indicator|<f4>CPU Registers Bitmap (32 bit)"
shape = "record"
];

Expand Down
12 changes: 12 additions & 0 deletions Source/Docs/runtime-tables.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,15 @@ MOSA Runtime Tables
This diagram represents the internal runtime tables within the MOSA virtual machine:

.. graphviz:: mosa-runtime-tables.dot

Internal String Object
----------------------

.. csv-table::
:header: "Fields"
:widths: 200

Object Header
Pointer to Method Table
String Length
Unicode String
2 changes: 2 additions & 0 deletions Source/Mosa.Compiler.Framework/IR.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,8 @@ public static class IR
public static readonly BaseInstruction TryEnd = new TryEnd();
public static readonly BaseInstruction TryStart = new TryStart();
public static readonly BaseInstruction SafePoint = new SafePoint();
public static readonly BaseInstruction UnstableRegionStart = new UnstableRegionStart();
public static readonly BaseInstruction UnstableRegionEnd = new UnstableRegionEnd();
public static readonly BaseInstruction Rethrow = new Rethrow();
public static readonly BaseInstruction GetVirtualFunctionPtr = new GetVirtualFunctionPtr();
public static readonly BaseInstruction MemoryCopy = new MemoryCopy();
Expand Down
18 changes: 18 additions & 0 deletions Source/Mosa.Compiler.Framework/Instructions/UnstableRegionEnd.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (c) MOSA Project. Licensed under the New BSD License.

// This code was generated by an automated template.

namespace Mosa.Compiler.Framework.Instructions;

/// <summary>
/// UnstableRegionEnd
/// </summary>
public sealed class UnstableRegionEnd : BaseIRInstruction
{
public UnstableRegionEnd()
: base(0, 0)
{
}

public override bool IgnoreDuringCodeGeneration => true;
}
18 changes: 18 additions & 0 deletions Source/Mosa.Compiler.Framework/Instructions/UnstableRegionStart.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (c) MOSA Project. Licensed under the New BSD License.

// This code was generated by an automated template.

namespace Mosa.Compiler.Framework.Instructions;

/// <summary>
/// UnstableRegionStart
/// </summary>
public sealed class UnstableRegionStart : BaseIRInstruction
{
public UnstableRegionStart()
: base(0, 0)
{
}

public override bool IgnoreDuringCodeGeneration => true;
}
2 changes: 1 addition & 1 deletion Source/Mosa.Compiler.Framework/Stages/SafePointStage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Mosa.Compiler.Framework.Stages;

// TODO:
// 1. Analyze method and determine:
// A. Determine if method contain any refernces to objects, or have any managed pointers
// A. Determine if method contains any references to objects, or have any managed pointers
// B. Determine start/end ranges of objects and managed pointers on the local stack and parameters
// C. Place SafePoint at:
// i. Method prologue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ protected static void CopyCompound(Transform transform, Context context, Operand
var srcReg = transform.VirtualRegisters.AllocateNativeInteger();
var dstReg = transform.VirtualRegisters.AllocateNativeInteger();

context.SetInstruction(transform.AddInstruction, srcReg, sourceBase, source);
context.SetInstruction(IR.UnstableRegionStart);

context.AppendInstruction(transform.AddInstruction, srcReg, sourceBase, source);
context.AppendInstruction(transform.AddInstruction, dstReg, destinationBase, destination);

var tmp = transform.VirtualRegisters.AllocateNativeInteger();
Expand Down Expand Up @@ -70,6 +72,8 @@ protected static void CopyCompound(Transform transform, Context context, Operand
continue;
}
}

context.AppendInstruction(IR.UnstableRegionEnd);
}

#endregion Helpers
Expand Down

0 comments on commit 1d63e48

Please sign in to comment.