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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
71 const int kPageBits = 32 - (kOffsetBits + kSpaceBits + kHeapObjectTagSize); | 71 const int kPageBits = 32 - (kOffsetBits + kSpaceBits + kHeapObjectTagSize); |
72 const int kPageShift = kOffsetShift + kOffsetBits; | 72 const int kPageShift = kOffsetShift + kOffsetBits; |
73 const int kPageMask = (1 << kPageBits) - 1; | 73 const int kPageMask = (1 << kPageBits) - 1; |
74 | 74 |
75 const int kPageAndOffsetShift = kOffsetShift; | 75 const int kPageAndOffsetShift = kOffsetShift; |
76 const int kPageAndOffsetBits = kPageBits + kOffsetBits; | 76 const int kPageAndOffsetBits = kPageBits + kOffsetBits; |
77 const int kPageAndOffsetMask = (1 << kPageAndOffsetBits) - 1; | 77 const int kPageAndOffsetMask = (1 << kPageAndOffsetBits) - 1; |
78 | 78 |
79 | 79 |
80 static inline AllocationSpace GetSpace(Address addr) { | 80 static inline AllocationSpace GetSpace(Address addr) { |
81 const int encoded = reinterpret_cast<int>(addr); | 81 const intptr_t encoded = reinterpret_cast<intptr_t>(addr); |
82 int space_number = ((encoded >> kSpaceShift) & kSpaceMask); | 82 int space_number = (static_cast<int>(encoded >> kSpaceShift) & kSpaceMask); |
83 if (space_number == kLOSpaceExecutable) space_number = LO_SPACE; | 83 if (space_number == kLOSpaceExecutable) space_number = LO_SPACE; |
84 else if (space_number == kLOSpacePointer) space_number = LO_SPACE; | 84 else if (space_number == kLOSpacePointer) space_number = LO_SPACE; |
85 return static_cast<AllocationSpace>(space_number); | 85 return static_cast<AllocationSpace>(space_number); |
86 } | 86 } |
87 | 87 |
88 | 88 |
89 static inline bool IsLargeExecutableObject(Address addr) { | 89 static inline bool IsLargeExecutableObject(Address addr) { |
90 const int encoded = reinterpret_cast<int>(addr); | 90 const intptr_t encoded = reinterpret_cast<intptr_t>(addr); |
91 const int space_number = ((encoded >> kSpaceShift) & kSpaceMask); | 91 const int space_number = |
92 if (space_number == kLOSpaceExecutable) return true; | 92 (static_cast<int>(encoded >> kSpaceShift) & kSpaceMask); |
93 return false; | 93 return (space_number == kLOSpaceExecutable); |
94 } | 94 } |
95 | 95 |
96 | 96 |
97 static inline bool IsLargeFixedArray(Address addr) { | 97 static inline bool IsLargeFixedArray(Address addr) { |
98 const int encoded = reinterpret_cast<int>(addr); | 98 const intptr_t encoded = reinterpret_cast<intptr_t>(addr); |
99 const int space_number = ((encoded >> kSpaceShift) & kSpaceMask); | 99 const int space_number = |
100 if (space_number == kLOSpacePointer) return true; | 100 (static_cast<int>(encoded >> kSpaceShift) & kSpaceMask); |
101 return false; | 101 return (space_number == kLOSpacePointer); |
102 } | 102 } |
103 | 103 |
104 | 104 |
105 static inline int PageIndex(Address addr) { | 105 static inline int PageIndex(Address addr) { |
106 const int encoded = reinterpret_cast<int>(addr); | 106 const intptr_t encoded = reinterpret_cast<intptr_t>(addr); |
107 return (encoded >> kPageShift) & kPageMask; | 107 return static_cast<int>(encoded >> kPageShift) & kPageMask; |
108 } | 108 } |
109 | 109 |
110 | 110 |
111 static inline int PageOffset(Address addr) { | 111 static inline int PageOffset(Address addr) { |
112 const int encoded = reinterpret_cast<int>(addr); | 112 const intptr_t encoded = reinterpret_cast<intptr_t>(addr); |
113 return ((encoded >> kOffsetShift) & kOffsetMask) << kObjectAlignmentBits; | 113 const int offset = static_cast<int>(encoded >> kOffsetShift) & kOffsetMask; |
114 return offset << kObjectAlignmentBits; | |
114 } | 115 } |
115 | 116 |
116 | 117 |
117 static inline int NewSpaceOffset(Address addr) { | 118 static inline int NewSpaceOffset(Address addr) { |
118 const int encoded = reinterpret_cast<int>(addr); | 119 const intptr_t encoded = reinterpret_cast<intptr_t>(addr); |
119 return ((encoded >> kPageAndOffsetShift) & kPageAndOffsetMask) << | 120 const int page_offset = |
120 kObjectAlignmentBits; | 121 static_cast<int>(encoded >> kPageAndOffsetShift) & kPageAndOffsetMask; |
122 return page_offset << kObjectAlignmentBits; | |
121 } | 123 } |
122 | 124 |
123 | 125 |
124 static inline int LargeObjectIndex(Address addr) { | 126 static inline int LargeObjectIndex(Address addr) { |
125 const int encoded = reinterpret_cast<int>(addr); | 127 const intptr_t encoded = reinterpret_cast<intptr_t>(addr); |
126 return (encoded >> kPageAndOffsetShift) & kPageAndOffsetMask; | 128 return static_cast<int>(encoded >> kPageAndOffsetShift) & kPageAndOffsetMask; |
127 } | 129 } |
128 | 130 |
129 | 131 |
130 // A RelativeAddress encodes a heap address that is independent of | 132 // A RelativeAddress encodes a heap address that is independent of |
131 // the actual memory addresses in real heap. The general case (for the | 133 // the actual memory addresses in real heap. The general case (for the |
132 // OLD, CODE and MAP spaces) is as a (space id, page number, page offset) | 134 // OLD, CODE and MAP spaces) is as a (space id, page number, page offset) |
133 // triple. The NEW space has page number == 0, because there are no | 135 // triple. The NEW space has page number == 0, because there are no |
134 // pages. The LARGE_OBJECT space has page offset = 0, since there is | 136 // pages. The LARGE_OBJECT space has page offset = 0, since there is |
135 // exactly one object per page. RelativeAddresses are encodable as | 137 // exactly one object per page. RelativeAddresses are encodable as |
136 // Addresses, so that they can replace the map() pointers of | 138 // Addresses, so that they can replace the map() pointers of |
(...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
721 const char* ExternalReferenceEncoder::NameOfAddress(Address key) const { | 723 const char* ExternalReferenceEncoder::NameOfAddress(Address key) const { |
722 int index = IndexOf(key); | 724 int index = IndexOf(key); |
723 return index >=0 ? ExternalReferenceTable::instance()->name(index) : NULL; | 725 return index >=0 ? ExternalReferenceTable::instance()->name(index) : NULL; |
724 } | 726 } |
725 | 727 |
726 | 728 |
727 int ExternalReferenceEncoder::IndexOf(Address key) const { | 729 int ExternalReferenceEncoder::IndexOf(Address key) const { |
728 if (key == NULL) return -1; | 730 if (key == NULL) return -1; |
729 HashMap::Entry* entry = | 731 HashMap::Entry* entry = |
730 const_cast<HashMap &>(encodings_).Lookup(key, Hash(key), false); | 732 const_cast<HashMap &>(encodings_).Lookup(key, Hash(key), false); |
731 return entry == NULL ? -1 : reinterpret_cast<int>(entry->value); | 733 return entry == NULL ? -1 : |
Kasper Lund
2009/05/07 11:48:54
I would put ? and : on separate lines like this:
| |
734 static_cast<int>(reinterpret_cast<intptr_t>(entry->value)); | |
732 } | 735 } |
733 | 736 |
734 | 737 |
735 void ExternalReferenceEncoder::Put(Address key, int index) { | 738 void ExternalReferenceEncoder::Put(Address key, int index) { |
736 HashMap::Entry* entry = encodings_.Lookup(key, Hash(key), true); | 739 HashMap::Entry* entry = encodings_.Lookup(key, Hash(key), true); |
737 entry->value = reinterpret_cast<void *>(index); | 740 entry->value = reinterpret_cast<void *>(index); |
738 } | 741 } |
739 | 742 |
740 | 743 |
741 ExternalReferenceDecoder::ExternalReferenceDecoder() | 744 ExternalReferenceDecoder::ExternalReferenceDecoder() |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
787 void Reserve(int bytes, int pos); | 790 void Reserve(int bytes, int pos); |
788 | 791 |
789 void PutC(char c) { | 792 void PutC(char c) { |
790 InsertC(c, len_); | 793 InsertC(c, len_); |
791 } | 794 } |
792 | 795 |
793 void PutInt(int i) { | 796 void PutInt(int i) { |
794 InsertInt(i, len_); | 797 InsertInt(i, len_); |
795 } | 798 } |
796 | 799 |
800 void PutAddress(Address p) { | |
801 PutBytes(reinterpret_cast<byte*>(&p), sizeof(p)); | |
802 } | |
803 | |
797 void PutBytes(const byte* a, int size) { | 804 void PutBytes(const byte* a, int size) { |
798 InsertBytes(a, len_, size); | 805 InsertBytes(a, len_, size); |
799 } | 806 } |
800 | 807 |
801 void PutString(const char* s) { | 808 void PutString(const char* s) { |
802 InsertString(s, len_); | 809 InsertString(s, len_); |
803 } | 810 } |
804 | 811 |
805 int InsertC(char c, int pos) { | 812 int InsertC(char c, int pos) { |
806 Reserve(1, pos); | 813 Reserve(1, pos); |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
907 Address obj_address_; | 914 Address obj_address_; |
908 Serializer* serializer_; | 915 Serializer* serializer_; |
909 ExternalReferenceEncoder* reference_encoder_; | 916 ExternalReferenceEncoder* reference_encoder_; |
910 List<int> offsets_; | 917 List<int> offsets_; |
911 List<Address> addresses_; | 918 List<Address> addresses_; |
912 }; | 919 }; |
913 | 920 |
914 | 921 |
915 // Helper functions for a map of encoded heap object addresses. | 922 // Helper functions for a map of encoded heap object addresses. |
916 static uint32_t HeapObjectHash(HeapObject* key) { | 923 static uint32_t HeapObjectHash(HeapObject* key) { |
917 return reinterpret_cast<uint32_t>(key) >> 2; | 924 uint32_t low32bits = static_cast<uint32_t>(reinterpret_cast<uintptr_t>(key)); |
925 return low32bits >> 2; | |
918 } | 926 } |
919 | 927 |
920 | 928 |
921 static bool MatchHeapObject(void* key1, void* key2) { | 929 static bool MatchHeapObject(void* key1, void* key2) { |
922 return key1 == key2; | 930 return key1 == key2; |
923 } | 931 } |
924 | 932 |
925 | 933 |
926 Serializer::Serializer() | 934 Serializer::Serializer() |
927 : global_handles_(4), | 935 : global_handles_(4), |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1146 } | 1154 } |
1147 for (int i = contexts.length() - 1; i >= 0; i--) { | 1155 for (int i = contexts.length() - 1; i >= 0; i--) { |
1148 HandleScopeImplementer::instance()->SaveContext(contexts[i]); | 1156 HandleScopeImplementer::instance()->SaveContext(contexts[i]); |
1149 } | 1157 } |
1150 PutGlobalHandleStack(contexts); | 1158 PutGlobalHandleStack(contexts); |
1151 } | 1159 } |
1152 | 1160 |
1153 | 1161 |
1154 void Serializer::PutEncodedAddress(Address addr) { | 1162 void Serializer::PutEncodedAddress(Address addr) { |
1155 writer_->PutC('P'); | 1163 writer_->PutC('P'); |
1156 writer_->PutInt(reinterpret_cast<int>(addr)); | 1164 writer_->PutAddress(addr); |
1157 } | 1165 } |
1158 | 1166 |
1159 | 1167 |
1160 Address Serializer::Encode(Object* o, bool* serialized) { | 1168 Address Serializer::Encode(Object* o, bool* serialized) { |
1161 *serialized = false; | 1169 *serialized = false; |
1162 if (o->IsSmi()) { | 1170 if (o->IsSmi()) { |
1163 return reinterpret_cast<Address>(o); | 1171 return reinterpret_cast<Address>(o); |
1164 } else { | 1172 } else { |
1165 HeapObject* obj = HeapObject::cast(o); | 1173 HeapObject* obj = HeapObject::cast(o); |
1166 if (IsVisited(obj)) { | 1174 if (IsVisited(obj)) { |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1329 for (Object** p = start; p < end; ++p) { | 1337 for (Object** p = start; p < end; ++p) { |
1330 if (root) { | 1338 if (root) { |
1331 roots_++; | 1339 roots_++; |
1332 // Read the next object or pointer from the stream | 1340 // Read the next object or pointer from the stream |
1333 // pointer in the stream. | 1341 // pointer in the stream. |
1334 int c = reader_.GetC(); | 1342 int c = reader_.GetC(); |
1335 if (c == '[') { | 1343 if (c == '[') { |
1336 *p = GetObject(); // embedded object | 1344 *p = GetObject(); // embedded object |
1337 } else { | 1345 } else { |
1338 ASSERT(c == 'P'); // pointer to previously serialized object | 1346 ASSERT(c == 'P'); // pointer to previously serialized object |
1339 *p = Resolve(reinterpret_cast<Address>(reader_.GetInt())); | 1347 *p = Resolve(reader_.GetAddress()); |
1340 } | 1348 } |
1341 } else { | 1349 } else { |
1342 // A pointer internal to a HeapObject that we've already | 1350 // A pointer internal to a HeapObject that we've already |
1343 // read: resolve it to a true address (or Smi) | 1351 // read: resolve it to a true address (or Smi) |
1344 *p = Resolve(reinterpret_cast<Address>(*p)); | 1352 *p = Resolve(reinterpret_cast<Address>(*p)); |
1345 } | 1353 } |
1346 } | 1354 } |
1347 root_ = root; | 1355 root_ = root; |
1348 } | 1356 } |
1349 | 1357 |
1350 | 1358 |
1351 void Deserializer::VisitExternalReferences(Address* start, Address* end) { | 1359 void Deserializer::VisitExternalReferences(Address* start, Address* end) { |
1352 for (Address* p = start; p < end; ++p) { | 1360 for (Address* p = start; p < end; ++p) { |
1353 uint32_t code = reinterpret_cast<uint32_t>(*p); | 1361 uint32_t code = static_cast<uint32_t>(reinterpret_cast<uintptr_t>(*p)); |
1354 *p = reference_decoder_->Decode(code); | 1362 *p = reference_decoder_->Decode(code); |
1355 } | 1363 } |
1356 } | 1364 } |
1357 | 1365 |
1358 | 1366 |
1359 void Deserializer::VisitRuntimeEntry(RelocInfo* rinfo) { | 1367 void Deserializer::VisitRuntimeEntry(RelocInfo* rinfo) { |
1360 uint32_t* pc = reinterpret_cast<uint32_t*>(rinfo->target_address_address()); | 1368 uint32_t* pc = reinterpret_cast<uint32_t*>(rinfo->target_address_address()); |
1361 uint32_t encoding = *pc; | 1369 uint32_t encoding = *pc; |
1362 Address target = reference_decoder_->Decode(encoding); | 1370 Address target = reference_decoder_->Decode(encoding); |
1363 rinfo->set_target_address(target); | 1371 rinfo->set_target_address(target); |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1469 List<Handle<Object> > entered_contexts(2); | 1477 List<Handle<Object> > entered_contexts(2); |
1470 GetGlobalHandleStack(&entered_contexts); | 1478 GetGlobalHandleStack(&entered_contexts); |
1471 for (int i = 0; i < entered_contexts.length(); i++) { | 1479 for (int i = 0; i < entered_contexts.length(); i++) { |
1472 HandleScopeImplementer::instance()->SaveContext(entered_contexts[i]); | 1480 HandleScopeImplementer::instance()->SaveContext(entered_contexts[i]); |
1473 } | 1481 } |
1474 } | 1482 } |
1475 | 1483 |
1476 | 1484 |
1477 Address Deserializer::GetEncodedAddress() { | 1485 Address Deserializer::GetEncodedAddress() { |
1478 reader_.ExpectC('P'); | 1486 reader_.ExpectC('P'); |
1479 return reinterpret_cast<Address>(reader_.GetInt()); | 1487 return reader_.GetAddress(); |
1480 } | 1488 } |
1481 | 1489 |
1482 | 1490 |
1483 Object* Deserializer::GetObject() { | 1491 Object* Deserializer::GetObject() { |
1484 // Read the prologue: type, size and encoded address. | 1492 // Read the prologue: type, size and encoded address. |
1485 InstanceType type = static_cast<InstanceType>(reader_.GetInt()); | 1493 InstanceType type = static_cast<InstanceType>(reader_.GetInt()); |
1486 int size = reader_.GetInt() << kObjectAlignmentBits; | 1494 int size = reader_.GetInt() << kObjectAlignmentBits; |
1487 Address a = GetEncodedAddress(); | 1495 Address a = GetEncodedAddress(); |
1488 | 1496 |
1489 // Get a raw object of the right size in the right space. | 1497 // Get a raw object of the right size in the right space. |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1603 ASSERT(index < large_objects_.length()); | 1611 ASSERT(index < large_objects_.length()); |
1604 } | 1612 } |
1605 return large_objects_[index]; // s.page_offset() is ignored. | 1613 return large_objects_[index]; // s.page_offset() is ignored. |
1606 } | 1614 } |
1607 UNREACHABLE(); | 1615 UNREACHABLE(); |
1608 return NULL; | 1616 return NULL; |
1609 } | 1617 } |
1610 | 1618 |
1611 | 1619 |
1612 } } // namespace v8::internal | 1620 } } // namespace v8::internal |
OLD | NEW |