Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JIT: Simplify JitDisasm matching behavior and support namespaces/generics in release #74430

Merged
merged 27 commits into from
Sep 4, 2022
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
51b978d
Remove SPILLED JitDisasm in favor of JitDisasmSpilled
jakobbotsch Aug 23, 2022
8100597
JIT: Simplify MethodSet matching behavior
jakobbotsch Aug 23, 2022
efdc84a
Update docs, minor nits
jakobbotsch Aug 23, 2022
a2af04b
Merge branch 'main' of github.com:dotnet/runtime into jit-method-name…
jakobbotsch Aug 23, 2022
dc67a40
Apply suggestions from code review
jakobbotsch Aug 24, 2022
03a1fa7
Update docs/design/coreclr/jit/viewing-jit-dumps.md
jakobbotsch Aug 25, 2022
4ded1a9
Use appendClassName to get namespaces and generic instantiations
jakobbotsch Aug 31, 2022
4dcce2a
Format instantiations in JIT
jakobbotsch Sep 1, 2022
510e5ec
Minor adjustments
jakobbotsch Sep 1, 2022
da27ae0
Add method instantiations
jakobbotsch Sep 1, 2022
55693f3
Update docs
jakobbotsch Sep 1, 2022
e9e6e06
Go back to square brackets
jakobbotsch Sep 1, 2022
daf08e4
Congruence
jakobbotsch Sep 1, 2022
633fa76
Single quotes
jakobbotsch Sep 1, 2022
2764293
Add some SPMI error traps
jakobbotsch Sep 1, 2022
0748742
Switch vsnprintf_s -> _vsnprintf_s, move StringPrinter::Printf to cpp…
jakobbotsch Sep 1, 2022
5de9b29
Another compilation fix
jakobbotsch Sep 1, 2022
98eee9f
Change crossgen2/ILC to fill in instantiations always
jakobbotsch Sep 2, 2022
bebe9f4
Fix a couple more angle brackets, add some braces to single line ifs
jakobbotsch Sep 2, 2022
0cf37d7
Make globbing quadratic instead of exponential
jakobbotsch Sep 2, 2022
68dfcda
Use asCorInfoType instead of getTypeForPrimitiveValueClass
jakobbotsch Sep 2, 2022
a94ac52
Run jit-format
jakobbotsch Sep 2, 2022
b0d00ac
Merge branch 'main' of github.com:dotnet/runtime into jit-method-name…
jakobbotsch Sep 2, 2022
a3f01e9
SPMI: Fix getTypeInstantiationArgument
jakobbotsch Sep 2, 2022
ae673c1
Bump JIT-EE GUID
jakobbotsch Sep 2, 2022
a8737b3
Add header comments, rename some parameters
jakobbotsch Sep 2, 2022
4507256
Apply suggestions from code review
jakobbotsch Sep 2, 2022
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
54 changes: 42 additions & 12 deletions docs/design/coreclr/jit/viewing-jit-dumps.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,29 +120,59 @@ These can be set in one of three ways:

## Specifying method names

The complete syntax for specifying a single method name (for a flag that takes a method name, such as `COMPlus_JitDump`) is:

Some environment variables such as `COMPlus_JitDump` take a set of patterns specifying method names. The matching works in the following way:
jakobbotsch marked this conversation as resolved.
Show resolved Hide resolved
* The JitDisasm string is a space-separated list of patterns. Patterns can arbitrarily contain both '*' (match any characters) and '?' (match any 1 character).
jakobbotsch marked this conversation as resolved.
Show resolved Hide resolved
* The string matched against depends on characters in the pattern:
+ If the pattern contains a ':' character, the string matched against is prefixed by the class name and a colon
+ If the pattern contains a '(' character, the string matched against is suffixed by the signature
+ If the class name (part before colon) contains a '[', the class contains its generic instantiation
+ If the method name (part between colon and '(') contains a '[', the method contains its generic instantiation

In particular, the matching is done against strings of the following format which coincides with how the JIT displays method signatures (so these can be copy pasted into the environment variable).
```
[[<Namespace>.]<ClassName>::]<MethodName>[([<types>)]
[ClassName[Instantiation]:]MethodName[Instantiation][(<types>)]
```

