OLD | NEW |
---|---|
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_INTERPRETER_CONSTANT_ARRAY_BUILDER_H_ | 5 #ifndef V8_INTERPRETER_CONSTANT_ARRAY_BUILDER_H_ |
6 #define V8_INTERPRETER_CONSTANT_ARRAY_BUILDER_H_ | 6 #define V8_INTERPRETER_CONSTANT_ARRAY_BUILDER_H_ |
7 | 7 |
8 #include "src/identity-map.h" | 8 #include "src/identity-map.h" |
9 #include "src/interpreter/bytecodes.h" | 9 #include "src/interpreter/bytecodes.h" |
10 #include "src/zone-containers.h" | 10 #include "src/zone-containers.h" |
(...skipping 30 matching lines...) Expand all Loading... | |
41 // |index|. | 41 // |index|. |
42 Handle<Object> At(size_t index) const; | 42 Handle<Object> At(size_t index) const; |
43 | 43 |
44 // Returns the number of elements in the array. | 44 // Returns the number of elements in the array. |
45 size_t size() const; | 45 size_t size() const; |
46 | 46 |
47 // Insert an object into the constants array if it is not already | 47 // Insert an object into the constants array if it is not already |
48 // present. Returns the array index associated with the object. | 48 // present. Returns the array index associated with the object. |
49 size_t Insert(Handle<Object> object); | 49 size_t Insert(Handle<Object> object); |
50 | 50 |
51 // Reserves a entry which cannot later be discarded, and returns the array | |
52 // index associated with the reservation. | |
53 size_t ReserveEntry(); | |
54 | |
55 // Commits an undiscardable reserved entry and updates the entry with the | |
56 // given object. | |
57 void InsertReservedEntry(size_t index, Handle<Object> object); | |
58 | |
51 // Creates a reserved entry in the constant pool and returns | 59 // Creates a reserved entry in the constant pool and returns |
52 // the size of the operand that'll be required to hold the entry | 60 // the size of the operand that'll be required to hold the entry |
53 // when committed. | 61 // when committed. |
54 OperandSize CreateReservedEntry(); | 62 OperandSize CreateDiscardableReservedEntry(); |
oth
2016/07/22 10:22:10
The names here used to align to give a hint that i
rmcilroy
2016/07/25 10:55:29
SGTM (/s/BindAllocatedEntry/InsertAllocatedEntry).
| |
55 | 63 |
56 // Commit reserved entry and returns the constant pool index for the | 64 // Commit reserved entry and returns the constant pool index for the |
57 // object. | 65 // object. |
58 size_t CommitReservedEntry(OperandSize operand_size, Handle<Object> object); | 66 size_t CommitReservedEntry(OperandSize operand_size, Handle<Object> object); |
59 | 67 |
60 // Discards constant pool reservation. | 68 // Discards constant pool reservation. |
61 void DiscardReservedEntry(OperandSize operand_size); | 69 void DiscardReservedEntry(OperandSize operand_size); |
62 | 70 |
63 private: | 71 private: |
64 typedef uint32_t index_t; | 72 typedef uint32_t index_t; |
65 | 73 |
66 index_t AllocateEntry(Handle<Object> object); | 74 index_t AllocateEntry(Handle<Object> object); |
75 index_t AllocateIndex(Handle<Object> object); | |
67 | 76 |
68 struct ConstantArraySlice final : public ZoneObject { | 77 struct ConstantArraySlice final : public ZoneObject { |
69 ConstantArraySlice(Zone* zone, size_t start_index, size_t capacity, | 78 ConstantArraySlice(Zone* zone, size_t start_index, size_t capacity, |
70 OperandSize operand_size); | 79 OperandSize operand_size); |
71 void Reserve(); | 80 void Reserve(); |
72 void Unreserve(); | 81 void Unreserve(); |
73 size_t Allocate(Handle<Object> object); | 82 size_t Allocate(Handle<Object> object); |
74 Handle<Object> At(size_t index) const; | 83 Handle<Object> At(size_t index) const; |
84 void Update(size_t index, Handle<Object> object); | |
75 | 85 |
76 inline size_t available() const { return capacity() - reserved() - size(); } | 86 inline size_t available() const { return capacity() - reserved() - size(); } |
77 inline size_t reserved() const { return reserved_; } | 87 inline size_t reserved() const { return reserved_; } |
78 inline size_t capacity() const { return capacity_; } | 88 inline size_t capacity() const { return capacity_; } |
79 inline size_t size() const { return constants_.size(); } | 89 inline size_t size() const { return constants_.size(); } |
80 inline size_t start_index() const { return start_index_; } | 90 inline size_t start_index() const { return start_index_; } |
81 inline size_t max_index() const { return start_index_ + capacity() - 1; } | 91 inline size_t max_index() const { return start_index_ + capacity() - 1; } |
82 inline OperandSize operand_size() const { return operand_size_; } | 92 inline OperandSize operand_size() const { return operand_size_; } |
83 | 93 |
84 private: | 94 private: |
85 const size_t start_index_; | 95 const size_t start_index_; |
86 const size_t capacity_; | 96 const size_t capacity_; |
87 size_t reserved_; | 97 size_t reserved_; |
88 OperandSize operand_size_; | 98 OperandSize operand_size_; |
89 ZoneVector<Handle<Object>> constants_; | 99 ZoneVector<Handle<Object>> constants_; |
90 | 100 |
91 DISALLOW_COPY_AND_ASSIGN(ConstantArraySlice); | 101 DISALLOW_COPY_AND_ASSIGN(ConstantArraySlice); |
92 }; | 102 }; |
93 | 103 |
94 const ConstantArraySlice* IndexToSlice(size_t index) const; | 104 ConstantArraySlice* IndexToSlice(size_t index) const; |
95 ConstantArraySlice* OperandSizeToSlice(OperandSize operand_size) const; | 105 ConstantArraySlice* OperandSizeToSlice(OperandSize operand_size) const; |
96 | 106 |
97 IdentityMap<index_t>* constants_map() { return &constants_map_; } | 107 IdentityMap<index_t>* constants_map() { return &constants_map_; } |
98 | 108 |
99 Isolate* isolate_; | 109 Isolate* isolate_; |
100 ConstantArraySlice* idx_slice_[3]; | 110 ConstantArraySlice* idx_slice_[3]; |
101 IdentityMap<index_t> constants_map_; | 111 IdentityMap<index_t> constants_map_; |
102 }; | 112 }; |
103 | 113 |
104 } // namespace interpreter | 114 } // namespace interpreter |
105 } // namespace internal | 115 } // namespace internal |
106 } // namespace v8 | 116 } // namespace v8 |
107 | 117 |
108 #endif // V8_INTERPRETER_CONSTANT_ARRAY_BUILDER_H_ | 118 #endif // V8_INTERPRETER_CONSTANT_ARRAY_BUILDER_H_ |
OLD | NEW |