6 #include "mono/metadata/debug-helpers.h"
7 #include "mono/metadata/verify.h"
8 #include "mono/metadata/profiler.h"
12 * @assembly: reference to an assembly
14 * JIT compilation of all methods in the assembly. Prints debugging
15 * information on stdout.
18 mono_jit_assembly (MonoAssembly *assembly)
20 MonoImage *image = assembly->image;
22 MonoTableInfo *t = &image->tables [MONO_TABLE_METHOD];
25 for (i = 0; i < t->rows; i++) {
27 method = mono_get_method (image,
28 (MONO_TABLE_METHOD << 24) | (i + 1),
31 printf ("\nMethod: %s\n\n", method->name);
33 if (method->flags & METHOD_ATTRIBUTE_ABSTRACT)
34 printf ("ABSTARCT\n");
36 arch_compile_method (method);
46 "%s %s, the Mono ECMA CLI JIT Compiler, (C) 2001 Ximian, Inc.\n\n"
47 "Usage is: %s [options] executable args...\n", name, VERSION, name);
49 "Valid Options are:\n"
50 "-d debug the jit, show disassembler output.\n"
51 "--dump-asm dumps the assembly code generated\n"
52 "--dump-forest dumps the reconstructed forest\n"
53 "--trace printf function call trace\n"
54 "--profile record and dump profile info\n"
55 "--share-code force jit to produce shared code\n"
56 "--print-vtable print the VTable of all used classes\n"
57 "--workers n maximum number of worker threads\n"
58 "--stabs write stabs debug information\n"
59 "--dwarf write dwarf2 debug information\n"
60 "--dwarf-plus write extended dwarf2 debug information\n"
61 "--stats print statistics about the jit operations\n"
62 "--noinline do not inline code\n"
63 "--compile cname compile methods in given class (namespace.name[:methodname])\n"
64 "--ncompile num compile methods num times (default: 1000)\n"
65 "--debug name insert a breakpoint at the start of method name\n"
66 "--help print this help message\n");
72 main (int argc, char *argv [])
75 MonoAssembly *assembly;
77 int compile_times = 1000;
78 char *compile_class = NULL;
80 gboolean testjit = FALSE;
81 int stack, verbose = FALSE;
83 mono_end_of_stack = &stack; /* a pointer to a local variable is always < BP */
88 for (i = 1; i < argc && argv [i][0] == '-'; i++){
89 if (strcmp (argv [i], "--help") == 0) {
91 } else if (strcmp (argv [i], "-d") == 0) {
93 mono_jit_dump_asm = TRUE;
94 mono_jit_dump_forest = TRUE;
95 } else if (strcmp (argv [i], "--dump-asm") == 0)
96 mono_jit_dump_asm = TRUE;
97 else if (strcmp (argv [i], "--dump-forest") == 0)
98 mono_jit_dump_forest = TRUE;
99 else if (strcmp (argv [i], "--trace") == 0)
100 mono_jit_trace_calls = TRUE;
101 else if (strcmp (argv [i], "--share-code") == 0)
102 mono_jit_share_code = TRUE;
103 else if (strcmp (argv [i], "--noinline") == 0)
104 mono_jit_inline_code = FALSE;
105 else if (strcmp (argv [i], "--print-vtable") == 0)
106 mono_print_vtable = TRUE;
107 else if (strcmp (argv [i], "--debug") == 0) {
108 MonoMethodDesc *desc = mono_method_desc_new (argv [++i], FALSE);
110 g_error ("Invalid method name '%s'", argv [i]);
111 mono_debug_methods = g_list_append (mono_debug_methods, desc);
112 } else if (strcmp (argv [i], "--count") == 0) {
113 compile_times = atoi (argv [++i]);
114 } else if (strcmp (argv [i], "--workers") == 0) {
115 mono_worker_threads = atoi (argv [++i]);
116 if (mono_worker_threads < 1)
117 mono_worker_threads = 1;
118 } else if (strcmp (argv [i], "--profile") == 0) {
119 mono_jit_profile = TRUE;
120 mono_profiler_install_simple ();
121 } else if (strcmp (argv [i], "--compile") == 0) {
122 compile_class = argv [++i];
123 } else if (strcmp (argv [i], "--ncompile") == 0) {
124 compile_times = atoi (argv [++i]);
125 } else if (strcmp (argv [i], "--stats") == 0) {
126 memset (&mono_jit_stats, 0, sizeof (MonoJitStats));
127 mono_jit_stats.enabled = TRUE;
128 } else if (strcmp (argv [i], "--stabs") == 0) {
129 if (mono_debug_handle)
130 g_error ("You can use either --stabs or --dwarf, but not both.");
131 mono_debug_handle = mono_debug_open_file ("", MONO_DEBUG_FORMAT_STABS);
132 } else if (strcmp (argv [i], "--dwarf") == 0) {
133 if (mono_debug_handle)
134 g_error ("You can use either --stabs or --dwarf, but not both.");
135 mono_debug_handle = mono_debug_open_file ("", MONO_DEBUG_FORMAT_DWARF2);
136 } else if (strcmp (argv [i], "--dwarf-plus") == 0) {
137 if (mono_debug_handle)
138 g_error ("You can use either --stabs or --dwarf, but not both.");
139 mono_debug_handle = mono_debug_open_file ("", MONO_DEBUG_FORMAT_DWARF2_PLUS);
140 } else if (strcmp (argv [i], "--verbose") == 0) {
151 domain = mono_jit_init (file);
153 error = mono_verify_corlib ();
155 fprintf (stderr, "Corlib not in sync with this runtime: %s\n", error);
159 assembly = mono_domain_assembly_open (domain, file);
161 fprintf (stderr, "Can not open image %s\n", file);
166 mono_jit_assembly (assembly);
167 } else if (compile_class) {
168 const char *cmethod = strrchr (compile_class, ':');
175 MonoMethodDesc *mdesc;
177 mdesc = mono_method_desc_new (compile_class, FALSE);
179 g_error ("Invalid method name '%s'", compile_class);
180 m = mono_method_desc_search_in_image (mdesc, assembly->image);
182 g_error ("Cannot find method '%s'", compile_class);
183 for (j = 0; j < compile_times; ++j) {
184 code = arch_compile_method (m);
188 cname = strrchr (compile_class, '.');
192 cname = compile_class;
193 compile_class = (char *)"";
195 class = mono_class_from_name (assembly->image, compile_class, cname);
197 g_error ("Cannot find class %s.%s", compile_class, cname);
198 mono_class_init (class);
199 for (j = 0; j < compile_times; ++j) {
200 for (i = 0; i < class->method.count; ++i) {
201 if (class->methods [i]->iflags & METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL)
203 if (class->methods [i]->flags & METHOD_ATTRIBUTE_ABSTRACT)
206 g_print ("Compiling: %s\n", class->methods [i]->name);
207 code = arch_compile_method (class->methods [i]);
214 * skip the program name from the args.
217 retval = mono_jit_exec (domain, assembly, argc - i, argv + i);
218 printf ("RESULT: %d\n", retval);
221 mono_profiler_shutdown ();
222 mono_jit_cleanup (domain);