Delete RETURNTYPE and change how we get ReturnKind for gccover. #24600
Conversation
1038c81
to
60ff08b
Compare
We would need this in other places in the next commits.
GC info v.2 has this information and it is checked in another place.
60ff08b
to
74c05a8
Compare
74c05a8
to
d5a3da5
Compare
d5a3da5
to
fcb3ee4
Compare
codeInfo->GetCodeManager()->GetReturnKind(gcInfoToken) must always return a valid kind nowdays (it could return an invalid lind only when GC Info v2 was not available).
PTAL @jkotas @BruceForstall @dotnet/jit-contrib |
Are all the questions in your PR description addressed, or do you still need answers to some of them? |
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.
LGTM after addressing @jkotas comments, plus minor questions/nits.
I am not sure about these two:
ComPlusMethodFrame::GcScanRoots: What should we do in this case? |
It cannot happen. Hijacking is only done for JITed/R2R code.
ComPlusMethodFrame is only used for a few special cases, like COM events. These special cases cannot return structs. |
Interop\COM\NETClients\IDispatch\NETClientIDispatch has a test that returns struct from COM method frame (its signature is coreclr/tests/src/Interop/COM/NETClients/IDispatch/Program.cs Lines 147 to 152 in 6e3a85e
but because this struct doesn't have pointer fields we do not need to report it and return just RT_Scalar. Thanks for the explanation, now I am sure that the current variant is safe and if in the future somebody adds a case with |
…et/coreclr#24600) * Move GetReturnKindFromMethodTable to method.hpp. We would need this in other places in the next commits. * Delete unnecessary checks from callhelpers. * Do not check return types in CanDeduplicateCode. GC info v.2 has this information and it is checked in another place. * Change ComPlusMethodFrame to use the new function. * Change gccover.cpp to use GetReturnKindFromMethodTable. * Delete RETURNTYPE. * Add check to ComPlusMethodFrame. * Delete check from threadsuspend. codeInfo->GetCodeManager()->GetReturnKind(gcInfoToken) must always return a valid kind nowdays (it could return an invalid lind only when GC Info v2 was not available). * Rename functions/arguments. * Add check for IsValidReturnKind. * delete unused var. Commit migrated from dotnet/coreclr@d5d1889
There are several places where we need to know the return type for a call:
HijackFrame::GcScanRoots
, it usesvm\threadsuspend.cpp::GetReturnKind
that gets correct kind it fromEECodeInfo
that points to a compiled method (it can't be a prestub), so code inHijackFrame::GcScanRoots
is our role model:coreclr/src/vm/frames.cpp
Line 1080 in bdb9959
question: can hijacking happen when we are in a compile stub and EECodeInfo is invalid?
GcCover.cpp
needs to know when to protect call return values when imitating Hijacking, but it doesn't haveEECodeInfo
(because mostMethodDescriptor
point to uncompiled code andPCODEs
point to compile stubs, so we can't getEECodeInfo->gcInfoToken
), so we have to restoreReturnKind
from method descriptor. This PR changesMethodDesc::ReturnsObject
to return precise information using code that was inReturnKind GetReturnKindFromMethodTable(Thread *pThread, EECodeInfo *codeInfo)
as example.Using this
ReturnKind
we can correctly understand when we need to protect first/second/both return registers on x64 Unix/arm64 and, for example, do not useINTERRUPT_INSTR_PROTECT_RET
in tricky cases.However,
ReturnKind GetReturnKindFromMethodTable
supports only x64 Unix and doesn't support arm64. So if we call it on arm64 with a method that return 16 bytes struct it fails with assert:coreclr/src/vm/method.cpp
Lines 1266 to 1278 in 221dc73
and there is comment:
coreclr/src/vm/threadsuspend.cpp
Lines 5767 to 5769 in 883a271
that says that it is not a simple restriction.
question: how can we get the necessary information for arm64?
ComPlusMethodFrame::GcScanRoots
needs to know which registers to protect but has the same issues asGCCoder
, but this method is not stress testing specific, so I assume it can cause gc holes in a real app that uses COM methods that return struct on arm64 Windows (we can't have COM on Unix).question: What should we do in this case?
This PR is preparation for https://github.com/dotnet/coreclr/issues/23199. With that change, I have correct kind in
GCCover
and can use different instruction to mark which registers I need to restore.Changes by commits:
0af5c96: Move GetReturnKindFromMethodTable to method.hpp.
We would need this in other places in the next commits.
2b0b08d: Delete unnecessary checks from callhelpers.
56e4ad8: Do not check return types in CanDeduplicateCode.
GC info v.2 has this information and it is checked in another place.
f96c1a0: Change ComPlusMethodFrame to use the new function.
92708d4: Change gccover.cpp to use GetReturnKindFromMethodTable.
6930780: Delete RETURNTYPE.
fcb3ee4: Add check to ComPlusMethodFrame.
2e6011d: Delete check from threadsuspend.
codeInfo->GetCodeManager()->GetReturnKind(gcInfoToken) must always return a valid kind nowdays (it could return an invalid lind only when GC Info v2 was not available).