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

Put HasNativeCodeReJITAware into GetFunctionAddress #90049

Merged

Conversation

mikelle-rogers
Copy link
Member

Went through many branches of the call tree to understand which changes needed to be made to ensure safe behavior when updating GetFunctionAddress to return possibly arbitrary nativeCode.

@mikelle-rogers
Copy link
Member Author

Fixes #89475.
There are a few more branches that need investigation, and some that have been investigated that still need fixing. I will open a new issue to specify those. I wanted to push the code I had so far to start getting feedback.

src/coreclr/debug/di/breakpoint.cpp Show resolved Hide resolved
src/coreclr/debug/ee/controller.cpp Outdated Show resolved Hide resolved
src/coreclr/vm/eedbginterfaceimpl.cpp Outdated Show resolved Hide resolved
src/coreclr/debug/daccess/task.cpp Outdated Show resolved Hide resolved
src/coreclr/debug/daccess/task.cpp Outdated Show resolved Hide resolved
src/coreclr/debug/ee/debugger.cpp Outdated Show resolved Hide resolved
@@ -1577,6 +1576,14 @@ DebuggerJitInfo *DebuggerMethodInfo::FindOrCreateInitAndAddJitInfo(MethodDesc* f
if (startAddr == NULL)
{
startAddr = g_pEEInterface->GetFunctionAddress(fd);
if (startAddr == NULL)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there scenarios that are still calling into FindOrCreateInitAndAddJitInfo() with startAddr=NULL after the other changes we did? (I'm not pushing back or implying anything, just asking)

If there aren't any scenarios left then we should assert startAddr != NULL and remove the code that handles the NULL case.

If there are still scenarios where startAddr==NULL can we enumerate them in a comment? What I'd like to get recorded is whether we've explicitly determined that searching default + active code version only is the correct behavior, or we know it isn't fully correct but we are using it for expediency, or we don't know one way or the other.

If GetNativeCodeReJITAware() is just a heuristic that often works but isn't fully correct then we should comment it clearly so that other devs don't accidentally start using it and dig the hole any deeper than it already is.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No more scenarios after calling GetFunctionAddress, I put an Assert in the code and the test still passes.

src/coreclr/debug/ee/functioninfo.cpp Outdated Show resolved Hide resolved
src/coreclr/debug/daccess/task.cpp Outdated Show resolved Hide resolved
src/coreclr/debug/daccess/task.cpp Outdated Show resolved Hide resolved
src/coreclr/debug/ee/controller.cpp Outdated Show resolved Hide resolved
Copy link
Member

@noahfalk noahfalk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM modulo a last little bug on ARM commented inline

src/coreclr/debug/ee/debugger.cpp Outdated Show resolved Hide resolved
src/coreclr/vm/method.hpp Outdated Show resolved Hide resolved
{
CodeVersionManager *pCodeVersionManager = GetCodeVersionManager();
CodeVersionManager::LockHolder codeVersioningLockHolder;
ILCodeVersion ilVersion = pCodeVersionManager->GetActiveILCodeVersion(PTR_MethodDesc(this));
if (!ilVersion.IsDefaultVersion())
ILCodeVersionCollection ilVersionCollection = pCodeVersionManager->GetILCodeVersions(PTR_MethodDesc(this));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before you were getting the current IL version's address. Is there any guarantee of what order you get this in? Does it return in order of IL version and descend until a native body is found? For things like deoptimization, is that what we want?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no guarantee of order, however, the work has been done to look through everything that calls this code, and make adjustments to allow this behavior to be safe. GetNativeCodeAnyVersion is only used in HasNativeCodeAnyVersion, which is used in EnumMethodInstances::Next and CdStart. It is only used to see whether or not there is a native code body. The reason it was changed is with the addition of deoptimization, there is a possibility that the user asks the code to be deoptimized before it has a default and active version (before the method is jitted). Thus, the code could have a native code version even though it did not have an active nor default native code version. @davmason @noahfalk

@mikelle-rogers mikelle-rogers merged commit eacb32e into dotnet:main Aug 14, 2023
109 checks passed
mikelle-rogers added a commit to mikelle-rogers/runtime that referenced this pull request Aug 16, 2023
…0049)"

This reverts commit eacb32e.
Need to investigate changes because they caused a test failure.
carlossanlop pushed a commit that referenced this pull request Aug 17, 2023
…#90696)

This reverts commit eacb32e.
Need to investigate changes because they caused a test failure.
@ghost ghost locked as resolved and limited conversation to collaborators Sep 14, 2023
@radical radical mentioned this pull request Sep 26, 2023
@mikelle-rogers
Copy link
Member Author

/backport to release/8.0

@github-actions github-actions bot unlocked this conversation Sep 26, 2023
@github-actions
Copy link
Contributor

Started backporting to release/8.0: https://github.com/dotnet/runtime/actions/runs/6317993923

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants