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

Side by Side Diff: runtime/vm/snapshot.h

Issue 1915853004: Option to output precompiled instructions as a blob for use with mmap instead of assembly for use i… (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 8 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
« no previous file with comments | « runtime/vm/raw_object.h ('k') | runtime/vm/snapshot.cc » ('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 #ifndef VM_SNAPSHOT_H_ 5 #ifndef VM_SNAPSHOT_H_
6 #define VM_SNAPSHOT_H_ 6 #define VM_SNAPSHOT_H_
7 7
8 #include "platform/assert.h" 8 #include "platform/assert.h"
9 #include "vm/allocation.h" 9 #include "vm/allocation.h"
10 #include "vm/bitfield.h" 10 #include "vm/bitfield.h"
(...skipping 826 matching lines...) Expand 10 before | Expand all | Expand 10 after
837 GrowableArray<Node*> nodes_; 837 GrowableArray<Node*> nodes_;
838 intptr_t first_unprocessed_object_id_; 838 intptr_t first_unprocessed_object_id_;
839 839
840 friend class FullSnapshotWriter; 840 friend class FullSnapshotWriter;
841 DISALLOW_COPY_AND_ASSIGN(ForwardList); 841 DISALLOW_COPY_AND_ASSIGN(ForwardList);
842 }; 842 };
843 843
844 844
845 class InstructionsWriter : public ZoneAllocated { 845 class InstructionsWriter : public ZoneAllocated {
846 public: 846 public:
847 InstructionsWriter(uint8_t** buffer, 847 InstructionsWriter()
848 ReAlloc alloc, 848 : next_offset_(InstructionsSnapshot::kHeaderSize),
849 intptr_t initial_size)
850 : stream_(buffer, alloc, initial_size),
851 next_offset_(InstructionsSnapshot::kHeaderSize),
852 next_object_offset_(DataSnapshot::kHeaderSize), 849 next_object_offset_(DataSnapshot::kHeaderSize),
853 binary_size_(0),
854 instructions_(), 850 instructions_(),
855 objects_() { 851 objects_() {
856 ASSERT(buffer != NULL);
857 ASSERT(alloc != NULL);
858 } 852 }
859 853 virtual ~InstructionsWriter() { }
860 // Size of the snapshot (assembly code).
861 intptr_t BytesWritten() const { return stream_.bytes_written(); }
862
863 intptr_t binary_size() { return binary_size_; }
864 854
865 int32_t GetOffsetFor(RawInstructions* instructions, RawCode* code); 855 int32_t GetOffsetFor(RawInstructions* instructions, RawCode* code);
866 856
867 int32_t GetObjectOffsetFor(RawObject* raw_object); 857 int32_t GetObjectOffsetFor(RawObject* raw_object);
868 858
869 void WriteAssembly(); 859 virtual void Write() = 0;
860 virtual intptr_t binary_size() = 0;
870 861
871 private: 862 protected:
872 struct InstructionsData { 863 struct InstructionsData {
873 explicit InstructionsData(RawInstructions* insns, 864 explicit InstructionsData(RawInstructions* insns,
874 RawCode* code, 865 RawCode* code,
875 intptr_t offset) 866 intptr_t offset)
876 : raw_insns_(insns), raw_code_(code), offset_(offset) { } 867 : raw_insns_(insns), raw_code_(code), offset_(offset) { }
877 868
878 union { 869 union {
879 RawInstructions* raw_insns_; 870 RawInstructions* raw_insns_;
880 const Instructions* insns_; 871 const Instructions* insns_;
881 }; 872 };
882 union { 873 union {
883 RawCode* raw_code_; 874 RawCode* raw_code_;
884 const Code* code_; 875 const Code* code_;
885 }; 876 };
886 intptr_t offset_; 877 intptr_t offset_;
887 }; 878 };
888 879
889 struct ObjectData { 880 struct ObjectData {
890 explicit ObjectData(RawObject* raw_obj) 881 explicit ObjectData(RawObject* raw_obj)
891 : raw_obj_(raw_obj) { } 882 : raw_obj_(raw_obj) { }
892 883
893 union { 884 union {
894 RawObject* raw_obj_; 885 RawObject* raw_obj_;
895 const Object* obj_; 886 const Object* obj_;
896 }; 887 };
897 }; 888 };
898 889
890 intptr_t next_offset_;
891 intptr_t next_object_offset_;
892 GrowableArray<InstructionsData> instructions_;
893 GrowableArray<ObjectData> objects_;
894
895 private:
896 DISALLOW_COPY_AND_ASSIGN(InstructionsWriter);
897 };
898
899
900 class AssemblyInstructionsWriter : public InstructionsWriter {
901 public:
902 AssemblyInstructionsWriter(uint8_t** assembly_buffer,
903 ReAlloc alloc,
904 intptr_t initial_size)
905 : InstructionsWriter(),
906 assembly_stream_(assembly_buffer, alloc, initial_size) {
907 }
908
909 virtual void Write();
910 virtual intptr_t binary_size() { return binary_size_; }
911
912 intptr_t AssemblySize() const { return assembly_stream_.bytes_written(); }
913
914 private:
899 void WriteWordLiteral(uword value) { 915 void WriteWordLiteral(uword value) {
900 // Padding is helpful for comparing the .S with --disassemble. 916 // Padding is helpful for comparing the .S with --disassemble.
901 #if defined(ARCH_IS_64_BIT) 917 #if defined(ARCH_IS_64_BIT)
902 stream_.Print(".quad 0x%0.16" Px "\n", value); 918 assembly_stream_.Print(".quad 0x%0.16" Px "\n", value);
903 #else 919 #else
904 stream_.Print(".long 0x%0.8" Px "\n", value); 920 assembly_stream_.Print(".long 0x%0.8" Px "\n", value);
905 #endif 921 #endif
906 binary_size_ += sizeof(value); 922 binary_size_ += sizeof(value);
907 } 923 }
908 924
909 WriteStream stream_; 925 WriteStream assembly_stream_;
910 intptr_t next_offset_;
911 intptr_t next_object_offset_;
912 intptr_t binary_size_; 926 intptr_t binary_size_;
913 GrowableArray<InstructionsData> instructions_;
914 GrowableArray<ObjectData> objects_;
915 927
916 DISALLOW_COPY_AND_ASSIGN(InstructionsWriter); 928 DISALLOW_COPY_AND_ASSIGN(AssemblyInstructionsWriter);
917 }; 929 };
918 930
919 931
932 class BlobInstructionsWriter : public InstructionsWriter {
933 public:
934 BlobInstructionsWriter(uint8_t** instructions_blob_buffer,
935 uint8_t** rodata_blob_buffer,
936 ReAlloc alloc,
937 intptr_t initial_size)
938 : InstructionsWriter(),
939 instructions_blob_stream_(instructions_blob_buffer, alloc, initial_size),
940 rodata_blob_stream_(rodata_blob_buffer, alloc, initial_size) {
941 }
942
943 virtual void Write();
944 virtual intptr_t binary_size() {
945 return InstructionsBlobSize() + RodataBlobSize();
946 }
947
948 intptr_t InstructionsBlobSize() const {
949 return instructions_blob_stream_.bytes_written();
950 }
951 intptr_t RodataBlobSize() const {
952 return rodata_blob_stream_.bytes_written();
953 }
954
955 private:
956 WriteStream instructions_blob_stream_;
957 WriteStream rodata_blob_stream_;
958
959 DISALLOW_COPY_AND_ASSIGN(BlobInstructionsWriter);
960 };
961
962
920 class SnapshotWriter : public BaseWriter { 963 class SnapshotWriter : public BaseWriter {
921 protected: 964 protected:
922 SnapshotWriter(Snapshot::Kind kind, 965 SnapshotWriter(Snapshot::Kind kind,
923 Thread* thread, 966 Thread* thread,
924 uint8_t** buffer, 967 uint8_t** buffer,
925 ReAlloc alloc, 968 ReAlloc alloc,
926 intptr_t initial_size, 969 intptr_t initial_size,
927 ForwardList* forward_list, 970 ForwardList* forward_list,
928 InstructionsWriter* instructions_writer, 971 InstructionsWriter* instructions_writer,
929 bool can_send_any_object, 972 bool can_send_any_object,
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
1063 friend class WriteInlinedObjectVisitor; 1106 friend class WriteInlinedObjectVisitor;
1064 DISALLOW_COPY_AND_ASSIGN(SnapshotWriter); 1107 DISALLOW_COPY_AND_ASSIGN(SnapshotWriter);
1065 }; 1108 };
1066 1109
1067 1110
1068 class FullSnapshotWriter { 1111 class FullSnapshotWriter {
1069 public: 1112 public:
1070 static const intptr_t kInitialSize = 64 * KB; 1113 static const intptr_t kInitialSize = 64 * KB;
1071 FullSnapshotWriter(uint8_t** vm_isolate_snapshot_buffer, 1114 FullSnapshotWriter(uint8_t** vm_isolate_snapshot_buffer,
1072 uint8_t** isolate_snapshot_buffer, 1115 uint8_t** isolate_snapshot_buffer,
1073 uint8_t** instructions_snapshot_buffer,
1074 ReAlloc alloc, 1116 ReAlloc alloc,
1117 InstructionsWriter* instructions_writer,
1075 bool snapshot_code, 1118 bool snapshot_code,
1076 bool vm_isolate_is_symbolic); 1119 bool vm_isolate_is_symbolic);
1077 ~FullSnapshotWriter(); 1120 ~FullSnapshotWriter();
1078 1121
1079 uint8_t** vm_isolate_snapshot_buffer() { 1122 uint8_t** vm_isolate_snapshot_buffer() {
1080 return vm_isolate_snapshot_buffer_; 1123 return vm_isolate_snapshot_buffer_;
1081 } 1124 }
1082 1125
1083 uint8_t** isolate_snapshot_buffer() { 1126 uint8_t** isolate_snapshot_buffer() {
1084 return isolate_snapshot_buffer_; 1127 return isolate_snapshot_buffer_;
1085 } 1128 }
1086 1129
1087 Thread* thread() const { return thread_; } 1130 Thread* thread() const { return thread_; }
1088 Zone* zone() const { return thread_->zone(); } 1131 Zone* zone() const { return thread_->zone(); }
1089 Isolate* isolate() const { return thread_->isolate(); } 1132 Isolate* isolate() const { return thread_->isolate(); }
1090 Heap* heap() const { return isolate()->heap(); } 1133 Heap* heap() const { return isolate()->heap(); }
1091 1134
1092 // Writes a full snapshot of the Isolate. 1135 // Writes a full snapshot of the Isolate.
1093 void WriteFullSnapshot(); 1136 void WriteFullSnapshot();
1094 1137
1095 intptr_t VmIsolateSnapshotSize() const { 1138 intptr_t VmIsolateSnapshotSize() const {
1096 return vm_isolate_snapshot_size_; 1139 return vm_isolate_snapshot_size_;
1097 } 1140 }
1098 intptr_t IsolateSnapshotSize() const { 1141 intptr_t IsolateSnapshotSize() const {
1099 return isolate_snapshot_size_; 1142 return isolate_snapshot_size_;
1100 } 1143 }
1101 intptr_t InstructionsSnapshotSize() const {
1102 return instructions_snapshot_size_;
1103 }
1104 1144
1105 private: 1145 private:
1106 // Writes a snapshot of the VM Isolate. 1146 // Writes a snapshot of the VM Isolate.
1107 void WriteVmIsolateSnapshot(); 1147 void WriteVmIsolateSnapshot();
1108 1148
1109 // Writes a full snapshot of a regular Dart Isolate. 1149 // Writes a full snapshot of a regular Dart Isolate.
1110 void WriteIsolateFullSnapshot(); 1150 void WriteIsolateFullSnapshot();
1111 1151
1112 Thread* thread_; 1152 Thread* thread_;
1113 uint8_t** vm_isolate_snapshot_buffer_; 1153 uint8_t** vm_isolate_snapshot_buffer_;
1114 uint8_t** isolate_snapshot_buffer_; 1154 uint8_t** isolate_snapshot_buffer_;
1115 uint8_t** instructions_snapshot_buffer_;
1116 ReAlloc alloc_; 1155 ReAlloc alloc_;
1117 intptr_t vm_isolate_snapshot_size_; 1156 intptr_t vm_isolate_snapshot_size_;
1118 intptr_t isolate_snapshot_size_; 1157 intptr_t isolate_snapshot_size_;
1119 intptr_t instructions_snapshot_size_;
1120 ForwardList* forward_list_; 1158 ForwardList* forward_list_;
1121 InstructionsWriter* instructions_writer_; 1159 InstructionsWriter* instructions_writer_;
1122 Array& scripts_; 1160 Array& scripts_;
1123 Array& symbol_table_; 1161 Array& symbol_table_;
1124 bool snapshot_code_; 1162 bool snapshot_code_;
1125 bool vm_isolate_is_symbolic_; 1163 bool vm_isolate_is_symbolic_;
1126 1164
1127 DISALLOW_COPY_AND_ASSIGN(FullSnapshotWriter); 1165 DISALLOW_COPY_AND_ASSIGN(FullSnapshotWriter);
1128 }; 1166 };
1129 1167
1130 1168
1131 class PrecompiledSnapshotWriter : public FullSnapshotWriter { 1169 class PrecompiledSnapshotWriter : public FullSnapshotWriter {
1132 public: 1170 public:
1133 PrecompiledSnapshotWriter(uint8_t** vm_isolate_snapshot_buffer, 1171 PrecompiledSnapshotWriter(uint8_t** vm_isolate_snapshot_buffer,
1134 uint8_t** isolate_snapshot_buffer, 1172 uint8_t** isolate_snapshot_buffer,
1135 uint8_t** instructions_snapshot_buffer, 1173 ReAlloc alloc,
1136 ReAlloc alloc); 1174 InstructionsWriter* instructions_writer);
1137 ~PrecompiledSnapshotWriter(); 1175 ~PrecompiledSnapshotWriter();
1138 }; 1176 };
1139 1177
1140 1178
1141 class ScriptSnapshotWriter : public SnapshotWriter { 1179 class ScriptSnapshotWriter : public SnapshotWriter {
1142 public: 1180 public:
1143 static const intptr_t kInitialSize = 64 * KB; 1181 static const intptr_t kInitialSize = 64 * KB;
1144 ScriptSnapshotWriter(uint8_t** buffer, ReAlloc alloc); 1182 ScriptSnapshotWriter(uint8_t** buffer, ReAlloc alloc);
1145 ~ScriptSnapshotWriter() { } 1183 ~ScriptSnapshotWriter() { }
1146 1184
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1183 private: 1221 private:
1184 SnapshotWriter* writer_; 1222 SnapshotWriter* writer_;
1185 bool as_references_; 1223 bool as_references_;
1186 1224
1187 DISALLOW_COPY_AND_ASSIGN(SnapshotWriterVisitor); 1225 DISALLOW_COPY_AND_ASSIGN(SnapshotWriterVisitor);
1188 }; 1226 };
1189 1227
1190 } // namespace dart 1228 } // namespace dart
1191 1229
1192 #endif // VM_SNAPSHOT_H_ 1230 #endif // VM_SNAPSHOT_H_
OLDNEW
« no previous file with comments | « runtime/vm/raw_object.h ('k') | runtime/vm/snapshot.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698