Example #1
0
static Slot*
new_slot (MonoGHashTable *hash)
{
	if (hash->gc_type == MONO_HASH_CONSERVATIVE_GC)
		return mono_gc_alloc_fixed (sizeof (Slot), NULL);
	else
		return mg_new (Slot, 1);
}
Example #2
0
static int
continuation_store (MonoContinuation *cont, int state, MonoException **e)
{
	MonoLMF *lmf = mono_get_lmf ();
	gsize num_bytes;

	if (!cont->domain) {
		*e =  mono_get_exception_argument ("cont", "Continuation not initialized");
		return 0;
	}
	if (cont->domain != mono_domain_get () || cont->thread_id != GetCurrentThreadId ()) {
		*e = mono_get_exception_argument ("cont", "Continuation from another thread or domain");
		return 0;
	}

	cont->lmf = lmf;
	cont->return_ip = __builtin_return_address (0);
	cont->return_sp = __builtin_frame_address (0);

	num_bytes = (char*)cont->top_sp - (char*)cont->return_sp;

	/*g_print ("store: %d bytes, sp: %p, ip: %p, lmf: %p\n", num_bytes, cont->return_sp, cont->return_ip, lmf);*/

	if (cont->saved_stack && num_bytes <= cont->stack_alloc_size) {
		/* clear to avoid GC retention */
		if (num_bytes < cont->stack_used_size) {
			memset ((char*)cont->saved_stack + num_bytes, 0, cont->stack_used_size - num_bytes);
		}
		cont->stack_used_size = num_bytes;
	} else {
		tasklets_lock ();
		internal_init ();
		if (cont->saved_stack) {
			mono_g_hash_table_remove (keepalive_stacks, cont->saved_stack);
			mono_gc_free_fixed (cont->saved_stack);
		}
		cont->stack_used_size = num_bytes;
		cont->stack_alloc_size = num_bytes * 1.1;
		cont->saved_stack = mono_gc_alloc_fixed (cont->stack_alloc_size, NULL);
		mono_g_hash_table_insert (keepalive_stacks, cont->saved_stack, cont->saved_stack);
		tasklets_unlock ();
	}
	memcpy (cont->saved_stack, cont->return_sp, num_bytes);

	return state;
}
Example #3
0
static int
continuation_store (MonoContinuation *cont, int state, MonoException **e)
{
	MonoLMF *lmf = mono_get_lmf ();
	gsize num_bytes;

	if (!cont->domain) {
		*e =  mono_get_exception_argument ("cont", "Continuation not initialized");
		return 0;
	}
	if (cont->domain != mono_domain_get () || !mono_native_thread_id_equals (cont->thread_id, mono_native_thread_id_get ())) {
		*e = mono_get_exception_argument ("cont", "Continuation from another thread or domain");
		return 0;
	}

	cont->lmf = lmf;
	cont->return_ip = __builtin_extract_return_addr (__builtin_return_address (0));
	cont->return_sp = __builtin_frame_address (0);

	num_bytes = (char*)cont->top_sp - (char*)cont->return_sp;

	/*g_print ("store: %d bytes, sp: %p, ip: %p, lmf: %p\n", num_bytes, cont->return_sp, cont->return_ip, lmf);*/

	if (cont->saved_stack && num_bytes <= cont->stack_alloc_size) {
		/* clear to avoid GC retention */
		if (num_bytes < cont->stack_used_size) {
			memset ((char*)cont->saved_stack + num_bytes, 0, cont->stack_used_size - num_bytes);
		}
		cont->stack_used_size = num_bytes;
	} else {
		tasklets_lock ();
		internal_init ();
		if (cont->saved_stack)
			mono_gc_free_fixed (cont->saved_stack);
		cont->stack_used_size = num_bytes;
		cont->stack_alloc_size = num_bytes * 1.1;
		cont->saved_stack = mono_gc_alloc_fixed (cont->stack_alloc_size, NULL, MONO_ROOT_SOURCE_THREADING, "saved tasklet stack");
		tasklets_unlock ();
	}
	memcpy (cont->saved_stack, cont->return_sp, num_bytes);

	return state;
}
Example #4
0
static inline MonoGHashNode*
g_hash_node_new (gpointer key,
		 gpointer value,
		 gint gc_type)
{
  MonoGHashNode *hash_node = NULL;

#if HAVE_BOEHM_GC
  if (node_free_lists [gc_type]) {
	  G_LOCK (g_hash_global);

	  if (node_free_lists [gc_type]) {
		  hash_node = node_free_lists [gc_type];
		  node_free_lists [gc_type] = node_free_lists [gc_type]->next;
	  }
	  G_UNLOCK (g_hash_global);
  }
  if (!hash_node) {
	  if (gc_type != MONO_HASH_CONSERVATIVE_GC) {
		  //hash_node = GC_MALLOC (sizeof (MonoGHashNode));
		  hash_node = GC_MALLOC_EXPLICITLY_TYPED (sizeof (MonoGHashNode), (GC_descr)node_gc_descs [gc_type]);
	  } else {
		  hash_node = GC_MALLOC (sizeof (MonoGHashNode));
	  }
  }
#elif defined(HAVE_SGEN_GC)
  if (node_free_lists [gc_type]) {
	  G_LOCK (g_hash_global);

	  if (node_free_lists [gc_type]) {
		  hash_node = node_free_lists [gc_type];
		  node_free_lists [gc_type] = node_free_lists [gc_type]->next;
	  }
	  G_UNLOCK (g_hash_global);
  }
  if (!hash_node) {
	  if (gc_type != MONO_HASH_CONSERVATIVE_GC) {
		  /* 
		   * Marking is handled by the marker function, no need to allocate GC visible
		   * memory.
		   */
		  if (!node_mem_chunk)
			  node_mem_chunk = g_mem_chunk_new ("hash node mem chunk",
												sizeof (MonoGHashNode),
												1024, G_ALLOC_ONLY);
		  hash_node = g_chunk_new (MonoGHashNode, node_mem_chunk);
	  } else {
		  hash_node = mono_gc_alloc_fixed (sizeof (MonoGHashNode), NULL);
	  }
  }
#else
  G_LOCK (g_hash_global);
  if (node_free_list)
    {
      hash_node = node_free_list;
      node_free_list = node_free_list->next;
    }
  else
    {
      if (!node_mem_chunk)
	node_mem_chunk = g_mem_chunk_new ("hash node mem chunk",
					  sizeof (MonoGHashNode),
					  1024, G_ALLOC_ONLY);
      
      hash_node = g_chunk_new (MonoGHashNode, node_mem_chunk);
    }
  G_UNLOCK (g_hash_global);
#endif

  SET_NODE_KEY (hash_node, gc_type, key);
  SET_NODE_VALUE (hash_node, gc_type, value);
  hash_node->next = NULL;
  
  return hash_node;
}