Skip to content

Commit 038c120

Browse files
committed
Cleanup duplicated code with different understandings of locator_t
1 parent 910ef00 commit 038c120

File tree

4 files changed

+59
-75
lines changed

4 files changed

+59
-75
lines changed

src/mono/mono/component/hot_reload.c

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2776,14 +2776,6 @@ add_param_info_for_method (BaselineInfo *base_info, uint32_t param_token, uint32
27762776
}
27772777
}
27782778

2779-
/* HACK - keep in sync with locator_t in metadata/metadata.c */
2780-
typedef struct {
2781-
guint32 idx; /* The index that we are trying to locate */
2782-
guint32 col_idx; /* The index in the row where idx may be stored */
2783-
MonoTableInfo *t; /* pointer to the table */
2784-
guint32 result;
2785-
} upd_locator_t;
2786-
27872779
void*
27882780
hot_reload_metadata_linear_search (MonoImage *base_image, MonoTableInfo *base_table, const void *key, BinarySearchComparer comparer)
27892781
{
@@ -2804,11 +2796,10 @@ hot_reload_metadata_linear_search (MonoImage *base_image, MonoTableInfo *base_ta
28042796
g_assert (success);
28052797
uint32_t rows = table_info_get_rows (latest_mod_table);
28062798

2807-
upd_locator_t *loc = (upd_locator_t*)key;
2799+
locator_t *loc = (locator_t*)key;
28082800
g_assert (loc);
2809-
loc->result = 0;
28102801
/* HACK: this is so that the locator can compute the row index of the given row. but passing the mutant table to other metadata functions could backfire. */
2811-
loc->t = (MonoTableInfo*)latest_mod_table;
2802+
*loc = locator_init ((MonoTableInfo*)latest_mod_table, loc->idx, loc->col_idx);
28122803
for (uint32_t idx = 0; idx < rows; ++idx) {
28132804
const char *row = latest_mod_table->base + idx * latest_mod_table->row_size;
28142805
if (!comparer (loc, row))

src/mono/mono/metadata/debug-mono-ppdb.c

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ enum {
6060
MONO_HAS_CUSTOM_DEBUG_MASK = 0x1f
6161
};
6262

63-
gboolean
63+
gboolean
6464
mono_get_pe_debug_info_full (MonoImage *image, guint8 *out_guid, gint32 *out_age, gint32 *out_timestamp, guint8 **ppdb_data,
6565
int *ppdb_uncompressed_size, int *ppdb_compressed_size, char **pdb_path, GArray *pdb_checksum_hash_type, GArray *pdb_checksum)
6666
{
@@ -761,16 +761,7 @@ mono_ppdb_lookup_locals (MonoDebugMethodInfo *minfo)
761761
return mono_ppdb_lookup_locals_internal (image, method_idx);
762762
}
763763

764-
/*
765-
* We use this to pass context information to the row locator
766-
*/
767-
typedef struct {
768-
guint32 idx; /* The index that we are trying to locate */
769-
guint32 col_idx; /* The index in the row where idx may be stored */
770-
MonoTableInfo *t; /* pointer to the table */
771-
guint32 result;
772-
} locator_t;
773-
764+
// FIXME: This duplicates table_locator from metadata.c
774765
static int
775766
table_locator (const void *a, const void *b)
776767
{
@@ -813,9 +804,11 @@ lookup_custom_debug_information (MonoImage* image, guint32 token, uint8_t parent
813804
if (!table->base)
814805
return 0;
815806

816-
loc.idx = (mono_metadata_token_index (token) << MONO_HAS_CUSTOM_DEBUG_BITS) | parent_type;
817-
loc.col_idx = MONO_CUSTOMDEBUGINFORMATION_PARENT;
818-
loc.t = table;
807+
loc = locator_init (
808+
table,
809+
(mono_metadata_token_index (token) << MONO_HAS_CUSTOM_DEBUG_BITS) | parent_type,
810+
MONO_CUSTOMDEBUGINFORMATION_PARENT
811+
);
819812

820813
if (!mono_binary_search (&loc, table->base, table_info_get_rows (table), table->row_size, table_locator))
821814
return NULL;

src/mono/mono/metadata/metadata-internals.h

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,6 +1134,56 @@ mono_metadata_get_class_guid (MonoClass* klass, uint8_t* guid, MonoError *error)
11341134

11351135
#define MONO_CLASS_IS_INTERFACE_INTERNAL(c) ((mono_class_get_flags (c) & TYPE_ATTRIBUTE_INTERFACE) || mono_type_is_generic_parameter (m_class_get_byval_arg (c)))
11361136

1137+
/*
1138+
* We use this to pass context information to the row locator
1139+
*/
1140+
typedef struct {
1141+
// caller inputs
1142+
// note: we can't optimize around locator_t.idx yet because a few call sites mutate it
1143+
guint32 idx; /* The index that we are trying to locate */
1144+
// no call sites mutate this so we can optimize around it
1145+
guint32 col_idx; /* The index in the row where idx may be stored */
1146+
// no call sites mutate this so we can optimize around it
1147+
MonoTableInfo *t; /* pointer to the table */
1148+
1149+
// optimization data
1150+
gboolean metadata_has_updates;
1151+
const char * t_base;
1152+
guint t_row_size;
1153+
guint32 t_rows;
1154+
guint32 column_size;
1155+
const char * first_column_data;
1156+
1157+
// result
1158+
guint32 result;
1159+
} locator_t;
1160+
1161+
MONO_ALWAYS_INLINE static locator_t
1162+
locator_init (MonoTableInfo *t, guint32 idx, guint32 col_idx)
1163+
{
1164+
locator_t result = { 0, };
1165+
1166+
result.idx = idx;
1167+
result.col_idx = col_idx;
1168+
result.t = t;
1169+
1170+
g_assert (t);
1171+
// FIXME: Callers shouldn't rely on this
1172+
if (!t->base)
1173+
return result;
1174+
1175+
// optimization data for decode_locator_row
1176+
result.metadata_has_updates = mono_metadata_has_updates ();
1177+
result.t_base = t->base;
1178+
result.t_row_size = t->row_size;
1179+
result.t_rows = table_info_get_rows (t);
1180+
g_assert (col_idx < mono_metadata_table_count (t->size_bitfield));
1181+
result.column_size = mono_metadata_table_size (t->size_bitfield, col_idx);
1182+
result.first_column_data = result.t_base + t->column_offsets [col_idx];
1183+
1184+
return result;
1185+
}
1186+
11371187
static inline gboolean
11381188
m_image_is_raw_data_allocated (MonoImage *image)
11391189
{

src/mono/mono/metadata/metadata.c

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -4679,56 +4679,6 @@ mono_metadata_token_from_dor (guint32 dor_index)
46794679
return 0;
46804680
}
46814681

4682-
/*
4683-
* We use this to pass context information to the row locator
4684-
*/
4685-
typedef struct {
4686-
// caller inputs
4687-
// note: we can't optimize around locator_t.idx yet because a few call sites mutate it
4688-
guint32 idx; /* The index that we are trying to locate */
4689-
// no call sites mutate this so we can optimize around it
4690-
guint32 col_idx; /* The index in the row where idx may be stored */
4691-
// no call sites mutate this so we can optimize around it
4692-
MonoTableInfo *t; /* pointer to the table */
4693-
4694-
// optimization data
4695-
gboolean metadata_has_updates;
4696-
const char * t_base;
4697-
guint t_row_size;
4698-
guint32 t_rows;
4699-
guint32 column_size;
4700-
const char * first_column_data;
4701-
4702-
// result
4703-
guint32 result;
4704-
} locator_t;
4705-
4706-
MONO_ALWAYS_INLINE static locator_t
4707-
locator_init (MonoTableInfo *t, guint32 idx, guint32 col_idx)
4708-
{
4709-
locator_t result = { 0, };
4710-
4711-
result.idx = idx;
4712-
result.col_idx = col_idx;
4713-
result.t = t;
4714-
4715-
g_assert (t);
4716-
// FIXME: Callers shouldn't rely on this
4717-
if (!t->base)
4718-
return result;
4719-
4720-
// optimization data for decode_locator_row
4721-
result.metadata_has_updates = mono_metadata_has_updates ();
4722-
result.t_base = t->base;
4723-
result.t_row_size = t->row_size;
4724-
result.t_rows = table_info_get_rows (t);
4725-
g_assert (col_idx < mono_metadata_table_count (t->size_bitfield));
4726-
result.column_size = mono_metadata_table_size (t->size_bitfield, col_idx);
4727-
result.first_column_data = result.t_base + t->column_offsets [col_idx];
4728-
4729-
return result;
4730-
}
4731-
47324682
static guint32
47334683
decode_locator_row (locator_t *loc, int row_index)
47344684
{

0 commit comments

Comments
 (0)