Skip to content

Commit 0953757

Browse files
authored
Cache the path on Module for easier diagnostics (#106103)
- Make `PEImage` take a path in its constructor and make its member const - Store the path when initializing `Module` This will let us avoid having to expose PEAssembly/PEImage in data descriptors to the cDAC just to get the module path.
1 parent 2ae5d7a commit 0953757

6 files changed

Lines changed: 30 additions & 22 deletions

File tree

src/coreclr/inc/sstring.inl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,9 @@ inline SString::SString(const WCHAR *string)
231231

232232
Set(string);
233233

234+
_ASSERTE(IsRepresentation(REPRESENTATION_UNICODE));
235+
SetNormalized();
236+
234237
SS_RETURN;
235238
}
236239

@@ -249,6 +252,9 @@ inline SString::SString(const WCHAR *string, COUNT_T count)
249252

250253
Set(string, count);
251254

255+
_ASSERTE(IsRepresentation(REPRESENTATION_UNICODE));
256+
SetNormalized();
257+
252258
SS_RETURN;
253259
}
254260

src/coreclr/vm/ceeload.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,8 @@ void Module::Initialize(AllocMemTracker *pamTracker, LPCWSTR szName)
414414

415415
m_loaderAllocator = GetAssembly()->GetLoaderAllocator();
416416
m_pSimpleName = m_pPEAssembly->GetSimpleName();
417+
m_path = m_pPEAssembly->GetPath().GetUnicode();
418+
_ASSERTE(m_path != NULL);
417419
m_baseAddress = m_pPEAssembly->HasLoadedPEImage() ? m_pPEAssembly->GetLoadedLayout()->GetBase() : NULL;
418420
if (m_pPEAssembly->IsReflectionEmit())
419421
m_dwTransientFlags |= IS_REFLECTION_EMIT;

src/coreclr/vm/ceeload.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,9 @@
4343
#include "ilinstrumentation.h"
4444
#include "codeversion.h"
4545

46-
class Stub;
4746
class MethodDesc;
4847
class FieldDesc;
4948
class Crst;
50-
class ClassConverter;
5149
class RefClassWriter;
5250
class ReflectionModule;
5351
class EEStringData;
@@ -56,11 +54,9 @@ class SigTypeContext;
5654
class Assembly;
5755
class BaseDomain;
5856
class AppDomain;
59-
class DomainModule;
6057
class SystemDomain;
6158
class Module;
6259
class SString;
63-
class Pending;
6460
class MethodTable;
6561
class DynamicMethodTable;
6662
class TieredCompilationManager;
@@ -615,6 +611,7 @@ class Module : public ModuleBase
615611

616612
private:
617613
PTR_CUTF8 m_pSimpleName; // Cached simple name for better performance and easier diagnostics
614+
const WCHAR* m_path; // Cached path for easier diagnostics
618615

619616
PTR_PEAssembly m_pPEAssembly;
620617
PTR_VOID m_baseAddress; // Cached base address for easier diagnostics
@@ -1384,7 +1381,13 @@ class Module : public ModuleBase
13841381
}
13851382

13861383
HRESULT GetScopeName(LPCUTF8 * pszName) { WRAPPER_NO_CONTRACT; return m_pPEAssembly->GetScopeName(pszName); }
1387-
const SString &GetPath() { WRAPPER_NO_CONTRACT; return m_pPEAssembly->GetPath(); }
1384+
const SString &GetPath()
1385+
{
1386+
WRAPPER_NO_CONTRACT;
1387+
// Validate the pointers are the same to ensure the lifetime of m_path is handled.
1388+
_ASSERTE(m_path == m_pPEAssembly->GetPath().GetUnicode());
1389+
return m_pPEAssembly->GetPath();
1390+
}
13881391

13891392
#ifdef LOGGING
13901393
LPCUTF8 GetDebugName() { WRAPPER_NO_CONTRACT; return m_pPEAssembly->GetDebugName(); }

src/coreclr/vm/peimage.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -615,9 +615,8 @@ void PEImage::EnumMemoryRegions(CLRDataEnumMemoryFlags flags)
615615

616616
#endif // #ifdef DACCESS_COMPILE
617617

618-
619-
PEImage::PEImage():
620-
m_path(),
618+
PEImage::PEImage(const WCHAR* path):
619+
m_path{path},
621620
m_pathHash(0),
622621
m_refCount(1),
623622
m_bInHashMap(FALSE),
@@ -788,7 +787,7 @@ PTR_PEImage PEImage::CreateFromByteArray(const BYTE* array, COUNT_T size)
788787
}
789788
CONTRACT_END;
790789

