[System.Runtime.Serialization] Static serializer calls directly into internal APIs...
commitae8d66d6a930c79008bdbcd21d82192835e70431
authorMiguel de Icaza <miguel@gnome.org>
Fri, 4 Dec 2015 18:40:13 +0000 (4 13:40 -0500)
committerMiguel de Icaza <miguel@gnome.org>
Fri, 4 Dec 2015 18:54:48 +0000 (4 13:54 -0500)
tree0f13a721b4eb488d5541c89e897aff6587c7c99d
parent8bc9896c5507b3f2e5324c8573652c4f262f0a67
[System.Runtime.Serialization] Static serializer calls directly into internal APIs to fix C6 regression

With C6 we introduced a regression
https://bugzilla.xamarin.com/show_bug.cgi?id=36100, which is caused by
the new static serialization code that we wrote to reuse Microsoft's
serializer.

The code uses Invoke on a series of MethodInfos, and this obscures the
actual code that will be invoked at runtime to serialize certain
objects, causing the following exception:

Attempting to JIT compile method '(wrapper runtime-invoke) <Module>:runtime_invoke_bool_Nullable`1<Decimal> (object,intptr,intptr,intptr)' while running with --aot-only.

This patch makes the simple code work, but a more thorough review of
the code would allow us to remove many of the slow dynamic codepaths
in the serializer.

We opted for that approach to keep the code as similar as possible to the
original.

But the code basically does this:

* Use the XmlFormatGeneratorStatics property InternalSerializeMethod,
  whose sole purpose is to delay computing the MethodInfo for the
  XmlFormatWriterGenerator's InternalSerialize.

* Use the resulting method in a few places to call the MethodInfo.

The MethodInfo was used because the original code uses Reflection.Emit
to create fast serializers and it needs handles to internal methods,
but our static rewriter does not need it.

We should replace all of those uses, but for now, this patch at least
deals with the 36100 bug.
mcs/class/System.Runtime.Serialization/ReferenceSources/XmlFormatWriterGenerator_static.cs
mcs/class/System.Runtime.Serialization/System.Runtime.Serialization_test.dll.sources
mcs/class/System.Runtime.Serialization/Test/System.Runtime.Serialization/Bug36100.cs [new file with mode: 0644]