summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Kotas <jkotas@microsoft.com>2017-04-17 17:37:09 -0500
committerGitHub <noreply@github.com>2017-04-17 17:37:09 -0500
commite0486761d6c019cb696dcd35aeecc031b1d01eef (patch)
treee6feee5aba340225ceee743cdaac51ef0d05106f
parent97079bd97cb1d28aa8b3287850e6894936f56d56 (diff)
downloadcoreclr-e0486761d6c019cb696dcd35aeecc031b1d01eef.tar.gz
coreclr-e0486761d6c019cb696dcd35aeecc031b1d01eef.tar.bz2
coreclr-e0486761d6c019cb696dcd35aeecc031b1d01eef.zip
Improve performance of Object.GetType for arrays (#10992)
* Improve performance of Object.GetType for arrays Cache managed Type object on MethodTable for arrays. Makes Object.GetType for arrays about 5x faster.
-rw-r--r--src/classlibnative/bcltype/objectnative.cpp6
-rw-r--r--src/vm/methodtable.h8
-rw-r--r--src/vm/methodtable.inl4
-rw-r--r--src/vm/typedesc.cpp6
4 files changed, 7 insertions, 17 deletions
diff --git a/src/classlibnative/bcltype/objectnative.cpp b/src/classlibnative/bcltype/objectnative.cpp
index 82b189d5c8..a90a37a692 100644
--- a/src/classlibnative/bcltype/objectnative.cpp
+++ b/src/classlibnative/bcltype/objectnative.cpp
@@ -198,12 +198,6 @@ NOINLINE static Object* GetClassHelper(OBJECTREF objRef)
TypeHandle typeHandle = objRef->GetTypeHandle();
OBJECTREF refType = NULL;
- // Arrays go down this slow path, at least don't do the full HelperMethodFrame setup
- // if we are fetching the cached entry.
- refType = typeHandle.GetManagedClassObjectFast();
- if (refType != NULL)
- return OBJECTREFToObject(refType);
-
HELPER_METHOD_FRAME_BEGIN_RET_ATTRIB_1(Frame::FRAME_ATTR_EXACT_DEPTH|Frame::FRAME_ATTR_CAPTURE_DEPTH_2, refType);
refType = typeHandle.GetManagedClassObject();
diff --git a/src/vm/methodtable.h b/src/vm/methodtable.h
index d5cb5ba866..df60fca09d 100644
--- a/src/vm/methodtable.h
+++ b/src/vm/methodtable.h
@@ -414,19 +414,13 @@ struct MethodTableWriteableData
};
DWORD m_dwFlags; // Lot of empty bits here.
-private:
/*
* m_hExposedClassObject is LoaderAllocator slot index to
- * a RuntimeType instance for this class. But
- * do NOT use it for Arrays or remoted objects! All arrays of objects
- * share the same MethodTable/EEClass.
- * @GENERICS: this used to live in EEClass but now lives here because it is per-instantiation data
- * only set in code:MethodTable.GetManagedClassObject
+ * a RuntimeType instance for this class.
*/
LOADERHANDLE m_hExposedClassObject;
#ifdef _DEBUG
-public:
// to avoid verify same method table too many times when it's not changing, we cache the GC count
// on which the method table is verified. When fast GC STRESS is turned on, we only verify the MT if
// current GC count is bigger than the number. Note most thing which will invalidate a MT will require a
diff --git a/src/vm/methodtable.inl b/src/vm/methodtable.inl
index c762512bf1..9b72d24d0f 100644
--- a/src/vm/methodtable.inl
+++ b/src/vm/methodtable.inl
@@ -1770,10 +1770,6 @@ FORCEINLINE OBJECTREF MethodTable::GetManagedClassObjectIfExists()
return NULL;
}
- // Only code:MethodTable::GetManagedClassObject sets m_pExposedClassObject and it insures that
- // remoted objects and arrays don't get in.
- _ASSERTE(!IsArray() && !IsTransparentProxy());
-
COMPILER_ASSUME(retVal != NULL);
return retVal;
}
diff --git a/src/vm/typedesc.cpp b/src/vm/typedesc.cpp
index 9d84c01488..d05cb558bc 100644
--- a/src/vm/typedesc.cpp
+++ b/src/vm/typedesc.cpp
@@ -837,6 +837,12 @@ OBJECTREF ParamTypeDesc::GetManagedClassObject()
pLoaderAllocator->ClearHandle(hExposedClassObject);
}
+ if (OwnsTemplateMethodTable())
+ {
+ // Set the handle on template methodtable as well to make Object.GetType for arrays take the fast path
+ EnsureWritablePages(m_TemplateMT.GetValue()->GetWriteableDataForWrite())->m_hExposedClassObject = m_hExposedClassObject;
+ }
+
// Log the TypeVarTypeDesc access
g_IBCLogger.LogTypeMethodTableWriteableAccess(&th);