791-
PEImageHolder pImage(new PEImage());
790+
PEImageHolder pImage(new PEImage(NULL /*path*/));
792791
PTR_PEImageLayout pLayout = PEImageLayout::CreateFromByteArray(pImage, array, size);
793792
_ASSERTE(!pLayout->IsMapped());
794793

src/coreclr/vm/peimage.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ class PEImage final
104104
static void Startup();
105105

106106
~PEImage();
107-
PEImage();
107+
explicit PEImage(const WCHAR* path);
108108

109109
BOOL Equals(PEImage* pImage);
110110

@@ -121,7 +121,7 @@ class PEImage final
121121
MDInternalImportFlags flags = MDInternalImport_Default,
122122
BundleFileLocation bundleFileLocation = BundleFileLocation::Invalid());
123123

124-
static PTR_PEImage FindByPath(LPCWSTR pPath, BOOL isInBundle = TRUE);
124+
static PTR_PEImage FindByPath(LPCWSTR pPath, BOOL isInBundle);
125125
void AddToHashMap();
126126
#endif
127127

@@ -206,7 +206,7 @@ class PEImage final
206206
// Private routines
207207
// ------------------------------------------------------------
208208

209-
void Init(LPCWSTR pPath, BundleFileLocation bundleFileLocation);
209+
void Init(BundleFileLocation bundleFileLocation);
210210

211211
struct PEImageLocator
212212
{
@@ -285,7 +285,7 @@ class PEImage final
285285
// Instance fields
286286
// ------------------------------------------------------------
287287

288-
SString m_path;
288+
const SString m_path;
289289
ULONG m_pathHash;
290290
LONG m_refCount;
291291

src/coreclr/vm/peimage.inl

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ inline CHECK PEImage::CheckFormat()
276276
CHECK_OK;
277277
}
278278

279-
inline void PEImage::Init(LPCWSTR pPath, BundleFileLocation bundleFileLocation)
279+
inline void PEImage::Init(BundleFileLocation bundleFileLocation)
280280
{
281281
CONTRACTL
282282
{
@@ -286,8 +286,6 @@ inline void PEImage::Init(LPCWSTR pPath, BundleFileLocation bundleFileLocation)
286286
}
287287
CONTRACTL_END;
288288

289-
m_path.Set(pPath);
290-
m_path.Normalize();
291289
m_pathHash = m_path.HashCaseInsensitive();
292290
m_bundleFileLocation = bundleFileLocation;
293291
SetModuleFileNameHintForDAC();
@@ -296,7 +294,7 @@ inline void PEImage::Init(LPCWSTR pPath, BundleFileLocation bundleFileLocation)
296294

297295

298296
/*static*/
299-
inline PTR_PEImage PEImage::FindByPath(LPCWSTR pPath, BOOL isInBundle /* = TRUE */)
297+
inline PTR_PEImage PEImage::FindByPath(LPCWSTR pPath, BOOL isInBundle)
300298
{
301299
CONTRACTL
302300
{
@@ -316,13 +314,13 @@ inline PTR_PEImage PEImage::FindByPath(LPCWSTR pPath, BOOL isInBundle /* = TRUE
316314
}
317315

318316
/* static */
319-
inline PTR_PEImage PEImage::OpenImage(LPCWSTR pPath, MDInternalImportFlags flags /* = MDInternalImport_Default */, BundleFileLocation bundleFileLocation)
317+
inline PTR_PEImage PEImage::OpenImage(LPCWSTR pPath, MDInternalImportFlags flags /* = MDInternalImport_Default */, BundleFileLocation bundleFileLocation /* = BundleFileLocation::Invalid() */)
320318
{
321319
BOOL forbidCache = (flags & MDInternalImport_NoCache);
322320
if (forbidCache)
323321
{
324-
PEImageHolder pImage(new PEImage);
325-
pImage->Init(pPath, bundleFileLocation);
322+
PEImageHolder pImage(new PEImage{pPath});
323+
pImage->Init(bundleFileLocation);
326324
return dac_cast<PTR_PEImage>(pImage.Extract());
327325
}
328326

@@ -337,8 +335,8 @@ inline PTR_PEImage PEImage::OpenImage(LPCWSTR pPath, MDInternalImportFlags flags
337335
return NULL;
338336
}
339337

340-
PEImageHolder pImage(new PEImage);
341-
pImage->Init(pPath, bundleFileLocation);
338+
PEImageHolder pImage(new PEImage{pPath});
339+
pImage->Init(bundleFileLocation);
342340

343341
pImage->AddToHashMap();
344342
return dac_cast<PTR_PEImage>(pImage.Extract());

0 commit comments

Comments
 (0)