Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions src/pmi/PMIDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public static int Drive(string assemblyName, bool verbose, Dictionary<string, st
while (!isFileCompleted && prepallRetryCount <= PREPALL_MAX_RETRY_COUNT)
{
prepallRetryCount++;
PrepAllResult pr = Compute(pi);
PrepAllResult pr = Compute(pi, verbose);
if (pr.success)
{
isFileCompleted = true;
Expand Down Expand Up @@ -152,7 +152,7 @@ public static int Drive(string assemblyName, bool verbose, Dictionary<string, st
}
}

private static PrepAllResult Compute(PrepAllInfo pi)
private static PrepAllResult Compute(PrepAllInfo pi, bool verbose)
{
PrepAllResult temp = new PrepAllResult();
temp.success = false;
Expand Down Expand Up @@ -192,11 +192,14 @@ private static PrepAllResult Compute(PrepAllInfo pi)
p.StartInfo.FileName = driverName;
p.StartInfo.Arguments = newCommandLine;

Console.WriteLine($"DRIVEALL: Invoking {driverName} {newCommandLine}");

foreach (var pair in pi.environment)
if (verbose)
{
Console.WriteLine($" {pair.Key}={pair.Value}");
Console.WriteLine($"DRIVEALL: Invoking {driverName} {newCommandLine}");

foreach (var pair in pi.environment)
{
Console.WriteLine($" {pair.Key}={pair.Value}");
}
}

p.Start();
Expand Down
223 changes: 150 additions & 73 deletions src/pmi/pmi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -436,82 +436,152 @@ protected bool TryPrepareMethod(Type type, MethodBase method, out TimeSpan elaps
bool success = false;
elapsedFunc = TimeSpan.MinValue;

try
{
DateTime startFunc = DateTime.Now;
GC.WaitForPendingFinalizers();
System.Runtime.CompilerServices.RuntimeHelpers.PrepareMethod(method.MethodHandle);
elapsedFunc = DateTime.Now - startFunc;
success = true;
}
catch (System.EntryPointNotFoundException)
{
Console.WriteLine();
Console.WriteLine($"EntryPointNotFoundException {type.FullName}::{method.Name}");
}
catch (System.BadImageFormatException)
{
Console.WriteLine();
Console.WriteLine($"BadImageFormatException {type.FullName}::{method.Name}");
}
catch (System.MissingMethodException)
{
Console.WriteLine();
Console.WriteLine($"MissingMethodException {type.FullName}::{method.Name}");
}
catch (System.ArgumentException e)
{
Console.WriteLine();
string msg = e.Message.Split(new char[] { '\r', '\n' })[0];
Console.WriteLine($"ArgumentException {type.FullName}::{method.Name} {msg}");
}
catch (System.IO.FileNotFoundException eFileNotFound)
{
Console.WriteLine();
Console.WriteLine($"FileNotFoundException {type.FullName}::{method.Name}" +
$" - {eFileNotFound.FileName} ({eFileNotFound.Message})");
}
catch (System.DllNotFoundException eDllNotFound)
{
Console.WriteLine();
Console.WriteLine($"DllNotFoundException {type.FullName}::{method.Name} ({eDllNotFound.Message})");
}
catch (System.TypeInitializationException eTypeInitialization)
{
Console.WriteLine();
Console.WriteLine("TypeInitializationException {type.FullName}::{method.Name}" +
$"{eTypeInitialization.TypeName} ({eTypeInitialization.Message})");
}
catch (System.Runtime.InteropServices.MarshalDirectiveException)
{
Console.WriteLine();
Console.WriteLine($"MarshalDirectiveException {type.FullName}::{method.Name}");
}
catch (System.TypeLoadException)
{
Console.WriteLine();
Console.WriteLine($"TypeLoadException {type.FullName}::{method.Name}");
}
catch (System.OverflowException)
{
Console.WriteLine();
Console.WriteLine($"OverflowException {type.FullName}::{method.Name}");
}
catch (System.InvalidProgramException)
{
Console.WriteLine();
Console.WriteLine($"InvalidProgramException {type.FullName}::{method.Name}");
}
catch (System.InvalidOperationException)
string methodToDisasm = Environment.GetEnvironmentVariable("COMPlus_JitDisasm");

bool useEnv = methodToDisasm != null;
ReadOnlySpan<char> methodName = null;
ReadOnlySpan<char> className = null;

bool namesMatch = false;

if (useEnv)
{
Console.WriteLine();
Console.WriteLine($"InvalidOperationException {type.FullName}::{method.Name}");
bool hasClassName = methodToDisasm.IndexOf(':') != -1;
bool containsArgs = methodToDisasm.IndexOf('(') != -1;
bool endsWithWildcard = methodToDisasm.IndexOf('*') != -1;

// COMPlus_JitDisasm=* passed, this is the same as not having
// the environment set.
if (endsWithWildcard && methodToDisasm.Length == 1)
{
useEnv = false;
}

int methodNameStart = 0;
ReadOnlySpan<char> splitStr = methodToDisasm.AsSpan(methodNameStart);

if (hasClassName)
{
methodNameStart = methodToDisasm.IndexOf(':') + 1;
className = splitStr.Slice(0, methodNameStart - 1);
}

int methodNameEnd = splitStr.Length - methodNameStart;
if (containsArgs)
{
methodNameEnd = splitStr.IndexOf('(') - methodNameStart;
}

if (endsWithWildcard)
{
--methodNameEnd;
}

methodName = splitStr.Slice(methodNameStart, methodNameEnd);

bool classNamesMatch = className.CompareTo(method.DeclaringType.Name.AsSpan(), StringComparison.OrdinalIgnoreCase) == 0;

if (!endsWithWildcard)
{
namesMatch = methodName.CompareTo(method.Name.AsSpan(), StringComparison.OrdinalIgnoreCase) == 0;
}
else
{
ReadOnlySpan<char> compareName = method.Name.AsSpan();

bool same = true;
for (int index = 0; index < methodName.Length; ++index)
{
if (methodName[index] != compareName[index])
{
same = false;
break;
}
}

namesMatch = same;
}
}
catch (Exception e)

if (!useEnv || namesMatch)
{
Console.WriteLine();
Console.WriteLine($"Unknown exception {type.FullName}::{method.Name}");
Console.WriteLine(e);
try
{
DateTime startFunc = DateTime.Now;
GC.WaitForPendingFinalizers();
System.Runtime.CompilerServices.RuntimeHelpers.PrepareMethod(method.MethodHandle);
elapsedFunc = DateTime.Now - startFunc;
success = true;
}
catch (System.EntryPointNotFoundException)
{
Console.WriteLine();
Console.WriteLine($"EntryPointNotFoundException {type.FullName}::{method.Name}");
}
catch (System.BadImageFormatException)
{
Console.WriteLine();
Console.WriteLine($"BadImageFormatException {type.FullName}::{method.Name}");
}
catch (System.MissingMethodException)
{
Console.WriteLine();
Console.WriteLine($"MissingMethodException {type.FullName}::{method.Name}");
}
catch (System.ArgumentException e)
{
Console.WriteLine();
string msg = e.Message.Split(new char[] { '\r', '\n' })[0];
Console.WriteLine($"ArgumentException {type.FullName}::{method.Name} {msg}");
}
catch (System.IO.FileNotFoundException eFileNotFound)
{
Console.WriteLine();
Console.WriteLine($"FileNotFoundException {type.FullName}::{method.Name}" +
$" - {eFileNotFound.FileName} ({eFileNotFound.Message})");
}
catch (System.DllNotFoundException eDllNotFound)
{
Console.WriteLine();
Console.WriteLine($"DllNotFoundException {type.FullName}::{method.Name} ({eDllNotFound.Message})");
}
catch (System.TypeInitializationException eTypeInitialization)
{
Console.WriteLine();
Console.WriteLine("TypeInitializationException {type.FullName}::{method.Name}" +
$"{eTypeInitialization.TypeName} ({eTypeInitialization.Message})");
}
catch (System.Runtime.InteropServices.MarshalDirectiveException)
{
Console.WriteLine();
Console.WriteLine($"MarshalDirectiveException {type.FullName}::{method.Name}");
}
catch (System.TypeLoadException)
{
Console.WriteLine();
Console.WriteLine($"TypeLoadException {type.FullName}::{method.Name}");
}
catch (System.OverflowException)
{
Console.WriteLine();
Console.WriteLine($"OverflowException {type.FullName}::{method.Name}");
}
catch (System.InvalidProgramException)
{
Console.WriteLine();
Console.WriteLine($"InvalidProgramException {type.FullName}::{method.Name}");
}
catch (System.InvalidOperationException)
{
Console.WriteLine();
Console.WriteLine($"InvalidOperationException {type.FullName}::{method.Name}");
}
catch (Exception e)
{
Console.WriteLine();
Console.WriteLine($"Unknown exception {type.FullName}::{method.Name}");
Console.WriteLine(e);
}
}

return success;
Expand Down Expand Up @@ -997,10 +1067,17 @@ bool Work(Type type)
}
}

string methodToDisasm = Environment.GetEnvironmentVariable("COMPlus_JitDisasm");

if (keepGoing)
{
foreach (MethodBase methodBase in methods)
{
if (methodToDisasm != null && methodToDisasm.IndexOf(methodBase.DeclaringType.Name) == -1)
{
continue;
}

if (methodBase == cctor)
{
continue;
Expand Down