Skip to content

Commit 7d68c7f

Browse files
hez2010jkotas
andauthored
Implement getClassAssemblyName (dotnet#106959)
* Add getClassAssemblyName * Handle nullptrs * Remove CORINFO_ASSEMBLY_HANDLE * Address feedbacks Co-authored-by: Jan Kotas <[email protected]>
1 parent 39c84a3 commit 7d68c7f

File tree

21 files changed

+256
-491
lines changed

21 files changed

+256
-491
lines changed

src/coreclr/inc/corinfo.h

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

933-
typedef struct CORINFO_ASSEMBLY_STRUCT_* CORINFO_ASSEMBLY_HANDLE;
934933
typedef struct CORINFO_MODULE_STRUCT_* CORINFO_MODULE_HANDLE;
935934
typedef struct CORINFO_DEPENDENCY_STRUCT_* CORINFO_DEPENDENCY_HANDLE;
936935
typedef struct CORINFO_CLASS_STRUCT_* CORINFO_CLASS_HANDLE;
@@ -2321,18 +2320,9 @@ class ICorStaticInfo
23212320
CORINFO_CLASS_HANDLE cls
23222321
) = 0;
23232322

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

23382328
// 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 = { /* 7f7fd340-4779-455a-8046-628f3cd8c3c7 */
47-
0x7f7fd340,
48-
0x4779,
49-
0x455a,
50-
{0x80, 0x46, 0x62, 0x8f, 0x3c, 0xd8, 0xc3, 0xc7}
46+
constexpr GUID JITEEVersionIdentifier = { /* b75a5475-ff22-4078-9551-2024ce03d383 */
47+
0xb75a5475,
48+
0xff22,
49+
0x4078,
50+
{0x95, 0x51, 0x20, 0x24, 0xce, 0x03, 0xd3, 0x83}
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
@@ -2586,8 +2586,7 @@ void Compiler::compInitOptions(JitFlags* jitFlags)
25862586
// We have an exclusion list. See if this method is in an assembly that is on the list.
25872587
// Note that we check this for every method, since we might inline across modules, and
25882588
// if the inlinee module is on the list, we don't want to use the altjit for it.
2589-
const char* methodAssemblyName = info.compCompHnd->getAssemblyName(
2590-
info.compCompHnd->getModuleAssembly(info.compCompHnd->getClassModule(info.compClassHnd)));
2589+
const char* methodAssemblyName = eeGetClassAssemblyName(info.compClassHnd);
25912590
if (s_pAltJitExcludeAssembliesList->IsInList(methodAssemblyName))
25922591
{
25932592
opts.altJit = false;
@@ -2614,8 +2613,7 @@ void Compiler::compInitOptions(JitFlags* jitFlags)
26142613
bool assemblyInIncludeList = true; // assume we'll dump, if there's not an include list (or it's empty).
26152614
if (s_pJitDisasmIncludeAssembliesList != nullptr && !s_pJitDisasmIncludeAssembliesList->IsEmpty())
26162615
{
2617-
const char* assemblyName = info.compCompHnd->getAssemblyName(
2618-
info.compCompHnd->getModuleAssembly(info.compCompHnd->getClassModule(info.compClassHnd)));
2616+
const char* assemblyName = eeGetClassAssemblyName(info.compClassHnd);
26192617
if (!s_pJitDisasmIncludeAssembliesList->IsInList(assemblyName))
26202618
{
26212619
// We have a list, and the current assembly is not in it, so we won't dump.
@@ -6335,39 +6333,29 @@ int Compiler::compCompile(CORINFO_MODULE_HANDLE classPtr,
63356333
#ifdef DEBUG
63366334
if (JitConfig.EnableExtraSuperPmiQueries())
63376335
{
6338-
// This call to getClassModule/getModuleAssembly/getAssemblyName fails in crossgen2 due to these
6339-
// APIs being unimplemented. So disable this extra info for pre-jit mode. See
6340-
// https://github.com/dotnet/runtime/issues/48888.
6341-
//
6342-
// Ditto for some of the class name queries for generic params.
6343-
//
6344-
if (!compileFlags->IsSet(JitFlags::JIT_FLAG_PREJIT))
6345-
{
6346-
// Get the assembly name, to aid finding any particular SuperPMI method context function
6347-
(void)info.compCompHnd->getAssemblyName(
6348-
info.compCompHnd->getModuleAssembly(info.compCompHnd->getClassModule(info.compClassHnd)));
6336+
// Get the assembly name, to aid finding any particular SuperPMI method context function
6337+
(void)eeGetClassAssemblyName(info.compClassHnd);
63496338

6350-
// Fetch class names for the method's generic parameters.
6351-
//
6352-
CORINFO_SIG_INFO sig;
6353-
info.compCompHnd->getMethodSig(info.compMethodHnd, &sig, nullptr);
6339+
// Fetch class names for the method's generic parameters.
6340+
//
6341+
CORINFO_SIG_INFO sig;
6342+
info.compCompHnd->getMethodSig(info.compMethodHnd, &sig, nullptr);
63546343

6355-
const unsigned classInst = sig.sigInst.classInstCount;
6356-
if (classInst > 0)
6344+
const unsigned classInst = sig.sigInst.classInstCount;
6345+
if (classInst > 0)
6346+
{
6347+
for (unsigned i = 0; i < classInst; i++)
63576348
{
6358-
for (unsigned i = 0; i < classInst; i++)
6359-
{
6360-
eeGetClassName(sig.sigInst.classInst[i]);
6361-
}
6349+
eeGetClassName(sig.sigInst.classInst[i]);
63626350
}
6351+
}
63636352

6364-
const unsigned methodInst = sig.sigInst.methInstCount;
6365-
if (methodInst > 0)
6353+
const unsigned methodInst = sig.sigInst.methInstCount;
6354+
if (methodInst > 0)
6355+
{
6356+
for (unsigned i = 0; i < methodInst; i++)
63666357
{
6367-
for (unsigned i = 0; i < methodInst; i++)
6368-
{
6369-
eeGetClassName(sig.sigInst.methInst[i]);
6370-
}
6358+
eeGetClassName(sig.sigInst.methInst[i]);
63716359
}
63726360
}
63736361
}
@@ -9221,8 +9209,7 @@ void JitTimer::PrintCsvMethodStats(Compiler* comp)
92219209
}
92229210
else
92239211
{
9224-
const char* methodAssemblyName = comp->info.compCompHnd->getAssemblyName(
9225-
comp->info.compCompHnd->getModuleAssembly(comp->info.compCompHnd->getClassModule(comp->info.compClassHnd)));
9212+
const char* methodAssemblyName = comp->eeGetClassAssemblyName(comp->info.compClassHnd);
92269213
fprintf(s_csvFile, "\"%s\",", methodAssemblyName);
92279214
}
92289215
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
@@ -8337,6 +8337,8 @@ class Compiler
83378337
void eePrintObjectDescription(const char* prefix, CORINFO_OBJECT_HANDLE handle);
83388338
const char* eeGetShortClassName(CORINFO_CLASS_HANDLE clsHnd);
83398339

8340+
const char* eeGetClassAssemblyName(CORINFO_CLASS_HANDLE clsHnd);
8341+
83408342
#if defined(DEBUG)
83418343
unsigned eeTryGetClassSize(CORINFO_CLASS_HANDLE clsHnd);
83428344
#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)