V8 Project
v8::internal::MemoryAllocator Class Reference

#include <spaces.h>

+ Collaboration diagram for v8::internal::MemoryAllocator:

Classes

struct  MemoryAllocationCallbackRegistration
 

Public Member Functions

 MemoryAllocator (Isolate *isolate)
 
bool SetUp (intptr_t max_capacity, intptr_t capacity_executable)
 
void TearDown ()
 
PageAllocatePage (intptr_t size, PagedSpace *owner, Executability executable)
 
LargePageAllocateLargePage (intptr_t object_size, Space *owner, Executability executable)
 
void Free (MemoryChunk *chunk)
 
intptr_t Available ()
 
intptr_t Size ()
 
intptr_t AvailableExecutable ()
 
intptr_t SizeExecutable ()
 
intptr_t MaxAvailable ()
 
bool IsOutsideAllocatedSpace (const void *address) const
 
MemoryChunkAllocateChunk (intptr_t reserve_area_size, intptr_t commit_area_size, Executability executable, Space *space)
 
Address ReserveAlignedMemory (size_t requested, size_t alignment, base::VirtualMemory *controller)
 
Address AllocateAlignedMemory (size_t reserve_size, size_t commit_size, size_t alignment, Executability executable, base::VirtualMemory *controller)
 
bool CommitMemory (Address addr, size_t size, Executability executable)
 
void FreeMemory (base::VirtualMemory *reservation, Executability executable)
 
void FreeMemory (Address addr, size_t size, Executability executable)
 
bool CommitBlock (Address start, size_t size, Executability executable)
 
bool UncommitBlock (Address start, size_t size)
 
void ZapBlock (Address start, size_t size)
 
void PerformAllocationCallback (ObjectSpace space, AllocationAction action, size_t size)
 
void AddMemoryAllocationCallback (MemoryAllocationCallback callback, ObjectSpace space, AllocationAction action)
 
void RemoveMemoryAllocationCallback (MemoryAllocationCallback callback)
 
bool MemoryAllocationCallbackRegistered (MemoryAllocationCallback callback)
 
MUST_USE_RESULT bool CommitExecutableMemory (base::VirtualMemory *vm, Address start, size_t commit_size, size_t reserved_size)
 

Static Public Member Functions

static int CodePageGuardStartOffset ()
 
static int CodePageGuardSize ()
 
static int CodePageAreaStartOffset ()
 
static int CodePageAreaEndOffset ()
 
static int CodePageAreaSize ()
 

Private Member Functions

PageInitializePagesInChunk (int chunk_id, int pages_in_chunk, PagedSpace *owner)
 
void UpdateAllocatedSpaceLimits (void *low, void *high)
 
 DISALLOW_IMPLICIT_CONSTRUCTORS (MemoryAllocator)
 

Private Attributes

Isolateisolate_
 
size_t capacity_
 
size_t capacity_executable_
 
size_t size_
 
size_t size_executable_
 
void * lowest_ever_allocated_
 
void * highest_ever_allocated_
 
List< MemoryAllocationCallbackRegistrationmemory_allocation_callbacks_
 

Detailed Description

Definition at line 1001 of file spaces.h.

Constructor & Destructor Documentation

◆ MemoryAllocator()

v8::internal::MemoryAllocator::MemoryAllocator ( Isolate isolate)
explicit

Definition at line 252 of file spaces.cc.

253  : isolate_(isolate),
254  capacity_(0),
256  size_(0),
257  size_executable_(0),
258  lowest_ever_allocated_(reinterpret_cast<void*>(-1)),
259  highest_ever_allocated_(reinterpret_cast<void*>(0)) {}

Member Function Documentation

◆ AddMemoryAllocationCallback()

void v8::internal::MemoryAllocator::AddMemoryAllocationCallback ( MemoryAllocationCallback  callback,
ObjectSpace  space,
AllocationAction  action 
)

Definition at line 772 of file spaces.cc.

774  {
775  DCHECK(callback != NULL);
776  MemoryAllocationCallbackRegistration registration(callback, space, action);
778  return memory_allocation_callbacks_.Add(registration);
779 }
List< MemoryAllocationCallbackRegistration > memory_allocation_callbacks_
Definition: spaces.h:1143
bool MemoryAllocationCallbackRegistered(MemoryAllocationCallback callback)
Definition: spaces.cc:763
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long enable alignment of csp to bytes on platforms which prefer the register to always be expose gc extension under the specified name show built in functions in stack traces use random jit cookie to mask large constants minimum length for automatic enable preparsing CPU profiler sampling interval in microseconds trace out of bounds accesses to external arrays default size of stack region v8 is allowed to maximum length of function source code printed in a stack trace min size of a semi space(in MBytes)
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long enable alignment of csp to bytes on platforms which prefer the register to always be NULL
#define DCHECK(condition)
Definition: logging.h:205

