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

Improve the hashtable for EEClassHash #94825

Merged
merged 15 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 6 additions & 0 deletions docs/design/specs/Ecma-335-Augments.md
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,12 @@ The text should be deleted:

> Furthermore, ~~the InterfaceImpl table is sorted using the Interface column as a secondary key, and~~ the GenericParam table is sorted using the Number column as a secondary key.

In addition to the TypeDef table having a special ordering constraint, the ExportedTypes table ALSO has the same constraint.

This line should be changed.

> Finally, this TypeDef _and ExportedType_ ~~table has~~ _tables have_ a special ordering constraint: the definition of an enclosing class shall precede the definition of all classes it encloses.

## Module Initializer

All modules may have a module initializer. A module initializer is defined as the type initializer (§ II.10.5.3) of the `<Module>` type (§ II.10.8).
Expand Down
11 changes: 4 additions & 7 deletions src/coreclr/inc/corhlprpriv.h
Original file line number Diff line number Diff line change
Expand Up @@ -294,15 +294,12 @@ class CQuickMemoryBase
}

// Copy single byte string and hold it
const char * SetStringNoThrow(const char * pStr, SIZE_T len)
const char * SetString(const char * pStr, SIZE_T len)
{
LPSTR buffer = (LPSTR) AllocNoThrow(len + 1);
LPSTR buffer = (LPSTR) AllocThrows(len + 1);
AaronRobinsonMSFT marked this conversation as resolved.
Show resolved Hide resolved

if (buffer != NULL)
{
memcpy(buffer, pStr, len);
buffer[len] = 0;
}
memcpy(buffer, pStr, len);
buffer[len] = 0;

return buffer;
}
Expand Down
21 changes: 0 additions & 21 deletions src/coreclr/vm/assembly.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,6 @@ void Assembly::Init(AllocMemTracker *pamTracker, LoaderAllocator *pLoaderAllocat

PrepareModuleForAssembly(m_pModule, pamTracker);

if (!m_pModule->IsReadyToRun())
CacheManifestExportedTypes(pamTracker);

// We'll load the friend assembly information lazily. For the ngen case we should avoid
// loading it entirely.
//CacheFriendAssemblyInfo();
Expand Down Expand Up @@ -952,24 +949,6 @@ Module * Assembly::FindModuleByTypeRef(

#ifndef DACCESS_COMPILE

void Assembly::CacheManifestExportedTypes(AllocMemTracker *pamTracker)
{
STANDARD_VM_CONTRACT;

mdToken mdExportedType;

HENUMInternalHolder phEnum(GetMDImport());
phEnum.EnumInit(mdtExportedType,
mdTokenNil);

ClassLoader::AvailableClasses_LockHolder lh(m_pClassLoader);

for(int i = 0; GetMDImport()->EnumNext(&phEnum, &mdExportedType); i++)
m_pClassLoader->AddExportedTypeHaveLock(GetModule(),
mdExportedType,
pamTracker);
}

void Assembly::PrepareModuleForAssembly(Module* module, AllocMemTracker *pamTracker)
{
STANDARD_VM_CONTRACT;
Expand Down
2 changes: 0 additions & 2 deletions src/coreclr/vm/assembly.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -416,8 +416,6 @@ class Assembly

//****************************************************************************************

void CacheManifestExportedTypes(AllocMemTracker *pamTracker);

void CacheFriendAssemblyInfo();
#ifndef DACCESS_COMPILE
ReleaseHolder<FriendAssemblyDescriptor> GetFriendAssemblyInfo();
Expand Down
38 changes: 36 additions & 2 deletions src/coreclr/vm/assemblynative.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,10 +362,27 @@ extern "C" void QCALLTYPE AssemblyNative_GetTypeCore(QCall::AssemblyHandle assem
ClassLoader* pClassLoader = pAssembly->GetLoader();

NameHandle typeName(pManifestModule, mdtBaseType);
CQuickBytes qbszNamespace;

for (int32_t i = -1; i < cNestedTypeNamesLength; i++)
{
typeName.SetName((i == -1) ? szTypeName : rgszNestedTypeNames[i]);
LPCUTF8 szFullyQualifiedName = (i == -1) ? szTypeName : rgszNestedTypeNames[i];

LPCUTF8 szNameSpace = "";
LPCUTF8 szName = "";

if ((szName = ns::FindSep(szFullyQualifiedName)) != NULL)
{
SIZE_T d = szName - szFullyQualifiedName;
szNameSpace = qbszNamespace.SetString(szFullyQualifiedName, d);
szName++;
}
else
{
szName = szFullyQualifiedName;
}

typeName.SetName(szNameSpace, szName);

// typeName.m_pBucket gets set here if the type is found
// it will be used in the next iteration to look up the nested type
Expand Down Expand Up @@ -415,6 +432,7 @@ extern "C" void QCALLTYPE AssemblyNative_GetTypeCoreIgnoreCase(QCall::AssemblyHa
ClassLoader* pClassLoader = pAssembly->GetLoader();

NameHandle typeName(pManifestModule, mdtBaseType);
CQuickBytes qbszNamespace;

// Set up the name handle
typeName.SetCaseInsensitive();
Expand All @@ -427,7 +445,23 @@ extern "C" void QCALLTYPE AssemblyNative_GetTypeCoreIgnoreCase(QCall::AssemblyHa
// The type name is expected to be lower-cased by the caller for case-insensitive lookups
name.LowerCase();

typeName.SetName(name.GetUTF8());
LPCUTF8 szFullyQualifiedName = name.GetUTF8();

LPCUTF8 szNameSpace = "";
LPCUTF8 szName = "";

if ((szName = ns::FindSep(szFullyQualifiedName)) != NULL)
{
SIZE_T d = szName - szFullyQualifiedName;
szNameSpace = qbszNamespace.SetString(szFullyQualifiedName, d);
szName++;
}
else
{
szName = szFullyQualifiedName;
}

typeName.SetName(szNameSpace, szName);

// typeName.m_pBucket gets set here if the type is found
// it will be used in the next iteration to look up the nested type
Expand Down
5 changes: 4 additions & 1 deletion src/coreclr/vm/binder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,13 @@ PTR_MethodTable CoreLibBinder::LookupClassLocal(BinderClassID id)
(void)ClassLoader::LoadTypeByNameThrowing(GetModule()->GetAssembly(), &nameHandle);

// Now load the nested type.
nameHandle.SetName(NULL, nestedTypeMaybe + 1);
nameHandle.SetName("", nestedTypeMaybe + 1);

// We don't support nested types in nested types.
_ASSERTE(strchr(nameHandle.GetName(), '+') == NULL);

// We don't support nested types with explicit namespaces
_ASSERTE(strchr(nameHandle.GetName(), '.') == NULL);
pMT = ClassLoader::LoadTypeByNameThrowing(GetModule()->GetAssembly(), &nameHandle).AsMethodTable();
}

Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/vm/ceeload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ void Module::Initialize(AllocMemTracker *pamTracker, LPCWSTR szName)
{
m_pAvailableClasses = EEClassHashTable::Create(this,
GetAssembly()->IsCollectible() ? AVAILABLE_CLASSES_HASH_BUCKETS_COLLECTIBLE : AVAILABLE_CLASSES_HASH_BUCKETS,
FALSE /* bCaseInsensitive */, pamTracker);
NULL, pamTracker);
}

if (m_pAvailableParamTypes == NULL)
Expand Down
Loading
Loading