Author: kornelpal
Date: 2006-07-18 11:06:12 -0400 (Tue, 18 Jul 2006)
New Revision: 62706

Modified:
   trunk/mono/mono/metadata/ChangeLog
   trunk/mono/mono/metadata/class-internals.h
   trunk/mono/mono/metadata/debug-helpers.c
   trunk/mono/mono/metadata/icall.c
   trunk/mono/mono/metadata/marshal.c
   trunk/mono/mono/metadata/reflection.c
   trunk/mono/mono/metadata/security-manager.c
   trunk/mono/mono/metadata/string-icalls.c
   trunk/mono/mono/metadata/string-icalls.h
   trunk/mono/mono/mini/ChangeLog
   trunk/mono/mono/mini/declsec.c
Log:
Redirect certain string constructors to CreateString () methods with matching 
signature that improves performance.

Modified: trunk/mono/mono/metadata/ChangeLog
===================================================================
--- trunk/mono/mono/metadata/ChangeLog  2006-07-18 14:53:50 UTC (rev 62705)
+++ trunk/mono/mono/metadata/ChangeLog  2006-07-18 15:06:12 UTC (rev 62706)
@@ -1,3 +1,21 @@
+2006-07-18  Kornél Pál  <[EMAIL PROTECTED]>
+
+       * class-internals.h: Added MONO_WRAPPER_MANAGED_TO_MANAGED wrapper type.
+       * debug-helpers.c: Map MONO_WRAPPER_MANAGED_TO_MANAGED to
+         "managed-to-managed".
+       * icall.c: Redirect string constructors that take sbyte* to
+         ves_icall_System_String_ctor_RedirectToCreateString.
+       * marshal.c: Redirect 
ves_icall_System_String_ctor_RedirectToCreateString
+         to CreateString () methods with matching signature.
+       * reflection.c: Use original security informations for
+         MONO_WRAPPER_MANAGED_TO_MANAGED.
+       * security-manager.c: Use original security informations for
+         MONO_WRAPPER_MANAGED_TO_MANAGED.
+       * string-icalls.c: Added 
ves_icall_System_String_ctor_RedirectToCreateString
+         that is a placeholder and only its address should be used.
+       * string-icalls.h: Added 
ves_icall_System_String_ctor_RedirectToCreateString
+         that is a placeholder and only its address should be used.
+
 2006-07-15  Jonathan Chambers  <[EMAIL PROTECTED]>
 
        Begin implementing COM Interop.

Modified: trunk/mono/mono/metadata/class-internals.h
===================================================================
--- trunk/mono/mono/metadata/class-internals.h  2006-07-18 14:53:50 UTC (rev 
62705)
+++ trunk/mono/mono/metadata/class-internals.h  2006-07-18 15:06:12 UTC (rev 
62706)
@@ -30,6 +30,7 @@
        MONO_WRAPPER_RUNTIME_INVOKE,
        MONO_WRAPPER_NATIVE_TO_MANAGED,
        MONO_WRAPPER_MANAGED_TO_NATIVE,
+       MONO_WRAPPER_MANAGED_TO_MANAGED,
        MONO_WRAPPER_REMOTING_INVOKE,
        MONO_WRAPPER_REMOTING_INVOKE_WITH_CHECK,
        MONO_WRAPPER_XDOMAIN_INVOKE,

Modified: trunk/mono/mono/metadata/debug-helpers.c
===================================================================
--- trunk/mono/mono/metadata/debug-helpers.c    2006-07-18 14:53:50 UTC (rev 
62705)
+++ trunk/mono/mono/metadata/debug-helpers.c    2006-07-18 15:06:12 UTC (rev 
62706)
@@ -23,6 +23,7 @@
        "runtime-invoke",
        "native-to-managed",
        "managed-to-native",
+       "managed-to-managed",
        "remoting-invoke",
        "remoting-invoke-with-check",
        "xdomain-invoke",

Modified: trunk/mono/mono/metadata/icall.c
===================================================================
--- trunk/mono/mono/metadata/icall.c    2006-07-18 14:53:50 UTC (rev 62705)
+++ trunk/mono/mono/metadata/icall.c    2006-07-18 15:06:12 UTC (rev 62706)
@@ -7075,9 +7075,9 @@
        {".ctor(char,int)", ves_icall_System_String_ctor_char_int},
        {".ctor(char[])", ves_icall_System_String_ctor_chara},
        {".ctor(char[],int,int)", ves_icall_System_String_ctor_chara_int_int},
