2 * mono.c: Main driver for the Mono JIT engine
5 * Dietmar Maurer (dietmar@ximian.com)
7 * (C) 2001, 2002 Ximian, Inc (http://www.ximian.com)
13 #include "mono/metadata/debug-helpers.h"
14 #include "mono/metadata/verify.h"
15 #include "mono/metadata/profiler.h"
16 #include <mono/os/util.h>
20 * @assembly: reference to an assembly
22 * JIT compilation of all methods in the assembly. Prints debugging
23 * information on stdout.
26 mono_jit_assembly (MonoAssembly *assembly)
28 MonoImage *image = assembly->image;
30 MonoTableInfo *t = &image->tables [MONO_TABLE_METHOD];
33 for (i = 0; i < t->rows; i++) {
35 method = mono_get_method (image,
36 (MONO_TABLE_METHOD << 24) | (i + 1),
39 printf ("\nMethod: %s\n\n", method->name);
41 if (method->flags & METHOD_ATTRIBUTE_ABSTRACT)
42 printf ("ABSTARCT\n");
44 arch_compile_method (method);
54 "%s %s, the Mono ECMA CLI JIT Compiler, (C) 2001, 2002 Ximian, Inc.\n\n"
55 "Usage is: %s [options] executable args...\n\n", name, VERSION, name);
57 "Runtime Debugging:\n"
58 " -d debug the jit, show disassembler output.\n"
59 " --dump-asm dumps the assembly code generated\n"
60 " --dump-forest dumps the reconstructed forest\n"
61 " --print-vtable print the VTable of all used classes\n"
62 " --stats print statistics about the jit operations\n"
63 " --trace printf function call trace\n"
64 " --compile cname compile methods in given class\n"
65 " format: (namespace.name[:methodname])\n"
66 " --ncompile num compile methods num times (default: 1000)\n"
69 " --dwarf write dwarf2 debug information\n"
70 " --dwarf-plus write extended dwarf2 debug information\n"
71 " --profile record and dump profile info\n"
72 " --stabs write stabs debug information\n"
73 " --debug name insert a breakpoint at the start of method name\n"
76 " --fast-iconv Use fast floating point integer conversion\n"
77 " --noinline Disable code inliner\n"
78 " --nols disable linear scan register allocation\n"
79 " --share-code force jit to produce shared code\n"
80 " --workers n maximum number of worker threads\n"
86 main (int argc, char *argv [])
89 MonoAssembly *assembly;
91 int compile_times = 1000;
92 char *compile_class = NULL;
94 gboolean testjit = FALSE;
95 int stack, verbose = FALSE;
97 g_log_set_always_fatal (G_LOG_LEVEL_ERROR);
98 g_log_set_fatal_mask (G_LOG_DOMAIN, G_LOG_LEVEL_ERROR);
103 for (i = 1; i < argc && argv [i][0] == '-'; i++){
104 if (strcmp (argv [i], "--help") == 0) {
106 } else if (strcmp (argv [i], "-d") == 0) {
108 mono_jit_dump_asm = TRUE;
109 mono_jit_dump_forest = TRUE;
110 } else if (strcmp (argv [i], "--dump-asm") == 0)
111 mono_jit_dump_asm = TRUE;
112 else if (strcmp (argv [i], "--dump-forest") == 0)
113 mono_jit_dump_forest = TRUE;
114 else if (strcmp (argv [i], "--trace") == 0)
115 mono_jit_trace_calls = TRUE;
116 else if (strcmp (argv [i], "--share-code") == 0)
117 mono_jit_share_code = TRUE;
118 else if (strcmp (argv [i], "--noinline") == 0)
119 mono_jit_inline_code = FALSE;
120 else if (strcmp (argv [i], "--nols") == 0)
121 mono_use_linear_scan = FALSE;
122 else if (strcmp (argv [i], "--print-vtable") == 0)
123 mono_print_vtable = TRUE;
124 else if (strcmp (argv [i], "--debug") == 0) {
125 MonoMethodDesc *desc = mono_method_desc_new (argv [++i], FALSE);
127 g_error ("Invalid method name '%s'", argv [i]);
128 mono_debug_methods = g_list_append (mono_debug_methods, desc);
129 } else if (strcmp (argv [i], "--count") == 0) {
130 compile_times = atoi (argv [++i]);
131 } else if (strcmp (argv [i], "--workers") == 0) {
132 mono_worker_threads = atoi (argv [++i]);
133 if (mono_worker_threads < 1)
134 mono_worker_threads = 1;
135 } else if (strcmp (argv [i], "--profile") == 0) {
136 mono_jit_profile = TRUE;
137 mono_profiler_install_simple ();
138 } else if (strcmp (argv [i], "--compile") == 0) {
139 compile_class = argv [++i];
140 } else if (strcmp (argv [i], "--ncompile") == 0) {
141 compile_times = atoi (argv [++i]);
142 } else if (strcmp (argv [i], "--stats") == 0) {
143 memset (&mono_jit_stats, 0, sizeof (MonoJitStats));
144 mono_jit_stats.enabled = TRUE;
145 } else if (strcmp (argv [i], "--stabs") == 0) {
146 if (mono_debug_format != MONO_DEBUG_FORMAT_NONE)
147 g_error ("You can only use one debugging format.");
148 mono_debug_format = MONO_DEBUG_FORMAT_STABS;
149 } else if (strcmp (argv [i], "--dwarf") == 0) {
150 if (mono_debug_format != MONO_DEBUG_FORMAT_NONE)
151 g_error ("You can only use one debugging format.");
152 mono_debug_format = MONO_DEBUG_FORMAT_DWARF2;
153 } else if (strcmp (argv [i], "--dwarf-plus") == 0) {
154 if (mono_debug_format != MONO_DEBUG_FORMAT_NONE)
155 g_error ("You can only use one debugging format.");
156 mono_debug_format = MONO_DEBUG_FORMAT_DWARF2_PLUS;
157 } else if (strcmp (argv [i], "--verbose") == 0) {
159 } else if (strcmp (argv [i], "--fast-iconv") == 0) {
160 mono_use_fast_iconv = TRUE;
170 if (mono_debug_format != MONO_DEBUG_FORMAT_NONE)
171 mono_debug_handle = mono_debug_open_file (file, mono_debug_format);
173 mono_set_rootdir (argv [0]);
174 domain = mono_jit_init (file);
176 error = mono_verify_corlib ();
178 fprintf (stderr, "Corlib not in sync with this runtime: %s\n", error);
182 assembly = mono_domain_assembly_open (domain, file);
184 fprintf (stderr, "Can not open image %s\n", file);
189 mono_jit_assembly (assembly);
190 } else if (compile_class) {
191 const char *cmethod = strrchr (compile_class, ':');
198 MonoMethodDesc *mdesc;
200 mdesc = mono_method_desc_new (compile_class, FALSE);
202 g_error ("Invalid method name '%s'", compile_class);
203 m = mono_method_desc_search_in_image (mdesc, assembly->image);
205 g_error ("Cannot find method '%s'", compile_class);
206 for (j = 0; j < compile_times; ++j) {
207 code = arch_compile_method (m);
211 cname = strrchr (compile_class, '.');
215 cname = compile_class;
216 compile_class = (char *)"";
218 class = mono_class_from_name (assembly->image, compile_class, cname);
220 g_error ("Cannot find class %s.%s", compile_class, cname);
221 mono_class_init (class);
222 for (j = 0; j < compile_times; ++j) {
223 for (i = 0; i < class->method.count; ++i) {
224 if (class->methods [i]->iflags & METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL)
226 if (class->methods [i]->flags & METHOD_ATTRIBUTE_ABSTRACT)
229 g_print ("Compiling: %s\n", class->methods [i]->name);
230 code = arch_compile_method (class->methods [i]);
236 retval = mono_jit_exec (domain, assembly, argc - i, argv + i);
237 printf ("RESULT: %d\n", retval);
240 mono_profiler_shutdown ();
241 mono_jit_cleanup (domain);