OLD | NEW |
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 917 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
928 virtual void VisitPointers(Object** start, Object** end) { | 928 virtual void VisitPointers(Object** start, Object** end) { |
929 for (Object** p = start; p < end; ++p) { | 929 for (Object** p = start; p < end; ++p) { |
930 if ((*p)->IsHeapObject()) { | 930 if ((*p)->IsHeapObject()) { |
931 offsets_.Add(reinterpret_cast<Address>(p) - obj_address_); | 931 offsets_.Add(reinterpret_cast<Address>(p) - obj_address_); |
932 Address a = serializer_->GetSavedAddress(HeapObject::cast(*p)); | 932 Address a = serializer_->GetSavedAddress(HeapObject::cast(*p)); |
933 addresses_.Add(a); | 933 addresses_.Add(a); |
934 } | 934 } |
935 } | 935 } |
936 } | 936 } |
937 | 937 |
| 938 // Do not assert that code targets have been converted to object pointers. |
| 939 virtual void BeginCodeIteration(Code* code) { |
| 940 } |
| 941 |
| 942 virtual void VisitCodeTarget(RelocInfo* rinfo) { |
| 943 ASSERT(RelocInfo::IsCodeTarget(rinfo->rmode())); |
| 944 Code* target = Code::GetCodeFromTargetAddress(rinfo->target_address()); |
| 945 Address encoded_target = serializer_->GetSavedAddress(target); |
| 946 offsets_.Add(rinfo->target_address_address() - obj_address_); |
| 947 addresses_.Add(encoded_target); |
| 948 } |
| 949 |
| 950 |
938 virtual void VisitExternalReferences(Address* start, Address* end) { | 951 virtual void VisitExternalReferences(Address* start, Address* end) { |
939 for (Address* p = start; p < end; ++p) { | 952 for (Address* p = start; p < end; ++p) { |
940 uint32_t code = reference_encoder_->Encode(*p); | 953 uint32_t code = reference_encoder_->Encode(*p); |
941 CHECK(*p == NULL ? code == 0 : code != 0); | 954 CHECK(*p == NULL ? code == 0 : code != 0); |
942 offsets_.Add(reinterpret_cast<Address>(p) - obj_address_); | 955 offsets_.Add(reinterpret_cast<Address>(p) - obj_address_); |
943 addresses_.Add(reinterpret_cast<Address>(code)); | 956 addresses_.Add(reinterpret_cast<Address>(code)); |
944 } | 957 } |
945 } | 958 } |
946 | 959 |
947 virtual void VisitRuntimeEntry(RelocInfo* rinfo) { | 960 virtual void VisitRuntimeEntry(RelocInfo* rinfo) { |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1086 roots_++; | 1099 roots_++; |
1087 // If the object was not just serialized, | 1100 // If the object was not just serialized, |
1088 // write its encoded address instead. | 1101 // write its encoded address instead. |
1089 if (!serialized) PutEncodedAddress(a); | 1102 if (!serialized) PutEncodedAddress(a); |
1090 } | 1103 } |
1091 } | 1104 } |
1092 root_ = root; | 1105 root_ = root; |
1093 } | 1106 } |
1094 | 1107 |
1095 | 1108 |
| 1109 void Serializer::VisitCodeTarget(RelocInfo* rinfo) { |
| 1110 ASSERT(RelocInfo::IsCodeTarget(rinfo->rmode())); |
| 1111 Code* target = Code::GetCodeFromTargetAddress(rinfo->target_address()); |
| 1112 bool serialized; |
| 1113 Encode(target, &serialized); |
| 1114 } |
| 1115 |
| 1116 |
1096 class GlobalHandlesRetriever: public ObjectVisitor { | 1117 class GlobalHandlesRetriever: public ObjectVisitor { |
1097 public: | 1118 public: |
1098 explicit GlobalHandlesRetriever(List<Object**>* handles) | 1119 explicit GlobalHandlesRetriever(List<Object**>* handles) |
1099 : global_handles_(handles) {} | 1120 : global_handles_(handles) {} |
1100 | 1121 |
1101 virtual void VisitPointers(Object** start, Object** end) { | 1122 virtual void VisitPointers(Object** start, Object** end) { |
1102 for (; start != end; ++start) { | 1123 for (; start != end; ++start) { |
1103 global_handles_->Add(start); | 1124 global_handles_->Add(start); |
1104 } | 1125 } |
1105 } | 1126 } |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1248 InstanceType type = map->instance_type(); | 1269 InstanceType type = map->instance_type(); |
1249 int size = obj->SizeFromMap(map); | 1270 int size = obj->SizeFromMap(map); |
1250 | 1271 |
1251 // Simulate the allocation of obj to predict where it will be | 1272 // Simulate the allocation of obj to predict where it will be |
1252 // allocated during deserialization. | 1273 // allocated during deserialization. |
1253 Address addr = Allocate(obj).Encode(); | 1274 Address addr = Allocate(obj).Encode(); |
1254 | 1275 |
1255 SaveAddress(obj, addr); | 1276 SaveAddress(obj, addr); |
1256 | 1277 |
1257 if (type == CODE_TYPE) { | 1278 if (type == CODE_TYPE) { |
1258 Code* code = Code::cast(obj); | 1279 LOG(CodeMoveEvent(obj->address(), addr)); |
1259 // Ensure Code objects contain Object pointers, not Addresses. | |
1260 code->ConvertICTargetsFromAddressToObject(); | |
1261 LOG(CodeMoveEvent(code->address(), addr)); | |
1262 } | 1280 } |
1263 | 1281 |
1264 // Write out the object prologue: type, size, and simulated address of obj. | 1282 // Write out the object prologue: type, size, and simulated address of obj. |
1265 writer_->PutC('['); | 1283 writer_->PutC('['); |
1266 CHECK_EQ(0, static_cast<int>(size & kObjectAlignmentMask)); | 1284 CHECK_EQ(0, static_cast<int>(size & kObjectAlignmentMask)); |
1267 writer_->PutInt(type); | 1285 writer_->PutInt(type); |
1268 writer_->PutInt(size >> kObjectAlignmentBits); | 1286 writer_->PutInt(size >> kObjectAlignmentBits); |
1269 PutEncodedAddress(addr); // encodes AllocationSpace | 1287 PutEncodedAddress(addr); // encodes AllocationSpace |
1270 | 1288 |
1271 // Visit all the pointers in the object other than the map. This | 1289 // Visit all the pointers in the object other than the map. This |
(...skipping 11 matching lines...) Expand all Loading... |
1283 updater.Update(writer_->position() - size); | 1301 updater.Update(writer_->position() - size); |
1284 | 1302 |
1285 #ifdef DEBUG | 1303 #ifdef DEBUG |
1286 if (FLAG_debug_serialization) { | 1304 if (FLAG_debug_serialization) { |
1287 // Write out the object epilogue to catch synchronization errors. | 1305 // Write out the object epilogue to catch synchronization errors. |
1288 PutEncodedAddress(addr); | 1306 PutEncodedAddress(addr); |
1289 writer_->PutC(']'); | 1307 writer_->PutC(']'); |
1290 } | 1308 } |
1291 #endif | 1309 #endif |
1292 | 1310 |
1293 if (type == CODE_TYPE) { | |
1294 Code* code = Code::cast(obj); | |
1295 // Convert relocations from Object* to Address in Code objects | |
1296 code->ConvertICTargetsFromObjectToAddress(); | |
1297 } | |
1298 | |
1299 objects_++; | 1311 objects_++; |
1300 return addr; | 1312 return addr; |
1301 } | 1313 } |
1302 | 1314 |
1303 | 1315 |
1304 RelativeAddress Serializer::Allocate(HeapObject* obj) { | 1316 RelativeAddress Serializer::Allocate(HeapObject* obj) { |
1305 // Find out which AllocationSpace 'obj' is in. | 1317 // Find out which AllocationSpace 'obj' is in. |
1306 AllocationSpace s; | 1318 AllocationSpace s; |
1307 bool found = false; | 1319 bool found = false; |
1308 for (int i = FIRST_SPACE; !found && i <= LAST_SPACE; i++) { | 1320 for (int i = FIRST_SPACE; !found && i <= LAST_SPACE; i++) { |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1415 } else { | 1427 } else { |
1416 // A pointer internal to a HeapObject that we've already | 1428 // A pointer internal to a HeapObject that we've already |
1417 // read: resolve it to a true address (or Smi) | 1429 // read: resolve it to a true address (or Smi) |
1418 *p = Resolve(reinterpret_cast<Address>(*p)); | 1430 *p = Resolve(reinterpret_cast<Address>(*p)); |
1419 } | 1431 } |
1420 } | 1432 } |
1421 root_ = root; | 1433 root_ = root; |
1422 } | 1434 } |
1423 | 1435 |
1424 | 1436 |
| 1437 void Deserializer::VisitCodeTarget(RelocInfo* rinfo) { |
| 1438 ASSERT(RelocInfo::IsCodeTarget(rinfo->rmode())); |
| 1439 Address encoded_address = reinterpret_cast<Address>(rinfo->target_object()); |
| 1440 Code* target_object = reinterpret_cast<Code*>(Resolve(encoded_address)); |
| 1441 rinfo->set_target_address(target_object->instruction_start()); |
| 1442 } |
| 1443 |
| 1444 |
1425 void Deserializer::VisitExternalReferences(Address* start, Address* end) { | 1445 void Deserializer::VisitExternalReferences(Address* start, Address* end) { |
1426 for (Address* p = start; p < end; ++p) { | 1446 for (Address* p = start; p < end; ++p) { |
1427 uint32_t code = static_cast<uint32_t>(reinterpret_cast<uintptr_t>(*p)); | 1447 uint32_t code = static_cast<uint32_t>(reinterpret_cast<uintptr_t>(*p)); |
1428 *p = reference_decoder_->Decode(code); | 1448 *p = reference_decoder_->Decode(code); |
1429 } | 1449 } |
1430 } | 1450 } |
1431 | 1451 |
1432 | 1452 |
1433 void Deserializer::VisitRuntimeEntry(RelocInfo* rinfo) { | 1453 void Deserializer::VisitRuntimeEntry(RelocInfo* rinfo) { |
1434 uint32_t* pc = reinterpret_cast<uint32_t*>(rinfo->target_address_address()); | 1454 uint32_t* pc = reinterpret_cast<uint32_t*>(rinfo->target_address_address()); |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1610 } | 1630 } |
1611 #endif | 1631 #endif |
1612 | 1632 |
1613 // Resolve the encoded pointers we just read in. | 1633 // Resolve the encoded pointers we just read in. |
1614 // Same as obj->Iterate(this), but doesn't rely on the map pointer being set. | 1634 // Same as obj->Iterate(this), but doesn't rely on the map pointer being set. |
1615 VisitPointer(reinterpret_cast<Object**>(obj->address())); | 1635 VisitPointer(reinterpret_cast<Object**>(obj->address())); |
1616 obj->IterateBody(type, size, this); | 1636 obj->IterateBody(type, size, this); |
1617 | 1637 |
1618 if (type == CODE_TYPE) { | 1638 if (type == CODE_TYPE) { |
1619 Code* code = Code::cast(obj); | 1639 Code* code = Code::cast(obj); |
1620 // Convert relocations from Object* to Address in Code objects | |
1621 code->ConvertICTargetsFromObjectToAddress(); | |
1622 LOG(CodeMoveEvent(a, code->address())); | 1640 LOG(CodeMoveEvent(a, code->address())); |
1623 } | 1641 } |
1624 objects_++; | 1642 objects_++; |
1625 return o; | 1643 return o; |
1626 } | 1644 } |
1627 | 1645 |
1628 | 1646 |
1629 static inline Object* ResolvePaged(int page_index, | 1647 static inline Object* ResolvePaged(int page_index, |
1630 int page_offset, | 1648 int page_offset, |
1631 PagedSpace* space, | 1649 PagedSpace* space, |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1694 ASSERT(index < large_objects_.length()); | 1712 ASSERT(index < large_objects_.length()); |
1695 } | 1713 } |
1696 return large_objects_[index]; // s.page_offset() is ignored. | 1714 return large_objects_[index]; // s.page_offset() is ignored. |
1697 } | 1715 } |
1698 UNREACHABLE(); | 1716 UNREACHABLE(); |
1699 return NULL; | 1717 return NULL; |
1700 } | 1718 } |
1701 | 1719 |
1702 | 1720 |
1703 } } // namespace v8::internal | 1721 } } // namespace v8::internal |
OLD | NEW |