-       {".ctor(sbyte*)", ves_icall_System_String_ctor_sbytep},
-       {".ctor(sbyte*,int,int)", ves_icall_System_String_ctor_sbytep_int_int},
-       {".ctor(sbyte*,int,int,System.Text.Encoding)", 
ves_icall_System_String_ctor_encoding},
+       {".ctor(sbyte*)", ves_icall_System_String_ctor_RedirectToCreateString},
+       {".ctor(sbyte*,int,int)", 
ves_icall_System_String_ctor_RedirectToCreateString},
+       {".ctor(sbyte*,int,int,System.Text.Encoding)", 
ves_icall_System_String_ctor_RedirectToCreateString},
        {"InternalAllocateStr", ves_icall_System_String_InternalAllocateStr},
        {"InternalCharCopy", ves_icall_System_String_InternalCharCopy},
        {"InternalCopyTo", ves_icall_System_String_InternalCopyTo},

Modified: trunk/mono/mono/metadata/marshal.c
===================================================================
--- trunk/mono/mono/metadata/marshal.c  2006-07-18 14:53:50 UTC (rev 62705)
+++ trunk/mono/mono/metadata/marshal.c  2006-07-18 15:06:12 UTC (rev 62706)
@@ -23,6 +23,7 @@
 #include "mono/metadata/domain-internals.h"
 #include "mono/metadata/gc-internal.h"
 #include "mono/metadata/threads-types.h"
+#include "mono/metadata/string-icalls.h"
 #include <mono/os/gc_wrapper.h>
 #include <string.h>
 #include <errno.h>
@@ -7245,6 +7246,7 @@
        MonoMethod *res;
        GHashTable *cache;
        gboolean pinvoke = FALSE;
+       gpointer iter;
        int i;
        const char *exc_class = "MissingMethodException";
        const char *exc_arg = NULL;
@@ -7272,6 +7274,49 @@
                        piinfo->addr = mono_lookup_internal_call (method);
        }
 
+       /* hack - redirect certain string constructors to CreateString */
+       if (piinfo->addr == 
ves_icall_System_String_ctor_RedirectToCreateString) {
+               g_assert (!pinvoke);
+               g_assert (method->string_ctor);
+               g_assert (sig->hasthis);
+
+               /* CreateString returns a value */
+               csig = signature_dup (method->klass->image, sig);
+               csig->ret = &mono_defaults.string_class->byval_arg;
+               csig->pinvoke = 0;
+
+               iter = NULL;
+               while ((res = mono_class_get_methods 
(mono_defaults.string_class, &iter))) {
+                       if (!strcmp ("CreateString", res->name) &&
+                               mono_metadata_signature_equal (csig, 
mono_method_signature (res))) {
+
+                               g_assert (!(res->iflags & 
METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL));
+                               g_assert (!(res->flags & 
METHOD_ATTRIBUTE_PINVOKE_IMPL));
+
+                               /* create a wrapper to preserve .ctor in stack 
trace */
+                               mb = mono_mb_new (method->klass, method->name, 
MONO_WRAPPER_MANAGED_TO_MANAGED);
+
+                               mono_mb_emit_byte (mb, CEE_LDARG_0);
+                               for (i = 1; i <= csig->param_count; i++)
+                                       mono_mb_emit_ldarg (mb, i);
+                               mono_mb_emit_managed_call (mb, res, NULL);
+                               mono_mb_emit_byte (mb, CEE_RET);
+
+                               /* use native_wrapper_cache because internal 
calls are looked up there */
+                               res = mono_mb_create_and_cache (cache, method,
+                                       mb, csig, csig->param_count + 1);
+
+                               mono_mb_free (mb);
+
+                               return res;
+                       }
+               }
+
+               /* exception will be thrown */
+               piinfo->addr = NULL;
+               g_warning ("cannot find CreateString for .ctor");
+       }
+
        mb = mono_mb_new (method->klass, method->name, 
MONO_WRAPPER_MANAGED_TO_NATIVE);
 
        mb->method->save_lmf = 1;

