In System.Runtime.Remoting:
authorRobert Jordan <robertj@gmx.net>
Tue, 30 Oct 2007 01:49:05 +0000 (01:49 -0000)
committerRobert Jordan <robertj@gmx.net>
Tue, 30 Oct 2007 01:49:05 +0000 (01:49 -0000)
2007-10-30  Robert Jordan  <robertj@gmx.net>

* RemotingServices.cs: (InternalExecuteMessage):
Resolve interface methods using the new icall GetVirtualMethod ().
Remove the now obsolete GetMethodBaseFromName + generic params
overloads.

In System.Runtime.Remoting.Messaging:
2007-10-30  Robert Jordan  <robertj@gmx.net>

* MethodCall.cs (ResolveMethod): Lookup the interface
using RemotingServices.GetVirtualMethod (). Eliminates
the costly GetMethodBaseFromName () call.

svn path=/trunk/mcs/; revision=88434

mcs/class/corlib/System.Runtime.Remoting.Messaging/ChangeLog
mcs/class/corlib/System.Runtime.Remoting.Messaging/MethodCall.cs
mcs/class/corlib/System.Runtime.Remoting/ChangeLog
mcs/class/corlib/System.Runtime.Remoting/RemotingServices.cs

index dc652baa22158af86c31b3077c59b1f042a7aca6..18945578b6f84d66626cff64a556443c70ece528 100644 (file)
@@ -1,3 +1,9 @@
+2007-10-30  Robert Jordan  <robertj@gmx.net>
+
+       * MethodCall.cs (ResolveMethod): Lookup the interface
+       using RemotingServices.GetVirtualMethod (). Eliminates
+       the costly GetMethodBaseFromName () call.
+
 2007-09-07   Robert Jordan  <robertj@gmx.net>
 
        * MethodCall (ResolveMethod): Handle generic methods in the
index 452f2a35e0b285fefb9b3b4aadc61bbec7afdf60..94069d1727eaa3113ab08eb50c57b0d8735bce13 100644 (file)
@@ -320,33 +320,25 @@ namespace System.Runtime.Remoting.Messaging {
                                }
 
                                Type requestType = CastTo (_typeName, type);
+                               if (requestType == null)
+                                       throw new RemotingException ("Cannot cast from client type '" + _typeName + "' to server type '" + type.FullName + "'");
 
-                               if (requestType != null) {
-                                       // Look for the method in the requested type. The method signature is provided
-                                       // only if the method is overloaded in the requested type.
-                                       _methodBase = RemotingServices.GetMethodBaseFromName (requestType, _methodName, _methodSignature);
-                                       if (_methodBase == null)
-                                               throw new RemotingException ("Method " + _methodName + " not found in " + type);
+                               // Look for the method in the requested type. The method signature is provided
+                               // only if the method is overloaded in the requested type.
+                               _methodBase = RemotingServices.GetMethodBaseFromName (requestType, _methodName, _methodSignature);
 
-                                       
-                                       // If the method is implemented in an interface, look for the method implementation.
-                                       // It can't be done in the previous GetMethodBaseFromName call because at that point we
-                                       // may not yet have the method signature.
-                                       if (requestType != type && requestType.IsInterface) {
-#if NET_2_0
-                                               if (_methodBase.IsGenericMethod)
-                                                       _methodBase = RemotingServices.GetMethodBaseFromName (type, _methodName, (Type[]) MethodSignature, _methodBase.GetGenericArguments ());
-                                               else // fall through
-#endif
-                                                       _methodBase = RemotingServices.GetMethodBaseFromName (type, _methodName, (Type[]) MethodSignature);
-                                       }
+                               if (_methodBase == null)
+                                       throw new RemotingException ("Method " + _methodName + " not found in " + requestType);
 
+                               // If the method is implemented in an interface, look for the method implementation.
+                               // It can't be done in the previous GetMethodBaseFromName call because at that point we
+                               // may not yet have the method signature.
+                               if (requestType != type && requestType.IsInterface) {
+                                       _methodBase = RemotingServices.GetVirtualMethod (type, _methodBase);
                                        if (_methodBase == null)
                                                throw new RemotingException ("Method " + _methodName + " not found in " + type);
-
                                }
-                               else
-                                       throw new RemotingException ("Cannot cast from client type '" + _typeName + "' to server type '" + type.FullName + "'");
+
                        } else {
                                _methodBase = RemotingServices.GetMethodBaseFromMethodMessage (this);
                                if (_methodBase == null) throw new RemotingException ("Method " + _methodName + " not found in " + TypeName);
@@ -360,7 +352,6 @@ namespace System.Runtime.Remoting.Messaging {
                                _methodBase = ((MethodInfo) _methodBase).MakeGenericMethod (GenericArguments);
                        }
 #endif
-
                }
 
                Type CastTo (string clientType, Type serverType)
