2002-07-24 Tim Coleman <tim@timcoleman.com>
[mono.git] / mono / jit / mono.c
index 1e0485732db3f72c23d15d5268d7a0f8676d4856..2b5ba165bc41b9d1789c24fc893c61cbb47d2013 100644 (file)
 #include "mono/metadata/debug-helpers.h"
 #include "mono/metadata/verify.h"
 #include "mono/metadata/profiler.h"
+#include "mono/metadata/threadpool.h"
+#include "mono/metadata/mono-config.h"
+#include <mono/metadata/profiler-private.h>
 #include <mono/os/util.h>
 
-/**
- * mono_jit_image:
- * @image: reference to an image
- * @verbose: If true, print debugging information on stdout.
- *
- * JIT compilation of all methods in the image.
- */
-void
-mono_jit_compile_image (MonoImage *image, int verbose)
-{
-       MonoMethod *method;
-       MonoTableInfo *t = &image->tables [MONO_TABLE_METHOD];
-       int i;
-
-       for (i = 0; i < t->rows; i++) {
-
-               method = mono_get_method (image, 
-                                         (MONO_TABLE_METHOD << 24) | (i + 1), 
-                                         NULL);
-
-               if (verbose)
-                       g_print ("Compiling: %s:%s\n\n", image->assembly_name, method->name);
-
-               if (method->flags & METHOD_ATTRIBUTE_ABSTRACT) {
-                       if (verbose)
-                               printf ("ABSTARCT\n");
-               } else
-                       arch_compile_method (method);
-
-       }
-
-}
-
 static MonoClass *
 find_class_in_assembly (MonoAssembly *assembly, const char *namespace, const char *name)
 {
@@ -110,6 +80,7 @@ mono_jit_compile_class (MonoAssembly *assembly, char *compile_class,
        char *code;
        int i, j;
        MonoClass *class;
+       MonoDomain *domain = mono_domain_get ();
 
        if (compile_class [0] == '@') {
                MonoImage *image = mono_image_loaded (compile_class + 1);
@@ -129,8 +100,9 @@ mono_jit_compile_class (MonoAssembly *assembly, char *compile_class,
                if (!m)
                        g_error ("Cannot find method '%s'", compile_class);
                for (j = 0; j < compile_times; ++j) {
-                       code = arch_compile_method (m);
+                       code = mono_compile_method (m);
                        // g_free (code);
+                       g_hash_table_remove (domain->jit_code_hash, m);
                }
        } else {
                cname = strrchr (compile_class, '.');
@@ -153,7 +125,8 @@ mono_jit_compile_class (MonoAssembly *assembly, char *compile_class,
                                if (verbose)
                                        g_print ("Compiling: %s.%s:%s\n",
                                                 compile_class, cname, class->methods [i]->name);
-                               code = arch_compile_method (class->methods [i]);
+                               code = mono_compile_method (class->methods [i]);
+                               g_hash_table_remove (domain->jit_code_hash, class->methods [i]);
                                // g_free (code);
                        }
                }
@@ -164,8 +137,8 @@ static void
 usage (char *name)
 {
        fprintf (stderr,
-                "%s %s, the Mono ECMA CLI JIT Compiler, (C) 2001, 2002 Ximian, Inc.\n\n"
-                "Usage is: %s [options] executable args...\n\n", name,  VERSION, name);
+                "mono %s, the Mono ECMA CLI JIT Compiler, (C) 2001, 2002 Ximian, Inc.\n\n"
+                "Usage is: %s [options] executable args...\n\n",  VERSION, name);
        fprintf (stderr,
                 "Runtime Debugging:\n"
                 "    -d                 debug the jit, show disassembler output.\n"
@@ -182,24 +155,27 @@ usage (char *name)
                 "    --ncompile NUM     compile methods NUM times (default: 1000)\n"
                 "\n"
                 "Development:\n"
-                "    --debug FORMAT     write a debugging file.  FORMAT is one of:\n"
+                "    --debug[=FORMAT]   write a debugging file.  FORMAT is one of:\n"
                 "                         stabs        to write stabs information\n"
                 "                         dwarf        to write dwarf2 information\n"
                 "                         dwarf-plus   to write extended dwarf2 information\n"
                 "    --debug-args ARGS  comma-separated list of additional arguments for the\n"
                 "                       symbol writer.  See the manpage for details.\n"
                 "    --profile          record and dump profile info\n"
+                "    --breakonex        set a breakpoint for unhandled exception\n"
                 "    --break NAME       insert a breakpoint at the start of method NAME\n"
                 "                       (NAME is in `namespace.name:methodname' format)\n"
-                "    --precomile name   precompile NAME before executing the main application:\n"
+                "    --precompile name  precompile NAME before executing the main application:\n"
                 "                       NAME is in one of the following formats:\n"
                 "                         namespace.name          compile the given class\n"
                 "                         namespace.name:method   compile the given method\n"
                 "                         @imagename              compile the given image\n"
                 "\n"
                 "Runtime:\n"
+                "    --config filename  Load specified config file instead of the default.\n"
                 "    --fast-iconv       Use fast floating point integer conversion\n"
                 "    --noinline         Disable code inliner\n"
+                "    --nointrinsic      Disable memcopy inliner\n"
                 "    --nols             disable linear scan register allocation\n"
                 "    --share-code       force jit to produce shared code\n"
                 "    --workers n        maximum number of worker threads\n"
@@ -216,9 +192,9 @@ main (int argc, char *argv [])
        int compile_times = 1000;
        char *compile_class = NULL;
        char *debug_args = NULL;
-       char *file, *error;
+       char *file, *error, *config_file = NULL;
        gboolean testjit = FALSE;
-       int stack, verbose = FALSE;
+       int verbose = FALSE;
        GList *precompile_classes = NULL;
 
        g_log_set_always_fatal (G_LOG_LEVEL_ERROR);
@@ -244,8 +220,12 @@ main (int argc, char *argv [])
                        mono_jit_share_code = TRUE;
                else if (strcmp (argv [i], "--noinline") == 0)
                        mono_jit_inline_code = FALSE;
+               else if (strcmp (argv [i], "--nointrinsic") == 0)
+                       mono_inline_memcpy = FALSE;
                else if (strcmp (argv [i], "--nols") == 0)
                        mono_use_linear_scan = FALSE;
+               else if (strcmp (argv [i], "--breakonex") == 0)
+                       mono_break_on_exc = TRUE;
                else if (strcmp (argv [i], "--print-vtable") == 0)
                        mono_print_vtable = TRUE;
                else if (strcmp (argv [i], "--break") == 0) {
@@ -255,6 +235,8 @@ main (int argc, char *argv [])
                        mono_debug_methods = g_list_append (mono_debug_methods, desc);
                } else if (strcmp (argv [i], "--count") == 0) {
                        compile_times = atoi (argv [++i]);
+               } else if (strcmp (argv [i], "--config") == 0) {
+                       config_file = argv [++i];
                } else if (strcmp (argv [i], "--workers") == 0) {
                        mono_worker_threads = atoi (argv [++i]);
                        if (mono_worker_threads < 1)
@@ -269,17 +251,23 @@ main (int argc, char *argv [])
                } else if (strcmp (argv [i], "--stats") == 0) {
                        memset (&mono_jit_stats, 0, sizeof (MonoJitStats));
                        mono_jit_stats.enabled = TRUE;
-               } else if (strcmp (argv [i], "--debug") == 0) {
+               } else if (strncmp (argv [i], "--debug=", 8) == 0) {
+                       const char *format = &argv [i][8];
+                               
                        if (mono_debug_format != MONO_DEBUG_FORMAT_NONE)
                                g_error ("You can only use one debugging format.");
-                       if (strcmp (argv [++i], "stabs") == 0)
+                       if (strcmp (format, "stabs") == 0)
                                mono_debug_format = MONO_DEBUG_FORMAT_STABS;
-                       else if (strcmp (argv [i], "dwarf") == 0)
+                       else if (strcmp (format, "dwarf") == 0)
                                mono_debug_format = MONO_DEBUG_FORMAT_DWARF2;
-                       else if (strcmp (argv [i], "dwarf-plus") == 0)
+                       else if (strcmp (format, "dwarf-plus") == 0)
                                mono_debug_format = MONO_DEBUG_FORMAT_DWARF2_PLUS;
                        else
-                               g_error ("Unknown debugging format: %s", argv [i]);
+                               g_error ("Unknown debugging format: %s", argv [i] + 8);
+               } else if (strcmp (argv [i], "--debug") == 0) {
+                       if (mono_debug_format != MONO_DEBUG_FORMAT_NONE)
+                               g_error ("You can only use one debugging format.");
+                       mono_debug_format = MONO_DEBUG_FORMAT_DWARF2_PLUS;
                } else if (strcmp (argv [i], "--debug-args") == 0) {
                        if (debug_args)
                                g_error ("You can use --debug-args only once.");
@@ -299,6 +287,7 @@ main (int argc, char *argv [])
        if (!file)
                usage (argv [0]);
 
+       mono_config_parse (config_file);
        mono_set_rootdir (argv [0]);
        domain = mono_jit_init (file);
 
@@ -315,10 +304,12 @@ main (int argc, char *argv [])
        }
 
        if (mono_debug_format != MONO_DEBUG_FORMAT_NONE) {
+               MonoDebugHandle *debug;
                gchar **args;
 
                args = g_strsplit (debug_args ? debug_args : "", ",", -1);
-               mono_debug_open (assembly, mono_debug_format, (const char **) args);
+               debug = mono_debug_open (assembly, mono_debug_format, (const char **) args);
+               mono_debug_add_image (debug, assembly->image);
                g_strfreev (args);
        }
 
@@ -333,7 +324,6 @@ main (int argc, char *argv [])
                        mono_jit_compile_class (assembly, tmp->data, 1, verbose);
 
                retval = mono_jit_exec (domain, assembly, argc - i, argv + i);
-               printf ("RESULT: %d\n", retval);
        }
 
        mono_profiler_shutdown ();