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

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

Issue 1309563006: Emit assembly instead of a blob for the instructions snapshot, and provide labels for the entry poi… (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 3 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/snapshot.h ('k') | tools/precompilation/create_instructions_snapshot_assembly.dart » ('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 "vm/snapshot.h" 5 #include "vm/snapshot.h"
6 6
7 #include "platform/assert.h" 7 #include "platform/assert.h"
8 #include "vm/bootstrap.h" 8 #include "vm/bootstrap.h"
9 #include "vm/class_finalizer.h" 9 #include "vm/class_finalizer.h"
10 #include "vm/dart.h" 10 #include "vm/dart.h"
(...skipping 1120 matching lines...) Expand 10 before | Expand all | Expand 10 after
1131 return Mint::NewCanonical(value); 1131 return Mint::NewCanonical(value);
1132 } 1132 }
1133 1133
1134 1134
1135 RawStacktrace* SnapshotReader::NewStacktrace() { 1135 RawStacktrace* SnapshotReader::NewStacktrace() {
1136 ALLOC_NEW_OBJECT(Stacktrace); 1136 ALLOC_NEW_OBJECT(Stacktrace);
1137 } 1137 }
1138 1138
1139 1139
1140 int32_t InstructionsWriter::GetOffsetFor(RawInstructions* instructions) { 1140 int32_t InstructionsWriter::GetOffsetFor(RawInstructions* instructions) {
1141 // Instructions are allocated with the code alignment and we don't write 1141 intptr_t offset = next_offset_;
1142 // anything else in the text section. 1142 next_offset_ += instructions->Size();
1143 ASSERT(Utils::IsAligned(stream_.bytes_written(), 1143 instructions_.Add(InstructionsData(instructions));
1144 OS::PreferredCodeAlignment())); 1144 return offset;
1145 }
1145 1146
1146 intptr_t offset = stream_.bytes_written(); 1147
1147 stream_.WriteBytes(reinterpret_cast<uint8_t*>(instructions) - kHeapObjectTag, 1148 static void EnsureIdentifier(char* label) {
1148 instructions->Size()); 1149 for (char c = *label; c != '\0'; c = *++label) {
1149 return offset; 1150 if (((c >= 'a') && (c <= 'z')) ||
1151 ((c >= 'A') && (c <= 'Z')) ||
1152 ((c >= '0') && (c <= '9'))) {
1153 continue;
1154 }
1155 *label = '_';
1156 }
1157 }
1158
1159
1160 void InstructionsWriter::WriteAssembly() {
1161 Zone* Z = Thread::Current()->zone();
1162
1163 // Handlify collected raw pointers as building the names below
1164 // will allocate on the Dart heap.
1165 for (intptr_t i = 0; i < instructions_.length(); i++) {
1166 InstructionsData& data = instructions_[i];
1167 data.insns_ = &Instructions::Handle(Z, data.raw_insns_);
1168 ASSERT(data.raw_code_ != NULL);
1169 data.code_ = &Code::Handle(Z, data.raw_code_);
1170 }
1171
1172 stream_.Print(".text\n");
1173 stream_.Print(".globl _kInstructionsSnapshot\n");
1174 stream_.Print(".balign %" Pd ", 0\n", OS::PreferredCodeAlignment());
1175 stream_.Print("_kInstructionsSnapshot:\n");
1176
1177 Object& owner = Object::Handle(Z);
1178 String& str = String::Handle(Z);
1179
1180 for (intptr_t i = 0; i < instructions_.length(); i++) {
1181 const Instructions& insns = *instructions_[i].insns_;
1182 const Code& code = *instructions_[i].code_;
1183
1184 ASSERT(insns.raw()->Size() % sizeof(uint64_t) == 0);
1185
1186 {
1187 // 1. Write from the header to the entry point.
1188 NoSafepointScope no_safepoint;
1189 uword beginning = reinterpret_cast<uword>(insns.raw()) - kHeapObjectTag;
1190 uword entry = beginning + Instructions::HeaderSize();
1191
1192 ASSERT(Utils::IsAligned(beginning, sizeof(uint64_t)));
1193 ASSERT(Utils::IsAligned(entry, sizeof(uint64_t)));
1194
1195 for (uint64_t* cursor = reinterpret_cast<uint64_t*>(beginning);
1196 cursor < reinterpret_cast<uint64_t*>(entry);
1197 cursor++) {
1198 stream_.Print(".quad 0x%0.16" Px64 "\n", *cursor);
1199 }
1200 }
1201
1202 // 2. Write a label at the entry point.
1203 owner = code.owner();
1204 if (owner.IsNull()) {
1205 const char* name = StubCode::NameOfStub(insns.EntryPoint());
1206 stream_.Print("Precompiled_Stub_%s:\n", name);
1207 } else if (owner.IsClass()) {
1208 str = Class::Cast(owner).Name();
1209 const char* name = str.ToCString();
1210 EnsureIdentifier(const_cast<char*>(name));
1211 stream_.Print("Precompiled_AllocationStub_%s_%" Pd ":\n", name, i);
1212 } else if (owner.IsFunction()) {
1213 const char* name = Function::Cast(owner).ToQualifiedCString();
1214 EnsureIdentifier(const_cast<char*>(name));
1215 stream_.Print("Precompiled_%s_%" Pd ":\n", name, i);
1216 } else {
1217 UNREACHABLE();
1218 }
1219
1220 {
1221 // 3. Write from the entry point to the end.
1222 NoSafepointScope no_safepoint;
1223 uword beginning = reinterpret_cast<uword>(insns.raw()) - kHeapObjectTag;
1224 uword entry = beginning + Instructions::HeaderSize();
1225 uword end = beginning + insns.raw()->Size();
1226
1227 ASSERT(Utils::IsAligned(beginning, sizeof(uint64_t)));
1228 ASSERT(Utils::IsAligned(entry, sizeof(uint64_t)));
1229 ASSERT(Utils::IsAligned(end, sizeof(uint64_t)));
1230
1231 for (uint64_t* cursor = reinterpret_cast<uint64_t*>(entry);
1232 cursor < reinterpret_cast<uint64_t*>(end);
1233 cursor++) {
1234 stream_.Print(".quad 0x%0.16" Px64 "\n", *cursor);
1235 }
1236 }
1237 }
1150 } 1238 }
1151 1239
1152 1240
1153 RawInstructions* InstructionsReader::GetInstructionsAt(int32_t offset, 1241 RawInstructions* InstructionsReader::GetInstructionsAt(int32_t offset,
1154 uword expected_tags) { 1242 uword expected_tags) {
1155 ASSERT(Utils::IsAligned(offset, OS::PreferredCodeAlignment())); 1243 ASSERT(Utils::IsAligned(offset, OS::PreferredCodeAlignment()));
1156 1244
1157 RawInstructions* result = 1245 RawInstructions* result =
1158 reinterpret_cast<RawInstructions*>( 1246 reinterpret_cast<RawInstructions*>(
1159 reinterpret_cast<uword>(buffer_) + offset + kHeapObjectTag); 1247 reinterpret_cast<uword>(buffer_) + offset + kHeapObjectTag);
(...skipping 777 matching lines...) Expand 10 before | Expand all | Expand 10 after
1937 void FullSnapshotWriter::WriteFullSnapshot() { 2025 void FullSnapshotWriter::WriteFullSnapshot() {
1938 if (!vm_isolate_is_symbolic_) { 2026 if (!vm_isolate_is_symbolic_) {
1939 // TODO(asiva): Don't mutate object headers during serialization. 2027 // TODO(asiva): Don't mutate object headers during serialization.
1940 WritableVMIsolateScope scope(Thread::Current()); 2028 WritableVMIsolateScope scope(Thread::Current());
1941 2029
1942 if (vm_isolate_snapshot_buffer() != NULL) { 2030 if (vm_isolate_snapshot_buffer() != NULL) {
1943 WriteVmIsolateSnapshot(); 2031 WriteVmIsolateSnapshot();
1944 } 2032 }
1945 WriteIsolateFullSnapshot(); 2033 WriteIsolateFullSnapshot();
1946 2034
2035 instructions_writer_->WriteAssembly();
1947 instructions_snapshot_size_ = instructions_writer_->BytesWritten(); 2036 instructions_snapshot_size_ = instructions_writer_->BytesWritten();
1948 } else { 2037 } else {
1949 if (vm_isolate_snapshot_buffer() != NULL) { 2038 if (vm_isolate_snapshot_buffer() != NULL) {
1950 WriteVmIsolateSnapshot(); 2039 WriteVmIsolateSnapshot();
1951 } 2040 }
1952 WriteIsolateFullSnapshot(); 2041 WriteIsolateFullSnapshot();
1953 } 2042 }
1954 } 2043 }
1955 2044
1956 2045
(...skipping 742 matching lines...) Expand 10 before | Expand all | Expand 10 after
2699 NoSafepointScope no_safepoint; 2788 NoSafepointScope no_safepoint;
2700 WriteObject(obj.raw()); 2789 WriteObject(obj.raw());
2701 UnmarkAll(); 2790 UnmarkAll();
2702 } else { 2791 } else {
2703 ThrowException(exception_type(), exception_msg()); 2792 ThrowException(exception_type(), exception_msg());
2704 } 2793 }
2705 } 2794 }
2706 2795
2707 2796
2708 } // namespace dart 2797 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/snapshot.h ('k') | tools/precompilation/create_instructions_snapshot_assembly.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698