Skip to content

Commit

Permalink
[browser][MT] GC, more testing and cleanup (#94466)
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelsavara authored Nov 9, 2023
1 parent b2538c4 commit 28dcc44
Show file tree
Hide file tree
Showing 29 changed files with 61 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public static async Task<int> Main(string[] args)
IncludedMethods = includedMethods
};

await Task.Yield();
return await runner.Run();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,6 @@ public void ApplicationNameSetFromArgument()

[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))]
[DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(NoSpecialEntryPointPattern.Program))]
[ActiveIssue("https://github.com/dotnet/runtime/issues/91538", typeof(PlatformDetection), nameof(PlatformDetection.IsWasmThreadingSupported))]
public void NoSpecialEntryPointPatternCanRunInParallel()
{
var factory = HostFactoryResolver.ResolveServiceProviderFactory(typeof(NoSpecialEntryPointPattern.Program).Assembly, s_WaitTimeout);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ namespace Microsoft.Extensions.Logging.Console.Test
public class JsonConsoleFormatterTests : ConsoleFormatterTests
{
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))]
[ActiveIssue("https://github.com/dotnet/runtime/issues/91538", typeof(PlatformDetection), nameof(PlatformDetection.IsWasmThreadingSupported))]
public void NoLogScope_DoesNotWriteAnyScopeContentToOutput_Json()
{
// Arrange
Expand Down Expand Up @@ -80,7 +79,6 @@ public void Log_TimestampFormatSet_ContainsTimestamp()
}

[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))]
[ActiveIssue("https://github.com/dotnet/runtime/issues/91538", typeof(PlatformDetection), nameof(PlatformDetection.IsWasmThreadingSupported))]
public void Log_NullMessage_LogsWhenMessageIsNotProvided()
{
// Arrange
Expand Down Expand Up @@ -125,7 +123,6 @@ public void Log_NullMessage_LogsWhenMessageIsNotProvided()
}

[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))]
[ActiveIssue("https://github.com/dotnet/runtime/issues/91538", typeof(PlatformDetection), nameof(PlatformDetection.IsWasmThreadingSupported))]
public void Log_ExceptionWithMessage_ExtractsInfo()
{
// Arrange
Expand Down Expand Up @@ -180,7 +177,6 @@ public void Log_ExceptionWithMessage_ExtractsInfo()
}

[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))]
[ActiveIssue("https://github.com/dotnet/runtime/issues/91538", typeof(PlatformDetection), nameof(PlatformDetection.IsWasmThreadingSupported))]
public void Log_IncludeScopes_ContainsDuplicateNamedPropertiesInScope_AcceptableJson()
{
// Arrange
Expand Down Expand Up @@ -214,7 +210,6 @@ public void Log_IncludeScopes_ContainsDuplicateNamedPropertiesInScope_Acceptable
}

[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))]
[ActiveIssue("https://github.com/dotnet/runtime/issues/91538", typeof(PlatformDetection), nameof(PlatformDetection.IsWasmThreadingSupported))]
public void Log_StateAndScopeAreCollections_IncludesMessageAndCollectionValues()
{
// Arrange
Expand Down Expand Up @@ -250,7 +245,6 @@ public void Log_StateAndScopeAreCollections_IncludesMessageAndCollectionValues()
}

[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))]
[ActiveIssue("https://github.com/dotnet/runtime/issues/91538", typeof(PlatformDetection), nameof(PlatformDetection.IsWasmThreadingSupported))]
[MemberData(nameof(SpecialCaseValues))]
public void Log_StateAndScopeContainsSpecialCaseValue_SerializesValueAsExpected(object value, string expectedJsonValue)
{
Expand Down Expand Up @@ -281,7 +275,6 @@ public void Log_StateAndScopeContainsSpecialCaseValue_SerializesValueAsExpected(
}

[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))]
[ActiveIssue("https://github.com/dotnet/runtime/issues/91538", typeof(PlatformDetection), nameof(PlatformDetection.IsWasmThreadingSupported))]
[MemberData(nameof(FloatingPointValues))]
public void Log_StateAndScopeContainsFloatingPointType_SerializesValue(object value)
{
Expand Down Expand Up @@ -321,7 +314,6 @@ static void AssertMessageValue(string message, string propertyName)
}

