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

Side by Side Diff: src/spaces.h

Issue 6905127: Make newspace semispaces be single page-sized memory chunks. (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/gc
Patch Set: Created 9 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « src/heap.cc ('k') | src/spaces.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 1392 matching lines...) Expand 10 before | Expand all | Expand 10 after
1403 1403
1404 const char* name() { return name_; } 1404 const char* name() { return name_; }
1405 void set_name(const char* name) { name_ = name; } 1405 void set_name(const char* name) { name_ = name; }
1406 1406
1407 private: 1407 private:
1408 const char* name_; 1408 const char* name_;
1409 }; 1409 };
1410 #endif 1410 #endif
1411 1411
1412 1412
1413 class NewSpacePage : public MemoryChunk {
1414 public:
1415 inline NewSpacePage* next_page() const {
1416 return static_cast<NewSpacePage*>(next_chunk());
1417 }
1418
1419 inline void set_next_page(NewSpacePage* page) {
1420 set_next_chunk(page);
1421 }
1422 private:
1423 // Finds the NewSpacePage containg the given address.
1424 static NewSpacePage* FromAddress(Address address_in_page) {
1425 Address page_start =
1426 reinterpret_cast<Address>(reinterpret_cast<uintptr_t>(address_in_page) &
1427 ~Page::kPageAlignmentMask);
1428 return reinterpret_cast<NewSpacePage*>(page_start);
1429 }
1430
1431 static NewSpacePage* Initialize(Heap* heap, Address start);
1432
1433 friend class SemiSpace;
1434 friend class SemiSpaceIterator;
1435 };
1436
1437
1413 // ----------------------------------------------------------------------------- 1438 // -----------------------------------------------------------------------------
1414 // SemiSpace in young generation 1439 // SemiSpace in young generation
1415 // 1440 //
1416 // A semispace is a contiguous chunk of memory. The mark-compact collector 1441 // A semispace is a contiguous chunk of memory holding page-like memory
1417 // uses the memory in the from space as a marking stack when tracing live 1442 // chunks. The mark-compact collector uses the memory of the first page in
1418 // objects. 1443 // the from space as a marking stack when tracing live objects.
1419 1444
1420 class SemiSpace : public Space { 1445 class SemiSpace : public Space {
1421 public: 1446 public:
1422 // Constructor. 1447 // Constructor.
1423 explicit SemiSpace(Heap* heap) : Space(heap, NEW_SPACE, NOT_EXECUTABLE) { 1448 explicit SemiSpace(Heap* heap) : Space(heap, NEW_SPACE, NOT_EXECUTABLE) {
1424 start_ = NULL; 1449 start_ = NULL;
1425 age_mark_ = NULL; 1450 age_mark_ = NULL;
1426 } 1451 }
1427 1452
1428 // Sets up the semispace using the given chunk. 1453 // Sets up the semispace using the given chunk.
(...skipping 15 matching lines...) Expand all
1444 // Grow the semispace to the new capacity. The new capacity 1469 // Grow the semispace to the new capacity. The new capacity
1445 // requested must be larger than the current capacity. 1470 // requested must be larger than the current capacity.
1446 bool GrowTo(int new_capacity); 1471 bool GrowTo(int new_capacity);
1447 1472
1448 // Shrinks the semispace to the new capacity. The new capacity 1473 // Shrinks the semispace to the new capacity. The new capacity
1449 // requested must be more than the amount of used memory in the 1474 // requested must be more than the amount of used memory in the
1450 // semispace and less than the current capacity. 1475 // semispace and less than the current capacity.
1451 bool ShrinkTo(int new_capacity); 1476 bool ShrinkTo(int new_capacity);
1452 1477
1453 // Returns the start address of the space. 1478 // Returns the start address of the space.
1454 Address low() { return start_; } 1479 Address low() {
1480 return NewSpacePage::FromAddress(start_)->body();
1481 }
1482
1455 // Returns one past the end address of the space. 1483 // Returns one past the end address of the space.
1456 Address high() { return low() + capacity_; } 1484 Address high() {
1485 // FIXME: Change when there is more than one page.
Erik Corry 2011/05/02 06:43:01 All these FIXMEs need to be 'TODO(gc):' instead.
1486 return current_page_->body() + current_page_->body_size();
1487 }
1457 1488
1458 // Age mark accessors. 1489 // Age mark accessors.
1459 Address age_mark() { return age_mark_; } 1490 Address age_mark() { return age_mark_; }
1460 void set_age_mark(Address mark) { age_mark_ = mark; } 1491 void set_age_mark(Address mark) { age_mark_ = mark; }
1461 1492
1462 // True if the address is in the address range of this semispace (not 1493 // True if the address is in the address range of this semispace (not
1463 // necessarily below the allocation pointer). 1494 // necessarily below the allocation pointer).
1464 bool Contains(Address a) { 1495 bool Contains(Address a) {
1465 return (reinterpret_cast<uintptr_t>(a) & address_mask_) 1496 return (reinterpret_cast<uintptr_t>(a) & address_mask_)
1466 == reinterpret_cast<uintptr_t>(start_); 1497 == reinterpret_cast<uintptr_t>(start_);
(...skipping 19 matching lines...) Expand all
1486 1517
1487 virtual bool ReserveSpace(int bytes) { 1518 virtual bool ReserveSpace(int bytes) {
1488 UNREACHABLE(); 1519 UNREACHABLE();
1489 return false; 1520 return false;
1490 } 1521 }
1491 1522
1492 bool is_committed() { return committed_; } 1523 bool is_committed() { return committed_; }
1493 bool Commit(); 1524 bool Commit();
1494 bool Uncommit(); 1525 bool Uncommit();
1495 1526
1527 NewSpacePage* first_page() { return NewSpacePage::FromAddress(start_); }
1528 NewSpacePage* current_page() { return current_page_; }
1529
1496 #ifdef ENABLE_HEAP_PROTECTION 1530 #ifdef ENABLE_HEAP_PROTECTION
1497 // Protect/unprotect the space by marking it read-only/writable. 1531 // Protect/unprotect the space by marking it read-only/writable.
1498 virtual void Protect() {} 1532 virtual void Protect() {}
1499 virtual void Unprotect() {} 1533 virtual void Unprotect() {}
1500 #endif 1534 #endif
1501 1535
1502 #ifdef DEBUG 1536 #ifdef DEBUG
1503 virtual void Print(); 1537 virtual void Print();
1504 virtual void Verify(); 1538 virtual void Verify();
1505 #endif 1539 #endif
(...skipping 18 matching lines...) Expand all
1524 // Used to govern object promotion during mark-compact collection. 1558 // Used to govern object promotion during mark-compact collection.
1525 Address age_mark_; 1559 Address age_mark_;
1526 1560
1527 // Masks and comparison values to test for containment in this semispace. 1561 // Masks and comparison values to test for containment in this semispace.
1528 uintptr_t address_mask_; 1562 uintptr_t address_mask_;
1529 uintptr_t object_mask_; 1563 uintptr_t object_mask_;
1530 uintptr_t object_expected_; 1564 uintptr_t object_expected_;
1531 1565
1532 bool committed_; 1566 bool committed_;
1533 1567
1568 NewSpacePage* current_page_;
1569
1534 public: 1570 public:
1535 TRACK_MEMORY("SemiSpace") 1571 TRACK_MEMORY("SemiSpace")
1536 }; 1572 };
1537 1573
1538 1574
1539 // A SemiSpaceIterator is an ObjectIterator that iterates over the active 1575 // A SemiSpaceIterator is an ObjectIterator that iterates over the active
1540 // semispace of the heap's new space. It iterates over the objects in the 1576 // semispace of the heap's new space. It iterates over the objects in the
1541 // semispace from a given start address (defaulting to the bottom of the 1577 // semispace from a given start address (defaulting to the bottom of the
1542 // semispace) to the top of the semispace. New objects allocated after the 1578 // semispace) to the top of the semispace. New objects allocated after the
1543 // iterator is created are not iterated. 1579 // iterator is created are not iterated.
1544 class SemiSpaceIterator : public ObjectIterator { 1580 class SemiSpaceIterator : public ObjectIterator {
1545 public: 1581 public:
1546 // Create an iterator over the objects in the given space. If no start 1582 // Create an iterator over the objects in the given space. If no start
1547 // address is given, the iterator starts from the bottom of the space. If 1583 // address is given, the iterator starts from the bottom of the space. If
1548 // no size function is given, the iterator calls Object::Size(). 1584 // no size function is given, the iterator calls Object::Size().
1549 explicit SemiSpaceIterator(NewSpace* space); 1585 explicit SemiSpaceIterator(NewSpace* space);
1550 SemiSpaceIterator(NewSpace* space, HeapObjectCallback size_func); 1586 SemiSpaceIterator(NewSpace* space, HeapObjectCallback size_func);
1551 SemiSpaceIterator(NewSpace* space, Address start); 1587 SemiSpaceIterator(NewSpace* space, Address start);
1552 1588
1553 HeapObject* next() { 1589 HeapObject* next() {
1590 if (current_ == current_page_limit_) {
1591 // FIXME: Add something here when we have more than one page.
1592 }
1554 if (current_ == limit_) return NULL; 1593 if (current_ == limit_) return NULL;
1555 1594
1556 HeapObject* object = HeapObject::FromAddress(current_); 1595 HeapObject* object = HeapObject::FromAddress(current_);
1557 int size = (size_func_ == NULL) ? object->Size() : size_func_(object); 1596 int size = (size_func_ == NULL) ? object->Size() : size_func_(object);
1558 1597
1559 current_ += size; 1598 current_ += size;
1560 return object; 1599 return object;
1561 } 1600 }
1562 1601
1563 // Implementation of the ObjectIterator functions. 1602 // Implementation of the ObjectIterator functions.
1564 virtual HeapObject* next_object() { return next(); } 1603 virtual HeapObject* next_object() { return next(); }
1565 1604
1566 private: 1605 private:
1567 void Initialize(NewSpace* space, 1606 void Initialize(NewSpace* space,
1568 Address start, 1607 Address start,
1569 Address end, 1608 Address end,
1570 HeapObjectCallback size_func); 1609 HeapObjectCallback size_func);
1571 1610
1572 // The semispace. 1611 // The semispace.
1573 SemiSpace* space_; 1612 SemiSpace* space_;
1574 // The current iteration point. 1613 // The current iteration point.
1575 Address current_; 1614 Address current_;
1615 // The end of the current page.
1616 Address current_page_limit_;
1576 // The end of iteration. 1617 // The end of iteration.
1577 Address limit_; 1618 Address limit_;
1578 // The callback function. 1619 // The callback function.
1579 HeapObjectCallback size_func_; 1620 HeapObjectCallback size_func_;
1580 }; 1621 };
1581 1622
1582 1623
1583 // ----------------------------------------------------------------------------- 1624 // -----------------------------------------------------------------------------
1584 // The young generation space. 1625 // The young generation space.
1585 // 1626 //
(...skipping 578 matching lines...) Expand 10 before | Expand all | Expand 10 after
2164 } 2205 }
2165 // Must be small, since an iteration is used for lookup. 2206 // Must be small, since an iteration is used for lookup.
2166 static const int kMaxComments = 64; 2207 static const int kMaxComments = 64;
2167 }; 2208 };
2168 #endif 2209 #endif
2169 2210
2170 2211
2171 } } // namespace v8::internal 2212 } } // namespace v8::internal
2172 2213
2173 #endif // V8_SPACES_H_ 2214 #endif // V8_SPACES_H_
OLDNEW
« no previous file with comments | « src/heap.cc ('k') | src/spaces.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698