Skip to content

Commit 3efbbe8

Browse files
authored
Add ability to filter interpreted methods by assembly (#116569)
* Add ability to filter interpreted methods by assembly This change adds support for assembly name to the methodset stuff so that it can be used to select interpreted methods or methods to generate interpreter compilation dump for. To preserve parity, I've made the same change to the JIT's version of the same functionality. This change is a prerequisity for an upcoming change that enables running coreclr tests interpreted. * PR feedback - added docs and fixed indentation
1 parent c0d033a commit 3efbbe8

File tree

10 files changed

+71
-15
lines changed

10 files changed

+71
-15
lines changed

docs/design/coreclr/jit/viewing-jit-dumps.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ Some environment variables such as `DOTNET_JitDisasm` take a list of patterns sp
172172
+ The simplest method list is a single method name specified using just the method name (no class name), e.g. `Main`.
173173
+ A list of simple method names can be used, e.g., `Main Test1 Test2`.
174174
* The string matched against depends on characters in the pattern:
175+
+ If the pattern contains a '!' character, the string matched against is prefixed by the assembly name and an exclamation mark.
176+
- Example: `testassembly!*` - specifies all methods from the assembly named `testassembly`.
175177
+ If the pattern contains a ':' character, the string matched against is prefixed by the class name and a colon.
176178
- Example: `TestClass:Main` - specifies a single method named `Main` in the class named `TestClass`.
177179
+ If the pattern contains a '(' character, the string matched against is suffixed by the signature.

src/coreclr/interpreter/compiler.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,6 +1199,8 @@ InterpCompiler::InterpCompiler(COMP_HANDLE compHnd,
11991199
m_classHnd = compHnd->getMethodClass(m_methodHnd);
12001200

12011201
m_methodName = ::PrintMethodName(compHnd, m_classHnd, m_methodHnd, &m_methodInfo->args,
1202+
/* includeAssembly */ false,
1203+
/* includeClass */ true,
12021204
/* includeClassInstantiation */ true,
12031205
/* includeMethodInstantiation */ true,
12041206
/* includeSignature */ true,
@@ -5155,6 +5157,8 @@ void InterpCompiler::PrintMethodName(CORINFO_METHOD_HANDLE method)
51555157
m_compHnd->getMethodSig(method, &sig, cls);
51565158

51575159
TArray<char> methodName = ::PrintMethodName(m_compHnd, cls, method, &sig,
5160+
/* includeAssembly */ false,
5161+
/* includeClass */ false,
51585162
/* includeClassInstantiation */ true,
51595163
/* includeMethodInstantiation */ true,
51605164
/* includeSignature */ true,

src/coreclr/interpreter/compiler.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ TArray<char> PrintMethodName(COMP_HANDLE comp,
1212
CORINFO_CLASS_HANDLE clsHnd,
1313
CORINFO_METHOD_HANDLE methHnd,
1414
CORINFO_SIG_INFO* sig,
15+
bool includeAssembly,
16+
bool includeClass,
1517
bool includeClassInstantiation,
1618
bool includeMethodInstantiation,
1719
bool includeSignature,

src/coreclr/interpreter/interpretershared.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ class MethodSet
8282
bool m_classNameContainsInstantiation;
8383
bool m_methodNameContainsInstantiation;
8484
bool m_containsSignature;
85+
bool m_containsAssemblyName;
8586
};
8687

8788
const char* m_listFromConfig = nullptr;

src/coreclr/interpreter/methodset.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,18 @@ void MethodSet::initialize(const char* listFromConfig)
4040
name->m_next = m_names;
4141
name->m_patternStart = start;
4242
name->m_patternEnd = end;
43-
const char* colon = static_cast<const char*>(memchr(start, ':', end - start));
44-
const char* startOfMethodName = colon != nullptr ? colon + 1 : start;
43+
const char* exclamation = static_cast<const char*>(memchr(start, '!', end - start));
44+
const char* startOfClassName = exclamation != nullptr ? exclamation + 1 : start;
45+
const char* colon = static_cast<const char*>(memchr(startOfClassName, ':', end - startOfClassName));
46+
const char* startOfMethodName = colon != nullptr ? colon + 1 : startOfClassName;
4547

4648
const char* parens = static_cast<const char*>(memchr(startOfMethodName, '(', end - startOfMethodName));
4749
const char* endOfMethodName = parens != nullptr ? parens : end;
4850
name->m_methodNameContainsInstantiation =
4951
memchr(startOfMethodName, '[', endOfMethodName - startOfMethodName) != nullptr;
5052

53+
name->m_containsAssemblyName = (exclamation != nullptr);
54+
5155
if (colon != nullptr)
5256
{
5357
name->m_containsClassName = true;
@@ -156,12 +160,16 @@ bool MethodSet::contains(COMP_HANDLE comp,
156160

157161
for (MethodName* name = m_names; name != nullptr; name = name->m_next)
158162
{
159-
if ((prevPattern == nullptr) || (name->m_containsClassName != prevPattern->m_containsClassName) ||
163+
if ((prevPattern == nullptr) ||
164+
(name->m_containsAssemblyName != prevPattern->m_containsAssemblyName) ||
165+
(name->m_containsClassName != prevPattern->m_containsClassName) ||
160166
(name->m_classNameContainsInstantiation != prevPattern->m_classNameContainsInstantiation) ||
161167
(name->m_methodNameContainsInstantiation != prevPattern->m_methodNameContainsInstantiation) ||
162168
(name->m_containsSignature != prevPattern->m_containsSignature))
163169
{
164-
printer = PrintMethodName(comp, name->m_containsClassName ? classHnd : NO_CLASS_HANDLE, methodHnd, sigInfo,
170+
printer = PrintMethodName(comp, classHnd, methodHnd, sigInfo,
171+
/* includeAssembly */ name->m_containsAssemblyName,
172+
/* includeClass */ name->m_containsClassName,
165173
/* includeClassInstantiation */ name->m_classNameContainsInstantiation,
166174
/* includeMethodInstantiation */ name->m_methodNameContainsInstantiation,
167175
/* includeSignature */ name->m_containsSignature,

src/coreclr/interpreter/naming.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ void AppendType(COMP_HANDLE comp, TArray<char>* printer, CORINFO_CLASS_HANDLE cl
77
void AppendCorInfoType(TArray<char>* printer, CorInfoType corInfoType);
88
void AppendTypeOrJitAlias(COMP_HANDLE comp, TArray<char>* printer, CORINFO_CLASS_HANDLE clsHnd, bool includeInstantiation);
99

10-
void AppendString(TArray<char>& array, const char* str)
10+
void AppendString(TArray<char>* array, const char* str)
1111
{
1212
if (str != nullptr)
1313
{
1414
size_t strLen = strlen(str);
15-
array.Append(str, static_cast<int32_t>(strLen));
15+
array->Append(str, static_cast<int32_t>(strLen));
1616
}
1717
}
1818

@@ -145,6 +145,8 @@ void AppendMethodName(COMP_HANDLE comp,
145145
CORINFO_CLASS_HANDLE clsHnd,
146146
CORINFO_METHOD_HANDLE methHnd,
147147
CORINFO_SIG_INFO* sig,
148+
bool includeAssembly,
149+
bool includeClass,
148150
bool includeClassInstantiation,
149151
bool includeMethodInstantiation,
150152
bool includeSignature,
@@ -153,7 +155,14 @@ void AppendMethodName(COMP_HANDLE comp,
153155
{
154156
TArray<char> result;
155157

156-
if (clsHnd != NO_CLASS_HANDLE)
158+
if (includeAssembly)
159+
{
160+
const char *pAssemblyName = comp->getClassAssemblyName(clsHnd);
161+
AppendString(printer, pAssemblyName);
162+
printer->Add('!');
163+
}
164+
165+
if (includeClass)
157166
{
158167
AppendType(comp, printer, clsHnd, includeClassInstantiation);
159168
printer->Add(':');
@@ -268,6 +277,8 @@ TArray<char> PrintMethodName(COMP_HANDLE comp,
268277
CORINFO_CLASS_HANDLE clsHnd,
269278
CORINFO_METHOD_HANDLE methHnd,
270279
CORINFO_SIG_INFO* sig,
280+
bool includeAssembly,
281+
bool includeClass,
271282
bool includeClassInstantiation,
272283
bool includeMethodInstantiation,
273284
bool includeSignature,
@@ -276,6 +287,7 @@ TArray<char> PrintMethodName(COMP_HANDLE comp,
276287
{
277288
TArray<char> printer;
278289
AppendMethodName(comp, &printer, clsHnd, methHnd, sig,
290+
includeAssembly, includeClass,
279291
includeClassInstantiation, includeMethodInstantiation,
280292
includeSignature, includeReturnType, includeThisSpecifier);
281293
printer.Add('\0'); // Ensure null-termination

src/coreclr/jit/compiler.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8323,6 +8323,8 @@ class Compiler
83238323
CORINFO_CLASS_HANDLE clsHnd,
83248324
CORINFO_METHOD_HANDLE methodHnd,
83258325
CORINFO_SIG_INFO* sig,
8326+
bool includeAssembly,
8327+
bool includeClass,
83268328
bool includeClassInstantiation,
83278329
bool includeMethodInstantiation,
83288330
bool includeSignature,

src/coreclr/jit/eeinterface.cpp

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,9 +248,11 @@ void AppendCorInfoTypeWithModModifiers(StringPrinter* printer, CorInfoTypeWithMo
248248
//
249249
// Arguments:
250250
// printer - the printer
251-
// clsHnd - Handle for the owning class, or NO_CLASS_HANDLE to not print the class.
251+
// clsHnd - Handle for the owning class.
252252
// sig - The signature of the method.
253-
// includeClassInstantiation - Whether to print the class instantiation. Only valid when clsHnd is passed.
253+
// includeAssembly - Whether to print the assembly name.
254+
// includeClass - Whether to print the class name.
255+
// includeClassInstantiation - Whether to print the class instantiation. Only valid when includeClass is passed.
254256
// includeMethodInstantiation - Whether to print the method instantiation. Requires the signature to be passed.
255257
// includeSignature - Whether to print the signature.
256258
// includeReturnType - Whether to include the return type at the end.
@@ -261,6 +263,8 @@ void Compiler::eePrintMethod(StringPrinter* printer,
261263
CORINFO_CLASS_HANDLE clsHnd,
262264
CORINFO_METHOD_HANDLE methHnd,
263265
CORINFO_SIG_INFO* sig,
266+
bool includeAssembly,
267+
bool includeClass,
264268
bool includeClassInstantiation,
265269
bool includeMethodInstantiation,
266270
bool includeSignature,
@@ -275,7 +279,14 @@ void Compiler::eePrintMethod(StringPrinter* printer,
275279
return;
276280
}
277281

278-
if (clsHnd != NO_CLASS_HANDLE)
282+
if (includeAssembly)
283+
{
284+
const char* pAssemblyName = info.compCompHnd->getClassAssemblyName(clsHnd);
285+
printer->Append(pAssemblyName);
286+
printer->Append('!');
287+
}
288+
289+
if (includeClass)
279290
{
280291
eePrintType(printer, clsHnd, includeClassInstantiation);
281292
printer->Append(':');
@@ -432,6 +443,8 @@ const char* Compiler::eeGetMethodFullName(
432443
CORINFO_SIG_INFO sig;
433444
eeGetMethodSig(hnd, &sig);
434445
eePrintMethod(&p, clsHnd, hnd, &sig,
446+
/* includeAssembly */ false,
447+
/* includeClass */ true,
435448
/* includeClassInstantiation */ true,
436449
/* includeMethodInstantiation */ true,
437450
/* includeSignature */ true, includeReturnType, includeThisSpecifier);
@@ -448,6 +461,8 @@ const char* Compiler::eeGetMethodFullName(
448461
success = eeRunFunctorWithSPMIErrorTrap([&]() {
449462
eePrintMethod(&p, clsHnd, hnd,
450463
/* sig */ nullptr,
464+
/* includeAssembly */ false,
465+
/* includeClass */ true,
451466
/* includeClassInstantiation */ false,
452467
/* includeMethodInstantiation */ false,
453468
/* includeSignature */ false,
@@ -464,8 +479,10 @@ const char* Compiler::eeGetMethodFullName(
464479
p.Truncate(0);
465480

466481
success = eeRunFunctorWithSPMIErrorTrap([&]() {
467-
eePrintMethod(&p, nullptr, hnd,
482+
eePrintMethod(&p, NO_CLASS_HANDLE, hnd,
468483
/* sig */ nullptr,
484+
/* includeAssembly */ false,
485+
/* includeClass */ false,
469486
/* includeClassInstantiation */ false,
470487
/* includeMethodInstantiation */ false,
471488
/* includeSignature */ false,
@@ -504,6 +521,8 @@ const char* Compiler::eeGetMethodName(CORINFO_METHOD_HANDLE methHnd, char* buffe
504521
bool success = eeRunFunctorWithSPMIErrorTrap([&]() {
505522
eePrintMethod(&p, NO_CLASS_HANDLE, methHnd,
506523
/* sig */ nullptr,
524+
/* includeAssembly */ false,
525+
/* includeClass */ false,
507526
/* includeClassInstantiation */ false,
508527
/* includeMethodInstantiation */ false,
509528
/* includeSignature */ false,

src/coreclr/jit/jitconfig.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,18 @@ void JitConfigValues::MethodSet::initialize(const char* listFromConfig, ICorJitH
4040
name->m_next = m_names;
4141
name->m_patternStart = start;
4242
name->m_patternEnd = end;
43-
const char* colon = static_cast<const char*>(memchr(start, ':', end - start));
44-
const char* startOfMethodName = colon != nullptr ? colon + 1 : start;
43+
const char* exclamation = static_cast<const char*>(memchr(start, '!', end - start));
44+
const char* startOfClassName = exclamation != nullptr ? exclamation + 1 : start;
45+
const char* colon = static_cast<const char*>(memchr(startOfClassName, ':', end - startOfClassName));
46+
const char* startOfMethodName = colon != nullptr ? colon + 1 : startOfClassName;
4547

4648
const char* parens = static_cast<const char*>(memchr(startOfMethodName, '(', end - startOfMethodName));
4749
const char* endOfMethodName = parens != nullptr ? parens : end;
4850
name->m_methodNameContainsInstantiation =
4951
memchr(startOfMethodName, '[', endOfMethodName - startOfMethodName) != nullptr;
5052

53+
name->m_containsAssemblyName = (exclamation != nullptr);
54+
5155
if (colon != nullptr)
5256
{
5357
name->m_containsClassName = true;
@@ -164,8 +168,9 @@ bool JitConfigValues::MethodSet::contains(CORINFO_METHOD_HANDLE methodHnd,
164168
{
165169
printer.Truncate(0);
166170
bool success = comp->eeRunFunctorWithSPMIErrorTrap([&]() {
167-
comp->eePrintMethod(&printer, name->m_containsClassName ? classHnd : NO_CLASS_HANDLE, methodHnd,
168-
sigInfo,
171+
comp->eePrintMethod(&printer, classHnd, methodHnd, sigInfo,
172+
/* includeAssembly */ name->m_containsAssemblyName,
173+
/* includeClass */ name->m_containsClassName,
169174
/* includeClassInstantiation */ name->m_classNameContainsInstantiation,
170175
/* includeMethodInstantiation */ name->m_methodNameContainsInstantiation,
171176
/* includeSignature */ name->m_containsSignature,

src/coreclr/jit/jitconfig.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class JitConfigValues
2222
MethodName* m_next;
2323
const char* m_patternStart;
2424
const char* m_patternEnd;
25+
bool m_containsAssemblyName;
2526
bool m_containsClassName;
2627
bool m_classNameContainsInstantiation;
2728
bool m_methodNameContainsInstantiation;

0 commit comments

Comments
 (0)