Skip to content

Commit 05d54b6

Browse files
hez2010jkotas
andauthored
Implement getClassAssemblyName (#106959) (#107516)
* Add getClassAssemblyName * Handle nullptrs * Remove CORINFO_ASSEMBLY_HANDLE * Address feedbacks Co-authored-by: Jan Kotas <jkotas@microsoft.com>
1 parent d30807e commit 05d54b6

File tree

21 files changed

+256
-490
lines changed

21 files changed

+256
-490
lines changed

src/coreclr/inc/corinfo.h

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -933,7 +933,6 @@ struct PatchpointInfo;
933933
// Cookie types consumed by the code generator (these are opaque values
934934
// not inspected by the code generator):
935935

936-
typedef struct CORINFO_ASSEMBLY_STRUCT_* CORINFO_ASSEMBLY_HANDLE;
937936
typedef struct CORINFO_MODULE_STRUCT_* CORINFO_MODULE_HANDLE;
938937
typedef struct CORINFO_DEPENDENCY_STRUCT_* CORINFO_DEPENDENCY_HANDLE;
939938
typedef struct CORINFO_CLASS_STRUCT_* CORINFO_CLASS_HANDLE;
@@ -2324,18 +2323,9 @@ class ICorStaticInfo
23242323
CORINFO_CLASS_HANDLE cls
23252324
) = 0;
23262325

