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 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 library_(Library::Handle(zone_)), | 196 library_(Library::Handle(zone_)), |
197 type_(AbstractType::Handle(zone_)), | 197 type_(AbstractType::Handle(zone_)), |
198 type_arguments_(TypeArguments::Handle(zone_)), | 198 type_arguments_(TypeArguments::Handle(zone_)), |
199 tokens_(GrowableObjectArray::Handle(zone_)), | 199 tokens_(GrowableObjectArray::Handle(zone_)), |
200 stream_(TokenStream::Handle(zone_)), | 200 stream_(TokenStream::Handle(zone_)), |
201 data_(ExternalTypedData::Handle(zone_)), | 201 data_(ExternalTypedData::Handle(zone_)), |
202 typed_data_(TypedData::Handle(zone_)), | 202 typed_data_(TypedData::Handle(zone_)), |
203 code_(Code::Handle(zone_)), | 203 code_(Code::Handle(zone_)), |
204 function_(Function::Handle(zone_)), | 204 function_(Function::Handle(zone_)), |
205 megamorphic_cache_(MegamorphicCache::Handle(zone_)), | 205 megamorphic_cache_(MegamorphicCache::Handle(zone_)), |
| 206 object_pool_(ObjectPool::Handle(zone_)), |
206 error_(UnhandledException::Handle(zone_)), | 207 error_(UnhandledException::Handle(zone_)), |
207 max_vm_isolate_object_id_( | 208 max_vm_isolate_object_id_( |
208 (kind == Snapshot::kFull) ? | 209 (kind == Snapshot::kFull) ? |
209 Object::vm_isolate_snapshot_object_table().Length() : 0), | 210 Object::vm_isolate_snapshot_object_table().Length() : 0), |
210 backward_references_(backward_refs), | 211 backward_references_(backward_refs), |
211 instructions_reader_(NULL) { | 212 instructions_reader_(NULL) { |
212 if (instructions_buffer != NULL) { | 213 if (instructions_buffer != NULL) { |
213 instructions_reader_ = | 214 instructions_reader_ = |
214 new InstructionsReader(instructions_buffer, data_buffer); | 215 new InstructionsReader(instructions_buffer, data_buffer); |
215 } | 216 } |
(...skipping 919 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1135 } | 1136 } |
1136 return Mint::NewCanonical(value); | 1137 return Mint::NewCanonical(value); |
1137 } | 1138 } |
1138 | 1139 |
1139 | 1140 |
1140 RawStacktrace* SnapshotReader::NewStacktrace() { | 1141 RawStacktrace* SnapshotReader::NewStacktrace() { |
1141 ALLOC_NEW_OBJECT(Stacktrace); | 1142 ALLOC_NEW_OBJECT(Stacktrace); |
1142 } | 1143 } |
1143 | 1144 |
1144 | 1145 |
1145 int32_t InstructionsWriter::GetOffsetFor(RawInstructions* instructions) { | 1146 int32_t InstructionsWriter::GetOffsetFor(RawInstructions* instructions, |
1146 intptr_t heap_size = instructions->Size(); | 1147 RawCode* code) { |
| 1148 #if defined(PRODUCT) |
| 1149 // Instructions are only dedup in product mode because it obfuscates profiler |
| 1150 // results. |
| 1151 for (intptr_t i = 0; i < instructions_.length(); i++) { |
| 1152 if (instructions_[i].raw_insns_ == instructions) { |
| 1153 return instructions_[i].offset_; |
| 1154 } |
| 1155 } |
| 1156 #endif |
| 1157 |
| 1158 intptr_t payload_size = instructions->ptr()->size_; |
| 1159 payload_size = Utils::RoundUp(payload_size, OS::PreferredCodeAlignment()); |
| 1160 |
1147 intptr_t offset = next_offset_; | 1161 intptr_t offset = next_offset_; |
1148 next_offset_ += heap_size; | 1162 ASSERT(Utils::IsAligned(next_offset_, OS::PreferredCodeAlignment())); |
1149 instructions_.Add(InstructionsData(instructions)); | 1163 next_offset_ += payload_size; |
| 1164 ASSERT(Utils::IsAligned(next_offset_, OS::PreferredCodeAlignment())); |
| 1165 instructions_.Add(InstructionsData(instructions, code, offset)); |
| 1166 |
1150 return offset; | 1167 return offset; |
1151 } | 1168 } |
1152 | 1169 |
1153 | 1170 |
1154 int32_t InstructionsWriter::GetObjectOffsetFor(RawObject* raw_object) { | 1171 int32_t InstructionsWriter::GetObjectOffsetFor(RawObject* raw_object) { |
1155 intptr_t heap_size = raw_object->Size(); | 1172 intptr_t heap_size = raw_object->Size(); |
1156 intptr_t offset = next_object_offset_; | 1173 intptr_t offset = next_object_offset_; |
1157 next_object_offset_ += heap_size; | 1174 next_object_offset_ += heap_size; |
1158 objects_.Add(ObjectData(raw_object)); | 1175 objects_.Add(ObjectData(raw_object)); |
1159 return offset; | 1176 return offset; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1206 | 1223 |
1207 Object& owner = Object::Handle(zone); | 1224 Object& owner = Object::Handle(zone); |
1208 String& str = String::Handle(zone); | 1225 String& str = String::Handle(zone); |
1209 | 1226 |
1210 for (intptr_t i = 0; i < instructions_.length(); i++) { | 1227 for (intptr_t i = 0; i < instructions_.length(); i++) { |
1211 const Instructions& insns = *instructions_[i].insns_; | 1228 const Instructions& insns = *instructions_[i].insns_; |
1212 const Code& code = *instructions_[i].code_; | 1229 const Code& code = *instructions_[i].code_; |
1213 | 1230 |
1214 ASSERT(insns.raw()->Size() % sizeof(uint64_t) == 0); | 1231 ASSERT(insns.raw()->Size() % sizeof(uint64_t) == 0); |
1215 | 1232 |
1216 { | 1233 // 1. Write a label at the entry point. |
1217 // 1. Write from the header to the entry point. | |
1218 NoSafepointScope no_safepoint; | |
1219 | |
1220 uword beginning = reinterpret_cast<uword>(insns.raw_ptr()); | |
1221 uword entry = beginning + Instructions::HeaderSize(); | |
1222 | |
1223 ASSERT(Utils::IsAligned(beginning, sizeof(uint64_t))); | |
1224 ASSERT(Utils::IsAligned(entry, sizeof(uint64_t))); | |
1225 | |
1226 // Write Instructions with the mark and VM heap bits set. | |
1227 uword marked_tags = insns.raw_ptr()->tags_; | |
1228 marked_tags = RawObject::VMHeapObjectTag::update(true, marked_tags); | |
1229 marked_tags = RawObject::MarkBit::update(true, marked_tags); | |
1230 | |
1231 WriteWordLiteral(marked_tags); | |
1232 beginning += sizeof(uword); | |
1233 | |
1234 for (uword* cursor = reinterpret_cast<uword*>(beginning); | |
1235 cursor < reinterpret_cast<uword*>(entry); | |
1236 cursor++) { | |
1237 WriteWordLiteral(*cursor); | |
1238 } | |
1239 } | |
1240 | |
1241 // 2. Write a label at the entry point. | |
1242 owner = code.owner(); | 1234 owner = code.owner(); |
1243 if (owner.IsNull()) { | 1235 if (owner.IsNull()) { |
1244 const char* name = StubCode::NameOfStub(insns.EntryPoint()); | 1236 const char* name = StubCode::NameOfStub(insns.EntryPoint()); |
1245 stream_.Print("Precompiled_Stub_%s:\n", name); | 1237 stream_.Print("Precompiled_Stub_%s:\n", name); |
1246 } else if (owner.IsClass()) { | 1238 } else if (owner.IsClass()) { |
1247 str = Class::Cast(owner).Name(); | 1239 str = Class::Cast(owner).Name(); |
1248 const char* name = str.ToCString(); | 1240 const char* name = str.ToCString(); |
1249 EnsureIdentifier(const_cast<char*>(name)); | 1241 EnsureIdentifier(const_cast<char*>(name)); |
1250 stream_.Print("Precompiled_AllocationStub_%s_%" Pd ":\n", name, i); | 1242 stream_.Print("Precompiled_AllocationStub_%s_%" Pd ":\n", name, i); |
1251 } else if (owner.IsFunction()) { | 1243 } else if (owner.IsFunction()) { |
1252 const char* name = Function::Cast(owner).ToQualifiedCString(); | 1244 const char* name = Function::Cast(owner).ToQualifiedCString(); |
1253 EnsureIdentifier(const_cast<char*>(name)); | 1245 EnsureIdentifier(const_cast<char*>(name)); |
1254 stream_.Print("Precompiled_%s_%" Pd ":\n", name, i); | 1246 stream_.Print("Precompiled_%s_%" Pd ":\n", name, i); |
1255 } else { | 1247 } else { |
1256 UNREACHABLE(); | 1248 UNREACHABLE(); |
1257 } | 1249 } |
1258 | 1250 |
1259 { | 1251 { |
1260 // 3. Write from the entry point to the end. | 1252 // 3. Write from the entry point to the end. |
1261 NoSafepointScope no_safepoint; | 1253 NoSafepointScope no_safepoint; |
1262 uword beginning = reinterpret_cast<uword>(insns.raw()) - kHeapObjectTag; | 1254 uword beginning = reinterpret_cast<uword>(insns.raw()) - kHeapObjectTag; |
1263 uword entry = beginning + Instructions::HeaderSize(); | 1255 uword entry = beginning + Instructions::HeaderSize(); |
1264 uword end = beginning + insns.raw()->Size(); | 1256 uword payload_size = insns.size(); |
| 1257 payload_size = Utils::RoundUp(payload_size, OS::PreferredCodeAlignment()); |
| 1258 uword end = entry + payload_size; |
1265 | 1259 |
1266 ASSERT(Utils::IsAligned(beginning, sizeof(uint64_t))); | 1260 ASSERT(Utils::IsAligned(beginning, sizeof(uint64_t))); |
1267 ASSERT(Utils::IsAligned(entry, sizeof(uint64_t))); | 1261 ASSERT(Utils::IsAligned(entry, sizeof(uint64_t))); |
1268 ASSERT(Utils::IsAligned(end, sizeof(uint64_t))); | 1262 ASSERT(Utils::IsAligned(end, sizeof(uint64_t))); |
1269 | 1263 |
1270 for (uword* cursor = reinterpret_cast<uword*>(entry); | 1264 for (uword* cursor = reinterpret_cast<uword*>(entry); |
1271 cursor < reinterpret_cast<uword*>(end); | 1265 cursor < reinterpret_cast<uword*>(end); |
1272 cursor++) { | 1266 cursor++) { |
1273 WriteWordLiteral(*cursor); | 1267 WriteWordLiteral(*cursor); |
1274 } | 1268 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1306 start += sizeof(uword); | 1300 start += sizeof(uword); |
1307 for (uword* cursor = reinterpret_cast<uword*>(start); | 1301 for (uword* cursor = reinterpret_cast<uword*>(start); |
1308 cursor < reinterpret_cast<uword*>(end); | 1302 cursor < reinterpret_cast<uword*>(end); |
1309 cursor++) { | 1303 cursor++) { |
1310 WriteWordLiteral(*cursor); | 1304 WriteWordLiteral(*cursor); |
1311 } | 1305 } |
1312 } | 1306 } |
1313 } | 1307 } |
1314 | 1308 |
1315 | 1309 |
1316 RawInstructions* InstructionsReader::GetInstructionsAt(int32_t offset, | 1310 uword InstructionsReader::GetInstructionsAt(int32_t offset) { |
1317 uword expected_tags) { | |
1318 ASSERT(Utils::IsAligned(offset, OS::PreferredCodeAlignment())); | 1311 ASSERT(Utils::IsAligned(offset, OS::PreferredCodeAlignment())); |
1319 | 1312 return reinterpret_cast<uword>(instructions_buffer_) + offset; |
1320 RawInstructions* result = | |
1321 reinterpret_cast<RawInstructions*>( | |
1322 reinterpret_cast<uword>(instructions_buffer_) + | |
1323 offset + kHeapObjectTag); | |
1324 | |
1325 #ifdef DEBUG | |
1326 uword actual_tags = result->ptr()->tags_; | |
1327 if (actual_tags != expected_tags) { | |
1328 FATAL2("Instructions tag mismatch: expected %" Pd ", saw %" Pd, | |
1329 expected_tags, | |
1330 actual_tags); | |
1331 } | |
1332 #endif | |
1333 | |
1334 ASSERT(result->IsMarked()); | |
1335 | |
1336 return result; | |
1337 } | 1313 } |
1338 | 1314 |
1339 | 1315 |
1340 RawObject* InstructionsReader::GetObjectAt(int32_t offset) { | 1316 RawObject* InstructionsReader::GetObjectAt(int32_t offset) { |
1341 ASSERT(Utils::IsAligned(offset, kWordSize)); | 1317 ASSERT(Utils::IsAligned(offset, kWordSize)); |
1342 | 1318 |
1343 RawObject* result = | 1319 RawObject* result = |
1344 reinterpret_cast<RawObject*>( | 1320 reinterpret_cast<RawObject*>( |
1345 reinterpret_cast<uword>(data_buffer_) + offset + kHeapObjectTag); | 1321 reinterpret_cast<uword>(data_buffer_) + offset + kHeapObjectTag); |
1346 ASSERT(result->IsMarked()); | 1322 ASSERT(result->IsMarked()); |
(...skipping 1340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2687 if (setjmp(*jump.Set()) == 0) { | 2663 if (setjmp(*jump.Set()) == 0) { |
2688 NoSafepointScope no_safepoint; | 2664 NoSafepointScope no_safepoint; |
2689 WriteObject(obj.raw()); | 2665 WriteObject(obj.raw()); |
2690 } else { | 2666 } else { |
2691 ThrowException(exception_type(), exception_msg()); | 2667 ThrowException(exception_type(), exception_msg()); |
2692 } | 2668 } |
2693 } | 2669 } |
2694 | 2670 |
2695 | 2671 |
2696 } // namespace dart | 2672 } // namespace dart |
OLD | NEW |