the .cs file is the really simple (and dumb) program that I used to get
this info from mono runtime.

As always... this is released under MIT\X11 license.

[based on revision(trunk) 127107]

>> With patch in method-to-ir.c
time mono --compile-all test.exe

real    0m0.151s
user    0m0.084s
sys    0m0.032s

mono --compile-all --stats test.exe
Mono Jit statistics
Compiled methods:       31
Methods from AOT:       0
Methods cache lookup:   12
Method trampolines:     22
Basic blocks:           275
Max basic blocks:       26
Allocated vars:         138
Compiled CIL code size: 1403
Native code size:       3575
Max code size ratio:    9.00 (MainClass::Main))
Biggest method:         612 (Hashtable::.ctor))
Code reallocs:          0
Allocated code size:    3575
Inlineable methods:     9
Inlined methods:        12
Regvars:                31
Locals stack size:      308

Created object count:   18
Delegates created:      0
Initialized classes:    108
Used classes:           23
Generic vtables:        22
Methods:                914
Static data size:       192
VTable data size:       11016
Mscorlib mempool size:  180312

Initialized classes:    23
Inflated types:         61
Generics virtual invokes: 0
Sharable generic methods: 0
Unsharable generic methods: 0
Shared generic methods: 0
Dynamic code allocs:    0
Dynamic code bytes:     0
Dynamic code frees:     0
IMT tables size:        2736
IMT number of tables:   18
IMT number of methods:  0
IMT used slots:         0
IMT colliding slots:    0
IMT max collisions:     0
IMT methods at max col: 0
IMT thunks size:        0
JIT info table inserts: 31
JIT info table removes: 0
JIT info table lookups: 42
Hazardous pointers:     0
Major GC collections:   2
Major GC time in msecs: 1.551000

JIT statistics
Unwind info size                    : 188
Max native code in a domain         : 4050
Max code space allocated in a domain: 65536
Total code space allocated          : 65536

Metadata statistics
MonoClass size                      : 66096
MonoClassExt size                   : 0
Memberref signature cache size      : 64

Generics statistics
Inflated methods size               : 3280
Inflated classes                    : 43
Inflated classes size               : 11696
Inflated signatures size            : 1264

>>without the patch in method-to-ir.c
time mono --compile-all test.exe

real    0m0.136s
user    0m0.068s
sys    0m0.032s

mono --compile-all --stats test.exe
Mono Jit statistics
Compiled methods:       31
Methods from AOT:       0
Methods cache lookup:   12
Method trampolines:     22
Basic blocks:           275
Max basic blocks:       26
Allocated vars:         138
Compiled CIL code size: 1403
Native code size:       3575
Max code size ratio:    9.00 (MainClass::Main))
Biggest method:         612 (Hashtable::.ctor))
Code reallocs:          0
Allocated code size:    3575
Inlineable methods:     9
Inlined methods:        12
Regvars:                31
Locals stack size:      308

Created object count:   18
Delegates created:      0
Initialized classes:    108
Used classes:           23
Generic vtables:        22
Methods:                914
Static data size:       192
VTable data size:       11016
Mscorlib mempool size:  180312

Initialized classes:    23
Inflated types:         61
Generics virtual invokes: 0
Sharable generic methods: 0
Unsharable generic methods: 0
Shared generic methods: 0
Dynamic code allocs:    0
Dynamic code bytes:     0
Dynamic code frees:     0
IMT tables size:        2736
IMT number of tables:   18
IMT number of methods:  0
IMT used slots:         0
IMT colliding slots:    0
IMT max collisions:     0
IMT methods at max col: 0
IMT thunks size:        0
JIT info table inserts: 31
JIT info table removes: 0
JIT info table lookups: 42
Hazardous pointers:     0
Major GC collections:   2
Major GC time in msecs: 1.447000

JIT statistics
Unwind info size                    : 188
Max native code in a domain         : 4066
Max code space allocated in a domain: 65536
Total code space allocated          : 65536

Metadata statistics
MonoClass size                      : 66096
MonoClassExt size                   : 0
Memberref signature cache size      : 64

Generics statistics
Inflated methods size               : 3280
Inflated classes                    : 43
Inflated classes size               : 11696
Inflated signatures size            : 1264

// Main.cs created with MonoDevelop
// User: jmaine at 5:50 PM 1/21/2009
//
// To change standard headers go to Edit->Preferences->Coding->Standard Headers
//
using System;

namespace test
{

	class MainClass
	{
		
		public static void Main(string[] args)
		{
			
		}
	}
}
Index: class/Makefile
===================================================================
--- class/Makefile	(revision 127107)
+++ class/Makefile	(working copy)
@@ -8,7 +8,8 @@
 	Mono.Security				\
 	System.Security				\
 	System.Configuration			\
-	System
+	System									
+	
 
 
 # Note that Mono.Security and System.Security aren't listed.
@@ -38,6 +39,7 @@
 	System.Configuration		\
 	System				\
 	System.XML			\
+	Mono.Runtime			\
 	I18N				\
 	System.Drawing			\
 	System.Transactions		\
Index: class/Mono.Runtime/Assembly/AssemblyInfo.cs
===================================================================
--- class/Mono.Runtime/Assembly/AssemblyInfo.cs	(revision 0)
+++ class/Mono.Runtime/Assembly/AssemblyInfo.cs	(revision 0)
@@ -0,0 +1,49 @@
+// AssemblyInfo.cs
+//
+// Author:
+//   Jerry Maine ([email protected])
+//
+// (C) Jerry Maine
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using System.Reflection;
+using System.Resources;
+using System.Security;
+using System.Security.Permissions;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about the system assembly
+
+[assembly: AssemblyVersion (Consts.FxVersion)]
+
+[assembly: AssemblyCompany ("MONO development team")]
+[assembly: AssemblyCopyright ("(c) 2009 Jerry Maine")]
+[assembly: AssemblyDescription ("Mono.Runtime.dll")]
+[assembly: AssemblyProduct ("MONO CLI")]
+[assembly: AssemblyTitle ("Mono.Runtime.dll")]
+[assembly: ComVisible (false)]
+[assembly: NeutralResourcesLanguage ("en-US")]
+[assembly: AssemblyDelaySign(true)]
+[assembly: AssemblyKeyFile("../mono.pub")]
+[assembly: CLSCompliant(true)]
\ No newline at end of file
Index: class/Mono.Runtime/Mono.Runtime.dll.sources
===================================================================
--- class/Mono.Runtime/Mono.Runtime.dll.sources	(revision 0)
+++ class/Mono.Runtime/Mono.Runtime.dll.sources	(revision 0)
@@ -0,0 +1,4 @@
+../../build/common/Consts.cs
+../../build/common/Locale.cs
+Assembly/AssemblyInfo.cs
+Mono.Runtime/MonoInlineAttribute.cs
Index: class/Mono.Runtime/Mono.Runtime/MonoInlineAttribute.cs
===================================================================
--- class/Mono.Runtime/Mono.Runtime/MonoInlineAttribute.cs	(revision 0)
+++ class/Mono.Runtime/Mono.Runtime/MonoInlineAttribute.cs	(revision 0)
@@ -0,0 +1,40 @@
+// MonoInlineAttribute.cs
+//
+// Author:
+//   Jerry Maine ([email protected])
+//
+// (C) Jerry Maine
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+
+
+namespace Mono.Runtime
+{
+	[AttributeUsage (AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Class, Inherited=false)]
+	public sealed class MonoInlineAttribute : Attribute
+	{
+		public MonoInlineAttribute ()
+		{
+		}
+	}
+}
Index: class/Mono.Runtime/Makefile
===================================================================
--- class/Mono.Runtime/Makefile	(revision 0)
+++ class/Mono.Runtime/Makefile	(revision 0)
@@ -0,0 +1,22 @@
+thisdir = class/Mono.Runtime
+SUBDIRS = 
+include ../../build/rules.make
+
+LIBRARY = Mono.Runtime.dll
+#LIB_MCS_FLAGS = -r:$(corlib) -r:System.Core.dll /unsafe
+LIB_MCS_FLAGS = -r:$(corlib) /unsafe
+TEST_MCS_FLAGS = -r:Mono.Runtime.dll
+
+NO_TEST = yes
+
+
+# This is a .NET 2.0 only assembly
+#VALID_PROFILE := $(filter net_2_0_bootstrap net_2_0, $(PROFILE))
+#ifndef VALID_PROFILE
+#LIBRARY_NAME = dummy-Mono.Runtime.dll
+#NO_INSTALL = yes
+#NO_TEST = yes
+#endif
+
+include ../../build/library.make
+
Index: class/Managed.Windows.Forms/Makefile
===================================================================
--- class/Managed.Windows.Forms/Makefile	(revision 127107)
+++ class/Managed.Windows.Forms/Makefile	(working copy)
@@ -8,6 +8,7 @@
 	/r:System.Drawing.dll /r:Accessibility.dll \
 	/r:System.Data.dll /r:Mono.Posix.dll \
 	/r:Mono.WebBrowser \
