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