2007-07-19 Mark Probst <mark.probst@gmail.com>
[mono.git] / mono / mini / driver.c
index 09ff7c97973d7282afbe64db40aa76e406c8455b..4d9cabda8e1e623c7587ad1b3e8c5b9a5ccaf10e 100644 (file)
 
 #include <config.h>
 #include <signal.h>
+#if HAVE_SCHED_SETAFFINITY
+#include <sched.h>
+#endif
+#ifdef HAVE_UNISTD_H
 #include <unistd.h>
+#endif
 
 #include <mono/metadata/assembly.h>
 #include <mono/metadata/loader.h>
 #include <ctype.h>
 #include "inssel.h"
 #include <locale.h>
+#include "version.h"
 
 static FILE *mini_stats_fd = NULL;
 
 static void mini_usage (void);
 
-extern int mini_wapi_hps (int argc, char **argv);
-extern int mini_wapi_semdel (int argc, char **argv);
-extern int mini_wapi_seminfo (int argc, char **argv);
-
 /* This turns off command line globbing under win32 */
 #ifdef PLATFORM_WIN32
 int _CRT_glob = 0;
@@ -326,7 +328,6 @@ mini_regression (MonoImage *image, int verbose, int *total_run) {
        *total_run = 0;
        for (opt = 0; opt < G_N_ELEMENTS (opt_sets); ++opt) {
                double elapsed, comp_time, start_time;
-               MonoJitInfo *jinfo;
 
                opt_flags = opt_sets [opt];
                mono_set_defaults (verbose, opt_flags);
@@ -339,8 +340,8 @@ mini_regression (MonoImage *image, int verbose, int *total_run) {
                /* fixme: ugly hack - delete all previously compiled methods */
                g_hash_table_destroy (mono_domain_get ()->jit_trampoline_hash);
                mono_domain_get ()->jit_trampoline_hash = g_hash_table_new (mono_aligned_addr_hash, NULL);
-               g_hash_table_destroy (mono_domain_get ()->jit_code_hash);
-               mono_domain_get ()->jit_code_hash = g_hash_table_new (mono_aligned_addr_hash, NULL);
+               mono_internal_hash_table_destroy (&(mono_domain_get ()->jit_code_hash));
+               mono_jit_code_hash_init (&(mono_domain_get ()->jit_code_hash));
 
                g_timer_start (timer);
                if (mini_stats_fd)
@@ -358,8 +359,8 @@ mini_regression (MonoImage *image, int verbose, int *total_run) {
                                        if (verbose >= 2)
                                                g_print ("Running '%s' ...\n", method->name);
 #ifdef MONO_USE_AOT_COMPILER
-                                       if ((jinfo = mono_aot_get_method (mono_get_root_domain (), method)))
-                                               func = jinfo->code_start;
+                                       if ((func = mono_aot_get_method (mono_get_root_domain (), method)))
+                                               ;
                                        else
 #endif
                                                func = (TestMethod)(gpointer)cfg->native_code;
@@ -386,8 +387,13 @@ mini_regression (MonoImage *image, int verbose, int *total_run) {
                        fprintf (mini_stats_fd, "],\n");
                g_timer_stop (timer);
                elapsed = g_timer_elapsed (timer, NULL);
-               g_print ("Results: total tests: %d, failed: %d, cfailed: %d (pass: %.2f%%)\n", 
-                       run, failed, cfailed, 100.0*(run-failed-cfailed)/run);
+               if (failed > 0 || cfailed > 0){
+                       g_print ("Results: total tests: %d, failed: %d, cfailed: %d (pass: %.2f%%)\n", 
+                                run, failed, cfailed, 100.0*(run-failed-cfailed)/run);
+               } else {
+                       g_print ("Results: total tests: %d, all pass \n",  run);
+               }
+               
                g_print ("Elapsed time: %f secs (%f, %f), Code size: %d\n\n", elapsed, 
                         elapsed - comp_time, comp_time, code_size);
                total += failed + cfailed;
@@ -419,8 +425,14 @@ mini_regression_list (int verbose, int count, char *images [])
                total += mini_regression (mono_assembly_get_image (ass), verbose, &run);
                total_run += run;
        }
-       g_print ("Overall results: tests: %d, failed: %d, opt combinations: %d (pass: %.2f%%)\n", 
-               total_run, total, (int)G_N_ELEMENTS (opt_sets), 100.0*(total_run-total)/total_run);
+       if (total > 0){
+               g_print ("Overall results: tests: %d, failed: %d, opt combinations: %d (pass: %.2f%%)\n", 
+                        total_run, total, (int)G_N_ELEMENTS (opt_sets), 100.0*(total_run-total)/total_run);
+       } else {
+               g_print ("Overall results: tests: %d, 100%% pass, opt combinations: %d\n", 
+                        total_run, (int)G_N_ELEMENTS (opt_sets));
+       }
+       
        return total;
 }
 
@@ -620,6 +632,7 @@ mini_usage (void)
                "    --verbose, -v          Increases the verbosity level\n"
                "    --help, -h             Show usage information\n"
                "    --version, -V          Show version information\n"
+               "    --runtime=VERSION      Use the VERSION runtime, instead of autodetecting\n"
                "    --optimize=OPT         Turns on or off a specific optimization\n"
                "                           Use --list-opt to get a list of optimizations\n"
                "    --security             Turns on the security manager (unsupported, default is off)\n");
@@ -657,6 +670,7 @@ static const char info[] =
 #else
     "\tSIGSEGV:       normal\n"
 #endif
+        "\tArchitecture:  " ARCHITECTURE "\n"
        "\tDisabled:      " DISABLED_FEATURES "\n"
        "";
 
@@ -680,9 +694,19 @@ mono_main (int argc, char* argv[])
        char *trace_options = NULL;
        char *profile_options = NULL;
        char *aot_options = NULL;
+       char *forced_version = NULL;
 
        setlocale (LC_ALL, "");
 
+#if HAVE_SCHED_SETAFFINITY
+       if (getenv ("MONO_NO_SMP")) {
+               unsigned long proc_mask = 1;
+               sched_setaffinity (getpid(), sizeof (unsigned long), &proc_mask);
+       }
+#endif
+       if (!g_thread_supported ())
+               g_thread_init (NULL);
+
        if (mono_running_on_valgrind () && getenv ("MONO_VALGRIND_LEAK_CHECK")) {
                GMemVTable mem_vtable;
 
@@ -712,7 +736,7 @@ mono_main (int argc, char* argv[])
                } else if (strcmp (argv [i], "--verbose") == 0 || strcmp (argv [i], "-v") == 0) {
                        mini_verbose++;
                } else if (strcmp (argv [i], "--version") == 0 || strcmp (argv [i], "-V") == 0) {
-                       g_print ("Mono JIT compiler version %s, (C) 2002-2006 Novell, Inc and Contributors. www.mono-project.com\n", VERSION);
+                       g_print ("Mono JIT compiler version %s (%s)\nCopyright (C) 2002-2007 Novell, Inc and Contributors. www.mono-project.com\n", VERSION, FULL_VERSION);
                        g_print (info);
                        if (mini_verbose) {
                                const char *cerror;
@@ -792,6 +816,8 @@ mono_main (int argc, char* argv[])
 #endif
                } else if (strcmp (argv [i], "--compile-all") == 0) {
                        action = DO_COMPILE;
+               } else if (strncmp (argv [i], "--runtime=", 10) == 0) {
+                       forced_version = &argv [i][10];
                } else if (strcmp (argv [i], "--profile") == 0) {
                        enable_profile = TRUE;
                        profile_options = NULL;
@@ -900,7 +926,7 @@ mono_main (int argc, char* argv[])
        }
 
        mono_set_defaults (mini_verbose, opt);
-       domain = mini_init (argv [i]);
+       domain = mini_init (argv [i], forced_version);
        
        switch (action) {
        case DO_REGRESSION:
@@ -959,7 +985,7 @@ mono_main (int argc, char* argv[])
 
        assembly = mono_assembly_open (aname, NULL);
        if (!assembly) {
-               fprintf (stderr, "cannot open assembly %s\n", aname);
+               fprintf (stderr, "Cannot open assembly %s.\n", aname);
                mini_cleanup (domain);
                return 2;
        }
@@ -978,13 +1004,15 @@ mono_main (int argc, char* argv[])
                error = mono_check_corlib_version ();
                if (error) {
                        fprintf (stderr, "Corlib not in sync with this runtime: %s\n", error);
+                       fprintf (stderr, "Loaded from: %s\n",
+                               mono_defaults.corlib? mono_image_get_filename (mono_defaults.corlib): "unknown");
                        fprintf (stderr, "Download a newer corlib or a newer runtime at http://www.go-mono.com/daily.\n");
                        exit (1);
                }
 
 #ifdef PLATFORM_WIN32
                /* Detach console when executing IMAGE_SUBSYSTEM_WINDOWS_GUI on win32 */
-               if (!mono_compile_aot && ((MonoCLIImageInfo*)(mono_assembly_get_image (assembly)->image_info))->cli_header.nt.pe_subsys_required == IMAGE_SUBSYSTEM_WINDOWS_GUI)
+               if (!enable_debugging && !mono_compile_aot && ((MonoCLIImageInfo*)(mono_assembly_get_image (assembly)->image_info))->cli_header.nt.pe_subsys_required == IMAGE_SUBSYSTEM_WINDOWS_GUI)
                        FreeConsole ();
 #endif
 
@@ -1139,7 +1167,13 @@ mono_main (int argc, char* argv[])
 MonoDomain * 
 mono_jit_init (const char *file)
 {
-       return mini_init (file);
+       return mini_init (file, NULL);
+}
+
+MonoDomain * 
+mono_jit_init_version (const char *file, const char *runtime_version)
+{
+       return mini_init (file, runtime_version);
 }
 
 void