References DCHECK, memory_allocation_callbacks_, MemoryAllocationCallbackRegistered(), NULL, and space().

Referenced by v8::V8::AddMemoryAllocationCallback().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ AllocateAlignedMemory()

Address v8::internal::MemoryAllocator::AllocateAlignedMemory ( size_t  reserve_size,
size_t  commit_size,
size_t  alignment,
Executability  executable,
base::VirtualMemory controller 
)

Definition at line 358 of file spaces.cc.

360  {
361  DCHECK(commit_size <= reserve_size);
362  base::VirtualMemory reservation;
363  Address base = ReserveAlignedMemory(reserve_size, alignment, &reservation);
364  if (base == NULL) return NULL;
365 
366  if (executable == EXECUTABLE) {
367  if (!CommitExecutableMemory(&reservation, base, commit_size,
368  reserve_size)) {
369  base = NULL;
370  }
371  } else {
372  if (reservation.Commit(base, commit_size, false)) {
373  UpdateAllocatedSpaceLimits(base, base + commit_size);
374  } else {
375  base = NULL;
376  }
377  }
378 
379  if (base == NULL) {
380  // Failed to commit the body. Release the mapping and any partially
381  // commited regions inside it.
382  reservation.Release();
383  return NULL;
384  }
385 
386  controller->TakeControl(&reservation);
387  return base;
388 }
void UpdateAllocatedSpaceLimits(void *low, void *high)
Definition: spaces.h:1152
Address ReserveAlignedMemory(size_t requested, size_t alignment, base::VirtualMemory *controller)
Definition: spaces.cc:345
MUST_USE_RESULT bool CommitExecutableMemory(base::VirtualMemory *vm, Address start, size_t commit_size, size_t reserved_size)
Definition: spaces.cc:834
byte * Address
Definition: globals.h:101

References v8::base::VirtualMemory::Commit(), CommitExecutableMemory(), DCHECK, v8::internal::EXECUTABLE, NULL, v8::base::VirtualMemory::Release(), ReserveAlignedMemory(), v8::base::VirtualMemory::TakeControl(), and UpdateAllocatedSpaceLimits().

Referenced by AllocateChunk().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ AllocateChunk()

MemoryChunk * v8::internal::MemoryAllocator::AllocateChunk ( intptr_t  reserve_area_size,
intptr_t  commit_area_size,
Executability  executable,
Space space 
)

Definition at line 548 of file spaces.cc.