For example
For example, consider the following:
```csharp
namespace MyNamespace
{
public class C<T1, T2>
{
[MethodImpl(MethodImplOptions.NoInlining)]
public void M<T3, T4>(T1 arg1, T2 arg2, T3 arg3, T4 arg4)
{
}
}
}

```
System.Object::ToString(System.Object)
new C<sbyte, string>().M<int, object>(default, default, default, default); // compilation 1
new C<int, int>().M<int, int>(default, default, default, default); // compilation 2
```

The namespace, class name, and argument types are optional, and if they are not present, default to a wildcard. Thus stating:
The full names of these instantiations are the following, as printed by `COMPlus_JitDisasmSummary`:

```
Main
MyNamespace.C`2[byte,System.__Canon]:M[int,System.__Canon](byte,System.__Canon,int,System.__Canon)
MyNamespace.C`2[int,int]:M[int,int](int,int,int,int)
```
Note that ``C`2`` here is the name put into metadata by Roslyn; the suffix is not added by RyuJIT.
For Powershell users keep in mind that backtick is the escape character and itself has to be escaped via double backtick.

will match all methods named Main from any class and any number of arguments.

`<types>` is a comma separated list of type names. Note that presently only the number of arguments and not the types themselves are used to distinguish methods. Thus, `Main(Foo, Bar)` and `Main(int, int)` will both match any main method with two arguments.
The following strings will match both compilations:
```
M
*C`2:M
*C`2[*]:M[*](*)
MyNamespace.C`2:M
```

The wildcard character `*` can be used for `<ClassName>` and `<MethodName>`. In particular `*` by itself indicates every method.
The following match only the first compilation:
```
M[int,*Canon]
MyNamespace.C`2[byte,*]:M
M(*Canon)
```

## Useful COMPlus variables

Expand Down
12 changes: 9 additions & 3 deletions src/coreclr/inc/corinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -2893,9 +2893,15 @@ class ICorStaticInfo
CORINFO_METHOD_HANDLE hMethod
) = 0;

