Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
9c15c1f
Allocate Type objects on Frozen Heap
EgorBo Sep 13, 2022
232033b
Mitigate perf regressions
EgorBo Sep 13, 2022
f63c941
clean up
EgorBo Sep 13, 2022
841e9c7
fix build issue?
EgorBo Sep 14, 2022
f168d13
Fix eeGetCPString for string literals in JitDisasm
EgorBo Sep 14, 2022
2f50121
Merge branch 'main' of github.com:dotnet/runtime into foh-type-objects
EgorBo Sep 14, 2022
3e6d3ba
clean up
EgorBo Sep 14, 2022
c939027
Merge branch 'main' of github.com:dotnet/runtime into foh-type-objects
EgorBo Sep 14, 2022
c8512a9
Update src/coreclr/jit/compiler.h
EgorBo Sep 17, 2022
bad7cc4
Merge branch 'main' of github.com:dotnet/runtime into foh-type-objects
EgorBo Sep 17, 2022
9d8526e
Address some of the feedback [WIP]
EgorBo Sep 17, 2022
18e1cd4
Address feedback
EgorBo Sep 17, 2022
a7fea6d
Fix compilation
EgorBo Sep 17, 2022
f2afedc
Introduce `objectToString` JIT-EE API
EgorBo Sep 17, 2022
6a8cedf
Update src/coreclr/vm/methodtable.cpp
EgorBo Sep 17, 2022
677f94b
check for unloadability in GetPinnedManagedClassObjectIfExists
EgorBo Sep 17, 2022
15bcad1
Merge branch 'foh-type-objects' of github.com:EgorBo/runtime-1 into f…
EgorBo Sep 17, 2022
81bacbb
Since I still have to check CanUnload I guess I don't need the bit test
EgorBo Sep 17, 2022
b5b7c98
Address feedback
EgorBo Sep 17, 2022
608e6c9
Add more temp debug checks for ci
EgorBo Sep 17, 2022
be063b8
Check if it reproduces because of jit
EgorBo Sep 18, 2022
59af88b
Check if it reproduces because of jit
EgorBo Sep 18, 2022
a8e0786
Ah, facepalm
EgorBo Sep 18, 2022
1f9a348
Clean up
EgorBo Sep 18, 2022
2fd4384
Address Jan's feedback
EgorBo Sep 18, 2022
8f2a767
Oops, a typo
EgorBo Sep 18, 2022
b4b7128
Share logic to extract OBJECTREF from m_hExposedClassObject
EgorBo Sep 18, 2022
a2ca5b1
Merge branch 'main' of github.com:dotnet/runtime into foh-type-objects
EgorBo Sep 19, 2022
fd099a2
Produce better asm code for JIT_GetRuntimeType
EgorBo Sep 19, 2022
64e7171
Merge branch 'main' of github.com:dotnet/runtime into foh-type-objects
EgorBo Sep 20, 2022
ac405a1
Merge branch 'main' of github.com:dotnet/runtime into foh-type-objects
EgorBo Sep 20, 2022
7ab7bd1
Address feedback
EgorBo Sep 20, 2022
895e9f5
Update src/coreclr/vm/jitinterface.cpp
EgorBo Sep 20, 2022
bcd47b1
Address feedback
EgorBo Sep 20, 2022
c217579
Update src/coreclr/vm/methodtable.cpp
EgorBo Sep 21, 2022
253747e
Address feedback: the bit is always there so we can do ` - 1`
EgorBo Sep 21, 2022
ca6c69a
Address feedback
EgorBo Sep 21, 2022
93ef525
Update src/coreclr/vm/methodtable.cpp
jkotas Sep 21, 2022
7394e1e
Update src/coreclr/jit/ee_il_dll.cpp
EgorBo Sep 21, 2022
f6055b9
remove null-termination from api
EgorBo Sep 21, 2022
57b1477
address feedback
EgorBo Sep 21, 2022
e9a396f
Address feedback
EgorBo Sep 21, 2022
4fbb894
Pass utf8 string in objectToString
EgorBo Sep 21, 2022
7476a68
remove char16_t left over
EgorBo Sep 21, 2022
bc2292b
fix compilation warning
EgorBo Sep 22, 2022
7bf7e0e
Update gentree.cpp
EgorBo Sep 22, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Address feedback
  • Loading branch information
