Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

new JitEE interface method: expandRawHandleIntrinsic #12071

Merged
merged 11 commits into from
Jun 6, 2017

Conversation

sandreenko
Copy link

It is implemented only in CoreRT and used in importer.

Delete isDelegateCreationAllowed because it is unused and I was waiting for a JitEEinterface change
to delete it.

@@ -6675,6 +6703,12 @@ var_types Compiler::impImportCall(OPCODE opcode,
call = impIntrinsic(newobjThis, clsHnd, methHnd, sig, pResolvedToken->token, readonlyCall,
(canTailCall && (tailCall != 0)), &intrinsicID);

if (compInlineResult->IsFailure())
Copy link
Author

@sandreenko sandreenko Jun 3, 2017

Choose a reason for hiding this comment

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

It is because now we call impLookupToTree inside impIntrinsic, that can set the Failure if it is compIsForInlining() and we need a runtime lookup.

@sandreenko
Copy link
Author

I didn't notice any order in these files (and code convention too), so I just added my method right after the last added resolveVirtualMethod.

{
assert(IsTargetAbi(CORINFO_CORERT_ABI)); // Only CoreRT supports it.
CORINFO_RESOLVED_TOKEN resolvedToken;
resolvedToken.hMethod = method;
Copy link
Author

Choose a reason for hiding this comment

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

@MichalStrehovsky Is it necessary to set hMethod here? It is usually an output argument for resolvedToken.

Copy link
Member

Choose a reason for hiding this comment

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

You can null it out. We can fetch that from token/tokenScope (and in fact, we need do it from the token anyway if the method is canonical (and it pretty much always will be canonical)).

Copy link
Author

Choose a reason for hiding this comment

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

Cool, done.

@sandreenko
Copy link
Author

PTAL @dotnet/jit-contrib, @MichalStrehovsky. @jkotas.

@@ -2111,13 +2121,6 @@ class ICorStaticInfo
BOOL *pfIsOpenDelegate /* is the delegate open */
) = 0;

// Determines whether the delegate creation obeys security transparency rules
Copy link
Member

Choose a reason for hiding this comment

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

While you are on it you can also delete getAddrModuleDomainID ... I have noticed earlier today that it is also unused.

Copy link
Author

Choose a reason for hiding this comment

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

Thanks, done.

@jkotas
Copy link
Member

jkotas commented Jun 3, 2017

LGTM

@sandreenko
Copy link
Author

sandreenko commented Jun 3, 2017

I think I do not understand the purpose of jit\ICorJitInfo_API_names.h, @AndyAyersMS do you know that? Why is not resolveVirtualMethod there?

{
assert(IsTargetAbi(CORINFO_CORERT_ABI)); // Only CoreRT supports it.
CORINFO_RESOLVED_TOKEN resolvedToken;
resolvedToken.hMethod = method;
Copy link
Member

Choose a reason for hiding this comment

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

You can null it out. We can fetch that from token/tokenScope (and in fact, we need do it from the token anyway if the method is canonical (and it pretty much always will be canonical)).

if (eeTypePtrOfNode == nullptr)
return nullptr;

unsigned eeSlot = lvaGrabTemp(true DEBUGARG("eeTypePtrOf"));
Copy link
Member

Choose a reason for hiding this comment

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

Nit: could you remove the references to EETypePtrOf?

While the original motivation for this is to allow having a EETypePtr EETypePtrOf<T>() method that intrinsically expands to "raw value of the TypeHandle of T", I'm already thinking of using this for IntPtr DefaultConstructorOf<T>() that expands to "pointer to the default constructor of type T" (to be used in the implementation of Activator.CreateInstance<T>). The API surface is general purpose to allow adding other interesting cases without requiring RyuJIT to learn about them.

Copy link
Author

Choose a reason for hiding this comment

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

Ok, is rawPointer an appropriate name?

impAssignTempGen(eeSlot, eeTypePtrOfNode, clsHnd, (unsigned)CHECK_SPILL_NONE);
GenTreePtr lclVar = gtNewLclvNode(eeSlot, TYP_I_IMPL);
GenTreePtr lclVarAddr = gtNewOperNode(GT_ADDR, TYP_I_IMPL, lclVar);
var_types resultType = JITtype2varType(sig->retType);
Copy link
Member

Choose a reason for hiding this comment

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

Would it be possible to add some kind of assert that the return type of the method is interchangeable with TYP_I_IMPL? (either an IntPtr, or a pointer-sized struct that is ideally not a GC pointer).

Copy link
Author

Choose a reason for hiding this comment

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

I am not sure about a GC pointer check.
I added noway_assert that the return tree has the same size as TYP_I_IMPL.

Sergey Andreenko added 2 commits June 2, 2017 18:49
and the additional assert. It should be noway_assert, because CoreRT
doesn't use this intrinsic in the debug mode.
@sandreenko
Copy link
Author

@dotnet-bot test Windows_NT arm64 Checked pri1r2r

fot the future usages.
@sandreenko
Copy link
Author

@dotnet-bot test Windows_NT arm64 Checked pri1r2r

@sandreenko
Copy link
Author

@dotnet-bot test Windows_NT Checked pri1r2r

@BruceForstall
Copy link
Member

Please port these changes to the desktop and build at least x86/x64/arm64 checked/release there before merging this (to ensure there are no desktop-specific build problems that will ensue when this is mirrored).

case CORINFO_INTRINSIC_GetRawHandle:
{
assert(IsTargetAbi(CORINFO_CORERT_ABI)); // Only CoreRT supports it.
CORINFO_RESOLVED_TOKEN resolvedToken;
Copy link
Member

Choose a reason for hiding this comment

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

Seems like this should be a noway_assert

Copy link
Author

Choose a reason for hiding this comment

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

Fixed

@@ -189,17 +189,6 @@ BOOL WrapICorJitInfo::isCompatibleDelegate(
return temp;
}

BOOL WrapICorJitInfo::isDelegateCreationAllowed(
CORINFO_CLASS_HANDLE delegateHnd,
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't you add a new case for expandRawHandleIntrinsic() in this file?

Copy link
Author

Choose a reason for hiding this comment

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

Fixed

@@ -20,7 +20,6 @@ DEF_CLR_API(getUnmanagedCallConv)
DEF_CLR_API(pInvokeMarshalingRequired)
DEF_CLR_API(satisfiesMethodConstraints)
DEF_CLR_API(isCompatibleDelegate)
DEF_CLR_API(isDelegateCreationAllowed)
DEF_CLR_API(isInstantiationOfVerifiedGeneric)
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't you add a new case for expandRawHandleIntrinsic() in this file?

Copy link
Author

Choose a reason for hiding this comment

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

I am not sure, I asked @AndyAyersMS in the message above why there is no resolveVirtualMethod there. Looks like we do not test code under MEASURE_CLRAPI_CALLS 1.

Copy link
Member

Choose a reason for hiding this comment

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

This was created by Peter Kukol to measure JIT-EE interface overhead. It's probably reasonable to keep it working as close as possible, even if we don't actively build with it regularly.

Copy link
Author

Choose a reason for hiding this comment

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

Ok, I fixed that for both methods. I checked that it is possible to build VM with this flag on.

@BruceForstall
Copy link
Member

When this is merged, please be prepared to immediately do a desktop SuperPMI recollection.

Sergey Andreenko added 2 commits June 5, 2017 16:43
add resolveVirtualMethod and expandRawHandleIntrinsic there.
@sandreenko
Copy link
Author

Please port these changes to the desktop and build at least x86/x64/arm64 checked/release there before merging this (to ensure there are no desktop-specific build problems that will ensue when this is mirrored).

Done for checked, it is in progress for release.

@sandreenko sandreenko merged commit b23a11e into dotnet:master Jun 6, 2017
MichalStrehovsky added a commit to dotnet/corert that referenced this pull request Jun 7, 2017
CoreRT side of dotnet/coreclr#12071.

I also took this as an opportunity to clean up how we use `runtimeLookupArgs` - we now consistently fill it out instead of trying to figure out what to put there based on the token and ready to run helper ID.
@karelz karelz modified the milestone: 2.1.0 Aug 28, 2017
@sandreenko sandreenko deleted the jitEEInterfaceChanges branch November 2, 2018 22:27
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.

6 participants