Modified: trunk/mono/mono/metadata/reflection.c
===================================================================
--- trunk/mono/mono/metadata/reflection.c       2006-07-18 14:53:50 UTC (rev 
62705)
+++ trunk/mono/mono/metadata/reflection.c       2006-07-18 15:06:12 UTC (rev 
62706)
@@ -10023,7 +10023,7 @@
                return FALSE;
 
        /* we want the original as the wrapper is "free" of the security 
informations */
-       if (method->wrapper_type == MONO_WRAPPER_MANAGED_TO_NATIVE) {
+       if (method->wrapper_type == MONO_WRAPPER_MANAGED_TO_NATIVE || 
method->wrapper_type == MONO_WRAPPER_MANAGED_TO_MANAGED) {
                method = mono_marshal_method_from_wrapper (method);
                if (!method)
                        return FALSE;
@@ -10071,7 +10071,7 @@
                return FALSE;
 
        /* we want the original as the wrapper is "free" of the security 
informations */
-       if (method->wrapper_type == MONO_WRAPPER_MANAGED_TO_NATIVE) {
+       if (method->wrapper_type == MONO_WRAPPER_MANAGED_TO_NATIVE || 
method->wrapper_type == MONO_WRAPPER_MANAGED_TO_MANAGED) {
                method = mono_marshal_method_from_wrapper (method);
                if (!method)
                        return FALSE;
@@ -10146,7 +10146,7 @@
                return FALSE;
 
        /* we want the original as the wrapper is "free" of the security 
informations */
-       if (method->wrapper_type == MONO_WRAPPER_MANAGED_TO_NATIVE) {
+       if (method->wrapper_type == MONO_WRAPPER_MANAGED_TO_NATIVE || 
method->wrapper_type == MONO_WRAPPER_MANAGED_TO_MANAGED) {
                method = mono_marshal_method_from_wrapper (method);
                if (!method)
                        return FALSE;

Modified: trunk/mono/mono/metadata/security-manager.c
===================================================================
--- trunk/mono/mono/metadata/security-manager.c 2006-07-18 14:53:50 UTC (rev 
62705)
+++ trunk/mono/mono/metadata/security-manager.c 2006-07-18 15:06:12 UTC (rev 
62706)
@@ -259,7 +259,7 @@
 {
        MonoMethod *method = m->method;
        /* we want the original as the wrapper is "free" of the security 
informations */
-       if (method->wrapper_type == MONO_WRAPPER_MANAGED_TO_NATIVE) {
+       if (method->wrapper_type == MONO_WRAPPER_MANAGED_TO_NATIVE || 
method->wrapper_type == MONO_WRAPPER_MANAGED_TO_MANAGED) {
                method = mono_marshal_method_from_wrapper (method);
        }
 

Modified: trunk/mono/mono/metadata/string-icalls.c
===================================================================
--- trunk/mono/mono/metadata/string-icalls.c    2006-07-18 14:53:50 UTC (rev 
62705)
+++ trunk/mono/mono/metadata/string-icalls.c    2006-07-18 15:06:12 UTC (rev 
62706)
@@ -239,6 +239,14 @@
        return s;
 }
 
+/* This function is redirected to String.CreateString ()
+   by mono_marshal_get_native_wrapper () */
+void
+ves_icall_System_String_ctor_RedirectToCreateString ()
+{
+       g_assert_not_reached ();
+}
+
 MonoString * 
 ves_icall_System_String_InternalJoin (MonoString *separator, MonoArray * 
value, gint32 sindex, gint32 count)
 {

Modified: trunk/mono/mono/metadata/string-icalls.h
===================================================================
--- trunk/mono/mono/metadata/string-icalls.h    2006-07-18 14:53:50 UTC (rev 
62705)
+++ trunk/mono/mono/metadata/string-icalls.h    2006-07-18 15:06:12 UTC (rev 
62706)
@@ -37,6 +37,9 @@
 MonoString *
 ves_icall_System_String_ctor_encoding (gpointer dummy, gint8 *value, gint32 
sindex, gint32 length, MonoObject *enc);
 
+void
+ves_icall_System_String_ctor_RedirectToCreateString ();
+
 MonoString * 
 ves_icall_System_String_InternalJoin (MonoString *separator, MonoArray * 
value, gint32 sindex, gint32 count);
 

Modified: trunk/mono/mono/mini/ChangeLog
===================================================================
--- trunk/mono/mono/mini/ChangeLog      2006-07-18 14:53:50 UTC (rev 62705)
+++ trunk/mono/mono/mini/ChangeLog      2006-07-18 15:06:12 UTC (rev 62706)
@@ -1,3 +1,8 @@
+2006-07-18  Kornél Pál  <[EMAIL PROTECTED]>
+
+       * declsec.c: Use original security informations for
+         MONO_WRAPPER_MANAGED_TO_MANAGED.
+
 2006-07-15  Jonathan Chambers  <[EMAIL PROTECTED]>
 
        * mini.c: Allow Com Interop methods/classes and

Modified: trunk/mono/mono/mini/declsec.c
===================================================================
--- trunk/mono/mono/mini/declsec.c      2006-07-18 14:53:50 UTC (rev 62705)
+++ trunk/mono/mono/mini/declsec.c      2006-07-18 15:06:12 UTC (rev 62706)
@@ -19,7 +19,7 @@
 {
        mono_jit_stats.cas_declsec_check++;
 
-       if (method->wrapper_type == MONO_WRAPPER_MANAGED_TO_NATIVE) {
+       if (method->wrapper_type == MONO_WRAPPER_MANAGED_TO_NATIVE || 
method->wrapper_type == MONO_WRAPPER_MANAGED_TO_MANAGED) {
                method = mono_marshal_method_from_wrapper (method);
                if (!method)
                        return FALSE;

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to