| 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 26 matching lines...) Expand all Loading... |
| 37 #include "runtime.h" | 37 #include "runtime.h" |
| 38 #include "serialize.h" | 38 #include "serialize.h" |
| 39 #include "stub-cache.h" | 39 #include "stub-cache.h" |
| 40 #include "v8threads.h" | 40 #include "v8threads.h" |
| 41 | 41 |
| 42 namespace v8 { | 42 namespace v8 { |
| 43 namespace internal { | 43 namespace internal { |
| 44 | 44 |
| 45 // Encoding: a RelativeAddress must be able to fit in a pointer: | 45 // Encoding: a RelativeAddress must be able to fit in a pointer: |
| 46 // it is encoded as an Address with (from MS to LS bits): | 46 // it is encoded as an Address with (from MS to LS bits): |
| 47 // 27 bits identifying a word in the space, in one of three formats: | 47 // 26 bits identifying a word in the space, in one of three formats: |
| 48 // - MAP and OLD spaces: 16 bits of page number, 11 bits of word offset in page | 48 // - MAP and OLD spaces: 15 bits of page number, 11 bits of word offset in page |
| 49 // - NEW space: 27 bits of word offset | 49 // - NEW space: 26 bits of word offset |
| 50 // - LO space: 27 bits of page number | 50 // - LO space: 26 bits of page number |
| 51 // 3 bits to encode the AllocationSpace (special values for code in LO space) | 51 // 4 bits to encode the AllocationSpace (special values for code in LO space) |
| 52 // 2 bits identifying this as a HeapObject | 52 // 2 bits identifying this as a HeapObject |
| 53 | 53 |
| 54 const int kSpaceShift = kHeapObjectTagSize; | 54 const int kSpaceShift = kHeapObjectTagSize; |
| 55 const int kSpaceBits = kSpaceTagSize; | 55 const int kSpaceBits = kSpaceTagSize; |
| 56 const int kSpaceMask = kSpaceTagMask; | 56 const int kSpaceMask = kSpaceTagMask; |
| 57 | 57 |
| 58 // These value are used instead of space numbers when serializing/ | 58 // These value are used instead of space numbers when serializing/ |
| 59 // deserializing. They indicate an object that is in large object space, but | 59 // deserializing. They indicate an object that is in large object space, but |
| 60 // should be treated specially. | 60 // should be treated specially. |
| 61 // Make the pages executable on platforms that support it: | 61 // Make the pages executable on platforms that support it: |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 if (space_ == kLOSpacePointer) return LO_SPACE; | 158 if (space_ == kLOSpacePointer) return LO_SPACE; |
| 159 return static_cast<AllocationSpace>(space_); | 159 return static_cast<AllocationSpace>(space_); |
| 160 } | 160 } |
| 161 int page_index() const { return page_index_; } | 161 int page_index() const { return page_index_; } |
| 162 int page_offset() const { return page_offset_; } | 162 int page_offset() const { return page_offset_; } |
| 163 | 163 |
| 164 bool in_paged_space() const { | 164 bool in_paged_space() const { |
| 165 return space_ == CODE_SPACE || | 165 return space_ == CODE_SPACE || |
| 166 space_ == OLD_POINTER_SPACE || | 166 space_ == OLD_POINTER_SPACE || |
| 167 space_ == OLD_DATA_SPACE || | 167 space_ == OLD_DATA_SPACE || |
| 168 space_ == MAP_SPACE; | 168 space_ == MAP_SPACE || |
| 169 space_ == GLOBAL_PROPERTY_CELL_SPACE; |
| 169 } | 170 } |
| 170 | 171 |
| 171 void next_address(int offset) { page_offset_ += offset; } | 172 void next_address(int offset) { page_offset_ += offset; } |
| 172 void next_page(int init_offset = 0) { | 173 void next_page(int init_offset = 0) { |
| 173 page_index_++; | 174 page_index_++; |
| 174 page_offset_ = init_offset; | 175 page_offset_ = init_offset; |
| 175 } | 176 } |
| 176 | 177 |
| 177 #ifdef DEBUG | 178 #ifdef DEBUG |
| 178 void Verify(); | 179 void Verify(); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 194 int page_offset_; | 195 int page_offset_; |
| 195 }; | 196 }; |
| 196 | 197 |
| 197 | 198 |
| 198 Address RelativeAddress::Encode() const { | 199 Address RelativeAddress::Encode() const { |
| 199 ASSERT(page_index_ >= 0); | 200 ASSERT(page_index_ >= 0); |
| 200 int word_offset = 0; | 201 int word_offset = 0; |
| 201 int result = 0; | 202 int result = 0; |
| 202 switch (space_) { | 203 switch (space_) { |
| 203 case MAP_SPACE: | 204 case MAP_SPACE: |
| 205 case GLOBAL_PROPERTY_CELL_SPACE: |
| 204 case OLD_POINTER_SPACE: | 206 case OLD_POINTER_SPACE: |
| 205 case OLD_DATA_SPACE: | 207 case OLD_DATA_SPACE: |
| 206 case CODE_SPACE: | 208 case CODE_SPACE: |
| 207 ASSERT_EQ(0, page_index_ & ~kPageMask); | 209 ASSERT_EQ(0, page_index_ & ~kPageMask); |
| 208 word_offset = page_offset_ >> kObjectAlignmentBits; | 210 word_offset = page_offset_ >> kObjectAlignmentBits; |
| 209 ASSERT_EQ(0, word_offset & ~kOffsetMask); | 211 ASSERT_EQ(0, word_offset & ~kOffsetMask); |
| 210 result = (page_index_ << kPageShift) | (word_offset << kOffsetShift); | 212 result = (page_index_ << kPageShift) | (word_offset << kOffsetShift); |
| 211 break; | 213 break; |
| 212 case NEW_SPACE: | 214 case NEW_SPACE: |
| 213 ASSERT_EQ(0, page_index_); | 215 ASSERT_EQ(0, page_index_); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 228 result |= (space_ << kSpaceShift) | kHeapObjectTag; | 230 result |= (space_ << kSpaceShift) | kHeapObjectTag; |
| 229 return reinterpret_cast<Address>(result); | 231 return reinterpret_cast<Address>(result); |
| 230 } | 232 } |
| 231 | 233 |
| 232 | 234 |
| 233 #ifdef DEBUG | 235 #ifdef DEBUG |
| 234 void RelativeAddress::Verify() { | 236 void RelativeAddress::Verify() { |
| 235 ASSERT(page_offset_ >= 0 && page_index_ >= 0); | 237 ASSERT(page_offset_ >= 0 && page_index_ >= 0); |
| 236 switch (space_) { | 238 switch (space_) { |
| 237 case MAP_SPACE: | 239 case MAP_SPACE: |
| 240 case GLOBAL_PROPERTY_CELL_SPACE: |
| 238 case OLD_POINTER_SPACE: | 241 case OLD_POINTER_SPACE: |
| 239 case OLD_DATA_SPACE: | 242 case OLD_DATA_SPACE: |
| 240 case CODE_SPACE: | 243 case CODE_SPACE: |
| 241 ASSERT(Page::kObjectStartOffset <= page_offset_ && | 244 ASSERT(Page::kObjectStartOffset <= page_offset_ && |
| 242 page_offset_ <= Page::kPageSize); | 245 page_offset_ <= Page::kPageSize); |
| 243 break; | 246 break; |
| 244 case NEW_SPACE: | 247 case NEW_SPACE: |
| 245 ASSERT(page_index_ == 0); | 248 ASSERT(page_index_ == 0); |
| 246 break; | 249 break; |
| 247 case LO_SPACE: | 250 case LO_SPACE: |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 RelativeAddress Allocate(int size, GCTreatment special_gc_treatment); | 287 RelativeAddress Allocate(int size, GCTreatment special_gc_treatment); |
| 285 | 288 |
| 286 private: | 289 private: |
| 287 RelativeAddress current_; | 290 RelativeAddress current_; |
| 288 }; | 291 }; |
| 289 | 292 |
| 290 | 293 |
| 291 void SimulatedHeapSpace::InitEmptyHeap(AllocationSpace space) { | 294 void SimulatedHeapSpace::InitEmptyHeap(AllocationSpace space) { |
| 292 switch (space) { | 295 switch (space) { |
| 293 case MAP_SPACE: | 296 case MAP_SPACE: |
| 297 case GLOBAL_PROPERTY_CELL_SPACE: |
| 294 case OLD_POINTER_SPACE: | 298 case OLD_POINTER_SPACE: |
| 295 case OLD_DATA_SPACE: | 299 case OLD_DATA_SPACE: |
| 296 case CODE_SPACE: | 300 case CODE_SPACE: |
| 297 current_ = RelativeAddress(space, 0, Page::kObjectStartOffset); | 301 current_ = RelativeAddress(space, 0, Page::kObjectStartOffset); |
| 298 break; | 302 break; |
| 299 case NEW_SPACE: | 303 case NEW_SPACE: |
| 300 case LO_SPACE: | 304 case LO_SPACE: |
| 301 current_ = RelativeAddress(space, 0, 0); | 305 current_ = RelativeAddress(space, 0, 0); |
| 302 break; | 306 break; |
| 303 } | 307 } |
| 304 } | 308 } |
| 305 | 309 |
| 306 | 310 |
| 307 void SimulatedHeapSpace::InitCurrentHeap(AllocationSpace space) { | 311 void SimulatedHeapSpace::InitCurrentHeap(AllocationSpace space) { |
| 308 switch (space) { | 312 switch (space) { |
| 309 case MAP_SPACE: | 313 case MAP_SPACE: |
| 314 case GLOBAL_PROPERTY_CELL_SPACE: |
| 310 case OLD_POINTER_SPACE: | 315 case OLD_POINTER_SPACE: |
| 311 case OLD_DATA_SPACE: | 316 case OLD_DATA_SPACE: |
| 312 case CODE_SPACE: { | 317 case CODE_SPACE: { |
| 313 PagedSpace* ps; | 318 PagedSpace* ps; |
| 314 if (space == MAP_SPACE) { | 319 if (space == MAP_SPACE) { |
| 315 ps = Heap::map_space(); | 320 ps = Heap::map_space(); |
| 321 } else if (space == GLOBAL_PROPERTY_CELL_SPACE) { |
| 322 ps = Heap::global_property_cell_space(); |
| 316 } else if (space == OLD_POINTER_SPACE) { | 323 } else if (space == OLD_POINTER_SPACE) { |
| 317 ps = Heap::old_pointer_space(); | 324 ps = Heap::old_pointer_space(); |
| 318 } else if (space == OLD_DATA_SPACE) { | 325 } else if (space == OLD_DATA_SPACE) { |
| 319 ps = Heap::old_data_space(); | 326 ps = Heap::old_data_space(); |
| 320 } else { | 327 } else { |
| 321 ASSERT(space == CODE_SPACE); | 328 ASSERT(space == CODE_SPACE); |
| 322 ps = Heap::code_space(); | 329 ps = Heap::code_space(); |
| 323 } | 330 } |
| 324 Address top = ps->top(); | 331 Address top = ps->top(); |
| 325 Page* top_page = Page::FromAllocationTop(top); | 332 Page* top_page = Page::FromAllocationTop(top); |
| (...skipping 780 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1106 writer_->PutC('S'); | 1113 writer_->PutC('S'); |
| 1107 writer_->PutC('['); | 1114 writer_->PutC('['); |
| 1108 writer_->PutInt(Heap::old_pointer_space()->Size() + | 1115 writer_->PutInt(Heap::old_pointer_space()->Size() + |
| 1109 Heap::new_space()->Size()); | 1116 Heap::new_space()->Size()); |
| 1110 writer_->PutC('|'); | 1117 writer_->PutC('|'); |
| 1111 writer_->PutInt(Heap::old_data_space()->Size() + Heap::new_space()->Size()); | 1118 writer_->PutInt(Heap::old_data_space()->Size() + Heap::new_space()->Size()); |
| 1112 writer_->PutC('|'); | 1119 writer_->PutC('|'); |
| 1113 writer_->PutInt(Heap::code_space()->Size() + Heap::new_space()->Size()); | 1120 writer_->PutInt(Heap::code_space()->Size() + Heap::new_space()->Size()); |
| 1114 writer_->PutC('|'); | 1121 writer_->PutC('|'); |
| 1115 writer_->PutInt(Heap::map_space()->Size()); | 1122 writer_->PutInt(Heap::map_space()->Size()); |
| 1123 writer_->PutC('|'); |
| 1124 writer_->PutInt(Heap::global_property_cell_space()->Size()); |
| 1116 writer_->PutC(']'); | 1125 writer_->PutC(']'); |
| 1117 // Write global handles. | 1126 // Write global handles. |
| 1118 writer_->PutC('G'); | 1127 writer_->PutC('G'); |
| 1119 writer_->PutC('['); | 1128 writer_->PutC('['); |
| 1120 GlobalHandlesRetriever ghr(&global_handles_); | 1129 GlobalHandlesRetriever ghr(&global_handles_); |
| 1121 GlobalHandles::IterateRoots(&ghr); | 1130 GlobalHandles::IterateRoots(&ghr); |
| 1122 for (int i = 0; i < global_handles_.length(); i++) { | 1131 for (int i = 0; i < global_handles_.length(); i++) { |
| 1123 writer_->PutC('N'); | 1132 writer_->PutC('N'); |
| 1124 } | 1133 } |
| 1125 writer_->PutC(']'); | 1134 writer_->PutC(']'); |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1288 //------------------------------------------------------------------------------ | 1297 //------------------------------------------------------------------------------ |
| 1289 // Implementation of Deserializer | 1298 // Implementation of Deserializer |
| 1290 | 1299 |
| 1291 | 1300 |
| 1292 static const int kInitArraySize = 32; | 1301 static const int kInitArraySize = 32; |
| 1293 | 1302 |
| 1294 | 1303 |
| 1295 Deserializer::Deserializer(const byte* str, int len) | 1304 Deserializer::Deserializer(const byte* str, int len) |
| 1296 : reader_(str, len), | 1305 : reader_(str, len), |
| 1297 map_pages_(kInitArraySize), | 1306 map_pages_(kInitArraySize), |
| 1307 global_property_cell_pages_(kInitArraySize), |
| 1298 old_pointer_pages_(kInitArraySize), | 1308 old_pointer_pages_(kInitArraySize), |
| 1299 old_data_pages_(kInitArraySize), | 1309 old_data_pages_(kInitArraySize), |
| 1300 code_pages_(kInitArraySize), | 1310 code_pages_(kInitArraySize), |
| 1301 large_objects_(kInitArraySize), | 1311 large_objects_(kInitArraySize), |
| 1302 global_handles_(4) { | 1312 global_handles_(4) { |
| 1303 root_ = true; | 1313 root_ = true; |
| 1304 roots_ = 0; | 1314 roots_ = 0; |
| 1305 objects_ = 0; | 1315 objects_ = 0; |
| 1306 reference_decoder_ = NULL; | 1316 reference_decoder_ = NULL; |
| 1307 #ifdef DEBUG | 1317 #ifdef DEBUG |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1460 reader_.ExpectC('['); | 1470 reader_.ExpectC('['); |
| 1461 InitPagedSpace(Heap::old_pointer_space(), | 1471 InitPagedSpace(Heap::old_pointer_space(), |
| 1462 reader_.GetInt(), | 1472 reader_.GetInt(), |
| 1463 &old_pointer_pages_); | 1473 &old_pointer_pages_); |
| 1464 reader_.ExpectC('|'); | 1474 reader_.ExpectC('|'); |
| 1465 InitPagedSpace(Heap::old_data_space(), reader_.GetInt(), &old_data_pages_); | 1475 InitPagedSpace(Heap::old_data_space(), reader_.GetInt(), &old_data_pages_); |
| 1466 reader_.ExpectC('|'); | 1476 reader_.ExpectC('|'); |
| 1467 InitPagedSpace(Heap::code_space(), reader_.GetInt(), &code_pages_); | 1477 InitPagedSpace(Heap::code_space(), reader_.GetInt(), &code_pages_); |
| 1468 reader_.ExpectC('|'); | 1478 reader_.ExpectC('|'); |
| 1469 InitPagedSpace(Heap::map_space(), reader_.GetInt(), &map_pages_); | 1479 InitPagedSpace(Heap::map_space(), reader_.GetInt(), &map_pages_); |
| 1480 reader_.ExpectC('|'); |
| 1481 InitPagedSpace(Heap::global_property_cell_space(), reader_.GetInt(), |
| 1482 &global_property_cell_pages_); |
| 1470 reader_.ExpectC(']'); | 1483 reader_.ExpectC(']'); |
| 1471 // Create placeholders for global handles later to be fill during | 1484 // Create placeholders for global handles later to be fill during |
| 1472 // IterateRoots. | 1485 // IterateRoots. |
| 1473 reader_.ExpectC('G'); | 1486 reader_.ExpectC('G'); |
| 1474 reader_.ExpectC('['); | 1487 reader_.ExpectC('['); |
| 1475 int c = reader_.GetC(); | 1488 int c = reader_.GetC(); |
| 1476 while (c != ']') { | 1489 while (c != ']') { |
| 1477 ASSERT(c == 'N'); | 1490 ASSERT(c == 'N'); |
| 1478 global_handles_.Add(GlobalHandles::Create(NULL).location()); | 1491 global_handles_.Add(GlobalHandles::Create(NULL).location()); |
| 1479 c = reader_.GetC(); | 1492 c = reader_.GetC(); |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1592 ASSERT(o->IsHeapObject()); | 1605 ASSERT(o->IsHeapObject()); |
| 1593 | 1606 |
| 1594 switch (GetSpace(encoded)) { | 1607 switch (GetSpace(encoded)) { |
| 1595 // For Map space and Old space, we cache the known Pages in map_pages, | 1608 // For Map space and Old space, we cache the known Pages in map_pages, |
| 1596 // old_pointer_pages and old_data_pages. Even though MapSpace keeps a list | 1609 // old_pointer_pages and old_data_pages. Even though MapSpace keeps a list |
| 1597 // of page addresses, we don't rely on it since GetObject uses AllocateRaw, | 1610 // of page addresses, we don't rely on it since GetObject uses AllocateRaw, |
| 1598 // and that appears not to update the page list. | 1611 // and that appears not to update the page list. |
| 1599 case MAP_SPACE: | 1612 case MAP_SPACE: |
| 1600 return ResolvePaged(PageIndex(encoded), PageOffset(encoded), | 1613 return ResolvePaged(PageIndex(encoded), PageOffset(encoded), |
| 1601 Heap::map_space(), &map_pages_); | 1614 Heap::map_space(), &map_pages_); |
| 1615 case GLOBAL_PROPERTY_CELL_SPACE: |
| 1616 return ResolvePaged(PageIndex(encoded), PageOffset(encoded), |
| 1617 Heap::global_property_cell_space(), |
| 1618 &global_property_cell_pages_); |
| 1602 case OLD_POINTER_SPACE: | 1619 case OLD_POINTER_SPACE: |
| 1603 return ResolvePaged(PageIndex(encoded), PageOffset(encoded), | 1620 return ResolvePaged(PageIndex(encoded), PageOffset(encoded), |
| 1604 Heap::old_pointer_space(), &old_pointer_pages_); | 1621 Heap::old_pointer_space(), &old_pointer_pages_); |
| 1605 case OLD_DATA_SPACE: | 1622 case OLD_DATA_SPACE: |
| 1606 return ResolvePaged(PageIndex(encoded), PageOffset(encoded), | 1623 return ResolvePaged(PageIndex(encoded), PageOffset(encoded), |
| 1607 Heap::old_data_space(), &old_data_pages_); | 1624 Heap::old_data_space(), &old_data_pages_); |
| 1608 case CODE_SPACE: | 1625 case CODE_SPACE: |
| 1609 return ResolvePaged(PageIndex(encoded), PageOffset(encoded), | 1626 return ResolvePaged(PageIndex(encoded), PageOffset(encoded), |
| 1610 Heap::code_space(), &code_pages_); | 1627 Heap::code_space(), &code_pages_); |
| 1611 case NEW_SPACE: | 1628 case NEW_SPACE: |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1631 ASSERT(index < large_objects_.length()); | 1648 ASSERT(index < large_objects_.length()); |
| 1632 } | 1649 } |
| 1633 return large_objects_[index]; // s.page_offset() is ignored. | 1650 return large_objects_[index]; // s.page_offset() is ignored. |
| 1634 } | 1651 } |
| 1635 UNREACHABLE(); | 1652 UNREACHABLE(); |
| 1636 return NULL; | 1653 return NULL; |
| 1637 } | 1654 } |
| 1638 | 1655 |
| 1639 | 1656 |
| 1640 } } // namespace v8::internal | 1657 } } // namespace v8::internal |
| OLD | NEW |