Welcome to mirror list, hosted at ThFree Co, Russian Federation.

heap-inl.h « cppgc « heap « src « v8 « deps - github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 28a4a14139ea99c8db32cb75038e1be5d3952365 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Copyright 2020 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "src/heap/cppgc/heap.h"

#include "src/heap/cppgc/globals.h"
#include "src/heap/cppgc/heap-object-header-inl.h"

#ifndef V8_HEAP_CPPGC_HEAP_INL_H_
#define V8_HEAP_CPPGC_HEAP_INL_H_

namespace cppgc {
namespace internal {

void* Heap::Allocate(size_t size, GCInfoIndex index) {
  // TODO(chromium:1056170): This is merely a dummy implementation and will be
  // replaced with proper allocation code throughout the migration.
  size_t allocation_size = size + sizeof(HeapObjectHeader);
  // The allocation size calculation can overflow for large sizes.
  CHECK_GT(allocation_size, size);
  // calloc() provides stricter alignment guarantees than the GC. Allocate
  // a multiple of kAllocationGranularity to follow restrictions of
  // HeapObjectHeader.
  allocation_size = (allocation_size + kAllocationMask) & ~kAllocationMask;
  void* memory = calloc(1, allocation_size);
  HeapObjectHeader* header =
      new (memory) HeapObjectHeader(allocation_size, index);
  objects_.push_back(header);
  return header->Payload();
}

}  // namespace internal
}  // namespace cppgc

#endif  // V8_HEAP_CPPGC_HEAP_INL_H_