-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Enhance DAC to allow getting AssemblyLoadContext for objects #37901
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
Conversation
|
Tagging subscribers to this area: @tommcdon |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/coreclr/src/inc/sospriv.idl
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where do you get the address of the loader allocator or the binder from? Do we also need APIs to e.g. get loader allocator from MethodTable or MethodDesc?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We already have that, I have added that quite some time ago.
interface ISOSDacInterface6 : IUnknown
{
HRESULT GetMethodTableCollectibleData(CLRDATA_ADDRESS mt, struct DacpMethodTableCollectibleData *data);
};
I also have the SOS change tested and ready to get in.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GetMethodTableCollectibleData returns LoaderAllocatorObjectHandle. How do you get from LoaderAllocatorObjectHandle to loaderAllocator ?
SOS change
It may be useful to add link to the SOS change for context.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #11157 (comment) for the steps to get from an object to the AssemblyLoadContext. There were two steps that couldn't be done via DAC before, those are the ones I'm adding here.
As for the SOS change, I was planning to create the PR after this one gets in.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You may want to write some of the SOS code to test these new DAC APIs to test the binder code added to the DAC has been properly "DACized" (dac_cast macros, etc).
|
Hmm, it seems that all Linux builds are broken due to a missing header. I am looking into it. |
src/coreclr/src/inc/dacprivate.h
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use more self-describing name, e.g. OwningAssemblyLoadContext ?
|
It looks good to me otherwise. I would like to see somebody from the diagnostic team to signoff on this as well. |
@mikem8361 @sdmaclea can you take a look? |
src/coreclr/src/inc/sospriv.idl
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You may want to write some of the SOS code to test these new DAC APIs to test the binder code added to the DAC has been properly "DACized" (dac_cast macros, etc).
|
I am going to redo this change to add just one new method to get pointer to managed AssemblyLoadContext for a given MethodTable. The current way worked only for collectible AssemblyLoadContext and I have realized that I can make it work for both collectible and non-collectible. |
|
@jkotas, @mikem8361 can you please take a look again? I've made substantial changes to you'll probably want to review it from scratch. I've redone the implementation to support |
I do not think that's required as long as we ship both changes in the same release cycle. |
|
I can see that the Unix build is broken for the DAC build, I need to investigate it. |
Right, as long as it's the same release we can change the interfaces. @janvorli it should be fairly easy to merge, whoever merges last can just add their methods to the existing interface in sospriv.idl and then regenerate sospriv.h and make sure the guid definition is right in sospriv_i.cpp. There shouldn't be any other work. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has a lot of non-DACized pointers. It is hard to see that none of them will get used by the DAC.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have DACized only the ones that are needed for getting the ALC. It was painful enough that way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand that it was painful. It is hard to see that it is correct. We prefer the type members to be fully DACized. Partially DACized types are bug farms.
mikem8361
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do like this approach better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you intentionally leave this commented out?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I should have removed that, I have missed it when looking through the code before commit.
src/coreclr/src/vm/pefile.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be better to store the PTR_AssemblyLoadContext in the PEFile and the object handle in AssemblyLoadContext base class to avoid DACizing the whole binder machinery?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am worried that we will keep finding holes in the binder DACization.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be better to store the
PTR_AssemblyLoadContextin the PEFile and the object handle inAssemblyLoadContextbase class to avoid DACizing the whole binder machinery?
I will try to do it that way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TO_TADDR [](start = 42, length = 8)
Can you please change this to CLRDATA_ADDRESS_TO_TADDR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. Btw, I am redoing it based on @jkotas feedback to simplify things considerably, so please wait with reviewing a bit.
7e2d6e3 to
2acb8c0
Compare
This change adds support to DAC for getting AssemblyLoadContext for a MethodTable. The returned AsseblyLoadContext is the context into which the related type was loaded.
2acb8c0 to
0a3bfe2
Compare
|
@jkotas I have updated the PR based on your suggestion of storing the AssemblyLoadContext in the PEFile. It worked quite well, the only little ugly thing being the need to set the ALC for the S.P.C. separately, as the PEFile (PEAssembly) for it is created during the ICLRRuntimeHost4::Start, but the related ALC much later during ICLRRuntimeHost4::CreateAppDomainWithManager. |
src/coreclr/src/vm/pefile.cpp
Outdated
| #endif | ||
| } | ||
|
|
||
| #ifndef DACCESS_COMPILE |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The whole function is !DACCESS_COMPILE. This ifdef should not be needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Strange, I have thought I have removed it already.
src/coreclr/src/vm/appdomain.cpp
Outdated
| // Initialize the assembly binder for the default context loads for CoreCLR. | ||
| IfFailThrow(CCoreCLRBinderHelper::DefaultBinderSetupContext(DefaultADID, &m_pTPABinderContext)); | ||
|
|
||
| SystemDomain::SystemFile()->SetAssemblyLoadContext(m_pTPABinderContext); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need to set it explicitly? I would expect the constructor to set it for corelib too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've mentioned it in my comment above. the PEFile (PEAssembly) for it is created during the ICLRRuntimeHost4::Start, but the related ALC much later during ICLRRuntimeHost4::CreateAppDomainWithManager.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe useful to add comment.
|
There are two tests failing.
It seems there is one more way how the |
src/coreclr/src/vm/pefile.cpp
Outdated
| GetILimage()->GetLayout(PEImageLayout::LAYOUT_ANY,PEImage::LAYOUT_CREATEIFNEEDED)->Release(); | ||
| } | ||
|
|
||
| AssemblyLoadContext* PEFile::LookupAssemblyLoadContext() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SetAssemblyLoadContext + LookupAssemblyLoadContext can be merged into a single method like void SetupAssemblyLoadContext() that computes it from the other PEFile state and sets it.
This change adds support to DAC for getting AssemblyLoadContext
for a MethodTable. The returned AsseblyLoadContext is the context
into which the related type was loaded.