[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))]
[ActiveIssue("https://github.com/dotnet/runtime/issues/91538", typeof(PlatformDetection), nameof(PlatformDetection.IsWasmThreadingSupported))]
public void Log_StateAndScopeContainsNullValue_SerializesNull()
{
// Arrange
Expand Down Expand Up @@ -351,7 +343,6 @@ public void Log_StateAndScopeContainsNullValue_SerializesNull()
}

[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))]
[ActiveIssue("https://github.com/dotnet/runtime/issues/91538", typeof(PlatformDetection), nameof(PlatformDetection.IsWasmThreadingSupported))]
public void Log_ScopeIsIEnumerable_SerializesKeyValuePair()
{
// Arrange
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
<TestRuntime>true</TestRuntime>
<EnableDefaultItems>true</EnableDefaultItems>
<IncludeRemoteExecutor>true</IncludeRemoteExecutor>
<_WasmPThreadPoolSize Condition="'$(MonoWasmBuildVariant)' == 'multithread'">100</_WasmPThreadPoolSize>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="$(LibrariesProjectRoot)Microsoft.Extensions.Logging.Console\src\Microsoft.Extensions.Logging.Console.csproj" SkipUseReferenceAssembly="true" />
</ItemGroup>

</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,7 @@ public void ICollectionCopyTo_InvalidArgs_Throws()
[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))]
[InlineData(100, 1, 10)]
[InlineData(4, 100000, 10)]
[ActiveIssue("https://github.com/dotnet/runtime/issues/91538", typeof(PlatformDetection), nameof(PlatformDetection.IsWasmThreadingSupported))]
public void BlockingCollection_WrappingCollection_ExpectedElementsTransferred(int numThreadsPerConsumerProducer, int numItemsPerThread, int producerSpin)
{
var bc = new BlockingCollection<int>(CreateProducerConsumerCollection());
Expand Down
1 change: 1 addition & 0 deletions src/libraries/System.Linq.Parallel/tests/ExchangeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ public static IEnumerable<object[]> AllMergeOptions_Multiple()

[ConditionalTheory]
[MemberData(nameof(PartitioningData), new[] { 0, 1, 2, 16, 1024 })]
[ActiveIssue("https://github.com/dotnet/runtime/issues/91541", typeof(PlatformDetection), nameof(PlatformDetection.IsWasmThreadingSupported))]
public static void Partitioning_Default(Labeled<ParallelQuery<int>> labeled, int count, int partitions)
{
if (partitions > 1 && !PlatformDetection.IsThreadingSupported)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,7 @@ static void FinalizeHelper(DisposeTracker disposeTracker)

// Several tests for deriving custom user types from CancellationTokenSource
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))]
[ActiveIssue("https://github.com/dotnet/runtime/issues/94486", typeof(PlatformDetection), nameof(PlatformDetection.IsWasmThreadingSupported))]
public static void DerivedCancellationTokenSource()
{
// Verify that a derived CTS is functional
Expand Down
2 changes: 2 additions & 0 deletions src/libraries/System.Threading.Tasks/tests/MethodCoverage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ public static async Task Task_WhenAny_TwoTasks_WakesOnFirstCompletion()
}

[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))]
[ActiveIssue("https://github.com/dotnet/runtime/issues/91541", typeof(PlatformDetection), nameof(PlatformDetection.IsWasmThreadingSupported))]
public static void CancellationTokenRegitration()
{
ManualResetEvent mre = new ManualResetEvent(false);
Expand All @@ -296,6 +297,7 @@ public static void CancellationTokenRegitration()
/// verify that the taskawaiter.UnsafeOnCompleted is invoked
/// </summary>
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))]
[ActiveIssue("https://github.com/dotnet/runtime/issues/91541", typeof(PlatformDetection), nameof(PlatformDetection.IsWasmThreadingSupported))]
public static void TaskAwaiter()
{
ManualResetEvent mre = new ManualResetEvent(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<TestRuntime>true</TestRuntime>
<IncludeRemoteExecutor>true</IncludeRemoteExecutor>
<TargetFramework>$(NetCoreAppCurrent)</TargetFramework>
<_WasmPThreadPoolSize Condition="'$(MonoWasmBuildVariant)' == 'multithread'">64</_WasmPThreadPoolSize>
</PropertyGroup>
<ItemGroup>
<Compile Include="Helpers.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ static async IAsyncEnumerable<int> CreateSourceEnumerable()
}

[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))]
[ActiveIssue("https://github.com/dotnet/runtime/issues/91538", typeof(PlatformDetection), nameof(PlatformDetection.IsWasmThreadingSupported))]
public static void AsyncEnumerableWithDelays()
{
var source = new InstrumentedAsyncEnumerable<int>(CreateSourceEnumerable());
Expand Down Expand Up @@ -104,6 +105,7 @@ static async IAsyncEnumerable<int> CreateSourceEnumerable()
}

