Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(279)

Side by Side Diff: runtime/vm/snapshot_test.cc

Issue 2481873005: clang-format runtime/vm (Closed)
Patch Set: Merge Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « runtime/vm/snapshot_ids.h ('k') | runtime/vm/source_report.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "platform/globals.h" 5 #include "platform/globals.h"
6 6
7 #include "include/dart_tools_api.h" 7 #include "include/dart_tools_api.h"
8 #include "platform/assert.h" 8 #include "platform/assert.h"
9 #include "vm/class_finalizer.h" 9 #include "vm/class_finalizer.h"
10 #include "vm/clustered_snapshot.h" 10 #include "vm/clustered_snapshot.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 if (expected.IsBool()) { 43 if (expected.IsBool()) {
44 if (actual.IsBool()) { 44 if (actual.IsBool()) {
45 return expected.raw() == actual.raw(); 45 return expected.raw() == actual.raw();
46 } 46 }
47 return false; 47 return false;
48 } 48 }
49 return false; 49 return false;
50 } 50 }
51 51
52 52
53 static uint8_t* malloc_allocator( 53 static uint8_t* malloc_allocator(uint8_t* ptr,
54 uint8_t* ptr, intptr_t old_size, intptr_t new_size) { 54 intptr_t old_size,
55 intptr_t new_size) {
55 return reinterpret_cast<uint8_t*>(realloc(ptr, new_size)); 56 return reinterpret_cast<uint8_t*>(realloc(ptr, new_size));
56 } 57 }
57 58
58 59
59 static uint8_t* zone_allocator( 60 static uint8_t* zone_allocator(uint8_t* ptr,
60 uint8_t* ptr, intptr_t old_size, intptr_t new_size) { 61 intptr_t old_size,
62 intptr_t new_size) {
61 Zone* zone = Thread::Current()->zone(); 63 Zone* zone = Thread::Current()->zone();
62 return zone->Realloc<uint8_t>(ptr, old_size, new_size); 64 return zone->Realloc<uint8_t>(ptr, old_size, new_size);
63 } 65 }
64 66
65 67
66 // Compare two Dart_CObject object graphs rooted in first and 68 // Compare two Dart_CObject object graphs rooted in first and
67 // second. The second graph will be destroyed by this operation no matter 69 // second. The second graph will be destroyed by this operation no matter
68 // whether the graphs are equal or not. 70 // whether the graphs are equal or not.
69 static void CompareDartCObjects(Dart_CObject* first, Dart_CObject* second) { 71 static void CompareDartCObjects(Dart_CObject* first, Dart_CObject* second) {
70 // Return immediately if entering a cycle. 72 // Return immediately if entering a cycle.
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 } 253 }
252 254
253 255
254 void CheckMint(int64_t value) { 256 void CheckMint(int64_t value) {
255 ApiNativeScope scope; 257 ApiNativeScope scope;
256 StackZone zone(Thread::Current()); 258 StackZone zone(Thread::Current());
257 259
258 Mint& mint = Mint::Handle(); 260 Mint& mint = Mint::Handle();
259 mint ^= Integer::New(value); 261 mint ^= Integer::New(value);
260 Dart_CObject* mint_cobject = SerializeAndDeserializeMint(mint); 262 Dart_CObject* mint_cobject = SerializeAndDeserializeMint(mint);
261 // On 64-bit platforms mints always require 64-bits as the smi range 263 // On 64-bit platforms mints always require 64-bits as the smi range
262 // here covers most of the 64-bit range. On 32-bit platforms the smi 264 // here covers most of the 64-bit range. On 32-bit platforms the smi
263 // range covers most of the 32-bit range and values outside that 265 // range covers most of the 32-bit range and values outside that
264 // range are also represented as mints. 266 // range are also represented as mints.
265 #if defined(ARCH_IS_64_BIT) 267 #if defined(ARCH_IS_64_BIT)
266 EXPECT_EQ(Dart_CObject_kInt64, mint_cobject->type); 268 EXPECT_EQ(Dart_CObject_kInt64, mint_cobject->type);
267 EXPECT_EQ(value, mint_cobject->value.as_int64); 269 EXPECT_EQ(value, mint_cobject->value.as_int64);
268 #else 270 #else
269 if (kMinInt32 < value && value < kMaxInt32) { 271 if (kMinInt32 < value && value < kMaxInt32) {
270 EXPECT_EQ(Dart_CObject_kInt32, mint_cobject->type); 272 EXPECT_EQ(Dart_CObject_kInt32, mint_cobject->type);
271 EXPECT_EQ(value, mint_cobject->value.as_int32); 273 EXPECT_EQ(value, mint_cobject->value.as_int32);
272 } else { 274 } else {
273 EXPECT_EQ(Dart_CObject_kInt64, mint_cobject->type); 275 EXPECT_EQ(Dart_CObject_kInt64, mint_cobject->type);
274 EXPECT_EQ(value, mint_cobject->value.as_int64); 276 EXPECT_EQ(value, mint_cobject->value.as_int64);
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
550 Dart_CObject* root = api_reader.ReadMessage(); 552 Dart_CObject* root = api_reader.ReadMessage();
551 EXPECT_EQ(Dart_CObject_kString, root->type); 553 EXPECT_EQ(Dart_CObject_kString, root->type);
552 EXPECT_STREQ(cstr, root->value.as_string); 554 EXPECT_STREQ(cstr, root->value.as_string);
553 CheckEncodeDecodeMessage(root); 555 CheckEncodeDecodeMessage(root);
554 } 556 }
555 557
556 558
557 TEST_CASE(SerializeString) { 559 TEST_CASE(SerializeString) {
558 TestString("This string shall be serialized"); 560 TestString("This string shall be serialized");
559 TestString("æøå"); // This file is UTF-8 encoded. 561 TestString("æøå"); // This file is UTF-8 encoded.
560 const char* data = "\x01" 562 const char* data =
561 "\x7F" 563 "\x01"
562 "\xC2\x80" // U+0080 564 "\x7F"
563 "\xDF\xBF" // U+07FF 565 "\xC2\x80" // U+0080
564 "\xE0\xA0\x80" // U+0800 566 "\xDF\xBF" // U+07FF
565 "\xEF\xBF\xBF"; // U+FFFF 567 "\xE0\xA0\x80" // U+0800
568 "\xEF\xBF\xBF"; // U+FFFF
566 569
567 TestString(data); 570 TestString(data);
568 // TODO(sgjesse): Add tests with non-BMP characters. 571 // TODO(sgjesse): Add tests with non-BMP characters.
569 } 572 }
570 573
571 574
572 TEST_CASE(SerializeArray) { 575 TEST_CASE(SerializeArray) {
573 // Write snapshot with object content. 576 // Write snapshot with object content.
574 const int kArrayLength = 10; 577 const int kArrayLength = 10;
575 Array& array = Array::Handle(Array::New(kArrayLength)); 578 Array& array = Array::Handle(Array::New(kArrayLength));
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
609 root.type = Dart_CObject_kArray; 612 root.type = Dart_CObject_kArray;
610 root.value.as_array.length = Array::kMaxElements + 1; 613 root.value.as_array.length = Array::kMaxElements + 1;
611 root.value.as_array.values = NULL; 614 root.value.as_array.values = NULL;
612 ExpectEncodeFail(&root); 615 ExpectEncodeFail(&root);
613 } 616 }
614 617
615 618
616 TEST_CASE(FailSerializeLargeNestedArray) { 619 TEST_CASE(FailSerializeLargeNestedArray) {
617 Dart_CObject parent; 620 Dart_CObject parent;
618 Dart_CObject child; 621 Dart_CObject child;
619 Dart_CObject* values[1] = { &child }; 622 Dart_CObject* values[1] = {&child};
620 623
621 parent.type = Dart_CObject_kArray; 624 parent.type = Dart_CObject_kArray;
622 parent.value.as_array.length = 1; 625 parent.value.as_array.length = 1;
623 parent.value.as_array.values = values; 626 parent.value.as_array.values = values;
624 child.type = Dart_CObject_kArray; 627 child.type = Dart_CObject_kArray;
625 child.value.as_array.length = Array::kMaxElements + 1; 628 child.value.as_array.length = Array::kMaxElements + 1;
626 ExpectEncodeFail(&parent); 629 ExpectEncodeFail(&parent);
627 } 630 }
628 631
629 632
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
726 } \ 729 } \
727 uint8_t* buffer; \ 730 uint8_t* buffer; \
728 MessageWriter writer(&buffer, &zone_allocator, true); \ 731 MessageWriter writer(&buffer, &zone_allocator, true); \
729 writer.WriteMessage(array); \ 732 writer.WriteMessage(array); \
730 intptr_t buffer_len = writer.BytesWritten(); \ 733 intptr_t buffer_len = writer.BytesWritten(); \
731 MessageSnapshotReader reader(buffer, buffer_len, thread); \ 734 MessageSnapshotReader reader(buffer, buffer_len, thread); \
732 TypedData& serialized_array = TypedData::Handle(); \ 735 TypedData& serialized_array = TypedData::Handle(); \
733 serialized_array ^= reader.ReadObject(); \ 736 serialized_array ^= reader.ReadObject(); \
734 for (int i = 0; i < kArrayLength; i++) { \ 737 for (int i = 0; i < kArrayLength; i++) { \
735 EXPECT_EQ(static_cast<ctype>(i), \ 738 EXPECT_EQ(static_cast<ctype>(i), \
736 serialized_array.Get##darttype(i*scale)); \ 739 serialized_array.Get##darttype(i* scale)); \
737 } \ 740 } \
738 } 741 }
739 742
740 743
741 #define TEST_EXTERNAL_TYPED_ARRAY(darttype, ctype) \ 744 #define TEST_EXTERNAL_TYPED_ARRAY(darttype, ctype) \
742 { \ 745 { \
743 StackZone zone(thread); \ 746 StackZone zone(thread); \
744 ctype data[] = { 0, 11, 22, 33, 44, 55, 66, 77 }; \ 747 ctype data[] = {0, 11, 22, 33, 44, 55, 66, 77}; \
745 intptr_t length = ARRAY_SIZE(data); \ 748 intptr_t length = ARRAY_SIZE(data); \
746 ExternalTypedData& array = ExternalTypedData::Handle( \ 749 ExternalTypedData& array = ExternalTypedData::Handle( \
747 ExternalTypedData::New(kExternalTypedData##darttype##ArrayCid, \ 750 ExternalTypedData::New(kExternalTypedData##darttype##ArrayCid, \
748 reinterpret_cast<uint8_t*>(data), length)); \ 751 reinterpret_cast<uint8_t*>(data), length)); \
749 intptr_t scale = array.ElementSizeInBytes(); \ 752 intptr_t scale = array.ElementSizeInBytes(); \
750 uint8_t* buffer; \ 753 uint8_t* buffer; \
751 MessageWriter writer(&buffer, &zone_allocator, true); \ 754 MessageWriter writer(&buffer, &zone_allocator, true); \
752 writer.WriteMessage(array); \ 755 writer.WriteMessage(array); \
753 intptr_t buffer_len = writer.BytesWritten(); \ 756 intptr_t buffer_len = writer.BytesWritten(); \
754 MessageSnapshotReader reader(buffer, buffer_len, thread); \ 757 MessageSnapshotReader reader(buffer, buffer_len, thread); \
755 TypedData& serialized_array = TypedData::Handle(); \ 758 TypedData& serialized_array = TypedData::Handle(); \
756 serialized_array ^= reader.ReadObject(); \ 759 serialized_array ^= reader.ReadObject(); \
757 for (int i = 0; i < length; i++) { \ 760 for (int i = 0; i < length; i++) { \
758 EXPECT_EQ(static_cast<ctype>(data[i]), \ 761 EXPECT_EQ(static_cast<ctype>(data[i]), \
759 serialized_array.Get##darttype(i*scale)); \ 762 serialized_array.Get##darttype(i* scale)); \
760 } \ 763 } \
761 } 764 }
762 765
763 766
764 TEST_CASE(SerializeTypedArray) { 767 TEST_CASE(SerializeTypedArray) {
765 TEST_TYPED_ARRAY(Int8, int8_t); 768 TEST_TYPED_ARRAY(Int8, int8_t);
766 TEST_TYPED_ARRAY(Uint8, uint8_t); 769 TEST_TYPED_ARRAY(Uint8, uint8_t);
767 TEST_TYPED_ARRAY(Int16, int16_t); 770 TEST_TYPED_ARRAY(Int16, int16_t);
768 TEST_TYPED_ARRAY(Uint16, uint16_t); 771 TEST_TYPED_ARRAY(Uint16, uint16_t);
769 TEST_TYPED_ARRAY(Int32, int32_t); 772 TEST_TYPED_ARRAY(Int32, int32_t);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
825 Snapshot::kScript, 828 Snapshot::kScript,
826 buffer, 829 buffer,
827 alloc, 830 alloc,
828 kInitialSize, 831 kInitialSize,
829 &forward_list_, 832 &forward_list_,
830 true /* can_send_any_object */), 833 true /* can_send_any_object */),
831 forward_list_(thread(), kMaxPredefinedObjectIds) { 834 forward_list_(thread(), kMaxPredefinedObjectIds) {
832 ASSERT(buffer != NULL); 835 ASSERT(buffer != NULL);
833 ASSERT(alloc != NULL); 836 ASSERT(alloc != NULL);
834 } 837 }
835 ~TestSnapshotWriter() { } 838 ~TestSnapshotWriter() {}
836 839
837 // Writes just a script object 840 // Writes just a script object
838 void WriteScript(const Script& script) { 841 void WriteScript(const Script& script) { WriteObject(script.raw()); }
839 WriteObject(script.raw());
840 }
841 842
842 private: 843 private:
843 ForwardList forward_list_; 844 ForwardList forward_list_;
844 845
845 DISALLOW_COPY_AND_ASSIGN(TestSnapshotWriter); 846 DISALLOW_COPY_AND_ASSIGN(TestSnapshotWriter);
846 }; 847 };
847 848
848 849
849 static void GenerateSourceAndCheck(const Script& script) { 850 static void GenerateSourceAndCheck(const Script& script) {
850 // Check if we are able to generate the source from the token stream. 851 // Check if we are able to generate the source from the token stream.
851 // Rescan this source and compare the token stream to see if they are 852 // Rescan this source and compare the token stream to see if they are
852 // the same. 853 // the same.
853 Zone* zone = Thread::Current()->zone(); 854 Zone* zone = Thread::Current()->zone();
854 const TokenStream& expected_tokens = 855 const TokenStream& expected_tokens =
855 TokenStream::Handle(zone, script.tokens()); 856 TokenStream::Handle(zone, script.tokens());
856 TokenStream::Iterator expected_iterator( 857 TokenStream::Iterator expected_iterator(zone, expected_tokens,
857 zone, 858 TokenPosition::kMinSource,
858 expected_tokens, 859 TokenStream::Iterator::kAllTokens);
859 TokenPosition::kMinSource,
860 TokenStream::Iterator::kAllTokens);
861 const String& str = String::Handle(zone, expected_tokens.GenerateSource()); 860 const String& str = String::Handle(zone, expected_tokens.GenerateSource());
862 const String& private_key = 861 const String& private_key =
863 String::Handle(zone, expected_tokens.PrivateKey()); 862 String::Handle(zone, expected_tokens.PrivateKey());
864 const TokenStream& reconstructed_tokens = 863 const TokenStream& reconstructed_tokens =
865 TokenStream::Handle(zone, TokenStream::New(str, 864 TokenStream::Handle(zone, TokenStream::New(str, private_key, false));
866 private_key,
867 false));
868 expected_iterator.SetCurrentPosition(TokenPosition::kMinSource); 865 expected_iterator.SetCurrentPosition(TokenPosition::kMinSource);
869 TokenStream::Iterator reconstructed_iterator( 866 TokenStream::Iterator reconstructed_iterator(
870 zone, 867 zone, reconstructed_tokens, TokenPosition::kMinSource,
871 reconstructed_tokens,
872 TokenPosition::kMinSource,
873 TokenStream::Iterator::kAllTokens); 868 TokenStream::Iterator::kAllTokens);
874 Token::Kind expected_kind = expected_iterator.CurrentTokenKind(); 869 Token::Kind expected_kind = expected_iterator.CurrentTokenKind();
875 Token::Kind reconstructed_kind = reconstructed_iterator.CurrentTokenKind(); 870 Token::Kind reconstructed_kind = reconstructed_iterator.CurrentTokenKind();
876 String& expected_literal = String::Handle(zone); 871 String& expected_literal = String::Handle(zone);
877 String& actual_literal = String::Handle(zone); 872 String& actual_literal = String::Handle(zone);
878 while (expected_kind != Token::kEOS && reconstructed_kind != Token::kEOS) { 873 while (expected_kind != Token::kEOS && reconstructed_kind != Token::kEOS) {
879 EXPECT_EQ(expected_kind, reconstructed_kind); 874 EXPECT_EQ(expected_kind, reconstructed_kind);
880 expected_literal ^= expected_iterator.CurrentLiteral(); 875 expected_literal ^= expected_iterator.CurrentLiteral();
881 actual_literal ^= reconstructed_iterator.CurrentLiteral(); 876 actual_literal ^= reconstructed_iterator.CurrentLiteral();
882 EXPECT_STREQ(expected_literal.ToCString(), actual_literal.ToCString()); 877 EXPECT_STREQ(expected_literal.ToCString(), actual_literal.ToCString());
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
928 "g h i''';\n" 923 "g h i''';\n"
929 " }\n" 924 " }\n"
930 " static ms6() {\n" 925 " static ms6() {\n"
931 " return '\\t \\n \\x00 \\xFF';\n" 926 " return '\\t \\n \\x00 \\xFF';\n"
932 " }\n" 927 " }\n"
933 "}\n"; 928 "}\n";
934 929
935 Zone* zone = thread->zone(); 930 Zone* zone = thread->zone();
936 String& url = String::Handle(zone, String::New("dart-test:SerializeScript")); 931 String& url = String::Handle(zone, String::New("dart-test:SerializeScript"));
937 String& source = String::Handle(zone, String::New(kScriptChars)); 932 String& source = String::Handle(zone, String::New(kScriptChars));
938 Script& script = Script::Handle(zone, Script::New(url, 933 Script& script =
939 source, 934 Script::Handle(zone, Script::New(url, source, RawScript::kScriptTag));
940 RawScript::kScriptTag));
941 const String& lib_url = String::Handle(zone, Symbols::New(thread, "TestLib")); 935 const String& lib_url = String::Handle(zone, Symbols::New(thread, "TestLib"));
942 Library& lib = Library::Handle(zone, Library::New(lib_url)); 936 Library& lib = Library::Handle(zone, Library::New(lib_url));
943 lib.Register(thread); 937 lib.Register(thread);
944 EXPECT(CompilerTest::TestCompileScript(lib, script)); 938 EXPECT(CompilerTest::TestCompileScript(lib, script));
945 939
946 // Write snapshot with script content. 940 // Write snapshot with script content.
947 uint8_t* buffer; 941 uint8_t* buffer;
948 TestSnapshotWriter writer(&buffer, &malloc_allocator); 942 TestSnapshotWriter writer(&buffer, &malloc_allocator);
949 writer.WriteScript(script); 943 writer.WriteScript(script);
950 944
(...skipping 11 matching lines...) Expand all
962 956
963 const TokenStream& expected_tokens = 957 const TokenStream& expected_tokens =
964 TokenStream::Handle(zone, script.tokens()); 958 TokenStream::Handle(zone, script.tokens());
965 const TokenStream& serialized_tokens = 959 const TokenStream& serialized_tokens =
966 TokenStream::Handle(zone, serialized_script.tokens()); 960 TokenStream::Handle(zone, serialized_script.tokens());
967 const ExternalTypedData& expected_data = 961 const ExternalTypedData& expected_data =
968 ExternalTypedData::Handle(zone, expected_tokens.GetStream()); 962 ExternalTypedData::Handle(zone, expected_tokens.GetStream());
969 const ExternalTypedData& serialized_data = 963 const ExternalTypedData& serialized_data =
970 ExternalTypedData::Handle(zone, serialized_tokens.GetStream()); 964 ExternalTypedData::Handle(zone, serialized_tokens.GetStream());
971 EXPECT_EQ(expected_data.Length(), serialized_data.Length()); 965 EXPECT_EQ(expected_data.Length(), serialized_data.Length());
972 TokenStream::Iterator expected_iterator(zone, 966 TokenStream::Iterator expected_iterator(zone, expected_tokens,
973 expected_tokens,
974 TokenPosition::kMinSource); 967 TokenPosition::kMinSource);
975 TokenStream::Iterator serialized_iterator(zone, 968 TokenStream::Iterator serialized_iterator(zone, serialized_tokens,
976 serialized_tokens,
977 TokenPosition::kMinSource); 969 TokenPosition::kMinSource);
978 Token::Kind expected_kind = expected_iterator.CurrentTokenKind(); 970 Token::Kind expected_kind = expected_iterator.CurrentTokenKind();
979 Token::Kind serialized_kind = serialized_iterator.CurrentTokenKind(); 971 Token::Kind serialized_kind = serialized_iterator.CurrentTokenKind();
980 while (expected_kind != Token::kEOS && serialized_kind != Token::kEOS) { 972 while (expected_kind != Token::kEOS && serialized_kind != Token::kEOS) {
981 EXPECT_EQ(expected_kind, serialized_kind); 973 EXPECT_EQ(expected_kind, serialized_kind);
982 expected_literal ^= expected_iterator.CurrentLiteral(); 974 expected_literal ^= expected_iterator.CurrentLiteral();
983 actual_literal ^= serialized_iterator.CurrentLiteral(); 975 actual_literal ^= serialized_iterator.CurrentLiteral();
984 EXPECT(expected_literal.Equals(actual_literal)); 976 EXPECT(expected_literal.Equals(actual_literal));
985 expected_iterator.Advance(); 977 expected_iterator.Advance();
986 serialized_iterator.Advance(); 978 serialized_iterator.Advance();
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1027 uint8_t* script_snapshot = NULL; 1019 uint8_t* script_snapshot = NULL;
1028 1020
1029 bool saved_load_deferred_eagerly_mode = FLAG_load_deferred_eagerly; 1021 bool saved_load_deferred_eagerly_mode = FLAG_load_deferred_eagerly;
1030 FLAG_load_deferred_eagerly = true; 1022 FLAG_load_deferred_eagerly = true;
1031 { 1023 {
1032 // Start an Isolate, and create a full snapshot of it. 1024 // Start an Isolate, and create a full snapshot of it.
1033 TestIsolateScope __test_isolate__; 1025 TestIsolateScope __test_isolate__;
1034 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. 1026 Dart_EnterScope(); // Start a Dart API scope for invoking API functions.
1035 1027
1036 // Write out the script snapshot. 1028 // Write out the script snapshot.
1037 result = Dart_CreateSnapshot(NULL, 1029 result = Dart_CreateSnapshot(NULL, &vm_isolate_snapshot_size,
1038 &vm_isolate_snapshot_size, 1030 &isolate_snapshot, &isolate_snapshot_size);
1039 &isolate_snapshot,
1040 &isolate_snapshot_size);
1041 EXPECT_VALID(result); 1031 EXPECT_VALID(result);
1042 full_snapshot = reinterpret_cast<uint8_t*>(malloc(isolate_snapshot_size)); 1032 full_snapshot = reinterpret_cast<uint8_t*>(malloc(isolate_snapshot_size));
1043 memmove(full_snapshot, isolate_snapshot, isolate_snapshot_size); 1033 memmove(full_snapshot, isolate_snapshot, isolate_snapshot_size);
1044 Dart_ExitScope(); 1034 Dart_ExitScope();
1045 } 1035 }
1046 FLAG_load_deferred_eagerly = saved_load_deferred_eagerly_mode; 1036 FLAG_load_deferred_eagerly = saved_load_deferred_eagerly_mode;
1047 1037
1048 { 1038 {
1049 // Now Create an Isolate using the full snapshot and load the 1039 // Now Create an Isolate using the full snapshot and load the
1050 // script and execute it. 1040 // script and execute it.
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
1115 EXPECT(!script.IsNull()); 1105 EXPECT(!script.IsNull());
1116 uri = script.url(); 1106 uri = script.url();
1117 OS::Print("Generating source for part: %s\n", uri.ToCString()); 1107 OS::Print("Generating source for part: %s\n", uri.ToCString());
1118 GenerateSourceAndCheck(script); 1108 GenerateSourceAndCheck(script);
1119 } 1109 }
1120 } 1110 }
1121 1111
1122 VM_TEST_CASE(GenerateSource) { 1112 VM_TEST_CASE(GenerateSource) {
1123 Zone* zone = thread->zone(); 1113 Zone* zone = thread->zone();
1124 Isolate* isolate = thread->isolate(); 1114 Isolate* isolate = thread->isolate();
1125 const GrowableObjectArray& libs = GrowableObjectArray::Handle( 1115 const GrowableObjectArray& libs =
1126 zone, isolate->object_store()->libraries()); 1116 GrowableObjectArray::Handle(zone, isolate->object_store()->libraries());
1127 Library& lib = Library::Handle(); 1117 Library& lib = Library::Handle();
1128 String& uri = String::Handle(); 1118 String& uri = String::Handle();
1129 for (intptr_t i = 0; i < libs.Length(); i++) { 1119 for (intptr_t i = 0; i < libs.Length(); i++) {
1130 lib ^= libs.At(i); 1120 lib ^= libs.At(i);
1131 EXPECT(!lib.IsNull()); 1121 EXPECT(!lib.IsNull());
1132 uri = lib.url(); 1122 uri = lib.url();
1133 OS::Print("Generating source for library: %s\n", uri.ToCString()); 1123 OS::Print("Generating source for library: %s\n", uri.ToCString());
1134 IterateScripts(lib); 1124 IterateScripts(lib);
1135 } 1125 }
1136 } 1126 }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1175 HandleScope scope(thread); 1165 HandleScope scope(thread);
1176 1166
1177 // Create a test library and Load up a test script in it. 1167 // Create a test library and Load up a test script in it.
1178 TestCase::LoadTestScript(kScriptChars, NULL); 1168 TestCase::LoadTestScript(kScriptChars, NULL);
1179 EXPECT_VALID(Api::CheckAndFinalizePendingClasses(thread)); 1169 EXPECT_VALID(Api::CheckAndFinalizePendingClasses(thread));
1180 timer1.Stop(); 1170 timer1.Stop();
1181 OS::PrintErr("Without Snapshot: %" Pd64 "us\n", timer1.TotalElapsedTime()); 1171 OS::PrintErr("Without Snapshot: %" Pd64 "us\n", timer1.TotalElapsedTime());
1182 1172
1183 // Write snapshot with object content. 1173 // Write snapshot with object content.
1184 { 1174 {
1185 FullSnapshotWriter writer(Snapshot::kCore, 1175 FullSnapshotWriter writer(Snapshot::kCore, NULL, &isolate_snapshot_buffer,
1186 NULL,
1187 &isolate_snapshot_buffer,
1188 &malloc_allocator, 1176 &malloc_allocator,
1189 NULL /* instructions_writer */); 1177 NULL /* instructions_writer */);
1190 writer.WriteFullSnapshot(); 1178 writer.WriteFullSnapshot();
1191 } 1179 }
1192 } 1180 }
1193 1181
1194 // Now Create another isolate using the snapshot and execute a method 1182 // Now Create another isolate using the snapshot and execute a method
1195 // from the script. 1183 // from the script.
1196 Timer timer2(true, "Snapshot_test"); 1184 Timer timer2(true, "Snapshot_test");
1197 timer2.Start(); 1185 timer2.Start();
1198 TestCase::CreateTestIsolateFromSnapshot(isolate_snapshot_buffer); 1186 TestCase::CreateTestIsolateFromSnapshot(isolate_snapshot_buffer);
1199 { 1187 {
1200 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. 1188 Dart_EnterScope(); // Start a Dart API scope for invoking API functions.
1201 timer2.Stop(); 1189 timer2.Stop();
1202 OS::PrintErr("From Snapshot: %" Pd64 "us\n", timer2.TotalElapsedTime()); 1190 OS::PrintErr("From Snapshot: %" Pd64 "us\n", timer2.TotalElapsedTime());
1203 1191
1204 // Invoke a function which returns an object. 1192 // Invoke a function which returns an object.
1205 Dart_Handle cls = 1193 Dart_Handle cls = Dart_GetClass(TestCase::lib(), NewString("FieldsTest"));
1206 Dart_GetClass(TestCase::lib(), NewString("FieldsTest"));
1207 result = Dart_Invoke(cls, NewString("testMain"), 0, NULL); 1194 result = Dart_Invoke(cls, NewString("testMain"), 0, NULL);
1208 EXPECT_VALID(result); 1195 EXPECT_VALID(result);
1209 Dart_ExitScope(); 1196 Dart_ExitScope();
1210 } 1197 }
1211 Dart_ShutdownIsolate(); 1198 Dart_ShutdownIsolate();
1212 free(isolate_snapshot_buffer); 1199 free(isolate_snapshot_buffer);
1213 } 1200 }
1214 1201
1215 1202
1216 UNIT_TEST_CASE(FullSnapshot1) { 1203 UNIT_TEST_CASE(FullSnapshot1) {
(...skipping 18 matching lines...) Expand all
1235 HandleScope scope(thread); 1222 HandleScope scope(thread);
1236 1223
1237 // Create a test library and Load up a test script in it. 1224 // Create a test library and Load up a test script in it.
1238 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 1225 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
1239 EXPECT_VALID(Api::CheckAndFinalizePendingClasses(thread)); 1226 EXPECT_VALID(Api::CheckAndFinalizePendingClasses(thread));
1240 timer1.Stop(); 1227 timer1.Stop();
1241 OS::PrintErr("Without Snapshot: %" Pd64 "us\n", timer1.TotalElapsedTime()); 1228 OS::PrintErr("Without Snapshot: %" Pd64 "us\n", timer1.TotalElapsedTime());
1242 1229
1243 // Write snapshot with object content. 1230 // Write snapshot with object content.
1244 { 1231 {
1245 FullSnapshotWriter writer(Snapshot::kCore, 1232 FullSnapshotWriter writer(Snapshot::kCore, NULL, &isolate_snapshot_buffer,
1246 NULL,
1247 &isolate_snapshot_buffer,
1248 &malloc_allocator, 1233 &malloc_allocator,
1249 NULL /* instructions_writer */); 1234 NULL /* instructions_writer */);
1250 writer.WriteFullSnapshot(); 1235 writer.WriteFullSnapshot();
1251 } 1236 }
1252 1237
1253 // Invoke a function which returns an object. 1238 // Invoke a function which returns an object.
1254 Dart_Handle cls = Dart_GetClass(lib, NewString("FieldsTest")); 1239 Dart_Handle cls = Dart_GetClass(lib, NewString("FieldsTest"));
1255 Dart_Handle result = Dart_Invoke(cls, NewString("testMain"), 0, NULL); 1240 Dart_Handle result = Dart_Invoke(cls, NewString("testMain"), 0, NULL);
1256 EXPECT_VALID(result); 1241 EXPECT_VALID(result);
1257 } 1242 }
1258 1243
1259 // Now Create another isolate using the snapshot and execute a method 1244 // Now Create another isolate using the snapshot and execute a method
1260 // from the script. 1245 // from the script.
1261 Timer timer2(true, "Snapshot_test"); 1246 Timer timer2(true, "Snapshot_test");
1262 timer2.Start(); 1247 timer2.Start();
1263 TestCase::CreateTestIsolateFromSnapshot(isolate_snapshot_buffer); 1248 TestCase::CreateTestIsolateFromSnapshot(isolate_snapshot_buffer);
1264 { 1249 {
1265 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. 1250 Dart_EnterScope(); // Start a Dart API scope for invoking API functions.
1266 timer2.Stop(); 1251 timer2.Stop();
1267 OS::PrintErr("From Snapshot: %" Pd64 "us\n", timer2.TotalElapsedTime()); 1252 OS::PrintErr("From Snapshot: %" Pd64 "us\n", timer2.TotalElapsedTime());
1268 1253
1269 // Invoke a function which returns an object. 1254 // Invoke a function which returns an object.
1270 Dart_Handle cls = Dart_GetClass(TestCase::lib(), 1255 Dart_Handle cls = Dart_GetClass(TestCase::lib(), NewString("FieldsTest"));
1271 NewString("FieldsTest"));
1272 Dart_Handle result = Dart_Invoke(cls, NewString("testMain"), 0, NULL); 1256 Dart_Handle result = Dart_Invoke(cls, NewString("testMain"), 0, NULL);
1273 if (Dart_IsError(result)) { 1257 if (Dart_IsError(result)) {
1274 // Print the error. It is probably an unhandled exception. 1258 // Print the error. It is probably an unhandled exception.
1275 fprintf(stderr, "%s\n", Dart_GetError(result)); 1259 fprintf(stderr, "%s\n", Dart_GetError(result));
1276 } 1260 }
1277 EXPECT_VALID(result); 1261 EXPECT_VALID(result);
1278 Dart_ExitScope(); 1262 Dart_ExitScope();
1279 } 1263 }
1280 Dart_ShutdownIsolate(); 1264 Dart_ShutdownIsolate();
1281 free(isolate_snapshot_buffer); 1265 free(isolate_snapshot_buffer);
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1340 intptr_t actual_num_libs; 1324 intptr_t actual_num_libs;
1341 1325
1342 bool saved_load_deferred_eagerly_mode = FLAG_load_deferred_eagerly; 1326 bool saved_load_deferred_eagerly_mode = FLAG_load_deferred_eagerly;
1343 FLAG_load_deferred_eagerly = true; 1327 FLAG_load_deferred_eagerly = true;
1344 { 1328 {
1345 // Start an Isolate, and create a full snapshot of it. 1329 // Start an Isolate, and create a full snapshot of it.
1346 TestIsolateScope __test_isolate__; 1330 TestIsolateScope __test_isolate__;
1347 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. 1331 Dart_EnterScope(); // Start a Dart API scope for invoking API functions.
1348 1332
1349 // Write out the script snapshot. 1333 // Write out the script snapshot.
1350 result = Dart_CreateSnapshot(NULL, 1334 result = Dart_CreateSnapshot(NULL, &vm_isolate_snapshot_size,
1351 &vm_isolate_snapshot_size, 1335 &isolate_snapshot, &isolate_snapshot_size);
1352 &isolate_snapshot,
1353 &isolate_snapshot_size);
1354 EXPECT_VALID(result); 1336 EXPECT_VALID(result);
1355 full_snapshot = reinterpret_cast<uint8_t*>(malloc(isolate_snapshot_size)); 1337 full_snapshot = reinterpret_cast<uint8_t*>(malloc(isolate_snapshot_size));
1356 memmove(full_snapshot, isolate_snapshot, isolate_snapshot_size); 1338 memmove(full_snapshot, isolate_snapshot, isolate_snapshot_size);
1357 Dart_ExitScope(); 1339 Dart_ExitScope();
1358 } 1340 }
1359 FLAG_load_deferred_eagerly = saved_load_deferred_eagerly_mode; 1341 FLAG_load_deferred_eagerly = saved_load_deferred_eagerly_mode;
1360 1342
1361 // Test for Dart_CreateScriptSnapshot. 1343 // Test for Dart_CreateScriptSnapshot.
1362 { 1344 {
1363 // Create an Isolate using the full snapshot, load a script and create 1345 // Create an Isolate using the full snapshot, load a script and create
1364 // a script snapshot of the script. 1346 // a script snapshot of the script.
1365 TestCase::CreateTestIsolateFromSnapshot(full_snapshot); 1347 TestCase::CreateTestIsolateFromSnapshot(full_snapshot);
1366 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. 1348 Dart_EnterScope(); // Start a Dart API scope for invoking API functions.
1367 1349
1368 // Load the library. 1350 // Load the library.
1369 Dart_Handle import_lib = Dart_LoadLibrary(NewString("dart_import_lib"), 1351 Dart_Handle import_lib =
1370 Dart_Null(), 1352 Dart_LoadLibrary(NewString("dart_import_lib"), Dart_Null(),
1371 NewString(kLibScriptChars), 1353 NewString(kLibScriptChars), 0, 0);
1372 0, 0);
1373 EXPECT_VALID(import_lib); 1354 EXPECT_VALID(import_lib);
1374 1355
1375 // Create a test library and Load up a test script in it. 1356 // Create a test library and Load up a test script in it.
1376 TestCase::LoadTestScript(kScriptChars, NULL); 1357 TestCase::LoadTestScript(kScriptChars, NULL);
1377 1358
1378 EXPECT_VALID(Dart_LibraryImportLibrary(TestCase::lib(), 1359 EXPECT_VALID(
1379 import_lib, 1360 Dart_LibraryImportLibrary(TestCase::lib(), import_lib, Dart_Null()));
1380 Dart_Null()));
1381 EXPECT_VALID(Api::CheckAndFinalizePendingClasses(Thread::Current())); 1361 EXPECT_VALID(Api::CheckAndFinalizePendingClasses(Thread::Current()));
1382 1362
1383 // Get list of library URLs loaded and save the count. 1363 // Get list of library URLs loaded and save the count.
1384 Dart_Handle libs = Dart_GetLibraryIds(); 1364 Dart_Handle libs = Dart_GetLibraryIds();
1385 EXPECT(Dart_IsList(libs)); 1365 EXPECT(Dart_IsList(libs));
1386 Dart_ListLength(libs, &expected_num_libs); 1366 Dart_ListLength(libs, &expected_num_libs);
1387 1367
1388 // Write out the script snapshot. 1368 // Write out the script snapshot.
1389 result = Dart_CreateScriptSnapshot(&buffer, &size); 1369 result = Dart_CreateScriptSnapshot(&buffer, &size);
1390 EXPECT_VALID(result); 1370 EXPECT_VALID(result);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1422 free(script_snapshot); 1402 free(script_snapshot);
1423 1403
1424 // Test for Dart_CreateLibrarySnapshot. 1404 // Test for Dart_CreateLibrarySnapshot.
1425 { 1405 {
1426 // Create an Isolate using the full snapshot, load a script and create 1406 // Create an Isolate using the full snapshot, load a script and create
1427 // a script snapshot of the script. 1407 // a script snapshot of the script.
1428 TestCase::CreateTestIsolateFromSnapshot(full_snapshot); 1408 TestCase::CreateTestIsolateFromSnapshot(full_snapshot);
1429 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. 1409 Dart_EnterScope(); // Start a Dart API scope for invoking API functions.
1430 1410
1431 // Load the library. 1411 // Load the library.
1432 Dart_Handle lib = Dart_LoadLibrary(NewString("dart_lib"), 1412 Dart_Handle lib = Dart_LoadLibrary(NewString("dart_lib"), Dart_Null(),
1433 Dart_Null(), 1413 NewString(kScriptChars), 0, 0);
1434 NewString(kScriptChars),
1435 0, 0);
1436 EXPECT_VALID(lib); 1414 EXPECT_VALID(lib);
1437 1415
1438 // Write out the script snapshot. 1416 // Write out the script snapshot.
1439 result = Dart_CreateLibrarySnapshot(lib, &buffer, &size); 1417 result = Dart_CreateLibrarySnapshot(lib, &buffer, &size);
1440 EXPECT_VALID(result); 1418 EXPECT_VALID(result);
1441 script_snapshot = reinterpret_cast<uint8_t*>(malloc(size)); 1419 script_snapshot = reinterpret_cast<uint8_t*>(malloc(size));
1442 memmove(script_snapshot, buffer, size); 1420 memmove(script_snapshot, buffer, size);
1443 Dart_ExitScope(); 1421 Dart_ExitScope();
1444 Dart_ShutdownIsolate(); 1422 Dart_ShutdownIsolate();
1445 } 1423 }
(...skipping 16 matching lines...) Expand all
1462 Dart_ExitScope(); 1440 Dart_ExitScope();
1463 Dart_ShutdownIsolate(); 1441 Dart_ShutdownIsolate();
1464 } 1442 }
1465 free(full_snapshot); 1443 free(full_snapshot);
1466 free(script_snapshot); 1444 free(script_snapshot);
1467 } 1445 }
1468 1446
1469 1447
1470 UNIT_TEST_CASE(ScriptSnapshot1) { 1448 UNIT_TEST_CASE(ScriptSnapshot1) {
1471 const char* kScriptChars = 1449 const char* kScriptChars =
1472 "class _SimpleNumEnumerable<T extends num> {" 1450 "class _SimpleNumEnumerable<T extends num> {"
1473 "final Iterable<T> _source;" 1451 "final Iterable<T> _source;"
1474 "const _SimpleNumEnumerable(this._source) : super();" 1452 "const _SimpleNumEnumerable(this._source) : super();"
1475 "}"; 1453 "}";
1476 1454
1477 Dart_Handle result; 1455 Dart_Handle result;
1478 uint8_t* buffer; 1456 uint8_t* buffer;
1479 intptr_t size; 1457 intptr_t size;
1480 intptr_t vm_isolate_snapshot_size; 1458 intptr_t vm_isolate_snapshot_size;
1481 uint8_t* isolate_snapshot = NULL; 1459 uint8_t* isolate_snapshot = NULL;
1482 intptr_t isolate_snapshot_size; 1460 intptr_t isolate_snapshot_size;
1483 uint8_t* full_snapshot = NULL; 1461 uint8_t* full_snapshot = NULL;
1484 uint8_t* script_snapshot = NULL; 1462 uint8_t* script_snapshot = NULL;
1485 1463
1486 bool saved_load_deferred_eagerly_mode = FLAG_load_deferred_eagerly; 1464 bool saved_load_deferred_eagerly_mode = FLAG_load_deferred_eagerly;
1487 FLAG_load_deferred_eagerly = true; 1465 FLAG_load_deferred_eagerly = true;
1488 bool saved_concurrent_sweep_mode = FLAG_concurrent_sweep; 1466 bool saved_concurrent_sweep_mode = FLAG_concurrent_sweep;
1489 FLAG_concurrent_sweep = false; 1467 FLAG_concurrent_sweep = false;
1490 { 1468 {
1491 // Start an Isolate, and create a full snapshot of it. 1469 // Start an Isolate, and create a full snapshot of it.
1492 TestIsolateScope __test_isolate__; 1470 TestIsolateScope __test_isolate__;
1493 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. 1471 Dart_EnterScope(); // Start a Dart API scope for invoking API functions.
1494 1472
1495 // Write out the script snapshot. 1473 // Write out the script snapshot.
1496 result = Dart_CreateSnapshot(NULL, 1474 result = Dart_CreateSnapshot(NULL, &vm_isolate_snapshot_size,
1497 &vm_isolate_snapshot_size, 1475 &isolate_snapshot, &isolate_snapshot_size);
1498 &isolate_snapshot,
1499 &isolate_snapshot_size);
1500 EXPECT_VALID(result); 1476 EXPECT_VALID(result);
1501 full_snapshot = reinterpret_cast<uint8_t*>(malloc(isolate_snapshot_size)); 1477 full_snapshot = reinterpret_cast<uint8_t*>(malloc(isolate_snapshot_size));
1502 memmove(full_snapshot, isolate_snapshot, isolate_snapshot_size); 1478 memmove(full_snapshot, isolate_snapshot, isolate_snapshot_size);
1503 Dart_ExitScope(); 1479 Dart_ExitScope();
1504 } 1480 }
1505 FLAG_concurrent_sweep = saved_concurrent_sweep_mode; 1481 FLAG_concurrent_sweep = saved_concurrent_sweep_mode;
1506 1482
1507 { 1483 {
1508 // Create an Isolate using the full snapshot, load a script and create 1484 // Create an Isolate using the full snapshot, load a script and create
1509 // a script snapshot of the script. 1485 // a script snapshot of the script.
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
1580 bool saved_load_deferred_eagerly_mode = FLAG_load_deferred_eagerly; 1556 bool saved_load_deferred_eagerly_mode = FLAG_load_deferred_eagerly;
1581 FLAG_load_deferred_eagerly = true; 1557 FLAG_load_deferred_eagerly = true;
1582 bool saved_concurrent_sweep_mode = FLAG_concurrent_sweep; 1558 bool saved_concurrent_sweep_mode = FLAG_concurrent_sweep;
1583 FLAG_concurrent_sweep = false; 1559 FLAG_concurrent_sweep = false;
1584 { 1560 {
1585 // Start an Isolate, and create a full snapshot of it. 1561 // Start an Isolate, and create a full snapshot of it.
1586 TestIsolateScope __test_isolate__; 1562 TestIsolateScope __test_isolate__;
1587 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. 1563 Dart_EnterScope(); // Start a Dart API scope for invoking API functions.
1588 1564
1589 // Write out the script snapshot. 1565 // Write out the script snapshot.
1590 result = Dart_CreateSnapshot(NULL, 1566 result = Dart_CreateSnapshot(NULL, &vm_isolate_snapshot_size,
1591 &vm_isolate_snapshot_size, 1567 &isolate_snapshot, &isolate_snapshot_size);
1592 &isolate_snapshot,
1593 &isolate_snapshot_size);
1594 EXPECT_VALID(result); 1568 EXPECT_VALID(result);
1595 full_snapshot = reinterpret_cast<uint8_t*>(malloc(isolate_snapshot_size)); 1569 full_snapshot = reinterpret_cast<uint8_t*>(malloc(isolate_snapshot_size));
1596 memmove(full_snapshot, isolate_snapshot, isolate_snapshot_size); 1570 memmove(full_snapshot, isolate_snapshot, isolate_snapshot_size);
1597 Dart_ExitScope(); 1571 Dart_ExitScope();
1598 } 1572 }
1599 FLAG_concurrent_sweep = saved_concurrent_sweep_mode; 1573 FLAG_concurrent_sweep = saved_concurrent_sweep_mode;
1600 1574
1601 { 1575 {
1602 // Create an Isolate using the full snapshot, load a script and create 1576 // Create an Isolate using the full snapshot, load a script and create
1603 // a script snapshot of the script. 1577 // a script snapshot of the script.
1604 TestCase::CreateTestIsolateFromSnapshot(full_snapshot); 1578 TestCase::CreateTestIsolateFromSnapshot(full_snapshot);
1605 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. 1579 Dart_EnterScope(); // Start a Dart API scope for invoking API functions.
1606 1580
1607 // Load the library. 1581 // Load the library.
1608 Dart_Handle import_lib = Dart_LoadLibrary(NewString("dart_import_lib"), 1582 Dart_Handle import_lib =
1609 Dart_Null(), 1583 Dart_LoadLibrary(NewString("dart_import_lib"), Dart_Null(),
1610 NewString(kLibScriptChars), 1584 NewString(kLibScriptChars), 0, 0);
1611 0, 0);
1612 EXPECT_VALID(import_lib); 1585 EXPECT_VALID(import_lib);
1613 1586
1614 // Create a test library and Load up a test script in it. 1587 // Create a test library and Load up a test script in it.
1615 TestCase::LoadTestScript(kScriptChars, NULL); 1588 TestCase::LoadTestScript(kScriptChars, NULL);
1616 1589
1617 EXPECT_VALID(Dart_LibraryImportLibrary(TestCase::lib(), 1590 EXPECT_VALID(
1618 import_lib, 1591 Dart_LibraryImportLibrary(TestCase::lib(), import_lib, Dart_Null()));
1619 Dart_Null()));
1620 EXPECT_VALID(Api::CheckAndFinalizePendingClasses(Thread::Current())); 1592 EXPECT_VALID(Api::CheckAndFinalizePendingClasses(Thread::Current()));
1621 1593
1622 // Write out the script snapshot. 1594 // Write out the script snapshot.
1623 result = Dart_CreateScriptSnapshot(&buffer, &size); 1595 result = Dart_CreateScriptSnapshot(&buffer, &size);
1624 EXPECT_VALID(result); 1596 EXPECT_VALID(result);
1625 script_snapshot = reinterpret_cast<uint8_t*>(malloc(size)); 1597 script_snapshot = reinterpret_cast<uint8_t*>(malloc(size));
1626 memmove(script_snapshot, buffer, size); 1598 memmove(script_snapshot, buffer, size);
1627 Dart_ExitScope(); 1599 Dart_ExitScope();
1628 Dart_ShutdownIsolate(); 1600 Dart_ShutdownIsolate();
1629 } 1601 }
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
1785 "}\n" 1757 "}\n"
1786 "getList() {\n" 1758 "getList() {\n"
1787 " return new List(kArrayLength);\n" 1759 " return new List(kArrayLength);\n"
1788 "}\n"; 1760 "}\n";
1789 1761
1790 TestCase::CreateTestIsolate(); 1762 TestCase::CreateTestIsolate();
1791 Isolate* isolate = Isolate::Current(); 1763 Isolate* isolate = Isolate::Current();
1792 EXPECT(isolate != NULL); 1764 EXPECT(isolate != NULL);
1793 Dart_EnterScope(); 1765 Dart_EnterScope();
1794 1766
1795 Dart_Handle lib = TestCase::LoadTestScript(kCustomIsolateScriptChars, 1767 Dart_Handle lib = TestCase::LoadTestScript(kCustomIsolateScriptChars, NULL);
1796 NULL);
1797 EXPECT_VALID(lib); 1768 EXPECT_VALID(lib);
1798 Dart_Handle smi_result; 1769 Dart_Handle smi_result;
1799 smi_result = Dart_Invoke(lib, NewString("getSmi"), 0, NULL); 1770 smi_result = Dart_Invoke(lib, NewString("getSmi"), 0, NULL);
1800 EXPECT_VALID(smi_result); 1771 EXPECT_VALID(smi_result);
1801 Dart_Handle bigint_result; 1772 Dart_Handle bigint_result;
1802 bigint_result = Dart_Invoke(lib, NewString("getBigint"), 0, NULL); 1773 bigint_result = Dart_Invoke(lib, NewString("getBigint"), 0, NULL);
1803 EXPECT_VALID(bigint_result); 1774 EXPECT_VALID(bigint_result);
1804 1775
1805 Dart_Handle ascii_string_result; 1776 Dart_Handle ascii_string_result;
1806 ascii_string_result = Dart_Invoke(lib, NewString("getAsciiString"), 0, NULL); 1777 ascii_string_result = Dart_Invoke(lib, NewString("getAsciiString"), 0, NULL);
(...skipping 871 matching lines...) Expand 10 before | Expand all | Expand 10 after
2678 } 2649 }
2679 } 2650 }
2680 Dart_ExitScope(); 2651 Dart_ExitScope();
2681 Dart_ShutdownIsolate(); 2652 Dart_ShutdownIsolate();
2682 } 2653 }
2683 2654
2684 2655
2685 static void CheckTypedData(Dart_CObject* object, 2656 static void CheckTypedData(Dart_CObject* object,
2686 Dart_TypedData_Type typed_data_type, 2657 Dart_TypedData_Type typed_data_type,
2687 int len) { 2658 int len) {
2688 EXPECT_EQ(Dart_CObject_kTypedData, object->type); 2659 EXPECT_EQ(Dart_CObject_kTypedData, object->type);
2689 EXPECT_EQ(typed_data_type, object->value.as_typed_data.type); 2660 EXPECT_EQ(typed_data_type, object->value.as_typed_data.type);
2690 EXPECT_EQ(len, object->value.as_typed_data.length); 2661 EXPECT_EQ(len, object->value.as_typed_data.length);
2691 } 2662 }
2692 2663
2693 UNIT_TEST_CASE(DartGeneratedListMessagesWithTypedData) { 2664 UNIT_TEST_CASE(DartGeneratedListMessagesWithTypedData) {
2694 static const char* kScriptChars = 2665 static const char* kScriptChars =
2695 "import 'dart:typed_data';\n" 2666 "import 'dart:typed_data';\n"
2696 "getTypedDataList() {\n" 2667 "getTypedDataList() {\n"
2697 " var list = new List(10);\n" 2668 " var list = new List(10);\n"
2698 " var index = 0;\n" 2669 " var index = 0;\n"
2699 " list[index++] = new Int8List(256);\n" 2670 " list[index++] = new Int8List(256);\n"
2700 " list[index++] = new Uint8List(256);\n" 2671 " list[index++] = new Uint8List(256);\n"
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
2779 // Generate a list of Uint8Lists from Dart code. 2750 // Generate a list of Uint8Lists from Dart code.
2780 uint8_t* buf = GetSerialized(lib, "getTypedDataList", &buf_len); 2751 uint8_t* buf = GetSerialized(lib, "getTypedDataList", &buf_len);
2781 ApiNativeScope scope; 2752 ApiNativeScope scope;
2782 Dart_CObject* root = GetDeserialized(buf, buf_len); 2753 Dart_CObject* root = GetDeserialized(buf, buf_len);
2783 EXPECT_NOTNULL(root); 2754 EXPECT_NOTNULL(root);
2784 EXPECT_EQ(Dart_CObject_kArray, root->type); 2755 EXPECT_EQ(Dart_CObject_kArray, root->type);
2785 struct { 2756 struct {
2786 Dart_TypedData_Type type; 2757 Dart_TypedData_Type type;
2787 int size; 2758 int size;
2788 } expected[] = { 2759 } expected[] = {
2789 { Dart_TypedData_kInt8, 256}, 2760 {Dart_TypedData_kInt8, 256}, {Dart_TypedData_kUint8, 256},
2790 { Dart_TypedData_kUint8, 256}, 2761 {Dart_TypedData_kInt16, 512}, {Dart_TypedData_kUint16, 512},
2791 { Dart_TypedData_kInt16, 512}, 2762 {Dart_TypedData_kInt32, 1024}, {Dart_TypedData_kUint32, 1024},
2792 { Dart_TypedData_kUint16, 512}, 2763 {Dart_TypedData_kInt64, 2048}, {Dart_TypedData_kUint64, 2048},
2793 { Dart_TypedData_kInt32, 1024}, 2764 {Dart_TypedData_kFloat32, 1024}, {Dart_TypedData_kFloat64, 2048},
2794 { Dart_TypedData_kUint32, 1024}, 2765 {Dart_TypedData_kInvalid, -1}};
2795 { Dart_TypedData_kInt64, 2048},
2796 { Dart_TypedData_kUint64, 2048},
2797 { Dart_TypedData_kFloat32, 1024},
2798 { Dart_TypedData_kFloat64, 2048},
2799 { Dart_TypedData_kInvalid, -1 }
2800 };
2801 2766
2802 int i = 0; 2767 int i = 0;
2803 while (expected[i].type != Dart_TypedData_kInvalid) { 2768 while (expected[i].type != Dart_TypedData_kInvalid) {
2804 CheckTypedData(root->value.as_array.values[i], 2769 CheckTypedData(root->value.as_array.values[i], expected[i].type,
2805 expected[i].type,
2806 expected[i].size); 2770 expected[i].size);
2807 i++; 2771 i++;
2808 } 2772 }
2809 EXPECT_EQ(i, root->value.as_array.length); 2773 EXPECT_EQ(i, root->value.as_array.length);
2810 } 2774 }
2811 { 2775 {
2812 // Generate a list of Uint8List views from Dart code. 2776 // Generate a list of Uint8List views from Dart code.
2813 uint8_t* buf = GetSerialized(lib, "getTypedDataViewList", &buf_len); 2777 uint8_t* buf = GetSerialized(lib, "getTypedDataViewList", &buf_len);
2814 ApiNativeScope scope; 2778 ApiNativeScope scope;
2815 Dart_CObject* root = GetDeserialized(buf, buf_len); 2779 Dart_CObject* root = GetDeserialized(buf, buf_len);
2816 EXPECT_NOTNULL(root); 2780 EXPECT_NOTNULL(root);
2817 EXPECT_EQ(Dart_CObject_kArray, root->type); 2781 EXPECT_EQ(Dart_CObject_kArray, root->type);
2818 struct { 2782 struct {
2819 Dart_TypedData_Type type; 2783 Dart_TypedData_Type type;
2820 int size; 2784 int size;
2821 } expected[] = { 2785 } expected[] = {
2822 { Dart_TypedData_kInt8, 256}, 2786 {Dart_TypedData_kInt8, 256}, {Dart_TypedData_kUint8, 256},
2823 { Dart_TypedData_kUint8, 256}, 2787 {Dart_TypedData_kInt16, 512}, {Dart_TypedData_kUint16, 512},
2824 { Dart_TypedData_kInt16, 512}, 2788 {Dart_TypedData_kInt32, 1024}, {Dart_TypedData_kUint32, 1024},
2825 { Dart_TypedData_kUint16, 512}, 2789 {Dart_TypedData_kInt64, 2048}, {Dart_TypedData_kUint64, 2048},
2826 { Dart_TypedData_kInt32, 1024}, 2790 {Dart_TypedData_kFloat32, 1024}, {Dart_TypedData_kFloat64, 2048},
2827 { Dart_TypedData_kUint32, 1024},
2828 { Dart_TypedData_kInt64, 2048},
2829 { Dart_TypedData_kUint64, 2048},
2830 { Dart_TypedData_kFloat32, 1024},
2831 { Dart_TypedData_kFloat64, 2048},
2832 2791
2833 { Dart_TypedData_kInt8, 512}, 2792 {Dart_TypedData_kInt8, 512}, {Dart_TypedData_kUint8, 512},
2834 { Dart_TypedData_kUint8, 512}, 2793 {Dart_TypedData_kInt8, 1024}, {Dart_TypedData_kUint8, 1024},
2835 { Dart_TypedData_kInt8, 1024}, 2794 {Dart_TypedData_kInt8, 2048}, {Dart_TypedData_kUint8, 2048},
2836 { Dart_TypedData_kUint8, 1024}, 2795 {Dart_TypedData_kInt8, 1024}, {Dart_TypedData_kUint8, 1024},
2837 { Dart_TypedData_kInt8, 2048}, 2796 {Dart_TypedData_kInt8, 2048}, {Dart_TypedData_kUint8, 2048},
2838 { Dart_TypedData_kUint8, 2048},
2839 { Dart_TypedData_kInt8, 1024},
2840 { Dart_TypedData_kUint8, 1024},
2841 { Dart_TypedData_kInt8, 2048},
2842 { Dart_TypedData_kUint8, 2048},
2843 2797
2844 { Dart_TypedData_kInt16, 256}, 2798 {Dart_TypedData_kInt16, 256}, {Dart_TypedData_kUint16, 256},
2845 { Dart_TypedData_kUint16, 256}, 2799 {Dart_TypedData_kInt16, 1024}, {Dart_TypedData_kUint16, 1024},
2846 { Dart_TypedData_kInt16, 1024}, 2800 {Dart_TypedData_kInt16, 2048}, {Dart_TypedData_kUint16, 2048},
2847 { Dart_TypedData_kUint16, 1024}, 2801 {Dart_TypedData_kInt16, 1024}, {Dart_TypedData_kUint16, 1024},
2848 { Dart_TypedData_kInt16, 2048}, 2802 {Dart_TypedData_kInt16, 2048}, {Dart_TypedData_kUint16, 2048},
2849 { Dart_TypedData_kUint16, 2048},
2850 { Dart_TypedData_kInt16, 1024},
2851 { Dart_TypedData_kUint16, 1024},
2852 { Dart_TypedData_kInt16, 2048},
2853 { Dart_TypedData_kUint16, 2048},
2854 2803
2855 { Dart_TypedData_kInvalid, -1 } 2804 {Dart_TypedData_kInvalid, -1}};
2856 };
2857 2805
2858 int i = 0; 2806 int i = 0;
2859 while (expected[i].type != Dart_TypedData_kInvalid) { 2807 while (expected[i].type != Dart_TypedData_kInvalid) {
2860 CheckTypedData(root->value.as_array.values[i], 2808 CheckTypedData(root->value.as_array.values[i], expected[i].type,
2861 expected[i].type,
2862 expected[i].size); 2809 expected[i].size);
2863 i++; 2810 i++;
2864 } 2811 }
2865 EXPECT_EQ(i, root->value.as_array.length); 2812 EXPECT_EQ(i, root->value.as_array.length);
2866 } 2813 }
2867 { 2814 {
2868 // Generate a list of Uint8Lists from Dart code. 2815 // Generate a list of Uint8Lists from Dart code.
2869 uint8_t* buf = 2816 uint8_t* buf =
2870 GetSerialized(lib, "getMultipleTypedDataViewList", &buf_len); 2817 GetSerialized(lib, "getMultipleTypedDataViewList", &buf_len);
2871 ApiNativeScope scope; 2818 ApiNativeScope scope;
2872 Dart_CObject* root = GetDeserialized(buf, buf_len); 2819 Dart_CObject* root = GetDeserialized(buf, buf_len);
2873 EXPECT_NOTNULL(root); 2820 EXPECT_NOTNULL(root);
2874 EXPECT_EQ(Dart_CObject_kArray, root->type); 2821 EXPECT_EQ(Dart_CObject_kArray, root->type);
2875 struct { 2822 struct {
2876 Dart_TypedData_Type type; 2823 Dart_TypedData_Type type;
2877 int size; 2824 int size;
2878 } expected[] = { 2825 } expected[] = {
2879 { Dart_TypedData_kInt8, 256}, 2826 {Dart_TypedData_kInt8, 256}, {Dart_TypedData_kUint8, 256},
2880 { Dart_TypedData_kUint8, 256}, 2827 {Dart_TypedData_kInt16, 256}, {Dart_TypedData_kUint16, 256},
2881 { Dart_TypedData_kInt16, 256}, 2828 {Dart_TypedData_kInt32, 256}, {Dart_TypedData_kUint32, 256},
2882 { Dart_TypedData_kUint16, 256}, 2829 {Dart_TypedData_kInt64, 256}, {Dart_TypedData_kUint64, 256},
2883 { Dart_TypedData_kInt32, 256}, 2830 {Dart_TypedData_kFloat32, 256}, {Dart_TypedData_kFloat64, 256},
2884 { Dart_TypedData_kUint32, 256}, 2831 {Dart_TypedData_kInvalid, -1}};
2885 { Dart_TypedData_kInt64, 256},
2886 { Dart_TypedData_kUint64, 256},
2887 { Dart_TypedData_kFloat32, 256},
2888 { Dart_TypedData_kFloat64, 256},
2889 { Dart_TypedData_kInvalid, -1 }
2890 };
2891 2832
2892 int i = 0; 2833 int i = 0;
2893 while (expected[i].type != Dart_TypedData_kInvalid) { 2834 while (expected[i].type != Dart_TypedData_kInvalid) {
2894 CheckTypedData(root->value.as_array.values[i], 2835 CheckTypedData(root->value.as_array.values[i], expected[i].type,
2895 expected[i].type,
2896 expected[i].size); 2836 expected[i].size);
2897 2837
2898 // All views point to the same data. 2838 // All views point to the same data.
2899 EXPECT_EQ(root->value.as_array.values[0]->value.as_typed_data.values, 2839 EXPECT_EQ(root->value.as_array.values[0]->value.as_typed_data.values,
2900 root->value.as_array.values[i]->value.as_typed_data.values); 2840 root->value.as_array.values[i]->value.as_typed_data.values);
2901 i++; 2841 i++;
2902 } 2842 }
2903 EXPECT_EQ(i, root->value.as_array.length); 2843 EXPECT_EQ(i, root->value.as_array.length);
2904 } 2844 }
2905 } 2845 }
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
2973 2913
2974 object.type = Dart_CObject_kDouble; 2914 object.type = Dart_CObject_kDouble;
2975 object.value.as_double = 3.14; 2915 object.value.as_double = 3.14;
2976 EXPECT(Dart_PostCObject(port_id, &object)); 2916 EXPECT(Dart_PostCObject(port_id, &object));
2977 2917
2978 object.type = Dart_CObject_kArray; 2918 object.type = Dart_CObject_kArray;
2979 object.value.as_array.length = 0; 2919 object.value.as_array.length = 0;
2980 EXPECT(Dart_PostCObject(port_id, &object)); 2920 EXPECT(Dart_PostCObject(port_id, &object));
2981 2921
2982 static const int kArrayLength = 10; 2922 static const int kArrayLength = 10;
2983 Dart_CObject* array = 2923 Dart_CObject* array = reinterpret_cast<Dart_CObject*>(Dart_ScopeAllocate(
2984 reinterpret_cast<Dart_CObject*>( 2924 sizeof(Dart_CObject) + sizeof(Dart_CObject*) * kArrayLength)); // NOLINT
2985 Dart_ScopeAllocate(
2986 sizeof(Dart_CObject) + sizeof(Dart_CObject*) * kArrayLength)); // NOLINT
2987 array->type = Dart_CObject_kArray; 2925 array->type = Dart_CObject_kArray;
2988 array->value.as_array.length = kArrayLength; 2926 array->value.as_array.length = kArrayLength;
2989 array->value.as_array.values = 2927 array->value.as_array.values = reinterpret_cast<Dart_CObject**>(array + 1);
2990 reinterpret_cast<Dart_CObject**>(array + 1);
2991 for (int i = 0; i < kArrayLength; i++) { 2928 for (int i = 0; i < kArrayLength; i++) {
2992 Dart_CObject* element = 2929 Dart_CObject* element = reinterpret_cast<Dart_CObject*>(
2993 reinterpret_cast<Dart_CObject*>( 2930 Dart_ScopeAllocate(sizeof(Dart_CObject)));
2994 Dart_ScopeAllocate(sizeof(Dart_CObject)));
2995 element->type = Dart_CObject_kInt32; 2931 element->type = Dart_CObject_kInt32;
2996 element->value.as_int32 = i; 2932 element->value.as_int32 = i;
2997 array->value.as_array.values[i] = element; 2933 array->value.as_array.values[i] = element;
2998 } 2934 }
2999 EXPECT(Dart_PostCObject(port_id, array)); 2935 EXPECT(Dart_PostCObject(port_id, array));
3000 2936
3001 result = Dart_RunLoop(); 2937 result = Dart_RunLoop();
3002 EXPECT(Dart_IsError(result)); 2938 EXPECT(Dart_IsError(result));
3003 EXPECT(Dart_ErrorHasException(result)); 2939 EXPECT(Dart_ErrorHasException(result));
3004 EXPECT_SUBSTRING("Exception: nulltruefalse123456æøå3.14[]100123456789\n", 2940 EXPECT_SUBSTRING("Exception: nulltruefalse123456æøå3.14[]100123456789\n",
3005 Dart_GetError(result)); 2941 Dart_GetError(result));
3006 2942
3007 Dart_ExitScope(); 2943 Dart_ExitScope();
3008 } 2944 }
3009 2945
3010 2946
3011 TEST_CASE(OmittedObjectEncodingLength) { 2947 TEST_CASE(OmittedObjectEncodingLength) {
3012 StackZone zone(Thread::Current()); 2948 StackZone zone(Thread::Current());
3013 uint8_t* buffer; 2949 uint8_t* buffer;
3014 MessageWriter writer(&buffer, &zone_allocator, true); 2950 MessageWriter writer(&buffer, &zone_allocator, true);
3015 writer.WriteInlinedObjectHeader(kOmittedObjectId); 2951 writer.WriteInlinedObjectHeader(kOmittedObjectId);
3016 // For performance, we'd like single-byte headers when ids are omitted. 2952 // For performance, we'd like single-byte headers when ids are omitted.
3017 // If this starts failing, consider renumbering the snapshot ids. 2953 // If this starts failing, consider renumbering the snapshot ids.
3018 EXPECT_EQ(1, writer.BytesWritten()); 2954 EXPECT_EQ(1, writer.BytesWritten());
3019 } 2955 }
3020 2956
3021 } // namespace dart 2957 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/snapshot_ids.h ('k') | runtime/vm/source_report.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698