Skip to content

Commit

Permalink
minor improvements to debug messages, cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
agracio committed May 18, 2024
1 parent 75e20b6 commit dd4123c
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions src/double/Edge.js/dotnetcore/coreclrembedding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
using System.Collections;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;
using Microsoft.Extensions.DependencyModel;
using Semver;

[StructLayout(LayoutKind.Sequential)]
// ReSharper disable once CheckNamespace
Expand Down Expand Up @@ -172,16 +170,16 @@ protected override Assembly Load(AssemblyName assemblyName)
}
}
}

DebugMessage("EdgeAssemblyLoadContext::Load (CLR) - Assembly {0} was not found in EdgeAssemblyResolver", assemblyName.Name);
return null;
}
}

private class EdgeAssemblyResolver
{
internal readonly Dictionary<string, string> CompileAssemblies = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
private readonly Dictionary<string, string> _libraries = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
private readonly Dictionary<string, string> _nativeLibraries = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
internal readonly Dictionary<string, string> CompileAssemblies = new(StringComparer.OrdinalIgnoreCase);
private readonly Dictionary<string, string> _libraries = new(StringComparer.OrdinalIgnoreCase);
private readonly Dictionary<string, string> _nativeLibraries = new(StringComparer.OrdinalIgnoreCase);
private readonly IList<string> _knownPaths = new List<string>();

private readonly string _packagesPath;
Expand All @@ -201,8 +199,11 @@ public EdgeAssemblyResolver()
{
profileDirectory = Environment.GetEnvironmentVariable("HOME");
}

_packagesPath = Path.Combine(profileDirectory, ".nuget", "packages");

if (!String.IsNullOrEmpty(profileDirectory))
{
_packagesPath = Path.Combine(profileDirectory, ".nuget", "packages");
}
}

DebugMessage("EdgeAssemblyResolver::ctor (CLR) - Packages path is {0}", _packagesPath);
Expand Down Expand Up @@ -249,8 +250,11 @@ private void AddDependencies(DependencyContext dependencyContext, bool standalon

foreach (RuntimeLibrary runtimeLibrary in dependencyContext.RuntimeLibraries)
{
DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Processing runtime dependency {1} {0}", runtimeLibrary.Name, runtimeLibrary.Type);

if (!_libraries.ContainsKey(runtimeLibrary.Name) && CompileAssemblies.ContainsKey(runtimeLibrary.Name))
{
DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Added runtime assembly {1} from {0}", CompileAssemblies[runtimeLibrary.Name], runtimeLibrary.Name);
_libraries[runtimeLibrary.Name] = CompileAssemblies[runtimeLibrary.Name];
}

Expand All @@ -261,7 +265,6 @@ private void AddDependencies(DependencyContext dependencyContext, bool standalon
continue;
}

DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Processing runtime dependency {1} {0}", runtimeLibrary.Name, runtimeLibrary.Type);

List<string> assets = runtimeLibrary.RuntimeAssemblyGroups.GetRuntimeAssets(RuntimeInformation.RuntimeIdentifier).ToList();

Expand Down Expand Up @@ -582,12 +585,14 @@ private bool TryAddAssembly(string assemblyName)

private static readonly bool DebugMode = Environment.GetEnvironmentVariable("EDGE_DEBUG") == "1";
private static readonly long MinDateTimeTicks = 621355968000000000;
private static readonly ConcurrentDictionary<Type, List<Tuple<string, Func<object, object>>>> TypePropertyAccessors = new ConcurrentDictionary<Type, List<Tuple<string, Func<object, object>>>>();
private static readonly ConcurrentDictionary<Type, List<Tuple<string, Func<object, object>>>> TypePropertyAccessors = new();
private static readonly int PointerSize = Marshal.SizeOf<IntPtr>();
private static readonly int V8BufferDataSize = Marshal.SizeOf<V8BufferData>();
private static readonly int V8ObjectDataSize = Marshal.SizeOf<V8ObjectData>();
private static readonly int V8ArrayDataSize = Marshal.SizeOf<V8ArrayData>();
private static readonly ConcurrentDictionary<string, Tuple<Type, MethodInfo>> Compilers = new ConcurrentDictionary<string, Tuple<Type, MethodInfo>>();
private static readonly ConcurrentDictionary<string, Tuple<Type, MethodInfo>> Compilers = new();
private static readonly IList<string> _failedAssemblyResolver = new List<string>();


public static void Initialize(IntPtr context, IntPtr exception)
{
Expand All @@ -597,7 +602,7 @@ public static void Initialize(IntPtr context, IntPtr exception)

// The call to Marshal.PtrToStructure should be working
// This appears to be a .Net Core issue - https://github.com/dotnet/coreclr/issues/22394
// Manually marshaling as a work around
// Manually marshaling as a workaround
//EdgeBootstrapperContext bootstrapperContext = Marshal.PtrToStructure<EdgeBootstrapperContext>(context);
EdgeBootstrapperContext bootstrapperContext = new EdgeBootstrapperContext
{
Expand Down Expand Up @@ -630,7 +635,7 @@ public static void Initialize(IntPtr context, IntPtr exception)

private static Assembly Assembly_Resolving(AssemblyLoadContext arg1, AssemblyName arg2)
{
if (arg2.Name == "System.Core")
if (arg2.Name == "System.Core" || _failedAssemblyResolver.Contains(arg2.Name))
{
return null;
}
Expand All @@ -641,7 +646,7 @@ private static Assembly Assembly_Resolving(AssemblyLoadContext arg1, AssemblyNam
{
return LoadContext.LoadFromAssemblyName(arg2);
}

_failedAssemblyResolver.Add(arg2.Name);
DebugMessage("CoreCLREmbedding::Assembly_Resolving (CLR) - Unable to resolve the assembly using the manifest list, returning null");

return null;
Expand Down

0 comments on commit dd4123c

Please sign in to comment.