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

JitEE interface additions to support object stack allocation. #20283

Merged

Conversation

erozenfeld
Copy link
Member

Added two methods to JitEE interface: getHeapClassSize and classHasFinalizer.

They are not expected to be called when R2R compiling (they assert and return E_NOTIMPL).
Implementing them so that they are robust for versioning is a future item.

This work is tracked by #20253.

@erozenfeld
Copy link
Member Author

@echesakov @AndyAyersMS @jkotas @dotnet/jit-contrib PTAL

MethodTable* pMT = VMClsHnd.GetMethodTable();
_ASSERTE(pMT);
_ASSERTE(!pMT->IsValueType());
result = pMT->GetBaseSize();
Copy link
Member

Choose a reason for hiding this comment

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

I think this should return GetNumInstanceFieldBytes(). GetBaseSize has extra padding for minimum object size. You should not need this padding for stack allocated objects.

Copy link
Member Author

Choose a reason for hiding this comment

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

I changed this to GetNumInstanceFieldBytes() + OBJECT_SIZE to account for method table pointer.

}
#endif

DWORD size = m_pEEJitInfo->getHeapClassSize(cls);
Copy link
Member

Choose a reason for hiding this comment

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

Why not just return m_pEEJitInfo->getHeapClassSize(cls); ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

BOOL ZapInfo::classHasFinalizer(CORINFO_CLASS_HANDLE cls)
{
#ifdef FEATURE_READYTORUN_COMPILER
if (IsReadyToRunCompilation())
Copy link
Member

Choose a reason for hiding this comment

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

It would be better to name this method canAllocateOnStack instead to encapsulate the policy on the EE-size.

The classes from the same version bubble can be allocated on stack just fine, even with R2R.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's not enough that the class being stack-allocated is from the same version bubble. I believe we need to check IsInheritanceChainLayoutFixedInCurrentVersionBubble here.

Copy link
Member

Choose a reason for hiding this comment

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

It is fine to just return false for R2R here, for now.

Copy link
Member Author

Choose a reason for hiding this comment

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

Do you think returning true if IsInheritanceChainLayoutFixedInCurrentVersionBubble returns true is incorrect?

Copy link
Member

Choose a reason for hiding this comment

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

Do you think returning true if IsInheritanceChainLayoutFixedInCurrentVersionBubble returns true is incorrect?

Yes, it should be correct. Feel free to add it if you would like to make work properly right away.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

CORINFO_CLASS_HANDLE cls
) = 0;

virtual BOOL classHasFinalizer(
Copy link
Member

Choose a reason for hiding this comment

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

What is the usage pattern of these method going to be? Is getHeapClassSize going to be always called right after classHasFinalizer succeeded? If it is the case, the two methods can be combined into one to reduce chattiness.

Copy link
Member Author

Choose a reason for hiding this comment

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

If classHasFinalizer returns true, getHeapClassSize won't be called.
If classHasFinalizer returns false, getHeapClassSize may or may not be called depending on the results of escape analysis.

Copy link
Member Author

Choose a reason for hiding this comment

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

I can replace these methods with
BOOL canAllocateClassOnStack(CORINFO_CLASS_HANDLE cls, unsigned* classSize)
to reduce chattiness. To make it cheaper it can set classSize to 0 when it returns FALSE.

Copy link
Member Author

Choose a reason for hiding this comment

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

I kept two methods but replaced classHasFinalizer with canAllocateOnStack.

Copy link
Member

@AndyAyersMS AndyAyersMS left a comment

Choose a reason for hiding this comment

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

Agree with Jan's feedback. Crossgen can just delegate down and R2R policy embedded in the main jit interface implementation.

You can see examples of version bubble checks in other parts of the jit interface, eg at the tail end of resolveVirtualMethodHelper.

@erozenfeld
Copy link
Member Author

@jkotas @AndyAyersMS I addressed all feedback, PTAL.

Copy link
Member

@AndyAyersMS AndyAyersMS left a comment

Choose a reason for hiding this comment

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

Looks good, just one question for follow-up.

src/vm/jitinterface.cpp Show resolved Hide resolved
@@ -2383,6 +2383,15 @@ class ICorStaticInfo
CORINFO_CLASS_HANDLE cls
Copy link
Member

Choose a reason for hiding this comment

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

Rev JIT/EE interface GUID?

Copy link
Member

Choose a reason for hiding this comment

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

(Look for JITEEVersionIdentifier)

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

@erozenfeld
Copy link
Member Author

@dotnet-bot test Ubuntu arm Cross Checked Innerloop Build and Test

src/vm/jitinterface.cpp Show resolved Hide resolved
src/vm/jitinterface.cpp Show resolved Hide resolved
Add two methods to JitEE interface: getHeapClassSize and canAllocateOnStack.

Change JITEEVersionIdentifier.
@erozenfeld erozenfeld force-pushed the ObjectStackAllocationJitInterface branch from cc75061 to ff47405 Compare October 8, 2018 20:31
@erozenfeld
Copy link
Member Author

@dotnet-bot test OSX10.12 x64 Checked Innerloop Build and Test
@dotnet-bot test Ubuntu x64 Checked CoreFX Tests
@dotnet-bot test Windows_NT arm64 Cross Checked Innerloop Build and Test
@dotnet-bot Windows_NT x64 Checked CoreFX Tests
@dotnet-bot Windows_NT x64 Release CoreFX Tests

@erozenfeld
Copy link
Member Author

@dotnet-bot test Windows_NT x64 Checked CoreFX Tests
@dotnet-bot test Windows_NT x64 Release CoreFX Tests

@erozenfeld
Copy link
Member Author

@dotnet-bot test Windows_NT arm64 Cross Checked Innerloop Build and Test

1 similar comment
@erozenfeld
Copy link
Member Author

@dotnet-bot test Windows_NT arm64 Cross Checked Innerloop Build and Test

@erozenfeld
Copy link
Member Author

Windows_NT arm64 Cross Checked Innerloop Build and Test failure is a known issue.

@erozenfeld erozenfeld merged commit 5f9f374 into dotnet:master Oct 11, 2018
A-And pushed a commit to A-And/coreclr that referenced this pull request Nov 20, 2018
…#20283)

Add two methods to JitEE interface: getHeapClassSize and canAllocateOnStack.

Change JITEEVersionIdentifier.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants