Skip to content

Commit

Permalink
[browser][MT] cleanup (#98672)
Browse files Browse the repository at this point in the history
Co-authored-by: Marek Fišera <mara@neptuo.com>
  • Loading branch information
pavelsavara and maraf authored Feb 21, 2024
1 parent 82e2360 commit 32929b6
Show file tree
Hide file tree
Showing 44 changed files with 421 additions and 299 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static void CallEntrypoint(JSMarshalerArgument* arguments_buffer)
}
catch (Exception ex)
{
Environment.FailFast("CallEntrypoint: Unexpected synchronous failure. " + ex);
Environment.FailFast($"CallEntrypoint: Unexpected synchronous failure (ManagedThreadId {Environment.CurrentManagedThreadId}): " + ex);
}
}

Expand Down Expand Up @@ -110,7 +110,7 @@ public static void ReleaseJSOwnedObjectByGCHandle(JSMarshalerArgument* arguments
}
catch (Exception ex)
{
Environment.FailFast("ReleaseJSOwnedObjectByGCHandle: Unexpected synchronous failure. " + ex);
Environment.FailFast($"ReleaseJSOwnedObjectByGCHandle: Unexpected synchronous failure (ManagedThreadId {Environment.CurrentManagedThreadId}): " + ex);
}
}

Expand Down Expand Up @@ -205,7 +205,7 @@ public static void CompleteTask(JSMarshalerArgument* arguments_buffer)
}
catch (Exception ex)
{
Environment.FailFast("CompleteTask: Unexpected synchronous failure. " + ex);
Environment.FailFast($"CompleteTask: Unexpected synchronous failure (ManagedThreadId {Environment.CurrentManagedThreadId}): " + ex);
}
}

