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 "--compile cname compile methods in given class (namespace.name[:methodname])\n"
63 "--ncompile num compile methods num times (default: 1000)\n"
64 "--debug name insert a breakpoint at the start of method name\n"
65 "--help print this help message\n");
71 main (int argc, char *argv [])
74 MonoAssembly *assembly;
76 int compile_times = 1000;
77 char *compile_class = NULL;
79 gboolean testjit = FALSE;
80 int stack, verbose = FALSE;
82 mono_end_of_stack = &stack; /* a pointer to a local variable is always < BP */
87 for (i = 1; i < argc && argv [i][0] == '-'; i++){
88 if (strcmp (argv [i], "--help") == 0) {
90 } else if (strcmp (argv [i], "-d") == 0) {
92 mono_jit_dump_asm = TRUE;
93 mono_jit_dump_forest = TRUE;
94 } else if (strcmp (argv [i], "--dump-asm") == 0)
95 mono_jit_dump_asm = TRUE;
96 else if (strcmp (argv [i], "--dump-forest") == 0)
97 mono_jit_dump_forest = TRUE;
98 else if (strcmp (argv [i], "--trace") == 0)
99 mono_jit_trace_calls = TRUE;
100 else if (strcmp (argv [i], "--share-code") == 0)
101 mono_jit_share_code = TRUE;
102 else if (strcmp (argv [i], "--print-vtable") == 0)
103 mono_print_vtable = TRUE;
104 else if (strcmp (argv [i], "--debug") == 0) {
105 MonoMethodDesc *desc = mono_method_desc_new (argv [++i], FALSE);
107 g_error ("Invalid method name '%s'", argv [i]);
108 mono_debug_methods = g_list_append (mono_debug_methods, desc);
109 } else if (strcmp (argv [i], "--count") == 0) {
110 compile_times = atoi (argv [++i]);
111 } else if (strcmp (argv [i], "--workers") == 0) {
112 mono_worker_threads = atoi (argv [++i]);
113 if (mono_worker_threads < 1)
114 mono_worker_threads = 1;
115 } else if (strcmp (argv [i], "--profile") == 0) {
116 mono_jit_profile = TRUE;
117 mono_profiler_install_simple ();
118 } else if (strcmp (argv [i], "--compile") == 0) {
119 compile_class = argv [++i];
120 } else if (strcmp (argv [i], "--ncompile") == 0) {
121 compile_times = atoi (argv [++i]);
122 } else if (strcmp (argv [i], "--stats") == 0) {
123 memset (&mono_jit_stats, 0, sizeof (MonoJitStats));
124 mono_jit_stats.enabled = TRUE;
125 } else if (strcmp (argv [i], "--stabs") == 0) {
126 if (mono_debug_handle)
127 g_error ("You can use either --stabs or --dwarf, but not both.");
128 mono_debug_handle = mono_debug_open_file ("", MONO_DEBUG_FORMAT_STABS);
129 } else if (strcmp (argv [i], "--dwarf") == 0) {
130 if (mono_debug_handle)
131 g_error ("You can use either --stabs or --dwarf, but not both.");
132 mono_debug_handle = mono_debug_open_file ("", MONO_DEBUG_FORMAT_DWARF2);
133 } else if (strcmp (argv [i], "--dwarf-plus") == 0) {
134 if (mono_debug_handle)
135 g_error ("You can use either --stabs or --dwarf, but not both.");
136 mono_debug_handle = mono_debug_open_file ("", MONO_DEBUG_FORMAT_DWARF2_PLUS);
137 } else if (strcmp (argv [i], "--verbose") == 0) {
148 domain = mono_jit_init (file);
150 error = mono_verify_corlib ();
152 fprintf (stderr, "Corlib not in sync with this runtime: %s\n", error);
156 assembly = mono_domain_assembly_open (domain, file);
158 fprintf (stderr, "Can not open image %s\n", file);
163 mono_jit_assembly (assembly);
164 } else if (compile_class) {
165 const char *cmethod = strrchr (compile_class, ':');
172 MonoMethodDesc *mdesc;
174 mdesc = mono_method_desc_new (compile_class, FALSE);
176 g_error ("Invalid method name '%s'", compile_class);
177 m = mono_method_desc_search_in_image (mdesc, assembly->image);
179 g_error ("Cannot find method '%s'", compile_class);
180 for (j = 0; j < compile_times; ++j) {
181 code = arch_compile_method (m);
185 cname = strrchr (compile_class, '.');
189 cname = compile_class;
190 compile_class = (char *)"";
192 class = mono_class_from_name (assembly->image, compile_class, cname);
194 g_error ("Cannot find class %s.%s", compile_class, cname);
195 mono_class_init (class);
196 for (j = 0; j < compile_times; ++j) {
197 for (i = 0; i < class->method.count; ++i) {
198 if (class->methods [i]->iflags & METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL)
200 if (class->methods [i]->flags & METHOD_ATTRIBUTE_ABSTRACT)
203 g_print ("Compiling: %s\n", class->methods [i]->name);
204 code = arch_compile_method (class->methods [i]);
211 * skip the program name from the args.
214 retval = mono_jit_exec (domain, assembly, argc - i, argv + i);
215 printf ("RESULT: %d\n", retval);
218 mono_profiler_shutdown ();
219 mono_jit_cleanup (domain);