Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resurrect null GC. #1468

Draft
wants to merge 1 commit into
base: unity-2021.2-mbe-pre-upgrade
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions mono/metadata/domain-internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ struct _MonoDomain {
MonoCoopMutex lock;
MonoMemPool *mp;
MonoCodeManager *code_mp;
void *gc_mp;
/*
* keep all the managed objects close to each other for the precise GC
* For the Boehm GC we additionally keep close also other GC-tracked pointers.
Expand Down
2 changes: 1 addition & 1 deletion mono/metadata/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ mono_domain_finalize (MonoDomain *domain, guint32 timeout)

/* We don't support domain finalization without a GC */
if (mono_gc_is_null ())
return FALSE;
return TRUE;

mono_gc_collect (mono_gc_max_generation ());

Expand Down
39 changes: 34 additions & 5 deletions mono/metadata/null-gc-handles.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ static mono_mutex_t handle_section;
#define lock_handles(handles) mono_os_mutex_lock (&handle_section)
#define unlock_handles(handles) mono_os_mutex_unlock (&handle_section)


void mono_gc_handle_lock () { lock_handles (NULL); }
void mono_gc_handle_unlock () { unlock_handles (NULL); }

typedef struct {
guint32 *bitmap;
gpointer *entries;
Expand Down Expand Up @@ -116,7 +120,7 @@ handle_data_alloc_entries (HandleData *handles)
handles->entries = (void **)g_malloc0 (sizeof (*handles->entries) * handles->size);
handles->domain_ids = (guint16 *)g_malloc0 (sizeof (*handles->domain_ids) * handles->size);
} else {
handles->entries = (void **)mono_gc_alloc_fixed (sizeof (*handles->entries) * handles->size, NULL, MONO_ROOT_SOURCE_GC_HANDLE, "GC Handle Table (Null)");
handles->entries = (void **)mono_gc_alloc_fixed (sizeof (*handles->entries) * handles->size, NULL, MONO_ROOT_SOURCE_GC_HANDLE, NULL, "GC Handle Table (Null)");
}
handles->bitmap = (guint32 *)g_malloc0 (handles->size / CHAR_BIT);
}
Expand Down Expand Up @@ -183,7 +187,7 @@ handle_data_grow (HandleData *handles, gboolean track)
handles->domain_ids = domain_ids;
} else {
gpointer *entries;
entries = (void **)mono_gc_alloc_fixed (sizeof (*handles->entries) * new_size, NULL, MONO_ROOT_SOURCE_GC_HANDLE, "GC Handle Table (Null)");
entries = (void **)mono_gc_alloc_fixed (sizeof (*handles->entries) * new_size, NULL, MONO_ROOT_SOURCE_GC_HANDLE, NULL, "GC Handle Table (Null)");
mono_gc_memmove_aligned (entries, handles->entries, sizeof (*handles->entries) * handles->size);
mono_gc_free_fixed (handles->entries);
handles->entries = entries;
Expand Down Expand Up @@ -224,7 +228,7 @@ alloc_handle (HandleData *handles, MonoObject *obj, gboolean track)
#endif
unlock_handles (handles);
res = MONO_GC_HANDLE (slot, handles->type);
mono_profiler_gc_handle (MONO_PROFILER_GC_HANDLE_CREATED, handles->type, res, obj);
MONO_PROFILER_RAISE (gc_handle_created, (res, handles->type, obj));
return res;
}

Expand Down Expand Up @@ -416,7 +420,7 @@ mono_gchandle_free (guint32 gchandle)
#endif
/*g_print ("freed entry %d of type %d\n", slot, handles->type);*/
unlock_handles (handles);
mono_profiler_gc_handle (MONO_PROFILER_GC_HANDLE_DESTROYED, handles->type, gchandle, NULL);
MONO_PROFILER_RAISE (gc_handle_deleted, (gchandle, handles->type));
}

/**
Expand All @@ -431,7 +435,7 @@ mono_gchandle_free_domain (MonoDomain *domain)
{
guint type;

for (type = HANDLE_TYPE_MIN; type < HANDLE_PINNED; ++type) {
for (type = HANDLE_TYPE_MIN; type <= HANDLE_PINNED; ++type) {
guint slot;
HandleData *handles = &gc_handles [type];
lock_handles (handles);
Expand All @@ -455,6 +459,31 @@ mono_gchandle_free_domain (MonoDomain *domain)
}

}

void
mono_gc_strong_handle_foreach (GFunc func, gpointer user_data)
{
int gcHandleTypeIndex;
uint32_t i;

lock_handles (handles);

for (gcHandleTypeIndex = HANDLE_NORMAL; gcHandleTypeIndex <= HANDLE_PINNED; gcHandleTypeIndex++)
{
HandleData* handles = &gc_handles[gcHandleTypeIndex];

for (i = 0; i < handles->size; i++)
{
if (!slot_occupied (handles, i))
continue;
if (handles->entries[i] != NULL)
func (handles->entries[i], user_data);
}
}

unlock_handles (handles);
}

#else

MONO_EMPTY_SOURCE_FILE (null_gc_handles);
Expand Down
Loading