Skip to content
This repository has been archived by the owner on Jun 14, 2024. It is now read-only.

Performance improvements, memory leak and misc other fixes and drop binary size by ~4% #11

Merged
merged 21 commits into from
Jun 13, 2016
Merged
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
6abaaa9
Fix CimInstance memory leak
cbnilrem Jun 8, 2016
6624efa
Plug minor test gap
cbnilrem Jun 8, 2016
98a7c74
Cache marshalled function tables to improve performance
cbnilrem Jun 8, 2016
5ab7df4
Add base class for MI objects and start transitioning some classes to it
cbnilrem Jun 8, 2016
78e7d0e
Move misc remaining Ptr/OutPtr structures to their logical containers
cbnilrem Jun 8, 2016
e2f0d8e
Split MI_NativeObject to create MI_NativeObjectWithFT
cbnilrem Jun 8, 2016
18bf441
Switch MI_ClassDecl to use MI_NativeObject
cbnilrem Jun 9, 2016
3318f55
Merge branch 'master' into cbnilrem-refactor
cbnilrem Jun 9, 2016
b0d7681
Switch most remaining objects over to MI_NativeObject
cbnilrem Jun 9, 2016
3cc41f7
Move Ptr/OutPtr constructs to MI_NativeObject
cbnilrem Jun 9, 2016
d7b748d
Derive MI_Serializer from MI_NativeObject
cbnilrem Jun 9, 2016
5a8917b
Derive MI_Deserializer from MI_NativeObject
cbnilrem Jun 9, 2016
c0c4965
Push information about native members into common base class
cbnilrem Jun 10, 2016
f2ec90b
Move session creation callbacks to their own file
cbnilrem Jun 10, 2016
7a18cb2
Merge branch 'master' into cbnilrem-refactor
cbnilrem Jun 10, 2016
2de2367
Derive MI_Value from MI_NativeObject
cbnilrem Jun 10, 2016
93a198b
Move some MI_Array understanding to MI_Array
cbnilrem Jun 10, 2016
546bc9d
Merge master
cbnilrem Jun 10, 2016
a73bf2d
Make MI_ExtendedArray tolerate null arrays on write
cbnilrem Jun 10, 2016
420d35d
Move MI_DeserializerCallbacks to its own file
cbnilrem Jun 10, 2016
a05ab6d
Allow MI_Value reference properties to be null
cbnilrem Jun 11, 2016
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
Push information about native members into common base class
cbnilrem committed Jun 10, 2016

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit c0c4965563e245c97bbe75324c6e4dd31b5adedc
29 changes: 13 additions & 16 deletions src/Microsoft.Management.Infrastructure/Native/MI_Application.cs
Original file line number Diff line number Diff line change
@@ -5,6 +5,19 @@ namespace Microsoft.Management.Infrastructure.Native
{
internal class MI_Application : MI_NativeObjectWithFT<MI_Application.MI_ApplicationFT>
{
[StructLayout(LayoutKind.Sequential, CharSet = MI_PlatformSpecific.AppropriateCharSet)]
private struct MI_ApplicationMembers
{
internal UInt64 reserved1;
internal IntPtr reserved2;
internal IntPtr ft;
}

static MI_Application()
{
CheckMembersTableMatchesNormalLayout<MI_ApplicationMembers>("ft");
}

internal static MI_Result Initialize(string applicationId, out MI_Instance extendedError, out MI_Application application)
{
MI_Application applicationLocal = MI_Application.NewDirectPtr();
@@ -46,18 +59,6 @@ out MI_Session session
session = sessionLocal;
return resultLocal;
}

[StructLayout(LayoutKind.Sequential, CharSet = MI_PlatformSpecific.AppropriateCharSet)]
private struct MI_ApplicationMembers
{
internal UInt64 reserved1;
internal IntPtr reserved2;
internal IntPtr ft;
}

// Marshal implements these with Reflection - pay this hit only once
private static int MI_ApplicationMembersFTOffset = (int)Marshal.OffsetOf<MI_ApplicationMembers>("ft");
private static int MI_ApplicationMembersSize = Marshal.SizeOf<MI_ApplicationMembers>();

private MI_Application(bool isDirect) : base(isDirect)
{
@@ -84,10 +85,6 @@ internal static MI_Application NewFromDirectPtr(IntPtr ptr)

internal static MI_Application Null { get { return null; } }

protected override int FunctionTableOffset { get { return MI_ApplicationMembersFTOffset; } }

protected override int MembersSize { get { return MI_ApplicationMembersSize; } }

internal MI_Result Close()
{
return this.ft.Close(this);
Original file line number Diff line number Diff line change
@@ -5,6 +5,19 @@ namespace Microsoft.Management.Infrastructure.Native
{
internal class MI_DestinationOptions : MI_NativeObjectWithFT<MI_DestinationOptions.MI_DestinationOptionsFT>
{
[StructLayout(LayoutKind.Sequential, CharSet = MI_PlatformSpecific.AppropriateCharSet)]
private struct MI_DestinationOptionsMembers
{
internal UInt64 reserved1;
internal IntPtr reserved2;
internal IntPtr ft;
}

static MI_DestinationOptions()
{
CheckMembersTableMatchesNormalLayout<MI_DestinationOptionsMembers>("ft");
}

internal MI_Result SetInterval(
string optionName,
MI_Interval value,
@@ -36,18 +49,6 @@ out MI_DestinationOptionsFlags flags
return resultLocal;
}

[StructLayout(LayoutKind.Sequential, CharSet = MI_PlatformSpecific.AppropriateCharSet)]
private struct MI_DestinationOptionsMembers
{
internal UInt64 reserved1;
internal IntPtr reserved2;
internal IntPtr ft;
}

// Marshal implements these with Reflection - pay this hit only once
private static int MI_DestinationOptionsMembersFTOffset = (int)Marshal.OffsetOf<MI_DestinationOptionsMembers>("ft");
private static int MI_DestinationOptionsMembersSize = Marshal.SizeOf<MI_DestinationOptionsMembers>();

private MI_DestinationOptions(bool isDirect) : base(isDirect)
{
}
@@ -73,10 +74,6 @@ internal static MI_DestinationOptions NewFromDirectPtr(IntPtr ptr)

internal static MI_DestinationOptions Null { get { return null; } }

protected override int FunctionTableOffset { get { return MI_DestinationOptionsMembersFTOffset; } }

protected override int MembersSize { get { return MI_DestinationOptionsMembersSize; } }

internal void Delete()
{
this.ft.Delete(this);
Original file line number Diff line number Diff line change
@@ -5,6 +5,16 @@ namespace Microsoft.Management.Infrastructure.Native
{
internal abstract class MI_NativeObject
{
[StructLayout(LayoutKind.Sequential, CharSet = MI_PlatformSpecific.AppropriateCharSet)]
protected struct MI_NativeObjectNormalMembersLayout
{
internal UInt64 reserved1;
internal IntPtr reserved2;
internal IntPtr ft;
}

protected static readonly int MI_NativeObjectNormalMembersLayoutSize = Marshal.SizeOf<MI_NativeObjectNormalMembersLayout>();

[StructLayout(LayoutKind.Sequential, CharSet = MI_PlatformSpecific.AppropriateCharSet)]
internal struct DirectPtr
{
@@ -75,7 +85,7 @@ protected MI_NativeObject(IntPtr existingPtr) : this(false)
Marshal.WriteIntPtr(this.allocatedData, existingPtr);
}

protected abstract int MembersSize { get; }
protected virtual int MembersSize { get { return MI_NativeObjectNormalMembersLayoutSize; } }

internal static ArrayPtr GetPointerArray(MI_NativeObject[] objects)
{
Original file line number Diff line number Diff line change
@@ -5,6 +5,9 @@ namespace Microsoft.Management.Infrastructure.Native
{
internal abstract class MI_NativeObjectWithFT<FunctionTableType> : MI_NativeObject where FunctionTableType : new()
{
// Marshal implements these with Reflection - pay this hit only once
protected static readonly int MI_NativeObjectNormalMembersLayoutFTOffset = (int)Marshal.OffsetOf<MI_NativeObject.MI_NativeObjectNormalMembersLayout>("ft");

public static implicit operator DirectPtr(MI_NativeObjectWithFT<FunctionTableType> instance)
{
// If the indirect pointer is zero then the object has not
@@ -49,7 +52,19 @@ private FunctionTableType MarshalFT()
return MI_FunctionTableCache.GetFTAsOffsetFromPtr<FunctionTableType>(this.Ptr, this.FunctionTableOffset);
}

protected abstract int FunctionTableOffset { get; }
protected static void CheckMembersTableMatchesNormalLayout<T>(string ftMember)
{
int actualFTOffSet = (int)Marshal.OffsetOf<T>(ftMember);
int actualMembersSize = Marshal.SizeOf<T>();

if (actualFTOffSet != MI_NativeObjectNormalMembersLayoutFTOffset ||
actualMembersSize != MI_NativeObjectNormalMembersLayoutSize)
{
throw new InvalidCastException();
}
}

protected virtual int FunctionTableOffset { get { return MI_NativeObjectNormalMembersLayoutFTOffset; } }

protected FunctionTableType ft
{
11 changes: 4 additions & 7 deletions src/Microsoft.Management.Infrastructure/Native/MI_Operation.cs
Original file line number Diff line number Diff line change
@@ -13,9 +13,10 @@ private struct MI_OperationMembers
internal IntPtr ft;
}

// Marshal implements these with Reflection - pay this hit only once
private static int MI_OperationMembersFTOffset = (int)Marshal.OffsetOf<MI_OperationMembers>("ft");
private static int MI_OperationMembersSize = Marshal.SizeOf<MI_OperationMembers>();
static MI_Operation()
{
CheckMembersTableMatchesNormalLayout<MI_OperationMembers>("ft");
}

private MI_Operation(bool isDirect) : base(isDirect)
{
@@ -46,10 +47,6 @@ internal void AssertValidInternalState()

internal static MI_Operation Null { get { return null; } }

protected override int FunctionTableOffset { get { return MI_OperationMembersFTOffset; } }

protected override int MembersSize { get { return MI_OperationMembersSize; } }

internal MI_Result Close()
{
return this.ft.Close(this);
Original file line number Diff line number Diff line change
@@ -5,6 +5,19 @@ namespace Microsoft.Management.Infrastructure.Native
{
internal class MI_OperationOptions : MI_NativeObjectWithFT<MI_OperationOptions.MI_OperationOptionsFT>
{
[StructLayout(LayoutKind.Sequential, CharSet = MI_PlatformSpecific.AppropriateCharSet)]
private struct MI_OperationOptionsMembers
{
internal UInt64 reserved1;
internal IntPtr reserved2;
internal IntPtr ft;
}

static MI_OperationOptions()
{
CheckMembersTableMatchesNormalLayout<MI_OperationOptionsMembers>("ft");
}

internal MI_Result SetInterval(
string optionName,
MI_Interval value,
@@ -36,18 +49,6 @@ out MI_OperationOptionsFlags flags
return resultLocal;
}

[StructLayout(LayoutKind.Sequential, CharSet = MI_PlatformSpecific.AppropriateCharSet)]
private struct MI_OperationOptionsMembers
{
internal UInt64 reserved1;
internal IntPtr reserved2;
internal IntPtr ft;
}

// Marshal implements these with Reflection - pay this hit only once
private static int MI_OperationOptionsMembersFTOffset = (int)Marshal.OffsetOf<MI_OperationOptionsMembers>("ft");
private static int MI_OperationOptionsMembersSize = Marshal.SizeOf<MI_OperationOptionsMembers>();

private MI_OperationOptions(bool isDirect) : base(isDirect)
{
}
@@ -73,10 +74,6 @@ internal static MI_OperationOptions NewFromDirectPtr(IntPtr ptr)

internal static MI_OperationOptions Null { get { return null; } }

protected override int FunctionTableOffset { get { return MI_OperationOptionsMembersFTOffset; } }

protected override int MembersSize { get { return MI_OperationOptionsMembersSize; } }

internal void Delete()
{
this.ft.Delete(this);
30 changes: 14 additions & 16 deletions src/Microsoft.Management.Infrastructure/Native/MI_ParameterSet.cs
Original file line number Diff line number Diff line change
@@ -5,6 +5,20 @@ namespace Microsoft.Management.Infrastructure.Native
{
internal class MI_ParameterSet : MI_NativeObjectWithFT<MI_ParameterSet.MI_ParameterSetFT>
{

[StructLayout(LayoutKind.Sequential, CharSet = MI_PlatformSpecific.AppropriateCharSet)]
private struct MI_ParameterSetMembers
{
internal UInt64 reserved1;
internal IntPtr reserved2;
internal IntPtr ft;
}

static MI_ParameterSet()
{
CheckMembersTableMatchesNormalLayout<MI_ParameterSetMembers>("ft");
}

internal MI_Result GetParameterAt(
UInt32 index,
out string name,
@@ -51,18 +65,6 @@ out UInt32 index
qualifierSet = qualifierSetLocal;
return resultLocal;
}

[StructLayout(LayoutKind.Sequential, CharSet = MI_PlatformSpecific.AppropriateCharSet)]
private struct MI_ParameterSetMembers
{
internal UInt64 reserved1;
internal IntPtr reserved2;
internal IntPtr ft;
}

// Marshal implements these with Reflection - pay this hit only once
private static int MI_ParameterSetMembersFTOffset = (int)Marshal.OffsetOf<MI_ParameterSetMembers>("ft");
private static int MI_ParameterSetMembersSize = Marshal.SizeOf<MI_ParameterSetMembers>();

private MI_ParameterSet(bool isDirect) : base(isDirect)
{
@@ -89,10 +91,6 @@ internal static MI_ParameterSet NewFromDirectPtr(IntPtr ptr)

internal static MI_ParameterSet Null { get { return null; } }

protected override int FunctionTableOffset { get { return MI_ParameterSetMembersFTOffset; } }

protected override int MembersSize { get { return MI_ParameterSetMembersSize; } }

internal MI_Result GetMethodReturnType(
out MI_Type returnType,
MI_QualifierSet qualifierSet
29 changes: 13 additions & 16 deletions src/Microsoft.Management.Infrastructure/Native/MI_QualifierSet.cs
Original file line number Diff line number Diff line change
@@ -5,6 +5,19 @@ namespace Microsoft.Management.Infrastructure.Native
{
internal class MI_QualifierSet : MI_NativeObjectWithFT<MI_QualifierSet.MI_QualifierSetFT>
{
[StructLayout(LayoutKind.Sequential, CharSet = MI_PlatformSpecific.AppropriateCharSet)]
private struct MI_QualifierSetMembers
{
internal UInt64 reserved1;
internal IntPtr reserved2;
internal IntPtr ft;
}

static MI_QualifierSet()
{
CheckMembersTableMatchesNormalLayout<MI_QualifierSetMembers>("ft");
}

internal MI_Result GetQualifier(
string name,
out MI_Type qualifierType,
@@ -47,18 +60,6 @@ out MI_Value qualifierValue
qualifierValue = qualifierValueLocal;
return resultLocal;
}

[StructLayout(LayoutKind.Sequential, CharSet = MI_PlatformSpecific.AppropriateCharSet)]
private struct MI_QualifierSetMembers
{
internal UInt64 reserved1;
internal IntPtr reserved2;
internal IntPtr ft;
}

// Marshal implements these with Reflection - pay this hit only once
private static int MI_QualifierSetMembersFTOffset = (int)Marshal.OffsetOf<MI_QualifierSetMembers>("ft");
private static int MI_QualifierSetMembersSize = Marshal.SizeOf<MI_QualifierSetMembers>();

private MI_QualifierSet(bool isDirect) : base(isDirect)
{
@@ -85,10 +86,6 @@ internal static MI_QualifierSet NewFromDirectPtr(IntPtr ptr)

internal static MI_QualifierSet Null { get { return null; } }

protected override int FunctionTableOffset { get { return MI_QualifierSetMembersFTOffset; } }

protected override int MembersSize { get { return MI_QualifierSetMembersSize; } }

internal MI_Result GetQualifierCount(
out UInt32 count
)
29 changes: 13 additions & 16 deletions src/Microsoft.Management.Infrastructure/Native/MI_Session.cs
Original file line number Diff line number Diff line change
@@ -5,6 +5,19 @@ namespace Microsoft.Management.Infrastructure.Native
{
internal class MI_Session : MI_NativeObjectWithFT<MI_Session.MI_SessionFT>
{
[StructLayout(LayoutKind.Sequential, CharSet = MI_PlatformSpecific.AppropriateCharSet)]
private struct MI_SessionMembers
{
internal UInt64 reserved1;
internal IntPtr reserved2;
internal IntPtr ft;
}

static MI_Session()
{
CheckMembersTableMatchesNormalLayout<MI_SessionMembers>("ft");
}

internal void GetInstance(
MI_OperationFlags flags,
MI_OperationOptions options,
@@ -381,18 +394,6 @@ out MI_Operation operation

operation = operationLocal;
}

[StructLayout(LayoutKind.Sequential, CharSet = MI_PlatformSpecific.AppropriateCharSet)]
private struct MI_SessionMembers
{
internal UInt64 reserved1;
internal IntPtr reserved2;
internal IntPtr ft;
}

// Marshal implements these with Reflection - pay this hit only once
private static int MI_SessionMembersFTOffset = (int)Marshal.OffsetOf<MI_SessionMembers>("ft");
private static int MI_SessionMembersSize = Marshal.SizeOf<MI_SessionMembers>();

private MI_Session(bool isDirect) : base(isDirect)
{
@@ -423,10 +424,6 @@ internal void AssertValidInternalState()

internal static MI_Session Null { get { return null; } }

protected override int FunctionTableOffset { get { return MI_SessionMembersFTOffset; } }

protected override int MembersSize { get { return MI_SessionMembersSize; } }

internal MI_Result Close(
IntPtr completionContext,
NativeMethods.MI_Session_Close_CompletionCallback completionCallback
Loading