2011-05-03 08:23:58 +00:00
|
|
|
// Copyright 2011 the V8 project authors. All rights reserved.
|
2014-04-29 06:42:26 +00:00
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
#ifndef V8_SPACES_H_
|
|
|
|
#define V8_SPACES_H_
|
|
|
|
|
2011-05-06 06:50:20 +00:00
|
|
|
#include "allocation.h"
|
2012-03-19 12:08:20 +00:00
|
|
|
#include "hashmap.h"
|
2011-05-03 08:23:58 +00:00
|
|
|
#include "list.h"
|
2008-07-03 15:10:15 +00:00
|
|
|
#include "log.h"
|
2013-08-29 09:58:30 +00:00
|
|
|
#include "platform/mutex.h"
|
2014-04-25 13:47:01 +00:00
|
|
|
#include "utils.h"
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-05-25 10:05:56 +00:00
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
class Isolate;
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Heap structures:
|
|
|
|
//
|
|
|
|
// A JS heap consists of a young generation, an old generation, and a large
|
|
|
|
// object space. The young generation is divided into two semispaces. A
|
|
|
|
// scavenger implements Cheney's copying algorithm. The old generation is
|
|
|
|
// separated into a map space and an old object space. The map space contains
|
|
|
|
// all (and only) map objects, the rest of old objects go into the old space.
|
|
|
|
// The old generation is collected by a mark-sweep-compact collector.
|
|
|
|
//
|
|
|
|
// The semispaces of the young generation are contiguous. The old and map
|
2010-05-27 12:30:45 +00:00
|
|
|
// spaces consists of a list of pages. A page has a page header and an object
|
2011-09-19 18:36:47 +00:00
|
|
|
// area.
|
2008-07-03 15:10:15 +00:00
|
|
|
//
|
|
|
|
// There is a separate large object space for objects larger than
|
|
|
|
// Page::kMaxHeapObjectSize, so that they do not have to move during
|
2010-05-27 12:30:45 +00:00
|
|
|
// collection. The large object space is paged. Pages in large object space
|
2011-09-19 18:36:47 +00:00
|
|
|
// may be larger than the page size.
|
2010-05-27 12:30:45 +00:00
|
|
|
//
|
2011-09-19 18:36:47 +00:00
|
|
|
// A store-buffer based write barrier is used to keep track of intergenerational
|
|
|
|
// references. See store-buffer.h.
|
2010-05-27 12:30:45 +00:00
|
|
|
//
|
2011-09-19 18:36:47 +00:00
|
|
|
// During scavenges and mark-sweep collections we sometimes (after a store
|
|
|
|
// buffer overflow) iterate intergenerational pointers without decoding heap
|
|
|
|
// object maps so if the page belongs to old pointer space or large object
|
|
|
|
// space it is essential to guarantee that the page does not contain any
|
|
|
|
// garbage pointers to new space: every pointer aligned word which satisfies
|
|
|
|
// the Heap::InNewSpace() predicate must be a pointer to a live heap object in
|
|
|
|
// new space. Thus objects in old pointer and large object spaces should have a
|
|
|
|
// special layout (e.g. no bare integer fields). This requirement does not
|
|
|
|
// apply to map space which is iterated in a special fashion. However we still
|
|
|
|
// require pointer fields of dead maps to be cleaned.
|
2010-05-27 12:30:45 +00:00
|
|
|
//
|
2011-09-19 18:36:47 +00:00
|
|
|
// To enable lazy cleaning of old space pages we can mark chunks of the page
|
|
|
|
// as being garbage. Garbage sections are marked with a special map. These
|
|
|
|
// sections are skipped when scanning the page, even if we are otherwise
|
|
|
|
// scanning without regard for object boundaries. Garbage sections are chained
|
|
|
|
// together to form a free list after a GC. Garbage sections created outside
|
|
|
|
// of GCs by object trunctation etc. may not be in the free list chain. Very
|
|
|
|
// small free spaces are ignored, they need only be cleaned of bogus pointers
|
|
|
|
// into new space.
|
2008-07-03 15:10:15 +00:00
|
|
|
//
|
2011-09-19 18:36:47 +00:00
|
|
|
// Each page may have up to one special garbage section. The start of this
|
|
|
|
// section is denoted by the top field in the space. The end of the section
|
|
|
|
// is denoted by the limit field in the space. This special garbage section
|
|
|
|
// is not marked with a free space map in the data. The point of this section
|
|
|
|
// is to enable linear allocation without having to constantly update the byte
|
|
|
|
// array every time the top field is updated and a new object is created. The
|
|
|
|
// special garbage section is not in the chain of garbage sections.
|
|
|
|
//
|
|
|
|
// Since the top and limit fields are in the space, not the page, only one page
|
|
|
|
// has a special garbage section, and if the top and limit are equal then there
|
|
|
|
// is no special garbage section.
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// Some assertion macros used in the debugging mode.
|
|
|
|
|
2009-12-17 08:53:18 +00:00
|
|
|
#define ASSERT_PAGE_ALIGNED(address) \
|
2008-07-03 15:10:15 +00:00
|
|
|
ASSERT((OffsetFrom(address) & Page::kPageAlignmentMask) == 0)
|
|
|
|
|
2009-12-17 08:53:18 +00:00
|
|
|
#define ASSERT_OBJECT_ALIGNED(address) \
|
2008-07-03 15:10:15 +00:00
|
|
|
ASSERT((OffsetFrom(address) & kObjectAlignmentMask) == 0)
|
|
|
|
|
2009-12-17 08:53:18 +00:00
|
|
|
#define ASSERT_OBJECT_SIZE(size) \
|
2014-01-23 13:02:27 +00:00
|
|
|
ASSERT((0 < size) && (size <= Page::kMaxRegularHeapObjectSize))
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-12-17 08:53:18 +00:00
|
|
|
#define ASSERT_PAGE_OFFSET(offset) \
|
|
|
|
ASSERT((Page::kObjectStartOffset <= offset) \
|
2008-07-03 15:10:15 +00:00
|
|
|
&& (offset <= Page::kPageSize))
|
|
|
|
|
2009-12-17 08:53:18 +00:00
|
|
|
#define ASSERT_MAP_PAGE_INDEX(index) \
|
2008-07-03 15:10:15 +00:00
|
|
|
ASSERT((0 <= index) && (index <= MapSpace::kMaxMapPageIndex))
|
|
|
|
|
|
|
|
|
|
|
|
class PagedSpace;
|
|
|
|
class MemoryAllocator;
|
2008-07-30 08:49:36 +00:00
|
|
|
class AllocationInfo;
|
2011-09-19 18:36:47 +00:00
|
|
|
class Space;
|
|
|
|
class FreeList;
|
|
|
|
class MemoryChunk;
|
|
|
|
|
|
|
|
class MarkBit {
|
|
|
|
public:
|
|
|
|
typedef uint32_t CellType;
|
|
|
|
|
|
|
|
inline MarkBit(CellType* cell, CellType mask, bool data_only)
|
|
|
|
: cell_(cell), mask_(mask), data_only_(data_only) { }
|
|
|
|
|
|
|
|
inline CellType* cell() { return cell_; }
|
|
|
|
inline CellType mask() { return mask_; }
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
bool operator==(const MarkBit& other) {
|
|
|
|
return cell_ == other.cell_ && mask_ == other.mask_;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
inline void Set() { *cell_ |= mask_; }
|
|
|
|
inline bool Get() { return (*cell_ & mask_) != 0; }
|
|
|
|
inline void Clear() { *cell_ &= ~mask_; }
|
|
|
|
|
|
|
|
inline bool data_only() { return data_only_; }
|
|
|
|
|
|
|
|
inline MarkBit Next() {
|
|
|
|
CellType new_mask = mask_ << 1;
|
|
|
|
if (new_mask == 0) {
|
|
|
|
return MarkBit(cell_ + 1, 1, data_only_);
|
|
|
|
} else {
|
|
|
|
return MarkBit(cell_, new_mask, data_only_);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
CellType* cell_;
|
|
|
|
CellType mask_;
|
|
|
|
// This boolean indicates that the object is in a data-only space with no
|
|
|
|
// pointers. This enables some optimizations when marking.
|
|
|
|
// It is expected that this field is inlined and turned into control flow
|
|
|
|
// at the place where the MarkBit object is created.
|
|
|
|
bool data_only_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Bitmap is a sequence of cells each containing fixed number of bits.
|
|
|
|
class Bitmap {
|
|
|
|
public:
|
|
|
|
static const uint32_t kBitsPerCell = 32;
|
|
|
|
static const uint32_t kBitsPerCellLog2 = 5;
|
|
|
|
static const uint32_t kBitIndexMask = kBitsPerCell - 1;
|
|
|
|
static const uint32_t kBytesPerCell = kBitsPerCell / kBitsPerByte;
|
|
|
|
static const uint32_t kBytesPerCellLog2 = kBitsPerCellLog2 - kBitsPerByteLog2;
|
|
|
|
|
|
|
|
static const size_t kLength =
|
|
|
|
(1 << kPageSizeBits) >> (kPointerSizeLog2);
|
|
|
|
|
|
|
|
static const size_t kSize =
|
|
|
|
(1 << kPageSizeBits) >> (kPointerSizeLog2 + kBitsPerByteLog2);
|
|
|
|
|
|
|
|
|
|
|
|
static int CellsForLength(int length) {
|
|
|
|
return (length + kBitsPerCell - 1) >> kBitsPerCellLog2;
|
|
|
|
}
|
|
|
|
|
|
|
|
int CellsCount() {
|
|
|
|
return CellsForLength(kLength);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int SizeFor(int cells_count) {
|
2011-09-22 16:01:35 +00:00
|
|
|
return sizeof(MarkBit::CellType) * cells_count;
|
2011-09-19 18:36:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
INLINE(static uint32_t IndexToCell(uint32_t index)) {
|
|
|
|
return index >> kBitsPerCellLog2;
|
|
|
|
}
|
|
|
|
|
|
|
|
INLINE(static uint32_t CellToIndex(uint32_t index)) {
|
|
|
|
return index << kBitsPerCellLog2;
|
|
|
|
}
|
|
|
|
|
|
|
|
INLINE(static uint32_t CellAlignIndex(uint32_t index)) {
|
|
|
|
return (index + kBitIndexMask) & ~kBitIndexMask;
|
|
|
|
}
|
|
|
|
|
|
|
|
INLINE(MarkBit::CellType* cells()) {
|
|
|
|
return reinterpret_cast<MarkBit::CellType*>(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
INLINE(Address address()) {
|
|
|
|
return reinterpret_cast<Address>(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
INLINE(static Bitmap* FromAddress(Address addr)) {
|
|
|
|
return reinterpret_cast<Bitmap*>(addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline MarkBit MarkBitFromIndex(uint32_t index, bool data_only = false) {
|
|
|
|
MarkBit::CellType mask = 1 << (index & kBitIndexMask);
|
|
|
|
MarkBit::CellType* cell = this->cells() + (index >> kBitsPerCellLog2);
|
|
|
|
return MarkBit(cell, mask, data_only);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void Clear(MemoryChunk* chunk);
|
|
|
|
|
|
|
|
static void PrintWord(uint32_t word, uint32_t himask = 0) {
|
|
|
|
for (uint32_t mask = 1; mask != 0; mask <<= 1) {
|
|
|
|
if ((mask & himask) != 0) PrintF("[");
|
|
|
|
PrintF((mask & word) ? "1" : "0");
|
|
|
|
if ((mask & himask) != 0) PrintF("]");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class CellPrinter {
|
|
|
|
public:
|
|
|
|
CellPrinter() : seq_start(0), seq_type(0), seq_length(0) { }
|
|
|
|
|
|
|
|
void Print(uint32_t pos, uint32_t cell) {
|
|
|
|
if (cell == seq_type) {
|
|
|
|
seq_length++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Flush();
|
|
|
|
|
|
|
|
if (IsSeq(cell)) {
|
|
|
|
seq_start = pos;
|
|
|
|
seq_length = 0;
|
|
|
|
seq_type = cell;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
PrintF("%d: ", pos);
|
|
|
|
PrintWord(cell);
|
|
|
|
PrintF("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
void Flush() {
|
|
|
|
if (seq_length > 0) {
|
|
|
|
PrintF("%d: %dx%d\n",
|
|
|
|
seq_start,
|
|
|
|
seq_type == 0 ? 0 : 1,
|
|
|
|
seq_length * kBitsPerCell);
|
|
|
|
seq_length = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool IsSeq(uint32_t cell) { return cell == 0 || cell == 0xFFFFFFFF; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
uint32_t seq_start;
|
|
|
|
uint32_t seq_type;
|
|
|
|
uint32_t seq_length;
|
|
|
|
};
|
|
|
|
|
|
|
|
void Print() {
|
|
|
|
CellPrinter printer;
|
|
|
|
for (int i = 0; i < CellsCount(); i++) {
|
|
|
|
printer.Print(i, cells()[i]);
|
|
|
|
}
|
|
|
|
printer.Flush();
|
|
|
|
PrintF("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsClean() {
|
|
|
|
for (int i = 0; i < CellsCount(); i++) {
|
2012-09-26 11:35:42 +00:00
|
|
|
if (cells()[i] != 0) {
|
|
|
|
return false;
|
|
|
|
}
|
2011-09-19 18:36:47 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class SkipList;
|
|
|
|
class SlotsBuffer;
|
|
|
|
|
|
|
|
// MemoryChunk represents a memory region owned by a specific space.
|
|
|
|
// It is divided into the header and the body. Chunk start is always
|
2012-01-16 12:38:59 +00:00
|
|
|
// 1MB aligned. Start of the body is aligned so it can accommodate
|
2011-09-19 18:36:47 +00:00
|
|
|
// any heap object.
|
|
|
|
class MemoryChunk {
|
|
|
|
public:
|
|
|
|
// Only works if the pointer is in the first kPageSize of the MemoryChunk.
|
|
|
|
static MemoryChunk* FromAddress(Address a) {
|
|
|
|
return reinterpret_cast<MemoryChunk*>(OffsetFrom(a) & ~kAlignmentMask);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Only works for addresses in pointer spaces, not data or code spaces.
|
2013-09-11 07:14:41 +00:00
|
|
|
static inline MemoryChunk* FromAnyPointerAddress(Heap* heap, Address addr);
|
2011-09-19 18:36:47 +00:00
|
|
|
|
|
|
|
Address address() { return reinterpret_cast<Address>(this); }
|
|
|
|
|
|
|
|
bool is_valid() { return address() != NULL; }
|
|
|
|
|
2014-02-12 15:40:23 +00:00
|
|
|
MemoryChunk* next_chunk() const {
|
|
|
|
return reinterpret_cast<MemoryChunk*>(Acquire_Load(&next_chunk_));
|
|
|
|
}
|
|
|
|
|
|
|
|
MemoryChunk* prev_chunk() const {
|
|
|
|
return reinterpret_cast<MemoryChunk*>(Acquire_Load(&prev_chunk_));
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_next_chunk(MemoryChunk* next) {
|
|
|
|
Release_Store(&next_chunk_, reinterpret_cast<AtomicWord>(next));
|
|
|
|
}
|
2011-09-19 18:36:47 +00:00
|
|
|
|
2014-02-12 15:40:23 +00:00
|
|
|
void set_prev_chunk(MemoryChunk* prev) {
|
|
|
|
Release_Store(&prev_chunk_, reinterpret_cast<AtomicWord>(prev));
|
|
|
|
}
|
2011-09-19 18:36:47 +00:00
|
|
|
|
|
|
|
Space* owner() const {
|
|
|
|
if ((reinterpret_cast<intptr_t>(owner_) & kFailureTagMask) ==
|
|
|
|
kFailureTag) {
|
2013-01-31 15:36:24 +00:00
|
|
|
return reinterpret_cast<Space*>(reinterpret_cast<intptr_t>(owner_) -
|
|
|
|
kFailureTag);
|
2011-09-19 18:36:47 +00:00
|
|
|
} else {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_owner(Space* space) {
|
|
|
|
ASSERT((reinterpret_cast<intptr_t>(space) & kFailureTagMask) == 0);
|
|
|
|
owner_ = reinterpret_cast<Address>(space) + kFailureTag;
|
|
|
|
ASSERT((reinterpret_cast<intptr_t>(owner_) & kFailureTagMask) ==
|
|
|
|
kFailureTag);
|
|
|
|
}
|
|
|
|
|
|
|
|
VirtualMemory* reserved_memory() {
|
|
|
|
return &reservation_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void InitializeReservedMemory() {
|
|
|
|
reservation_.Reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_reserved_memory(VirtualMemory* reservation) {
|
|
|
|
ASSERT_NOT_NULL(reservation);
|
|
|
|
reservation_.TakeControl(reservation);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool scan_on_scavenge() { return IsFlagSet(SCAN_ON_SCAVENGE); }
|
|
|
|
void initialize_scan_on_scavenge(bool scan) {
|
|
|
|
if (scan) {
|
|
|
|
SetFlag(SCAN_ON_SCAVENGE);
|
|
|
|
} else {
|
|
|
|
ClearFlag(SCAN_ON_SCAVENGE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
inline void set_scan_on_scavenge(bool scan);
|
|
|
|
|
|
|
|
int store_buffer_counter() { return store_buffer_counter_; }
|
|
|
|
void set_store_buffer_counter(int counter) {
|
|
|
|
store_buffer_counter_ = counter;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Contains(Address addr) {
|
2012-02-23 12:11:24 +00:00
|
|
|
return addr >= area_start() && addr < area_end();
|
2011-09-19 18:36:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Checks whether addr can be a limit of addresses in this page.
|
|
|
|
// It's a limit if it's in the page, or if it's just after the
|
|
|
|
// last byte of the page.
|
|
|
|
bool ContainsLimit(Address addr) {
|
2012-02-23 12:11:24 +00:00
|
|
|
return addr >= area_start() && addr <= area_end();
|
2011-09-19 18:36:47 +00:00
|
|
|
}
|
|
|
|
|
2012-09-26 11:35:42 +00:00
|
|
|
// Every n write barrier invocations we go to runtime even though
|
|
|
|
// we could have handled it in generated code. This lets us check
|
|
|
|
// whether we have hit the limit and should do some more marking.
|
|
|
|
static const int kWriteBarrierCounterGranularity = 500;
|
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
enum MemoryChunkFlags {
|
|
|
|
IS_EXECUTABLE,
|
|
|
|
ABOUT_TO_BE_FREED,
|
|
|
|
POINTERS_TO_HERE_ARE_INTERESTING,
|
|
|
|
POINTERS_FROM_HERE_ARE_INTERESTING,
|
|
|
|
SCAN_ON_SCAVENGE,
|
|
|
|
IN_FROM_SPACE, // Mutually exclusive with IN_TO_SPACE.
|
|
|
|
IN_TO_SPACE, // All pages in new space has one of these two set.
|
|
|
|
NEW_SPACE_BELOW_AGE_MARK,
|
|
|
|
CONTAINS_ONLY_DATA,
|
|
|
|
EVACUATION_CANDIDATE,
|
|
|
|
RESCAN_ON_EVACUATION,
|
|
|
|
|
|
|
|
// Pages swept precisely can be iterated, hitting only the live objects.
|
|
|
|
// Whereas those swept conservatively cannot be iterated over. Both flags
|
|
|
|
// indicate that marking bits have been cleared by the sweeper, otherwise
|
|
|
|
// marking bits are still intact.
|
|
|
|
WAS_SWEPT_PRECISELY,
|
|
|
|
WAS_SWEPT_CONSERVATIVELY,
|
|
|
|
|
2012-11-15 17:57:40 +00:00
|
|
|
// Large objects can have a progress bar in their page header. These object
|
|
|
|
// are scanned in increments and will be kept black while being scanned.
|
|
|
|
// Even if the mutator writes to them they will be kept black and a white
|
|
|
|
// to grey transition is performed in the value.
|
|
|
|
HAS_PROGRESS_BAR,
|
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
// Last flag, keep at bottom.
|
|
|
|
NUM_MEMORY_CHUNK_FLAGS
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static const int kPointersToHereAreInterestingMask =
|
|
|
|
1 << POINTERS_TO_HERE_ARE_INTERESTING;
|
|
|
|
|
|
|
|
static const int kPointersFromHereAreInterestingMask =
|
|
|
|
1 << POINTERS_FROM_HERE_ARE_INTERESTING;
|
|
|
|
|
|
|
|
static const int kEvacuationCandidateMask =
|
|
|
|
1 << EVACUATION_CANDIDATE;
|
|
|
|
|
|
|
|
static const int kSkipEvacuationSlotsRecordingMask =
|
|
|
|
(1 << EVACUATION_CANDIDATE) |
|
|
|
|
(1 << RESCAN_ON_EVACUATION) |
|
|
|
|
(1 << IN_FROM_SPACE) |
|
|
|
|
(1 << IN_TO_SPACE);
|
|
|
|
|
|
|
|
|
|
|
|
void SetFlag(int flag) {
|
|
|
|
flags_ |= static_cast<uintptr_t>(1) << flag;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClearFlag(int flag) {
|
|
|
|
flags_ &= ~(static_cast<uintptr_t>(1) << flag);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetFlagTo(int flag, bool value) {
|
|
|
|
if (value) {
|
|
|
|
SetFlag(flag);
|
|
|
|
} else {
|
|
|
|
ClearFlag(flag);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsFlagSet(int flag) {
|
|
|
|
return (flags_ & (static_cast<uintptr_t>(1) << flag)) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set or clear multiple flags at a time. The flags in the mask
|
|
|
|
// are set to the value in "flags", the rest retain the current value
|
|
|
|
// in flags_.
|
|
|
|
void SetFlags(intptr_t flags, intptr_t mask) {
|
|
|
|
flags_ = (flags_ & ~mask) | (flags & mask);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return all current flags.
|
|
|
|
intptr_t GetFlags() { return flags_; }
|
|
|
|
|
2014-02-14 12:33:35 +00:00
|
|
|
|
|
|
|
// PARALLEL_SWEEPING_DONE - The page state when sweeping is complete or
|
|
|
|
// sweeping must not be performed on that page.
|
2014-03-25 11:57:26 +00:00
|
|
|
// PARALLEL_SWEEPING_FINALIZE - A sweeper thread is done sweeping this
|
|
|
|
// page and will not touch the page memory anymore.
|
|
|
|
// PARALLEL_SWEEPING_IN_PROGRESS - This page is currently swept by a
|
|
|
|
// sweeper thread.
|
|
|
|
// PARALLEL_SWEEPING_PENDING - This page is ready for parallel sweeping.
|
2014-02-14 12:33:35 +00:00
|
|
|
enum ParallelSweepingState {
|
|
|
|
PARALLEL_SWEEPING_DONE,
|
2014-03-25 11:57:26 +00:00
|
|
|
PARALLEL_SWEEPING_FINALIZE,
|
2014-02-14 12:33:35 +00:00
|
|
|
PARALLEL_SWEEPING_IN_PROGRESS,
|
|
|
|
PARALLEL_SWEEPING_PENDING
|
|
|
|
};
|
|
|
|
|
|
|
|
ParallelSweepingState parallel_sweeping() {
|
|
|
|
return static_cast<ParallelSweepingState>(
|
2014-03-27 13:26:25 +00:00
|
|
|
Acquire_Load(¶llel_sweeping_));
|
2013-01-30 12:19:32 +00:00
|
|
|
}
|
|
|
|
|
2014-02-14 12:33:35 +00:00
|
|
|
void set_parallel_sweeping(ParallelSweepingState state) {
|
2014-03-27 13:26:25 +00:00
|
|
|
Release_Store(¶llel_sweeping_, state);
|
2013-01-30 12:19:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool TryParallelSweeping() {
|
2014-03-27 13:26:25 +00:00
|
|
|
return Acquire_CompareAndSwap(¶llel_sweeping_,
|
|
|
|
PARALLEL_SWEEPING_PENDING,
|
|
|
|
PARALLEL_SWEEPING_IN_PROGRESS) ==
|
|
|
|
PARALLEL_SWEEPING_PENDING;
|
2013-01-30 12:19:32 +00:00
|
|
|
}
|
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
// Manage live byte count (count of bytes known to be live,
|
|
|
|
// because they are marked black).
|
|
|
|
void ResetLiveBytes() {
|
2011-10-11 09:28:06 +00:00
|
|
|
if (FLAG_gc_verbose) {
|
2011-09-20 11:20:00 +00:00
|
|
|
PrintF("ResetLiveBytes:%p:%x->0\n",
|
|
|
|
static_cast<void*>(this), live_byte_count_);
|
|
|
|
}
|
2011-09-19 18:36:47 +00:00
|
|
|
live_byte_count_ = 0;
|
|
|
|
}
|
|
|
|
void IncrementLiveBytes(int by) {
|
2011-10-11 09:28:06 +00:00
|
|
|
if (FLAG_gc_verbose) {
|
2011-09-20 11:20:00 +00:00
|
|
|
printf("UpdateLiveBytes:%p:%x%c=%x->%x\n",
|
|
|
|
static_cast<void*>(this), live_byte_count_,
|
|
|
|
((by < 0) ? '-' : '+'), ((by < 0) ? -by : by),
|
|
|
|
live_byte_count_ + by);
|
|
|
|
}
|
2011-09-19 18:36:47 +00:00
|
|
|
live_byte_count_ += by;
|
2011-09-20 11:20:00 +00:00
|
|
|
ASSERT_LE(static_cast<unsigned>(live_byte_count_), size_);
|
|
|
|
}
|
|
|
|
int LiveBytes() {
|
|
|
|
ASSERT(static_cast<unsigned>(live_byte_count_) <= size_);
|
|
|
|
return live_byte_count_;
|
2011-09-19 18:36:47 +00:00
|
|
|
}
|
2012-01-18 09:21:07 +00:00
|
|
|
|
2012-09-26 11:35:42 +00:00
|
|
|
int write_barrier_counter() {
|
|
|
|
return static_cast<int>(write_barrier_counter_);
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_write_barrier_counter(int counter) {
|
|
|
|
write_barrier_counter_ = counter;
|
|
|
|
}
|
|
|
|
|
2012-11-15 17:57:40 +00:00
|
|
|
int progress_bar() {
|
|
|
|
ASSERT(IsFlagSet(HAS_PROGRESS_BAR));
|
|
|
|
return progress_bar_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_progress_bar(int progress_bar) {
|
|
|
|
ASSERT(IsFlagSet(HAS_PROGRESS_BAR));
|
|
|
|
progress_bar_ = progress_bar;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ResetProgressBar() {
|
|
|
|
if (IsFlagSet(MemoryChunk::HAS_PROGRESS_BAR)) {
|
|
|
|
set_progress_bar(0);
|
|
|
|
ClearFlag(MemoryChunk::HAS_PROGRESS_BAR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-26 16:16:49 +00:00
|
|
|
bool IsLeftOfProgressBar(Object** slot) {
|
|
|
|
Address slot_address = reinterpret_cast<Address>(slot);
|
|
|
|
ASSERT(slot_address > this->address());
|
2012-11-28 10:53:39 +00:00
|
|
|
return (slot_address - (this->address() + kObjectStartOffset)) <
|
2012-11-26 16:16:49 +00:00
|
|
|
progress_bar();
|
|
|
|
}
|
2012-09-26 11:35:42 +00:00
|
|
|
|
2012-01-18 09:21:07 +00:00
|
|
|
static void IncrementLiveBytesFromGC(Address address, int by) {
|
2011-09-19 18:36:47 +00:00
|
|
|
MemoryChunk::FromAddress(address)->IncrementLiveBytes(by);
|
|
|
|
}
|
|
|
|
|
2012-01-18 09:21:07 +00:00
|
|
|
static void IncrementLiveBytesFromMutator(Address address, int by);
|
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
static const intptr_t kAlignment =
|
|
|
|
(static_cast<uintptr_t>(1) << kPageSizeBits);
|
|
|
|
|
|
|
|
static const intptr_t kAlignmentMask = kAlignment - 1;
|
|
|
|
|
2014-02-12 15:40:23 +00:00
|
|
|
static const intptr_t kSizeOffset = 0;
|
2011-09-20 11:20:00 +00:00
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
static const intptr_t kLiveBytesOffset =
|
2012-02-23 12:11:24 +00:00
|
|
|
kSizeOffset + kPointerSize + kPointerSize + kPointerSize +
|
|
|
|
kPointerSize + kPointerSize +
|
|
|
|
kPointerSize + kPointerSize + kPointerSize + kIntSize;
|
2011-09-19 18:36:47 +00:00
|
|
|
|
|
|
|
static const size_t kSlotsBufferOffset = kLiveBytesOffset + kIntSize;
|
|
|
|
|
2012-09-26 11:35:42 +00:00
|
|
|
static const size_t kWriteBarrierCounterOffset =
|
2012-09-26 08:55:19 +00:00
|
|
|
kSlotsBufferOffset + kPointerSize + kPointerSize;
|
2011-09-19 18:36:47 +00:00
|
|
|
|
2013-01-30 12:19:32 +00:00
|
|
|
static const size_t kHeaderSize = kWriteBarrierCounterOffset + kPointerSize +
|
2013-04-10 10:24:24 +00:00
|
|
|
kIntSize + kIntSize + kPointerSize +
|
2014-02-12 15:40:23 +00:00
|
|
|
5 * kPointerSize +
|
|
|
|
kPointerSize + kPointerSize;
|
2012-09-26 11:35:42 +00:00
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
static const int kBodyOffset =
|
2012-10-17 13:04:49 +00:00
|
|
|
CODE_POINTER_ALIGN(kHeaderSize + Bitmap::kSize);
|
2011-09-19 18:36:47 +00:00
|
|
|
|
|
|
|
// The start offset of the object area in a page. Aligned to both maps and
|
|
|
|
// code alignment to be suitable for both. Also aligned to 32 words because
|
|
|
|
// the marking bitmap is arranged in 32 bit chunks.
|
|
|
|
static const int kObjectStartAlignment = 32 * kPointerSize;
|
|
|
|
static const int kObjectStartOffset = kBodyOffset - 1 +
|
|
|
|
(kObjectStartAlignment - (kBodyOffset - 1) % kObjectStartAlignment);
|
|
|
|
|
2012-01-31 13:33:44 +00:00
|
|
|
size_t size() const { return size_; }
|
2011-09-19 18:36:47 +00:00
|
|
|
|
2012-01-31 13:33:44 +00:00
|
|
|
void set_size(size_t size) {
|
|
|
|
size_ = size;
|
|
|
|
}
|
2011-11-11 09:45:12 +00:00
|
|
|
|
2012-03-05 16:39:25 +00:00
|
|
|
void SetArea(Address area_start, Address area_end) {
|
|
|
|
area_start_ = area_start;
|
|
|
|
area_end_ = area_end;
|
|
|
|
}
|
|
|
|
|
2013-09-11 18:30:01 +00:00
|
|
|
Executability executable() {
|
|
|
|
return IsFlagSet(IS_EXECUTABLE) ? EXECUTABLE : NOT_EXECUTABLE;
|
2011-09-19 18:36:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ContainsOnlyData() {
|
|
|
|
return IsFlagSet(CONTAINS_ONLY_DATA);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool InNewSpace() {
|
|
|
|
return (flags_ & ((1 << IN_FROM_SPACE) | (1 << IN_TO_SPACE))) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool InToSpace() {
|
|
|
|
return IsFlagSet(IN_TO_SPACE);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool InFromSpace() {
|
|
|
|
return IsFlagSet(IN_FROM_SPACE);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
// Markbits support
|
|
|
|
|
|
|
|
inline Bitmap* markbits() {
|
|
|
|
return Bitmap::FromAddress(address() + kHeaderSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PrintMarkbits() { markbits()->Print(); }
|
|
|
|
|
|
|
|
inline uint32_t AddressToMarkbitIndex(Address addr) {
|
|
|
|
return static_cast<uint32_t>(addr - this->address()) >> kPointerSizeLog2;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline static uint32_t FastAddressToMarkbitIndex(Address addr) {
|
|
|
|
const intptr_t offset =
|
|
|
|
reinterpret_cast<intptr_t>(addr) & kAlignmentMask;
|
|
|
|
|
|
|
|
return static_cast<uint32_t>(offset) >> kPointerSizeLog2;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline Address MarkbitIndexToAddress(uint32_t index) {
|
|
|
|
return this->address() + (index << kPointerSizeLog2);
|
|
|
|
}
|
|
|
|
|
|
|
|
void InsertAfter(MemoryChunk* other);
|
|
|
|
void Unlink();
|
|
|
|
|
|
|
|
inline Heap* heap() { return heap_; }
|
|
|
|
|
2014-02-12 15:40:23 +00:00
|
|
|
static const int kFlagsOffset = kPointerSize;
|
2011-09-19 18:36:47 +00:00
|
|
|
|
|
|
|
bool IsEvacuationCandidate() { return IsFlagSet(EVACUATION_CANDIDATE); }
|
|
|
|
|
|
|
|
bool ShouldSkipEvacuationSlotRecording() {
|
|
|
|
return (flags_ & kSkipEvacuationSlotsRecordingMask) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline SkipList* skip_list() {
|
|
|
|
return skip_list_;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void set_skip_list(SkipList* skip_list) {
|
|
|
|
skip_list_ = skip_list;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline SlotsBuffer* slots_buffer() {
|
|
|
|
return slots_buffer_;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline SlotsBuffer** slots_buffer_address() {
|
|
|
|
return &slots_buffer_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MarkEvacuationCandidate() {
|
|
|
|
ASSERT(slots_buffer_ == NULL);
|
|
|
|
SetFlag(EVACUATION_CANDIDATE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClearEvacuationCandidate() {
|
|
|
|
ASSERT(slots_buffer_ == NULL);
|
|
|
|
ClearFlag(EVACUATION_CANDIDATE);
|
|
|
|
}
|
|
|
|
|
2012-02-23 12:11:24 +00:00
|
|
|
Address area_start() { return area_start_; }
|
|
|
|
Address area_end() { return area_end_; }
|
|
|
|
int area_size() {
|
|
|
|
return static_cast<int>(area_end() - area_start());
|
|
|
|
}
|
2013-01-29 09:09:55 +00:00
|
|
|
bool CommitArea(size_t requested);
|
2011-09-19 18:36:47 +00:00
|
|
|
|
2012-10-22 16:33:10 +00:00
|
|
|
// Approximate amount of physical memory committed for this chunk.
|
|
|
|
size_t CommittedPhysicalMemory() {
|
|
|
|
return high_water_mark_;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void UpdateHighWaterMark(Address mark);
|
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
protected:
|
|
|
|
size_t size_;
|
|
|
|
intptr_t flags_;
|
2012-02-23 12:11:24 +00:00
|
|
|
|
|
|
|
// Start and end of allocatable memory on this chunk.
|
|
|
|
Address area_start_;
|
|
|
|
Address area_end_;
|
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
// If the chunk needs to remember its memory reservation, it is stored here.
|
|
|
|
VirtualMemory reservation_;
|
|
|
|
// The identity of the owning space. This is tagged as a failure pointer, but
|
|
|
|
// no failure can be in an object, so this can be distinguished from any entry
|
|
|
|
// in a fixed array.
|
|
|
|
Address owner_;
|
|
|
|
Heap* heap_;
|
|
|
|
// Used by the store buffer to keep track of which pages to mark scan-on-
|
|
|
|
// scavenge.
|
|
|
|
int store_buffer_counter_;
|
|
|
|
// Count of bytes marked black on page.
|
|
|
|
int live_byte_count_;
|
|
|
|
SlotsBuffer* slots_buffer_;
|
|
|
|
SkipList* skip_list_;
|
2012-09-26 11:35:42 +00:00
|
|
|
intptr_t write_barrier_counter_;
|
2012-11-15 17:57:40 +00:00
|
|
|
// Used by the incremental marker to keep track of the scanning progress in
|
|
|
|
// large objects that have a progress bar and are scanned in increments.
|
|
|
|
int progress_bar_;
|
2012-10-22 16:33:10 +00:00
|
|
|
// Assuming the initial allocation on a page is sequential,
|
|
|
|
// count highest number of bytes ever allocated on the page.
|
|
|
|
int high_water_mark_;
|
2011-09-19 18:36:47 +00:00
|
|
|
|
2014-02-14 12:33:35 +00:00
|
|
|
AtomicWord parallel_sweeping_;
|
2013-01-30 12:19:32 +00:00
|
|
|
|
2013-04-10 10:24:24 +00:00
|
|
|
// PagedSpace free-list statistics.
|
|
|
|
intptr_t available_in_small_free_list_;
|
|
|
|
intptr_t available_in_medium_free_list_;
|
|
|
|
intptr_t available_in_large_free_list_;
|
|
|
|
intptr_t available_in_huge_free_list_;
|
|
|
|
intptr_t non_available_small_blocks_;
|
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
static MemoryChunk* Initialize(Heap* heap,
|
|
|
|
Address base,
|
|
|
|
size_t size,
|
2012-02-23 12:11:24 +00:00
|
|
|
Address area_start,
|
|
|
|
Address area_end,
|
2013-09-11 18:30:01 +00:00
|
|
|
Executability executable,
|
2011-09-19 18:36:47 +00:00
|
|
|
Space* owner);
|
|
|
|
|
2014-02-12 15:40:23 +00:00
|
|
|
private:
|
|
|
|
// next_chunk_ holds a pointer of type MemoryChunk
|
|
|
|
AtomicWord next_chunk_;
|
|
|
|
// prev_chunk_ holds a pointer of type MemoryChunk
|
|
|
|
AtomicWord prev_chunk_;
|
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
friend class MemoryAllocator;
|
|
|
|
};
|
|
|
|
|
2012-04-02 08:32:31 +00:00
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
STATIC_CHECK(sizeof(MemoryChunk) <= MemoryChunk::kHeaderSize);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2012-04-02 08:32:31 +00:00
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
2011-09-19 18:36:47 +00:00
|
|
|
// A page is a memory chunk of a size 1MB. Large object pages may be larger.
|
2008-07-03 15:10:15 +00:00
|
|
|
//
|
|
|
|
// The only way to get a page pointer is by calling factory methods:
|
|
|
|
// Page* p = Page::FromAddress(addr); or
|
|
|
|
// Page* p = Page::FromAllocationTop(top);
|
2011-09-19 18:36:47 +00:00
|
|
|
class Page : public MemoryChunk {
|
2008-07-03 15:10:15 +00:00
|
|
|
public:
|
|
|
|
// Returns the page containing a given address. The address ranges
|
|
|
|
// from [page_addr .. page_addr + kPageSize[
|
2011-09-19 18:36:47 +00:00
|
|
|
// This only works if the object is in fact in a page. See also MemoryChunk::
|
|
|
|
// FromAddress() and FromAnyAddress().
|
2008-07-03 15:10:15 +00:00
|
|
|
INLINE(static Page* FromAddress(Address a)) {
|
|
|
|
return reinterpret_cast<Page*>(OffsetFrom(a) & ~kPageAlignmentMask);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns the page containing an allocation top. Because an allocation
|
|
|
|
// top address can be the upper bound of the page, we need to subtract
|
|
|
|
// it with kPointerSize first. The address ranges from
|
|
|
|
// [page_addr + kObjectStartOffset .. page_addr + kPageSize].
|
|
|
|
INLINE(static Page* FromAllocationTop(Address top)) {
|
|
|
|
Page* p = FromAddress(top - kPointerSize);
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
// Returns the next page in the chain of pages owned by a space.
|
2008-07-03 15:10:15 +00:00
|
|
|
inline Page* next_page();
|
2011-09-19 18:36:47 +00:00
|
|
|
inline Page* prev_page();
|
|
|
|
inline void set_next_page(Page* page);
|
|
|
|
inline void set_prev_page(Page* page);
|
2010-05-27 12:30:45 +00:00
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// Checks whether an address is page aligned.
|
|
|
|
static bool IsAlignedToPageSize(Address a) {
|
|
|
|
return 0 == (OffsetFrom(a) & kPageAlignmentMask);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns the offset of a given address to this page.
|
|
|
|
INLINE(int Offset(Address a)) {
|
2009-11-11 09:50:06 +00:00
|
|
|
int offset = static_cast<int>(a - address());
|
2008-07-03 15:10:15 +00:00
|
|
|
return offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns the address for a given offset to the this page.
|
|
|
|
Address OffsetToAddress(int offset) {
|
|
|
|
ASSERT_PAGE_OFFSET(offset);
|
|
|
|
return address() + offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
|
2008-09-05 12:34:09 +00:00
|
|
|
// Page size in bytes. This must be a multiple of the OS page size.
|
2008-07-03 15:10:15 +00:00
|
|
|
static const int kPageSize = 1 << kPageSizeBits;
|
|
|
|
|
2013-07-24 08:50:03 +00:00
|
|
|
// Maximum object size that fits in a page. Objects larger than that size
|
|
|
|
// are allocated in large object space and are never moved in memory. This
|
|
|
|
// also applies to new space allocation, since objects are never migrated
|
2013-08-05 12:52:53 +00:00
|
|
|
// from new space to large object space. Takes double alignment into account.
|
2014-01-23 13:02:27 +00:00
|
|
|
static const int kMaxRegularHeapObjectSize = kPageSize - kObjectStartOffset;
|
2010-05-27 12:30:45 +00:00
|
|
|
|
2012-02-23 12:11:24 +00:00
|
|
|
// Page size mask.
|
|
|
|
static const intptr_t kPageAlignmentMask = (1 << kPageSizeBits) - 1;
|
2010-05-27 12:30:45 +00:00
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
inline void ClearGCFields();
|
2010-05-27 12:30:45 +00:00
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
static inline Page* Initialize(Heap* heap,
|
|
|
|
MemoryChunk* chunk,
|
2013-09-11 18:30:01 +00:00
|
|
|
Executability executable,
|
2011-09-19 18:36:47 +00:00
|
|
|
PagedSpace* owner);
|
2010-05-27 12:30:45 +00:00
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
void InitializeAsAnchor(PagedSpace* owner);
|
2010-05-27 12:30:45 +00:00
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
bool WasSweptPrecisely() { return IsFlagSet(WAS_SWEPT_PRECISELY); }
|
|
|
|
bool WasSweptConservatively() { return IsFlagSet(WAS_SWEPT_CONSERVATIVELY); }
|
|
|
|
bool WasSwept() { return WasSweptPrecisely() || WasSweptConservatively(); }
|
2010-05-27 12:30:45 +00:00
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
void MarkSweptPrecisely() { SetFlag(WAS_SWEPT_PRECISELY); }
|
|
|
|
void MarkSweptConservatively() { SetFlag(WAS_SWEPT_CONSERVATIVELY); }
|
2010-05-27 12:30:45 +00:00
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
void ClearSweptPrecisely() { ClearFlag(WAS_SWEPT_PRECISELY); }
|
|
|
|
void ClearSweptConservatively() { ClearFlag(WAS_SWEPT_CONSERVATIVELY); }
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2013-04-10 10:24:24 +00:00
|
|
|
void ResetFreeListStatistics();
|
|
|
|
|
|
|
|
#define FRAGMENTATION_STATS_ACCESSORS(type, name) \
|
|
|
|
type name() { return name##_; } \
|
|
|
|
void set_##name(type name) { name##_ = name; } \
|
|
|
|
void add_##name(type name) { name##_ += name; }
|
|
|
|
|
|
|
|
FRAGMENTATION_STATS_ACCESSORS(intptr_t, non_available_small_blocks)
|
|
|
|
FRAGMENTATION_STATS_ACCESSORS(intptr_t, available_in_small_free_list)
|
|
|
|
FRAGMENTATION_STATS_ACCESSORS(intptr_t, available_in_medium_free_list)
|
|
|
|
FRAGMENTATION_STATS_ACCESSORS(intptr_t, available_in_large_free_list)
|
|
|
|
FRAGMENTATION_STATS_ACCESSORS(intptr_t, available_in_huge_free_list)
|
|
|
|
|
|
|
|
#undef FRAGMENTATION_STATS_ACCESSORS
|
|
|
|
|
2011-09-20 11:20:00 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
void Print();
|
|
|
|
#endif // DEBUG
|
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
friend class MemoryAllocator;
|
|
|
|
};
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
STATIC_CHECK(sizeof(Page) <= MemoryChunk::kHeaderSize);
|
2011-03-18 20:35:07 +00:00
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
|
|
|
|
class LargePage : public MemoryChunk {
|
|
|
|
public:
|
|
|
|
HeapObject* GetObject() {
|
2012-02-23 12:11:24 +00:00
|
|
|
return HeapObject::FromAddress(area_start());
|
2011-09-19 18:36:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline LargePage* next_page() const {
|
|
|
|
return static_cast<LargePage*>(next_chunk());
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void set_next_page(LargePage* page) {
|
|
|
|
set_next_chunk(page);
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
static inline LargePage* Initialize(Heap* heap, MemoryChunk* chunk);
|
|
|
|
|
|
|
|
friend class MemoryAllocator;
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
STATIC_CHECK(sizeof(LargePage) <= MemoryChunk::kHeaderSize);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-07-30 08:49:36 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Space is the abstract superclass for all allocation spaces.
|
|
|
|
class Space : public Malloced {
|
|
|
|
public:
|
2013-09-11 18:30:01 +00:00
|
|
|
Space(Heap* heap, AllocationSpace id, Executability executable)
|
|
|
|
: heap_(heap), id_(id), executable_(executable) {}
|
2009-03-24 12:47:53 +00:00
|
|
|
|
2008-09-05 12:34:09 +00:00
|
|
|
virtual ~Space() {}
|
2009-03-24 12:47:53 +00:00
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
Heap* heap() const { return heap_; }
|
|
|
|
|
2008-07-30 08:49:36 +00:00
|
|
|
// Does the space need executable memory?
|
2013-09-11 18:30:01 +00:00
|
|
|
Executability executable() { return executable_; }
|
2009-03-24 12:47:53 +00:00
|
|
|
|
2008-07-30 08:49:36 +00:00
|
|
|
// Identity used in error reporting.
|
|
|
|
AllocationSpace identity() { return id_; }
|
2009-03-24 12:47:53 +00:00
|
|
|
|
2010-11-15 10:38:24 +00:00
|
|
|
// Returns allocated size.
|
2010-09-30 07:22:53 +00:00
|
|
|
virtual intptr_t Size() = 0;
|
2009-03-24 12:47:53 +00:00
|
|
|
|
2010-11-15 10:38:24 +00:00
|
|
|
// Returns size of objects. Can differ from the allocated size
|
|
|
|
// (e.g. see LargeObjectSpace).
|
|
|
|
virtual intptr_t SizeOfObjects() { return Size(); }
|
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
virtual int RoundSizeDownToObjectAlignment(int size) {
|
|
|
|
if (id_ == CODE_SPACE) {
|
|
|
|
return RoundDown(size, kCodeAlignment);
|
|
|
|
} else {
|
|
|
|
return RoundDown(size, kPointerSize);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-05 12:34:09 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
virtual void Print() = 0;
|
|
|
|
#endif
|
2009-03-24 12:47:53 +00:00
|
|
|
|
2008-07-30 08:49:36 +00:00
|
|
|
private:
|
2011-03-18 20:35:07 +00:00
|
|
|
Heap* heap_;
|
2008-07-30 08:49:36 +00:00
|
|
|
AllocationSpace id_;
|
2013-09-11 18:30:01 +00:00
|
|
|
Executability executable_;
|
2008-07-30 08:49:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-10-05 11:16:25 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// All heap objects containing executable code (code objects) must be allocated
|
|
|
|
// from a 2 GB range of memory, so that they can call each other using 32-bit
|
|
|
|
// displacements. This happens automatically on 32-bit platforms, where 32-bit
|
|
|
|
// displacements cover the entire 4GB virtual address space. On 64-bit
|
|
|
|
// platforms, we support this using the CodeRange object, which reserves and
|
|
|
|
// manages a range of virtual memory.
|
2011-03-18 20:35:07 +00:00
|
|
|
class CodeRange {
|
2009-10-05 11:16:25 +00:00
|
|
|
public:
|
2011-08-04 15:18:18 +00:00
|
|
|
explicit CodeRange(Isolate* isolate);
|
2011-08-18 12:33:40 +00:00
|
|
|
~CodeRange() { TearDown(); }
|
2011-08-04 15:18:18 +00:00
|
|
|
|
2009-10-05 11:16:25 +00:00
|
|
|
// Reserves a range of virtual memory, but does not commit any of it.
|
|
|
|
// Can only be called once, at heap initialization time.
|
|
|
|
// Returns false on failure.
|
2014-04-09 12:45:56 +00:00
|
|
|
bool SetUp(size_t requested_size);
|
2009-10-05 11:16:25 +00:00
|
|
|
|
|
|
|
// Frees the range of virtual memory, and frees the data structures used to
|
|
|
|
// manage it.
|
2011-03-18 20:35:07 +00:00
|
|
|
void TearDown();
|
2009-10-05 11:16:25 +00:00
|
|
|
|
2011-08-04 15:18:18 +00:00
|
|
|
bool exists() { return this != NULL && code_range_ != NULL; }
|
2013-03-11 14:11:03 +00:00
|
|
|
Address start() {
|
|
|
|
if (this == NULL || code_range_ == NULL) return NULL;
|
|
|
|
return static_cast<Address>(code_range_->address());
|
|
|
|
}
|
2011-03-18 20:35:07 +00:00
|
|
|
bool contains(Address address) {
|
2011-08-04 15:18:18 +00:00
|
|
|
if (this == NULL || code_range_ == NULL) return false;
|
2009-10-05 11:16:25 +00:00
|
|
|
Address start = static_cast<Address>(code_range_->address());
|
|
|
|
return start <= address && address < start + code_range_->size();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Allocates a chunk of memory from the large-object portion of
|
|
|
|
// the code range. On platforms with no separate code range, should
|
|
|
|
// not be called.
|
2013-01-29 09:09:55 +00:00
|
|
|
MUST_USE_RESULT Address AllocateRawMemory(const size_t requested_size,
|
|
|
|
const size_t commit_size,
|
2011-09-19 18:36:47 +00:00
|
|
|
size_t* allocated);
|
2013-01-29 09:09:55 +00:00
|
|
|
bool CommitRawMemory(Address start, size_t length);
|
|
|
|
bool UncommitRawMemory(Address start, size_t length);
|
2011-09-19 18:36:47 +00:00
|
|
|
void FreeRawMemory(Address buf, size_t length);
|
2009-10-05 11:16:25 +00:00
|
|
|
|
|
|
|
private:
|
2011-08-04 15:18:18 +00:00
|
|
|
Isolate* isolate_;
|
2011-03-18 20:35:07 +00:00
|
|
|
|
2009-10-05 11:16:25 +00:00
|
|
|
// The reserved range of virtual memory that all code objects are put in.
|
2011-03-18 20:35:07 +00:00
|
|
|
VirtualMemory* code_range_;
|
2009-10-05 11:16:25 +00:00
|
|
|
// Plain old data class, just a struct plus a constructor.
|
|
|
|
class FreeBlock {
|
|
|
|
public:
|
|
|
|
FreeBlock(Address start_arg, size_t size_arg)
|
2011-09-19 18:36:47 +00:00
|
|
|
: start(start_arg), size(size_arg) {
|
|
|
|
ASSERT(IsAddressAligned(start, MemoryChunk::kAlignment));
|
2012-01-31 13:33:44 +00:00
|
|
|
ASSERT(size >= static_cast<size_t>(Page::kPageSize));
|
2011-09-19 18:36:47 +00:00
|
|
|
}
|
2009-10-05 11:16:25 +00:00
|
|
|
FreeBlock(void* start_arg, size_t size_arg)
|
2011-09-19 18:36:47 +00:00
|
|
|
: start(static_cast<Address>(start_arg)), size(size_arg) {
|
|
|
|
ASSERT(IsAddressAligned(start, MemoryChunk::kAlignment));
|
2012-01-31 13:33:44 +00:00
|
|
|
ASSERT(size >= static_cast<size_t>(Page::kPageSize));
|
2011-09-19 18:36:47 +00:00
|
|
|
}
|
2009-10-05 11:16:25 +00:00
|
|
|
|
|
|
|
Address start;
|
|
|
|
size_t size;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Freed blocks of memory are added to the free list. When the allocation
|
|
|
|
// list is exhausted, the free list is sorted and merged to make the new
|
|
|
|
// allocation list.
|
2011-03-18 20:35:07 +00:00
|
|
|
List<FreeBlock> free_list_;
|
2009-10-05 11:16:25 +00:00
|
|
|
// Memory is allocated from the free blocks on the allocation list.
|
|
|
|
// The block at current_allocation_block_index_ is the current block.
|
2011-03-18 20:35:07 +00:00
|
|
|
List<FreeBlock> allocation_list_;
|
|
|
|
int current_allocation_block_index_;
|
2009-10-05 11:16:25 +00:00
|
|
|
|
|
|
|
// Finds a block on the allocation list that contains at least the
|
|
|
|
// requested amount of memory. If none is found, sorts and merges
|
|
|
|
// the existing free memory blocks, and searches again.
|
|
|
|
// If none can be found, terminates V8 with FatalProcessOutOfMemory.
|
2011-03-18 20:35:07 +00:00
|
|
|
void GetNextAllocationBlock(size_t requested);
|
2009-10-05 11:16:25 +00:00
|
|
|
// Compares the start addresses of two free blocks.
|
|
|
|
static int CompareFreeBlockAddress(const FreeBlock* left,
|
|
|
|
const FreeBlock* right);
|
2011-03-18 20:35:07 +00:00
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(CodeRange);
|
2009-10-05 11:16:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
class SkipList {
|
|
|
|
public:
|
|
|
|
SkipList() {
|
|
|
|
Clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Clear() {
|
|
|
|
for (int idx = 0; idx < kSize; idx++) {
|
|
|
|
starts_[idx] = reinterpret_cast<Address>(-1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Address StartFor(Address addr) {
|
|
|
|
return starts_[RegionNumber(addr)];
|
|
|
|
}
|
|
|
|
|
|
|
|
void AddObject(Address addr, int size) {
|
|
|
|
int start_region = RegionNumber(addr);
|
|
|
|
int end_region = RegionNumber(addr + size - kPointerSize);
|
|
|
|
for (int idx = start_region; idx <= end_region; idx++) {
|
|
|
|
if (starts_[idx] > addr) starts_[idx] = addr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int RegionNumber(Address addr) {
|
|
|
|
return (OffsetFrom(addr) & Page::kPageAlignmentMask) >> kRegionSizeLog2;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void Update(Address addr, int size) {
|
|
|
|
Page* page = Page::FromAddress(addr);
|
|
|
|
SkipList* list = page->skip_list();
|
|
|
|
if (list == NULL) {
|
|
|
|
list = new SkipList();
|
|
|
|
page->set_skip_list(list);
|
|
|
|
}
|
|
|
|
|
|
|
|
list->AddObject(addr, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
static const int kRegionSizeLog2 = 13;
|
|
|
|
static const int kRegionSize = 1 << kRegionSizeLog2;
|
|
|
|
static const int kSize = Page::kPageSize / kRegionSize;
|
|
|
|
|
|
|
|
STATIC_ASSERT(Page::kPageSize % kRegionSize == 0);
|
|
|
|
|
|
|
|
Address starts_[kSize];
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// A space acquires chunks of memory from the operating system. The memory
|
2011-09-19 18:36:47 +00:00
|
|
|
// allocator allocated and deallocates pages for the paged heap spaces and large
|
|
|
|
// pages for large object space.
|
2008-07-03 15:10:15 +00:00
|
|
|
//
|
2011-09-19 18:36:47 +00:00
|
|
|
// Each space has to manage it's own pages.
|
2010-04-22 14:42:21 +00:00
|
|
|
//
|
2011-03-18 20:35:07 +00:00
|
|
|
class MemoryAllocator {
|
2008-07-03 15:10:15 +00:00
|
|
|
public:
|
2011-08-04 15:18:18 +00:00
|
|
|
explicit MemoryAllocator(Isolate* isolate);
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// Initializes its internal bookkeeping structures.
|
2010-11-10 08:38:42 +00:00
|
|
|
// Max capacity of the total space and executable memory limit.
|
2012-01-13 13:09:52 +00:00
|
|
|
bool SetUp(intptr_t max_capacity, intptr_t capacity_executable);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
void TearDown();
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2013-09-11 18:30:01 +00:00
|
|
|
Page* AllocatePage(
|
|
|
|
intptr_t size, PagedSpace* owner, Executability executable);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2013-09-11 18:30:01 +00:00
|
|
|
LargePage* AllocateLargePage(
|
|
|
|
intptr_t object_size, Space* owner, Executability executable);
|
2011-03-18 20:35:07 +00:00
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
void Free(MemoryChunk* chunk);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// Returns the maximum available bytes of heaps.
|
2012-01-31 13:33:44 +00:00
|
|
|
intptr_t Available() { return capacity_ < size_ ? 0 : capacity_ - size_; }
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-07-13 21:24:54 +00:00
|
|
|
// Returns allocated spaces in bytes.
|
2012-01-31 13:33:44 +00:00
|
|
|
intptr_t Size() { return size_; }
|
2009-07-13 21:24:54 +00:00
|
|
|
|
2010-11-10 08:38:42 +00:00
|
|
|
// Returns the maximum available executable bytes of heaps.
|
2011-03-18 20:35:07 +00:00
|
|
|
intptr_t AvailableExecutable() {
|
2010-11-10 08:38:42 +00:00
|
|
|
if (capacity_executable_ < size_executable_) return 0;
|
|
|
|
return capacity_executable_ - size_executable_;
|
|
|
|
}
|
|
|
|
|
2010-08-18 10:45:15 +00:00
|
|
|
// Returns allocated executable spaces in bytes.
|
2011-03-18 20:35:07 +00:00
|
|
|
intptr_t SizeExecutable() { return size_executable_; }
|
2010-08-18 10:45:15 +00:00
|
|
|
|
2008-09-05 12:34:09 +00:00
|
|
|
// Returns maximum available bytes that the old space can have.
|
2011-03-18 20:35:07 +00:00
|
|
|
intptr_t MaxAvailable() {
|
2014-01-23 13:02:27 +00:00
|
|
|
return (Available() / Page::kPageSize) * Page::kMaxRegularHeapObjectSize;
|
2008-09-05 12:34:09 +00:00
|
|
|
}
|
|
|
|
|
2013-09-05 08:17:57 +00:00
|
|
|
// Returns an indication of whether a pointer is in a space that has
|
|
|
|
// been allocated by this MemoryAllocator.
|
2013-09-12 08:57:10 +00:00
|
|
|
V8_INLINE bool IsOutsideAllocatedSpace(const void* address) const {
|
2013-09-05 08:17:57 +00:00
|
|
|
return address < lowest_ever_allocated_ ||
|
|
|
|
address >= highest_ever_allocated_;
|
|
|
|
}
|
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
// Reports statistic info of the space.
|
|
|
|
void ReportStatistics();
|
|
|
|
#endif
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2013-01-29 09:09:55 +00:00
|
|
|
// Returns a MemoryChunk in which the memory region from commit_area_size to
|
|
|
|
// reserve_area_size of the chunk area is reserved but not committed, it
|
|
|
|
// could be committed later by calling MemoryChunk::CommitArea.
|
|
|
|
MemoryChunk* AllocateChunk(intptr_t reserve_area_size,
|
|
|
|
intptr_t commit_area_size,
|
2013-09-11 18:30:01 +00:00
|
|
|
Executability executable,
|
2011-09-19 18:36:47 +00:00
|
|
|
Space* space);
|
|
|
|
|
|
|
|
Address ReserveAlignedMemory(size_t requested,
|
|
|
|
size_t alignment,
|
|
|
|
VirtualMemory* controller);
|
2013-01-29 09:09:55 +00:00
|
|
|
Address AllocateAlignedMemory(size_t reserve_size,
|
|
|
|
size_t commit_size,
|
2011-09-19 18:36:47 +00:00
|
|
|
size_t alignment,
|
2013-09-11 18:30:01 +00:00
|
|
|
Executability executable,
|
2011-09-19 18:36:47 +00:00
|
|
|
VirtualMemory* controller);
|
|
|
|
|
2013-09-11 18:30:01 +00:00
|
|
|
bool CommitMemory(Address addr, size_t size, Executability executable);
|
2013-09-05 08:17:57 +00:00
|
|
|
|
2013-09-11 18:30:01 +00:00
|
|
|
void FreeMemory(VirtualMemory* reservation, Executability executable);
|
|
|
|
void FreeMemory(Address addr, size_t size, Executability executable);
|
2011-09-19 18:36:47 +00:00
|
|
|
|
|
|
|
// Commit a contiguous block of memory from the initial chunk. Assumes that
|
|
|
|
// the address is not NULL, the size is greater than zero, and that the
|
|
|
|
// block is contained in the initial chunk. Returns true if it succeeded
|
|
|
|
// and false otherwise.
|
2013-09-11 18:30:01 +00:00
|
|
|
bool CommitBlock(Address start, size_t size, Executability executable);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
// Uncommit a contiguous block of memory [start..(start+size)[.
|
|
|
|
// start is not NULL, the size is greater than zero, and the
|
|
|
|
// block is contained in the initial chunk. Returns true if it succeeded
|
|
|
|
// and false otherwise.
|
|
|
|
bool UncommitBlock(Address start, size_t size);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
// Zaps a contiguous block of memory [start..(start+size)[ thus
|
|
|
|
// filling it up with a recognizable non-NULL bit pattern.
|
|
|
|
void ZapBlock(Address start, size_t size);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
void PerformAllocationCallback(ObjectSpace space,
|
|
|
|
AllocationAction action,
|
|
|
|
size_t size);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
void AddMemoryAllocationCallback(MemoryAllocationCallback callback,
|
|
|
|
ObjectSpace space,
|
|
|
|
AllocationAction action);
|
2010-04-22 14:42:21 +00:00
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
void RemoveMemoryAllocationCallback(
|
|
|
|
MemoryAllocationCallback callback);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
bool MemoryAllocationCallbackRegistered(
|
|
|
|
MemoryAllocationCallback callback);
|
2010-12-07 09:11:56 +00:00
|
|
|
|
2012-02-23 12:11:24 +00:00
|
|
|
static int CodePageGuardStartOffset();
|
|
|
|
|
|
|
|
static int CodePageGuardSize();
|
|
|
|
|
|
|
|
static int CodePageAreaStartOffset();
|
|
|
|
|
|
|
|
static int CodePageAreaEndOffset();
|
|
|
|
|
|
|
|
static int CodePageAreaSize() {
|
|
|
|
return CodePageAreaEndOffset() - CodePageAreaStartOffset();
|
|
|
|
}
|
|
|
|
|
2013-09-05 08:17:57 +00:00
|
|
|
MUST_USE_RESULT bool CommitExecutableMemory(VirtualMemory* vm,
|
|
|
|
Address start,
|
|
|
|
size_t commit_size,
|
|
|
|
size_t reserved_size);
|
2012-02-23 12:11:24 +00:00
|
|
|
|
2010-12-07 11:01:02 +00:00
|
|
|
private:
|
2011-08-04 15:18:18 +00:00
|
|
|
Isolate* isolate_;
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// Maximum space size in bytes.
|
2011-09-19 18:36:47 +00:00
|
|
|
size_t capacity_;
|
2010-11-10 08:38:42 +00:00
|
|
|
// Maximum subset of capacity_ that can be executable
|
2011-09-19 18:36:47 +00:00
|
|
|
size_t capacity_executable_;
|
2011-03-18 18:49:56 +00:00
|
|
|
|
2011-03-18 19:41:05 +00:00
|
|
|
// Allocated space size in bytes.
|
2012-01-31 13:33:44 +00:00
|
|
|
size_t size_;
|
2010-08-18 10:45:15 +00:00
|
|
|
// Allocated executable space size in bytes.
|
2011-09-19 18:36:47 +00:00
|
|
|
size_t size_executable_;
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2013-09-05 08:17:57 +00:00
|
|
|
// We keep the lowest and highest addresses allocated as a quick way
|
|
|
|
// of determining that pointers are outside the heap. The estimate is
|
|
|
|
// conservative, i.e. not all addrsses in 'allocated' space are allocated
|
|
|
|
// to our heap. The range is [lowest, highest[, inclusive on the low end
|
|
|
|
// and exclusive on the high end.
|
|
|
|
void* lowest_ever_allocated_;
|
|
|
|
void* highest_ever_allocated_;
|
|
|
|
|
2010-09-03 11:31:58 +00:00
|
|
|
struct MemoryAllocationCallbackRegistration {
|
|
|
|
MemoryAllocationCallbackRegistration(MemoryAllocationCallback callback,
|
|
|
|
ObjectSpace space,
|
|
|
|
AllocationAction action)
|
|
|
|
: callback(callback), space(space), action(action) {
|
|
|
|
}
|
|
|
|
MemoryAllocationCallback callback;
|
|
|
|
ObjectSpace space;
|
|
|
|
AllocationAction action;
|
|
|
|
};
|
2011-09-19 18:36:47 +00:00
|
|
|
|
2010-09-03 11:31:58 +00:00
|
|
|
// A List of callback that are triggered when memory is allocated or free'd
|
2011-03-18 20:35:07 +00:00
|
|
|
List<MemoryAllocationCallbackRegistration>
|
2010-09-03 11:31:58 +00:00
|
|
|
memory_allocation_callbacks_;
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// Initializes pages in a chunk. Returns the first page address.
|
|
|
|
// This function and GetChunkId() are provided for the mark-compact
|
|
|
|
// collector to rebuild page headers in the from space, which is
|
|
|
|
// used as a marking stack and its page headers are destroyed.
|
2011-03-18 20:35:07 +00:00
|
|
|
Page* InitializePagesInChunk(int chunk_id, int pages_in_chunk,
|
|
|
|
PagedSpace* owner);
|
2011-03-18 18:49:56 +00:00
|
|
|
|
2013-09-05 08:17:57 +00:00
|
|
|
void UpdateAllocatedSpaceLimits(void* low, void* high) {
|
|
|
|
lowest_ever_allocated_ = Min(lowest_ever_allocated_, low);
|
|
|
|
highest_ever_allocated_ = Max(highest_ever_allocated_, high);
|
|
|
|
}
|
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
DISALLOW_IMPLICIT_CONSTRUCTORS(MemoryAllocator);
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Interface for heap object iterator to be implemented by all object space
|
|
|
|
// object iterators.
|
|
|
|
//
|
2010-01-25 22:53:18 +00:00
|
|
|
// NOTE: The space specific object iterators also implements the own next()
|
|
|
|
// method which is used to avoid using virtual functions
|
2008-07-03 15:10:15 +00:00
|
|
|
// iterating a specific space.
|
|
|
|
|
|
|
|
class ObjectIterator : public Malloced {
|
|
|
|
public:
|
|
|
|
virtual ~ObjectIterator() { }
|
|
|
|
|
|
|
|
virtual HeapObject* next_object() = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Heap object iterator in new/old/map spaces.
|
|
|
|
//
|
2011-09-19 18:36:47 +00:00
|
|
|
// A HeapObjectIterator iterates objects from the bottom of the given space
|
|
|
|
// to its top or from the bottom of the given page to its top.
|
2009-05-14 08:55:34 +00:00
|
|
|
//
|
2011-09-19 18:36:47 +00:00
|
|
|
// If objects are allocated in the page during iteration the iterator may
|
|
|
|
// or may not iterate over those objects. The caller must create a new
|
|
|
|
// iterator in order to be sure to visit these new objects.
|
2008-07-03 15:10:15 +00:00
|
|
|
class HeapObjectIterator: public ObjectIterator {
|
|
|
|
public:
|
2011-09-19 18:36:47 +00:00
|
|
|
// Creates a new object iterator in a given space.
|
2008-07-03 15:10:15 +00:00
|
|
|
// If the size function is not given, the iterator calls the default
|
|
|
|
// Object::Size().
|
|
|
|
explicit HeapObjectIterator(PagedSpace* space);
|
|
|
|
HeapObjectIterator(PagedSpace* space, HeapObjectCallback size_func);
|
2010-08-30 08:54:43 +00:00
|
|
|
HeapObjectIterator(Page* page, HeapObjectCallback size_func);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
// Advance to the next object, skipping free spaces and other fillers and
|
|
|
|
// skipping the special garbage section of which there is one per space.
|
|
|
|
// Returns NULL when the iteration has ended.
|
|
|
|
inline HeapObject* Next() {
|
|
|
|
do {
|
|
|
|
HeapObject* next_obj = FromCurrentPage();
|
|
|
|
if (next_obj != NULL) return next_obj;
|
|
|
|
} while (AdvanceToNextPage());
|
|
|
|
return NULL;
|
2010-01-25 22:53:18 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
virtual HeapObject* next_object() {
|
|
|
|
return Next();
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
private:
|
2011-09-19 18:36:47 +00:00
|
|
|
enum PageMode { kOnePageOnly, kAllPagesInSpace };
|
2010-01-25 22:53:18 +00:00
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
Address cur_addr_; // Current iteration point.
|
|
|
|
Address cur_end_; // End iteration point.
|
|
|
|
HeapObjectCallback size_func_; // Size function or NULL.
|
|
|
|
PagedSpace* space_;
|
|
|
|
PageMode page_mode_;
|
2010-01-25 22:53:18 +00:00
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
// Fast (inlined) path of next().
|
|
|
|
inline HeapObject* FromCurrentPage();
|
2010-01-25 22:53:18 +00:00
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
// Slow path of next(), goes into the next page. Returns false if the
|
|
|
|
// iteration has ended.
|
|
|
|
bool AdvanceToNextPage();
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// Initializes fields.
|
2011-09-19 18:36:47 +00:00
|
|
|
inline void Initialize(PagedSpace* owner,
|
|
|
|
Address start,
|
|
|
|
Address end,
|
|
|
|
PageMode mode,
|
|
|
|
HeapObjectCallback size_func);
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
2009-05-14 08:55:34 +00:00
|
|
|
// A PageIterator iterates the pages in a paged space.
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
class PageIterator BASE_EMBEDDED {
|
|
|
|
public:
|
2011-09-19 18:36:47 +00:00
|
|
|
explicit inline PageIterator(PagedSpace* space);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
inline bool has_next();
|
|
|
|
inline Page* next();
|
|
|
|
|
|
|
|
private:
|
2009-05-14 08:55:34 +00:00
|
|
|
PagedSpace* space_;
|
|
|
|
Page* prev_page_; // Previous page returned.
|
2011-09-19 18:36:47 +00:00
|
|
|
// Next page that will be returned. Cached here so that we can use this
|
|
|
|
// iterator for operations that deallocate pages.
|
|
|
|
Page* next_page_;
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
2011-09-19 18:36:47 +00:00
|
|
|
// A space has a circular list of pages. The next page can be accessed via
|
|
|
|
// Page::next_page() call.
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// An abstraction of allocation and relocation pointers in a page-structured
|
|
|
|
// space.
|
2008-07-30 08:49:36 +00:00
|
|
|
class AllocationInfo {
|
|
|
|
public:
|
2013-10-25 09:58:21 +00:00
|
|
|
AllocationInfo() : top_(NULL), limit_(NULL) {
|
2011-09-19 18:36:47 +00:00
|
|
|
}
|
|
|
|
|
2013-10-25 09:58:21 +00:00
|
|
|
INLINE(void set_top(Address top)) {
|
|
|
|
SLOW_ASSERT(top == NULL ||
|
|
|
|
(reinterpret_cast<intptr_t>(top) & HeapObjectTagMask()) == 0);
|
|
|
|
top_ = top;
|
|
|
|
}
|
|
|
|
|
|
|
|
INLINE(Address top()) const {
|
|
|
|
SLOW_ASSERT(top_ == NULL ||
|
|
|
|
(reinterpret_cast<intptr_t>(top_) & HeapObjectTagMask()) == 0);
|
|
|
|
return top_;
|
|
|
|
}
|
|
|
|
|
|
|
|
Address* top_address() {
|
|
|
|
return &top_;
|
|
|
|
}
|
|
|
|
|
|
|
|
INLINE(void set_limit(Address limit)) {
|
|
|
|
SLOW_ASSERT(limit == NULL ||
|
|
|
|
(reinterpret_cast<intptr_t>(limit) & HeapObjectTagMask()) == 0);
|
|
|
|
limit_ = limit;
|
|
|
|
}
|
|
|
|
|
|
|
|
INLINE(Address limit()) const {
|
|
|
|
SLOW_ASSERT(limit_ == NULL ||
|
|
|
|
(reinterpret_cast<intptr_t>(limit_) & HeapObjectTagMask()) == 0);
|
|
|
|
return limit_;
|
|
|
|
}
|
|
|
|
|
|
|
|
Address* limit_address() {
|
|
|
|
return &limit_;
|
|
|
|
}
|
2008-07-30 08:49:36 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
bool VerifyPagedAllocation() {
|
2013-10-25 09:58:21 +00:00
|
|
|
return (Page::FromAllocationTop(top_) == Page::FromAllocationTop(limit_))
|
|
|
|
&& (top_ <= limit_);
|
2008-07-30 08:49:36 +00:00
|
|
|
}
|
|
|
|
#endif
|
2013-10-25 09:58:21 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
// Current allocation top.
|
|
|
|
Address top_;
|
|
|
|
// Current allocation limit.
|
|
|
|
Address limit_;
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// An abstraction of the accounting statistics of a page-structured space.
|
2012-01-16 12:38:59 +00:00
|
|
|
// The 'capacity' of a space is the number of object-area bytes (i.e., not
|
2008-07-03 15:10:15 +00:00
|
|
|
// including page bookkeeping structures) currently in the space. The 'size'
|
|
|
|
// of a space is the number of allocated bytes, the 'waste' in the space is
|
|
|
|
// the number of bytes that are not allocated and not available to
|
2012-01-16 12:38:59 +00:00
|
|
|
// allocation without reorganizing the space via a GC (e.g. small blocks due
|
2008-07-03 15:10:15 +00:00
|
|
|
// to internal fragmentation, top of page areas in map space), and the bytes
|
|
|
|
// 'available' is the number of unallocated bytes that are not waste. The
|
|
|
|
// capacity is the sum of size, waste, and available.
|
|
|
|
//
|
|
|
|
// The stats are only set by functions that ensure they stay balanced. These
|
|
|
|
// functions increase or decrease one of the non-capacity stats in
|
|
|
|
// conjunction with capacity, or else they always balance increases and
|
|
|
|
// decreases to the non-capacity stats.
|
|
|
|
class AllocationStats BASE_EMBEDDED {
|
|
|
|
public:
|
|
|
|
AllocationStats() { Clear(); }
|
|
|
|
|
2012-01-16 12:38:59 +00:00
|
|
|
// Zero out all the allocation statistics (i.e., no capacity).
|
2008-07-03 15:10:15 +00:00
|
|
|
void Clear() {
|
|
|
|
capacity_ = 0;
|
2013-11-05 11:59:42 +00:00
|
|
|
max_capacity_ = 0;
|
2008-07-03 15:10:15 +00:00
|
|
|
size_ = 0;
|
|
|
|
waste_ = 0;
|
|
|
|
}
|
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
void ClearSizeWaste() {
|
|
|
|
size_ = capacity_;
|
|
|
|
waste_ = 0;
|
|
|
|
}
|
|
|
|
|
2012-01-16 12:38:59 +00:00
|
|
|
// Reset the allocation statistics (i.e., available = capacity with no
|
2008-07-03 15:10:15 +00:00
|
|
|
// wasted or allocated bytes).
|
|
|
|
void Reset() {
|
|
|
|
size_ = 0;
|
|
|
|
waste_ = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Accessors for the allocation statistics.
|
2010-09-30 07:22:53 +00:00
|
|
|
intptr_t Capacity() { return capacity_; }
|
2013-11-05 11:59:42 +00:00
|
|
|
intptr_t MaxCapacity() { return max_capacity_; }
|
2010-09-30 07:22:53 +00:00
|
|
|
intptr_t Size() { return size_; }
|
|
|
|
intptr_t Waste() { return waste_; }
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
// Grow the space by adding available bytes. They are initially marked as
|
|
|
|
// being in use (part of the size), but will normally be immediately freed,
|
|
|
|
// putting them on the free list and removing them from size_.
|
2008-07-03 15:10:15 +00:00
|
|
|
void ExpandSpace(int size_in_bytes) {
|
|
|
|
capacity_ += size_in_bytes;
|
2011-09-19 18:36:47 +00:00
|
|
|
size_ += size_in_bytes;
|
2013-11-05 11:59:42 +00:00
|
|
|
if (capacity_ > max_capacity_) {
|
|
|
|
max_capacity_ = capacity_;
|
|
|
|
}
|
2011-09-19 18:36:47 +00:00
|
|
|
ASSERT(size_ >= 0);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 12:27:31 +00:00
|
|
|
// Shrink the space by removing available bytes. Since shrinking is done
|
|
|
|
// during sweeping, bytes have been marked as being in use (part of the size)
|
|
|
|
// and are hereby freed.
|
|
|
|
void ShrinkSpace(int size_in_bytes) {
|
|
|
|
capacity_ -= size_in_bytes;
|
|
|
|
size_ -= size_in_bytes;
|
|
|
|
ASSERT(size_ >= 0);
|
|
|
|
}
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// Allocate from available bytes (available -> size).
|
2010-09-30 07:22:53 +00:00
|
|
|
void AllocateBytes(intptr_t size_in_bytes) {
|
2008-07-03 15:10:15 +00:00
|
|
|
size_ += size_in_bytes;
|
2011-09-19 18:36:47 +00:00
|
|
|
ASSERT(size_ >= 0);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Free allocated bytes, making them available (size -> available).
|
2010-09-30 07:22:53 +00:00
|
|
|
void DeallocateBytes(intptr_t size_in_bytes) {
|
2008-07-03 15:10:15 +00:00
|
|
|
size_ -= size_in_bytes;
|
2011-09-19 18:36:47 +00:00
|
|
|
ASSERT(size_ >= 0);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Waste free bytes (available -> waste).
|
|
|
|
void WasteBytes(int size_in_bytes) {
|
2011-09-19 18:36:47 +00:00
|
|
|
size_ -= size_in_bytes;
|
2008-07-03 15:10:15 +00:00
|
|
|
waste_ += size_in_bytes;
|
2011-09-19 18:36:47 +00:00
|
|
|
ASSERT(size_ >= 0);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2010-09-30 07:22:53 +00:00
|
|
|
intptr_t capacity_;
|
2013-11-05 11:59:42 +00:00
|
|
|
intptr_t max_capacity_;
|
2010-09-30 07:22:53 +00:00
|
|
|
intptr_t size_;
|
|
|
|
intptr_t waste_;
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Free lists for old object spaces
|
|
|
|
//
|
|
|
|
// Free-list nodes are free blocks in the heap. They look like heap objects
|
|
|
|
// (free-list node pointers have the heap object tag, and they have a map like
|
|
|
|
// a heap object). They have a size and a next pointer. The next pointer is
|
|
|
|
// the raw address of the next free list node (or NULL).
|
|
|
|
class FreeListNode: public HeapObject {
|
|
|
|
public:
|
|
|
|
// Obtain a free-list node from a raw address. This is not a cast because
|
|
|
|
// it does not check nor require that the first word at the address is a map
|
|
|
|
// pointer.
|
|
|
|
static FreeListNode* FromAddress(Address address) {
|
|
|
|
return reinterpret_cast<FreeListNode*>(HeapObject::FromAddress(address));
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool IsFreeListNode(HeapObject* object);
|
|
|
|
|
|
|
|
// Set the size in bytes, which can be read with HeapObject::Size(). This
|
|
|
|
// function also writes a map to the first word of the block so that it
|
|
|
|
// looks like a heap object to the garbage collector and heap iteration
|
|
|
|
// functions.
|
|
|
|
void set_size(Heap* heap, int size_in_bytes);
|
|
|
|
|
|
|
|
// Accessors for the next field.
|
|
|
|
inline FreeListNode* next();
|
|
|
|
inline FreeListNode** next_address();
|
|
|
|
inline void set_next(FreeListNode* next);
|
|
|
|
|
|
|
|
inline void Zap();
|
|
|
|
|
2012-09-14 11:16:56 +00:00
|
|
|
static inline FreeListNode* cast(MaybeObject* maybe) {
|
|
|
|
ASSERT(!maybe->IsFailure());
|
|
|
|
return reinterpret_cast<FreeListNode*>(maybe);
|
|
|
|
}
|
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
private:
|
|
|
|
static const int kNextOffset = POINTER_SIZE_ALIGN(FreeSpace::kHeaderSize);
|
|
|
|
|
|
|
|
DISALLOW_IMPLICIT_CONSTRUCTORS(FreeListNode);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-12-11 17:45:01 +00:00
|
|
|
// The free list category holds a pointer to the top element and a pointer to
|
|
|
|
// the end element of the linked list of free memory blocks.
|
|
|
|
class FreeListCategory {
|
|
|
|
public:
|
2013-01-30 12:19:32 +00:00
|
|
|
FreeListCategory() :
|
2014-02-13 15:01:10 +00:00
|
|
|
top_(0),
|
2013-01-30 12:19:32 +00:00
|
|
|
end_(NULL),
|
|
|
|
available_(0) {}
|
|
|
|
|
|
|
|
intptr_t Concatenate(FreeListCategory* category);
|
2012-12-11 17:45:01 +00:00
|
|
|
|
|
|
|
void Reset();
|
|
|
|
|
|
|
|
void Free(FreeListNode* node, int size_in_bytes);
|
|
|
|
|
|
|
|
FreeListNode* PickNodeFromList(int *node_size);
|
2013-06-14 11:22:25 +00:00
|
|
|
FreeListNode* PickNodeFromList(int size_in_bytes, int *node_size);
|
2012-12-11 17:45:01 +00:00
|
|
|
|
|
|
|
intptr_t EvictFreeListItemsInList(Page* p);
|
2014-01-21 19:30:27 +00:00
|
|
|
bool ContainsPageFreeListItemsInList(Page* p);
|
2012-12-11 17:45:01 +00:00
|
|
|
|
|
|
|
void RepairFreeList(Heap* heap);
|
|
|
|
|
2014-02-13 15:01:10 +00:00
|
|
|
FreeListNode* top() const {
|
|
|
|
return reinterpret_cast<FreeListNode*>(NoBarrier_Load(&top_));
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_top(FreeListNode* top) {
|
|
|
|
NoBarrier_Store(&top_, reinterpret_cast<AtomicWord>(top));
|
|
|
|
}
|
2012-12-11 17:45:01 +00:00
|
|
|
|
|
|
|
FreeListNode** GetEndAddress() { return &end_; }
|
|
|
|
FreeListNode* end() const { return end_; }
|
|
|
|
void set_end(FreeListNode* end) { end_ = end; }
|
|
|
|
|
|
|
|
int* GetAvailableAddress() { return &available_; }
|
|
|
|
int available() const { return available_; }
|
|
|
|
void set_available(int available) { available_ = available; }
|
|
|
|
|
2013-08-29 09:58:30 +00:00
|
|
|
Mutex* mutex() { return &mutex_; }
|
2013-01-30 12:19:32 +00:00
|
|
|
|
2014-01-21 19:30:27 +00:00
|
|
|
bool IsEmpty() {
|
2014-02-13 15:01:10 +00:00
|
|
|
return top() == 0;
|
2014-01-21 19:30:27 +00:00
|
|
|
}
|
|
|
|
|
2012-12-11 17:45:01 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
intptr_t SumFreeList();
|
|
|
|
int FreeListLength();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
private:
|
2014-02-13 15:01:10 +00:00
|
|
|
// top_ points to the top FreeListNode* in the free list category.
|
|
|
|
AtomicWord top_;
|
2012-12-11 17:45:01 +00:00
|
|
|
FreeListNode* end_;
|
2013-08-29 09:58:30 +00:00
|
|
|
Mutex mutex_;
|
2012-12-11 17:45:01 +00:00
|
|
|
|
|
|
|
// Total available bytes in all blocks of this free list category.
|
|
|
|
int available_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
// The free list for the old space. The free list is organized in such a way
|
|
|
|
// as to encourage objects allocated around the same time to be near each
|
|
|
|
// other. The normal way to allocate is intended to be by bumping a 'top'
|
|
|
|
// pointer until it hits a 'limit' pointer. When the limit is hit we need to
|
|
|
|
// find a new space to allocate from. This is done with the free list, which
|
|
|
|
// is divided up into rough categories to cut down on waste. Having finer
|
|
|
|
// categories would scatter allocation more.
|
|
|
|
|
|
|
|
// The old space free list is organized in categories.
|
|
|
|
// 1-31 words: Such small free areas are discarded for efficiency reasons.
|
|
|
|
// They can be reclaimed by the compactor. However the distance between top
|
|
|
|
// and limit may be this small.
|
|
|
|
// 32-255 words: There is a list of spaces this large. It is used for top and
|
|
|
|
// limit when the object we need to allocate is 1-31 words in size. These
|
|
|
|
// spaces are called small.
|
|
|
|
// 256-2047 words: There is a list of spaces this large. It is used for top and
|
|
|
|
// limit when the object we need to allocate is 32-255 words in size. These
|
|
|
|
// spaces are called medium.
|
|
|
|
// 1048-16383 words: There is a list of spaces this large. It is used for top
|
|
|
|
// and limit when the object we need to allocate is 256-2047 words in size.
|
|
|
|
// These spaces are call large.
|
|
|
|
// At least 16384 words. This list is for objects of 2048 words or larger.
|
|
|
|
// Empty pages are added to this list. These spaces are called huge.
|
2014-01-21 11:41:18 +00:00
|
|
|
class FreeList {
|
2011-09-19 18:36:47 +00:00
|
|
|
public:
|
|
|
|
explicit FreeList(PagedSpace* owner);
|
|
|
|
|
2013-01-30 12:19:32 +00:00
|
|
|
intptr_t Concatenate(FreeList* free_list);
|
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
// Clear the free list.
|
|
|
|
void Reset();
|
|
|
|
|
|
|
|
// Return the number of bytes available on the free list.
|
2012-12-11 17:45:01 +00:00
|
|
|
intptr_t available() {
|
|
|
|
return small_list_.available() + medium_list_.available() +
|
|
|
|
large_list_.available() + huge_list_.available();
|
|
|
|
}
|
2011-09-19 18:36:47 +00:00
|
|
|
|
|
|
|
// Place a node on the free list. The block of size 'size_in_bytes'
|
|
|
|
// starting at 'start' is placed on the free list. The return value is the
|
|
|
|
// number of bytes that have been lost due to internal fragmentation by
|
|
|
|
// freeing the block. Bookkeeping information will be written to the block,
|
2012-01-16 12:38:59 +00:00
|
|
|
// i.e., its contents will be destroyed. The start address should be word
|
2011-09-19 18:36:47 +00:00
|
|
|
// aligned, and the size should be a non-zero multiple of the word size.
|
|
|
|
int Free(Address start, int size_in_bytes);
|
|
|
|
|
|
|
|
// Allocate a block of size 'size_in_bytes' from the free list. The block
|
|
|
|
// is unitialized. A failure is returned if no block is available. The
|
|
|
|
// number of bytes lost to fragmentation is returned in the output parameter
|
|
|
|
// 'wasted_bytes'. The size should be a non-zero multiple of the word size.
|
|
|
|
MUST_USE_RESULT HeapObject* Allocate(int size_in_bytes);
|
|
|
|
|
2014-01-21 19:30:27 +00:00
|
|
|
bool IsEmpty() {
|
|
|
|
return small_list_.IsEmpty() && medium_list_.IsEmpty() &&
|
|
|
|
large_list_.IsEmpty() && huge_list_.IsEmpty();
|
|
|
|
}
|
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
void Zap();
|
|
|
|
intptr_t SumFreeLists();
|
|
|
|
bool IsVeryLong();
|
|
|
|
#endif
|
|
|
|
|
2012-09-14 11:16:56 +00:00
|
|
|
// Used after booting the VM.
|
|
|
|
void RepairLists(Heap* heap);
|
|
|
|
|
2011-11-10 13:24:00 +00:00
|
|
|
intptr_t EvictFreeListItems(Page* p);
|
2014-01-21 19:30:27 +00:00
|
|
|
bool ContainsPageFreeListItems(Page* p);
|
2011-09-19 18:36:47 +00:00
|
|
|
|
2013-01-30 12:19:32 +00:00
|
|
|
FreeListCategory* small_list() { return &small_list_; }
|
|
|
|
FreeListCategory* medium_list() { return &medium_list_; }
|
|
|
|
FreeListCategory* large_list() { return &large_list_; }
|
|
|
|
FreeListCategory* huge_list() { return &huge_list_; }
|
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
private:
|
|
|
|
// The size range of blocks, in bytes.
|
|
|
|
static const int kMinBlockSize = 3 * kPointerSize;
|
2014-01-23 13:02:27 +00:00
|
|
|
static const int kMaxBlockSize = Page::kMaxRegularHeapObjectSize;
|
2011-09-19 18:36:47 +00:00
|
|
|
|
2012-01-31 13:33:44 +00:00
|
|
|
FreeListNode* FindNodeFor(int size_in_bytes, int* node_size);
|
2011-09-19 18:36:47 +00:00
|
|
|
|
|
|
|
PagedSpace* owner_;
|
|
|
|
Heap* heap_;
|
|
|
|
|
|
|
|
static const int kSmallListMin = 0x20 * kPointerSize;
|
|
|
|
static const int kSmallListMax = 0xff * kPointerSize;
|
|
|
|
static const int kMediumListMax = 0x7ff * kPointerSize;
|
|
|
|
static const int kLargeListMax = 0x3fff * kPointerSize;
|
|
|
|
static const int kSmallAllocationMax = kSmallListMin - kPointerSize;
|
|
|
|
static const int kMediumAllocationMax = kSmallListMax;
|
|
|
|
static const int kLargeAllocationMax = kMediumListMax;
|
2012-12-11 17:45:01 +00:00
|
|
|
FreeListCategory small_list_;
|
|
|
|
FreeListCategory medium_list_;
|
|
|
|
FreeListCategory large_list_;
|
|
|
|
FreeListCategory huge_list_;
|
2011-09-19 18:36:47 +00:00
|
|
|
|
|
|
|
DISALLOW_IMPLICIT_CONSTRUCTORS(FreeList);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-07-30 08:49:36 +00:00
|
|
|
class PagedSpace : public Space {
|
2008-07-03 15:10:15 +00:00
|
|
|
public:
|
|
|
|
// Creates a space with a maximum capacity, and an id.
|
2011-03-18 20:35:07 +00:00
|
|
|
PagedSpace(Heap* heap,
|
|
|
|
intptr_t max_capacity,
|
2010-09-30 07:22:53 +00:00
|
|
|
AllocationSpace id,
|
2013-09-11 18:30:01 +00:00
|
|
|
Executability executable);
|
2008-07-30 08:49:36 +00:00
|
|
|
|
|
|
|
virtual ~PagedSpace() {}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// Set up the space using the given address range of virtual memory (from
|
|
|
|
// the memory allocator's initial chunk) if possible. If the block of
|
|
|
|
// addresses is not big enough to contain a single page-aligned page, a
|
|
|
|
// fresh chunk will be allocated.
|
2012-01-13 13:09:52 +00:00
|
|
|
bool SetUp();
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// Returns true if the space has been successfully set up and not
|
|
|
|
// subsequently torn down.
|
2012-01-13 13:09:52 +00:00
|
|
|
bool HasBeenSetUp();
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// Cleans up the space, frees all pages in this space except those belonging
|
|
|
|
// to the initial chunk, uncommits addresses in the initial chunk.
|
|
|
|
void TearDown();
|
|
|
|
|
|
|
|
// Checks whether an object/address is in this space.
|
|
|
|
inline bool Contains(Address a);
|
|
|
|
bool Contains(HeapObject* o) { return Contains(o->address()); }
|
|
|
|
|
2008-07-30 08:49:36 +00:00
|
|
|
// Given an address occupied by a live object, return that object if it is
|
2014-04-23 15:08:03 +00:00
|
|
|
// in this space, or a Smi if it is not. The implementation iterates over
|
|
|
|
// objects in the page containing the address, the cost is linear in the
|
|
|
|
// number of objects in the page. It may be slow.
|
|
|
|
Object* FindObject(Address addr);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2012-09-14 11:16:56 +00:00
|
|
|
// During boot the free_space_map is created, and afterwards we may need
|
|
|
|
// to write it into the free list nodes that were already created.
|
2013-11-12 16:36:14 +00:00
|
|
|
void RepairFreeListsAfterBoot();
|
2012-09-14 11:16:56 +00:00
|
|
|
|
2008-09-05 12:34:09 +00:00
|
|
|
// Prepares for a mark-compact GC.
|
2013-11-12 16:36:14 +00:00
|
|
|
void PrepareForMarkCompact();
|
2010-05-27 12:30:45 +00:00
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
// Current capacity without growing (Size() + Available()).
|
2010-09-30 07:22:53 +00:00
|
|
|
intptr_t Capacity() { return accounting_stats_.Capacity(); }
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-10-20 07:51:49 +00:00
|
|
|
// Total amount of memory committed for this space. For paged
|
|
|
|
// spaces this equals the capacity.
|
2010-09-30 07:22:53 +00:00
|
|
|
intptr_t CommittedMemory() { return Capacity(); }
|
2009-10-20 07:51:49 +00:00
|
|
|
|
2013-11-05 11:59:42 +00:00
|
|
|
// The maximum amount of memory ever committed for this space.
|
|
|
|
intptr_t MaximumCommittedMemory() { return accounting_stats_.MaxCapacity(); }
|
|
|
|
|
2012-10-22 16:33:10 +00:00
|
|
|
// Approximate amount of physical memory committed for this space.
|
|
|
|
size_t CommittedPhysicalMemory();
|
|
|
|
|
2013-04-10 10:24:24 +00:00
|
|
|
struct SizeStats {
|
|
|
|
intptr_t Total() {
|
|
|
|
return small_size_ + medium_size_ + large_size_ + huge_size_;
|
|
|
|
}
|
|
|
|
|
|
|
|
intptr_t small_size_;
|
|
|
|
intptr_t medium_size_;
|
|
|
|
intptr_t large_size_;
|
|
|
|
intptr_t huge_size_;
|
|
|
|
};
|
|
|
|
|
|
|
|
void ObtainFreeListStatistics(Page* p, SizeStats* sizes);
|
|
|
|
void ResetFreeListStatistics();
|
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
// Sets the capacity, the available space and the wasted space to zero.
|
|
|
|
// The stats are rebuilt during sweeping by adding each page to the
|
|
|
|
// capacity and the size when it is encountered. As free spaces are
|
|
|
|
// discovered during the sweeping they are subtracted from the size and added
|
|
|
|
// to the available and wasted totals.
|
|
|
|
void ClearStats() {
|
|
|
|
accounting_stats_.ClearSizeWaste();
|
2013-04-10 10:24:24 +00:00
|
|
|
ResetFreeListStatistics();
|
2011-09-19 18:36:47 +00:00
|
|
|
}
|
|
|
|
|
2013-02-28 15:07:28 +00:00
|
|
|
// Increases the number of available bytes of that space.
|
|
|
|
void AddToAccountingStats(intptr_t bytes) {
|
|
|
|
accounting_stats_.DeallocateBytes(bytes);
|
|
|
|
}
|
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
// Available bytes without growing. These are the bytes on the free list.
|
|
|
|
// The bytes in the linear allocation area are not included in this total
|
|
|
|
// because updating the stats would slow down allocation. New pages are
|
|
|
|
// immediately added to the free list so they show up here.
|
|
|
|
intptr_t Available() { return free_list_.available(); }
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
// Allocated bytes in this space. Garbage bytes that were not found due to
|
2014-04-25 09:50:42 +00:00
|
|
|
// concurrent sweeping are counted as being allocated! The bytes in the
|
|
|
|
// current linear allocation area (between top and limit) are also counted
|
|
|
|
// here.
|
2010-09-30 07:22:53 +00:00
|
|
|
virtual intptr_t Size() { return accounting_stats_.Size(); }
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2012-01-11 10:33:34 +00:00
|
|
|
// As size, but the bytes in lazily swept pages are estimated and the bytes
|
|
|
|
// in the current linear allocation area are not included.
|
2013-03-04 15:47:59 +00:00
|
|
|
virtual intptr_t SizeOfObjects();
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
// Wasted bytes in this space. These are just the bytes that were thrown away
|
|
|
|
// due to being too small to use for allocation. They do not include the
|
|
|
|
// free bytes that were not found at all due to lazy sweeping.
|
|
|
|
virtual intptr_t Waste() { return accounting_stats_.Waste(); }
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// Returns the allocation pointer in this space.
|
2013-10-25 09:58:21 +00:00
|
|
|
Address top() { return allocation_info_.top(); }
|
|
|
|
Address limit() { return allocation_info_.limit(); }
|
|
|
|
|
|
|
|
// The allocation top address.
|
|
|
|
Address* allocation_top_address() {
|
|
|
|
return allocation_info_.top_address();
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2013-10-25 09:58:21 +00:00
|
|
|
// The allocation limit address.
|
|
|
|
Address* allocation_limit_address() {
|
|
|
|
return allocation_info_.limit_address();
|
|
|
|
}
|
2013-03-14 08:32:52 +00:00
|
|
|
|
2008-07-30 08:49:36 +00:00
|
|
|
// Allocate the requested number of bytes in the space if possible, return a
|
|
|
|
// failure object if not.
|
2013-11-11 17:46:08 +00:00
|
|
|
MUST_USE_RESULT inline MaybeObject* AllocateRaw(int size_in_bytes);
|
2008-07-30 08:49:36 +00:00
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
// Give a block of memory to the space's free list. It might be added to
|
|
|
|
// the free list or accounted as waste.
|
|
|
|
// If add_to_freelist is false then just accounting stats are updated and
|
|
|
|
// no attempt to add area to free list is made.
|
2012-01-31 13:33:44 +00:00
|
|
|
int Free(Address start, int size_in_bytes) {
|
2011-09-19 18:36:47 +00:00
|
|
|
int wasted = free_list_.Free(start, size_in_bytes);
|
|
|
|
accounting_stats_.DeallocateBytes(size_in_bytes - wasted);
|
|
|
|
return size_in_bytes - wasted;
|
|
|
|
}
|
2010-04-22 14:42:21 +00:00
|
|
|
|
2012-04-12 10:06:32 +00:00
|
|
|
void ResetFreeList() {
|
|
|
|
free_list_.Reset();
|
|
|
|
}
|
|
|
|
|
2010-04-22 14:42:21 +00:00
|
|
|
// Set space allocation info.
|
2013-11-14 15:14:37 +00:00
|
|
|
void SetTopAndLimit(Address top, Address limit) {
|
2011-09-19 18:36:47 +00:00
|
|
|
ASSERT(top == limit ||
|
|
|
|
Page::FromAddress(top) == Page::FromAddress(limit - 1));
|
2013-10-25 09:58:21 +00:00
|
|
|
MemoryChunk::UpdateHighWaterMark(allocation_info_.top());
|
|
|
|
allocation_info_.set_top(top);
|
|
|
|
allocation_info_.set_limit(limit);
|
2010-04-22 14:42:21 +00:00
|
|
|
}
|
|
|
|
|
2013-11-14 15:14:37 +00:00
|
|
|
// Empty space allocation info, returning unused area to free list.
|
|
|
|
void EmptyAllocationInfo() {
|
|
|
|
// Mark the old linear allocation area with a free space map so it can be
|
|
|
|
// skipped when scanning the heap.
|
|
|
|
int old_linear_size = static_cast<int>(limit() - top());
|
|
|
|
Free(top(), old_linear_size);
|
|
|
|
SetTopAndLimit(NULL, NULL);
|
|
|
|
}
|
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
void Allocate(int bytes) {
|
|
|
|
accounting_stats_.AllocateBytes(bytes);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
2013-11-05 11:59:42 +00:00
|
|
|
void IncreaseCapacity(int size);
|
2008-09-05 12:34:09 +00:00
|
|
|
|
2011-09-29 12:27:31 +00:00
|
|
|
// Releases an unused page and shrinks the space.
|
2013-03-08 14:41:21 +00:00
|
|
|
void ReleasePage(Page* page, bool unlink);
|
2011-09-29 12:27:31 +00:00
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
// The dummy page that anchors the linked list of pages.
|
|
|
|
Page* anchor() { return &anchor_; }
|
|
|
|
|
2012-10-12 11:41:14 +00:00
|
|
|
#ifdef VERIFY_HEAP
|
2009-07-09 14:34:08 +00:00
|
|
|
// Verify integrity of this space.
|
|
|
|
virtual void Verify(ObjectVisitor* visitor);
|
|
|
|
|
|
|
|
// Overridden by subclasses to verify space-specific object
|
|
|
|
// properties (e.g., only maps or free-list nodes are in map space).
|
|
|
|
virtual void VerifyObject(HeapObject* obj) {}
|
2012-10-12 11:41:14 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
// Print meta info and objects in this space.
|
|
|
|
virtual void Print();
|
|
|
|
|
|
|
|
// Reports statistics for the space
|
|
|
|
void ReportStatistics();
|
2009-07-09 14:34:08 +00:00
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// Report code object related statistics
|
|
|
|
void CollectCodeStatistics();
|
2013-09-03 11:54:08 +00:00
|
|
|
static void ReportCodeStatistics(Isolate* isolate);
|
|
|
|
static void ResetCodeStatistics(Isolate* isolate);
|
2008-07-03 15:10:15 +00:00
|
|
|
#endif
|
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
bool was_swept_conservatively() { return was_swept_conservatively_; }
|
|
|
|
void set_was_swept_conservatively(bool b) { was_swept_conservatively_ = b; }
|
|
|
|
|
|
|
|
// Evacuation candidates are swept by evacuator. Needs to return a valid
|
|
|
|
// result before _and_ after evacuation has finished.
|
2014-04-25 09:50:42 +00:00
|
|
|
static bool ShouldBeSweptBySweeperThreads(Page* p) {
|
2011-09-19 18:36:47 +00:00
|
|
|
return !p->IsEvacuationCandidate() &&
|
|
|
|
!p->IsFlagSet(Page::RESCAN_ON_EVACUATION) &&
|
|
|
|
!p->WasSweptPrecisely();
|
|
|
|
}
|
|
|
|
|
2013-03-01 12:46:20 +00:00
|
|
|
void IncrementUnsweptFreeBytes(intptr_t by) {
|
2012-01-18 09:21:07 +00:00
|
|
|
unswept_free_bytes_ += by;
|
|
|
|
}
|
|
|
|
|
2012-01-17 14:09:12 +00:00
|
|
|
void IncreaseUnsweptFreeBytes(Page* p) {
|
2014-04-25 09:50:42 +00:00
|
|
|
ASSERT(ShouldBeSweptBySweeperThreads(p));
|
2012-02-23 12:11:24 +00:00
|
|
|
unswept_free_bytes_ += (p->area_size() - p->LiveBytes());
|
2012-01-11 10:33:34 +00:00
|
|
|
}
|
|
|
|
|
2013-03-01 12:46:20 +00:00
|
|
|
void DecrementUnsweptFreeBytes(intptr_t by) {
|
2013-02-28 15:07:28 +00:00
|
|
|
unswept_free_bytes_ -= by;
|
|
|
|
}
|
|
|
|
|
2012-01-17 14:09:12 +00:00
|
|
|
void DecreaseUnsweptFreeBytes(Page* p) {
|
2014-04-25 09:50:42 +00:00
|
|
|
ASSERT(ShouldBeSweptBySweeperThreads(p));
|
2012-02-23 12:11:24 +00:00
|
|
|
unswept_free_bytes_ -= (p->area_size() - p->LiveBytes());
|
2012-01-17 14:09:12 +00:00
|
|
|
}
|
|
|
|
|
2013-02-28 15:07:28 +00:00
|
|
|
void ResetUnsweptFreeBytes() {
|
|
|
|
unswept_free_bytes_ = 0;
|
|
|
|
}
|
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
Page* FirstPage() { return anchor_.next_page(); }
|
|
|
|
Page* LastPage() { return anchor_.prev_page(); }
|
|
|
|
|
|
|
|
void EvictEvacuationCandidatesFromFreeLists();
|
2010-04-22 14:42:21 +00:00
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
bool CanExpand();
|
2010-08-30 12:34:32 +00:00
|
|
|
|
2011-11-29 11:56:14 +00:00
|
|
|
// Returns the number of total pages in this space.
|
|
|
|
int CountTotalPages();
|
|
|
|
|
2012-02-23 12:11:24 +00:00
|
|
|
// Return size of allocatable area on a page in this space.
|
|
|
|
inline int AreaSize() {
|
|
|
|
return area_size_;
|
|
|
|
}
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
protected:
|
2013-01-30 12:19:32 +00:00
|
|
|
FreeList* free_list() { return &free_list_; }
|
|
|
|
|
2012-02-23 12:11:24 +00:00
|
|
|
int area_size_;
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// Maximum capacity of this space.
|
2010-09-30 07:22:53 +00:00
|
|
|
intptr_t max_capacity_;
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2012-04-02 08:32:31 +00:00
|
|
|
intptr_t SizeOfFirstPage();
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// Accounting information for this space.
|
|
|
|
AllocationStats accounting_stats_;
|
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
// The dummy page that anchors the double linked list of pages.
|
|
|
|
Page anchor_;
|
2009-05-14 08:55:34 +00:00
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
// The space's free list.
|
|
|
|
FreeList free_list_;
|
2010-04-22 14:42:21 +00:00
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// Normal allocation information.
|
|
|
|
AllocationInfo allocation_info_;
|
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
bool was_swept_conservatively_;
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2012-01-11 10:33:34 +00:00
|
|
|
// The number of free bytes which could be reclaimed by advancing the
|
2014-04-25 09:50:42 +00:00
|
|
|
// concurrent sweeper threads. This is only an estimation because concurrent
|
|
|
|
// sweeping is done conservatively.
|
2012-01-11 10:33:34 +00:00
|
|
|
intptr_t unswept_free_bytes_;
|
|
|
|
|
2012-01-31 13:33:44 +00:00
|
|
|
// Expands the space by allocating a fixed number of pages. Returns false if
|
|
|
|
// it cannot allocate requested number of pages from OS, or if the hard heap
|
|
|
|
// size limit has been hit.
|
|
|
|
bool Expand();
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
// Generic fast case allocation function that tries linear allocation at the
|
|
|
|
// address denoted by top in allocation_info_.
|
2011-09-22 17:10:40 +00:00
|
|
|
inline HeapObject* AllocateLinearly(int size_in_bytes);
|
2008-07-30 08:49:36 +00:00
|
|
|
|
|
|
|
// Slow path of AllocateRaw. This function is space-dependent.
|
2011-09-19 18:36:47 +00:00
|
|
|
MUST_USE_RESULT virtual HeapObject* SlowAllocateRaw(int size_in_bytes);
|
2008-07-30 08:49:36 +00:00
|
|
|
|
2009-03-24 12:47:53 +00:00
|
|
|
friend class PageIterator;
|
2014-01-21 11:41:18 +00:00
|
|
|
friend class MarkCompactCollector;
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-07-29 08:10:19 +00:00
|
|
|
class NumberAndSizeInfo BASE_EMBEDDED {
|
2008-07-03 15:10:15 +00:00
|
|
|
public:
|
2009-07-29 08:10:19 +00:00
|
|
|
NumberAndSizeInfo() : number_(0), bytes_(0) {}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-07-29 08:10:19 +00:00
|
|
|
int number() const { return number_; }
|
2008-07-03 15:10:15 +00:00
|
|
|
void increment_number(int num) { number_ += num; }
|
|
|
|
|
2009-07-29 08:10:19 +00:00
|
|
|
int bytes() const { return bytes_; }
|
2008-07-03 15:10:15 +00:00
|
|
|
void increment_bytes(int size) { bytes_ += size; }
|
|
|
|
|
|
|
|
void clear() {
|
|
|
|
number_ = 0;
|
|
|
|
bytes_ = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
int number_;
|
|
|
|
int bytes_;
|
|
|
|
};
|
2009-07-29 08:10:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
// HistogramInfo class for recording a single "bar" of a histogram. This
|
2011-07-13 09:09:04 +00:00
|
|
|
// class is used for collecting statistics to print to the log file.
|
2009-07-29 08:10:19 +00:00
|
|
|
class HistogramInfo: public NumberAndSizeInfo {
|
|
|
|
public:
|
|
|
|
HistogramInfo() : NumberAndSizeInfo() {}
|
|
|
|
|
|
|
|
const char* name() { return name_; }
|
|
|
|
void set_name(const char* name) { name_ = name; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
const char* name_;
|
|
|
|
};
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
enum SemiSpaceId {
|
|
|
|
kFromSpace = 0,
|
|
|
|
kToSpace = 1
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class SemiSpace;
|
|
|
|
|
|
|
|
|
|
|
|
class NewSpacePage : public MemoryChunk {
|
|
|
|
public:
|
|
|
|
// GC related flags copied from from-space to to-space when
|
|
|
|
// flipping semispaces.
|
|
|
|
static const intptr_t kCopyOnFlipFlagsMask =
|
|
|
|
(1 << MemoryChunk::POINTERS_TO_HERE_ARE_INTERESTING) |
|
|
|
|
(1 << MemoryChunk::POINTERS_FROM_HERE_ARE_INTERESTING) |
|
|
|
|
(1 << MemoryChunk::SCAN_ON_SCAVENGE);
|
|
|
|
|
2014-01-23 13:02:27 +00:00
|
|
|
static const int kAreaSize = Page::kMaxRegularHeapObjectSize;
|
2012-02-23 12:11:24 +00:00
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
inline NewSpacePage* next_page() const {
|
|
|
|
return static_cast<NewSpacePage*>(next_chunk());
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void set_next_page(NewSpacePage* page) {
|
|
|
|
set_next_chunk(page);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline NewSpacePage* prev_page() const {
|
|
|
|
return static_cast<NewSpacePage*>(prev_chunk());
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void set_prev_page(NewSpacePage* page) {
|
|
|
|
set_prev_chunk(page);
|
|
|
|
}
|
|
|
|
|
|
|
|
SemiSpace* semi_space() {
|
|
|
|
return reinterpret_cast<SemiSpace*>(owner());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool is_anchor() { return !this->InNewSpace(); }
|
|
|
|
|
|
|
|
static bool IsAtStart(Address addr) {
|
|
|
|
return (reinterpret_cast<intptr_t>(addr) & Page::kPageAlignmentMask)
|
|
|
|
== kObjectStartOffset;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool IsAtEnd(Address addr) {
|
|
|
|
return (reinterpret_cast<intptr_t>(addr) & Page::kPageAlignmentMask) == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
Address address() {
|
|
|
|
return reinterpret_cast<Address>(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Finds the NewSpacePage containg the given address.
|
|
|
|
static inline NewSpacePage* FromAddress(Address address_in_page) {
|
|
|
|
Address page_start =
|
|
|
|
reinterpret_cast<Address>(reinterpret_cast<uintptr_t>(address_in_page) &
|
|
|
|
~Page::kPageAlignmentMask);
|
|
|
|
NewSpacePage* page = reinterpret_cast<NewSpacePage*>(page_start);
|
|
|
|
return page;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Find the page for a limit address. A limit address is either an address
|
|
|
|
// inside a page, or the address right after the last byte of a page.
|
|
|
|
static inline NewSpacePage* FromLimit(Address address_limit) {
|
|
|
|
return NewSpacePage::FromAddress(address_limit - 1);
|
|
|
|
}
|
|
|
|
|
2014-02-03 12:20:15 +00:00
|
|
|
// Checks if address1 and address2 are on the same new space page.
|
|
|
|
static inline bool OnSamePage(Address address1, Address address2) {
|
|
|
|
return NewSpacePage::FromAddress(address1) ==
|
|
|
|
NewSpacePage::FromAddress(address2);
|
|
|
|
}
|
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
private:
|
|
|
|
// Create a NewSpacePage object that is only used as anchor
|
|
|
|
// for the doubly-linked list of real pages.
|
|
|
|
explicit NewSpacePage(SemiSpace* owner) {
|
|
|
|
InitializeAsAnchor(owner);
|
|
|
|
}
|
|
|
|
|
|
|
|
static NewSpacePage* Initialize(Heap* heap,
|
|
|
|
Address start,
|
|
|
|
SemiSpace* semi_space);
|
|
|
|
|
|
|
|
// Intialize a fake NewSpacePage used as sentinel at the ends
|
|
|
|
// of a doubly-linked list of real NewSpacePages.
|
|
|
|
// Only uses the prev/next links, and sets flags to not be in new-space.
|
|
|
|
void InitializeAsAnchor(SemiSpace* owner);
|
|
|
|
|
|
|
|
friend class SemiSpace;
|
|
|
|
friend class SemiSpaceIterator;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// SemiSpace in young generation
|
|
|
|
//
|
2011-09-19 18:36:47 +00:00
|
|
|
// A semispace is a contiguous chunk of memory holding page-like memory
|
|
|
|
// chunks. The mark-compact collector uses the memory of the first page in
|
|
|
|
// the from space as a marking stack when tracing live objects.
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-07-30 08:49:36 +00:00
|
|
|
class SemiSpace : public Space {
|
2008-07-03 15:10:15 +00:00
|
|
|
public:
|
2008-10-17 09:13:27 +00:00
|
|
|
// Constructor.
|
2011-09-19 18:36:47 +00:00
|
|
|
SemiSpace(Heap* heap, SemiSpaceId semispace)
|
2013-09-11 18:30:01 +00:00
|
|
|
: Space(heap, NEW_SPACE, NOT_EXECUTABLE),
|
2011-09-19 18:36:47 +00:00
|
|
|
start_(NULL),
|
|
|
|
age_mark_(NULL),
|
|
|
|
id_(semispace),
|
|
|
|
anchor_(this),
|
|
|
|
current_page_(NULL) { }
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2012-01-31 13:33:44 +00:00
|
|
|
// Sets up the semispace using the given chunk.
|
2012-01-24 16:00:19 +00:00
|
|
|
void SetUp(Address start, int initial_capacity, int maximum_capacity);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// Tear down the space. Heap memory was not allocated by the space, so it
|
|
|
|
// is not deallocated here.
|
|
|
|
void TearDown();
|
|
|
|
|
|
|
|
// True if the space has been set up but not torn down.
|
2012-01-13 13:09:52 +00:00
|
|
|
bool HasBeenSetUp() { return start_ != NULL; }
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-08-21 13:14:53 +00:00
|
|
|
// Grow the semispace to the new capacity. The new capacity
|
2011-09-20 15:35:36 +00:00
|
|
|
// requested must be larger than the current capacity and less than
|
|
|
|
// the maximum capacity.
|
2009-08-21 13:14:53 +00:00
|
|
|
bool GrowTo(int new_capacity);
|
|
|
|
|
|
|
|
// Shrinks the semispace to the new capacity. The new capacity
|
|
|
|
// requested must be more than the amount of used memory in the
|
|
|
|
// semispace and less than the current capacity.
|
|
|
|
bool ShrinkTo(int new_capacity);
|
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
// Returns the start address of the first page of the space.
|
|
|
|
Address space_start() {
|
|
|
|
ASSERT(anchor_.next_page() != &anchor_);
|
2012-02-23 12:11:24 +00:00
|
|
|
return anchor_.next_page()->area_start();
|
2011-09-19 18:36:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Returns the start address of the current page of the space.
|
|
|
|
Address page_low() {
|
2012-02-23 12:11:24 +00:00
|
|
|
return current_page_->area_start();
|
2011-09-19 18:36:47 +00:00
|
|
|
}
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// Returns one past the end address of the space.
|
2011-09-19 18:36:47 +00:00
|
|
|
Address space_end() {
|
2012-02-23 12:11:24 +00:00
|
|
|
return anchor_.prev_page()->area_end();
|
2011-09-19 18:36:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Returns one past the end address of the current page of the space.
|
|
|
|
Address page_high() {
|
2012-02-23 12:11:24 +00:00
|
|
|
return current_page_->area_end();
|
2011-09-19 18:36:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool AdvancePage() {
|
|
|
|
NewSpacePage* next_page = current_page_->next_page();
|
|
|
|
if (next_page == anchor()) return false;
|
|
|
|
current_page_ = next_page;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Resets the space to using the first page.
|
|
|
|
void Reset();
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// Age mark accessors.
|
|
|
|
Address age_mark() { return age_mark_; }
|
2011-09-19 18:36:47 +00:00
|
|
|
void set_age_mark(Address mark);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// True if the address is in the address range of this semispace (not
|
|
|
|
// necessarily below the allocation pointer).
|
|
|
|
bool Contains(Address a) {
|
2009-05-04 13:11:38 +00:00
|
|
|
return (reinterpret_cast<uintptr_t>(a) & address_mask_)
|
|
|
|
== reinterpret_cast<uintptr_t>(start_);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// True if the object is a heap object in the address range of this
|
|
|
|
// semispace (not necessarily below the allocation pointer).
|
|
|
|
bool Contains(Object* o) {
|
2009-05-04 13:11:38 +00:00
|
|
|
return (reinterpret_cast<uintptr_t>(o) & object_mask_) == object_expected_;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
2010-01-12 15:16:23 +00:00
|
|
|
// If we don't have these here then SemiSpace will be abstract. However
|
|
|
|
// they should never be called.
|
2010-09-30 07:22:53 +00:00
|
|
|
virtual intptr_t Size() {
|
2008-09-05 12:34:09 +00:00
|
|
|
UNREACHABLE();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-08-13 12:03:42 +00:00
|
|
|
bool is_committed() { return committed_; }
|
|
|
|
bool Commit();
|
|
|
|
bool Uncommit();
|
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
NewSpacePage* first_page() { return anchor_.next_page(); }
|
|
|
|
NewSpacePage* current_page() { return current_page_; }
|
|
|
|
|
2012-10-12 11:41:14 +00:00
|
|
|
#ifdef VERIFY_HEAP
|
|
|
|
virtual void Verify();
|
|
|
|
#endif
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
#ifdef DEBUG
|
2008-09-05 12:34:09 +00:00
|
|
|
virtual void Print();
|
2011-09-19 18:36:47 +00:00
|
|
|
// Validate a range of of addresses in a SemiSpace.
|
|
|
|
// The "from" address must be on a page prior to the "to" address,
|
|
|
|
// in the linked page order, or it must be earlier on the same page.
|
|
|
|
static void AssertValidRange(Address from, Address to);
|
|
|
|
#else
|
|
|
|
// Do nothing.
|
|
|
|
inline static void AssertValidRange(Address from, Address to) {}
|
2008-07-03 15:10:15 +00:00
|
|
|
#endif
|
|
|
|
|
2009-08-19 10:36:19 +00:00
|
|
|
// Returns the current capacity of the semi space.
|
2010-09-28 12:49:25 +00:00
|
|
|
int Capacity() { return capacity_; }
|
2009-08-19 10:36:19 +00:00
|
|
|
|
|
|
|
// Returns the maximum capacity of the semi space.
|
|
|
|
int MaximumCapacity() { return maximum_capacity_; }
|
|
|
|
|
2009-08-21 13:14:53 +00:00
|
|
|
// Returns the initial capacity of the semi space.
|
|
|
|
int InitialCapacity() { return initial_capacity_; }
|
2009-08-19 10:36:19 +00:00
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
SemiSpaceId id() { return id_; }
|
|
|
|
|
|
|
|
static void Swap(SemiSpace* from, SemiSpace* to);
|
|
|
|
|
2013-11-05 11:59:42 +00:00
|
|
|
// Returns the maximum amount of memory ever committed by the semi space.
|
|
|
|
size_t MaximumCommittedMemory() { return maximum_committed_; }
|
|
|
|
|
2012-10-22 16:33:10 +00:00
|
|
|
// Approximate amount of physical memory committed for this space.
|
|
|
|
size_t CommittedPhysicalMemory();
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
private:
|
2011-09-19 18:36:47 +00:00
|
|
|
// Flips the semispace between being from-space and to-space.
|
|
|
|
// Copies the flags into the masked positions on all pages in the space.
|
|
|
|
void FlipPages(intptr_t flags, intptr_t flag_mask);
|
|
|
|
|
2013-11-05 11:59:42 +00:00
|
|
|
// Updates Capacity and MaximumCommitted based on new capacity.
|
|
|
|
void SetCapacity(int new_capacity);
|
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
NewSpacePage* anchor() { return &anchor_; }
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// The current and maximum capacity of the space.
|
|
|
|
int capacity_;
|
|
|
|
int maximum_capacity_;
|
2009-08-21 13:14:53 +00:00
|
|
|
int initial_capacity_;
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2013-11-05 11:59:42 +00:00
|
|
|
intptr_t maximum_committed_;
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// The start address of the space.
|
|
|
|
Address start_;
|
|
|
|
// Used to govern object promotion during mark-compact collection.
|
|
|
|
Address age_mark_;
|
|
|
|
|
|
|
|
// Masks and comparison values to test for containment in this semispace.
|
2009-05-04 13:11:38 +00:00
|
|
|
uintptr_t address_mask_;
|
|
|
|
uintptr_t object_mask_;
|
|
|
|
uintptr_t object_expected_;
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-08-13 12:03:42 +00:00
|
|
|
bool committed_;
|
2011-09-19 18:36:47 +00:00
|
|
|
SemiSpaceId id_;
|
|
|
|
|
|
|
|
NewSpacePage anchor_;
|
|
|
|
NewSpacePage* current_page_;
|
2009-08-13 12:03:42 +00:00
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
friend class SemiSpaceIterator;
|
|
|
|
friend class NewSpacePageIterator;
|
2008-07-03 15:10:15 +00:00
|
|
|
public:
|
|
|
|
TRACK_MEMORY("SemiSpace")
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// A SemiSpaceIterator is an ObjectIterator that iterates over the active
|
|
|
|
// semispace of the heap's new space. It iterates over the objects in the
|
|
|
|
// semispace from a given start address (defaulting to the bottom of the
|
|
|
|
// semispace) to the top of the semispace. New objects allocated after the
|
|
|
|
// iterator is created are not iterated.
|
|
|
|
class SemiSpaceIterator : public ObjectIterator {
|
|
|
|
public:
|
|
|
|
// Create an iterator over the objects in the given space. If no start
|
|
|
|
// address is given, the iterator starts from the bottom of the space. If
|
|
|
|
// no size function is given, the iterator calls Object::Size().
|
2011-09-19 18:36:47 +00:00
|
|
|
|
|
|
|
// Iterate over all of allocated to-space.
|
2008-07-03 15:10:15 +00:00
|
|
|
explicit SemiSpaceIterator(NewSpace* space);
|
2011-09-19 18:36:47 +00:00
|
|
|
// Iterate over all of allocated to-space, with a custome size function.
|
2008-07-03 15:10:15 +00:00
|
|
|
SemiSpaceIterator(NewSpace* space, HeapObjectCallback size_func);
|
2011-09-19 18:36:47 +00:00
|
|
|
// Iterate over part of allocated to-space, from start to the end
|
|
|
|
// of allocation.
|
2008-07-03 15:10:15 +00:00
|
|
|
SemiSpaceIterator(NewSpace* space, Address start);
|
2011-09-19 18:36:47 +00:00
|
|
|
// Iterate from one address to another in the same semi-space.
|
|
|
|
SemiSpaceIterator(Address from, Address to);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
HeapObject* Next() {
|
2010-01-25 22:53:18 +00:00
|
|
|
if (current_ == limit_) return NULL;
|
2011-09-19 18:36:47 +00:00
|
|
|
if (NewSpacePage::IsAtEnd(current_)) {
|
|
|
|
NewSpacePage* page = NewSpacePage::FromLimit(current_);
|
|
|
|
page = page->next_page();
|
|
|
|
ASSERT(!page->is_anchor());
|
2012-02-23 12:11:24 +00:00
|
|
|
current_ = page->area_start();
|
2011-09-19 18:36:47 +00:00
|
|
|
if (current_ == limit_) return NULL;
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
HeapObject* object = HeapObject::FromAddress(current_);
|
|
|
|
int size = (size_func_ == NULL) ? object->Size() : size_func_(object);
|
|
|
|
|
|
|
|
current_ += size;
|
|
|
|
return object;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Implementation of the ObjectIterator functions.
|
2011-09-19 18:36:47 +00:00
|
|
|
virtual HeapObject* next_object() { return Next(); }
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
private:
|
2011-09-19 18:36:47 +00:00
|
|
|
void Initialize(Address start,
|
|
|
|
Address end,
|
2008-07-03 15:10:15 +00:00
|
|
|
HeapObjectCallback size_func);
|
|
|
|
|
|
|
|
// The current iteration point.
|
|
|
|
Address current_;
|
|
|
|
// The end of iteration.
|
|
|
|
Address limit_;
|
|
|
|
// The callback function.
|
|
|
|
HeapObjectCallback size_func_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// A PageIterator iterates the pages in a semi-space.
|
|
|
|
class NewSpacePageIterator BASE_EMBEDDED {
|
|
|
|
public:
|
|
|
|
// Make an iterator that runs over all pages in to-space.
|
|
|
|
explicit inline NewSpacePageIterator(NewSpace* space);
|
|
|
|
|
|
|
|
// Make an iterator that runs over all pages in the given semispace,
|
|
|
|
// even those not used in allocation.
|
|
|
|
explicit inline NewSpacePageIterator(SemiSpace* space);
|
|
|
|
|
|
|
|
// Make iterator that iterates from the page containing start
|
|
|
|
// to the page that contains limit in the same semispace.
|
|
|
|
inline NewSpacePageIterator(Address start, Address limit);
|
|
|
|
|
|
|
|
inline bool has_next();
|
|
|
|
inline NewSpacePage* next();
|
|
|
|
|
|
|
|
private:
|
|
|
|
NewSpacePage* prev_page_; // Previous page returned.
|
|
|
|
// Next page that will be returned. Cached here so that we can use this
|
|
|
|
// iterator for operations that deallocate pages.
|
|
|
|
NewSpacePage* next_page_;
|
|
|
|
// Last page returned.
|
|
|
|
NewSpacePage* last_page_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// The young generation space.
|
|
|
|
//
|
|
|
|
// The new space consists of a contiguous pair of semispaces. It simply
|
|
|
|
// forwards most functions to the appropriate semispace.
|
|
|
|
|
2008-07-30 08:49:36 +00:00
|
|
|
class NewSpace : public Space {
|
2008-07-03 15:10:15 +00:00
|
|
|
public:
|
2008-10-17 09:13:27 +00:00
|
|
|
// Constructor.
|
2011-03-18 20:35:07 +00:00
|
|
|
explicit NewSpace(Heap* heap)
|
2013-09-11 18:30:01 +00:00
|
|
|
: Space(heap, NEW_SPACE, NOT_EXECUTABLE),
|
2011-09-19 18:36:47 +00:00
|
|
|
to_space_(heap, kToSpace),
|
|
|
|
from_space_(heap, kFromSpace),
|
|
|
|
reservation_(),
|
|
|
|
inline_allocation_limit_step_(0) {}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// Sets up the new space using the given chunk.
|
2012-01-13 13:09:52 +00:00
|
|
|
bool SetUp(int reserved_semispace_size_, int max_semispace_size);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// Tears down the space. Heap memory was not allocated by the space, so it
|
|
|
|
// is not deallocated here.
|
|
|
|
void TearDown();
|
|
|
|
|
|
|
|
// True if the space has been set up but not torn down.
|
2012-01-13 13:09:52 +00:00
|
|
|
bool HasBeenSetUp() {
|
|
|
|
return to_space_.HasBeenSetUp() && from_space_.HasBeenSetUp();
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Flip the pair of spaces.
|
|
|
|
void Flip();
|
|
|
|
|
2009-08-19 10:36:19 +00:00
|
|
|
// Grow the capacity of the semispaces. Assumes that they are not at
|
2009-08-21 13:14:53 +00:00
|
|
|
// their maximum capacity.
|
|
|
|
void Grow();
|
|
|
|
|
|
|
|
// Shrink the capacity of the semispaces.
|
|
|
|
void Shrink();
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// True if the address or object lies in the address range of either
|
|
|
|
// semispace (not necessarily below the allocation pointer).
|
|
|
|
bool Contains(Address a) {
|
2009-05-04 13:11:38 +00:00
|
|
|
return (reinterpret_cast<uintptr_t>(a) & address_mask_)
|
|
|
|
== reinterpret_cast<uintptr_t>(start_);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2011-09-19 18:36:47 +00:00
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
bool Contains(Object* o) {
|
2011-09-19 18:36:47 +00:00
|
|
|
Address a = reinterpret_cast<Address>(o);
|
|
|
|
return (reinterpret_cast<uintptr_t>(a) & object_mask_) == object_expected_;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Return the allocated bytes in the active semispace.
|
2011-09-19 18:36:47 +00:00
|
|
|
virtual intptr_t Size() {
|
2012-02-23 12:11:24 +00:00
|
|
|
return pages_used_ * NewSpacePage::kAreaSize +
|
2011-09-19 18:36:47 +00:00
|
|
|
static_cast<int>(top() - to_space_.page_low());
|
|
|
|
}
|
|
|
|
|
2010-09-30 07:22:53 +00:00
|
|
|
// The same, but returning an int. We have to have the one that returns
|
|
|
|
// intptr_t because it is inherited, but if we know we are dealing with the
|
|
|
|
// new space, which can't get as big as the other spaces then this is useful:
|
|
|
|
int SizeAsInt() { return static_cast<int>(Size()); }
|
2009-10-20 07:51:49 +00:00
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
// Return the current capacity of a semispace.
|
|
|
|
intptr_t EffectiveCapacity() {
|
2011-10-13 11:50:00 +00:00
|
|
|
SLOW_ASSERT(to_space_.Capacity() == from_space_.Capacity());
|
2012-02-23 12:11:24 +00:00
|
|
|
return (to_space_.Capacity() / Page::kPageSize) * NewSpacePage::kAreaSize;
|
2011-09-19 18:36:47 +00:00
|
|
|
}
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// Return the current capacity of a semispace.
|
2010-09-30 07:22:53 +00:00
|
|
|
intptr_t Capacity() {
|
2009-08-19 10:36:19 +00:00
|
|
|
ASSERT(to_space_.Capacity() == from_space_.Capacity());
|
|
|
|
return to_space_.Capacity();
|
|
|
|
}
|
2009-10-20 07:51:49 +00:00
|
|
|
|
|
|
|
// Return the total amount of memory committed for new space.
|
2010-09-30 07:22:53 +00:00
|
|
|
intptr_t CommittedMemory() {
|
2009-10-20 07:51:49 +00:00
|
|
|
if (from_space_.is_committed()) return 2 * Capacity();
|
|
|
|
return Capacity();
|
|
|
|
}
|
|
|
|
|
2013-11-05 11:59:42 +00:00
|
|
|
// Return the total amount of memory committed for new space.
|
|
|
|
intptr_t MaximumCommittedMemory() {
|
|
|
|
return to_space_.MaximumCommittedMemory() +
|
|
|
|
from_space_.MaximumCommittedMemory();
|
|
|
|
}
|
|
|
|
|
2012-10-22 16:33:10 +00:00
|
|
|
// Approximate amount of physical memory committed for this space.
|
|
|
|
size_t CommittedPhysicalMemory();
|
|
|
|
|
2011-10-14 09:25:10 +00:00
|
|
|
// Return the available bytes without growing.
|
2011-09-19 18:36:47 +00:00
|
|
|
intptr_t Available() {
|
2011-10-14 09:25:10 +00:00
|
|
|
return Capacity() - Size();
|
2011-09-19 18:36:47 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// Return the maximum capacity of a semispace.
|
2009-08-19 10:36:19 +00:00
|
|
|
int MaximumCapacity() {
|
|
|
|
ASSERT(to_space_.MaximumCapacity() == from_space_.MaximumCapacity());
|
|
|
|
return to_space_.MaximumCapacity();
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-08-21 13:14:53 +00:00
|
|
|
// Returns the initial capacity of a semispace.
|
2010-09-28 12:49:25 +00:00
|
|
|
int InitialCapacity() {
|
2009-08-21 13:14:53 +00:00
|
|
|
ASSERT(to_space_.InitialCapacity() == from_space_.InitialCapacity());
|
|
|
|
return to_space_.InitialCapacity();
|
|
|
|
}
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// Return the address of the allocation pointer in the active semispace.
|
2011-09-19 18:36:47 +00:00
|
|
|
Address top() {
|
2013-10-25 09:58:21 +00:00
|
|
|
ASSERT(to_space_.current_page()->ContainsLimit(allocation_info_.top()));
|
|
|
|
return allocation_info_.top();
|
2011-09-19 18:36:47 +00:00
|
|
|
}
|
2013-10-25 09:58:21 +00:00
|
|
|
|
|
|
|
void set_top(Address top) {
|
|
|
|
ASSERT(to_space_.current_page()->ContainsLimit(top));
|
|
|
|
allocation_info_.set_top(top);
|
|
|
|
}
|
|
|
|
|
2014-02-03 12:20:15 +00:00
|
|
|
// Return the address of the allocation pointer limit in the active semispace.
|
|
|
|
Address limit() {
|
|
|
|
ASSERT(to_space_.current_page()->ContainsLimit(allocation_info_.limit()));
|
|
|
|
return allocation_info_.limit();
|
|
|
|
}
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// Return the address of the first object in the active semispace.
|
2011-09-19 18:36:47 +00:00
|
|
|
Address bottom() { return to_space_.space_start(); }
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// Get the age mark of the inactive semispace.
|
2008-10-17 09:13:27 +00:00
|
|
|
Address age_mark() { return from_space_.age_mark(); }
|
2008-07-03 15:10:15 +00:00
|
|
|
// Set the age mark in the active semispace.
|
2008-10-17 09:13:27 +00:00
|
|
|
void set_age_mark(Address mark) { to_space_.set_age_mark(mark); }
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// The start address of the space and a bit mask. Anding an address in the
|
|
|
|
// new space with the mask will result in the start address.
|
|
|
|
Address start() { return start_; }
|
2009-08-03 11:05:26 +00:00
|
|
|
uintptr_t mask() { return address_mask_; }
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
INLINE(uint32_t AddressToMarkbitIndex(Address addr)) {
|
|
|
|
ASSERT(Contains(addr));
|
|
|
|
ASSERT(IsAligned(OffsetFrom(addr), kPointerSize) ||
|
|
|
|
IsAligned(OffsetFrom(addr) - 1, kPointerSize));
|
|
|
|
return static_cast<uint32_t>(addr - start_) >> kPointerSizeLog2;
|
|
|
|
}
|
|
|
|
|
|
|
|
INLINE(Address MarkbitIndexToAddress(uint32_t index)) {
|
|
|
|
return reinterpret_cast<Address>(index << kPointerSizeLog2);
|
|
|
|
}
|
|
|
|
|
2013-10-25 09:58:21 +00:00
|
|
|
// The allocation top and limit address.
|
|
|
|
Address* allocation_top_address() {
|
|
|
|
return allocation_info_.top_address();
|
|
|
|
}
|
|
|
|
|
|
|
|
// The allocation limit address.
|
|
|
|
Address* allocation_limit_address() {
|
|
|
|
return allocation_info_.limit_address();
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2011-11-09 13:48:43 +00:00
|
|
|
MUST_USE_RESULT INLINE(MaybeObject* AllocateRaw(int size_in_bytes));
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// Reset the allocation pointer to the beginning of the active semispace.
|
|
|
|
void ResetAllocationInfo();
|
|
|
|
|
2013-11-14 15:14:37 +00:00
|
|
|
void UpdateInlineAllocationLimit(int size_in_bytes);
|
2011-09-19 18:36:47 +00:00
|
|
|
void LowerInlineAllocationLimit(intptr_t step) {
|
|
|
|
inline_allocation_limit_step_ = step;
|
2013-11-14 15:14:37 +00:00
|
|
|
UpdateInlineAllocationLimit(0);
|
2013-10-25 09:58:21 +00:00
|
|
|
top_on_previous_step_ = allocation_info_.top();
|
2011-09-19 18:36:47 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
// Get the extent of the inactive semispace (for use as a marking stack,
|
|
|
|
// or to zap it). Notice: space-addresses are not necessarily on the
|
|
|
|
// same page, so FromSpaceStart() might be above FromSpaceEnd().
|
|
|
|
Address FromSpacePageLow() { return from_space_.page_low(); }
|
|
|
|
Address FromSpacePageHigh() { return from_space_.page_high(); }
|
|
|
|
Address FromSpaceStart() { return from_space_.space_start(); }
|
|
|
|
Address FromSpaceEnd() { return from_space_.space_end(); }
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
// Get the extent of the active semispace's pages' memory.
|
|
|
|
Address ToSpaceStart() { return to_space_.space_start(); }
|
|
|
|
Address ToSpaceEnd() { return to_space_.space_end(); }
|
|
|
|
|
|
|
|
inline bool ToSpaceContains(Address address) {
|
|
|
|
return to_space_.Contains(address);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2011-09-19 18:36:47 +00:00
|
|
|
inline bool FromSpaceContains(Address address) {
|
|
|
|
return from_space_.Contains(address);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// True if the object is a heap object in the address range of the
|
|
|
|
// respective semispace (not necessarily below the allocation pointer of the
|
|
|
|
// semispace).
|
2011-09-19 18:36:47 +00:00
|
|
|
inline bool ToSpaceContains(Object* o) { return to_space_.Contains(o); }
|
|
|
|
inline bool FromSpaceContains(Object* o) { return from_space_.Contains(o); }
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
// Try to switch the active semispace to a new, empty, page.
|
|
|
|
// Returns false if this isn't possible or reasonable (i.e., there
|
|
|
|
// are no pages, or the current page is already empty), or true
|
|
|
|
// if successful.
|
|
|
|
bool AddFreshPage();
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2012-10-12 11:41:14 +00:00
|
|
|
#ifdef VERIFY_HEAP
|
2008-07-03 15:10:15 +00:00
|
|
|
// Verify the active semispace.
|
2008-09-05 12:34:09 +00:00
|
|
|
virtual void Verify();
|
2012-10-12 11:41:14 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
2008-07-03 15:10:15 +00:00
|
|
|
// Print the active semispace.
|
2008-10-17 09:13:27 +00:00
|
|
|
virtual void Print() { to_space_.Print(); }
|
2008-07-03 15:10:15 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// Iterates the active semispace to collect statistics.
|
|
|
|
void CollectStatistics();
|
|
|
|
// Reports previously collected statistics of the active semispace.
|
|
|
|
void ReportStatistics();
|
|
|
|
// Clears previously collected statistics.
|
|
|
|
void ClearHistograms();
|
|
|
|
|
|
|
|
// Record the allocation or promotion of a heap object. Note that we don't
|
|
|
|
// record every single allocation, but only those that happen in the
|
|
|
|
// to space during a scavenge GC.
|
|
|
|
void RecordAllocation(HeapObject* obj);
|
|
|
|
void RecordPromotion(HeapObject* obj);
|
|
|
|
|
2009-08-13 12:03:42 +00:00
|
|
|
// Return whether the operation succeded.
|
|
|
|
bool CommitFromSpaceIfNeeded() {
|
|
|
|
if (from_space_.is_committed()) return true;
|
|
|
|
return from_space_.Commit();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool UncommitFromSpace() {
|
|
|
|
if (!from_space_.is_committed()) return true;
|
|
|
|
return from_space_.Uncommit();
|
|
|
|
}
|
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
inline intptr_t inline_allocation_limit_step() {
|
|
|
|
return inline_allocation_limit_step_;
|
|
|
|
}
|
|
|
|
|
|
|
|
SemiSpace* active_space() { return &to_space_; }
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
private:
|
2011-09-19 18:36:47 +00:00
|
|
|
// Update allocation info to match the current to-space page.
|
|
|
|
void UpdateAllocationInfo();
|
|
|
|
|
|
|
|
Address chunk_base_;
|
|
|
|
uintptr_t chunk_size_;
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// The semispaces.
|
2008-10-17 09:13:27 +00:00
|
|
|
SemiSpace to_space_;
|
|
|
|
SemiSpace from_space_;
|
2011-09-19 18:36:47 +00:00
|
|
|
VirtualMemory reservation_;
|
|
|
|
int pages_used_;
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// Start address and bit mask for containment testing.
|
|
|
|
Address start_;
|
2009-05-07 08:50:22 +00:00
|
|
|
uintptr_t address_mask_;
|
|
|
|
uintptr_t object_mask_;
|
|
|
|
uintptr_t object_expected_;
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// Allocation pointer and limit for normal allocation and allocation during
|
|
|
|
// mark-compact collection.
|
|
|
|
AllocationInfo allocation_info_;
|
2011-09-19 18:36:47 +00:00
|
|
|
|
|
|
|
// When incremental marking is active we will set allocation_info_.limit
|
|
|
|
// to be lower than actual limit and then will gradually increase it
|
|
|
|
// in steps to guarantee that we do incremental marking steps even
|
|
|
|
// when all allocation is performed from inlined generated code.
|
|
|
|
intptr_t inline_allocation_limit_step_;
|
|
|
|
|
|
|
|
Address top_on_previous_step_;
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
HistogramInfo* allocated_histogram_;
|
|
|
|
HistogramInfo* promoted_histogram_;
|
|
|
|
|
2011-11-09 13:48:43 +00:00
|
|
|
MUST_USE_RESULT MaybeObject* SlowAllocateRaw(int size_in_bytes);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
friend class SemiSpaceIterator;
|
|
|
|
|
|
|
|
public:
|
|
|
|
TRACK_MEMORY("NewSpace")
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Old object space (excluding map objects)
|
|
|
|
|
|
|
|
class OldSpace : public PagedSpace {
|
|
|
|
public:
|
|
|
|
// Creates an old space object with a given maximum capacity.
|
|
|
|
// The constructor does not allocate pages from OS.
|
2011-03-18 20:35:07 +00:00
|
|
|
OldSpace(Heap* heap,
|
|
|
|
intptr_t max_capacity,
|
|
|
|
AllocationSpace id,
|
2013-09-11 18:30:01 +00:00
|
|
|
Executability executable)
|
|
|
|
: PagedSpace(heap, max_capacity, id, executable) {
|
2012-01-31 13:33:44 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
TRACK_MEMORY("OldSpace")
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
// For contiguous spaces, top should be in the space (or at the end) and limit
|
|
|
|
// should be the end of the space.
|
|
|
|
#define ASSERT_SEMISPACE_ALLOCATION_INFO(info, space) \
|
2013-10-25 09:58:21 +00:00
|
|
|
SLOW_ASSERT((space).page_low() <= (info).top() \
|
|
|
|
&& (info).top() <= (space).page_high() \
|
|
|
|
&& (info).limit() <= (space).page_high())
|
2011-09-19 18:36:47 +00:00
|
|
|
|
|
|
|
|
2009-07-09 11:13:08 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Old space for all map objects
|
|
|
|
|
2013-11-12 16:36:14 +00:00
|
|
|
class MapSpace : public PagedSpace {
|
2009-07-09 11:13:08 +00:00
|
|
|
public:
|
|
|
|
// Creates a map space object with a maximum capacity.
|
2012-02-08 15:39:41 +00:00
|
|
|
MapSpace(Heap* heap, intptr_t max_capacity, AllocationSpace id)
|
2013-11-12 16:36:14 +00:00
|
|
|
: PagedSpace(heap, max_capacity, id, NOT_EXECUTABLE),
|
2012-02-08 15:39:41 +00:00
|
|
|
max_map_space_pages_(kMaxMapPageIndex - 1) {
|
2010-01-19 16:34:37 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-07-09 11:13:08 +00:00
|
|
|
// Given an index, returns the page address.
|
2011-09-19 18:36:47 +00:00
|
|
|
// TODO(1600): this limit is artifical just to keep code compilable
|
|
|
|
static const int kMaxMapPageIndex = 1 << 16;
|
|
|
|
|
|
|
|
virtual int RoundSizeDownToObjectAlignment(int size) {
|
|
|
|
if (IsPowerOf2(Map::kSize)) {
|
|
|
|
return RoundDown(size, Map::kSize);
|
|
|
|
} else {
|
|
|
|
return (size / Map::kSize) * Map::kSize;
|
2010-01-13 19:16:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-09 11:13:08 +00:00
|
|
|
protected:
|
|
|
|
virtual void VerifyObject(HeapObject* obj);
|
|
|
|
|
|
|
|
private:
|
2014-01-23 13:02:27 +00:00
|
|
|
static const int kMapsPerPage = Page::kMaxRegularHeapObjectSize / Map::kSize;
|
2010-01-13 19:16:07 +00:00
|
|
|
|
|
|
|
// Do map space compaction if there is a page gap.
|
2010-01-19 16:34:37 +00:00
|
|
|
int CompactionThreshold() {
|
|
|
|
return kMapsPerPage * (max_map_space_pages_ - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
const int max_map_space_pages_;
|
2010-01-13 19:16:07 +00:00
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
public:
|
|
|
|
TRACK_MEMORY("MapSpace")
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-07-09 11:13:08 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
2013-06-12 15:03:44 +00:00
|
|
|
// Old space for simple property cell objects
|
2009-07-09 11:13:08 +00:00
|
|
|
|
2013-11-12 16:36:14 +00:00
|
|
|
class CellSpace : public PagedSpace {
|
2009-07-09 11:13:08 +00:00
|
|
|
public:
|
|
|
|
// Creates a property cell space object with a maximum capacity.
|
2011-03-18 20:35:07 +00:00
|
|
|
CellSpace(Heap* heap, intptr_t max_capacity, AllocationSpace id)
|
2013-11-12 16:36:14 +00:00
|
|
|
: PagedSpace(heap, max_capacity, id, NOT_EXECUTABLE) {
|
|
|
|
}
|
2013-06-12 15:03:44 +00:00
|
|
|
|
|
|
|
virtual int RoundSizeDownToObjectAlignment(int size) {
|
|
|
|
if (IsPowerOf2(Cell::kSize)) {
|
|
|
|
return RoundDown(size, Cell::kSize);
|
|
|
|
} else {
|
|
|
|
return (size / Cell::kSize) * Cell::kSize;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual void VerifyObject(HeapObject* obj);
|
|
|
|
|
|
|
|
public:
|
|
|
|
TRACK_MEMORY("CellSpace")
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Old space for all global object property cell objects
|
|
|
|
|
2013-11-12 16:36:14 +00:00
|
|
|
class PropertyCellSpace : public PagedSpace {
|
2013-06-12 15:03:44 +00:00
|
|
|
public:
|
|
|
|
// Creates a property cell space object with a maximum capacity.
|
|
|
|
PropertyCellSpace(Heap* heap, intptr_t max_capacity,
|
|
|
|
AllocationSpace id)
|
2013-11-12 16:36:14 +00:00
|
|
|
: PagedSpace(heap, max_capacity, id, NOT_EXECUTABLE) {
|
|
|
|
}
|
2009-07-09 11:13:08 +00:00
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
virtual int RoundSizeDownToObjectAlignment(int size) {
|
2013-06-14 16:06:12 +00:00
|
|
|
if (IsPowerOf2(PropertyCell::kSize)) {
|
|
|
|
return RoundDown(size, PropertyCell::kSize);
|
2011-09-19 18:36:47 +00:00
|
|
|
} else {
|
2013-06-14 16:06:12 +00:00
|
|
|
return (size / PropertyCell::kSize) * PropertyCell::kSize;
|
2011-09-19 18:36:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-09 11:13:08 +00:00
|
|
|
protected:
|
|
|
|
virtual void VerifyObject(HeapObject* obj);
|
|
|
|
|
|
|
|
public:
|
2013-06-12 15:03:44 +00:00
|
|
|
TRACK_MEMORY("PropertyCellSpace")
|
2009-07-09 11:13:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Large objects ( > Page::kMaxHeapObjectSize ) are allocated and managed by
|
|
|
|
// the large object space. A large object is allocated from OS heap with
|
|
|
|
// extra padding bytes (Page::kPageSize + Page::kObjectStartOffset).
|
|
|
|
// A large object always starts at Page::kObjectStartOffset to a page.
|
|
|
|
// Large objects do not move during garbage collections.
|
|
|
|
|
2008-07-30 08:49:36 +00:00
|
|
|
class LargeObjectSpace : public Space {
|
2008-07-03 15:10:15 +00:00
|
|
|
public:
|
2011-10-19 10:15:09 +00:00
|
|
|
LargeObjectSpace(Heap* heap, intptr_t max_capacity, AllocationSpace id);
|
2008-09-05 12:34:09 +00:00
|
|
|
virtual ~LargeObjectSpace() {}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// Initializes internal data structures.
|
2012-01-13 13:09:52 +00:00
|
|
|
bool SetUp();
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// Releases internal resources, frees objects in this space.
|
|
|
|
void TearDown();
|
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
static intptr_t ObjectSizeFor(intptr_t chunk_size) {
|
|
|
|
if (chunk_size <= (Page::kPageSize + Page::kObjectStartOffset)) return 0;
|
|
|
|
return chunk_size - Page::kPageSize - Page::kObjectStartOffset;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Shared implementation of AllocateRaw, AllocateRawCode and
|
|
|
|
// AllocateRawFixedArray.
|
2013-09-11 18:30:01 +00:00
|
|
|
MUST_USE_RESULT MaybeObject* AllocateRaw(int object_size,
|
|
|
|
Executability executable);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2010-05-27 12:30:45 +00:00
|
|
|
// Available bytes for objects in this space.
|
2011-03-18 20:35:07 +00:00
|
|
|
inline intptr_t Available();
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2010-09-30 07:22:53 +00:00
|
|
|
virtual intptr_t Size() {
|
2008-07-03 15:10:15 +00:00
|
|
|
return size_;
|
|
|
|
}
|
|
|
|
|
2010-11-15 10:38:24 +00:00
|
|
|
virtual intptr_t SizeOfObjects() {
|
|
|
|
return objects_size_;
|
|
|
|
}
|
|
|
|
|
2013-11-05 11:59:42 +00:00
|
|
|
intptr_t MaximumCommittedMemory() {
|
|
|
|
return maximum_committed_;
|
|
|
|
}
|
|
|
|
|
2012-06-25 12:51:03 +00:00
|
|
|
intptr_t CommittedMemory() {
|
|
|
|
return Size();
|
|
|
|
}
|
|
|
|
|
2012-10-22 16:33:10 +00:00
|
|
|
// Approximate amount of physical memory committed for this space.
|
|
|
|
size_t CommittedPhysicalMemory();
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
int PageCount() {
|
|
|
|
return page_count_;
|
|
|
|
}
|
|
|
|
|
2014-04-23 15:08:03 +00:00
|
|
|
// Finds an object for a given address, returns a Smi if it is not found.
|
|
|
|
// The function iterates through all objects in this space, may be slow.
|
|
|
|
Object* FindObject(Address a);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2012-03-19 12:08:20 +00:00
|
|
|
// Finds a large object page containing the given address, returns NULL
|
2010-08-30 08:54:43 +00:00
|
|
|
// if such a page doesn't exist.
|
2012-03-19 12:08:20 +00:00
|
|
|
LargePage* FindPage(Address a);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// Frees unmarked objects.
|
|
|
|
void FreeUnmarkedObjects();
|
|
|
|
|
|
|
|
// Checks whether a heap object is in this space; O(1).
|
|
|
|
bool Contains(HeapObject* obj);
|
|
|
|
|
|
|
|
// Checks whether the space is empty.
|
2011-09-19 18:36:47 +00:00
|
|
|
bool IsEmpty() { return first_page_ == NULL; }
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
LargePage* first_page() { return first_page_; }
|
|
|
|
|
2012-10-12 11:41:14 +00:00
|
|
|
#ifdef VERIFY_HEAP
|
2008-09-05 12:34:09 +00:00
|
|
|
virtual void Verify();
|
2012-10-12 11:41:14 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
2008-09-05 12:34:09 +00:00
|
|
|
virtual void Print();
|
2008-07-03 15:10:15 +00:00
|
|
|
void ReportStatistics();
|
|
|
|
void CollectCodeStatistics();
|
|
|
|
#endif
|
|
|
|
// Checks whether an address is in the object area in this space. It
|
|
|
|
// iterates all objects in the space. May be slow.
|
2014-04-23 15:08:03 +00:00
|
|
|
bool SlowContains(Address addr) { return FindObject(addr)->IsHeapObject(); }
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
private:
|
2011-10-19 10:15:09 +00:00
|
|
|
intptr_t max_capacity_;
|
2013-11-05 11:59:42 +00:00
|
|
|
intptr_t maximum_committed_;
|
2008-07-03 15:10:15 +00:00
|
|
|
// The head of the linked list of large object chunks.
|
2011-09-19 18:36:47 +00:00
|
|
|
LargePage* first_page_;
|
2010-09-30 07:22:53 +00:00
|
|
|
intptr_t size_; // allocated bytes
|
2008-07-03 15:10:15 +00:00
|
|
|
int page_count_; // number of chunks
|
2010-11-15 10:38:24 +00:00
|
|
|
intptr_t objects_size_; // size of objects
|
2012-03-19 12:08:20 +00:00
|
|
|
// Map MemoryChunk::kAlignment-aligned chunks to large pages covering them
|
|
|
|
HashMap chunk_map_;
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-03-24 12:47:53 +00:00
|
|
|
friend class LargeObjectIterator;
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
public:
|
|
|
|
TRACK_MEMORY("LargeObjectSpace")
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class LargeObjectIterator: public ObjectIterator {
|
|
|
|
public:
|
|
|
|
explicit LargeObjectIterator(LargeObjectSpace* space);
|
|
|
|
LargeObjectIterator(LargeObjectSpace* space, HeapObjectCallback size_func);
|
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
HeapObject* Next();
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// implementation of ObjectIterator.
|
2011-09-19 18:36:47 +00:00
|
|
|
virtual HeapObject* next_object() { return Next(); }
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
private:
|
2011-09-19 18:36:47 +00:00
|
|
|
LargePage* current_;
|
2008-07-03 15:10:15 +00:00
|
|
|
HeapObjectCallback size_func_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
// Iterates over the chunks (pages and large object pages) that can contain
|
|
|
|
// pointers to new space.
|
|
|
|
class PointerChunkIterator BASE_EMBEDDED {
|
|
|
|
public:
|
|
|
|
inline explicit PointerChunkIterator(Heap* heap);
|
|
|
|
|
|
|
|
// Return NULL when the iterator is done.
|
|
|
|
MemoryChunk* next() {
|
|
|
|
switch (state_) {
|
|
|
|
case kOldPointerState: {
|
|
|
|
if (old_pointer_iterator_.has_next()) {
|
|
|
|
return old_pointer_iterator_.next();
|
|
|
|
}
|
|
|
|
state_ = kMapState;
|
|
|
|
// Fall through.
|
|
|
|
}
|
|
|
|
case kMapState: {
|
|
|
|
if (map_iterator_.has_next()) {
|
|
|
|
return map_iterator_.next();
|
|
|
|
}
|
|
|
|
state_ = kLargeObjectState;
|
|
|
|
// Fall through.
|
|
|
|
}
|
|
|
|
case kLargeObjectState: {
|
|
|
|
HeapObject* heap_object;
|
|
|
|
do {
|
|
|
|
heap_object = lo_iterator_.Next();
|
|
|
|
if (heap_object == NULL) {
|
|
|
|
state_ = kFinishedState;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
// Fixed arrays are the only pointer-containing objects in large
|
|
|
|
// object space.
|
|
|
|
} while (!heap_object->IsFixedArray());
|
|
|
|
MemoryChunk* answer = MemoryChunk::FromAddress(heap_object->address());
|
|
|
|
return answer;
|
|
|
|
}
|
|
|
|
case kFinishedState:
|
|
|
|
return NULL;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
UNREACHABLE();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
enum State {
|
|
|
|
kOldPointerState,
|
|
|
|
kMapState,
|
|
|
|
kLargeObjectState,
|
|
|
|
kFinishedState
|
|
|
|
};
|
|
|
|
State state_;
|
|
|
|
PageIterator old_pointer_iterator_;
|
|
|
|
PageIterator map_iterator_;
|
|
|
|
LargeObjectIterator lo_iterator_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
struct CommentStatistic {
|
|
|
|
const char* comment;
|
|
|
|
int size;
|
|
|
|
int count;
|
|
|
|
void Clear() {
|
|
|
|
comment = NULL;
|
|
|
|
size = 0;
|
|
|
|
count = 0;
|
|
|
|
}
|
|
|
|
// Must be small, since an iteration is used for lookup.
|
|
|
|
static const int kMaxComments = 64;
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
} } // namespace v8::internal
|
|
|
|
|
|
|
|
#endif // V8_SPACES_H_
|