Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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') continue; |
| 1151 if (c >= 'A' && c <= 'Z') continue; | |
| 1152 if (c >= '0' && c <= '9') continue; | |
|
siva
2015/09/04 20:34:04
why not :
if (((c >= 'a') && (c <= 'z')) ||
(
rmacnak
2015/09/04 22:11:56
Done.
| |
| 1153 *label = '_'; | |
| 1154 } | |
| 1155 } | |
| 1156 | |
| 1157 | |
| 1158 void InstructionsWriter::WriteAssembly() { | |
| 1159 Zone* Z = Thread::Current()->zone(); | |
| 1160 | |
| 1161 // Handlify collected raw pointers as the building the names below | |
|
siva
2015/09/04 20:34:04
as building the names
rmacnak
2015/09/04 22:11:57
Done.
| |
| 1162 // will allocate on the Dart heap. | |
| 1163 for (intptr_t i = 0; i < instructions_.length(); i++) { | |
| 1164 InstructionsData& data = instructions_[i]; | |
| 1165 data.insns_ = &Instructions::Handle(Z, data.raw_insns_); | |
| 1166 ASSERT(data.raw_code_ != NULL); | |
| 1167 data.code_ = &Code::Handle(Z, data.raw_code_); | |
| 1168 } | |
| 1169 | |
| 1170 stream_.Print(".text\n"); | |
| 1171 stream_.Print(".globl _kInstructionsSnapshot\n"); | |
| 1172 stream_.Print(".balign %" Pd ", 0\n", OS::PreferredCodeAlignment()); | |
| 1173 stream_.Print("_kInstructionsSnapshot:\n"); | |
| 1174 | |
| 1175 Object& owner = Object::Handle(Z); | |
| 1176 String& str = String::Handle(Z); | |
| 1177 | |
| 1178 for (intptr_t i = 0; i < instructions_.length(); i++) { | |
| 1179 const Instructions& insns = *instructions_[i].insns_; | |
| 1180 const Code& code = *instructions_[i].code_; | |
|
siva
2015/09/04 20:34:04
Why do you have that additional loop on top to cre
rmacnak
2015/09/04 22:11:57
As discussed offline, GC can happen in the middle
| |
| 1181 | |
| 1182 ASSERT(insns.raw()->Size() % sizeof(uint64_t) == 0); | |
| 1183 | |
| 1184 { | |
| 1185 // 1. Write from the header to the entry point. | |
| 1186 NoSafepointScope no_safepoint; | |
| 1187 uword beginning = reinterpret_cast<uword>(insns.raw()) - kHeapObjectTag; | |
| 1188 uword entry = beginning + Instructions::HeaderSize(); | |
| 1189 | |
| 1190 ASSERT(Utils::IsAligned(beginning, sizeof(uint64_t))); | |
| 1191 ASSERT(Utils::IsAligned(entry, sizeof(uint64_t))); | |
| 1192 | |
| 1193 for (uint64_t* cursor = reinterpret_cast<uint64_t*>(beginning); | |
| 1194 cursor < reinterpret_cast<uint64_t*>(entry); | |
| 1195 cursor++) { | |
| 1196 stream_.Print(".quad 0x%0.16" Px64 "\n", *cursor); | |
| 1197 } | |
| 1198 } | |
| 1199 | |
| 1200 // 2. Write a label at the entry point. | |
| 1201 owner = code.owner(); | |
| 1202 if (owner.IsNull()) { | |
| 1203 const char* name = StubCode::NameOfStub(insns.EntryPoint()); | |
| 1204 stream_.Print("Precompiled_Stub_%s:\n", name); | |
| 1205 } else if (owner.IsClass()) { | |
| 1206 str = Class::Cast(owner).Name(); | |
| 1207 const char* name = str.ToCString(); | |
| 1208 EnsureIdentifier(const_cast<char*>(name)); | |
| 1209 stream_.Print("Precompiled_AllocationStub_%s_%" Pd ":\n", name, i); | |
| 1210 } else if (owner.IsFunction()) { | |
| 1211 const char* name = Function::Cast(owner).ToQualifiedCString(); | |
| 1212 EnsureIdentifier(const_cast<char*>(name)); | |
| 1213 stream_.Print("Precompiled_%s_%" Pd ":\n", name, i); | |
| 1214 } else { | |
| 1215 UNREACHABLE(); | |
| 1216 } | |
| 1217 | |
| 1218 { | |
| 1219 // 3. Write from the entry point to the end. | |
| 1220 NoSafepointScope no_safepoint; | |
| 1221 uword beginning = reinterpret_cast<uword>(insns.raw()) - kHeapObjectTag; | |
| 1222 uword entry = beginning + Instructions::HeaderSize(); | |
| 1223 uword end = beginning + insns.raw()->Size(); | |
| 1224 | |
| 1225 ASSERT(Utils::IsAligned(beginning, sizeof(uint64_t))); | |
| 1226 ASSERT(Utils::IsAligned(entry, sizeof(uint64_t))); | |
| 1227 ASSERT(Utils::IsAligned(end, sizeof(uint64_t))); | |
|
siva
2015/09/04 20:34:04
are these assertions valid for all architectures i
rmacnak
2015/09/04 22:11:56
The minimum OS::PreferredCodeAlignment() is 16.
| |
| 1228 | |
| 1229 for (uint64_t* cursor = reinterpret_cast<uint64_t*>(entry); | |
| 1230 cursor < reinterpret_cast<uint64_t*>(end); | |
| 1231 cursor++) { | |
| 1232 stream_.Print(".quad 0x%0.16" Px64 "\n", *cursor); | |
| 1233 } | |
| 1234 } | |
| 1235 } | |
| 1150 } | 1236 } |
| 1151 | 1237 |
| 1152 | 1238 |
| 1153 RawInstructions* InstructionsReader::GetInstructionsAt(int32_t offset, | 1239 RawInstructions* InstructionsReader::GetInstructionsAt(int32_t offset, |
| 1154 uword expected_tags) { | 1240 uword expected_tags) { |
| 1155 ASSERT(Utils::IsAligned(offset, OS::PreferredCodeAlignment())); | 1241 ASSERT(Utils::IsAligned(offset, OS::PreferredCodeAlignment())); |
| 1156 | 1242 |
| 1157 RawInstructions* result = | 1243 RawInstructions* result = |
| 1158 reinterpret_cast<RawInstructions*>( | 1244 reinterpret_cast<RawInstructions*>( |
| 1159 reinterpret_cast<uword>(buffer_) + offset + kHeapObjectTag); | 1245 reinterpret_cast<uword>(buffer_) + offset + kHeapObjectTag); |
| (...skipping 777 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1937 void FullSnapshotWriter::WriteFullSnapshot() { | 2023 void FullSnapshotWriter::WriteFullSnapshot() { |
| 1938 if (!vm_isolate_is_symbolic_) { | 2024 if (!vm_isolate_is_symbolic_) { |
| 1939 // TODO(asiva): Don't mutate object headers during serialization. | 2025 // TODO(asiva): Don't mutate object headers during serialization. |
| 1940 WritableVMIsolateScope scope(Thread::Current()); | 2026 WritableVMIsolateScope scope(Thread::Current()); |
| 1941 | 2027 |
| 1942 if (vm_isolate_snapshot_buffer() != NULL) { | 2028 if (vm_isolate_snapshot_buffer() != NULL) { |
| 1943 WriteVmIsolateSnapshot(); | 2029 WriteVmIsolateSnapshot(); |
| 1944 } | 2030 } |
| 1945 WriteIsolateFullSnapshot(); | 2031 WriteIsolateFullSnapshot(); |
| 1946 | 2032 |
| 2033 instructions_writer_->WriteAssembly(); | |
| 1947 instructions_snapshot_size_ = instructions_writer_->BytesWritten(); | 2034 instructions_snapshot_size_ = instructions_writer_->BytesWritten(); |
| 1948 } else { | 2035 } else { |
| 1949 if (vm_isolate_snapshot_buffer() != NULL) { | 2036 if (vm_isolate_snapshot_buffer() != NULL) { |
| 1950 WriteVmIsolateSnapshot(); | 2037 WriteVmIsolateSnapshot(); |
| 1951 } | 2038 } |
| 1952 WriteIsolateFullSnapshot(); | 2039 WriteIsolateFullSnapshot(); |
| 1953 } | 2040 } |
| 1954 } | 2041 } |
| 1955 | 2042 |
| 1956 | 2043 |
| (...skipping 742 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2699 NoSafepointScope no_safepoint; | 2786 NoSafepointScope no_safepoint; |
| 2700 WriteObject(obj.raw()); | 2787 WriteObject(obj.raw()); |
| 2701 UnmarkAll(); | 2788 UnmarkAll(); |
| 2702 } else { | 2789 } else { |
| 2703 ThrowException(exception_type(), exception_msg()); | 2790 ThrowException(exception_type(), exception_msg()); |
| 2704 } | 2791 } |
| 2705 } | 2792 } |
| 2706 | 2793 |
| 2707 | 2794 |
| 2708 } // namespace dart | 2795 } // namespace dart |
| OLD | NEW |