EgorBo committed Sep 20, 2022
commit bcd47b1d39e923ed2695f9f6cd3be73e13b78928
2 changes: 1 addition & 1 deletion src/coreclr/vm/methodtable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4219,7 +4219,7 @@ OBJECTREF MethodTable::GetManagedClassObject()
{
// Make sure that we have been restored
CheckRestore();
TypeHandle::AllocateManagedClassObject(GetLoaderAllocator(), (RUNTIMETYPEHANDLE*)&GetWriteableData()->m_hExposedClassObject, TypeHandle(this));
TypeHandle(this).AllocateManagedClassObject((RUNTIMETYPEHANDLE*)&GetWriteableData()->m_hExposedClassObject);
}
RETURN(GetManagedClassObjectIfExists());
}
Expand Down
5 changes: 3 additions & 2 deletions src/coreclr/vm/methodtable.inl
Original file line number Diff line number Diff line change
Expand Up @@ -1345,9 +1345,10 @@ FORCEINLINE OBJECTREF MethodTable::GetManagedClassObjectIfExists()
const RUNTIMETYPEHANDLE handle = GetWriteableData_NoLogging()->m_hExposedClassObject;

// First, check if we have a cached reference to an effectively pinned (allocated on FOH) object
if (handle != NULL && (handle & 1) == 0)
if (handle & 1)
{
return (OBJECTREF)handle;
// Clear the "is pinned object" bit from the managed reference
return (OBJECTREF)((handle >> 1) << 1); // C++ compiler is expected to emit "and reg, mask"
}

OBJECTREF retVal;
Expand Down
5 changes: 2 additions & 3 deletions src/coreclr/vm/typedesc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ OBJECTREF ParamTypeDesc::GetManagedClassObject()

if (m_hExposedClassObject == NULL)
{
TypeHandle::AllocateManagedClassObject(GetLoaderAllocator(), &m_hExposedClassObject, TypeHandle(this));
TypeHandle(this).AllocateManagedClassObject(&m_hExposedClassObject);
}
return GetManagedClassObjectIfExists();
}
Expand Down Expand Up @@ -1579,7 +1579,6 @@ BOOL TypeVarTypeDesc::SatisfiesConstraints(SigTypeContext *pTypeContextOfConstra
return TRUE;
}


OBJECTREF TypeVarTypeDesc::GetManagedClassObject()
{
CONTRACTL {
Expand All @@ -1595,7 +1594,7 @@ OBJECTREF TypeVarTypeDesc::GetManagedClassObject()

if (m_hExposedClassObject == NULL)
{
TypeHandle::AllocateManagedClassObject(GetLoaderAllocator(), &m_hExposedClassObject, TypeHandle(this));
TypeHandle(this).AllocateManagedClassObject(&m_hExposedClassObject);
}
return GetManagedClassObjectIfExists();
}
Expand Down
32 changes: 19 additions & 13 deletions src/coreclr/vm/typehandle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,26 +353,31 @@ bool TypeHandle::IsManagedClassObjectPinned() const
return !GetLoaderAllocator()->CanUnload() || IsFnPtrType();
}

