From 811c75103687c976fdf0fe007f6272bd871c7066 Mon Sep 17 00:00:00 2001 From: Sergey Bogdanov Date: Mon, 5 Nov 2012 15:02:59 +0200 Subject: [PATCH] AOT related fixes stabilizing tests increase trampoline for tests --- src/ServiceStack.Text/Common/WriteLists.cs | 1 + src/ServiceStack.Text/JsConfig.cs | 250 +++++++++++------- .../ServiceStack.Text.Tests.MonoTouch/Aot.cs | 7 +- .../Info.plist | 4 +- .../ServiceStack.Text.Tests.MonoTouch.csproj | 10 + .../DictionaryTests.cs | 20 ++ tests/ServiceStack.Text.Tests/StructTests.cs | 20 ++ 7 files changed, 209 insertions(+), 103 deletions(-) diff --git a/src/ServiceStack.Text/Common/WriteLists.cs b/src/ServiceStack.Text/Common/WriteLists.cs index be3df54a1..f08b906d5 100644 --- a/src/ServiceStack.Text/Common/WriteLists.cs +++ b/src/ServiceStack.Text/Common/WriteLists.cs @@ -297,6 +297,7 @@ public static void WriteGenericIListValueType(TextWriter writer, IList list) public static void WriteArray(TextWriter writer, object oArrayValue) { + if (oArrayValue == null) return; WriteGenericArray(writer, (Array)oArrayValue); } diff --git a/src/ServiceStack.Text/JsConfig.cs b/src/ServiceStack.Text/JsConfig.cs index fa8baf8ea..cb8265c55 100644 --- a/src/ServiceStack.Text/JsConfig.cs +++ b/src/ServiceStack.Text/JsConfig.cs @@ -388,14 +388,12 @@ public static void RegisterForAot() RegisterElement(); RegisterElement(); RegisterElement(); - RegisterElement(); + + RegisterElement(); RegisterElement(); RegisterElement(); RegisterElement(); RegisterElement(); - RegisterElement(); - RegisterElement(); - RegisterElement(); RegisterElement(); RegisterElement(); @@ -410,24 +408,24 @@ public static void RegisterForAot() RegisterElement(); RegisterElement(); RegisterElement(); - RegisterElement(); - RegisterElement(); - RegisterElement(); + + //RegisterElement(); + + RegisterTypeForAot(); // used by DateTime + + // register built in structs + RegisterTypeForAot(); + RegisterTypeForAot(); + RegisterTypeForAot(); + RegisterTypeForAot(); + RegisterTypeForAot(); + RegisterTypeForAot(); } [MonoTouch.Foundation.Preserve] - public static bool RegisterTypeForAot() + public static void RegisterTypeForAot() { - bool ret = false; - try - { - RegisterSerializers(); - ret = true; - }catch(Exception e){ - Console.WriteLine("Aot error: " + e); - } - - return ret; + AotConfig.RegisterSerializers(); } [MonoTouch.Foundation.Preserve] @@ -436,96 +434,148 @@ static void RegisterQueryStringWriter() var i = 0; if (QueryStringWriter.WriteFn() != null) i++; } - + [MonoTouch.Foundation.Preserve] - static void RegisterCsvSerializer() + internal static int RegisterElement() { - CsvSerializer.WriteFn(); - CsvSerializer.WriteObject(null, null); - CsvWriter.Write(null, default(IEnumerable)); - CsvWriter.WriteRow(null, default(T)); - } + var i = 0; + i += AotConfig.RegisterSerializers(); + AotConfig.RegisterElement(); + AotConfig.RegisterElement(); + return i; + } - [MonoTouch.Foundation.Preserve] - internal static void RegisterSerializers() + /// + /// Class contains Ahead-of-Time (AOT) explicit class declarations which is used only to workaround "-aot-only" exceptions occured on device only. + /// + [MonoTouch.Foundation.Preserve(AllMembers=true)] + internal class AotConfig { - Register(JsonTypeSerializer.Instance); - Register(JsvTypeSerializer.Instance); - RegisterCsvSerializer(); - RegisterQueryStringWriter(); - } + internal static JsReader jsonReader; + internal static JsWriter jsonWriter; + internal static JsReader jsvReader; + internal static JsWriter jsvWriter; + internal static JsonTypeSerializer jsonSerializer; + internal static JsvTypeSerializer jsvSerializer; + + static AotConfig() + { + jsonSerializer = new JsonTypeSerializer(); + jsvSerializer = new JsvTypeSerializer(); + jsonReader = new JsReader(); + jsonWriter = new JsWriter(); + jsvReader = new JsReader(); + jsvWriter = new JsWriter(); + } + + internal static int RegisterSerializers() + { + var i = 0; + i += Register(); + if (jsonSerializer.GetParseFn() != null) i++; + if (jsonSerializer.GetWriteFn() != null) i++; + if (jsonReader.GetParseFn() != null) i++; + if (jsonWriter.GetWriteFn() != null) i++; + + i += Register(); + if (jsvSerializer.GetParseFn() != null) i++; + if (jsvSerializer.GetWriteFn() != null) i++; + if (jsvReader.GetParseFn() != null) i++; + if (jsvWriter.GetWriteFn() != null) i++; + + + //RegisterCsvSerializer(); + RegisterQueryStringWriter(); + return i; + } + internal static void RegisterCsvSerializer() + { + CsvSerializer.WriteFn(); + CsvSerializer.WriteObject(null, null); + CsvWriter.Write(null, default(IEnumerable)); + CsvWriter.WriteRow(null, default(T)); + } - [MonoTouch.Foundation.Preserve] - internal static void RegisterElement() - { - RegisterSerializers(); - RegisterElement(); - RegisterElement(); - } + public static ParseStringDelegate GetParseFn(Type type) + { + var parseFn = JsonTypeSerializer.Instance.GetParseFn(type); + return parseFn; + } - [MonoTouch.Foundation.Preserve] - internal static void Register(ITypeSerializer serializer) where TSerializer : ITypeSerializer - { - var i = 0; - if (JsonWriter.WriteFn() != null) i++; - if (JsonWriter.Instance.GetWriteFn() != null) i++; - if (JsonReader.Parse(null) != null) i++; - if (JsonReader.GetParseFn() != null) i++; - //if (JsWriter.GetTypeSerializer().GetWriteFn() != null) i++; - if (new List() != null) i++; - if (new T[0] != null) i++; - if (serializer.GetParseFn() != null) i++; - if (serializer.GetWriteFn() != null) i++; - if (DeserializeArray.Parse != null) i++; - - JsConfig.ExcludeTypeInfo = false; - if (JsConfig.SerializeFn != null) i++; - //JsConfig.SerializeFn = arg => ""; - //JsConfig.DeSerializeFn = arg => default(T); - if (WriteType.Write != null) i++; - DeserializeArrayWithElements.ParseGenericArray(null, null); - DeserializeCollection.ParseCollection(null, null, null); - DeserializeListWithElements.ParseGenericList(null, null, null); - - SpecializedQueueElements.ConvertToQueue(null); - SpecializedQueueElements.ConvertToStack(null); - - WriteListsOfElements.WriteList(null, null); - WriteListsOfElements.WriteIList(null, null); - WriteListsOfElements.WriteEnumerable(null, null); - WriteListsOfElements.WriteListValueType(null, null); - WriteListsOfElements.WriteIListValueType(null, null); - WriteListsOfElements.WriteIListValueType(null, null); - WriteListsOfElements.WriteGenericArrayValueType(null, null); - - JsonReader.Parse(null); - - TranslateListWithElements.LateBoundTranslateToGenericICollection(null, null); - TranslateListWithConvertibleElements.LateBoundTranslateToGenericICollection(null, null); - - QueryStringWriter.WriteObject(null, null); - } + internal static int Register() where TSerializer : ITypeSerializer + { + var i = 0; + + if (JsonWriter.WriteFn() != null) i++; + if (JsonWriter.Instance.GetWriteFn() != null) i++; + if (JsonReader.Instance.GetParseFn() != null) i++; + if (JsonReader.Parse(null) != null) i++; + if (JsonReader.GetParseFn() != null) i++; + //if (JsWriter.GetTypeSerializer().GetWriteFn() != null) i++; + if (new List() != null) i++; + if (new T[0] != null) i++; + + JsConfig.ExcludeTypeInfo = false; + + if (JsConfig.OnDeserializedFn != null) i++; + if (JsConfig.HasDeserializeFn) i++; + if (JsConfig.SerializeFn != null) i++; + if (JsConfig.DeSerializeFn != null) i++; + //JsConfig.SerializeFn = arg => ""; + //JsConfig.DeSerializeFn = arg => default(T); + if (TypeConfig.Properties != null) i++; + +/* + if (WriteType.Write != null) i++; + if (WriteType.Write != null) i++; + + if (DeserializeBuiltin.Parse != null) i++; + if (DeserializeArray.Parse != null) i++; + DeserializeType.ExtractType(null); + DeserializeArrayWithElements.ParseGenericArray(null, null); + DeserializeCollection.ParseCollection(null, null, null); + DeserializeListWithElements.ParseGenericList(null, null, null); + + SpecializedQueueElements.ConvertToQueue(null); + SpecializedQueueElements.ConvertToStack(null); +*/ + + WriteListsOfElements.WriteList(null, null); + WriteListsOfElements.WriteIList(null, null); + WriteListsOfElements.WriteEnumerable(null, null); + WriteListsOfElements.WriteListValueType(null, null); + WriteListsOfElements.WriteIListValueType(null, null); + WriteListsOfElements.WriteGenericArrayValueType(null, null); + WriteListsOfElements.WriteArray(null, null); + + TranslateListWithElements.LateBoundTranslateToGenericICollection(null, null); + TranslateListWithConvertibleElements.LateBoundTranslateToGenericICollection(null, null); + + QueryStringWriter.WriteObject(null, null); + return i; + } - static void RegisterElement() where TSerializer : ITypeSerializer - { - DeserializeDictionary.ParseDictionary(null, null, null, null); - DeserializeDictionary.ParseDictionary(null, null, null, null); - - ToStringDictionaryMethods.WriteIDictionary(null, null, null, null); - ToStringDictionaryMethods.WriteIDictionary(null, null, null, null); - - // Include List deserialisations from the Register<> method above. This solves issue where List properties on responses deserialise to null. - // No idea why this is happening because there is no visible exception raised. Suspect MonoTouch is swallowing an AOT exception somewhere. - DeserializeArrayWithElements.ParseGenericArray(null, null); - DeserializeListWithElements.ParseGenericList(null, null, null); - - // Cannot use the line below for some unknown reason - when trying to compile to run on device, mtouch bombs during native code compile. - // Something about this line or its inner workings is offensive to mtouch. Luckily this was not needed for my List issue. - // DeserializeCollection.ParseCollection(null, null, null); - - TranslateListWithElements.LateBoundTranslateToGenericICollection(null, typeof(List)); - TranslateListWithConvertibleElements.LateBoundTranslateToGenericICollection(null, typeof(List)); + internal static void RegisterElement() where TSerializer : ITypeSerializer + { + DeserializeDictionary.ParseDictionary(null, null, null, null); + DeserializeDictionary.ParseDictionary(null, null, null, null); + + ToStringDictionaryMethods.WriteIDictionary(null, null, null, null); + ToStringDictionaryMethods.WriteIDictionary(null, null, null, null); + + // Include List deserialisations from the Register<> method above. This solves issue where List properties on responses deserialise to null. + // No idea why this is happening because there is no visible exception raised. Suspect MonoTouch is swallowing an AOT exception somewhere. + DeserializeArrayWithElements.ParseGenericArray(null, null); + DeserializeListWithElements.ParseGenericList(null, null, null); + + // Cannot use the line below for some unknown reason - when trying to compile to run on device, mtouch bombs during native code compile. + // Something about this line or its inner workings is offensive to mtouch. Luckily this was not needed for my List issue. + // DeserializeCollection.ParseCollection(null, null, null); + + TranslateListWithElements.LateBoundTranslateToGenericICollection(null, typeof(List)); + TranslateListWithConvertibleElements.LateBoundTranslateToGenericICollection(null, typeof(List)); + } } #endif diff --git a/tests/ServiceStack.Text.Tests.MonoTouch/Aot.cs b/tests/ServiceStack.Text.Tests.MonoTouch/Aot.cs index cba58fa84..7b119e6f4 100644 --- a/tests/ServiceStack.Text.Tests.MonoTouch/Aot.cs +++ b/tests/ServiceStack.Text.Tests.MonoTouch/Aot.cs @@ -4,13 +4,18 @@ namespace ServiceStack.Text.Tests { - public class Aot + public static class Aot { public static void Init () { JsConfig.RegisterForAot (); + JsConfig.RegisterTypeForAot (); + + JsConfig.RegisterTypeForAot> (); JsConfig.RegisterTypeForAot> (); + + JsConfig.RegisterTypeForAot> (); JsConfig.RegisterTypeForAot> (); } } diff --git a/tests/ServiceStack.Text.Tests.MonoTouch/Info.plist b/tests/ServiceStack.Text.Tests.MonoTouch/Info.plist index 8653860cf..4d114089c 100644 --- a/tests/ServiceStack.Text.Tests.MonoTouch/Info.plist +++ b/tests/ServiceStack.Text.Tests.MonoTouch/Info.plist @@ -2,6 +2,8 @@ + MinimumOSVersion + 3.2 UIDeviceFamily 1 @@ -20,7 +22,5 @@ UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight - MinimumOSVersion - 3.2 diff --git a/tests/ServiceStack.Text.Tests.MonoTouch/ServiceStack.Text.Tests.MonoTouch.csproj b/tests/ServiceStack.Text.Tests.MonoTouch/ServiceStack.Text.Tests.MonoTouch.csproj index 2c622f70f..e89754d68 100644 --- a/tests/ServiceStack.Text.Tests.MonoTouch/ServiceStack.Text.Tests.MonoTouch.csproj +++ b/tests/ServiceStack.Text.Tests.MonoTouch/ServiceStack.Text.Tests.MonoTouch.csproj @@ -48,6 +48,8 @@ True True + ARMv6 + -aot "ntrampolines=2048" -aot "nrgctx-trampolines=2048" -aot "nimt-trampolines=1024" -nosymbolstrip -nostrip none @@ -58,6 +60,10 @@ False iPhone Developer MONOTOUCH + + ARMv6 + + -aot "ntrampolines=2048" -aot "nrgctx-trampolines=2048" -aot "nimt-trampolines=1024" -nosymbolstrip -nostrip none @@ -68,6 +74,8 @@ False True iPhone Distribution + + ARMv6 none @@ -77,6 +85,8 @@ 4 False iPhone Distribution + + ARMv6 diff --git a/tests/ServiceStack.Text.Tests/DictionaryTests.cs b/tests/ServiceStack.Text.Tests/DictionaryTests.cs index b35b90e24..06e89b4b8 100644 --- a/tests/ServiceStack.Text.Tests/DictionaryTests.cs +++ b/tests/ServiceStack.Text.Tests/DictionaryTests.cs @@ -10,6 +10,26 @@ namespace ServiceStack.Text.Tests public class DictionaryTests : TestBase { + [TestFixtureSetUp] + public void SetUp() + { +#if MONOTOUCH + JsConfig.RegisterTypeForAot> (); + JsConfig.RegisterTypeForAot> (); + + JsConfig.RegisterTypeForAot> (); + JsConfig.RegisterTypeForAot> (); + + JsConfig.RegisterTypeForAot>> (); + JsConfig.RegisterTypeForAot>> (); + + JsConfig.RegisterTypeForAot>> (); + JsConfig.RegisterTypeForAot>> (); + + +#endif + } + [TearDown] public void TearDown() { diff --git a/tests/ServiceStack.Text.Tests/StructTests.cs b/tests/ServiceStack.Text.Tests/StructTests.cs index 804bf04e0..a6b2b681d 100644 --- a/tests/ServiceStack.Text.Tests/StructTests.cs +++ b/tests/ServiceStack.Text.Tests/StructTests.cs @@ -51,6 +51,26 @@ public override string ToString() } } + [TestFixtureSetUp] + public void SetUp() + { +#if MONOTOUCH + JsConfig.RegisterTypeForAot (); + JsConfig.RegisterTypeForAot (); + JsConfig.RegisterTypeForAot (); + JsConfig.RegisterTypeForAot (); + JsConfig.RegisterTypeForAot (); + JsConfig.RegisterTypeForAot> (); + JsConfig.RegisterTypeForAot (); +#endif + } + + [TearDown] + public void TearDown() + { + JsConfig.Reset(); + } + [Test] public void Test_structs() {