File: Contracts\IGC.cs
Web Access
Project: src\src\runtime\src\native\managed\cdac\Microsoft.Diagnostics.DataContractReader.Abstractions\Microsoft.Diagnostics.DataContractReader.Abstractions.csproj (Microsoft.Diagnostics.DataContractReader.Abstractions)
// 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.Collections.Generic;

namespace Microsoft.Diagnostics.DataContractReader.Contracts;

public static class GCIdentifiers
{
    public const string Server = "server";
    public const string Workstation = "workstation";

    public const string Regions = "regions";
    public const string Segments = "segments";

    public const string Background = "background";

    public const string DynamicHeapCount = "dynamic_heap";
}

public enum HandleType
{
    WeakShort = 0,
    WeakLong = 1,
    Strong = 2,
    Pinned = 3,
    RefCounted = 5,
    Dependent = 6,
    WeakInteriorPointer = 10,
    CrossReference = 11,
}

public record struct HandleData(
    TargetPointer Handle,
    TargetPointer Secondary,
    uint Type,
    bool StrongReference,
    uint RefCount,
    uint JupiterRefCount,
    bool IsPegged);

public readonly struct GCHeapData
{
    public TargetPointer MarkArray { get; init; }
    public TargetPointer NextSweepObject { get; init; }
    public TargetPointer BackGroundSavedMinAddress { get; init; }
    public TargetPointer BackGroundSavedMaxAddress { get; init; }
    public TargetPointer AllocAllocated { get; init; }
    public TargetPointer EphemeralHeapSegment { get; init; }
    public TargetPointer CardTable { get; init; }
    public IReadOnlyList<GCGenerationData> GenerationTable { get; init; }
    public IReadOnlyList<TargetPointer> FillPointers { get; init; }
    public TargetPointer SavedSweepEphemeralSegment { get; init; } /* Only valid in segment GC builds */
    public TargetPointer SavedSweepEphemeralStart { get; init; } /* Only valid in segment GC builds */

    public TargetPointer InternalRootArray { get; init; }
    public TargetNUInt InternalRootArrayIndex { get; init; }
    public bool HeapAnalyzeSuccess { get; init; }

    public IReadOnlyList<TargetNUInt> InterestingData { get; init; }
    public IReadOnlyList<TargetNUInt> CompactReasons { get; init; }
    public IReadOnlyList<TargetNUInt> ExpandMechanisms { get; init; }
    public IReadOnlyList<TargetNUInt> InterestingMechanismBits { get; init; }
}

public readonly struct GCGenerationData
{
    public TargetPointer StartSegment { get; init; }
    public TargetPointer AllocationStart { get; init; }
    public TargetPointer AllocationContextPointer { get; init; }
    public TargetPointer AllocationContextLimit { get; init; }
}

public readonly struct GCHeapSegmentData
{
    public TargetPointer Allocated { get; init; }
    public TargetPointer Committed { get; init; }
    public TargetPointer Reserved { get; init; }
    public TargetPointer Used { get; init; }
    public TargetPointer Mem { get; init; }
    public TargetNUInt Flags { get; init; }
    public TargetPointer Next { get; init; }
    public TargetPointer BackgroundAllocated { get; init; }
    public TargetPointer Heap { get; init; }
}

public readonly struct GCOomData
{
    public int Reason { get; init; }
    public TargetNUInt AllocSize { get; init; }
    public TargetPointer Reserved { get; init; }
    public TargetPointer Allocated { get; init; }
    public TargetNUInt GCIndex { get; init; }
    public int Fgm { get; init; }
    public TargetNUInt Size { get; init; }
    public TargetNUInt AvailablePagefileMB { get; init; }
    public bool LohP { get; init; }
}

public enum FreeRegionKind
{
    FreeUnknownRegion = 0,
    FreeGlobalHugeRegion = 1,
    FreeGlobalRegion = 2,
    FreeRegion = 3,
    FreeSohSegment = 4,
    FreeUohSegment = 5,
}

public readonly struct GCMemoryRegionData
{
    public TargetPointer Start { get; init; }
    public ulong Size { get; init; }
    public ulong ExtraData { get; init; }
    public int Heap { get; init; }
}

public enum GCSegmentClassification
{
    Unknown,
    Gen0,
    Gen1,
    Gen2,
    LOH,
    POH,
    NonGC,
    Ephemeral,
}

public readonly record struct GCHeapSegmentInfo(
    TargetPointer Start,
    TargetPointer End,
    GCSegmentClassification Generation);

public interface IGC : IContract
{
    static string IContract.Name { get; } = nameof(GC);

    string[] GetGCIdentifiers() => throw new NotImplementedException();

    uint GetGCHeapCount() => throw new NotImplementedException();
    bool GetGCStructuresValid() => throw new NotImplementedException();
    uint GetMaxGeneration() => throw new NotImplementedException();
    void GetGCBounds(out TargetPointer minAddr, out TargetPointer maxAddr) => throw new NotImplementedException();
    uint GetCurrentGCState() => throw new NotImplementedException();
    bool TryGetGCDynamicAdaptationMode(out int mode) => throw new NotImplementedException();
    GCHeapSegmentData GetHeapSegmentData(TargetPointer segmentAddress) => throw new NotImplementedException();
    IReadOnlyList<TargetNUInt> GetGlobalMechanisms() => throw new NotImplementedException();
    IEnumerable<TargetPointer> GetGCHeaps() => throw new NotImplementedException();

    // workstation variant
    GCHeapData GetHeapData() => throw new NotImplementedException();
    // server variant
    GCHeapData GetHeapData(TargetPointer heapAddress) => throw new NotImplementedException();

    // workstation variant
    GCOomData GetOomData() => throw new NotImplementedException();
    // server variant
    GCOomData GetOomData(TargetPointer heapAddress) => throw new NotImplementedException();
    List<HandleData> GetHandles(HandleType[] types) => throw new NotImplementedException();
    HandleType[] GetSupportedHandleTypes() => throw new NotImplementedException();
    HandleType[] GetHandleTypes(uint[] types) => throw new NotImplementedException();
    TargetNUInt GetHandleExtraInfo(TargetPointer handle) => throw new NotImplementedException();

    void GetGlobalAllocationContext(out TargetPointer allocPtr, out TargetPointer allocLimit) => throw new NotImplementedException();

    IReadOnlyList<GCMemoryRegionData> GetHandleTableMemoryRegions() => throw new NotImplementedException();
    IReadOnlyList<GCMemoryRegionData> GetGCBookkeepingMemoryRegions() => throw new NotImplementedException();
    IReadOnlyList<GCMemoryRegionData> GetGCFreeRegions() => throw new NotImplementedException();

    // Enumerates the raw GC heap segments for a single heap as recorded by the GC's per-generation
    // segment lists.
    IEnumerable<GCHeapSegmentInfo> EnumerateHeapSegments(GCHeapData heapData) => throw new NotImplementedException();
}

public readonly struct GC : IGC
{
    // Everything throws NotImplementedException
}