Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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 @@ -162,6 +162,7 @@ public partial class MyClass {
_members.InstanceMethods.InvokeVirtualVoidMethod (__id, this, __args);
} finally {
JNIEnv.DeleteLocalRef (native_value);
global::System.GC.KeepAlive (value);
Copy link
Contributor

Choose a reason for hiding this comment

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

Does not need to be addressed for d16-8: We don't need a GC.KeepAlive() for types which will be "deep marshaled". This includes System.String and array types. For master, would we be able to skip this?

}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ public virtual unsafe string Key {
_members.InstanceMethods.InvokeVirtualVoidMethod (__id, this, __args);
} finally {
JNIEnv.DeleteLocalRef (native_value);
global::System.GC.KeepAlive (value);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public partial class MyClass {
JNIEnv.CopyArray (native_value, value);
JNIEnv.DeleteLocalRef (native_value);
}
global::System.GC.KeepAlive (value);
}
}

Expand All @@ -46,6 +47,7 @@ public partial class MyClass {
JNIEnv.CopyArray (native_value, value);
JNIEnv.DeleteLocalRef (native_value);
}
global::System.GC.KeepAlive (value);
}
}

Expand All @@ -65,6 +67,7 @@ public partial class MyClass {
JNIEnv.CopyArray (native_value, value);
JNIEnv.DeleteLocalRef (native_value);
}
global::System.GC.KeepAlive (value);
}
}