void TypeHandle::AllocateManagedClassObject(LoaderAllocator* allocator, RUNTIMETYPEHANDLE* pDest, TypeHandle type)
void TypeHandle::AllocateManagedClassObject(RUNTIMETYPEHANDLE* pDest)
{
REFLECTCLASSBASEREF refClass = NULL;

PTR_LoaderAllocator allocator = GetLoaderAllocator();

if (!allocator->CanUnload())
{
// Allocate RuntimeType on a frozen segment
// Take a lock here since we don't want to allocate redundant objects which won't be collected
CrstHolder exposedClassLock(AppDomain::GetMethodTableExposedClassObjectLock());

if (*pDest == NULL)
{
// Allocate RuntimeType on a frozen segment
// Take a lock here since we don't want to allocate redundant objects which won't be collected

FrozenObjectHeapManager* foh = SystemDomain::GetFrozenObjectHeapManager();
Object* obj = foh->TryAllocateObject(g_pRuntimeTypeClass, g_pRuntimeTypeClass->GetBaseSize());
_ASSERTE(obj != NULL);
// Since objects are aligned we can use the lowest bit as a storage for "is pinned object" flag
_ASSERTE((((SSIZE_T)obj) & 1) == 0);
refClass = (REFLECTCLASSBASEREF)ObjectToOBJECTREF(obj);
refClass->SetType(type);
*pDest = (RUNTIMETYPEHANDLE)obj;
refClass->SetType(*this);
RUNTIMETYPEHANDLE handle = (RUNTIMETYPEHANDLE)obj;
// Set the bit to 1 (we'll have to reset it before use)
handle |= 1;
*pDest = handle;
}
}
else
Expand All @@ -381,9 +386,8 @@ void TypeHandle::AllocateManagedClassObject(LoaderAllocator* allocator, RUNTIMET
refClass = (REFLECTCLASSBASEREF)AllocateObject(g_pRuntimeTypeClass);
refClass->SetKeepAlive(allocator->GetExposedObject());
LOADERHANDLE exposedClassObjectHandle = allocator->AllocateHandle(refClass);
// Set the lowest bit, we use it GetPinnedManagedClassObjectIfExists as a fast detection of the unloadable context
exposedClassObjectHandle |= 1;
refClass->SetType(type);
_ASSERTE((exposedClassObjectHandle & 1) == 0);
refClass->SetType(*this);

// Let all threads fight over who wins using InterlockedCompareExchange.
// Only the winner can set m_ExposedClassObject from NULL.
Expand All @@ -403,9 +407,10 @@ OBJECTREF TypeHandle::GetManagedClassObjectFromHandleFast(RUNTIMETYPEHANDLE hand
// For a non-unloadable context, handle is expected to be either null (is not cached yet)
// or be a direct pointer to a frozen RuntimeType object

if (handle != NULL && (handle & 1) == 0)
if (handle & 1)
{
return (OBJECTREF)handle;
// Clear the "is pinned object" bit from the managed reference
return (OBJECTREF)((handle >> 1) << 1); // C++ compiler is expected to emit "and reg, mask"
Copy link
Member

Choose a reason for hiding this comment

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

Why is (x >> 1) << 1 and hoping for an optimization to kick in better, than doing - 1 like what the existing code does?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, indeed! with -1 it's now lea rax, [rdx-1] instead of and rdx, 0FFFFFFFFFFFFFFFEh

}
return NULL;
}
Expand All @@ -415,9 +420,10 @@ OBJECTREF TypeHandle::GetManagedClassObjectFromHandle(LoaderAllocator* allocator
LIMITED_METHOD_CONTRACT;

// First, check if we have a cached reference to an effectively pinned (allocated on FOH) object
if (handle != NULL && (handle & 1) == 0)
if (handle & 1)
{
return (OBJECTREF)handle;
// Clear the "is pinned object" bit from the managed reference
return (OBJECTREF)((handle >> 1) << 1); // C++ compiler is expected to emit "and reg, mask"
}

OBJECTREF retVal;
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/vm/typehandle.h
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ class TypeHandle
// represents a not-unloadable context, it allocates the object on a frozen segment
// so the direct reference will be stored to the pDest argument. In case of unloadable
// context, an index to the pinned table will be saved.
static void AllocateManagedClassObject(LoaderAllocator* allocator, RUNTIMETYPEHANDLE* pDest, TypeHandle type);
void AllocateManagedClassObject(RUNTIMETYPEHANDLE* pDest);
static OBJECTREF GetManagedClassObjectFromHandleFast(RUNTIMETYPEHANDLE handle);
static OBJECTREF GetManagedClassObjectFromHandle(LoaderAllocator* allocator, RUNTIMETYPEHANDLE handle);
#endif
Expand Down