+	/r:Mono.Runtime.dll \
 	@System.Windows.Forms.dll.resources \
 	-debug -nowarn:618,612,809
 
Index: class/Managed.Windows.Forms/System.Windows.Forms/AmbientProperties.cs
===================================================================
--- class/Managed.Windows.Forms/System.Windows.Forms/AmbientProperties.cs	(revision 127107)
+++ class/Managed.Windows.Forms/System.Windows.Forms/AmbientProperties.cs	(working copy)
@@ -27,8 +27,11 @@
 // COMPLETE
 
 using System.Drawing;
+using Mono.Runtime;
 
 namespace System.Windows.Forms {
+	
+	[MonoInline]
 	public sealed class AmbientProperties {
 		#region Local Variables
 		private Color	fore_color;
Index: class/Managed.Windows.Forms/System.Windows.Forms/Clipboard.cs
===================================================================
--- class/Managed.Windows.Forms/System.Windows.Forms/Clipboard.cs	(revision 127107)
+++ class/Managed.Windows.Forms/System.Windows.Forms/Clipboard.cs	(working copy)
@@ -33,8 +33,10 @@
 using System.Collections;
 using System.Collections.Specialized;
 using System.ComponentModel;
+using Mono.Runtime;
 
 namespace System.Windows.Forms {
+	[MonoInline]
 	public sealed class Clipboard {
 		#region Local Variables
 		#endregion	// Local Variables
Index: class/Managed.Windows.Forms/System.Windows.Forms/ControlPaint.cs
===================================================================
--- class/Managed.Windows.Forms/System.Windows.Forms/ControlPaint.cs	(revision 127107)
+++ class/Managed.Windows.Forms/System.Windows.Forms/ControlPaint.cs	(working copy)
@@ -29,8 +29,10 @@
 using System.Drawing;
 using System.Drawing.Drawing2D;
 using System.Drawing.Imaging;
+using Mono.Runtime;
 
 namespace System.Windows.Forms {
+	[MonoInline]
 	public sealed class ControlPaint {
 		#region Local Variables
 		static int		RGBMax=255;
Index: class/Managed.Windows.Forms/System.Windows.Forms/Application.cs
===================================================================
--- class/Managed.Windows.Forms/System.Windows.Forms/Application.cs	(revision 127107)
+++ class/Managed.Windows.Forms/System.Windows.Forms/Application.cs	(working copy)
@@ -43,9 +43,11 @@
 using System.Text;
 #endif
 using System.Windows.Forms.VisualStyles;
+using Mono.Runtime;
 
 namespace System.Windows.Forms
 {
+	[MonoInline]
 	public sealed class Application
 	{
 		internal class MWFThread
Index: mono/metadata/object-internals.h
===================================================================
--- mono/metadata/object-internals.h	(revision 127107)
+++ mono/metadata/object-internals.h	(working copy)
@@ -1284,6 +1284,15 @@
 void
 mono_method_clear_object (MonoDomain *domain, MonoMethod *method) MONO_INTERNAL;
 
+
+gboolean
+mono_method_has_custom_attr (MonoMethod *method, const char *attr_assembly, const char *attr_name_space, const char *attr_name) MONO_INTERNAL;
+
+gboolean
+mono_class_has_custom_attr (MonoClass *klass, const char *attr_assembly, const char *attr_name_space, const char *attr_name) MONO_INTERNAL;
+
+gboolean
+mono_assembly_has_custom_attr (MonoAssembly *assembly, const char *attr_assembly, const char *attr_name_space, const char *attr_name) MONO_INTERNAL;
 #endif /* __MONO_OBJECT_INTERNALS_H__ */
 
 
Index: mono/metadata/reflection.c
===================================================================
--- mono/metadata/reflection.c	(revision 127107)
+++ mono/metadata/reflection.c	(working copy)
@@ -8215,6 +8215,35 @@
 	return FALSE;
 }
 
+/** added start **/
+
+static gboolean
+mono_custom_attrs_has_attr_partial (MonoCustomAttrInfo *ainfo, const char *attr_assembly, const char *attr_name_space, const char *attr_name)
+{
+	int i;
+	MonoClass *klass;
+
+	if (attr_name == NULL)
+		return FALSE;
+
+	for (i = 0; i < ainfo->num_attrs; ++i) {
+		klass = ainfo->attrs [i].ctor->klass;
+		if (attr_assembly != NULL)
+			if (strcmp (klass->image->assembly_name, attr_assembly) )
+				continue;
+			
+		if (attr_name_space != NULL)
+			if (strcmp (klass->name_space, attr_name_space) )
+				continue;
+
+		if (!strcmp (klass->name, attr_name) )
+				return TRUE;
+	}
+	return FALSE;
+}
+
+/** added end **/
+
 MonoObject*
 mono_custom_attrs_get_attr (MonoCustomAttrInfo *ainfo, MonoClass *attr_klass)
 {
@@ -8240,6 +8269,165 @@
 		return NULL;
 }
 
+/** added start **/
+/*NOTE, this doesn't work with dynamic assemblies*/
+static gboolean
+mono_image_has_assembly_ref (MonoImage *image, const char *target_assembly)
+{
+        MonoTableInfo *t;
+        int i;
+
+	//TODO: Fix this to work with dynamic assemblies.
+        if (image->dynamic)
+            return FALSE;
+
+        t = &image->tables [MONO_TABLE_ASSEMBLYREF];
+        for (i = 0; i < t->rows; i++) {
+            const char *ref_name = mono_metadata_string_heap (image, mono_metadata_decode_row_col (t, i, MONO_ASSEMBLYREF_NAME));
+            if (!strcmp (target_assembly, ref_name))
+                return TRUE;
+        }
+        return FALSE;
+}
+
+
+static gboolean
+mono_index_has_custom_attr (MonoImage *image, guint32 idx, const char *attr_assembly, const char *attr_name_space, const char *attr_name)
+{
+	guint32 mtoken, i, x;
+	guint32 cols [MONO_CUSTOM_ATTR_SIZE];
+	MonoTableInfo *ca;
+	MonoMethod* attr_ctor;
+
+	ca = &image->tables [MONO_TABLE_CUSTOMATTRIBUTE];
+
+	if (attr_name == NULL)
+		return FALSE;
+
+	if (attr_assembly != NULL)
+		if (!mono_image_has_assembly_ref(image, attr_assembly))
+			return FALSE;
+
+	i = mono_metadata_custom_attrs_from_index (image, idx);
+	if (!i)
+		return FALSE;
+	i --;
+
+	for (x = i; i < ca->rows; x++) {
+		mono_metadata_decode_row (ca, x, cols, MONO_CUSTOM_ATTR_SIZE);
+		if (cols[MONO_CUSTOM_ATTR_PARENT] != idx)
+			break;
+		
+		mtoken = cols [MONO_CUSTOM_ATTR_TYPE] >> MONO_CUSTOM_ATTR_TYPE_BITS;
+		switch (cols [MONO_CUSTOM_ATTR_TYPE] & MONO_CUSTOM_ATTR_TYPE_MASK) {
+		case MONO_CUSTOM_ATTR_TYPE_METHODDEF:
+			mtoken |= MONO_TOKEN_METHOD_DEF;
+			break;
+		case MONO_CUSTOM_ATTR_TYPE_MEMBERREF:
+			mtoken |= MONO_TOKEN_MEMBER_REF;
+			break;
+		default:
+			g_error ("Unknown table for custom attr type %08x", cols [MONO_CUSTOM_ATTR_TYPE]);
+			break;
+		}
+		attr_ctor = mono_get_method (image, mtoken, NULL);
+		if (!attr_ctor) {
+			g_warning ("Can't find custom attr constructor image: %s mtoken: 0x%08x", image->name, mtoken);
+			return FALSE;
+		} else {
+			if (attr_assembly != NULL)
+				if (strcmp (attr_ctor->klass->image->assembly_name, attr_assembly) )
+					continue;
+			
+			if (attr_name_space != NULL)
+				if (strcmp (attr_ctor->klass->name_space, attr_name_space) )
+					continue;
+
+			if (!strcmp (attr_ctor->klass->name, attr_name) )
+				return TRUE;
+		}
+	}
+
+	return FALSE;
+}
+
+static gboolean
+dynamic_has_custom_attr_partial (MonoImage* image, void *key, const char *attr_assembly, const char *attr_name_space, const char *attr_name)
+{
+	gboolean result;
+	MonoCustomAttrInfo *ainfo = lookup_custom_attr (image, key);
+
+	if (ainfo != NULL) {
+		result = mono_custom_attrs_has_attr_partial (ainfo, attr_assembly, attr_name_space, attr_name);
+		mono_custom_attrs_free (ainfo);
+		return result;	
+	}
+
+	return FALSE;
+}
+
+gboolean
+mono_method_has_custom_attr (MonoMethod *method, const char *attr_assembly, const char *attr_name_space, const char *attr_name)
+{
+	guint32 idx;
+
+	/*
+	 * An instantiated method has the same cattrs as the generic method definition.
+	 *
+	 * LAMESPEC: The .NET SRE throws an exception for instantiations of generic method builders
+	 *           Note that this stanza is not necessary for non-SRE types, but it's a micro-optimization
+	 */
+	if (method->is_inflated)
+		method = ((MonoMethodInflated *) method)->declaring;
+	
+	if (method->dynamic || method->klass->image->dynamic) 
+		return dynamic_has_custom_attr_partial (method->klass->image, method, attr_assembly, attr_name_space, attr_name); 
+
+	idx = mono_method_get_index (method);
+	idx <<= MONO_CUSTOM_ATTR_BITS;
+	idx |= MONO_CUSTOM_ATTR_METHODDEF;
+	return mono_index_has_custom_attr (method->klass->image, idx, attr_assembly, attr_name_space, attr_name);
+}
+
+gboolean
+mono_class_has_custom_attr (MonoClass *klass, const char *attr_assembly, const char *attr_name_space, const char *attr_name)
+{
+	guint32 idx;
+
+	if (klass->generic_class)
+		klass = klass->generic_class->container_class;
+
+	if (klass->image->dynamic)
+		return dynamic_has_custom_attr_partial (klass->image, klass, attr_assembly, attr_name_space, attr_name);
+
+	if (klass->byval_arg.type == MONO_TYPE_VAR || klass->byval_arg.type == MONO_TYPE_MVAR) {
+		idx = mono_metadata_token_index (klass->sizes.generic_param_token);
+		idx <<= MONO_CUSTOM_ATTR_BITS;
+		idx |= MONO_CUSTOM_ATTR_GENERICPAR;
+	} else {
+		idx = mono_metadata_token_index (klass->type_token);
+		idx <<= MONO_CUSTOM_ATTR_BITS;
+		idx |= MONO_CUSTOM_ATTR_TYPEDEF;
+	}
+	return mono_index_has_custom_attr (klass->image, idx, attr_assembly, attr_name_space, attr_name);
+}
+
+gboolean
+mono_assembly_has_custom_attr (MonoAssembly *assembly, const char *attr_assembly, const char *attr_name_space, const char *attr_name)
+{
+	guint32 idx;
+	
+	if (assembly->image->dynamic)
+		return dynamic_has_custom_attr_partial (assembly->image, assembly, attr_assembly, attr_name_space, attr_name);
+
+	idx = 1; /* there is only one assembly */
+	idx <<= MONO_CUSTOM_ATTR_BITS;
+	idx |= MONO_CUSTOM_ATTR_ASSEMBLY;
+	return mono_index_has_custom_attr (assembly->image, idx, attr_assembly, attr_name_space, attr_name);
+}
+
+/** added end **/
+
 /*
  * mono_reflection_get_custom_attrs_info:
  * @obj: a reflection object handle
Index: mono/mini/method-to-ir.c
===================================================================
--- mono/mini/method-to-ir.c	(revision 127107)
+++ mono/mini/method-to-ir.c	(working copy)
@@ -3337,6 +3337,14 @@
 	    !header || header->num_clauses)
 		return FALSE;
 
+	/*if ( (mono_assembly_has_custom_attr (method->klass->image->assembly, "Mono.Runtime", "Mono.Runtime", "MonoInlineAtteribute") )|
+		(mono_class_has_custom_attr (method->klass, "Mono.Runtime", "Mono.Runtime", "MonoInlineAtteribute") ) |
+		(mono_method_has_custom_attr (method, "Mono.Runtime", "Mono.Runtime", "MonoInlineAtteribute") ) ) {
+		if (cfg->verbose_level > 2)
+			printf ("Inline Hint: %s\n", method->name);
+	}*/
+
+
 	/* also consider num_locals? */
 	/* Do the size check early to avoid creating vtables */
 	if (!inline_limit_inited) {
_______________________________________________
Mono-devel-list mailing list
[email protected]
http://lists.ximian.com/mailman/listinfo/mono-devel-list

Reply via email to