index 67e4c4b21bbeb77ac6b13caa896644be22f43c0e..a1083dca2ad2dee2b218beb8bb86a3ebf5547757 100644 (file)
@@ -1,3 +1,10 @@
+2007-10-30  Robert Jordan  <robertj@gmx.net>
+
+       * RemotingServices.cs: (InternalExecuteMessage):
+       Resolve interface methods using the new icall GetVirtualMethod ().
+       Remove the now obsolete GetMethodBaseFromName + generic params
+       overloads.
+
 2007-08-30  Robert Jordan  <robertj@gmx.net>
 
        * RemotingServices.cs (InternalExecuteMessage): Resolve interface
index ddd0c8774880abf32803afd2aad4727e0769174f..dfcc2d4b71264809d4543281955e27d3b92a56db 100644 (file)
@@ -103,6 +103,10 @@ namespace System.Runtime.Remoting
                internal extern static object InternalExecute (MethodBase method, Object obj,
                                                               Object[] parameters, out object [] out_args);
 
+               // Returns the actual implementation of @method in @type.
+               [MethodImplAttribute(MethodImplOptions.InternalCall)]
+               internal extern static MethodBase GetVirtualMethod (Type type, MethodBase method);
+
 #if NET_2_0
                [ReliabilityContractAttribute (Consistency.WillNotCorruptState, Cer.Success)]
 #endif
@@ -120,42 +124,21 @@ namespace System.Runtime.Remoting
                            reqMsg.MethodBase == FieldSetterMethod || 
                            reqMsg.MethodBase == FieldGetterMethod) {
                                method = reqMsg.MethodBase;
-                       } else  {
-                               method = tt.GetMethod (reqMsg.MethodName, methodBindings, null,
-                                       (Type[]) reqMsg.MethodSignature, null);
-
-                               // maybe an explicit interface implementation
-                               if (method == null && reqMsg.MethodBase.DeclaringType.IsInterface)
-                                       method = tt.GetMethod (
-                                               reqMsg.MethodBase.DeclaringType.FullName + "." + reqMsg.MethodName,
-                                               methodBindings, null, (Type[]) reqMsg.MethodSignature, null);
+                       } else {
+                               method = GetVirtualMethod (tt, reqMsg.MethodBase);
+
+                               if (method == null)
+                                       throw new RemotingException (
+                                               String.Format ("Cannot resolve method {0}:{1}", tt, reqMsg.MethodName));
                        }
 
 #if NET_2_0
                        if (reqMsg.MethodBase.IsGenericMethod) {
                                Type[] genericArguments = reqMsg.MethodBase.GetGenericArguments ();
-
-                               if (method == null) {
-                                       // method is probably overloaded
-                                       method = GetGenericMethod (tt, reqMsg.MethodName, methodBindings,
-                                               (Type[]) reqMsg.MethodSignature, genericArguments);
-
-                                       // maybe an explicit interface implementation
-                                       if (method == null && reqMsg.MethodBase.DeclaringType.IsInterface)
-                                               method = GetGenericMethod (tt,
-                                                       reqMsg.MethodBase.DeclaringType.FullName + "." + reqMsg.MethodName,
-                                                       methodBindings, (Type[]) reqMsg.MethodSignature, genericArguments);
-                               }
-
-                               if (method != null)
-                                       method = ((MethodInfo)method).MakeGenericMethod (genericArguments);
+                               method = ((MethodInfo)method).MakeGenericMethod (genericArguments);
                        }
 #endif
 
-                       if (method == null)
-                               throw new RemotingException (
-                                       String.Format ("Cannot resolve method {0}:{1}", tt, reqMsg.MethodName));
-
                        object oldContext = CallContext.SetCurrentCallContext (reqMsg.LogicalCallContext);
                        
                        try 
