Skip to content

Commit

Permalink
Always build with hot reload support (in a component) (#54124)
Browse files Browse the repository at this point in the history
Get rid of the ENABLE_METADATA_UPDATE ifdef.  To disable hot reload,
don't include the component in the runtime
  • Loading branch information
lambdageek authored Jun 14, 2021
1 parent af5c238 commit 8818fb0
Show file tree
Hide file tree
Showing 23 changed files with 4 additions and 171 deletions.
4 changes: 0 additions & 4 deletions src/mono/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,6 @@ if((CMAKE_CXX_COMPILER_ID STREQUAL "GNU") OR(CMAKE_CXX_COMPILER_ID STREQUAL "Cla
set(GCC 1)
endif()

if(DISABLE_INTERPRETER)
unset(ENABLE_METADATA_UPDATE)
endif()

add_definitions(-DHAVE_CONFIG_H)

if(GCC)
Expand Down
7 changes: 0 additions & 7 deletions src/mono/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,4 @@
<MonoAOTCompilerProjDirectory>$([MSBuild]::NormalizeDirectory('$(RepoTasksDir)', 'AotCompilerTask'))</MonoAOTCompilerProjDirectory>
</PropertyGroup>

<!-- Feature defaults for mono.proj and System.Private.CoreLib.csproj -->
<PropertyGroup>
<!-- default metadata update support for specific platforms -->
<MonoMetadataUpdate Condition="'$(MonoMetadataUpdate)' == '' and ('$(TargetsAndroid)' == 'true' or '$(TargetsBrowser)' == 'true')">true</MonoMetadataUpdate>
<MonoMetadataUpdate Condition="'$(MonoMetadataUpdate)' == '' and ('$(TargetsiOS)' == 'true' or '$(TargetstvOS)' == 'true' or '$(TargetsMacCatalyst)' == 'true')">true</MonoMetadataUpdate>
<MonoMetadataUpdate Condition="'$(MonoMetadataUpdate)' == ''">false</MonoMetadataUpdate>
</PropertyGroup>
</Project>
5 changes: 0 additions & 5 deletions src/mono/System.Private.CoreLib/System.Private.CoreLib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,6 @@
<DefineConstants Condition="'$(FeatureObjCMarshal)' == 'true'">$(DefineConstants);FEATURE_OBJCMARSHAL</DefineConstants>
</PropertyGroup>

<!-- Experimental mono metadata update feature -->
<PropertyGroup>
<DefineConstants Condition="'$(MonoMetadataUpdate)' == 'true'">$(DefineConstants);FEATURE_METADATA_UPDATE</DefineConstants>
</PropertyGroup>

<!-- ILLinker settings -->
<PropertyGroup>
<ILLinkTrimAssembly>true</ILLinkTrimAssembly>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ public static void ApplyUpdate(Assembly assembly, ReadOnlySpan<byte> metadataDel
if (runtimeAssembly == typeof(AssemblyExtensions).Assembly)
throw new InvalidOperationException (SR.InvalidOperation_AssemblyNotEditable);

#if !FEATURE_METADATA_UPDATE
throw new NotSupportedException (SR.NotSupported_MethodBodyReplacement);
#else
unsafe
{
IntPtr monoAssembly = runtimeAssembly.GetUnderlyingNativeHandle ();
Expand All @@ -48,7 +45,6 @@ public static void ApplyUpdate(Assembly assembly, ReadOnlySpan<byte> metadataDel
ApplyUpdate_internal(monoAssembly, metadataDeltaPtr, metadataDelta.Length, ilDeltaPtr, ilDelta.Length, pdbDeltaPtr, pdbDelta.Length);
}
}
#endif
}

private static Lazy<string> s_ApplyUpdateCapabilities = new Lazy<string>(() => InitializeApplyUpdateCapabilities());
Expand All @@ -57,21 +53,14 @@ public static void ApplyUpdate(Assembly assembly, ReadOnlySpan<byte> metadataDel

private static string InitializeApplyUpdateCapabilities()
{
#if !FEATURE_METADATA_UPDATE
return string.Empty;
#else
return ApplyUpdateEnabled() != 0 ? "Baseline" : string.Empty ;
#endif
}


#if FEATURE_METADATA_UPDATE
[MethodImpl (MethodImplOptions.InternalCall)]
private static extern int ApplyUpdateEnabled ();

[MethodImpl (MethodImplOptions.InternalCall)]
private static unsafe extern void ApplyUpdate_internal (IntPtr base_assm, byte* dmeta_bytes, int dmeta_length, byte *dil_bytes, int dil_length, byte *dpdb_bytes, int dpdb_length);
#endif

}
}
3 changes: 0 additions & 3 deletions src/mono/cmake/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -1070,9 +1070,6 @@
/* Enable runtime checks of mempool references between metadata images (must set env var MONO_CHECK_MODE=metadata) */
#cmakedefine ENABLE_CHECKED_BUILD_METADATA 1

/* Enable runtime support for metadata updates */
#cmakedefine ENABLE_METADATA_UPDATE 1

/* Enable static linking of mono runtime components */
#cmakedefine STATIC_COMPONENTS

Expand Down
2 changes: 0 additions & 2 deletions src/mono/cmake/options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ option (ENABLE_CHECKED_BUILD_PRIVATE_TYPES "Enable compile time checking that ge
option (ENABLE_CHECKED_BUILD_GC "Enable runtime GC Safe / Unsafe mode assertion checks (must set env var MONO_CHECK_MODE=gc)")
option (ENABLE_CHECKED_BUILD_THREAD "Enable runtime history of per-thread coop state transitions (must set env var MONO_CHECK_MODE=thread)")
option (ENABLE_CHECKED_BUILD_METADATA "Enable runtime checks of mempool references between metadata images (must set env var MONO_CHECK_MODE=metadata)")
option (ENABLE_METADATA_UPDATE "Enable runtime support for metadata updates")
option (ENABLE_MSCORDBI "Generate mscordbi to support icordbg interface")
option (STATIC_COMPONENTS "Compile mono runtime components as static (not dynamic) libraries")

Expand All @@ -63,4 +62,3 @@ set (ENABLE_MINIMAL "" CACHE STRING "Set many DISABLE_ options at once. Comma-se
set (AOT_TARGET_TRIPLE "" CACHE STRING "Target triple for AOT cross compiler")
set (AOT_OFFSETS_FILE "" CACHE STRING "Offsets file for AOT cross compiler")
set (LLVM_PREFIX "" CACHE STRING "Enable LLVM support with LLVM installed at <LLVM_PREFIX>.")

8 changes: 0 additions & 8 deletions src/mono/mono.proj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
- MonoAOTEnableLLVM - enable LLVM for an AOT-only Mono
- MonoAOTLLVMDir - [optional] the directory where LLVM is located, for an AOT-only Mono
- MonoVerboseBuild - enable verbose build
- MonoMetadataUpdate - enable experimental method body replacement code (in Directory.Build.props)
- MonoThreadSuspend - coop,hybrid,preemptive - default thread suspend mode
-->

Expand Down Expand Up @@ -412,10 +411,6 @@
</ItemGroup>

<!-- Devloop features -->
<ItemGroup Condition="'$(MonoMetadataUpdate)' == 'true'">
<_MonoCMakeArgs Include="-DENABLE_METADATA_UPDATE=1" />
</ItemGroup>

<ItemGroup Condition="'$(MonoMsCorDbi)' == 'true'">
<_MonoCMakeArgs Include="-DENABLE_MSCORDBI=1" />
</ItemGroup>
Expand Down Expand Up @@ -655,9 +650,6 @@
<MonoAOTCMakeArgs Condition="'$(MonoAOTEnableLLVM)' == 'true'" Include="-DLLVM_PREFIX=$(MonoAOTLLVMDir.TrimEnd('\/'))" />
<MonoAOTCMakeArgs Include="$(_MonoAOTCFLAGSOption)" />
<MonoAOTCMakeArgs Include="$(_MonoAOTCXXFLAGSOption)" />
<!-- Devloop features -->
<MonoAOTCMakeArgs Condition="'$(MonoMetadataUpdate)' == 'true'" Include="-DENABLE_METADATA_UPDATE=1" />

<!-- thread suspend -->
<MonoAOTCMakeArgs Include="-DGC_SUSPEND=$(MonoThreadSuspend)" />
</ItemGroup>
Expand Down
2 changes: 0 additions & 2 deletions src/mono/mono/metadata/domain.c
Original file line number Diff line number Diff line change
Expand Up @@ -485,10 +485,8 @@ void
mono_close_exe_image (void)
{
gboolean do_close = exe_image != NULL;
#ifdef ENABLE_METADATA_UPDATE
/* FIXME: shutdown hack. We mess something up and try to double-close/free it. */
do_close = do_close && !exe_image->has_updates;
#endif
if (do_close)
mono_image_close (exe_image);
}
Expand Down
2 changes: 0 additions & 2 deletions src/mono/mono/metadata/icall-decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,7 @@ ICALL_EXPORT void ves_icall_System_Threading_LowLevelLifoSemaphore_ReleaseIn
ICALL_EXPORT void ves_icall_System_Runtime_Intrinsics_X86_X86Base___cpuidex (int abcd[4], int function_id, int subfunction_id);
#endif

#ifdef ENABLE_METADATA_UPDATE
ICALL_EXPORT void ves_icall_AssemblyExtensions_ApplyUpdate (MonoAssembly *assm, gconstpointer dmeta_bytes, int32_t dmeta_len, gconstpointer dil_bytes, int32_t dil_len, gconstpointer dpdb_bytes, int32_t dpdb_len);
ICALL_EXPORT gint32 ves_icall_AssemblyExtensions_ApplyUpdateEnabled (void);
#endif

#endif // __MONO_METADATA_ICALL_DECL_H__
2 changes: 0 additions & 2 deletions src/mono/mono/metadata/icall-def-netcore.h
Original file line number Diff line number Diff line change
Expand Up @@ -245,11 +245,9 @@ ICALL_TYPE(FIELDI, "System.Reflection.FieldInfo", FILEDI_1)
HANDLES(FILEDI_1, "get_marshal_info", ves_icall_System_Reflection_FieldInfo_get_marshal_info, MonoReflectionMarshalAsAttribute, 1, (MonoReflectionField))
HANDLES(FILEDI_2, "internal_from_handle_type", ves_icall_System_Reflection_FieldInfo_internal_from_handle_type, MonoReflectionField, 2, (MonoClassField_ref, MonoType_ref))

#ifdef ENABLE_METADATA_UPDATE
ICALL_TYPE(ASSMEXT, "System.Reflection.Metadata.AssemblyExtensions", ASSMEXT_2)
NOHANDLES(ICALL(ASSMEXT_2, "ApplyUpdateEnabled", ves_icall_AssemblyExtensions_ApplyUpdateEnabled))
NOHANDLES(ICALL(ASSMEXT_1, "ApplyUpdate_internal", ves_icall_AssemblyExtensions_ApplyUpdate))
#endif

ICALL_TYPE(MBASE, "System.Reflection.MethodBase", MBASE_1)
HANDLES(MBASE_1, "GetCurrentMethod", ves_icall_GetCurrentMethod, MonoReflectionMethod, 0, ())
Expand Down
2 changes: 0 additions & 2 deletions src/mono/mono/metadata/icall.c
Original file line number Diff line number Diff line change
Expand Up @@ -5737,7 +5737,6 @@ ves_icall_Mono_Runtime_DumpStateTotal (guint64 *portable_hash, guint64 *unportab
return result;
}

#ifdef ENABLE_METADATA_UPDATE
void
ves_icall_AssemblyExtensions_ApplyUpdate (MonoAssembly *assm,
gconstpointer dmeta_bytes, int32_t dmeta_len,
Expand All @@ -5759,7 +5758,6 @@ gint32 ves_icall_AssemblyExtensions_ApplyUpdateEnabled (void)
{
return mono_metadata_update_available ();
}
#endif

MonoBoolean
ves_icall_System_Reflection_AssemblyName_ParseAssemblyName (const char *name, MonoAssemblyName *aname, MonoBoolean *is_version_defined_arg, MonoBoolean *is_token_defined_arg)
Expand Down
12 changes: 0 additions & 12 deletions src/mono/mono/metadata/image.c
Original file line number Diff line number Diff line change
Expand Up @@ -599,14 +599,12 @@ load_tables (MonoImage *image)
image->idx_guid_wide = ((heap_sizes & 0x02) == 2);
image->idx_blob_wide = ((heap_sizes & 0x04) == 4);

#ifdef ENABLE_METADATA_UPDATE
if (G_UNLIKELY (image->minimal_delta)) {
/* sanity check */
g_assert (image->idx_string_wide);
g_assert (image->idx_guid_wide);
g_assert (image->idx_blob_wide);
}
#endif

valid_mask = read64 (heap_tables + 8);
rows = (const guint32 *) (heap_tables + 24);
Expand Down Expand Up @@ -1174,7 +1172,6 @@ hash_guid (const char *str)
return h;
}

#ifdef ENABLE_METADATA_UPDATE
static void
dump_encmap (MonoImage *image)
{
Expand All @@ -1192,7 +1189,6 @@ dump_encmap (MonoImage *image)
}
}
}
#endif

static MonoImage *
do_mono_image_load (MonoImage *image, MonoImageOpenStatus *status,
Expand Down Expand Up @@ -1238,9 +1234,7 @@ do_mono_image_load (MonoImage *image, MonoImageOpenStatus *status,
if (!mono_image_load_cli_data (image))
goto invalid_image;

#ifdef ENABLE_METADATA_UPDATE
dump_encmap (image);
#endif

mono_image_load_names (image);

Expand Down Expand Up @@ -2151,9 +2145,7 @@ mono_image_close_except_pools (MonoImage *image)

mono_image_invoke_unload_hook (image);

#ifdef ENABLE_METADATA_UPDATE
mono_metadata_update_cleanup_on_close (image);
#endif

/*
* The caches inside a MonoImage might refer to metadata which is stored in referenced
Expand Down Expand Up @@ -2273,10 +2265,8 @@ mono_image_close_except_pools (MonoImage *image)
mono_image_close_except_pools_all (image->modules, image->module_count);
g_free (image->modules_loaded);

#ifdef ENABLE_METADATA_UPDATE
if (image->has_updates)
mono_metadata_update_image_close_except_pools_all (image);
#endif

mono_os_mutex_destroy (&image->szarray_cache_lock);
mono_os_mutex_destroy (&image->lock);
Expand Down Expand Up @@ -2322,9 +2312,7 @@ mono_image_close_finish (MonoImage *image)
mono_image_close_all (image->files, image->file_count);
mono_image_close_all (image->modules, image->module_count);

#ifdef ENABLE_METADATA_UPDATE
mono_metadata_update_image_close_all (image);
#endif

#ifndef DISABLE_PERFCOUNTERS
/* FIXME: use an explicit subtraction method as soon as it's available */
Expand Down
2 changes: 0 additions & 2 deletions src/mono/mono/metadata/loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -2035,10 +2035,8 @@ mono_method_get_header_internal (MonoMethod *method, MonoError *error)
g_assert (mono_metadata_token_table (method->token) == MONO_TABLE_METHOD);
idx = mono_metadata_token_index (method->token);

#ifdef ENABLE_METADATA_UPDATE
if (G_UNLIKELY (img->has_updates))
loc = mono_metadata_update_get_updated_method_rva (img, idx);
#endif

if (!loc) {
rva = mono_metadata_decode_row_col (&img->tables [MONO_TABLE_METHOD], idx - 1, MONO_METHOD_RVA);
Expand Down
23 changes: 0 additions & 23 deletions src/mono/mono/metadata/metadata-internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -793,19 +793,6 @@ struct _MonoMetadataUpdateData {
int has_updates;
};

#ifndef ENABLE_METADATA_UPDATE
static inline gboolean
mono_metadata_has_updates (void)
{
return FALSE;
}

static inline void
mono_image_effective_table (const MonoTableInfo **t, int *idx)
{
}
#else /* ENABLE_METADATA_UPDATE */

extern MonoMetadataUpdateData mono_metadata_update_data_private;

/* returns TRUE if there's at least one update */
Expand Down Expand Up @@ -833,7 +820,6 @@ mono_image_relative_delta_index (MonoImage *image_dmeta, int token);

void
mono_image_load_enc_delta (MonoImage *base_image, gconstpointer dmeta, uint32_t dmeta_len, gconstpointer dil, uint32_t dil_len, MonoError *error);
#endif /* ENABLE_METADATA_UPDATE */

gboolean
mono_image_load_cli_header (MonoImage *image, MonoCLIImageInfo *iinfo);
Expand Down Expand Up @@ -863,14 +849,6 @@ mono_metadata_get_shared_type (MonoType *type);
void
mono_metadata_clean_generic_classes_for_image (MonoImage *image);

#ifndef ENABLE_METADATA_UPDATE
static inline gboolean
mono_metadata_table_bounds_check (MonoImage *image, int table_index, int token_index)
{
/* token_index is 1-based. TRUE means the token is out of bounds */
return token_index > image->tables [table_index].rows_;
}
#else
gboolean
mono_metadata_table_bounds_check_slow (MonoImage *image, int table_index, int token_index);

Expand All @@ -885,7 +863,6 @@ mono_metadata_table_bounds_check (MonoImage *image, int table_index, int token_i
return TRUE;
return mono_metadata_table_bounds_check_slow (image, table_index, token_index);
}
#endif

MONO_COMPONENT_API
const char * mono_meta_table_name (int table);
Expand Down
12 changes: 0 additions & 12 deletions src/mono/mono/metadata/metadata-update.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ mono_metadata_update_available (void)
return mono_component_hot_reload ()->component.available ();
}

#ifdef ENABLE_METADATA_UPDATE

MonoMetadataUpdateData mono_metadata_update_data_private;

void
Expand Down Expand Up @@ -122,14 +120,4 @@ mono_metadata_update_delta_heap_lookup (MonoImage *base_image, MetadataHeapGette
return mono_component_hot_reload ()->delta_heap_lookup (base_image, get_heap, orig_index, image_out, index_out);
}

#else /* ENABLE_METADATA_UPDATE */

void
mono_metadata_update_init (void)
{
MonoComponentHotReload *comp = mono_component_hot_reload ();
comp->set_fastpath_data (NULL);
}

#endif /* ENABLE_METADATA_UPDATE */

20 changes: 0 additions & 20 deletions src/mono/mono/metadata/metadata-update.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ typedef MonoStreamHeader* (*MetadataHeapGetterFunc) (MonoImage*);
gboolean
mono_metadata_update_available (void);

#ifdef ENABLE_METADATA_UPDATE

gboolean
mono_metadata_update_enabled (int *modifiable_assemblies_out);

Expand Down Expand Up @@ -56,22 +54,4 @@ mono_metadata_update_table_bounds_check (MonoImage *base_image, int table_index,
gboolean
mono_metadata_update_delta_heap_lookup (MonoImage *base_image, MetadataHeapGetterFunc get_heap, uint32_t orig_index, MonoImage **image_out, uint32_t *index_out);

#else /* ENABLE_METADATA_UPDATE */

static inline gboolean
mono_metadata_update_enabled (int *modifiable_assemblies_out)
{
if (modifiable_assemblies_out)
*modifiable_assemblies_out = 0;
return FALSE;
}

static inline gboolean
mono_metadata_update_no_inline (MonoMethod *caller, MonoMethod *callee)
{
return FALSE;
}

#endif /* ENABLE_METADATA_UPDATE */

#endif /*__MONO_METADATA_UPDATE_H__*/
Loading

0 comments on commit 8818fb0

Please sign in to comment.