Expand Down Expand Up @@ -280,7 +280,7 @@ public static void BindAssemblyExports(JSMarshalerArgument* arguments_buffer)
}
catch (Exception ex)
{
Environment.FailFast("BindAssemblyExports: Unexpected synchronous failure. " + ex);
Environment.FailFast($"BindAssemblyExports: Unexpected synchronous failure (ManagedThreadId {Environment.CurrentManagedThreadId}): " + ex);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,9 @@ internal unsafe JSBindingType this[int position]
/// </summary>
/// <param name="signature">Generated metadata about the method signature used for marshaling.</param>
/// <param name="arguments">The intermediate buffer with marshalled arguments.</param>
#if !DEBUG
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#endif
public static void InvokeJS(JSFunctionBinding signature, Span<JSMarshalerArgument> arguments)
{
InvokeJSImportImpl(signature, arguments);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ public static JSObject DotnetInstance
/// <param name="moduleUrl">The location of the module file.</param>
/// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
/// <returns>A proxy for the JavaScript object that contains the module's exports.</returns>
#if !DEBUG
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#endif
public static Task<JSObject> ImportAsync(string moduleName, string moduleUrl, CancellationToken cancellationToken = default)
{
return JSHostImplementation.ImportAsync(moduleName, moduleUrl, cancellationToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ public static MethodInfo GetTaskResultMethodInfo(Type taskType)
throw new InvalidOperationException();
}

#if !DEBUG
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#endif
public static void ThrowException(ref JSMarshalerArgument arg)
{
arg.ToManaged(out Exception? ex);
Expand All @@ -85,7 +87,9 @@ public static async Task<JSObject> ImportAsync(string moduleName, string moduleU
ConfigureAwaitOptions.ForceYielding); // this helps to finish the import before we bind the module in [JSImport]
}

#if !DEBUG
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#endif
public static async Task<JSObject> CancellationHelper(Task<JSObject> jsTask, CancellationToken cancellationToken)
{
if (jsTask.IsCompletedSuccessfully)
Expand Down Expand Up @@ -293,6 +297,7 @@ public static unsafe JSFunctionBinding BindManagedFunction(string fullyQualified

var signature = GetMethodSignature(signatures, null, null);

// this will hit JS side possibly on another thread, depending on JSProxyContext.CurrentThreadContext
JavaScriptImports.BindCSFunction(monoMethod, assemblyName, nameSpace, shortClassName, methodName, signatureHash, (IntPtr)signature.Header);

FreeMethodSignatureBuffer(signature);
Expand All @@ -310,7 +315,9 @@ public static void SetHasExternalEventLoop(Thread thread)
}
#endif

#if !DEBUG
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#endif
public static RuntimeMethodHandle GetMethodHandleFromIntPtr(IntPtr ptr)
{
var temp = new IntPtrAndHandle { ptr = ptr };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ internal struct JSMarshalerArgumentImpl
/// <summary>
/// This API supports JSImport infrastructure and is not intended to be used directly from your code.
/// </summary>
#if !DEBUG
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#endif
public unsafe void Initialize()
{
slot.Type = MarshalerType.None;
Expand All @@ -85,7 +87,9 @@ public unsafe void Initialize()
}

#if FEATURE_WASM_MANAGED_THREADS
#if !DEBUG
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#endif
internal unsafe void InitializeWithContext(JSProxyContext knownProxyContext)
{
slot.Type = MarshalerType.None;
Expand All @@ -111,11 +115,11 @@ internal JSProxyContext ToManagedContext
// during JSExport, this is marshaling parameters and it would be set by:
// - alloc_stack_frame
// - set_js_handle/set_gc_handle
var proxyContextGCHandle = (GCHandle)slot.ContextHandle;
if (proxyContextGCHandle == default)
if (slot.ContextHandle == IntPtr.Zero)
{
Environment.FailFast($"ContextHandle not set, ManagedThreadId: {Environment.CurrentManagedThreadId}. {Environment.NewLine} {Environment.StackTrace}");
Environment.FailFast($"ContextHandle not set (ManagedThreadId {Environment.CurrentManagedThreadId}): {Environment.NewLine} {Environment.StackTrace}");
}
var proxyContextGCHandle = (GCHandle)slot.ContextHandle;
var argumentContext = (JSProxyContext)proxyContextGCHandle.Target!;
return argumentContext;
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ internal JSObject(IntPtr jsHandle, JSProxyContext ctx)
/// <inheritdoc />
public override string ToString() => $"(js-obj js '{JSHandle}')";

#if !DEBUG
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#endif
internal void AssertNotDisposed()
{
lock (ProxyContext)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ private JSProxyContext()
public bool IsMainThread;
public JSSynchronizationContext SynchronizationContext;

#if !DEBUG
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#endif
public bool IsCurrentThread()
{
return ManagedTID == Environment.CurrentManagedThreadId;
Expand Down Expand Up @@ -232,7 +234,9 @@ public static JSProxyContext CurrentOperationContext

#endif

#if !DEBUG
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#endif
public static JSProxyContext AssertIsInteropThread()
{
#if FEATURE_WASM_MANAGED_THREADS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ public partial struct JSMarshalerArgument
/// It's used by JSImport code generator and should not be used by developers in source code.
/// </summary>
/// <param name="value">The value to be marshaled.</param>
#if !DEBUG
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#endif
public unsafe void ToManagedBig(out long value)
{
if (slot.Type == MarshalerType.None)
Expand All @@ -28,7 +30,9 @@ public unsafe void ToManagedBig(out long value)
/// It's used by JSImport code generator and should not be used by developers in source code.
/// </summary>
/// <param name="value">The value to be marshaled.</param>
#if !DEBUG
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#endif
public void ToJSBig(long value)
{
slot.Type = MarshalerType.BigInt64;
Expand All @@ -40,7 +44,9 @@ public void ToJSBig(long value)
/// It's used by JSImport code generator and should not be used by developers in source code.
/// </summary>
/// <param name="value">The value to be marshaled.</param>
#if !DEBUG
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#endif
public unsafe void ToManagedBig(out long? value)
{
if (slot.Type == MarshalerType.None)
Expand All @@ -56,7 +62,9 @@ public unsafe void ToManagedBig(out long? value)
/// It's used by JSImport code generator and should not be used by developers in source code.
/// </summary>
/// <param name="value">The value to be marshaled.</param>
#if !DEBUG
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#endif
public void ToJSBig(long? value)
{
if (value.HasValue)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ public partial struct JSMarshalerArgument
/// It's used by JSImport code generator and should not be used by developers in source code.
/// </summary>
/// <param name="value">The value to be marshaled.</param>
#if !DEBUG
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#endif
public unsafe void ToManaged(out bool value)
{
if (slot.Type == MarshalerType.None)
Expand All @@ -28,7 +30,9 @@ public unsafe void ToManaged(out bool value)
/// It's used by JSImport code generator and should not be used by developers in source code.
/// </summary>
/// <param name="value">The value to be marshaled.</param>
#if !DEBUG
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#endif
public void ToJS(bool value)
{
slot.Type = MarshalerType.Boolean;
Expand All @@ -40,7 +44,9 @@ public void ToJS(bool value)
/// It's used by JSImport code generator and should not be used by developers in source code.
/// </summary>
/// <param name="value">The value to be marshaled.</param>
#if !DEBUG
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#endif
public unsafe void ToManaged(out bool? value)
{
if (slot.Type == MarshalerType.None)
Expand All @@ -56,7 +62,9 @@ public unsafe void ToManaged(out bool? value)
/// It's used by JSImport code generator and should not be used by developers in source code.
/// </summary>
/// <param name="value">The value to be marshaled.</param>
#if !DEBUG
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#endif
public void ToJS(bool? value)
{
if (value.HasValue)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ public partial struct JSMarshalerArgument
/// It's used by JSImport code generator and should not be used by developers in source code.
/// </summary>
/// <param name="value">The value to be marshaled.</param>
#if !DEBUG
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#endif
public unsafe void ToManaged(out byte value)
{
if (slot.Type == MarshalerType.None)
Expand All @@ -28,7 +30,9 @@ public unsafe void ToManaged(out byte value)
/// It's used by JSImport code generator and should not be used by developers in source code.
/// </summary>
/// <param name="value">The value to be marshaled.</param>
#if !DEBUG
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#endif
public void ToJS(byte value)
{
slot.Type = MarshalerType.Byte;
Expand All @@ -40,7 +44,9 @@ public void ToJS(byte value)
/// It's used by JSImport code generator and should not be used by developers in source code.
/// </summary>
/// <param name="value">The value to be marshaled.</param>
#if !DEBUG
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#endif
public unsafe void ToManaged(out byte? value)
{
if (slot.Type == MarshalerType.None)
Expand All @@ -56,7 +62,9 @@ public unsafe void ToManaged(out byte? value)
/// It's used by JSImport code generator and should not be used by developers in source code.
/// </summary>
/// <param name="value">The value to be marshaled.</param>
#if !DEBUG
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#endif
public void ToJS(byte? value)
{
if (value.HasValue)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ public partial struct JSMarshalerArgument
/// It's used by JSImport code generator and should not be used by developers in source code.
/// </summary>
/// <param name="value">The value to be marshaled.</param>
#if !DEBUG
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#endif
public unsafe void ToManaged(out char value)
{
if (slot.Type == MarshalerType.None)
Expand All @@ -28,7 +30,9 @@ public unsafe void ToManaged(out char value)
/// It's used by JSImport code generator and should not be used by developers in source code.
/// </summary>
/// <param name="value">The value to be marshaled.</param>
#if !DEBUG
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#endif
public void ToJS(char value)
{
slot.Type = MarshalerType.Char;
Expand All @@ -40,7 +44,9 @@ public void ToJS(char value)
/// It's used by JSImport code generator and should not be used by developers in source code.
/// </summary>
/// <param name="value">The value to be marshaled.</param>
#if !DEBUG
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#endif
public unsafe void ToManaged(out char? value)
{
if (slot.Type == MarshalerType.None)
Expand All @@ -56,7 +62,9 @@ public unsafe void ToManaged(out char? value)
/// It's used by JSImport code generator and should not be used by developers in source code.
/// </summary>
/// <param name="value">The value to be marshaled.</param>
#if !DEBUG
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#endif
public void ToJS(char? value)
{
if (value.HasValue)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ public partial struct JSMarshalerArgument
/// It's used by JSImport code generator and should not be used by developers in source code.
/// </summary>
/// <param name="value">The value to be marshaled.</param>
#if !DEBUG
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#endif
public unsafe void ToManaged(out DateTimeOffset value)
{
if (slot.Type == MarshalerType.None)
Expand All @@ -28,7 +30,9 @@ public unsafe void ToManaged(out DateTimeOffset value)
/// It's used by JSImport code generator and should not be used by developers in source code.
/// </summary>
/// <param name="value">The value to be marshaled.</param>
#if !DEBUG
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#endif
public void ToJS(DateTimeOffset value)
{
slot.Type = MarshalerType.DateTimeOffset;
Expand All @@ -40,7 +44,9 @@ public void ToJS(DateTimeOffset value)
/// It's used by JSImport code generator and should not be used by developers in source code.
/// </summary>
/// <param name="value">The value to be marshaled.</param>
#if !DEBUG
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#endif
public unsafe void ToManaged(out DateTimeOffset? value)
{
if (slot.Type == MarshalerType.None)
Expand All @@ -56,7 +62,9 @@ public unsafe void ToManaged(out DateTimeOffset? value)
/// It's used by JSImport code generator and should not be used by developers in source code.
/// </summary>
/// <param name="value">The value to be marshaled.</param>
#if !DEBUG
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#endif
public void ToJS(DateTimeOffset? value)
{
if (value.HasValue)
Expand All @@ -75,7 +83,9 @@ public void ToJS(DateTimeOffset? value)
/// It's used by JSImport code generator and should not be used by developers in source code.
/// </summary>
/// <param name="value">The value to be marshaled.</param>
#if !DEBUG
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#endif
public unsafe void ToManaged(out DateTime value)
{
if (slot.Type == MarshalerType.None)
Expand All @@ -91,7 +101,9 @@ public unsafe void ToManaged(out DateTime value)
/// It's used by JSImport code generator and should not be used by developers in source code.
/// </summary>
/// <param name="value">The value to be marshaled.</param>
#if !DEBUG
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#endif
public void ToJS(DateTime value)
{
slot.Type = MarshalerType.DateTime;
Expand All @@ -103,7 +115,9 @@ public void ToJS(DateTime value)
/// It's used by JSImport code generator and should not be used by developers in source code.
/// </summary>
/// <param name="value">The value to be marshaled.</param>
#if !DEBUG
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#endif
public unsafe void ToManaged(out DateTime? value)
{
if (slot.Type == MarshalerType.None)
Expand All @@ -119,7 +133,9 @@ public unsafe void ToManaged(out DateTime? value)
/// It's used by JSImport code generator and should not be used by developers in source code.
/// </summary>
/// <param name="value">The value to be marshaled.</param>
#if !DEBUG
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#endif
public void ToJS(DateTime? value)
{
if (value.HasValue)
Expand Down
Loading

0 comments on commit 32929b6

Please sign in to comment.