java.interop icon indicating copy to clipboard operation
java.interop copied to clipboard

Experiment: use `GetValue` for all parameters in the marshal methods

Open radekdoulik opened this issue 7 years ago • 1 comments
trafficstars

The jnimarshalmethod-gen's generated marshal methods now can use code provided by predefined and custom marshalers.

That idea comes from the discussion about https://github.com/xamarin/java.interop/issues/388 where we have concerns about using custom marshalers for interfaces.

Would it make sense to leave that for runtime? So that GetValue would go through the custom marshalers, as it already can?

Could that also be used for the return values? Note that we would also need to find out the return value type at the time we generate the methods. Context: https://github.com/xamarin/java.interop/issues/387

PRO:

  • simpler generated methods
  • do not need to know the custom marshaler at the time when we generate methods (that might not work for the return types though)

CONS:

  • performance overhead
  • complex change with unknown result

Alternative solution:

  • instead of using interface custom marshaler, allow specifing custom marshal manager for the jnimarshalmethod-gen.exe as the command line option?

radekdoulik avatar Nov 02 '18 10:11 radekdoulik

Example generator-emitted marshal method:

static void n_Foo(IntPtr jnienv, IntPtr __this, IntPtr __intArray)
{
	var __envp = new JniTransition(__jnienv);
	try
	{
		var __jvm = JniEnvironment.Runtime;
		var __vm = __jvm.ValueManager;
		__vm.WaitForGCBridgeProcessing();
		var __this_val = __vm.GetValue<ExportTest>(__this);
		var intArray = __vm.GetValue<int[]>(__intArray);
		__this_val.Foo(intArray);
	}
	catch (Exception __e) if (__jvm.ExceptionShouldTransitionToJni(__e))
	{
		__envp.SetPendingException(__e);
	}
	finally
	{
		__envp.Dispose();
	}
}

jonpryor avatar Dec 16 '19 23:12 jonpryor