Expand All @@ -84,6 +87,7 @@ public partial class MyClass {
JNIEnv.CopyArray (native_value, value);
JNIEnv.DeleteLocalRef (native_value);
}
global::System.GC.KeepAlive (value);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public partial class MyClass {
JNIEnv.CopyArray (native_value, value);
JNIEnv.DeleteLocalRef (native_value);
}
global::System.GC.KeepAlive (value);
}
}
}
Expand Down Expand Up @@ -65,6 +66,7 @@ public partial class MyClass {
JNIEnv.CopyArray (native_value, value);
JNIEnv.DeleteLocalRef (native_value);
}
global::System.GC.KeepAlive (value);
}
}
}
Expand Down Expand Up @@ -94,6 +96,7 @@ public partial class MyClass {
JNIEnv.CopyArray (native_value, value);
JNIEnv.DeleteLocalRef (native_value);
}
global::System.GC.KeepAlive (value);
}
}
}
Expand Down Expand Up @@ -123,6 +126,7 @@ public partial class MyClass {
JNIEnv.CopyArray (native_value, value);
JNIEnv.DeleteLocalRef (native_value);
}
global::System.GC.KeepAlive (value);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ public partial class MyClass {
_members.InstanceMethods.InvokeVirtualVoidMethod (__id, this, __args);
} finally {
JNIEnv.DeleteLocalRef (native_value);
global::System.GC.KeepAlive (value);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ public virtual unsafe string? Key {
_members.InstanceMethods.InvokeVirtualVoidMethod (__id, this, __args);
} finally {
JNIEnv.DeleteLocalRef (native_value);
global::System.GC.KeepAlive (value);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ public partial class MyClass {
_members.InstanceMethods.InvokeVirtualVoidMethod (__id, this, __args);
} finally {
JNIEnv.DeleteLocalRef (native_value);
global::System.GC.KeepAlive (value);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ public virtual unsafe string Key {
_members.InstanceMethods.InvokeVirtualVoidMethod (__id, this, __args);
} finally {
JNIEnv.DeleteLocalRef (native_value);
global::System.GC.KeepAlive (value);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ static void n_SetAdapter_Lxamarin_test_SpinnerAdapter_ (IntPtr jnienv, IntPtr na
__args [0] = new JniArgumentValue ((value == null) ? IntPtr.Zero : ((global::Java.Lang.Object) value).Handle);
_members.InstanceMethods.InvokeVirtualVoidMethod (__id, this, __args);
} finally {
global::System.GC.KeepAlive (value);
}
}
}
Expand Down Expand Up @@ -126,6 +127,7 @@ public AbsSpinnerInvoker (IntPtr handle, JniHandleOwnership transfer) : base (ha
_members.InstanceMethods.InvokeAbstractVoidMethod (__id, this, __args);
} finally {
JNIEnv.DeleteLocalRef (native_value);
global::System.GC.KeepAlive (value);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ public AdapterViewInvoker (IntPtr handle, JniHandleOwnership transfer) : base (h
_members.InstanceMethods.InvokeAbstractVoidMethod (__id, this, __args);
} finally {
JNIEnv.DeleteLocalRef (native_value);
global::System.GC.KeepAlive (value);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ static int n_GetSpanFlags_Ljava_lang_Object_ (IntPtr jnienv, IntPtr native__this
var __rm = _members.InstanceMethods.InvokeVirtualInt32Method (__id, this, __args);
return (global::Android.Text.SpanTypes) __rm;
} finally {
global::System.GC.KeepAlive (what);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ static int n_GetSpanFlags_Ljava_lang_Object_ (IntPtr jnienv, IntPtr native__this
var __rm = _members.InstanceMethods.InvokeVirtualInt32Method (__id, this, __args);
return (global::Android.Text.SpanTypes) __rm;
} finally {
global::System.GC.KeepAlive (p0);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ public virtual unsafe void SetOnClickListener (global::Android.Views.View.IOnCli
__args [0] = new JniArgumentValue ((l == null) ? IntPtr.Zero : ((global::Java.Lang.Object) l).Handle);
_members.InstanceMethods.InvokeVirtualVoidMethod (__id, this, __args);
} finally {
global::System.GC.KeepAlive (l);
}
}

Expand Down Expand Up @@ -206,6 +207,7 @@ public virtual unsafe void SetOn123Listener (global::Android.Views.View.IOnClick
__args [0] = new JniArgumentValue ((l == null) ? IntPtr.Zero : ((global::Java.Lang.Object) l).Handle);
_members.InstanceMethods.InvokeVirtualVoidMethod (__id, this, __args);
} finally {
global::System.GC.KeepAlive (l);
}
}

Expand Down Expand Up @@ -238,6 +240,7 @@ public virtual unsafe void AddTouchables (global::System.Collections.Generic.ILi
_members.InstanceMethods.InvokeVirtualVoidMethod (__id, this, __args);
} finally {
JNIEnv.DeleteLocalRef (native_views);
global::System.GC.KeepAlive (views);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public unsafe void SetOnEventListener (global::Com.Google.Android.Exoplayer.Drm.
__args [0] = new JniArgumentValue ((p0 == null) ? IntPtr.Zero : ((global::Java.Lang.Object) p0).Handle);
_members.InstanceMethods.InvokeAbstractVoidMethod (__id, this, __args);
} finally {
global::System.GC.KeepAlive (p0);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ static int n_Handle_Ljava_lang_Object_Ljava_lang_Throwable_ (IntPtr jnienv, IntP
var __rm = _members.InstanceMethods.InvokeVirtualInt32Method (__id, this, __args);
return __rm;
} finally {
global::System.GC.KeepAlive (o);
global::System.GC.KeepAlive (t);
}
}

Expand Down Expand Up @@ -255,6 +257,7 @@ public virtual unsafe void VoidMethodWithParams (string astring, int anint, glob
_members.InstanceMethods.InvokeVirtualVoidMethod (__id, this, __args);
} finally {
JNIEnv.DeleteLocalRef (native_astring);
global::System.GC.KeepAlive (anObject);
}
}

Expand Down Expand Up @@ -318,6 +321,7 @@ public virtual unsafe void ArrayListTest (global::System.Collections.Generic.ILi
_members.InstanceMethods.InvokeVirtualVoidMethod (__id, this, __args);
} finally {
JNIEnv.DeleteLocalRef (native_p0);
global::System.GC.KeepAlive (p0);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ public override unsafe int SomeInteger {
__args [0] = new JniArgumentValue ((value == null) ? IntPtr.Zero : ((global::Java.Lang.Object) value).Handle);
_members.InstanceMethods.InvokeAbstractVoidMethod (__id, this, __args);
} finally {
global::System.GC.KeepAlive (value);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public virtual unsafe void SetA (global::Java.Lang.Object adapter)
_members.InstanceMethods.InvokeVirtualVoidMethod (__id, this, __args);
} finally {
JNIEnv.DeleteLocalRef (native_adapter);
global::System.GC.KeepAlive (adapter);
}
}

Expand Down Expand Up @@ -92,6 +93,7 @@ public virtual unsafe void ListTest (global::System.Collections.Generic.IList<gl
_members.InstanceMethods.InvokeVirtualVoidMethod (__id, this, __args);
} finally {
JNIEnv.DeleteLocalRef (native_p0);
global::System.GC.KeepAlive (p0);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ public static unsafe void SetSomeObject (global::Java.Lang.Object newvalue)
__args [0] = new JniArgumentValue ((newvalue == null) ? IntPtr.Zero : ((global::Java.Lang.Object) newvalue).Handle);
_members.StaticMethods.InvokeVoidMethod (__id, __args);
} finally {
global::System.GC.KeepAlive (newvalue);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ public virtual unsafe int Read (byte[] buffer)
JNIEnv.CopyArray (native_buffer, buffer);
JNIEnv.DeleteLocalRef (native_buffer);
}
global::System.GC.KeepAlive (buffer);
}
}

Expand Down Expand Up @@ -257,6 +258,7 @@ public virtual unsafe int Read (byte[] buffer, int byteOffset, int byteCount)
JNIEnv.CopyArray (native_buffer, buffer);
JNIEnv.DeleteLocalRef (native_buffer);
}
global::System.GC.KeepAlive (buffer);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ public virtual unsafe void Write (byte[] buffer)
JNIEnv.CopyArray (native_buffer, buffer);
JNIEnv.DeleteLocalRef (native_buffer);
}
global::System.GC.KeepAlive (buffer);
}
}

