| 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" |
| 11 | 11 |
| 12 namespace v8 { | 12 namespace v8 { |
| 13 namespace internal { | 13 namespace internal { |
| 14 | 14 |
| 15 class Isolate; | 15 class Isolate; |
| 16 | 16 |
| 17 namespace interpreter { | 17 namespace interpreter { |
| 18 | 18 |
| 19 // A helper class for constructing constant arrays for the | 19 // A helper class for constructing constant arrays for the |
| 20 // interpreter. Each instance of this class is intended to be used to | 20 // interpreter. Each instance of this class is intended to be used to |
| 21 // generate exactly one FixedArray of constants via the ToFixedArray | 21 // generate exactly one FixedArray of constants via the ToFixedArray |
| 22 // method. | 22 // method. |
| 23 class ConstantArrayBuilder final BASE_EMBEDDED { | 23 class ConstantArrayBuilder final BASE_EMBEDDED { |
| 24 public: | 24 public: |
| 25 // Capacity of the 8-bit operand slice. | 25 // Capacity of the 8-bit operand slice. |
| 26 static const size_t kLowCapacity = 1u << kBitsPerByte; | 26 static const size_t k8BitCapacity = 1u << kBitsPerByte; |
| 27 | |
| 28 // Capacity of the combined 8-bit and 16-bit operand slices. | |
| 29 static const size_t kMaxCapacity = 1u << (2 * kBitsPerByte); | |
| 30 | 27 |
| 31 // Capacity of the 16-bit operand slice. | 28 // Capacity of the 16-bit operand slice. |
| 32 static const size_t kHighCapacity = kMaxCapacity - kLowCapacity; | 29 static const size_t k16BitCapacity = (1u << 2 * kBitsPerByte) - k8BitCapacity; |
| 30 |
| 31 // Capacity of the 32-bit operand slice. |
| 32 static const size_t k32BitCapacity = |
| 33 kMaxUInt32 - k16BitCapacity - k8BitCapacity + 1; |
| 33 | 34 |
| 34 ConstantArrayBuilder(Isolate* isolate, Zone* zone); | 35 ConstantArrayBuilder(Isolate* isolate, Zone* zone); |
| 35 | 36 |
| 36 // Generate a fixed array of constants based on inserted objects. | 37 // Generate a fixed array of constants based on inserted objects. |
| 37 Handle<FixedArray> ToFixedArray(); | 38 Handle<FixedArray> ToFixedArray(); |
| 38 | 39 |
| 39 // Returns the object in the constant pool array that at index | 40 // Returns the object in the constant pool array that at index |
| 40 // |index|. | 41 // |index|. |
| 41 Handle<Object> At(size_t index) const; | 42 Handle<Object> At(size_t index) const; |
| 42 | 43 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 53 OperandSize CreateReservedEntry(); | 54 OperandSize CreateReservedEntry(); |
| 54 | 55 |
| 55 // Commit reserved entry and returns the constant pool index for the | 56 // Commit reserved entry and returns the constant pool index for the |
| 56 // object. | 57 // object. |
| 57 size_t CommitReservedEntry(OperandSize operand_size, Handle<Object> object); | 58 size_t CommitReservedEntry(OperandSize operand_size, Handle<Object> object); |
| 58 | 59 |
| 59 // Discards constant pool reservation. | 60 // Discards constant pool reservation. |
| 60 void DiscardReservedEntry(OperandSize operand_size); | 61 void DiscardReservedEntry(OperandSize operand_size); |
| 61 | 62 |
| 62 private: | 63 private: |
| 63 typedef uint16_t index_t; | 64 typedef uint32_t index_t; |
| 64 | 65 |
| 65 index_t AllocateEntry(Handle<Object> object); | 66 index_t AllocateEntry(Handle<Object> object); |
| 66 | 67 |
| 67 struct ConstantArraySlice final { | 68 struct ConstantArraySlice final : public ZoneObject { |
| 68 ConstantArraySlice(Zone* zone, size_t start_index, size_t capacity); | 69 ConstantArraySlice(Zone* zone, size_t start_index, size_t capacity, |
| 70 OperandSize operand_size); |
| 69 void Reserve(); | 71 void Reserve(); |
| 70 void Unreserve(); | 72 void Unreserve(); |
| 71 size_t Allocate(Handle<Object> object); | 73 size_t Allocate(Handle<Object> object); |
| 72 Handle<Object> At(size_t index) const; | 74 Handle<Object> At(size_t index) const; |
| 73 | 75 |
| 74 inline size_t available() const { return capacity() - reserved() - size(); } | 76 inline size_t available() const { return capacity() - reserved() - size(); } |
| 75 inline size_t reserved() const { return reserved_; } | 77 inline size_t reserved() const { return reserved_; } |
| 76 inline size_t capacity() const { return capacity_; } | 78 inline size_t capacity() const { return capacity_; } |
| 77 inline size_t size() const { return constants_.size(); } | 79 inline size_t size() const { return constants_.size(); } |
| 78 inline size_t start_index() const { return start_index_; } | 80 inline size_t start_index() const { return start_index_; } |
| 81 inline size_t max_index() const { return start_index_ + capacity() - 1; } |
| 82 inline OperandSize operand_size() const { return operand_size_; } |
| 79 | 83 |
| 80 private: | 84 private: |
| 81 const size_t start_index_; | 85 const size_t start_index_; |
| 82 const size_t capacity_; | 86 const size_t capacity_; |
| 83 size_t reserved_; | 87 size_t reserved_; |
| 88 OperandSize operand_size_; |
| 84 ZoneVector<Handle<Object>> constants_; | 89 ZoneVector<Handle<Object>> constants_; |
| 85 | 90 |
| 86 DISALLOW_COPY_AND_ASSIGN(ConstantArraySlice); | 91 DISALLOW_COPY_AND_ASSIGN(ConstantArraySlice); |
| 87 }; | 92 }; |
| 88 | 93 |
| 94 const ConstantArraySlice* IndexToSlice(size_t index) const; |
| 95 ConstantArraySlice* OperandSizeToSlice(OperandSize operand_size) const; |
| 96 |
| 89 IdentityMap<index_t>* constants_map() { return &constants_map_; } | 97 IdentityMap<index_t>* constants_map() { return &constants_map_; } |
| 90 | 98 |
| 91 Isolate* isolate_; | 99 Isolate* isolate_; |
| 92 ConstantArraySlice idx8_slice_; | 100 ConstantArraySlice* idx_slice_[2]; |
| 93 ConstantArraySlice idx16_slice_; | |
| 94 IdentityMap<index_t> constants_map_; | 101 IdentityMap<index_t> constants_map_; |
| 95 }; | 102 }; |
| 96 | 103 |
| 97 } // namespace interpreter | 104 } // namespace interpreter |
| 98 } // namespace internal | 105 } // namespace internal |
| 99 } // namespace v8 | 106 } // namespace v8 |
| 100 | 107 |
| 101 #endif // V8_INTERPRETER_CONSTANT_ARRAY_BUILDER_H_ | 108 #endif // V8_INTERPRETER_CONSTANT_ARRAY_BUILDER_H_ |
| OLD | NEW |