Exemple #1
0
void
mono_gc_base_init (void)
{
  MonoThreadInfoCallbacks cb;
  int dummy;

  if (gc_initialized)
    return;

  mono_counters_init ();

  corgc_init ();

  memset (&cb, 0, sizeof (cb));
  cb.thread_register = corgc_thread_register;
  cb.thread_unregister = corgc_thread_unregister;
  cb.mono_method_is_critical = (gboolean(*)(void*))mono_runtime_is_critical_method;
#ifndef HOST_WIN32
  cb.thread_exit = mono_gc_pthread_exit;
  cb.mono_gc_pthread_create = mono_gc_pthread_create;
#endif
  mono_threads_init (&cb, sizeof (CorgcThreadInfo));
  mono_thread_info_attach (&dummy);

  mono_gc_enable_events ();
  gc_initialized = TRUE;
}
int
main (void)
{
	MonoThreadInfoCallbacks cb = { NULL };
	MonoThreadInfoRuntimeCallbacks ticallbacks;
	int res = 0;

	CHECKED_MONO_INIT ();
	mono_threads_init (&cb, sizeof (MonoThreadInfo));
	memset (&ticallbacks, 0, sizeof (ticallbacks));
	ticallbacks.thread_state_init = thread_state_init;
	mono_threads_runtime_init (&ticallbacks);

	mono_thread_info_attach ((gpointer)&cb);

	// benchmark_conc ();
	// benchmark_glib ();

	res += single_writer_single_reader ();
	res += parallel_writer_single_reader ();
	res += single_writer_parallel_reader ();
	res += parallel_writer_parallel_reader ();

	return res;
}
Exemple #3
0
void
mono_gc_base_init (void)
{
	MonoThreadInfoCallbacks cb;

	memset (&cb, 0, sizeof (cb));
	cb.mono_method_is_critical = mono_runtime_is_critical_method;
	cb.mono_gc_pthread_create = (gpointer)mono_gc_pthread_create;

	mono_threads_init (&cb, sizeof (MonoThreadInfo));
}
Exemple #4
0
void
mono_gc_base_init (void)
{
	MonoThreadInfoCallbacks cb;
	int dummy;

	mono_counters_init ();

	memset (&cb, 0, sizeof (cb));
	/* TODO: This casts away an incompatible pointer type warning in the same
	         manner that boehm-gc does it. This is probably worth investigating
	         more carefully. */
	cb.mono_method_is_critical = (gpointer)mono_runtime_is_critical_method;

	mono_threads_init (&cb, sizeof (MonoThreadInfo));

	mono_thread_info_attach (&dummy);
}
int
main (int argc, char *argv [])
{
	int primes [] = { 1, 2, 3, 5, 7, 11, 13, 17 };
	MonoThreadInfoCallbacks thread_callbacks;
	thread_data_t thread_data [NUM_THREADS];
	int i;

	memset (&thread_callbacks, 0, sizeof (thread_callbacks));

	mono_metadata_init ();

	mono_threads_init (&thread_callbacks, 0);

	mono_thread_smr_init ();
	mono_lls_init (&lls, free_node);

	for (i = 0; i < N; ++i) {
		nodes [i].node.key = i;
		nodes [i].state = STATE_OUT;
	}

	for (i = 0; i < NUM_THREADS; ++i) {
		int result;

		thread_data [i].num_adds = thread_data [i].num_removes = 0;
		thread_data [i].skip = primes [i];
		result = pthread_create (&thread_data [i].thread, NULL, worker, &thread_data [i]);
		assert (!result);
	}

	for (i = 0; i < NUM_THREADS; ++i) {
		int result = pthread_join (thread_data [i].thread, NULL);
		assert (!result);
		printf ("thread %d  adds %d  removes %d\n", i, thread_data [i].num_adds, thread_data [i].num_removes);
	}

	return 0;
}
Exemple #6
0
void
mono_gc_base_init (void)
{
	MonoThreadInfoCallbacks cb;
	char *env;

	if (gc_initialized)
		return;

	/*
	 * Handle the case when we are called from a thread different from the main thread,
	 * confusing libgc.
	 * FIXME: Move this to libgc where it belongs.
	 *
	 * we used to do this only when running on valgrind,
	 * but it happens also in other setups.
	 */
#if defined(HAVE_PTHREAD_GETATTR_NP) && defined(HAVE_PTHREAD_ATTR_GETSTACK)
	{
		size_t size;
		void *sstart;
		pthread_attr_t attr;
		pthread_getattr_np (pthread_self (), &attr);
		pthread_attr_getstack (&attr, &sstart, &size);
		pthread_attr_destroy (&attr); 
		/*g_print ("stackbottom pth is: %p\n", (char*)sstart + size);*/
#ifdef __ia64__
		/*
		 * The calculation above doesn't seem to work on ia64, also we need to set
		 * GC_register_stackbottom as well, but don't know how.
		 */
#else
		/* apparently with some linuxthreads implementations sstart can be NULL,
		 * fallback to the more imprecise method (bug# 78096).
		 */
		if (sstart) {
			GC_stackbottom = (char*)sstart + size;
		} else {
			int dummy;
			gsize stack_bottom = (gsize)&dummy;
			stack_bottom += 4095;
			stack_bottom &= ~4095;
			GC_stackbottom = (char*)stack_bottom;
		}
#endif
	}
#elif defined(HAVE_PTHREAD_GET_STACKSIZE_NP) && defined(HAVE_PTHREAD_GET_STACKADDR_NP)
		GC_stackbottom = (char*)pthread_get_stackaddr_np (pthread_self ());
#elif defined(__OpenBSD__)
#  include <pthread_np.h>
	{
		stack_t ss;
		int rslt;

		rslt = pthread_stackseg_np(pthread_self(), &ss);
		g_assert (rslt == 0);

		GC_stackbottom = (char*)ss.ss_sp;
	}
#elif defined(__native_client__)
	/* Do nothing, GC_stackbottom is set correctly in libgc */
#else
	{
		int dummy;
		gsize stack_bottom = (gsize)&dummy;
		stack_bottom += 4095;
		stack_bottom &= ~4095;
		/*g_print ("stackbottom is: %p\n", (char*)stack_bottom);*/
		GC_stackbottom = (char*)stack_bottom;
	}
#endif

#if !defined(PLATFORM_ANDROID)
	/* If GC_no_dls is set to true, GC_find_limit is not called. This causes a seg fault on Android. */
	GC_no_dls = TRUE;
#endif
	GC_init ();
	GC_oom_fn = mono_gc_out_of_memory;
	GC_set_warn_proc (mono_gc_warning);
	GC_finalize_on_demand = 1;
	GC_finalizer_notifier = mono_gc_finalize_notify;

#ifdef HAVE_GC_GCJ_MALLOC
	GC_init_gcj_malloc (5, NULL);
#endif

#ifdef HAVE_GC_ALLOW_REGISTER_THREADS
	GC_allow_register_threads();
#endif

	if ((env = getenv ("MONO_GC_PARAMS"))) {
		char **ptr, **opts = g_strsplit (env, ",", -1);
		for (ptr = opts; *ptr; ++ptr) {
			char *opt = *ptr;
			if (g_str_has_prefix (opt, "max-heap-size=")) {
				glong max_heap;

				opt = strchr (opt, '=') + 1;
				if (*opt && mono_gc_parse_environment_string_extract_number (opt, &max_heap)) {
					if (max_heap < MIN_BOEHM_MAX_HEAP_SIZE) {
						fprintf (stderr, "max-heap-size must be at least %dMb.\n", MIN_BOEHM_MAX_HEAP_SIZE_IN_MB);
						exit (1);
					}
					GC_set_max_heap_size (max_heap);
				} else {
					fprintf (stderr, "max-heap-size must be an integer.\n");
					exit (1);
				}
				continue;
			} else {
				fprintf (stderr, "MONO_GC_PARAMS must be a comma-delimited list of one or more of the following:\n");
				fprintf (stderr, "  max-heap-size=N (where N is an integer, possibly with a k, m or a g suffix)\n");
				exit (1);
			}
		}
		g_strfreev (opts);
	}

	memset (&cb, 0, sizeof (cb));
	cb.thread_register = boehm_thread_register;
	cb.mono_method_is_critical = (gpointer)mono_runtime_is_critical_method;
#ifndef HOST_WIN32
	cb.mono_gc_pthread_create = (gpointer)mono_gc_pthread_create;
#endif
	
	mono_threads_init (&cb, sizeof (MonoThreadInfo));

	mono_gc_enable_events ();
	gc_initialized = TRUE;
}