Expand Down Expand Up @@ -175,6 +176,7 @@ public virtual unsafe void Write (byte[] buffer, int offset, int count)
JNIEnv.CopyArray (native_buffer, buffer);
JNIEnv.DeleteLocalRef (native_buffer);
}
global::System.GC.KeepAlive (buffer);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public virtual unsafe void SetObject (byte[] value)
JNIEnv.CopyArray (native_value, value);
JNIEnv.DeleteLocalRef (native_value);
}
global::System.GC.KeepAlive (value);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ static void n_SetObject_Ljava_lang_Object_ (IntPtr jnienv, IntPtr native__this,
__args [0] = new JniArgumentValue ((value == null) ? IntPtr.Zero : ((global::Java.Lang.Object) value).Handle);
_members.InstanceMethods.InvokeVirtualVoidMethod (__id, this, __args);
} finally {
global::System.GC.KeepAlive (value);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public virtual unsafe void SetObject (string[] value)
JNIEnv.CopyArray (native_value, value);
JNIEnv.DeleteLocalRef (native_value);
}
global::System.GC.KeepAlive (value);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ public override unsafe int GetSpanFlags (global::Java.Lang.Object tag)
var __rm = _members.InstanceMethods.InvokeAbstractInt32Method (__id, this, __args);
return __rm;
} finally {
global::System.GC.KeepAlive (tag);
}
}

Expand All @@ -194,6 +195,7 @@ public override unsafe void Append (global::Java.Lang.ICharSequence value)
_members.InstanceMethods.InvokeAbstractVoidMethod (__id, this, __args);
} finally {
JNIEnv.DeleteLocalRef (native_value);
global::System.GC.KeepAlive (value);
}
}

Expand All @@ -210,6 +212,7 @@ public override unsafe void Append (global::Java.Lang.ICharSequence value)
return global::Java.Lang.Object.GetObject<Java.Lang.ICharSequence> (__rm.Handle, JniHandleOwnership.TransferLocalRef);
} finally {
JNIEnv.DeleteLocalRef (native_value);
global::System.GC.KeepAlive (value);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public unsafe int CompareTo (global::Java.Lang.Object o)
return __rm;
} finally {
JNIEnv.DeleteLocalRef (native_o);
global::System.GC.KeepAlive (o);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.IO;
using System.Linq;
using Mono.Options;

namespace MonoDroid.Generation {
Expand Down Expand Up @@ -182,9 +183,37 @@ internal override void WriteMethodBody (Method method, string indent, GenBase ty
writer.WriteLine ("{0}}} finally {{", indent);
foreach (string cleanup in method.Parameters.GetCallCleanup (opt))
writer.WriteLine ("{0}\t{1}", indent, cleanup);
foreach (var p in method.Parameters.Where (GenerateKeepAlive))
writer.WriteLine ($"{indent}\tglobal::System.GC.KeepAlive ({opt.GetSafeIdentifier (p.Name)});");

writer.WriteLine ("{0}}}", indent);
}

bool GenerateKeepAlive (Parameter p)
{
if (p.Symbol.IsEnum)
return false;

return p.Type switch {
"bool" => false,
"sbyte" => false,
"char" => false,
"double" => false,
"float" => false,
"int" => false,
"long" => false,
"short" => false,
"uint" => false,
"ushort" => false,
"ulong" => false,
"byte" => false,
"ubyte" => false, // Not a C# type, but we will see it from Kotlin unsigned types support
"string" => false,
"Android.Graphics.Color" => false,
_ => true
};
}

internal override void WriteFieldIdField (Field field, string indent)
{
// No field id_ field required
Expand Down