[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))]
[ActiveIssue("https://github.com/dotnet/runtime/issues/91538", typeof(PlatformDetection), nameof(PlatformDetection.IsWasmThreadingSupported))]
public static void AsyncEnumerableWithException()
{
var source = new InstrumentedAsyncEnumerable<int>(CreateSourceEnumerable());
Expand Down Expand Up @@ -132,6 +134,7 @@ static async IAsyncEnumerable<int> CreateSourceEnumerable()
}

[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))]
[ActiveIssue("https://github.com/dotnet/runtime/issues/91538", typeof(PlatformDetection), nameof(PlatformDetection.IsWasmThreadingSupported))]
public static void AsyncEnumerableWithCancellation()
{
var source = new InstrumentedAsyncEnumerable<string>(CreateSourceEnumerable());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1255,6 +1255,7 @@ public static void LongContinuationChain_Unwrap_DoesNotStackOverflow()
}

[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))]
[ActiveIssue("https://github.com/dotnet/runtime/issues/91541", typeof(PlatformDetection), nameof(PlatformDetection.IsWasmThreadingSupported))]
public static void LongContinuationChain_Await_DoesNotStackOverflow()
{
const int DiveDepth = 12_000;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<IncludeRemoteExecutor>true</IncludeRemoteExecutor>
<TargetFramework>$(NetCoreAppCurrent)</TargetFramework>
<TestRuntime>true</TestRuntime>
<_WasmPThreadPoolSize Condition="'$(MonoWasmBuildVariant)' == 'multithread'">64</_WasmPThreadPoolSize>
</PropertyGroup>
<ItemGroup>
<Compile Include="ThreadPoolTests.cs" />
Expand Down
9 changes: 0 additions & 9 deletions src/libraries/tests.proj
Original file line number Diff line number Diff line change
Expand Up @@ -382,19 +382,10 @@
</ItemGroup>

<ItemGroup Condition="'$(TargetOS)' == 'browser' and '$(MonoWasmBuildVariant)' == 'multithread' and '$(RunDisabledWasmTests)' != 'true'">
<!-- Issue: https://github.com/dotnet/runtime/issues/72101 -->
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Text.Json\tests\System.Text.Json.Tests\System.Text.Json.Tests.csproj" />
<!-- Issue: https://github.com/dotnet/runtime/issues/74411 -->
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Net.Http\tests\FunctionalTests\System.Net.Http.Functional.Tests.csproj" />
<!-- Issue: https://github.com/dotnet/runtime/issues/74413 -->
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Net.WebSockets.Client\tests\System.Net.WebSockets.Client.Tests.csproj" />
<!-- https://github.com/dotnet/runtime/issues/91538 -->
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Threading.Tasks\tests\System.Threading.Tasks.Tests.csproj" />
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Collections.Concurrent\tests\System.Collections.Concurrent.Tests.csproj" />
<ProjectExclusions Include="$(MSBuildThisFileDirectory)Microsoft.Extensions.DependencyInjection\tests\DI.Tests\Microsoft.Extensions.DependencyInjection.Tests.csproj" />
<!-- https://github.com/dotnet/runtime/issues/91593 -->
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Threading.Tasks.Dataflow\tests\System.Threading.Tasks.Dataflow.Tests.csproj" />
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Threading.Channels\tests\System.Threading.Channels.Tests.csproj" />
</ItemGroup>

<!-- Aggressive Trimming related failures -->
Expand Down
2 changes: 1 addition & 1 deletion src/mono/mono/component/diagnostics_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ queue_push_sync (WasmIpcStreamQueue *q, const uint8_t *buf, uint32_t buf_size, u
gboolean is_browser_thread = FALSE;
while (mono_atomic_load_i32 (&q->buf_full) != 0) {
if (G_UNLIKELY (!is_browser_thread_inited)) {
is_browser_thread = mono_threads_wasm_is_browser_thread ();
is_browser_thread = mono_threads_wasm_is_ui_thread ();
is_browser_thread_inited = TRUE;
}
if (G_UNLIKELY (is_browser_thread)) {
Expand Down
19 changes: 2 additions & 17 deletions src/mono/mono/metadata/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -686,21 +686,6 @@ ves_icall_System_GCHandle_InternalSet (MonoGCHandle handle, MonoObjectHandle obj
static MonoCoopSem finalizer_sem;
static volatile gboolean finished;

#ifdef HOST_WASM

static void
mono_wasm_gc_finalize_notify (void)
{
#if 0
/* use this if we are going to start the finalizer thread on wasm. */
mono_coop_sem_post (&finalizer_sem);
#else
mono_main_thread_schedule_background_job (mono_runtime_do_background_work);
#endif
}

#endif /* HOST_WASM */

/*
* mono_gc_finalize_notify:
*
Expand All @@ -720,8 +705,8 @@ mono_gc_finalize_notify (void)

#if defined(HOST_WASI)
// TODO: Schedule the background job on WASI. Threads aren't yet supported in this build.
#elif defined(HOST_WASM)
mono_wasm_gc_finalize_notify ();
#elif defined(HOST_WASM) && defined(DISABLE_THREADS)
mono_main_thread_schedule_background_job (mono_runtime_do_background_work);
#else
mono_coop_sem_post (&finalizer_sem);
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/mono/mono/metadata/sgen-mono.c
Original file line number Diff line number Diff line change
Expand Up @@ -2893,7 +2893,7 @@ sgen_client_binary_protocol_collection_end (int minor_gc_count, int generation,
MONO_PROFILER_RAISE (gc_event, (MONO_GC_EVENT_END, generation, generation == GENERATION_OLD && sgen_concurrent_collection_in_progress));
}

#ifdef HOST_WASM
#if defined(HOST_WASM) && defined(DISABLE_THREADS)
void
sgen_client_schedule_background_job (void (*cb)(void))
{
Expand Down
2 changes: 1 addition & 1 deletion src/mono/mono/metadata/sgen-stw.c
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ mono_wasm_gc_lock(void)
MONO_ENTER_GC_UNSAFE;
#ifndef DISABLE_THREADS
/* only the browser thread is allowed to take the GC lock */
g_assert (mono_threads_wasm_is_browser_thread ());
g_assert (mono_threads_wasm_is_ui_thread ());
LOCK_GC;
acquire_gc_locks();
#else
Expand Down
2 changes: 1 addition & 1 deletion src/mono/mono/metadata/threads.c
Original file line number Diff line number Diff line change
Expand Up @@ -1237,7 +1237,7 @@ start_wrapper_internal (StartInfo *start_info, gsize *stack_ptr)
if (G_UNLIKELY (external_eventloop)) {
/* if the thread wants to stay alive in an external eventloop, don't clean up after it */
if (mono_thread_platform_external_eventloop_keepalive_check ())
return 0;
return 0; // MONO_ENTER_GC_SAFE_UNBALANCED is done in start_wrapper
}

/* Do any cleanup needed for apartment state. This
Expand Down
2 changes: 1 addition & 1 deletion src/mono/mono/sgen/sgen-gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -2740,7 +2740,7 @@ extern gboolean mono_wasm_enable_gc;
void
sgen_perform_collection (size_t requested_size, int generation_to_collect, const char *reason, gboolean forced_serial, gboolean stw)
{
#ifdef HOST_BROWSER
#if defined(HOST_BROWSER) && defined(DISABLE_THREADS)
if (!mono_wasm_enable_gc) {
g_assert (stw); //can't handle non-stw mode (IE, domain unload)
//we ignore forced_serial
Expand Down
Loading

0 comments on commit 28dcc44

Please sign in to comment.