551  {
552  DCHECK(commit_area_size <= reserve_area_size);
553 
554  size_t chunk_size;
555  Heap* heap = isolate_->heap();
556  Address base = NULL;
557  base::VirtualMemory reservation;
558  Address area_start = NULL;
559  Address area_end = NULL;
560 
561  //
562  // MemoryChunk layout:
563  //
564  // Executable
565  // +----------------------------+<- base aligned with MemoryChunk::kAlignment
566  // | Header |
567  // +----------------------------+<- base + CodePageGuardStartOffset
568  // | Guard |
569  // +----------------------------+<- area_start_
570  // | Area |
571  // +----------------------------+<- area_end_ (area_start + commit_area_size)
572  // | Committed but not used |
573  // +----------------------------+<- aligned at OS page boundary
574  // | Reserved but not committed |
575  // +----------------------------+<- aligned at OS page boundary
576  // | Guard |
577  // +----------------------------+<- base + chunk_size
578  //
579  // Non-executable
580  // +----------------------------+<- base aligned with MemoryChunk::kAlignment
581  // | Header |
582  // +----------------------------+<- area_start_ (base + kObjectStartOffset)
583  // | Area |
584  // +----------------------------+<- area_end_ (area_start + commit_area_size)
585  // | Committed but not used |
586  // +----------------------------+<- aligned at OS page boundary
587  // | Reserved but not committed |
588  // +----------------------------+<- base + chunk_size
589  //
590 
591  if (executable == EXECUTABLE) {
592  chunk_size = RoundUp(CodePageAreaStartOffset() + reserve_area_size,
595 
596  // Check executable memory limit.
597  if (size_executable_ + chunk_size > capacity_executable_) {
598  LOG(isolate_, StringEvent("MemoryAllocator::AllocateRawMemory",
599  "V8 Executable Allocation capacity exceeded"));
600  return NULL;
601  }
602 
603  // Size of header (not executable) plus area (executable).
604  size_t commit_size = RoundUp(CodePageGuardStartOffset() + commit_area_size,
606  // Allocate executable memory either from code range or from the
607  // OS.
608  if (isolate_->code_range() != NULL && isolate_->code_range()->valid()) {
609  base = isolate_->code_range()->AllocateRawMemory(chunk_size, commit_size,
610  &chunk_size);
611  DCHECK(
612  IsAligned(reinterpret_cast<intptr_t>(base), MemoryChunk::kAlignment));
613  if (base == NULL) return NULL;
614  size_ += chunk_size;
615  // Update executable memory size.
616  size_executable_ += chunk_size;
617  } else {
618  base = AllocateAlignedMemory(chunk_size, commit_size,
619  MemoryChunk::kAlignment, executable,
620  &reservation);
621  if (base == NULL) return NULL;
622  // Update executable memory size.
623  size_executable_ += reservation.size();
624  }
625 
626  if (Heap::ShouldZapGarbage()) {
628  ZapBlock(base + CodePageAreaStartOffset(), commit_area_size);
629  }
630 
631  area_start = base + CodePageAreaStartOffset();
632  area_end = area_start + commit_area_size;
633  } else {
634  chunk_size = RoundUp(MemoryChunk::kObjectStartOffset + reserve_area_size,
636  size_t commit_size =
637  RoundUp(MemoryChunk::kObjectStartOffset + commit_area_size,
639  base =
640  AllocateAlignedMemory(chunk_size, commit_size, MemoryChunk::kAlignment,
641  executable, &reservation);
642 
643  if (base == NULL) return NULL;
644 
645  if (Heap::ShouldZapGarbage()) {
646  ZapBlock(base, Page::kObjectStartOffset + commit_area_size);
647  }
648 
649  area_start = base + Page::kObjectStartOffset;
650  area_end = area_start + commit_area_size;
651  }
652 
653  // Use chunk_size for statistics and callbacks because we assume that they
654  // treat reserved but not-yet committed memory regions of chunks as allocated.
655  isolate_->counters()->memory_allocated()->Increment(
656  static_cast<int>(chunk_size));
657 
658  LOG(isolate_, NewEvent("MemoryChunk", base, chunk_size));
659  if (owner != NULL) {
660  ObjectSpace space = static_cast<ObjectSpace>(1 << owner->identity());
662  }
663 
664  MemoryChunk* result = MemoryChunk::Initialize(
665  heap, base, chunk_size, area_start, area_end, executable, owner);
666  result->set_reserved_memory(&reservation);
667  return result;
668 }
static intptr_t CommitPageSize()
MUST_USE_RESULT Address AllocateRawMemory(const size_t requested_size, const size_t commit_size, size_t *allocated)
Definition: spaces.cc:186
static bool ShouldZapGarbage()
Definition: heap.h:926
CodeRange * code_range()
Definition: isolate.h:863
Counters * counters()
Definition: isolate.h:857
static int CodePageGuardSize()
Definition: spaces.cc:815
void ZapBlock(Address start, size_t size)
Definition: spaces.cc:743
static int CodePageAreaStartOffset()
Definition: spaces.cc:820
Address AllocateAlignedMemory(size_t reserve_size, size_t commit_size, size_t alignment, Executability executable, base::VirtualMemory *controller)
Definition: spaces.cc:358
void PerformAllocationCallback(ObjectSpace space, AllocationAction action, size_t size)
Definition: spaces.cc:750
static int CodePageGuardStartOffset()
Definition: spaces.cc:808
static const int kObjectStartOffset
Definition: spaces.h:550
static MemoryChunk * Initialize(Heap *heap, Address base, size_t size, Address area_start, Address area_end, Executability executable, Space *owner)
Definition: spaces.cc:430
static const intptr_t kAlignment
Definition: spaces.h:523
#define LOG(isolate, Call)
Definition: log.h:69
static void RoundUp(Vector< char > buffer, int *length, int *decimal_point)
Definition: fixed-dtoa.cc:171
bool IsAligned(T value, U alignment)
Definition: utils.h:123
@ kAllocationActionAllocate
Definition: v8.h:4166
ObjectSpace
Definition: v8.h:4152

References AllocateAlignedMemory(), v8::internal::CodeRange::AllocateRawMemory(), capacity_executable_, v8::internal::Isolate::code_range(), CodePageAreaStartOffset(), CodePageGuardSize(), CodePageGuardStartOffset(), v8::base::OS::CommitPageSize(), v8::internal::Isolate::counters(), DCHECK, v8::internal::EXECUTABLE, v8::internal::Isolate::heap(), v8::internal::Space::identity(), v8::internal::MemoryChunk::Initialize(), v8::internal::IsAligned(), isolate_, v8::internal::MemoryChunk::kAlignment, v8::kAllocationActionAllocate, v8::internal::MemoryChunk::kObjectStartOffset, LOG, NULL, PerformAllocationCallback(), v8::internal::RoundUp(), v8::internal::MemoryChunk::set_reserved_memory(), v8::internal::Heap::ShouldZapGarbage(), v8::base::VirtualMemory::size(), size_, size_executable_, space(), v8::internal::CodeRange::valid(), and ZapBlock().

Referenced by v8::internal::AllocateCodeChunk(), AllocateLargePage(), AllocatePage(), and v8::internal::PagedSpace::CreateEmergencyMemory().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ AllocateLargePage()

LargePage * v8::internal::MemoryAllocator::AllocateLargePage ( intptr_t  object_size,
Space owner,
Executability  executable 
)

Definition at line 690 of file spaces.cc.

692  {
693  MemoryChunk* chunk =
694  AllocateChunk(object_size, object_size, executable, owner);
695  if (chunk == NULL) return NULL;
696  return LargePage::Initialize(isolate_->heap(), chunk);
697 }
static LargePage * Initialize(Heap *heap, MemoryChunk *chunk)
Definition: spaces-inl.h:292
MemoryChunk * AllocateChunk(intptr_t reserve_area_size, intptr_t commit_area_size, Executability executable, Space *space)
Definition: spaces.cc:548

References AllocateChunk(), v8::internal::Isolate::heap(), v8::internal::LargePage::Initialize(), isolate_, and NULL.

Referenced by v8::internal::LargeObjectSpace::AllocateRaw().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ AllocatePage()

Page * v8::internal::MemoryAllocator::AllocatePage ( intptr_t  size,
PagedSpace owner,
Executability  executable 
)

Definition at line 680 of file spaces.cc.

681  {
682  MemoryChunk* chunk = AllocateChunk(size, size, executable, owner);
683 
684  if (chunk == NULL) return NULL;
685 
686  return Page::Initialize(isolate_->heap(), chunk, executable, owner);
687 }
static Page * Initialize(Heap *heap, MemoryChunk *chunk, Executability executable, PagedSpace *owner)
Definition: spaces-inl.h:136
enable harmony numeric enable harmony object literal extensions Optimize object size

References AllocateChunk(), v8::internal::Isolate::heap(), v8::internal::Page::Initialize(), isolate_, NULL, and size.

Referenced by v8::internal::PagedSpace::Expand().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Available()

intptr_t v8::internal::MemoryAllocator::Available ( )
inline

Definition at line 1020 of file spaces.h.

1020 { return capacity_ < size_ ? 0 : capacity_ - size_; }

References capacity_, and size_.

Referenced by MaxAvailable(), v8::internal::Heap::PrintShortHeapStatistics(), and v8::internal::Heap::RecordStats().

+ Here is the caller graph for this function:

◆ AvailableExecutable()

intptr_t v8::internal::MemoryAllocator::AvailableExecutable ( )
inline

Definition at line 1026 of file spaces.h.

1026  {
1027  if (capacity_executable_ < size_executable_) return 0;
1029  }

References capacity_executable_, and size_executable_.

◆ CodePageAreaEndOffset()

int v8::internal::MemoryAllocator::CodePageAreaEndOffset ( )
static

Definition at line 827 of file spaces.cc.

827  {
828  // We are guarding code pages: the last OS page will be protected as
829  // non-writable.
830  return Page::kPageSize - static_cast<int>(base::OS::CommitPageSize());
831 }
static const int kPageSize
Definition: spaces.h:748

References v8::base::OS::CommitPageSize(), and v8::internal::Page::kPageSize.

Referenced by CodePageAreaSize().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ CodePageAreaSize()

static int v8::internal::MemoryAllocator::CodePageAreaSize ( )
inlinestatic

Definition at line 1103 of file spaces.h.

1103  {
1105  }
static int CodePageAreaEndOffset()
Definition: spaces.cc:827

References CodePageAreaEndOffset(), and CodePageAreaStartOffset().

Referenced by v8::internal::PagedSpace::PagedSpace(), and v8::internal::Serializer::SpaceAreaSize().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ CodePageAreaStartOffset()

int v8::internal::MemoryAllocator::CodePageAreaStartOffset ( )
static

Definition at line 820 of file spaces.cc.

820  {
821  // We are guarding code pages: the first OS page after the header
822  // will be protected as non-writable.
824 }

References CodePageGuardSize(), and CodePageGuardStartOffset().

Referenced by AllocateChunk(), CodePageAreaSize(), and CommitExecutableMemory().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ CodePageGuardSize()

int v8::internal::MemoryAllocator::CodePageGuardSize ( )
static

Definition at line 815 of file spaces.cc.

815  {
816  return static_cast<int>(base::OS::CommitPageSize());
817 }

References v8::base::OS::CommitPageSize().

Referenced by AllocateChunk(), CodePageAreaStartOffset(), v8::internal::MemoryChunk::CommitArea(), and CommitExecutableMemory().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ CodePageGuardStartOffset()

int v8::internal::MemoryAllocator::CodePageGuardStartOffset ( )
static

Definition at line 808 of file spaces.cc.

808  {
809  // We are guarding code pages: the first OS page after the header
810  // will be protected as non-writable.
812 }

References v8::base::OS::CommitPageSize(), v8::internal::MemoryChunk::kObjectStartOffset, and v8::internal::RoundUp().

Referenced by AllocateChunk(), CodePageAreaStartOffset(), and CommitExecutableMemory().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ CommitBlock()

bool v8::internal::MemoryAllocator::CommitBlock ( Address  start,
size_t  size,
Executability  executable 
)

Definition at line 723 of file spaces.cc.

724  {
725  if (!CommitMemory(start, size, executable)) return false;
726 
727  if (Heap::ShouldZapGarbage()) {
728  ZapBlock(start, size);
729  }
730 
731  isolate_->counters()->memory_allocated()->Increment(static_cast<int>(size));
732  return true;
733 }
bool CommitMemory(Address addr, size_t size, Executability executable)
Definition: spaces.cc:284

References CommitMemory(), v8::internal::Isolate::counters(), isolate_, v8::internal::Heap::ShouldZapGarbage(), size, and ZapBlock().

+ Here is the call graph for this function:

◆ CommitExecutableMemory()

bool v8::internal::MemoryAllocator::CommitExecutableMemory ( base::VirtualMemory vm,
Address  start,
size_t  commit_size,
size_t  reserved_size 
)

Definition at line 834 of file spaces.cc.

836  {
837  // Commit page header (not executable).
838  if (!vm->Commit(start, CodePageGuardStartOffset(), false)) {
839  return false;
840  }
841 
842  // Create guard page after the header.
843  if (!vm->Guard(start + CodePageGuardStartOffset())) {
844  return false;
845  }
846 
847  // Commit page body (executable).
848  if (!vm->Commit(start + CodePageAreaStartOffset(),
849  commit_size - CodePageGuardStartOffset(), true)) {
850  return false;
851  }
852 
853  // Create guard page before the end.
854  if (!vm->Guard(start + reserved_size - CodePageGuardSize())) {
855  return false;
856  }
857 
859  commit_size -
861  return true;
862 }

References CodePageAreaStartOffset(), CodePageGuardSize(), CodePageGuardStartOffset(), v8::base::VirtualMemory::Commit(), v8::base::VirtualMemory::Guard(), and UpdateAllocatedSpaceLimits().

Referenced by AllocateAlignedMemory(), and v8::internal::CodeRange::AllocateRawMemory().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ CommitMemory()

bool v8::internal::MemoryAllocator::CommitMemory ( Address  addr,
size_t  size,
Executability  executable 
)

Definition at line 284 of file spaces.cc.

285  {
287  executable == EXECUTABLE)) {
288  return false;
289  }
290  UpdateAllocatedSpaceLimits(base, base + size);
291  return true;
292 }
static bool CommitRegion(void *base, size_t size, bool is_executable)

References v8::base::VirtualMemory::CommitRegion(), v8::internal::EXECUTABLE, size, and UpdateAllocatedSpaceLimits().

Referenced by CommitBlock(), and v8::internal::CodeRange::CommitRawMemory().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ DISALLOW_IMPLICIT_CONSTRUCTORS()

v8::internal::MemoryAllocator::DISALLOW_IMPLICIT_CONSTRUCTORS ( MemoryAllocator  )
private

◆ Free()

void v8::internal::MemoryAllocator::Free ( MemoryChunk chunk)

Definition at line 700 of file spaces.cc.

700  {
701  LOG(isolate_, DeleteEvent("MemoryChunk", chunk));
702  if (chunk->owner() != NULL) {
704  static_cast<ObjectSpace>(1 << chunk->owner()->identity());
706  }
707 
708  isolate_->heap()->RememberUnmappedPage(reinterpret_cast<Address>(chunk),
709  chunk->IsEvacuationCandidate());
710 
711  delete chunk->slots_buffer();
712  delete chunk->skip_list();
713 
714  base::VirtualMemory* reservation = chunk->reserved_memory();
715  if (reservation->IsReserved()) {
716  FreeMemory(reservation, chunk->executable());
717  } else {
718  FreeMemory(chunk->address(), chunk->size(), chunk->executable());
719  }
720 }
void RememberUnmappedPage(Address page, bool compacted)
Definition: heap.cc:6072
void FreeMemory(base::VirtualMemory *reservation, Executability executable)
Definition: spaces.cc:295
@ kAllocationActionFree
Definition: v8.h:4167

References v8::internal::MemoryChunk::address(), v8::internal::MemoryChunk::executable(), FreeMemory(), v8::internal::Isolate::heap(), v8::internal::Space::identity(), v8::internal::MemoryChunk::IsEvacuationCandidate(), isolate_, v8::base::VirtualMemory::IsReserved(), v8::kAllocationActionFree, LOG, NULL, v8::internal::MemoryChunk::owner(), PerformAllocationCallback(), v8::internal::Heap::RememberUnmappedPage(), v8::internal::MemoryChunk::reserved_memory(), v8::internal::MemoryChunk::size(), v8::internal::MemoryChunk::skip_list(), v8::internal::MemoryChunk::slots_buffer(), and space().

Referenced by v8::internal::PagedSpace::FreeEmergencyMemory(), v8::internal::Heap::FreeQueuedChunks(), v8::internal::LargeObjectSpace::FreeUnmarkedObjects(), v8::internal::PagedSpace::ReleasePage(), v8::internal::PagedSpace::TearDown(), v8::internal::LargeObjectSpace::TearDown(), and v8::internal::DeoptimizerData::~DeoptimizerData().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ FreeMemory() [1/2]

void v8::internal::MemoryAllocator::FreeMemory ( Address  addr,
size_t  size,
Executability  executable 
)

Definition at line 319 of file spaces.cc.

320  {
321  // TODO(gc) make code_range part of memory allocator?
322  DCHECK(size_ >= size);
323  size_ -= size;
324 
325  isolate_->counters()->memory_allocated()->Decrement(static_cast<int>(size));
326 
327  if (executable == EXECUTABLE) {
330  }
331  if (isolate_->code_range() != NULL &&
332  isolate_->code_range()->contains(static_cast<Address>(base))) {
333  DCHECK(executable == EXECUTABLE);
335  } else {
336  DCHECK(executable == NOT_EXECUTABLE || isolate_->code_range() == NULL ||
337  !isolate_->code_range()->valid());
338  bool result = base::VirtualMemory::ReleaseRegion(base, size);
339  USE(result);
340  DCHECK(result);
341  }
342 }
static bool ReleaseRegion(void *base, size_t size)
bool contains(Address address)
Definition: spaces.h:887
void FreeRawMemory(Address buf, size_t length)
Definition: spaces.cc:233
void USE(T)
Definition: macros.h:322
@ NOT_EXECUTABLE
Definition: globals.h:391

References v8::internal::Isolate::code_range(), v8::internal::CodeRange::contains(), v8::internal::Isolate::counters(), DCHECK, v8::internal::EXECUTABLE, v8::internal::CodeRange::FreeRawMemory(), isolate_, v8::internal::NOT_EXECUTABLE, NULL, v8::base::VirtualMemory::ReleaseRegion(), size, size_, size_executable_, USE(), and v8::internal::CodeRange::valid().

+ Here is the call graph for this function:

◆ FreeMemory() [2/2]

void v8::internal::MemoryAllocator::FreeMemory ( base::VirtualMemory reservation,
Executability  executable 
)

Definition at line 295 of file spaces.cc.

296  {
297  // TODO(gc) make code_range part of memory allocator?
298  DCHECK(reservation->IsReserved());
299  size_t size = reservation->size();
300  DCHECK(size_ >= size);
301  size_ -= size;
302 
303  isolate_->counters()->memory_allocated()->Decrement(static_cast<int>(size));
304 
305  if (executable == EXECUTABLE) {
308  }
309  // Code which is part of the code-range does not have its own VirtualMemory.
310  DCHECK(isolate_->code_range() == NULL ||
312  static_cast<Address>(reservation->address())));
313  DCHECK(executable == NOT_EXECUTABLE || isolate_->code_range() == NULL ||
314  !isolate_->code_range()->valid());
315  reservation->Release();
316 }

References v8::base::VirtualMemory::address(), v8::internal::Isolate::code_range(), v8::internal::CodeRange::contains(), v8::internal::Isolate::counters(), DCHECK, v8::internal::EXECUTABLE, isolate_, v8::base::VirtualMemory::IsReserved(), v8::internal::NOT_EXECUTABLE, NULL, v8::base::VirtualMemory::Release(), v8::base::VirtualMemory::size(), size, size_, size_executable_, and v8::internal::CodeRange::valid().

Referenced by Free(), and v8::internal::NewSpace::TearDown().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ InitializePagesInChunk()

Page* v8::internal::MemoryAllocator::InitializePagesInChunk ( int  chunk_id,
int  pages_in_chunk,
PagedSpace owner 
)
private

◆ IsOutsideAllocatedSpace()

bool v8::internal::MemoryAllocator::IsOutsideAllocatedSpace ( const void *  address) const
inline

Definition at line 1041 of file spaces.h.

1041  {
1042  return address < lowest_ever_allocated_ ||
1043  address >= highest_ever_allocated_;
1044  }

References highest_ever_allocated_, and lowest_ever_allocated_.

Referenced by v8::internal::Heap::Contains(), and v8::internal::Heap::InSpace().

+ Here is the caller graph for this function:

◆ MaxAvailable()

intptr_t v8::internal::MemoryAllocator::MaxAvailable ( )
inline

Definition at line 1035 of file spaces.h.

1035  {
1037  }
static const int kMaxRegularHeapObjectSize
Definition: spaces.h:754

References Available(), v8::internal::Page::kMaxRegularHeapObjectSize, and v8::internal::Page::kPageSize.

Referenced by v8::internal::Heap::SelectGarbageCollector().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ MemoryAllocationCallbackRegistered()

bool v8::internal::MemoryAllocator::MemoryAllocationCallbackRegistered ( MemoryAllocationCallback  callback)

Definition at line 763 of file spaces.cc.

764  {
765  for (int i = 0; i < memory_allocation_callbacks_.length(); ++i) {
766  if (memory_allocation_callbacks_[i].callback == callback) return true;
767  }
768  return false;
769 }

References memory_allocation_callbacks_.

Referenced by AddMemoryAllocationCallback().

+ Here is the caller graph for this function:

◆ PerformAllocationCallback()

void v8::internal::MemoryAllocator::PerformAllocationCallback ( ObjectSpace  space,
AllocationAction  action,
size_t  size 
)

Definition at line 750 of file spaces.cc.

752  {
753  for (int i = 0; i < memory_allocation_callbacks_.length(); ++i) {
754  MemoryAllocationCallbackRegistration registration =
756  if ((registration.space & space) == space &&
757  (registration.action & action) == action)
758  registration.callback(space, action, static_cast<int>(size));
759  }
760 }

References v8::internal::MemoryAllocator::MemoryAllocationCallbackRegistration::action, v8::internal::MemoryAllocator::MemoryAllocationCallbackRegistration::callback, memory_allocation_callbacks_, size, space(), and v8::internal::MemoryAllocator::MemoryAllocationCallbackRegistration::space.

Referenced by AllocateChunk(), Free(), and v8::internal::LargeObjectSpace::TearDown().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ RemoveMemoryAllocationCallback()

void v8::internal::MemoryAllocator::RemoveMemoryAllocationCallback ( MemoryAllocationCallback  callback)

Definition at line 782 of file spaces.cc.

783  {
784  DCHECK(callback != NULL);
785  for (int i = 0; i < memory_allocation_callbacks_.length(); ++i) {
786  if (memory_allocation_callbacks_[i].callback == callback) {
788  return;
789  }
790  }
791  UNREACHABLE();
792 }
#define UNREACHABLE()
Definition: logging.h:30

References DCHECK, memory_allocation_callbacks_, NULL, and UNREACHABLE.

Referenced by v8::V8::RemoveMemoryAllocationCallback().

+ Here is the caller graph for this function:

◆ ReserveAlignedMemory()

Address v8::internal::MemoryAllocator::ReserveAlignedMemory ( size_t  requested,
size_t  alignment,
base::VirtualMemory controller 
)

Definition at line 345 of file spaces.cc.

346  {
347  base::VirtualMemory reservation(size, alignment);
348 
349  if (!reservation.IsReserved()) return NULL;
350  size_ += reservation.size();
351  Address base =
352  RoundUp(static_cast<Address>(reservation.address()), alignment);
353  controller->TakeControl(&reservation);
354  return base;
355 }

References v8::base::VirtualMemory::address(), v8::base::VirtualMemory::IsReserved(), NULL, v8::internal::RoundUp(), v8::base::VirtualMemory::size(), size, size_, and v8::base::VirtualMemory::TakeControl().

Referenced by AllocateAlignedMemory(), and v8::internal::NewSpace::SetUp().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SetUp()

bool v8::internal::MemoryAllocator::SetUp ( intptr_t  max_capacity,
intptr_t  capacity_executable 
)

Definition at line 262 of file spaces.cc.

262  {
263  capacity_ = RoundUp(capacity, Page::kPageSize);
264  capacity_executable_ = RoundUp(capacity_executable, Page::kPageSize);
266 
267  size_ = 0;
268  size_executable_ = 0;
269 
270  return true;
271 }
#define DCHECK_GE(v1, v2)
Definition: logging.h:208

References capacity_, capacity_executable_, DCHECK_GE, v8::internal::Page::kPageSize, v8::internal::RoundUp(), size_, and size_executable_.

Referenced by v8::internal::Heap::SetUp().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Size()

intptr_t v8::internal::MemoryAllocator::Size ( )
inline

Definition at line 1023 of file spaces.h.

1023 { return size_; }

References size_.

Referenced by v8::internal::StatisticsExtension::GetCounters(), v8::internal::Heap::PrintShortHeapStatistics(), v8::internal::Heap::RecordStats(), v8::internal::GCTracer::Start(), and v8::internal::GCTracer::Stop().

+ Here is the caller graph for this function:

◆ SizeExecutable()

intptr_t v8::internal::MemoryAllocator::SizeExecutable ( )
inline

Definition at line 1032 of file spaces.h.

1032 { return size_executable_; }

References size_executable_.

Referenced by v8::internal::RegExpCompiler::Assemble(), and v8::internal::Heap::CommittedMemoryExecutable().

+ Here is the caller graph for this function:

◆ TearDown()

void v8::internal::MemoryAllocator::TearDown ( )

Definition at line 274 of file spaces.cc.

274  {
275  // Check that spaces were torn down before MemoryAllocator.
276  DCHECK(size_ == 0);
277  // TODO(gc) this will be true again when we fix FreeMemory.
278  // DCHECK(size_executable_ == 0);
279  capacity_ = 0;
281 }

References capacity_, capacity_executable_, DCHECK, and size_.

Referenced by v8::internal::Heap::TearDown().

+ Here is the caller graph for this function:

◆ UncommitBlock()

bool v8::internal::MemoryAllocator::UncommitBlock ( Address  start,
size_t  size 
)

Definition at line 736 of file spaces.cc.

736  {
737  if (!base::VirtualMemory::UncommitRegion(start, size)) return false;
738  isolate_->counters()->memory_allocated()->Decrement(static_cast<int>(size));
739  return true;
740 }
static bool UncommitRegion(void *base, size_t size)

References v8::internal::Isolate::counters(), isolate_, size, and v8::base::VirtualMemory::UncommitRegion().

Referenced by v8::internal::SemiSpace::ShrinkTo().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ UpdateAllocatedSpaceLimits()

void v8::internal::MemoryAllocator::UpdateAllocatedSpaceLimits ( void *  low,
void *  high 
)
inlineprivate

Definition at line 1152 of file spaces.h.

1152  {
1155  }
static LifetimePosition Min(LifetimePosition a, LifetimePosition b)
static LifetimePosition Max(LifetimePosition a, LifetimePosition b)

References highest_ever_allocated_, lowest_ever_allocated_, v8::internal::Max(), and v8::internal::Min().

Referenced by AllocateAlignedMemory(), CommitExecutableMemory(), and CommitMemory().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ZapBlock()

void v8::internal::MemoryAllocator::ZapBlock ( Address  start,
size_t  size 
)

Definition at line 743 of file spaces.cc.

743  {
744  for (size_t s = 0; s + kPointerSize <= size; s += kPointerSize) {
745  Memory::Address_at(start + s) = kZapValue;
746  }
747 }
static Address & Address_at(Address addr)
Definition: v8memory.h:56
const int kPointerSize
Definition: globals.h:129
const Address kZapValue
Definition: globals.h:269

References v8::internal::Memory::Address_at(), v8::internal::kPointerSize, v8::internal::kZapValue, and size.

Referenced by AllocateChunk(), v8::internal::MemoryChunk::CommitArea(), and CommitBlock().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ capacity_

size_t v8::internal::MemoryAllocator::capacity_
private

Definition at line 1115 of file spaces.h.

Referenced by Available(), SetUp(), and TearDown().

◆ capacity_executable_

size_t v8::internal::MemoryAllocator::capacity_executable_
private

Definition at line 1117 of file spaces.h.

Referenced by AllocateChunk(), AvailableExecutable(), SetUp(), and TearDown().

◆ highest_ever_allocated_

void* v8::internal::MemoryAllocator::highest_ever_allocated_
private

Definition at line 1130 of file spaces.h.

Referenced by IsOutsideAllocatedSpace(), and UpdateAllocatedSpaceLimits().

◆ isolate_

Isolate* v8::internal::MemoryAllocator::isolate_
private

◆ lowest_ever_allocated_

void* v8::internal::MemoryAllocator::lowest_ever_allocated_
private

Definition at line 1129 of file spaces.h.

Referenced by IsOutsideAllocatedSpace(), and UpdateAllocatedSpaceLimits().

◆ memory_allocation_callbacks_

List<MemoryAllocationCallbackRegistration> v8::internal::MemoryAllocator::memory_allocation_callbacks_
private

◆ size_

size_t v8::internal::MemoryAllocator::size_
private

◆ size_executable_

size_t v8::internal::MemoryAllocator::size_executable_
private

Definition at line 1122 of file spaces.h.

Referenced by AllocateChunk(), AvailableExecutable(), FreeMemory(), SetUp(), and SizeExecutable().


The documentation for this class was generated from the following files: