Merge pull request #5428 from kumpera/wasm-support-p2
authorRodrigo Kumpera <kumpera@users.noreply.github.com>
Fri, 8 Sep 2017 18:55:38 +0000 (14:55 -0400)
committerGitHub <noreply@github.com>
Fri, 8 Sep 2017 18:55:38 +0000 (14:55 -0400)
Mono Wasm support

1  2 
configure.ac
mono/metadata/object.c
mono/mini/mini-exceptions.c
mono/sgen/sgen-gc.c

diff --combined configure.ac
index c2d59d88407f5e0cfbdff1ac84cbdce31ff8aef2,72892380d5a2f68df5f549410f52c5de3654e0b5..bad8ecc8e3c8d08b5978acdf663d81535eb076be
@@@ -40,8 -40,8 +40,8 @@@ MONO_VERSION_BUILD=`echo $VERSION | cu
  # This can be reset to 0 when Mono's version number is bumped
  # since it's part of the corlib version (the prefix '1' in the full
  # version number is to ensure the number isn't treated as octal in C)
 -MONO_CORLIB_COUNTER=0
 -MONO_CORLIB_VERSION=`printf "1%02d%02d%02d%03d" $MONO_VERSION_MAJOR $MONO_VERSION_MINOR $MONO_VERSION_BUILD $MONO_CORLIB_COUNTER`
 +MONO_CORLIB_COUNTER=1
 +MONO_CORLIB_VERSION=`printf "1%02d%02d%02d%03d" $MONO_VERSION_MAJOR $MONO_VERSION_MINOR 0 $MONO_CORLIB_COUNTER`
  
  AC_DEFINE_UNQUOTED(MONO_CORLIB_VERSION,$MONO_CORLIB_VERSION,[Version of the corlib-runtime interface])
  AC_SUBST(MONO_CORLIB_VERSION)
@@@ -117,8 -117,8 +117,8 @@@ host_darwin=n
  
  
  if test "x$enable_wasm" = "xyes"; then
- CFLAGS="$CFLAGS -D_REENTRANT -D_GNU_SOURCE -DNO_UNALIGNED_ACCESS -s WASM=1 -DWASM -Os"
- CPPFLAGS="$CPPFLAGS -D_REENTRANT -DUSE_MMAP -D_GNU_SOURCE -DNO_UNALIGNED_ACCESS -s WASM=1 -DWASM -Os"
+ CFLAGS="$CFLAGS -D_REENTRANT -D_GNU_SOURCE -DNO_UNALIGNED_ACCESS -s WASM=1"
+ CPPFLAGS="$CPPFLAGS -D_REENTRANT -DUSE_MMAP -D_GNU_SOURCE -DNO_UNALIGNED_ACCESS -s WASM=1"
  libdl="-ldl"
  libgc_threads=pthreads
  
@@@ -555,7 -555,18 +555,18 @@@ AC_CHECK_FUNCS(_finite, , AC_MSG_CHECKI
  AC_CHECK_HEADERS(linux/magic.h)
  
  # not 64 bit clean in cross-compile
- AC_CHECK_SIZEOF(void *, 4)
+ if test "x$enable_wasm" = "xyes"; then
+ AC_DEFINE(SIZEOF_VOID_P,4)
+ AC_DEFINE(SIZEOF_LONG,4)
+ ac_cv_sizeof_void_p="4"
+ ac_cv_sizeof_long="4"
+ else
+ AC_CHECK_SIZEOF(void *)
+ AC_CHECK_SIZEOF(long)
+ fi
+ AC_CHECK_SIZEOF(int)
+ AC_CHECK_SIZEOF(long long)
  
  AC_CACHE_CHECK([for clang],
        mono_cv_clang,[
@@@ -1502,8 -1513,6 +1513,8 @@@ if test x$host_win32 = xno; the
                AC_CHECK_FUNCS(getpwuid_r)
        fi
  
 +      AC_FUNC_STRERROR_R()
 +
        dnl ****************************************************************
        dnl *** Check for sched_setaffinity from glibc versions before   ***
        dnl *** 2.3.4. The older versions of the function only take 2    ***
@@@ -3067,6 -3076,7 +3078,7 @@@ TARGET=WAS
  HOST=WASM
  arch_target=wasm
  AC_DEFINE(TARGET_WASM, 1, [Target wasm])
+ AC_DEFINE(HOST_WASM, 1, [Host wasm])
  BTLS_SUPPORTED=no
  with_tls=pthread
  target_mach=no
@@@ -3752,10 -3762,6 +3764,6 @@@ AC_SUBST(PIDTYPE
  AC_DEFINE(HAVE_CLASSIC_WINAPI_SUPPORT, 1, [Use classic Windows API support])
  AC_DEFINE(HAVE_UWP_WINAPI_SUPPORT, 0, [Don't use UWP Windows API support])
  
- AC_CHECK_SIZEOF(int)
- AC_CHECK_SIZEOF(void *)
- AC_CHECK_SIZEOF(long)
- AC_CHECK_SIZEOF(long long)
  AC_CHECK_FUNCS(strlcpy stpcpy strtok_r rewinddir vasprintf strerror_r)
  AC_CHECK_FUNCS(getrlimit)
  AC_CHECK_FUNCS(fork execv execve)
@@@ -4342,6 -4348,7 +4350,7 @@@ AM_CONDITIONAL(POWERPC64, test x$TARGE
  AM_CONDITIONAL(ARM, test x$TARGET = xARM)
  AM_CONDITIONAL(ARM64, test x$TARGET = xARM64)
  AM_CONDITIONAL(S390X, test x$TARGET = xS390X)
+ AM_CONDITIONAL(WASM, test x$TARGET = xWASM)
  AM_CONDITIONAL(HOST_X86, test x$HOST = xX86)
  AM_CONDITIONAL(HOST_AMD64, test x$HOST = xAMD64)
  AM_CONDITIONAL(HOST_ARM, test x$HOST = xARM)
@@@ -4373,7 -4380,7 +4382,7 @@@ AC_SUBST(mono_build_root
  mono_runtime=mono/mini/mono
  AC_SUBST(mono_runtime)
  
 -CSC_LOCATION=`cd $srcdir && pwd`/external/roslyn-binaries/Microsoft.Net.Compilers/Microsoft.Net.Compilers.2.3.1/tools/csc.exe
 +CSC_LOCATION=`cd $srcdir && pwd`/external/roslyn-binaries/Microsoft.Net.Compilers/Microsoft.Net.Compilers.2.3.2/tools/csc.exe
  
  if test $csc_compiler = mcs; then
    CSC=$mcs_topdir/class/lib/build/mcs.exe
diff --combined mono/metadata/object.c
index 38dfb764e46f92ef329aed59ab559b4c070a3faf,cef662c5b0c41c4d1268be3ff5ccd7c7963e01ef..2ea88c75f8cfde20ecb362453f027e16dbe1225a
@@@ -2565,7 -2565,7 +2565,7 @@@ mono_remote_class (MonoDomain *domain, 
        rc->xdomain_vtable = NULL;
        rc->proxy_class_name = name;
  #ifndef DISABLE_PERFCOUNTERS
 -      mono_perfcounters->loader_bytes += mono_string_length (MONO_HANDLE_RAW (class_name)) + 1;
 +      InterlockedAdd (&mono_perfcounters->loader_bytes, mono_string_length (MONO_HANDLE_RAW (class_name)) + 1);
  #endif
  
        g_hash_table_insert (domain->proxy_vtable_hash, key, rc);
@@@ -5257,8 -5257,9 +5257,9 @@@ mono_object_new_checked (MonoDomain *do
  
        MonoVTable *vtable;
  
-       vtable = mono_class_vtable (domain, klass);
-       g_assert (vtable); /* FIXME don't swallow the error */
+       vtable = mono_class_vtable_full (domain, klass, error);
+       if (!is_ok (error))
+               return NULL;
  
        MonoObject *o = mono_object_new_specific_checked (vtable, error);
        return o;
index 611201eecd7f6a490714df7889f2431ed1d7209b,ae4a87ccae0ef6293e1400c9018455242024bbaf..10cf1b75cb194d9051761962546b5ffba8b9f8f8
  #define MONO_ARCH_CONTEXT_DEF
  #endif
  
 -#ifndef MONO_ARCH_STACK_GROWS_UP
 -#define MONO_ARCH_STACK_GROWS_UP 0
 -#endif
 -
  /*
   * Raw frame information is stored in MonoException.trace_ips as an IntPtr[].
   * This structure represents one entry.
@@@ -145,6 -149,18 +145,6 @@@ mono_thread_get_managed_sp (void
        return addr;
  }
  
 -static inline int
 -mini_abort_threshold_offset (gpointer threshold, gpointer sp)
 -{
 -      intptr_t stack_threshold = (intptr_t) threshold;
 -      intptr_t stack_pointer = (intptr_t) sp;
 -
 -      const int direction = MONO_ARCH_STACK_GROWS_UP ? -1 : 1;
 -      intptr_t magnitude = stack_pointer - stack_threshold;
 -
 -      return direction * magnitude;
 -}
 -
  static inline void
  mini_clear_abort_threshold (void)
  {
@@@ -160,7 -176,7 +160,7 @@@ mini_set_abort_threshold (MonoContext *
        // Only move it up, to avoid thrown/caught
        // exceptions lower in the stack from triggering
        // a rethrow
 -      gboolean above_threshold = mini_abort_threshold_offset (jit_tls->abort_exc_stack_threshold, sp) >= 0;
 +      gboolean above_threshold = (gsize) sp >= (gsize) jit_tls->abort_exc_stack_threshold;
        if (!jit_tls->abort_exc_stack_threshold || above_threshold) {
                jit_tls->abort_exc_stack_threshold = sp;
        }
@@@ -178,7 -194,7 +178,7 @@@ mini_above_abort_threshold (void
        if (!sp)
                return TRUE;
  
 -      gboolean above_threshold = mini_abort_threshold_offset (jit_tls->abort_exc_stack_threshold, sp) >= 0;
 +      gboolean above_threshold = (gsize) sp >= (gsize) jit_tls->abort_exc_stack_threshold;
  
        if (above_threshold)
                jit_tls->abort_exc_stack_threshold = sp;
@@@ -1669,7 -1685,10 +1669,7 @@@ mono_handle_exception_internal_first_pa
                        dynamic_methods = g_slist_prepend (dynamic_methods, method);
  
                if (stack_overflow) {
 -                      if (MONO_ARCH_STACK_GROWS_UP)
 -                              free_stack = (guint8*)(MONO_CONTEXT_GET_SP (&initial_ctx)) - (guint8*)(MONO_CONTEXT_GET_SP (ctx));
 -                      else
 -                              free_stack = (guint8*)(MONO_CONTEXT_GET_SP (ctx)) - (guint8*)(MONO_CONTEXT_GET_SP (&initial_ctx));
 +                      free_stack = (guint8*)(MONO_CONTEXT_GET_SP (ctx)) - (guint8*)(MONO_CONTEXT_GET_SP (&initial_ctx));
                } else {
                        free_stack = 0xffffff;
                }
  
                                if (ei->flags == MONO_EXCEPTION_CLAUSE_FILTER) {
  #ifndef DISABLE_PERFCOUNTERS
 -                                      mono_perfcounters->exceptions_filters++;
 +                                      InterlockedIncrement (&mono_perfcounters->exceptions_filters);
  #endif
  
  #ifndef MONO_CROSS_COMPILE
@@@ -2025,7 -2044,10 +2025,7 @@@ mono_handle_exception_internal (MonoCon
                //printf ("M: %s %d.\n", mono_method_full_name (method, TRUE), frame_count);
  
                if (stack_overflow) {
 -                      if (MONO_ARCH_STACK_GROWS_UP)
 -                              free_stack = (guint8*)(MONO_CONTEXT_GET_SP (&initial_ctx)) - (guint8*)(MONO_CONTEXT_GET_SP (ctx));
 -                      else
 -                              free_stack = (guint8*)(MONO_CONTEXT_GET_SP (ctx)) - (guint8*)(MONO_CONTEXT_GET_SP (&initial_ctx));
 +                      free_stack = (guint8*)(MONO_CONTEXT_GET_SP (ctx)) - (guint8*)(MONO_CONTEXT_GET_SP (&initial_ctx));
                } else {
                        free_stack = 0xffffff;
                }
                                        }
                                        mono_set_lmf (lmf);
  #ifndef DISABLE_PERFCOUNTERS
 -                                      mono_perfcounters->exceptions_depth += frame_count;
 +                                      InterlockedAdd (&mono_perfcounters->exceptions_depth, frame_count);
  #endif
                                        if (obj == (MonoObject *)domain->stack_overflow_ex)
                                                jit_tls->handling_stack_ovf = FALSE;
                                        MONO_PROFILER_RAISE (exception_clause, (method, i, ei->flags, ex_obj));
                                        jit_tls->orig_ex_ctx_set = FALSE;
  #ifndef DISABLE_PERFCOUNTERS
 -                                      mono_perfcounters->exceptions_finallys++;
 +                                      InterlockedIncrement (&mono_perfcounters->exceptions_finallys);
  #endif
                                }
                                if (ei->flags == MONO_EXCEPTION_CLAUSE_FAULT || ei->flags == MONO_EXCEPTION_CLAUSE_FINALLY) {
@@@ -2277,7 -2299,7 +2277,7 @@@ mono_handle_exception (MonoContext *ctx
        MONO_REQ_GC_UNSAFE_MODE;
  
  #ifndef DISABLE_PERFCOUNTERS
 -      mono_perfcounters->exceptions_thrown++;
 +      InterlockedIncrement (&mono_perfcounters->exceptions_thrown);
  #endif
  
        return mono_handle_exception_internal (ctx, obj, FALSE, NULL);
@@@ -3263,7 -3285,7 +3263,7 @@@ mono_llvm_load_exception (void
  
        if (mono_ex->trace_ips) {
                GList *trace_ips = NULL;
-               gpointer ip = __builtin_return_address (0);
+               gpointer ip = RETURN_ADDRESS ();
  
                size_t upper = mono_array_length (mono_ex->trace_ips);
  
diff --combined mono/sgen/sgen-gc.c
index beb5ce1b2580c265935db3200a138fd91f31c9a4,1c54fc261f9ecd5133b5edc84f467de7169917ec..d5416f0df3630ee6a6bc5b4781bc0e9c5442873c
  
  #include <mono/utils/memcheck.h>
  #include <mono/utils/mono-mmap-internals.h>
 +#include <mono/utils/unlocked.h>
  
  #undef pthread_create
  #undef pthread_join
@@@ -337,13 -336,6 +337,6 @@@ nursery_canaries_enabled (void
  
  #define safe_object_get_size  sgen_safe_object_get_size
  
- #if defined(HAVE_CONC_GC_AS_DEFAULT)
- /* Use concurrent major on deskstop platforms */
- #define DEFAULT_MAJOR SGEN_MAJOR_CONCURRENT
- #else
- #define DEFAULT_MAJOR SGEN_MAJOR_SERIAL
- #endif
  typedef enum {
        SGEN_MAJOR_DEFAULT,
        SGEN_MAJOR_SERIAL,
@@@ -1863,7 -1855,7 +1856,7 @@@ collect_nursery (const char *reason, gb
        major_collector.finish_nursery_collection ();
  
        TV_GETTIME (last_minor_collection_end_tv);
 -      InterlockedAdd64 (&gc_stats.minor_gc_time, TV_ELAPSED (last_minor_collection_start_tv, last_minor_collection_end_tv));
 +      UnlockedAdd64 (&gc_stats.minor_gc_time, TV_ELAPSED (last_minor_collection_start_tv, last_minor_collection_end_tv));
  
        sgen_debug_dump_heap ("minor", InterlockedRead (&gc_stats.minor_gc_count) - 1, NULL);
  
@@@ -2357,7 -2349,7 +2350,7 @@@ major_do_collection (const char *reason
        sgen_gray_object_queue_dispose (&gc_thread_gray_queue);
  
        TV_GETTIME (time_end);
 -      InterlockedAdd64 (&gc_stats.major_gc_time, TV_ELAPSED (time_start, time_end));
 +      UnlockedAdd64 (&gc_stats.major_gc_time, TV_ELAPSED (time_start, time_end));
  
        /* FIXME: also report this to the user, preferably in gc-end. */
        if (major_collector.get_and_reset_num_major_objects_marked)
@@@ -2393,7 -2385,7 +2386,7 @@@ major_start_concurrent_collection (cons
        num_objects_marked = major_collector.get_and_reset_num_major_objects_marked ();
  
        TV_GETTIME (time_end);
 -      InterlockedAdd64 (&gc_stats.major_gc_time, TV_ELAPSED (time_start, time_end));
 +      UnlockedAdd64 (&gc_stats.major_gc_time, TV_ELAPSED (time_start, time_end));
  
        current_collection_generation = -1;
  }
@@@ -2421,7 -2413,7 +2414,7 @@@ major_update_concurrent_collection (voi
        sgen_los_update_cardtable_mod_union ();
  
        TV_GETTIME (total_end);
 -      InterlockedAdd64 (&gc_stats.major_gc_time, TV_ELAPSED (total_start, total_end));
 +      UnlockedAdd64 (&gc_stats.major_gc_time, TV_ELAPSED (total_start, total_end));
  }
  
  static void
@@@ -2443,7 -2435,7 +2436,7 @@@ major_finish_concurrent_collection (gbo
        sgen_workers_stop_all_workers (GENERATION_OLD);
  
        SGEN_TV_GETTIME (time_major_conc_collection_end);
 -      InterlockedAdd64 (&gc_stats.major_gc_time_concurrent, SGEN_TV_ELAPSED (time_major_conc_collection_start, time_major_conc_collection_end));
 +      UnlockedAdd64 (&gc_stats.major_gc_time_concurrent, SGEN_TV_ELAPSED (time_major_conc_collection_start, time_major_conc_collection_end));
  
        major_collector.update_cardtable_mod_union ();
        sgen_los_update_cardtable_mod_union ();
        sgen_gray_object_queue_dispose (&gc_thread_gray_queue);
  
        TV_GETTIME (total_end);
 -      InterlockedAdd64 (&gc_stats.major_gc_time, TV_ELAPSED (total_start, total_end));
 +      UnlockedAdd64 (&gc_stats.major_gc_time, TV_ELAPSED (total_start, total_end));
  
        current_collection_generation = -1;
  }