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

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

Issue 1190143003: Fix for issue 23647 (https://github.com/dart-lang/sdk/issues/23647) (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Address self review comments Created 5 years, 6 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') | 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 "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 1264 matching lines...) Expand 10 before | Expand all | Expand 10 after
1275 can_send_any_object_(can_send_any_object) { 1275 can_send_any_object_(can_send_any_object) {
1276 ASSERT(forward_list_ != NULL); 1276 ASSERT(forward_list_ != NULL);
1277 } 1277 }
1278 1278
1279 1279
1280 void SnapshotWriter::WriteObject(RawObject* rawobj) { 1280 void SnapshotWriter::WriteObject(RawObject* rawobj) {
1281 WriteObjectImpl(rawobj); 1281 WriteObjectImpl(rawobj);
1282 WriteForwardedObjects(); 1282 WriteForwardedObjects();
1283 } 1283 }
1284 1284
1285 #define VM_OBJECT_CLASS_LIST(V) \
1286 V(OneByteString) \
1287 V(Mint) \
1288 V(Bigint) \
1289 V(Double) \
1290
1291 #define VM_OBJECT_WRITE(clazz) \
1292 case clazz::kClassId: { \
1293 object_id = forward_list_->AddObject(rawobj, kIsSerialized); \
1294 Raw##clazz* raw_obj = reinterpret_cast<Raw##clazz*>(rawobj); \
1295 raw_obj->WriteTo(this, object_id, kind()); \
1296 return; \
1297 } \
1285 1298
1286 void SnapshotWriter::HandleVMIsolateObject(RawObject* rawobj) { 1299 void SnapshotWriter::HandleVMIsolateObject(RawObject* rawobj) {
1287 // Check if it is a singleton null object. 1300 // Check if it is a singleton null object.
1288 if (rawobj == Object::null()) { 1301 if (rawobj == Object::null()) {
1289 WriteVMIsolateObject(kNullObject); 1302 WriteVMIsolateObject(kNullObject);
1290 return; 1303 return;
1291 } 1304 }
1292 1305
1293 // Check if it is a singleton sentinel object. 1306 // Check if it is a singleton sentinel object.
1294 if (rawobj == Object::sentinel().raw()) { 1307 if (rawobj == Object::sentinel().raw()) {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1338 if (id == kClassCid) { 1351 if (id == kClassCid) {
1339 RawClass* raw_class = reinterpret_cast<RawClass*>(rawobj); 1352 RawClass* raw_class = reinterpret_cast<RawClass*>(rawobj);
1340 intptr_t class_id = raw_class->ptr()->id_; 1353 intptr_t class_id = raw_class->ptr()->id_;
1341 if (IsSingletonClassId(class_id)) { 1354 if (IsSingletonClassId(class_id)) {
1342 intptr_t object_id = ObjectIdFromClassId(class_id); 1355 intptr_t object_id = ObjectIdFromClassId(class_id);
1343 WriteVMIsolateObject(object_id); 1356 WriteVMIsolateObject(object_id);
1344 return; 1357 return;
1345 } 1358 }
1346 } 1359 }
1347 1360
1348 // Check it is a predefined symbol in the VM isolate. 1361 if (kind() == Snapshot::kFull) {
1349 id = Symbols::LookupVMSymbol(rawobj); 1362 // Check it is a predefined symbol in the VM isolate.
1350 if (id != kInvalidIndex) { 1363 id = Symbols::LookupVMSymbol(rawobj);
1351 WriteVMIsolateObject(id); 1364 if (id != kInvalidIndex) {
1352 return; 1365 WriteVMIsolateObject(id);
1353 } 1366 return;
1367 }
1354 1368
1355 // Check if it is an object from the vm isolate snapshot object table. 1369 // Check if it is an object from the vm isolate snapshot object table.
1356 id = FindVmSnapshotObject(rawobj); 1370 id = FindVmSnapshotObject(rawobj);
1357 if (id != kInvalidIndex) { 1371 if (id != kInvalidIndex) {
1358 WriteIndexedObject(id); 1372 WriteIndexedObject(id);
1359 return; 1373 return;
1374 }
1375 } else {
1376 // In the case of script snapshots or for messages we do not use
1377 // the index into the vm isolate snapshot object table, instead we
1378 // explicitly write the object out.
1379 intptr_t object_id = forward_list_->FindObject(rawobj);
1380 if (object_id != -1) {
rmacnak 2015/06/18 20:34:55 kInvalidIndex
1381 WriteIndexedObject(object_id);
1382 return;
1383 } else {
1384 switch (id) {
1385 VM_OBJECT_CLASS_LIST(VM_OBJECT_WRITE)
1386 case kTypedDataUint32ArrayCid: {
1387 object_id = forward_list_->AddObject(rawobj, kIsSerialized);
1388 RawTypedData* raw_obj = reinterpret_cast<RawTypedData*>(rawobj);
1389 raw_obj->WriteTo(this, object_id, kind());
1390 return;
1391 }
1392 default:
1393 OS::Print("class id = %d\n", id);
1394 break;
1395 }
1396 }
1360 } 1397 }
1361 UNREACHABLE(); 1398 UNREACHABLE();
1362 } 1399 }
1363 1400
1401 #undef VM_OBJECT_WRITE
1402
1364 1403
1365 void SnapshotWriter::WriteObjectRef(RawObject* raw) { 1404 void SnapshotWriter::WriteObjectRef(RawObject* raw) {
1366 // First check if object can be written as a simple predefined type. 1405 // First check if object can be written as a simple predefined type.
1367 if (CheckAndWritePredefinedObject(raw)) { 1406 if (CheckAndWritePredefinedObject(raw)) {
1368 return; 1407 return;
1369 } 1408 }
1370 1409
1371 NoSafepointScope no_safepoint; 1410 NoSafepointScope no_safepoint;
1372 RawClass* cls = class_table_->At(raw->GetClassId()); 1411 RawClass* cls = class_table_->At(raw->GetClassId());
1373 intptr_t class_id = cls->ptr()->id_; 1412 intptr_t class_id = cls->ptr()->id_;
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
1688 uword tags = raw->ptr()->tags_; 1727 uword tags = raw->ptr()->tags_;
1689 ASSERT(SerializedHeaderTag::decode(tags) != kObjectId); 1728 ASSERT(SerializedHeaderTag::decode(tags) != kObjectId);
1690 raw->ptr()->tags_ = value; 1729 raw->ptr()->tags_ = value;
1691 Node* node = new Node(raw, tags, state); 1730 Node* node = new Node(raw, tags, state);
1692 ASSERT(node != NULL); 1731 ASSERT(node != NULL);
1693 nodes_.Add(node); 1732 nodes_.Add(node);
1694 return object_id; 1733 return object_id;
1695 } 1734 }
1696 1735
1697 1736
1737 intptr_t ForwardList::AddObject(RawObject* raw, SerializeState state) {
1738 NoSafepointScope no_safepoint;
1739 intptr_t object_id = next_object_id();
1740 ASSERT(object_id > 0 && object_id <= kMaxObjectId);
1741 uword tags = raw->ptr()->tags_;
1742 // OS::Print("tags = 0x%x\n", tags);
rmacnak 2015/06/18 20:34:55 slip
1743 ASSERT(SerializedHeaderTag::decode(tags) != kObjectId);
1744 Node* node = new Node(raw, tags, state);
1745 ASSERT(node != NULL);
1746 nodes_.Add(node);
1747 return object_id;
1748 }
1749
1750
1751 intptr_t ForwardList::FindObject(RawObject* raw) {
1752 NoSafepointScope no_safepoint;
1753 intptr_t id;
1754 for (id = first_object_id(); id < next_object_id(); ++id) {
1755 const Node* node = NodeForObjectId(id);
1756 if (raw == node->raw()) {
1757 return id;
1758 }
1759 }
1760 return kInvalidIndex;
1761 }
1762
1763
1698 void ForwardList::UnmarkAll() const { 1764 void ForwardList::UnmarkAll() const {
1699 for (intptr_t id = first_object_id(); id < next_object_id(); ++id) { 1765 for (intptr_t id = first_object_id(); id < next_object_id(); ++id) {
1700 const Node* node = NodeForObjectId(id); 1766 const Node* node = NodeForObjectId(id);
1701 RawObject* raw = node->raw(); 1767 RawObject* raw = node->raw();
1702 raw->ptr()->tags_ = node->tags(); // Restore original tags. 1768 if (SerializedHeaderTag::decode(raw->ptr()->tags_) == kObjectId) {
1769 raw->ptr()->tags_ = node->tags(); // Restore original tags.
1770 }
1703 } 1771 }
1704 Isolate::Current()->DecrementNoSafepointScopeDepth(); 1772 Isolate::Current()->DecrementNoSafepointScopeDepth();
1705 } 1773 }
1706 1774
1707 1775
1708 bool SnapshotWriter::CheckAndWritePredefinedObject(RawObject* rawobj) { 1776 bool SnapshotWriter::CheckAndWritePredefinedObject(RawObject* rawobj) {
1709 // Check if object can be written in one of the following ways: 1777 // Check if object can be written in one of the following ways:
1710 // - Smi: the Smi value is written as is (last bit is not tagged). 1778 // - Smi: the Smi value is written as is (last bit is not tagged).
1711 // - VM internal class (from VM isolate): (index of class in vm isolate | 0x3) 1779 // - VM internal class (from VM isolate): (index of class in vm isolate | 0x3)
1712 // - Object that has already been written: (negative id in stream | 0x3) 1780 // - Object that has already been written: (negative id in stream | 0x3)
(...skipping 561 matching lines...) Expand 10 before | Expand all | Expand 10 after
2274 NoSafepointScope no_safepoint; 2342 NoSafepointScope no_safepoint;
2275 WriteObject(obj.raw()); 2343 WriteObject(obj.raw());
2276 UnmarkAll(); 2344 UnmarkAll();
2277 } else { 2345 } else {
2278 ThrowException(exception_type(), exception_msg()); 2346 ThrowException(exception_type(), exception_msg());
2279 } 2347 }
2280 } 2348 }
2281 2349
2282 2350
2283 } // namespace dart 2351 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/snapshot.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698