• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2017 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "src/snapshot/builtin-serializer-allocator.h"
6 
7 #include "src/heap/heap-inl.h"
8 
9 namespace v8 {
10 namespace internal {
11 
Allocate(AllocationSpace space,uint32_t size)12 SerializerReference BuiltinSerializerAllocator::Allocate(AllocationSpace space,
13                                                          uint32_t size) {
14   DCHECK_EQ(space, CODE_SPACE);
15   DCHECK_GT(size, 0);
16 
17   // Builtin serialization & deserialization does not use the reservation
18   // system.  Instead of worrying about chunk indices and offsets, we simply
19   // need to generate unique offsets here.
20 
21   const auto ref =
22       SerializerReference::BuiltinReference(next_builtin_reference_index_);
23 
24   allocated_bytes_ += size;
25   next_builtin_reference_index_++;
26 
27   return ref;
28 }
29 
30 #ifdef DEBUG
BackReferenceIsAlreadyAllocated(SerializerReference reference) const31 bool BuiltinSerializerAllocator::BackReferenceIsAlreadyAllocated(
32     SerializerReference reference) const {
33   DCHECK(reference.is_builtin_reference());
34   return reference.builtin_index() < next_builtin_reference_index_;
35 }
36 #endif  // DEBUG
37 
38 std::vector<SerializedData::Reservation>
EncodeReservations() const39 BuiltinSerializerAllocator::EncodeReservations() const {
40   return std::vector<SerializedData::Reservation>();
41 }
42 
OutputStatistics()43 void BuiltinSerializerAllocator::OutputStatistics() {
44   DCHECK(FLAG_serialization_statistics);
45 
46   PrintF("  Spaces (bytes):\n");
47 
48   for (int space = FIRST_SPACE; space < kNumberOfSpaces; space++) {
49     PrintF("%16s", AllocationSpaceName(static_cast<AllocationSpace>(space)));
50   }
51   PrintF("\n");
52 
53   for (int space = FIRST_SPACE; space < kNumberOfSpaces; space++) {
54     uint32_t space_size = (space == CODE_SPACE) ? allocated_bytes_ : 0;
55     PrintF("%16d", space_size);
56   }
57   PrintF("\n");
58 }
59 
60 }  // namespace internal
61 }  // namespace v8
62