@@ -396,131 +379,6 @@ namespace System.Runtime.Remoting
                        return GetMethodBaseFromName (type, msg.MethodName, (Type[]) msg.MethodSignature);
                }
 
-#if NET_2_0
-
-               internal static MethodBase GetMethodBaseFromName (Type type, string methodName, Type[] signature, Type[] genericArguments)
-               {
-                       if (type.IsInterface) {
-                               return FindInterfaceMethod (type, methodName, signature, genericArguments);
-                       }
-                       else {
-                               MethodBase method = null;
-                               if (signature == null)
-                                       method = GetGenericMethod (type, methodName, methodBindings, genericArguments);
-                               else
-                                       method = GetGenericMethod (type, methodName, methodBindings, signature, genericArguments);
-                               
-                               if (method != null)
-                                       return method;
-                                       
-                               if (methodName == "FieldSetter")
-                                       return FieldSetterMethod;
-
-                               if (methodName == "FieldGetter")
-                                       return FieldGetterMethod;
-                               
-                               if (signature == null)
-                                       return type.GetConstructor (methodBindings, null, Type.EmptyTypes, null);
-                               else
-                                       return type.GetConstructor (methodBindings, null, signature, null);
-                       }
-               }
-               
-               static MethodBase FindInterfaceMethod (Type type, string methodName, Type[] signature, Type[] genericArguments)
-               {
-                       MethodBase method = null;
-                       
-                       if (signature == null)
-                               method = GetGenericMethod (type, methodName, methodBindings, genericArguments);
-                       else
-                               method = GetGenericMethod (type, methodName, methodBindings, signature, genericArguments);
-                               
-                       if (method != null) return method;
-                       
-                       foreach (Type t in type.GetInterfaces ()) {
-                               method = FindInterfaceMethod (t, methodName, signature);
-                               if (method != null) return method;
-                       }
-                       
-                       return null;
-               }
-
-               // returns the generic method with the specifed generic arguments
-               internal static MethodInfo GetGenericMethod (Type type, string name, BindingFlags flags, Type[] genericArguments)
-               {
-                       if (type == null)
-                               throw new ArgumentNullException ("type");
-
-                       if (name == null)
-                               throw new ArgumentNullException ("name");
-
-                       if (genericArguments == null)
-                               throw new ArgumentNullException ("genericArguments");
-
-                       foreach (MethodInfo mi in type.GetMethods (flags)) {
-                               if (!mi.IsGenericMethod)
-                                       continue;
-
-                               if (mi.Name != name)
-                                       continue;
-
-                               if (mi.GetGenericArguments ().Length != genericArguments.Length)
-                                       continue;
-
-                               return mi;
-                       }
-                       return null;
-               }
-
-               // returns the generic method with the specifed generic arguments
-               internal static MethodInfo GetGenericMethod (Type type, string name, BindingFlags flags, Type[] signature, Type[] genericArguments)
-               {
-                       if (type == null)
-                               throw new ArgumentNullException ("type");
-
-                       if (name == null)
-                               throw new ArgumentNullException ("name");
-
-                       if (signature == null)
-                               throw new ArgumentNullException ("signature");
-
-                       if (genericArguments == null)
-                               throw new ArgumentNullException ("genericArguments");
-
-                       foreach (MethodInfo mi in type.GetMethods (flags)) {
-                               if (!mi.IsGenericMethod)
-                                       continue;
-
-                               if (mi.Name != name)
-                                       continue;
-
-                               if (mi.GetGenericArguments ().Length != genericArguments.Length)
-                                       continue;
-
-                               ParameterInfo[] parms = mi.GetParameters ();
-                               if (parms.Length != signature.Length)
-                                       continue;
-
-                               if (!mi.ContainsGenericParameters) {
-                                       bool mismatch = false;
-                                       for (int i = 0; i < parms.Length; i++) {
-                                               if (parms [i].ParameterType != signature [i]) {
-                                                       mismatch = true;
-                                                       break;
-                                               }
-                                       }
-                                       if (mismatch)
-                                               continue;
-                               }
-
-                               return mi;
-                       }
-
-                       return null;
-               }
-
-#endif
-
                internal static MethodBase GetMethodBaseFromName (Type type, string methodName, Type[] signature)
                {
                        if (type.IsInterface) {