Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,45 @@ protected override bool CompareValueToValue(AsyncMethodVariant value1, AsyncMeth
}
private AsyncVariantHashtable _asyncVariantHashtable = new AsyncVariantHashtable();

public AsyncResumptionStub GetAsyncResumptionStub(MethodDesc targetMethod, TypeDesc owningType)
{
return _asyncResumptionStubHashtable.GetOrCreateValue(new AsyncResumptionStubKey(targetMethod, owningType));
}

private readonly struct AsyncResumptionStubKey : System.IEquatable<AsyncResumptionStubKey>
{
public readonly MethodDesc TargetMethod;
public readonly TypeDesc OwningType;

public AsyncResumptionStubKey(MethodDesc targetMethod, TypeDesc owningType)
{
TargetMethod = targetMethod;
OwningType = owningType;
}

public bool Equals(AsyncResumptionStubKey other)
=> TargetMethod == other.TargetMethod;

public override bool Equals(object obj)
=> obj is AsyncResumptionStubKey other && Equals(other);

public override int GetHashCode()
=> TargetMethod.GetHashCode();
}

private sealed class AsyncResumptionStubHashtable : LockFreeReaderHashtable<AsyncResumptionStubKey, AsyncResumptionStub>
{
protected override int GetKeyHashCode(AsyncResumptionStubKey key) => key.GetHashCode();
protected override int GetValueHashCode(AsyncResumptionStub value) => value.TargetMethod.GetHashCode();
protected override bool CompareKeyToValue(AsyncResumptionStubKey key, AsyncResumptionStub value)
=> key.TargetMethod == value.TargetMethod;
protected override bool CompareValueToValue(AsyncResumptionStub value1, AsyncResumptionStub value2)
=> value1.TargetMethod == value2.TargetMethod;
Comment thread
jtschuster marked this conversation as resolved.
Comment thread
jtschuster marked this conversation as resolved.
protected override AsyncResumptionStub CreateValueFromKey(AsyncResumptionStubKey key)
=> new AsyncResumptionStub(key.TargetMethod, key.OwningType);
}
private AsyncResumptionStubHashtable _asyncResumptionStubHashtable = new AsyncResumptionStubHashtable();
Comment thread
jtschuster marked this conversation as resolved.

public MetadataType GetContinuationType(GCPointerMap pointerMap)
{
return _continuationTypeHashtable.GetOrCreateValue(pointerMap);
Expand Down
1 change: 0 additions & 1 deletion src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,6 @@ private void CompileMethodCleanup()
#if !READYTORUN
_debugInfo = null;
#endif
_asyncResumptionStub = null;

_debugLocInfos = null;
_debugVarInfos = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ private void ImportCall(ILOpcode opcode, int token)

const string asyncReason = "Async state machine";

var resumptionStub = new AsyncResumptionStub(_canonMethod, _compilation.TypeSystemContext.GeneratedAssembly.GetGlobalModuleType());
AsyncResumptionStub resumptionStub = _compilation.TypeSystemContext.GetAsyncResumptionStub(_canonMethod, _compilation.TypeSystemContext.GeneratedAssembly.GetGlobalModuleType());
_dependencies.Add(_compilation.NodeFactory.MethodEntrypoint(resumptionStub), asyncReason);

_dependencies.Add(_factory.ConstructedTypeSymbol(_compilation.TypeSystemContext.ContinuationType), asyncReason);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -477,8 +477,6 @@ unsafe partial class CorInfoImpl
private List<EcmaMethod> _ilBodiesNeeded;
private Dictionary<TypeDesc, bool> _preInitedTypes = new Dictionary<TypeDesc, bool>();
private HashSet<MethodDesc> _synthesizedPgoDependencies;
private MethodDesc _asyncResumptionStub;

public bool HasColdCode { get; private set; }

public CorInfoImpl(ReadyToRunCodegenCompilation compilation)
Expand All @@ -500,14 +498,11 @@ private void AddResumptionStubFixup(MethodWithGCInfo compiledStubNode)

private CORINFO_METHOD_STRUCT_* getAsyncResumptionStub(ref void* entryPoint)
{
if (_asyncResumptionStub is null)
{
_asyncResumptionStub = new AsyncResumptionStub(MethodBeingCompiled, MethodBeingCompiled.OwningType);
AddResumptionStubFixup(_compilation.NodeFactory.CompiledMethodNode(_asyncResumptionStub));
}
MethodDesc asyncResumptionStub = _compilation.TypeSystemContext.GetAsyncResumptionStub(MethodBeingCompiled, MethodBeingCompiled.OwningType);
AddResumptionStubFixup(_compilation.NodeFactory.CompiledMethodNode(asyncResumptionStub));

entryPoint = (void*)ObjectToHandle(_compilation.NodeFactory.CompiledMethodNode(_asyncResumptionStub));
return ObjectToHandle(_asyncResumptionStub);
entryPoint = (void*)ObjectToHandle(_compilation.NodeFactory.CompiledMethodNode(asyncResumptionStub));
return ObjectToHandle(asyncResumptionStub);
}

private static mdToken FindGenericMethodArgTypeSpec(EcmaModule module)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ internal unsafe partial class CorInfoImpl

private RyuJitCompilation _compilation;
private MethodDebugInformation _debugInfo;
private MethodDesc _asyncResumptionStub;
private MethodCodeNode _methodCodeNode;
private DebugLocInfo[] _debugLocInfos;
private DebugVarInfo[] _debugVarInfos;
Expand All @@ -57,10 +56,10 @@ private UnboxingMethodDesc getUnboxingThunk(MethodDesc method)

private CORINFO_METHOD_STRUCT_* getAsyncResumptionStub(ref void* entryPoint)
{
_asyncResumptionStub ??= new AsyncResumptionStub(MethodBeingCompiled, _compilation.TypeSystemContext.GeneratedAssembly.GetGlobalModuleType());
MethodDesc asyncResumptionStub = _compilation.TypeSystemContext.GetAsyncResumptionStub(MethodBeingCompiled, _compilation.TypeSystemContext.GeneratedAssembly.GetGlobalModuleType());

entryPoint = (void*)ObjectToHandle(_compilation.NodeFactory.MethodEntrypoint(_asyncResumptionStub));
return ObjectToHandle(_asyncResumptionStub);
entryPoint = (void*)ObjectToHandle(_compilation.NodeFactory.MethodEntrypoint(asyncResumptionStub));
return ObjectToHandle(asyncResumptionStub);
}

public void CompileMethod(MethodCodeNode methodCodeNodeNeedingCode, MethodIL methodIL = null)
Expand Down
Loading