2327-
virtual CORINFO_MODULE_HANDLE getClassModule (
2328-
CORINFO_CLASS_HANDLE cls
2329-
) = 0;
2330-
2331-
// Returns the assembly that contains the module "mod".
2332-
virtual CORINFO_ASSEMBLY_HANDLE getModuleAssembly (
2333-
CORINFO_MODULE_HANDLE mod
2334-
) = 0;
2335-
2336-
// Returns the name of the assembly "assem".
2337-
virtual const char* getAssemblyName (
2338-
CORINFO_ASSEMBLY_HANDLE assem
2326+
// Returns the assembly name of the class "cls", or nullptr if there is none.
2327+
virtual const char* getClassAssemblyName (
2328+
CORINFO_CLASS_HANDLE cls
23392329
) = 0;
23402330

23412331
// Allocate and delete process-lifetime objects. Should only be

src/coreclr/inc/icorjitinfoimpl_generated.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -193,15 +193,9 @@ bool isValueClass(
193193
uint32_t getClassAttribs(
194194
CORINFO_CLASS_HANDLE cls) override;
195195

196-
CORINFO_MODULE_HANDLE getClassModule(
196+
const char* getClassAssemblyName(
197197
CORINFO_CLASS_HANDLE cls) override;
198198

199-
CORINFO_ASSEMBLY_HANDLE getModuleAssembly(
200-
CORINFO_MODULE_HANDLE mod) override;
201-
202-
const char* getAssemblyName(
203-
CORINFO_ASSEMBLY_HANDLE assem) override;
204-
205199
void* LongLifetimeMalloc(
206200
size_t sz) override;
207201

src/coreclr/inc/jiteeversionguid.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ typedef const GUID *LPCGUID;
4343
#define GUID_DEFINED
4444
#endif // !GUID_DEFINED
4545

46-
constexpr GUID JITEEVersionIdentifier = { /* f43f9022-8795-4791-ba55-c450d76cfeb9 */
47-
0xf43f9022,
48-
0x8795,
49-
0x4791,
50-
{0xba, 0x55, 0xc4, 0x50, 0xd7, 0x6c, 0xfe, 0xb9}
46+
constexpr GUID JITEEVersionIdentifier = { /* d6218a78-9a34-4c6f-8db5-077a06022fae */
47+
0xd6218a78,
48+
0x9a34,
49+
0x4c6f,
50+
{0x8d, 0xb5, 0x07, 0x7a, 0x06, 0x02, 0x2f, 0xae}
5151
};
5252

5353
//////////////////////////////////////////////////////////////////////////////////////////////////////////

src/coreclr/jit/ICorJitInfo_names_generated.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,7 @@ DEF_CLR_API(getTypeInstantiationArgument)
4545
DEF_CLR_API(printClassName)
4646
DEF_CLR_API(isValueClass)
4747
DEF_CLR_API(getClassAttribs)
48-
DEF_CLR_API(getClassModule)
49-
DEF_CLR_API(getModuleAssembly)
50-
DEF_CLR_API(getAssemblyName)
48+
DEF_CLR_API(getClassAssemblyName)
5149
DEF_CLR_API(LongLifetimeMalloc)
5250
DEF_CLR_API(LongLifetimeFree)
5351
DEF_CLR_API(getIsClassInitedFlagAddress)

src/coreclr/jit/ICorJitInfo_wrapper_generated.hpp

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -416,30 +416,12 @@ uint32_t WrapICorJitInfo::getClassAttribs(
416416
return temp;
417417
}
418418

419-
CORINFO_MODULE_HANDLE WrapICorJitInfo::getClassModule(
419+
const char* WrapICorJitInfo::getClassAssemblyName(
420420
CORINFO_CLASS_HANDLE cls)
421421
{
422-
API_ENTER(getClassModule);
423-
CORINFO_MODULE_HANDLE temp = wrapHnd->getClassModule(cls);
424-
API_LEAVE(getClassModule);
425-
return temp;
426-
}
427-
428-
CORINFO_ASSEMBLY_HANDLE WrapICorJitInfo::getModuleAssembly(
429-
CORINFO_MODULE_HANDLE mod)
430-
{
431-
API_ENTER(getModuleAssembly);
432-
CORINFO_ASSEMBLY_HANDLE temp = wrapHnd->getModuleAssembly(mod);
433-
API_LEAVE(getModuleAssembly);
434-
return temp;
435-
}
436-
437-
const char* WrapICorJitInfo::getAssemblyName(
438-
CORINFO_ASSEMBLY_HANDLE assem)
439-
{
440-
API_ENTER(getAssemblyName);
441-
const char* temp = wrapHnd->getAssemblyName(assem);
442-
API_LEAVE(getAssemblyName);
422+
API_ENTER(getClassAssemblyName);
423+
const char* temp = wrapHnd->getClassAssemblyName(cls);
424+
API_LEAVE(getClassAssemblyName);
443425
return temp;
444426
}
445427

src/coreclr/jit/compiler.cpp

Lines changed: 20 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2656,8 +2656,7 @@ void Compiler::compInitOptions(JitFlags* jitFlags)
26562656
// We have an exclusion list. See if this method is in an assembly that is on the list.
26572657
// Note that we check this for every method, since we might inline across modules, and
26582658
// if the inlinee module is on the list, we don't want to use the altjit for it.
2659-
const char* methodAssemblyName = info.compCompHnd->getAssemblyName(
2660-
info.compCompHnd->getModuleAssembly(info.compCompHnd->getClassModule(info.compClassHnd)));
2659+
const char* methodAssemblyName = eeGetClassAssemblyName(info.compClassHnd);
26612660
if (s_pAltJitExcludeAssembliesList->IsInList(methodAssemblyName))
26622661
{
26632662
opts.altJit = false;
@@ -2684,8 +2683,7 @@ void Compiler::compInitOptions(JitFlags* jitFlags)
26842683
bool assemblyInIncludeList = true; // assume we'll dump, if there's not an include list (or it's empty).
26852684
if (s_pJitDisasmIncludeAssembliesList != nullptr && !s_pJitDisasmIncludeAssembliesList->IsEmpty())
26862685
{
2687-
const char* assemblyName = info.compCompHnd->getAssemblyName(
2688-
info.compCompHnd->getModuleAssembly(info.compCompHnd->getClassModule(info.compClassHnd)));
2686+
const char* assemblyName = eeGetClassAssemblyName(info.compClassHnd);
26892687
if (!s_pJitDisasmIncludeAssembliesList->IsInList(assemblyName))
26902688
{
26912689
// We have a list, and the current assembly is not in it, so we won't dump.
@@ -6457,39 +6455,29 @@ int Compiler::compCompile(CORINFO_MODULE_HANDLE classPtr,
64576455
#ifdef DEBUG
64586456
if (JitConfig.EnableExtraSuperPmiQueries())
64596457
{
6460-
// This call to getClassModule/getModuleAssembly/getAssemblyName fails in crossgen2 due to these
6461-
// APIs being unimplemented. So disable this extra info for pre-jit mode. See
6462-
// https://github.com/dotnet/runtime/issues/48888.
6463-
//
6464-
// Ditto for some of the class name queries for generic params.
6465-
//
6466-
if (!compileFlags->IsSet(JitFlags::JIT_FLAG_PREJIT))
6467-
{
6468-
// Get the assembly name, to aid finding any particular SuperPMI method context function
6469-
(void)info.compCompHnd->getAssemblyName(
6470-
info.compCompHnd->getModuleAssembly(info.compCompHnd->getClassModule(info.compClassHnd)));
6458+
// Get the assembly name, to aid finding any particular SuperPMI method context function
6459+
(void)eeGetClassAssemblyName(info.compClassHnd);
64716460

6472-
// Fetch class names for the method's generic parameters.
6473-
//
6474-
CORINFO_SIG_INFO sig;
6475-
info.compCompHnd->getMethodSig(info.compMethodHnd, &sig, nullptr);
6461+
// Fetch class names for the method's generic parameters.
6462+
//
6463+
CORINFO_SIG_INFO sig;
6464+
info.compCompHnd->getMethodSig(info.compMethodHnd, &sig, nullptr);
64766465

6477-
const unsigned classInst = sig.sigInst.classInstCount;
6478-
if (classInst > 0)
6466+
const unsigned classInst = sig.sigInst.classInstCount;
6467+
if (classInst > 0)
6468+
{
6469+
for (unsigned i = 0; i < classInst; i++)
64796470
{
6480-
for (unsigned i = 0; i < classInst; i++)
6481-
{
6482-
eeGetClassName(sig.sigInst.classInst[i]);
6483-
}
6471+
eeGetClassName(sig.sigInst.classInst[i]);
64846472
}
6473+
}
64856474

6486-
const unsigned methodInst = sig.sigInst.methInstCount;
6487-
if (methodInst > 0)
6475+
const unsigned methodInst = sig.sigInst.methInstCount;
6476+
if (methodInst > 0)
6477+
{
6478+
for (unsigned i = 0; i < methodInst; i++)
64886479
{
6489-
for (unsigned i = 0; i < methodInst; i++)
6490-
{
6491-
eeGetClassName(sig.sigInst.methInst[i]);
6492-
}
6480+
eeGetClassName(sig.sigInst.methInst[i]);
64936481
}
64946482
}
64956483
}
@@ -9379,8 +9367,7 @@ void JitTimer::PrintCsvMethodStats(Compiler* comp)
93799367
}
93809368
else
93819369
{
9382-
const char* methodAssemblyName = comp->info.compCompHnd->getAssemblyName(
9383-
comp->info.compCompHnd->getModuleAssembly(comp->info.compCompHnd->getClassModule(comp->info.compClassHnd)));
9370+
const char* methodAssemblyName = comp->eeGetClassAssemblyName(comp->info.compClassHnd);
93849371
fprintf(s_csvFile, "\"%s\",", methodAssemblyName);
93859372
}
93869373
fprintf(s_csvFile, "%u,", comp->info.compILCodeSize);

src/coreclr/jit/compiler.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8306,6 +8306,8 @@ class Compiler
83068306
void eePrintObjectDescription(const char* prefix, CORINFO_OBJECT_HANDLE handle);
83078307
const char* eeGetShortClassName(CORINFO_CLASS_HANDLE clsHnd);
83088308

8309+
const char* eeGetClassAssemblyName(CORINFO_CLASS_HANDLE clsHnd);
8310+
83098311
#if defined(DEBUG)
83108312
unsigned eeTryGetClassSize(CORINFO_CLASS_HANDLE clsHnd);
83118313
#endif

src/coreclr/jit/eeinterface.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,27 @@ const char* Compiler::eeGetShortClassName(CORINFO_CLASS_HANDLE clsHnd)
596596
return printer.GetBuffer();
597597
}
598598

599+
//------------------------------------------------------------------------
600+
// eeGetClassAssemblyName:
601+
// Get the assembly name of a type.
602+
// If missing information (in SPMI), then return a placeholder string.
603+
//
604+
// Parameters:
605+
// clsHnd - the handle of the class
606+
//
607+
// Return value:
608+
// The name string.
609+
//
610+
const char* Compiler::eeGetClassAssemblyName(CORINFO_CLASS_HANDLE clsHnd)
611+
{
612+
const char* assemblyName = "<unknown assembly>";
613+
eeRunFunctorWithSPMIErrorTrap([&]() {
614+
assemblyName = info.compCompHnd->getClassAssemblyName(clsHnd);
615+
});
616+
617+
return assemblyName != nullptr ? assemblyName : "<no assembly>";
618+
}
619+
599620
void Compiler::eePrintObjectDescription(const char* prefix, CORINFO_OBJECT_HANDLE handle)
600621
{
601622
const size_t maxStrSize = 64;

src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2092,12 +2092,17 @@ private uint getClassAttribsInternal(TypeDesc type)
20922092
return (uint)result;
20932093
}
20942094

2095-
private CORINFO_MODULE_STRUCT_* getClassModule(CORINFO_CLASS_STRUCT_* cls)
2096-
{ throw new NotImplementedException("getClassModule"); }
2097-
private CORINFO_ASSEMBLY_STRUCT_* getModuleAssembly(CORINFO_MODULE_STRUCT_* mod)
2098-
{ throw new NotImplementedException("getModuleAssembly"); }
2099-
private byte* getAssemblyName(CORINFO_ASSEMBLY_STRUCT_* assem)
2100-
{ throw new NotImplementedException("getAssemblyName"); }
2095+
private byte* getClassAssemblyName(CORINFO_CLASS_STRUCT_* cls)
2096+
{
2097+
TypeDesc type = HandleToObject(cls);
2098+
2099+
if (type is MetadataType mdType)
2100+
{
2101+
return (byte*)GetPin(StringToUTF8(mdType.Module.Assembly.GetName().Name));
2102+
}
2103+
2104+
return null;
2105+
}
21012106

21022107
#pragma warning disable CA1822 // Mark members as static
21032108
private void* LongLifetimeMalloc(UIntPtr sz)

0 commit comments

Comments
 (0)