// this function is for debugging only. It returns the method name
// and if 'moduleName' is non-null, it sets it to something that will
// says which method (a class name, or a module name)
// This function returns the method name and if 'moduleName' is non-null,
// it sets it to something that will says what contains the method (a class
// name, or a module name). Note that the moduleName parameter is for
jakobbotsch marked this conversation as resolved.
Show resolved Hide resolved
// diagnostics only.
//
// The method name returned is the same as getMethodNameFromMetadata except
// in the case of functions without metadata (e.g. IL stubs), where this
// function still returns a reasonable name while getMethodNameFromMetadata
// returns null.
virtual const char* getMethodName (
CORINFO_METHOD_HANDLE ftn, /* IN */
const char **moduleName /* OUT */
Expand Down
10 changes: 5 additions & 5 deletions src/coreclr/inc/jiteeversionguid.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ typedef const GUID *LPCGUID;
#define GUID_DEFINED
#endif // !GUID_DEFINED

constexpr GUID JITEEVersionIdentifier = { /* 1b9551b8-21f4-4233-9c90-f3eabd6a322b */
0x1b9551b8,
0x21f4,
0x4233,
{0x9c, 0x90, 0xf3, 0xea, 0xbd, 0x6a, 0x32, 0x2b}
constexpr GUID JITEEVersionIdentifier = { /* 0cd8b9d4-04f4-45a7-b16b-7f24b7c0a454 */
0x0cd8b9d4,
0x04f4,
0x45a7,
{0xb1, 0x6b, 0x7f, 0x24, 0xb7, 0xc0, 0xa4, 0x54}
};

//////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down
80 changes: 33 additions & 47 deletions src/coreclr/jit/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1769,6 +1769,7 @@ void Compiler::compInit(ArenaAllocator* pAlloc,
info.compCompHnd = compHnd;
info.compMethodHnd = methodHnd;
info.compMethodInfo = methodInfo;
info.compClassHnd = compHnd->getMethodClass(methodHnd);

#ifdef DEBUG
bRangeAllowStress = false;
Expand All @@ -1788,17 +1789,10 @@ void Compiler::compInit(ArenaAllocator* pAlloc,
info.compClassName = nullptr;
info.compFullName = nullptr;

const char* classNamePtr;
const char* methodName;

methodName = eeGetMethodName(methodHnd, &classNamePtr);
unsigned len = (unsigned)roundUp(strlen(classNamePtr) + 1);
info.compClassName = getAllocator(CMK_DebugOnly).allocate<char>(len);
info.compMethodName = methodName;
strcpy_s((char*)info.compClassName, len, classNamePtr);

info.compFullName = eeGetMethodFullName(methodHnd);
info.compPerfScore = 0.0;
info.compMethodName = eeGetMethodName(methodHnd, nullptr);
info.compClassName = eeGetClassName(info.compClassHnd);
info.compFullName = eeGetMethodFullName(methodHnd);
info.compPerfScore = 0.0;

info.compMethodSuperPMIIndex = g_jitHost->getIntConfigValue(W("SuperPMIMethodContextNumber"), -1);
#endif // defined(DEBUG) || defined(LATE_DISASM) || DUMP_FLOWGRAPHS
Expand Down Expand Up @@ -2534,7 +2528,7 @@ void Compiler::compInitOptions(JitFlags* jitFlags)

if (opts.jitFlags->IsSet(JitFlags::JIT_FLAG_ALT_JIT))
{
if (pfAltJit->contains(info.compMethodName, info.compClassName, &info.compMethodInfo->args))
if (pfAltJit->contains(info.compMethodHnd, info.compClassHnd, &info.compMethodInfo->args))
{
opts.altJit = true;
}
Expand Down Expand Up @@ -2615,7 +2609,7 @@ void Compiler::compInitOptions(JitFlags* jitFlags)
//
if (compIsForImportOnly() && (!altJitConfig || opts.altJit))
{
if (JitConfig.JitImportBreak().contains(info.compMethodName, info.compClassName, &info.compMethodInfo->args))
if (JitConfig.JitImportBreak().contains(info.compMethodHnd, info.compClassHnd, &info.compMethodInfo->args))
{
assert(!"JitImportBreak reached");
}
Expand All @@ -2630,7 +2624,7 @@ void Compiler::compInitOptions(JitFlags* jitFlags)
//
if (!compIsForInlining())
{
if (JitConfig.JitDump().contains(info.compMethodName, info.compClassName, &info.compMethodInfo->args))
if (JitConfig.JitDump().contains(info.compMethodHnd, info.compClassHnd, &info.compMethodInfo->args))
{
verboseDump = true;
}
Expand Down Expand Up @@ -2865,32 +2859,32 @@ void Compiler::compInitOptions(JitFlags* jitFlags)
opts.dspOrder = true;
}

if (JitConfig.JitGCDump().contains(info.compMethodName, info.compClassName, &info.compMethodInfo->args))
if (JitConfig.JitGCDump().contains(info.compMethodHnd, info.compClassHnd, &info.compMethodInfo->args))
{
opts.dspGCtbls = true;
}

if (JitConfig.JitDisasm().contains(info.compMethodName, info.compClassName, &info.compMethodInfo->args))
if (JitConfig.JitDisasm().contains(info.compMethodHnd, info.compClassHnd, &info.compMethodInfo->args))
{
opts.disAsm = true;
}

if (JitConfig.JitDisasm().contains("SPILLED", nullptr, nullptr))
if (JitConfig.JitDisasmSpilled())
{
opts.disAsmSpilled = true;
}

if (JitConfig.JitUnwindDump().contains(info.compMethodName, info.compClassName, &info.compMethodInfo->args))
if (JitConfig.JitUnwindDump().contains(info.compMethodHnd, info.compClassHnd, &info.compMethodInfo->args))
{
opts.dspUnwind = true;
}

if (JitConfig.JitEHDump().contains(info.compMethodName, info.compClassName, &info.compMethodInfo->args))
if (JitConfig.JitEHDump().contains(info.compMethodHnd, info.compClassHnd, &info.compMethodInfo->args))
{
opts.dspEHTable = true;
}

if (JitConfig.JitDebugDump().contains(info.compMethodName, info.compClassName, &info.compMethodInfo->args))
if (JitConfig.JitDebugDump().contains(info.compMethodHnd, info.compClassHnd, &info.compMethodInfo->args))
{
opts.dspDebugInfo = true;
}
Expand Down Expand Up @@ -2928,7 +2922,7 @@ void Compiler::compInitOptions(JitFlags* jitFlags)
opts.compLongAddress = true;
}

if (JitConfig.JitOptRepeat().contains(info.compMethodName, info.compClassName, &info.compMethodInfo->args))
if (JitConfig.JitOptRepeat().contains(info.compMethodHnd, info.compClassHnd, &info.compMethodInfo->args))
{
opts.optRepeat = true;
}
Expand All @@ -2938,7 +2932,7 @@ void Compiler::compInitOptions(JitFlags* jitFlags)
// JitEarlyExpandMDArraysFilter.
if (JitConfig.JitEarlyExpandMDArrays() == 0)
{
if (JitConfig.JitEarlyExpandMDArraysFilter().contains(info.compMethodName, info.compClassName,
if (JitConfig.JitEarlyExpandMDArraysFilter().contains(info.compMethodHnd, info.compClassHnd,
&info.compMethodInfo->args))
{
opts.compJitEarlyExpandMDArrays = true;
Expand Down Expand Up @@ -2979,7 +2973,7 @@ void Compiler::compInitOptions(JitFlags* jitFlags)
printf(""); // in our logic this causes a flush
}

if (JitConfig.JitBreak().contains(info.compMethodName, info.compClassName, &info.compMethodInfo->args))
if (JitConfig.JitBreak().contains(info.compMethodHnd, info.compClassHnd, &info.compMethodInfo->args))
{
assert(!"JitBreak reached");
}
Expand All @@ -2991,8 +2985,8 @@ void Compiler::compInitOptions(JitFlags* jitFlags)
}

if (verbose ||
JitConfig.JitDebugBreak().contains(info.compMethodName, info.compClassName, &info.compMethodInfo->args) ||
JitConfig.JitBreak().contains(info.compMethodName, info.compClassName, &info.compMethodInfo->args))
JitConfig.JitDebugBreak().contains(info.compMethodHnd, info.compClassHnd, &info.compMethodInfo->args) ||
JitConfig.JitBreak().contains(info.compMethodHnd, info.compClassHnd, &info.compMethodInfo->args))
{
compDebugBreak = true;
}
Expand All @@ -3011,14 +3005,9 @@ void Compiler::compInitOptions(JitFlags* jitFlags)
s_pJitFunctionFileInitialized = true;
}
#else // DEBUG
if (!JitConfig.JitDisasm().isEmpty())
if (JitConfig.JitDisasm().contains(info.compMethodHnd, info.compClassHnd, &info.compMethodInfo->args))
{
const char* methodName = info.compCompHnd->getMethodName(info.compMethodHnd, nullptr);
const char* className = info.compCompHnd->getClassName(info.compClassHnd);
if (JitConfig.JitDisasm().contains(methodName, className, &info.compMethodInfo->args))
{
opts.disAsm = true;
}
opts.disAsm = true;
}
#endif // !DEBUG

Expand Down Expand Up @@ -3186,21 +3175,21 @@ void Compiler::compInitOptions(JitFlags* jitFlags)
// JitForceProcedureSplitting is used to force procedure splitting on checked assemblies.
// This is useful for debugging on a checked build. Note that we still only do procedure
// splitting in the zapper.
if (JitConfig.JitForceProcedureSplitting().contains(info.compMethodName, info.compClassName,
if (JitConfig.JitForceProcedureSplitting().contains(info.compMethodHnd, info.compClassHnd,
&info.compMethodInfo->args))
{
opts.compProcedureSplitting = true;
}

// JitNoProcedureSplitting will always disable procedure splitting.
if (JitConfig.JitNoProcedureSplitting().contains(info.compMethodName, info.compClassName,
if (JitConfig.JitNoProcedureSplitting().contains(info.compMethodHnd, info.compClassHnd,
&info.compMethodInfo->args))
{
opts.compProcedureSplitting = false;
}
//
// JitNoProcedureSplittingEH will disable procedure splitting in functions with EH.
if (JitConfig.JitNoProcedureSplittingEH().contains(info.compMethodName, info.compClassName,
if (JitConfig.JitNoProcedureSplittingEH().contains(info.compMethodHnd, info.compClassHnd,
&info.compMethodInfo->args))
{
opts.compProcedureSplittingEH = false;
Expand Down Expand Up @@ -3316,7 +3305,7 @@ bool Compiler::compJitHaltMethod()
/* This method returns true when we use an INS_BREAKPOINT to allow us to step into the generated native code */
/* Note that this these two "Jit" environment variables also work for ngen images */

if (JitConfig.JitHalt().contains(info.compMethodName, info.compClassName, &info.compMethodInfo->args))
if (JitConfig.JitHalt().contains(info.compMethodHnd, info.compClassHnd, &info.compMethodInfo->args))
{
return true;
}
Expand Down Expand Up @@ -3420,7 +3409,7 @@ bool Compiler::compStressCompileHelper(compStressArea stressArea, unsigned weigh
}

if (!JitConfig.JitStressOnly().isEmpty() &&
!JitConfig.JitStressOnly().contains(info.compMethodName, info.compClassName, &info.compMethodInfo->args))
!JitConfig.JitStressOnly().contains(info.compMethodHnd, info.compClassHnd, &info.compMethodInfo->args))
{
return false;
}
Expand Down Expand Up @@ -3703,7 +3692,7 @@ void Compiler::compSetOptimizationLevel()

if (!theMinOptsValue)
{
if (JitConfig.JitMinOptsName().contains(info.compMethodName, info.compClassName, &info.compMethodInfo->args))
if (JitConfig.JitMinOptsName().contains(info.compMethodHnd, info.compClassHnd, &info.compMethodInfo->args))
{
theMinOptsValue = true;
}
Expand Down Expand Up @@ -4207,8 +4196,7 @@ const char* Compiler::compGetStressMessage() const
{
// Or is it excluded via name?
if (!JitConfig.JitStressOnly().isEmpty() ||
!JitConfig.JitStressOnly().contains(info.compMethodName, info.compClassName,
&info.compMethodInfo->args))
!JitConfig.JitStressOnly().contains(info.compMethodHnd, info.compClassHnd, &info.compMethodInfo->args))
{
// Not excluded -- stress can happen
stressMessage = " JitStress";
Expand Down Expand Up @@ -5000,7 +4988,8 @@ void Compiler::compCompile(void** methodCodePtr, uint32_t* methodCodeSize, JitFl
#ifdef DEBUG
const char* fullName = info.compFullName;
#else
const char* fullName = eeGetMethodFullName(info.compMethodHnd);
const char* fullName =
eeGetMethodFullName(info.compMethodHnd, /* includeReturnType */ false, /* includeThisSpecifier */ false);
#endif

char debugPart[128] = {0};
Expand Down Expand Up @@ -5375,13 +5364,13 @@ bool Compiler::skipMethod()
return true;
}

if (JitConfig.JitExclude().contains(info.compMethodName, info.compClassName, &info.compMethodInfo->args))
if (JitConfig.JitExclude().contains(info.compMethodHnd, info.compClassHnd, &info.compMethodInfo->args))
{
return true;
}

if (!JitConfig.JitInclude().isEmpty() &&
!JitConfig.JitInclude().contains(info.compMethodName, info.compClassName, &info.compMethodInfo->args))
!JitConfig.JitInclude().contains(info.compMethodHnd, info.compClassHnd, &info.compMethodInfo->args))
{
return true;
}
Expand Down Expand Up @@ -5687,9 +5676,7 @@ int Compiler::compCompile(CORINFO_MODULE_HANDLE classPtr,
{
impTokenLookupContextHandle = impInlineInfo->tokenLookupContextHandle;

assert(impInlineInfo->inlineCandidateInfo->clsHandle == info.compCompHnd->getMethodClass(info.compMethodHnd));
info.compClassHnd = impInlineInfo->inlineCandidateInfo->clsHandle;

assert(impInlineInfo->inlineCandidateInfo->clsHandle == info.compClassHnd);
assert(impInlineInfo->inlineCandidateInfo->clsAttr == info.compCompHnd->getClassAttribs(info.compClassHnd));
// printf("%x != %x\n", impInlineInfo->inlineCandidateInfo->clsAttr,
// info.compCompHnd->getClassAttribs(info.compClassHnd));
Expand All @@ -5699,7 +5686,6 @@ int Compiler::compCompile(CORINFO_MODULE_HANDLE classPtr,
{
impTokenLookupContextHandle = METHOD_BEING_COMPILED_CONTEXT();

info.compClassHnd = info.compCompHnd->getMethodClass(info.compMethodHnd);
info.compClassAttr = info.compCompHnd->getClassAttribs(info.compClassHnd);
}

Expand Down
Loading