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

Unify two identical implementations of class_kind in SGen GC bridges #107909

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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: 0 additions & 1 deletion src/mono/mono/metadata/sgen-bridge-internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ typedef struct {
void (*processing_stw_step) (void);
void (*processing_build_callback_data) (int generation);
void (*processing_after_callback) (int generation);
MonoGCBridgeObjectKind (*class_kind) (MonoClass *klass);
void (*register_finalized_object) (GCObject *object);
void (*describe_pointer) (GCObject *object);

Expand Down
28 changes: 27 additions & 1 deletion src/mono/mono/metadata/sgen-bridge.c
Original file line number Diff line number Diff line change
Expand Up @@ -486,10 +486,36 @@ sgen_bridge_processing_finish (int generation)
mono_bridge_processing_in_progress = FALSE;
}

// Is this class bridged or not, and should its dependencies be scanned or not?
// The result of this callback will be cached for use by is_opaque_object later.
MonoGCBridgeObjectKind
sgen_bridge_class_kind (MonoClass *klass)
{
return bridge_processor.class_kind (klass);
MonoGCBridgeObjectKind res = mono_bridge_callbacks.bridge_class_kind (klass);

/* If it's a bridge, nothing we can do about it. */
if (res == GC_BRIDGE_TRANSPARENT_BRIDGE_CLASS || res == GC_BRIDGE_OPAQUE_BRIDGE_CLASS)
return res;

/* Non bridge classes with no pointers will never point to a bridge, so we can savely ignore them. */
if (!m_class_has_references (klass)) {
SGEN_LOG (6, "class %s is opaque\n", m_class_get_name (klass));
return GC_BRIDGE_OPAQUE_CLASS;
}

/* Some arrays can be ignored */
if (m_class_get_rank (klass) == 1) {
MonoClass *elem_class = m_class_get_element_class (klass);

/* FIXME the bridge check can be quite expensive, cache it at the class level. */
/* An array of a sealed type that is not a bridge will never get to a bridge */
if ((mono_class_get_flags (elem_class) & TYPE_ATTRIBUTE_SEALED) && !m_class_has_references (elem_class) && !mono_bridge_callbacks.bridge_class_kind (elem_class)) {
SGEN_LOG (6, "class %s is opaque\n", m_class_get_name (klass));
return GC_BRIDGE_OPAQUE_CLASS;
}
}

return GC_BRIDGE_TRANSPARENT_CLASS;
}

void
Expand Down
31 changes: 0 additions & 31 deletions src/mono/mono/metadata/sgen-new-bridge.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,36 +176,6 @@ set_config (const SgenBridgeProcessorConfig *config)
}
}

static MonoGCBridgeObjectKind
class_kind (MonoClass *klass)
{
MonoGCBridgeObjectKind res = mono_bridge_callbacks.bridge_class_kind (klass);

/* If it's a bridge, nothing we can do about it. */
if (res == GC_BRIDGE_TRANSPARENT_BRIDGE_CLASS || res == GC_BRIDGE_OPAQUE_BRIDGE_CLASS)
return res;

/* Non bridge classes with no pointers will never point to a bridge, so we can savely ignore them. */
if (!m_class_has_references (klass)) {
SGEN_LOG (6, "class %s is opaque\n", m_class_get_name (klass));
return GC_BRIDGE_OPAQUE_CLASS;
}

/* Some arrays can be ignored */
if (m_class_get_rank (klass) == 1) {
MonoClass *elem_class = m_class_get_element_class (klass);

/* FIXME the bridge check can be quite expensive, cache it at the class level. */
/* An array of a sealed type that is not a bridge will never get to a bridge */
if ((mono_class_get_flags (elem_class) & TYPE_ATTRIBUTE_SEALED) && !m_class_has_references (elem_class) && !mono_bridge_callbacks.bridge_class_kind (elem_class)) {
SGEN_LOG (6, "class %s is opaque\n", m_class_get_name (klass));
return GC_BRIDGE_OPAQUE_CLASS;
}
}

return GC_BRIDGE_TRANSPARENT_CLASS;
}

static HashEntry*
get_hash_entry (MonoObject *obj, gboolean *existing)
{
Expand Down Expand Up @@ -1081,7 +1051,6 @@ sgen_new_bridge_init (SgenBridgeProcessor *collector)
collector->processing_stw_step = processing_stw_step;
collector->processing_build_callback_data = processing_build_callback_data;
collector->processing_after_callback = processing_after_callback;
collector->class_kind = class_kind;
collector->register_finalized_object = register_finalized_object;
collector->describe_pointer = describe_pointer;
collector->set_config = set_config;
Expand Down
33 changes: 0 additions & 33 deletions src/mono/mono/metadata/sgen-tarjan-bridge.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,38 +40,6 @@
* which colors. The color graph then becomes the reduced SCC graph.
*/

// Is this class bridged or not, and should its dependencies be scanned or not?
// The result of this callback will be cached for use by is_opaque_object later.
static MonoGCBridgeObjectKind
class_kind (MonoClass *klass)
{
MonoGCBridgeObjectKind res = mono_bridge_callbacks.bridge_class_kind (klass);

/* If it's a bridge, nothing we can do about it. */
if (res == GC_BRIDGE_TRANSPARENT_BRIDGE_CLASS || res == GC_BRIDGE_OPAQUE_BRIDGE_CLASS)
return res;

/* Non bridge classes with no pointers will never point to a bridge, so we can savely ignore them. */
if (!m_class_has_references (klass)) {
SGEN_LOG (6, "class %s is opaque\n", m_class_get_name (klass));
return GC_BRIDGE_OPAQUE_CLASS;
}

/* Some arrays can be ignored */
if (m_class_get_rank (klass) == 1) {
MonoClass *elem_class = m_class_get_element_class (klass);

/* FIXME the bridge check can be quite expensive, cache it at the class level. */
/* An array of a sealed type that is not a bridge will never get to a bridge */
if ((mono_class_get_flags (elem_class) & TYPE_ATTRIBUTE_SEALED) && !m_class_has_references (elem_class) && !mono_bridge_callbacks.bridge_class_kind (elem_class)) {
SGEN_LOG (6, "class %s is opaque\n", m_class_get_name (klass));
return GC_BRIDGE_OPAQUE_CLASS;
}
}

return GC_BRIDGE_TRANSPARENT_CLASS;
}

//enable usage logging
// #define DUMP_GRAPH 1

Expand Down Expand Up @@ -1260,7 +1228,6 @@ sgen_tarjan_bridge_init (SgenBridgeProcessor *collector)
collector->processing_stw_step = processing_stw_step;
collector->processing_build_callback_data = processing_build_callback_data;
collector->processing_after_callback = processing_after_callback;
collector->class_kind = class_kind;
collector->register_finalized_object = register_finalized_object;
collector->describe_pointer = describe_pointer;
collector->set_config = set_config;
Expand Down
Loading