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

WASM Bindings optimizations and fixes #41808

Merged
merged 92 commits into from
Nov 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
92 commits
Select commit Hold shift + click to select a range
bc06440
Fix MarshalTypedArrayByte and re-enable it. Re-enable TestFunctionApply
kg Oct 7, 2020
3a086fc
Re-enable MarshalTypedArray
kg Oct 7, 2020
448f6bb
Detect when the managed wrapper for a JS object has been collected an…
kg Oct 10, 2020
cc7d6ef
Remove debugging code
kg Oct 12, 2020
3f062d5
Cleanup
kg Oct 12, 2020
63edf6d
Checkpoint
kg Sep 2, 2020
34db536
Checkpoint
kg Sep 2, 2020
a6e23ac
Checkpoint
kg Sep 2, 2020
3010582
Checkpoint
kg Sep 2, 2020
fb825f0
Checkpoint
kg Sep 2, 2020
89c1ccd
Checkpoint: Works again
kg Sep 2, 2020
93145d3
Checkpoint
kg Sep 3, 2020
51510f4
Checkpoint
kg Sep 3, 2020
cc90abf
Checkpoint
kg Sep 3, 2020
1659d0f
Checkpoint
kg Sep 3, 2020
30aa9f9
Checkpoint
kg Sep 3, 2020
7f61cc0
Checkpoint
kg Sep 3, 2020
e322c12
Checkpoint
kg Sep 3, 2020
944d2a8
Checkpoint benchmark
kg Sep 3, 2020
9951ee8
Checkpoint
kg Sep 3, 2020
a4a6928
Checkpoint
kg Sep 3, 2020
ce163d6
Maintain a small pool of temporary root instances to minimize GC pres…
kg Sep 10, 2020
d0a709a
Don't use release_roots in call_method due to varargs overhead
kg Sep 10, 2020
721ca89
Various call_method optimizations
kg Sep 10, 2020
d6fb37e
Checkpoint
kg Sep 11, 2020
e74265a
Checkpoint
kg Sep 11, 2020
ad19722
Checkpoint
kg Sep 11, 2020
7732fb5
Checkpoint: Make binding methods produce a wrapper that is faster to …
kg Sep 11, 2020
14aea42
Optimize get/set on temporary roots
kg Sep 11, 2020
88c2c58
Checkpoint
kg Sep 11, 2020
d527d08
Checkpoint
kg Sep 11, 2020
8edc845
Checkpoint
kg Sep 11, 2020
b7717ad
Checkpoint
kg Sep 11, 2020
c5db1a7
Checkpoint
kg Sep 11, 2020
fa0f14e
Checkpoint
kg Sep 11, 2020
98b8888
Checkpoint
kg Sep 11, 2020
f0c9b4f
Checkpoint
kg Sep 11, 2020
8ad1750
Checkpoint
kg Sep 11, 2020
bb83ead
Checkpoint
kg Sep 11, 2020
2da2944
Checkpoint
kg Sep 11, 2020
17bbf87
Checkpoint
kg Sep 11, 2020
87ea9d3
Checkpoint
kg Sep 11, 2020
f3aad06
Checkpoint
kg Sep 11, 2020
2b50178
Checkpoint
kg Sep 11, 2020
2e19e9d
Checkpoint
kg Sep 11, 2020
da6905d
Checkpoint
kg Sep 11, 2020
8ee112a
Checkpoint
kg Sep 11, 2020
968350d
Checkpoint
kg Sep 11, 2020
a15ecd4
Checkpoint: Don't rely on finally block for teardown in call path, be…
kg Sep 12, 2020
e97f71f
Checkpoint
kg Sep 12, 2020
9d0a7c0
Checkpoint
kg Sep 12, 2020
40261df
Checkpoint
kg Sep 12, 2020
6738f62
Checkpoint: Unboxing fast path for primitives
kg Sep 12, 2020
a05c84d
Checkpoint: Fix unboxing fast path
kg Sep 12, 2020
4fbdfa6
Update bindings to use bound static methods instead of call_method in…
kg Sep 12, 2020
58253fd
Checkpoint
kg Sep 12, 2020
5fc5c15
Checkpoint
kg Sep 12, 2020
5eceb5e
Address PR feedback
kg Sep 16, 2020
3c29e85
Revert sample and add separate proj for benchmark
kg Sep 17, 2020
e164f7c
Fix benchmark
kg Sep 17, 2020
5ca18f1
Revert test change
kg Sep 17, 2020
bc8b0c5
Fix passing mono object ptrs to bound functions
kg Sep 18, 2020
5e80d53
Implement unboxing for chars
kg Sep 19, 2020
c9e1ef4
Don't allocate a root buffer for arguments if nothing needs to be roo…
kg Sep 22, 2020
1caf839
Fix whitespace damage from merge
kg Sep 22, 2020
d8616c7
Tweaks to try and prevent boxing/gc
kg Sep 22, 2020
2f1f031
Fix typo
kg Sep 23, 2020
f5e9877
Add some tests
lewing Oct 12, 2020
2821872
Fix test failures
kg Oct 13, 2020
61bcc89
Add more error handling and diagnostic messages
kg Oct 14, 2020
7ad28a0
Repair merge damage
kg Oct 15, 2020
e165bba
Remove bindings benchmark
kg Oct 15, 2020
f43d68c
Use TypedArray.fill 3-argument version to zero memory
kg Oct 15, 2020
b5e211f
Checkpoint: Introduce format strings
kg Oct 15, 2020
58bfb83
Fix interpolated strings
lewing Oct 15, 2020
392c55e
Test refactoring
kg Oct 15, 2020
6267d66
Checkpoint: Add more test coverage for bindings and interop
kg Oct 15, 2020
506b4f0
Checkpoint
kg Oct 16, 2020
0c9f9d7
Checkpoint
kg Oct 16, 2020
4f33972
Checkpoint: Enum marshaling works
kg Oct 16, 2020
f9bc6b5
Improve test coverage
kg Oct 16, 2020
a27fefd
Checkpoint: Unify unboxing of primitive types
kg Oct 16, 2020
f9f5f89
Checkpoint: Unify unboxing of primitive types
kg Oct 16, 2020
9081ffd
Checkpoint: Restore fn to satisfy runtime-test.js
kg Oct 16, 2020
1e0ba4d
Checkpoint: Unify boxing for primitives
kg Oct 16, 2020
d24c02b
Checkpoint
kg Oct 16, 2020
215cdd2
Remove now-unused box methods
kg Oct 16, 2020
dcdb16a
Don't store names for null method IDs
kg Oct 16, 2020
fcf398a
Fix indentation damage
kg Oct 16, 2020
5e9cff3
Add test
kg Oct 16, 2020
2806916
Satisfy CI
kg Oct 20, 2020
635aa03
Accept weaker promises
lewing Nov 6, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,16 @@ private static int BindJSObject(int jsId, bool ownsHandle, int mappedType)
WeakReference? reference;
lock (_boundObjects)
{
if (!_boundObjects.TryGetValue(jsId, out reference))
if (_boundObjects.TryGetValue(jsId, out reference))
{
if ((reference.Target == null) || ((reference.Target as JSObject)?.IsDisposed == true))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fairly sure this is just masking the problem, I wonder if the issue is that we need to be able to promote weak refs into strong ones.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's correct in some scenarios for it to have expired, if nothing is retaining a reference to globalThis.Math then the C# wrapper for it should be able to get collected. That's at least what was causing the test failures

{
_boundObjects.Remove(jsId);
reference = null;
}
}

if (reference == null)
{
IntPtr jsIntPtr = (IntPtr)jsId;
reference = new WeakReference(mappedType > 0 ? BindJSType(jsIntPtr, ownsHandle, mappedType) : new JSObject(jsIntPtr, ownsHandle), true);
Expand Down Expand Up @@ -229,21 +238,6 @@ private static int GetJSObjectId(object rawObj)
js.GetWrappedObject() ?? h.Target : h.Target;
}

private static object BoxInt(int i)
{
return i;
}

private static object BoxDouble(double d)
{
return d;
}

private static object BoxBool(int b)
{
return b == 0 ? false : true;
}

private static bool IsSimpleArray(object a)
{
return a is System.Array arr && arr.Rank == 1 && arr.GetLowerBound(0) == 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ private static object InvokeMarshalObj()
return _marshalledObject;
}

private static object InvokeReturnMarshalObj()
{
return _marshalledObject;
}

internal static int _valOne, _valTwo;
private static void ManipulateObject(JSObject obj)
{
Expand Down Expand Up @@ -316,20 +321,26 @@ private static void CreateFunctionSum()
internal static int _sumValue = 0;
private static void CallFunctionSum()
{
if (_sumFunction == null)
throw new Exception("_sumFunction is null");
_sumValue = (int)_sumFunction.Call(null, 3, 5);
}

private static Function _mathMinFunction;
private static void CreateFunctionApply()
{
var math = (JSObject)Runtime.GetGlobalObject("Math");
if (math == null)
throw new Exception("Runtime.GetGlobalObject(Math) returned null");
_mathMinFunction = (Function)math.GetObjectProperty("min");

}

internal static int _minValue = 0;
private static void CallFunctionApply()
{
if (_mathMinFunction == null)
throw new Exception("_mathMinFunction is null");
_minValue = (int)_mathMinFunction.Apply(null, new object[] { 5, 6, 2, 3, 7 });
}

Expand All @@ -345,5 +356,32 @@ public static void SetBlobAsUri(Uri blobUri)
_blobURI = blobUri;
}

internal static uint _uintValue;
private static void InvokeUInt(uint value)
{
_uintValue = value;
}

internal static TestEnum _enumValue;
private static void SetEnumValue(TestEnum value)
{
_enumValue = value;
}
private static TestEnum GetEnumValue()
{
return _enumValue;
}

private static UInt64 GetUInt64()
{
return UInt64.MaxValue;
}
}

public enum TestEnum : uint {
FirstValue = 1,
Zero = 0,
Five = 5,
BigValue = 0xFFFFFFFEu
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,13 @@ public static void FunctionSum()
}

[Fact]
[ActiveIssue("https://github.com/dotnet/runtime/issues/40112")]
public static void FunctionMath()
{
JSObject math = (JSObject)Runtime.GetGlobalObject("Math");
Assert.NotNull(math);
Assert.True(math != null, "math != null");

Function mathMax = (Function)math.GetObjectProperty("max");
Assert.NotNull(mathMax);
Assert.True(mathMax != null, "math.max != null");

var maxValue = (int)mathMax.Apply(null, new object[] { 5, 6, 2, 3, 7 });
Assert.Equal(7, maxValue);
Expand All @@ -108,7 +107,7 @@ public static void FunctionMath()
Assert.Equal(7, maxValue);

Function mathMin = (Function)((JSObject)Runtime.GetGlobalObject("Math")).GetObjectProperty("min");
Assert.NotNull(mathMin);
Assert.True(mathMin != null, "math.min != null");

var minValue = (int)mathMin.Apply(null, new object[] { 5, 6, 2, 3, 7 });
Assert.Equal(2, minValue);
Expand Down
Loading