diff --git a/src/coreclr/vm/appdomain.cpp b/src/coreclr/vm/appdomain.cpp index f8436aca04d5b3..a7da045ef42147 100644 --- a/src/coreclr/vm/appdomain.cpp +++ b/src/coreclr/vm/appdomain.cpp @@ -1164,7 +1164,7 @@ void SystemDomain::LoadBaseSystemClasses() // Only partially load the system assembly. Other parts of the code will want to access // the globals in this function before finishing the load. - m_pSystemAssembly = DefaultDomain()->LoadDomainAssembly(NULL, m_pSystemPEAssembly, FILE_LOAD_POST_LOADLIBRARY)->GetAssembly(); + m_pSystemAssembly = DefaultDomain()->LoadDomainAssembly(NULL, m_pSystemPEAssembly, FILE_LOAD_POST_ALLOCATE)->GetAssembly(); // Set up binder for CoreLib CoreLibBinder::AttachModule(m_pSystemAssembly->GetModule()); @@ -2119,13 +2119,8 @@ static const char *fileLoadLevelName[] = { "CREATE", // FILE_LOAD_CREATE "BEGIN", // FILE_LOAD_BEGIN - "FIND_NATIVE_IMAGE", // FILE_LOAD_FIND_NATIVE_IMAGE - "VERIFY_NATIVE_IMAGE_DEPENDENCIES", // FILE_LOAD_VERIFY_NATIVE_IMAGE_DEPENDENCIES "ALLOCATE", // FILE_LOAD_ALLOCATE - "ADD_DEPENDENCIES", // FILE_LOAD_ADD_DEPENDENCIES - "PRE_LOADLIBRARY", // FILE_LOAD_PRE_LOADLIBRARY - "LOADLIBRARY", // FILE_LOAD_LOADLIBRARY - "POST_LOADLIBRARY", // FILE_LOAD_POST_LOADLIBRARY + "POST_ALLOCATE", // FILE_LOAD_POST_ALLOCATE "EAGER_FIXUPS", // FILE_LOAD_EAGER_FIXUPS "DELIVER_EVENTS", // FILE_LOAD_DELIVER_EVENTS "VTABLE FIXUPS", // FILE_LOAD_VTABLE_FIXUPS @@ -2193,7 +2188,6 @@ BOOL FileLoadLock::CompleteLoadLevel(FileLoadLevel level, BOOL success) switch(level) { case FILE_LOAD_ALLOCATE: - case FILE_LOAD_ADD_DEPENDENCIES: case FILE_LOAD_DELIVER_EVENTS: case FILE_LOADED: case FILE_ACTIVE: // The timing of stress logs is not critical, so even for the FILE_ACTIVE stage we need not do it while the m_pList lock is held. @@ -2809,53 +2803,26 @@ void AppDomain::TryIncrementalLoad(DomainAssembly *pFile, FileLoadLevel workLeve EX_TRY { - - // Special case: for LoadLibrary, we cannot hold the lock during the - // actual LoadLibrary call, because we might get a callback from _CorDllMain on any - // other thread. (Note that this requires DomainAssembly's LoadLibrary to be independently threadsafe.) - - if (workLevel == FILE_LOAD_LOADLIBRARY) - { - lockHolder.Release(); - released = TRUE; - } - // Do the work BOOL success = pFile->DoIncrementalLoad(workLevel); - if (released) - { - // Reobtain lock to increment level. (Note that another thread may - // have already done it which is OK. - if (pLoadLock->Acquire(workLevel)) - { - // note lockHolder.Acquire isn't wired up to actually take the lock - lockHolder = pLoadLock; - released = FALSE; - } - } - if (!released) + // Complete the level. + if (pLoadLock->CompleteLoadLevel(workLevel, success) && + pLoadLock->GetLoadLevel()==FILE_LOAD_DELIVER_EVENTS) { - // Complete the level. - if (pLoadLock->CompleteLoadLevel(workLevel, success) && - pLoadLock->GetLoadLevel()==FILE_LOAD_DELIVER_EVENTS) - { - lockHolder.Release(); - released = TRUE; - pFile->DeliverAsyncEvents(); - }; - } + lockHolder.Release(); + released = TRUE; + pFile->DeliverAsyncEvents(); + }; } EX_HOOK { Exception *pEx = GET_EXCEPTION(); - //We will cache this error and wire this load to forever fail, // unless the exception is transient or the file is loaded OK but just cannot execute if (!pEx->IsTransient() && !pFile->IsLoaded()) { - if (released) { // Reobtain lock to increment level. (Note that another thread may diff --git a/src/coreclr/vm/ceeload.cpp b/src/coreclr/vm/ceeload.cpp index 75e93bcdbee395..447e585c5f42d8 100644 --- a/src/coreclr/vm/ceeload.cpp +++ b/src/coreclr/vm/ceeload.cpp @@ -4425,11 +4425,6 @@ VOID Module::EnsureAllocated() GetDomainAssembly()->EnsureAllocated(); } -VOID Module::EnsureLibraryLoaded() -{ - STANDARD_VM_CONTRACT; - GetDomainAssembly()->EnsureLibraryLoaded(); -} #endif // !DACCESS_COMPILE CHECK Module::CheckActivated() diff --git a/src/coreclr/vm/ceeload.h b/src/coreclr/vm/ceeload.h index 9bcae6e145d843..d4c5c719b616ac 100644 --- a/src/coreclr/vm/ceeload.h +++ b/src/coreclr/vm/ceeload.h @@ -951,7 +951,6 @@ class Module : public ModuleBase #ifndef DACCESS_COMPILE VOID EnsureActive(); VOID EnsureAllocated(); - VOID EnsureLibraryLoaded(); #endif CHECK CheckActivated(); diff --git a/src/coreclr/vm/domainassembly.cpp b/src/coreclr/vm/domainassembly.cpp index 30dbe9207e630a..c0db1363ccc5f4 100644 --- a/src/coreclr/vm/domainassembly.cpp +++ b/src/coreclr/vm/domainassembly.cpp @@ -389,30 +389,12 @@ BOOL DomainAssembly::DoIncrementalLoad(FileLoadLevel level) Begin(); break; - case FILE_LOAD_FIND_NATIVE_IMAGE: - break; - - case FILE_LOAD_VERIFY_NATIVE_IMAGE_DEPENDENCIES: - break; - case FILE_LOAD_ALLOCATE: Allocate(); break; - case FILE_LOAD_ADD_DEPENDENCIES: - AddDependencies(); - break; - - case FILE_LOAD_PRE_LOADLIBRARY: - PreLoadLibrary(); - break; - - case FILE_LOAD_LOADLIBRARY: - LoadLibrary(); - break; - - case FILE_LOAD_POST_LOADLIBRARY: - PostLoadLibrary(); + case FILE_LOAD_POST_ALLOCATE: + PostAllocate(); break; case FILE_LOAD_EAGER_FIXUPS: @@ -453,29 +435,7 @@ BOOL DomainAssembly::DoIncrementalLoad(FileLoadLevel level) return TRUE; } -void DomainAssembly::PreLoadLibrary() -{ - CONTRACTL - { - INSTANCE_CHECK; - STANDARD_VM_CHECK; - } - CONTRACTL_END; - -} // DomainAssembly::PreLoadLibrary - -void DomainAssembly::LoadLibrary() -{ - CONTRACTL - { - INSTANCE_CHECK; - STANDARD_VM_CHECK; - } - CONTRACTL_END; - -} - -void DomainAssembly::PostLoadLibrary() +void DomainAssembly::PostAllocate() { CONTRACTL { @@ -511,11 +471,6 @@ void DomainAssembly::PostLoadLibrary() #endif } -void DomainAssembly::AddDependencies() -{ - STANDARD_VM_CONTRACT; -} - void DomainAssembly::EagerFixups() { WRAPPER_NO_CONTRACT; @@ -744,18 +699,16 @@ void DomainAssembly::Allocate() INSTANCE_CHECK; STANDARD_VM_CHECK; INJECT_FAULT(COMPlusThrowOM();); + PRECONDITION(m_pAssembly == NULL); } CONTRACTL_END; AllocMemTracker amTracker; AllocMemTracker * pamTracker = &amTracker; - Assembly * pAssembly = m_pAssembly; - - if (pAssembly==NULL) + Assembly * pAssembly; { - //! If you decide to remove "if" do not remove this brace: order is important here - in the case of an exception, - //! the Assembly holder must destruct before the AllocMemTracker declared above. + // Order is important here - in the case of an exception, the Assembly holder must destruct before the AllocMemTracker declared above. NewHolder assemblyHolder(NULL); assemblyHolder = pAssembly = Assembly::Create(GetPEAssembly(), GetDebuggerInfoBits(), this->IsCollectible(), pamTracker, this->IsCollectible() ? this->GetLoaderAllocator() : NULL); @@ -766,6 +719,9 @@ void DomainAssembly::Allocate() } SetAssembly(pAssembly); + + // Creating the Assembly should have ensured the PEAssembly is loaded + _ASSERT(GetPEAssembly()->IsLoaded()); } void DomainAssembly::DeliverAsyncEvents() diff --git a/src/coreclr/vm/domainassembly.h b/src/coreclr/vm/domainassembly.h index 64b8c4a9fdf4e3..2070e703c2e96b 100644 --- a/src/coreclr/vm/domainassembly.h +++ b/src/coreclr/vm/domainassembly.h @@ -35,13 +35,8 @@ enum FileLoadLevel FILE_LOAD_CREATE, FILE_LOAD_BEGIN, - FILE_LOAD_FIND_NATIVE_IMAGE, - FILE_LOAD_VERIFY_NATIVE_IMAGE_DEPENDENCIES, FILE_LOAD_ALLOCATE, - FILE_LOAD_ADD_DEPENDENCIES, - FILE_LOAD_PRE_LOADLIBRARY, - FILE_LOAD_LOADLIBRARY, - FILE_LOAD_POST_LOADLIBRARY, + FILE_LOAD_POST_ALLOCATE, FILE_LOAD_EAGER_FIXUPS, FILE_LOAD_DELIVER_EVENTS, FILE_LOAD_VTABLE_FIXUPS, @@ -222,12 +217,6 @@ class DomainAssembly final return EnsureLoadLevel(FILE_LOAD_ALLOCATE); } - void EnsureLibraryLoaded() - { - WRAPPER_NO_CONTRACT; - return EnsureLoadLevel(FILE_LOAD_LOADLIBRARY); - } - // EnsureLoadLevel is a generic routine used to ensure that the file is not in a delay loaded // state (unless it needs to be.) This should be used when a particular level of loading // is required for an operation. Note that deadlocks are tolerated so the level may be one @@ -309,10 +298,7 @@ class DomainAssembly final #ifndef DACCESS_COMPILE void Begin(); void Allocate(); - void AddDependencies(); - void PreLoadLibrary(); - void LoadLibrary(); - void PostLoadLibrary(); + void PostAllocate(); void EagerFixups(); void VtableFixups(); void DeliverSyncEvents(); diff --git a/src/coreclr/vm/methodtablebuilder.cpp b/src/coreclr/vm/methodtablebuilder.cpp index def33bc6c063fd..8ed085986a915d 100644 --- a/src/coreclr/vm/methodtablebuilder.cpp +++ b/src/coreclr/vm/methodtablebuilder.cpp @@ -1260,7 +1260,7 @@ MethodTableBuilder::BuildMethodTableThrowing( } CONTRACTL_END; - pModule->EnsureLibraryLoaded(); + pModule->EnsureAllocated(); // The following structs, defined as private members of MethodTableBuilder, contain the necessary local // parameters needed for BuildMethodTable Look at the struct definitions for a detailed list of all