Skip to content

Commit

Permalink
Remove Unrestored/UnrestoredTypeKey flags, load levels, checks (#97674)
Browse files Browse the repository at this point in the history
These were from NGEN support, so we can remove the flags, load levels, and assorted checks for them.
  • Loading branch information
elinor-fung authored Jan 31, 2024
1 parent 7410954 commit 36287c2
Show file tree
Hide file tree
Showing 30 changed files with 46 additions and 405 deletions.
15 changes: 3 additions & 12 deletions src/coreclr/debug/daccess/dacdbiimpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1487,19 +1487,12 @@ void DacDbiInterfaceImpl::GetTypeHandles(VMPTR_TypeHandle vmThExact,
*pThExact = TypeHandle::FromPtr(vmThExact.GetDacPtr());
*pThApprox = TypeHandle::FromPtr(vmThApprox.GetDacPtr());

// If we can't find the class, return the proper HR to the right side. Note: if the class is not a value class and
// the class is also not restored, then we must pretend that the class is still not loaded. We are gonna let
// unrestored value classes slide, though, and special case access to the class's parent below.
if ((pThApprox->IsNull()) || ((!pThApprox->IsValueType()) && (!pThApprox->IsRestored())))
// If we can't find the class, return the proper HR to the right side.
if (pThApprox->IsNull())
{
LOG((LF_CORDB, LL_INFO10000, "D::GASCI: class isn't loaded.\n"));
ThrowHR(CORDBG_E_CLASS_NOT_LOADED);
}
// If the exact type handle is not restored ignore it.
if (!pThExact->IsNull() && !pThExact->IsRestored())
{
*pThExact = TypeHandle();
}
} // DacDbiInterfaceImpl::GetTypeHandles

//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -3005,9 +2998,7 @@ TypeHandle DacDbiInterfaceImpl::GetExactClassTypeHandle(DebuggerIPCE_ExpandedTyp
TypeHandle typeConstructor =
ClassLoader::LookupTypeDefOrRefInModule(pModule, pTopLevelTypeData->ClassTypeData.metadataToken);

// If we can't find the class, throw the appropriate HR. Note: if the class is not a value class and
// the class is also not restored, then we must pretend that the class is still not loaded. We are gonna let
// unrestored value classes slide, though, and special case access to the class's parent below.
// If we can't find the class, throw the appropriate HR.
if (typeConstructor.IsNull())
{
LOG((LF_CORDB, LL_INFO10000, "D::ETITTH: class isn't loaded.\n"));
Expand Down
10 changes: 3 additions & 7 deletions src/coreclr/debug/daccess/inspect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ InitFieldIter(DeepFieldDescIterator* fieldIter,
includeParents = true;
}

if (typeHandle.IsNull() ||
!typeHandle.GetMethodTable() ||
!typeHandle.IsRestored())
if (typeHandle.IsNull() || !typeHandle.GetMethodTable())
{
return E_INVALIDARG;
}
Expand Down Expand Up @@ -2683,8 +2681,7 @@ ClrDataTypeDefinition::NewFromModule(ClrDataAccess* dac,
// If the type isn't loaded a metadata-query
// TypeDefinition is produced.
TypeHandle typeHandle = module->LookupTypeDef(token);
if (!typeHandle.IsNull() &&
!typeHandle.IsRestored())
if (!typeHandle.IsNull())
{
// The type isn't fully usable so just go with metadata.
typeHandle = TypeHandle();
Expand Down Expand Up @@ -3799,8 +3796,7 @@ ClrDataTypeInstance::NewFromModule(ClrDataAccess* dac,
IXCLRDataTypeInstance** pubTypeInst)
{
TypeHandle typeHandle = module->LookupTypeDef(token);
if (typeHandle.IsNull() ||
!typeHandle.IsRestored())
if (typeHandle.IsNull())
{
return E_INVALIDARG;
}
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/vm/binder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ NOINLINE PTR_MethodTable CoreLibBinder::LookupClassIfExist(BinderClassID id)
const CoreLibClassDescription *d = (&g_CoreLib)->m_classDescriptions + (int)id;

PTR_MethodTable pMT = ClassLoader::LoadTypeByNameThrowing(GetModule()->GetAssembly(), d->nameSpace, d->name,
ClassLoader::ReturnNullIfNotFound, ClassLoader::DontLoadTypes, CLASS_LOAD_UNRESTOREDTYPEKEY).AsMethodTable();
ClassLoader::ReturnNullIfNotFound, ClassLoader::DontLoadTypes, CLASS_LOAD_APPROXPARENTS).AsMethodTable();

_ASSERTE((pMT == NULL) || (pMT->GetModule() == GetModule()));

Expand Down
1 change: 0 additions & 1 deletion src/coreclr/vm/callhelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,6 @@ void MethodDescCallSite::CallTargetWorker(const ARG_SLOT *pArguments, ARG_SLOT *
{
TypeHandle th = m_methodSig.GetLastTypeHandleThrowing(ClassLoader::DontLoadTypes);
CONSISTENCY_CHECK(th.CheckFullyLoaded());
CONSISTENCY_CHECK(th.IsRestored());
}
}
m_methodSig.Reset();
Expand Down
12 changes: 3 additions & 9 deletions src/coreclr/vm/ceeload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1939,8 +1939,7 @@ void Module::FreeClassTables()
while (typeDefIter.Next())
{
MethodTable * pMT = typeDefIter.GetElement();

if (pMT != NULL && pMT->IsRestored())
if (pMT != NULL)
{
pMT->GetClass()->Destruct(pMT);
}
Expand All @@ -1958,9 +1957,6 @@ void Module::FreeClassTables()
{
TypeHandle th = pEntry->GetTypeHandle();

if (!th.IsRestored())
continue;

// We need to call destruct on instances of EEClass whose "canonical" dependent lives in this table
// There is nothing interesting to destruct on array EEClass
if (!th.IsTypeDesc())
Expand Down Expand Up @@ -3573,8 +3569,7 @@ BOOL Module::NotifyDebuggerLoad(AppDomain *pDomain, DomainAssembly * pDomainAsse
while (typeDefIter.Next())
{
MethodTable * pMT = typeDefIter.GetElement();

if (pMT != NULL && pMT->IsRestored())
if (pMT != NULL)
{
result = TypeHandle(pMT).NotifyDebuggerLoad(pDomain, attaching) || result;
}
Expand All @@ -3599,8 +3594,7 @@ void Module::NotifyDebuggerUnload(AppDomain *pDomain)
while (typeDefIter.Next())
{
MethodTable * pMT = typeDefIter.GetElement();

if (pMT != NULL && pMT->IsRestored())
if (pMT != NULL)
{
TypeHandle(pMT).NotifyDebuggerUnload(pDomain);
}
Expand Down
18 changes: 1 addition & 17 deletions src/coreclr/vm/classloadlevel.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,9 @@
// Placeholder level used before type has been created or located in ngen image
//
//
// CLASS_LOAD_UNRESTOREDTYPEKEY
//
// Type lives in an ngen image and components of its type key need restoring:
// for methodtables: generic arguments, EEClass pointer, Module pointer in EEClass
// for typedescs: param type, template methodtable
//
//
// CLASS_LOAD_UNRESTORED
//
// Type lives in an ngen image and contains fields that need restoring
// (e.g. parent, interfaces, param type)
//
//
// CLASS_LOAD_APPROXPARENTS
//
// Type has been created, or loaded from an ngen image and fields
// have been restored, but some fields have been filled in with only
// Type has been created, but some fields have been filled in with only
// "approximate" information for generic type arguments. In
// particular, the parent class is approximate, and interfaces are
// generic (instantiation at formal type parameters). Other
Expand Down Expand Up @@ -71,8 +57,6 @@
enum ClassLoadLevel
{
CLASS_LOAD_BEGIN,
CLASS_LOAD_UNRESTOREDTYPEKEY,
CLASS_LOAD_UNRESTORED,
CLASS_LOAD_APPROXPARENTS,
CLASS_LOAD_EXACTPARENTS,
CLASS_DEPENDENCIES_LOADED,
Expand Down
14 changes: 2 additions & 12 deletions src/coreclr/vm/clsload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,7 @@ void ClassLoader::EnsureLoaded(TypeHandle typeHnd, ClassLoadLevel level)

if (typeHnd.GetLoadLevel() < level)
{
if (level > CLASS_LOAD_UNRESTORED)
if (level >= CLASS_LOAD_APPROXPARENTS)
{
TypeKey typeKey = typeHnd.GetTypeKey();

Expand Down Expand Up @@ -1328,7 +1328,6 @@ ClassLoader::LoadTypeHandleThrowing(
#ifndef DACCESS_COMPILE
// Replace AvailableClasses Module entry with found TypeHandle
if (!typeHnd.IsNull() &&
typeHnd.IsRestored() &&
foundEntry.GetEntryType() == HashedTypeEntry::EntryType::IsHashedClassEntry &&
(foundEntry.GetClassHashBasedEntryValue() != NULL) &&
(foundEntry.GetClassHashBasedEntryValue()->GetData() != typeHnd.AsPtr()))
Expand Down Expand Up @@ -2045,7 +2044,6 @@ TypeHandle ClassLoader::LoadTypeDefOrRefThrowing(ModuleBase *pModule,
PRECONDITION(level > CLASS_LOAD_BEGIN && level <= CLASS_LOADED);

POSTCONDITION(CheckPointer(RETVAL, NameHandle::OKToLoad(typeDefOrRef, tokenNotToLoad) && (fNotFoundAction == ThrowIfNotFound) ? NULL_NOT_OK : NULL_OK));
POSTCONDITION(level <= CLASS_LOAD_UNRESTORED || RETVAL.IsNull() || RETVAL.IsRestored());
SUPPORTS_DAC;
}
CONTRACT_END;
Expand Down Expand Up @@ -2616,8 +2614,7 @@ TypeHandle ClassLoader::DoIncrementalLoad(const TypeKey *pTypeKey, TypeHandle ty

switch (currentLevel)
{
// Attain at least level CLASS_LOAD_UNRESTORED (if just locating type in ngen image)
// or at least level CLASS_LOAD_APPROXPARENTS (if creating type for the first time)
// Attain at least level CLASS_LOAD_APPROXPARENTS (if creating type for the first time)
case CLASS_LOAD_BEGIN :
{
AllocMemTracker amTracker;
Expand All @@ -2630,13 +2627,6 @@ TypeHandle ClassLoader::DoIncrementalLoad(const TypeKey *pTypeKey, TypeHandle ty
}
break;

case CLASS_LOAD_UNRESTOREDTYPEKEY :
break;

// Attain level CLASS_LOAD_APPROXPARENTS, starting with unrestored class
case CLASS_LOAD_UNRESTORED :
break;

// Attain level CLASS_LOAD_EXACTPARENTS
case CLASS_LOAD_APPROXPARENTS :
if (!typeHnd.IsTypeDesc())
Expand Down
4 changes: 0 additions & 4 deletions src/coreclr/vm/eventtrace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1254,10 +1254,6 @@ VOID ETW::TypeSystemLog::LogTypeAndParametersIfNecessary(BulkTypeEventLogger * p
}

TypeHandle th = TypeHandle::FromTAddr((TADDR) thAsAddr);
if (!th.IsRestored())
{
return;
}

// Check to see if we've already logged this type. If so, bail immediately.
// Otherwise, mark that it's getting logged (by adding it to the hash), and fall
Expand Down
1 change: 0 additions & 1 deletion src/coreclr/vm/field.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,6 @@ PTR_VOID FieldDesc::GetStaticAddressHandle(PTR_VOID base)
MODE_ANY;
FORBID_FAULT;
PRECONDITION(IsStatic());
PRECONDITION(GetEnclosingMethodTable()->IsRestored());
}
CONTRACTL_END

Expand Down
2 changes: 0 additions & 2 deletions src/coreclr/vm/generics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -480,8 +480,6 @@ ClassLoader::CreateTypeHandleForNonCanonicalGenericInstantiation(
// We never have non-virtual slots in this method table (set SetNumVtableSlots and SetNumVirtuals above)
_ASSERTE(!pMT->HasNonVirtualSlots());

pMT->GetAuxiliaryDataForWrite()->SetIsRestoredForBuildMethodTable();

RETURN(TypeHandle(pMT));
} // ClassLoader::CreateTypeHandleForNonCanonicalGenericInstantiation

Expand Down
2 changes: 0 additions & 2 deletions src/coreclr/vm/genmeth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ static MethodDesc* CreateMethodDesc(LoaderAllocator *pAllocator,
PRECONDITION(CheckPointer(pAllocator));
PRECONDITION(CheckPointer(pMT));
PRECONDITION(CheckPointer(pTemplateMD));
PRECONDITION(pMT->IsRestored());
PRECONDITION(pTemplateMD->GetMethodTable()->GetCanonicalMethodTable() == pMT->GetCanonicalMethodTable());
}
CONTRACTL_END
Expand Down Expand Up @@ -731,7 +730,6 @@ MethodDesc::FindOrCreateAssociatedMethodDesc(MethodDesc* pDefMD,

PRECONDITION(CheckPointer(pDefMD));
PRECONDITION(CheckPointer(pExactMT));
PRECONDITION(pExactMT->IsRestored());

// If the method descriptor belongs to a generic type then
// the input exact type must be an instantiation of that type.
Expand Down
1 change: 0 additions & 1 deletion src/coreclr/vm/interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9681,7 +9681,6 @@ void Interpreter::DoCallWork(bool virtualCall, void* thisArg, CORINFO_RESOLVED_T
{
TypeHandle th = ms.GetLastTypeHandleThrowing(ClassLoader::LoadTypes);
CONSISTENCY_CHECK(th.CheckFullyLoaded());
CONSISTENCY_CHECK(th.IsRestored());
}
}
}
Expand Down
5 changes: 0 additions & 5 deletions src/coreclr/vm/jithelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2445,7 +2445,6 @@ HCIMPL1(Object*, JIT_New, CORINFO_CLASS_HANDLE typeHnd_)

_ASSERTE(!typeHnd.IsTypeDesc()); // heap objects must have method tables
MethodTable *pMT = typeHnd.AsMethodTable();
_ASSERTE(pMT->IsRestored());

#ifdef _DEBUG
if (g_pConfig->FastGCStressLevel()) {
Expand All @@ -2472,7 +2471,6 @@ HCIMPL1(Object*, JIT_NewMaybeFrozen, CORINFO_CLASS_HANDLE typeHnd_)

_ASSERTE(!typeHnd.IsTypeDesc()); // heap objects must have method tables
MethodTable* pMT = typeHnd.AsMethodTable();
_ASSERTE(pMT->IsRestored());

#ifdef _DEBUG
if (g_pConfig->FastGCStressLevel()) {
Expand Down Expand Up @@ -3494,7 +3492,6 @@ HCIMPL2(CORINFO_GENERIC_HANDLE, JIT_GenericHandleClass, CORINFO_CLASS_HANDLE cla
CONTRACTL {
FCALL_CHECK;
PRECONDITION(CheckPointer(classHnd));
PRECONDITION(TypeHandle(classHnd).IsRestored());
PRECONDITION(CheckPointer(signature));
} CONTRACTL_END;

Expand All @@ -3514,7 +3511,6 @@ HCIMPL2(CORINFO_GENERIC_HANDLE, JIT_GenericHandleClassWithSlotAndModule, CORINFO
CONTRACTL{
FCALL_CHECK;
PRECONDITION(CheckPointer(classHnd));
PRECONDITION(TypeHandle(classHnd).IsRestored());
PRECONDITION(CheckPointer(pArgs));
} CONTRACTL_END;

Expand All @@ -3536,7 +3532,6 @@ HCIMPL2(CORINFO_GENERIC_HANDLE, JIT_GenericHandleClassLogging, CORINFO_CLASS_HAN
CONTRACTL {
FCALL_CHECK;
PRECONDITION(CheckPointer(classHnd));
PRECONDITION(TypeHandle(classHnd).IsRestored());
PRECONDITION(CheckPointer(signature));
} CONTRACTL_END;

Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/vm/jitinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6594,7 +6594,7 @@ bool CEEInfo::notifyMethodInfoUsage(CORINFO_METHOD_HANDLE ftn)
#endif // FEATURE_REJIT

EE_TO_JIT_TRANSITION();

return true;
}

Expand Down Expand Up @@ -8691,7 +8691,7 @@ bool CEEInfo::resolveVirtualMethodHelper(CORINFO_DEVIRTUALIZATION_INFO * info)

TypeHandle ObjClassHnd(info->objClass);
MethodTable* pObjMT = ObjClassHnd.GetMethodTable();
_ASSERTE(pObjMT->IsRestored() && pObjMT->IsFullyLoaded());
_ASSERTE(pObjMT->IsFullyLoaded());

// Can't devirtualize from __Canon.
if (ObjClassHnd == TypeHandle(g_pCanonMethodTableClass))
Expand Down
10 changes: 0 additions & 10 deletions src/coreclr/vm/methoditer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,23 +94,13 @@ BOOL LoadedMethodDescIterator::Next(
if (!GetCurrentModule()->GetAvailableParamTypes()->FindNext(&m_typeIterator, &m_typeIteratorEntry))
goto ADVANCE_ASSEMBLY;

//if (m_typeIteratorEntry->data != TypeHandle(m_mainMD->GetMethodTable()))
// goto ADVANCE_TYPE;

// When looking up the AvailableParamTypes table we have to be really careful since
// the entries may be unrestored, and may have all sorts of encoded tokens in them.
// Similar logic occurs in the Lookup function for that table. We will clean this
// up in Whidbey Beta2.
TypeHandle th = m_typeIteratorEntry->GetTypeHandle();

if (th.IsTypeDesc())
goto ADVANCE_TYPE;

MethodTable *pMT = th.AsMethodTable();

if (!pMT->IsRestored())
goto ADVANCE_TYPE;

// Check the class token
if (pMT->GetTypeDefRid() != m_mainMD->GetMethodTable()->GetTypeDefRid())
goto ADVANCE_TYPE;
Expand Down
Loading

0 comments on commit 36287c2

Please sign in to comment.