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

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

Issue 1952023002: Minor cleanup based on profiler output of CompileParseFunction. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 7 months 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
« runtime/vm/raw_object.h ('K') | « runtime/vm/raw_object.h ('k') | no next file » | 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/dart_api_impl.h" 10 #include "vm/dart_api_impl.h"
(...skipping 841 matching lines...) Expand 10 before | Expand all | Expand 10 after
852 ForwardList forward_list_; 852 ForwardList forward_list_;
853 853
854 DISALLOW_COPY_AND_ASSIGN(TestSnapshotWriter); 854 DISALLOW_COPY_AND_ASSIGN(TestSnapshotWriter);
855 }; 855 };
856 856
857 857
858 static void GenerateSourceAndCheck(const Script& script) { 858 static void GenerateSourceAndCheck(const Script& script) {
859 // Check if we are able to generate the source from the token stream. 859 // Check if we are able to generate the source from the token stream.
860 // Rescan this source and compare the token stream to see if they are 860 // Rescan this source and compare the token stream to see if they are
861 // the same. 861 // the same.
862 const TokenStream& expected_tokens = TokenStream::Handle(script.tokens()); 862 Zone* zone = Thread::Current()->zone();
863 const TokenStream& expected_tokens =
864 TokenStream::Handle(zone, script.tokens());
863 TokenStream::Iterator expected_iterator( 865 TokenStream::Iterator expected_iterator(
866 zone,
864 expected_tokens, 867 expected_tokens,
865 TokenPosition::kMinSource, 868 TokenPosition::kMinSource,
866 TokenStream::Iterator::kAllTokens); 869 TokenStream::Iterator::kAllTokens);
867 const String& str = String::Handle(expected_tokens.GenerateSource()); 870 const String& str = String::Handle(zone, expected_tokens.GenerateSource());
868 const String& private_key = String::Handle(expected_tokens.PrivateKey()); 871 const String& private_key =
872 String::Handle(zone, expected_tokens.PrivateKey());
869 Scanner scanner(str, private_key); 873 Scanner scanner(str, private_key);
870 const TokenStream& reconstructed_tokens = 874 const TokenStream& reconstructed_tokens =
871 TokenStream::Handle(TokenStream::New(scanner.GetStream(), 875 TokenStream::Handle(zone, TokenStream::New(scanner.GetStream(),
872 private_key, 876 private_key,
873 false)); 877 false));
874 expected_iterator.SetCurrentPosition(TokenPosition::kMinSource); 878 expected_iterator.SetCurrentPosition(TokenPosition::kMinSource);
875 TokenStream::Iterator reconstructed_iterator( 879 TokenStream::Iterator reconstructed_iterator(
880 zone,
876 reconstructed_tokens, 881 reconstructed_tokens,
877 TokenPosition::kMinSource, 882 TokenPosition::kMinSource,
878 TokenStream::Iterator::kAllTokens); 883 TokenStream::Iterator::kAllTokens);
879 Token::Kind expected_kind = expected_iterator.CurrentTokenKind(); 884 Token::Kind expected_kind = expected_iterator.CurrentTokenKind();
880 Token::Kind reconstructed_kind = reconstructed_iterator.CurrentTokenKind(); 885 Token::Kind reconstructed_kind = reconstructed_iterator.CurrentTokenKind();
881 String& expected_literal = String::Handle(); 886 String& expected_literal = String::Handle(zone);
882 String& actual_literal = String::Handle(); 887 String& actual_literal = String::Handle(zone);
883 while (expected_kind != Token::kEOS && reconstructed_kind != Token::kEOS) { 888 while (expected_kind != Token::kEOS && reconstructed_kind != Token::kEOS) {
884 EXPECT_EQ(expected_kind, reconstructed_kind); 889 EXPECT_EQ(expected_kind, reconstructed_kind);
885 expected_literal ^= expected_iterator.CurrentLiteral(); 890 expected_literal ^= expected_iterator.CurrentLiteral();
886 actual_literal ^= reconstructed_iterator.CurrentLiteral(); 891 actual_literal ^= reconstructed_iterator.CurrentLiteral();
887 EXPECT_STREQ(expected_literal.ToCString(), actual_literal.ToCString()); 892 EXPECT_STREQ(expected_literal.ToCString(), actual_literal.ToCString());
888 expected_iterator.Advance(); 893 expected_iterator.Advance();
889 reconstructed_iterator.Advance(); 894 reconstructed_iterator.Advance();
890 expected_kind = expected_iterator.CurrentTokenKind(); 895 expected_kind = expected_iterator.CurrentTokenKind();
891 reconstructed_kind = reconstructed_iterator.CurrentTokenKind(); 896 reconstructed_kind = reconstructed_iterator.CurrentTokenKind();
892 } 897 }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
930 " return '''\n" 935 " return '''\n"
931 "a b c\n" 936 "a b c\n"
932 "d ${d} e\n" 937 "d ${d} e\n"
933 "g h i''';\n" 938 "g h i''';\n"
934 " }\n" 939 " }\n"
935 " static ms6() {\n" 940 " static ms6() {\n"
936 " return '\\t \\n \\x00 \\xFF';\n" 941 " return '\\t \\n \\x00 \\xFF';\n"
937 " }\n" 942 " }\n"
938 "}\n"; 943 "}\n";
939 944
940 String& url = String::Handle(String::New("dart-test:SerializeScript")); 945 Zone* zone = thread->zone();
941 String& source = String::Handle(String::New(kScriptChars)); 946 String& url = String::Handle(zone, String::New("dart-test:SerializeScript"));
942 Script& script = Script::Handle(Script::New(url, 947 String& source = String::Handle(zone, String::New(kScriptChars));
943 source, 948 Script& script = Script::Handle(zone, Script::New(url,
944 RawScript::kScriptTag)); 949 source,
945 const String& lib_url = String::Handle(Symbols::New(thread, "TestLib")); 950 RawScript::kScriptTag));
946 Library& lib = Library::Handle(Library::New(lib_url)); 951 const String& lib_url = String::Handle(zone, Symbols::New(thread, "TestLib"));
952 Library& lib = Library::Handle(zone, Library::New(lib_url));
947 lib.Register(); 953 lib.Register();
948 EXPECT(CompilerTest::TestCompileScript(lib, script)); 954 EXPECT(CompilerTest::TestCompileScript(lib, script));
949 955
950 // Write snapshot with script content. 956 // Write snapshot with script content.
951 uint8_t* buffer; 957 uint8_t* buffer;
952 TestSnapshotWriter writer(&buffer, &malloc_allocator); 958 TestSnapshotWriter writer(&buffer, &malloc_allocator);
953 writer.WriteScript(script); 959 writer.WriteScript(script);
954 960
955 // Read object back from the snapshot. 961 // Read object back from the snapshot.
956 ScriptSnapshotReader reader(buffer, writer.BytesWritten(), thread); 962 ScriptSnapshotReader reader(buffer, writer.BytesWritten(), thread);
957 Script& serialized_script = Script::Handle(thread->zone()); 963 Script& serialized_script = Script::Handle(zone);
958 serialized_script ^= reader.ReadObject(); 964 serialized_script ^= reader.ReadObject();
959 965
960 // Check if the serialized script object matches the original script. 966 // Check if the serialized script object matches the original script.
961 String& expected_literal = String::Handle(); 967 String& expected_literal = String::Handle(zone);
962 String& actual_literal = String::Handle(); 968 String& actual_literal = String::Handle(zone);
963 String& str = String::Handle(); 969 String& str = String::Handle(zone);
964 str ^= serialized_script.url(); 970 str ^= serialized_script.url();
965 EXPECT(url.Equals(str)); 971 EXPECT(url.Equals(str));
966 972
967 const TokenStream& expected_tokens = TokenStream::Handle(script.tokens()); 973 const TokenStream& expected_tokens =
974 TokenStream::Handle(zone, script.tokens());
968 const TokenStream& serialized_tokens = 975 const TokenStream& serialized_tokens =
969 TokenStream::Handle(serialized_script.tokens()); 976 TokenStream::Handle(zone, serialized_script.tokens());
970 const ExternalTypedData& expected_data = 977 const ExternalTypedData& expected_data =
971 ExternalTypedData::Handle(expected_tokens.GetStream()); 978 ExternalTypedData::Handle(zone, expected_tokens.GetStream());
972 const ExternalTypedData& serialized_data = 979 const ExternalTypedData& serialized_data =
973 ExternalTypedData::Handle(serialized_tokens.GetStream()); 980 ExternalTypedData::Handle(zone, serialized_tokens.GetStream());
974 EXPECT_EQ(expected_data.Length(), serialized_data.Length()); 981 EXPECT_EQ(expected_data.Length(), serialized_data.Length());
975 TokenStream::Iterator expected_iterator(expected_tokens, 982 TokenStream::Iterator expected_iterator(zone,
983 expected_tokens,
976 TokenPosition::kMinSource); 984 TokenPosition::kMinSource);
977 TokenStream::Iterator serialized_iterator(serialized_tokens, 985 TokenStream::Iterator serialized_iterator(zone,
986 serialized_tokens,
978 TokenPosition::kMinSource); 987 TokenPosition::kMinSource);
979 Token::Kind expected_kind = expected_iterator.CurrentTokenKind(); 988 Token::Kind expected_kind = expected_iterator.CurrentTokenKind();
980 Token::Kind serialized_kind = serialized_iterator.CurrentTokenKind(); 989 Token::Kind serialized_kind = serialized_iterator.CurrentTokenKind();
981 while (expected_kind != Token::kEOS && serialized_kind != Token::kEOS) { 990 while (expected_kind != Token::kEOS && serialized_kind != Token::kEOS) {
982 EXPECT_EQ(expected_kind, serialized_kind); 991 EXPECT_EQ(expected_kind, serialized_kind);
983 expected_literal ^= expected_iterator.CurrentLiteral(); 992 expected_literal ^= expected_iterator.CurrentLiteral();
984 actual_literal ^= serialized_iterator.CurrentLiteral(); 993 actual_literal ^= serialized_iterator.CurrentLiteral();
985 EXPECT(expected_literal.Equals(actual_literal)); 994 EXPECT(expected_literal.Equals(actual_literal));
986 expected_iterator.Advance(); 995 expected_iterator.Advance();
987 serialized_iterator.Advance(); 996 serialized_iterator.Advance();
(...skipping 2020 matching lines...) Expand 10 before | Expand all | Expand 10 after
3008 StackZone zone(Thread::Current()); 3017 StackZone zone(Thread::Current());
3009 uint8_t* buffer; 3018 uint8_t* buffer;
3010 MessageWriter writer(&buffer, &zone_allocator, true); 3019 MessageWriter writer(&buffer, &zone_allocator, true);
3011 writer.WriteInlinedObjectHeader(kOmittedObjectId); 3020 writer.WriteInlinedObjectHeader(kOmittedObjectId);
3012 // For performance, we'd like single-byte headers when ids are omitted. 3021 // For performance, we'd like single-byte headers when ids are omitted.
3013 // If this starts failing, consider renumbering the snapshot ids. 3022 // If this starts failing, consider renumbering the snapshot ids.
3014 EXPECT_EQ(1, writer.BytesWritten()); 3023 EXPECT_EQ(1, writer.BytesWritten());
3015 } 3024 }
3016 3025
3017 } // namespace dart 3026 } // namespace dart
OLDNEW
« runtime/vm/raw_object.h ('K') | « runtime/vm/raw_object.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698