| 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 interpreter. | 19 // A helper class for constructing constant arrays for the |
| 20 class ConstantArrayBuilder final : public ZoneObject { | 20 // interpreter. Each instance of this class is intended to be used to |
| 21 // generate exactly one FixedArray of constants via the ToFixedArray |
| 22 // method. |
| 23 class ConstantArrayBuilder final BASE_EMBEDDED { |
| 21 public: | 24 public: |
| 22 // Capacity of the 8-bit operand slice. | 25 // Capacity of the 8-bit operand slice. |
| 23 static const size_t kLowCapacity = 1u << kBitsPerByte; | 26 static const size_t kLowCapacity = 1u << kBitsPerByte; |
| 24 | 27 |
| 25 // Capacity of the combined 8-bit and 16-bit operand slices. | 28 // Capacity of the combined 8-bit and 16-bit operand slices. |
| 26 static const size_t kMaxCapacity = 1u << (2 * kBitsPerByte); | 29 static const size_t kMaxCapacity = 1u << (2 * kBitsPerByte); |
| 27 | 30 |
| 28 // Capacity of the 16-bit operand slice. | 31 // Capacity of the 16-bit operand slice. |
| 29 static const size_t kHighCapacity = kMaxCapacity - kLowCapacity; | 32 static const size_t kHighCapacity = kMaxCapacity - kLowCapacity; |
| 30 | 33 |
| 31 ConstantArrayBuilder(Isolate* isolate, Zone* zone); | 34 ConstantArrayBuilder(Isolate* isolate, Zone* zone); |
| 32 | 35 |
| 33 // Generate a fixed array of constants based on inserted objects. | 36 // Generate a fixed array of constants based on inserted objects. |
| 34 Handle<FixedArray> ToFixedArray() const; | 37 Handle<FixedArray> ToFixedArray(); |
| 35 | 38 |
| 36 // Returns the object in the constant pool array that at index | 39 // Returns the object in the constant pool array that at index |
| 37 // |index|. | 40 // |index|. |
| 38 Handle<Object> At(size_t index) const; | 41 Handle<Object> At(size_t index) const; |
| 39 | 42 |
| 40 // Returns the number of elements in the array. | 43 // Returns the number of elements in the array. |
| 41 size_t size() const; | 44 size_t size() const; |
| 42 | 45 |
| 43 // Insert an object into the constants array if it is not already | 46 // Insert an object into the constants array if it is not already |
| 44 // present. Returns the array index associated with the object. | 47 // present. Returns the array index associated with the object. |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 | 79 |
| 77 private: | 80 private: |
| 78 const size_t start_index_; | 81 const size_t start_index_; |
| 79 const size_t capacity_; | 82 const size_t capacity_; |
| 80 size_t reserved_; | 83 size_t reserved_; |
| 81 ZoneVector<Handle<Object>> constants_; | 84 ZoneVector<Handle<Object>> constants_; |
| 82 | 85 |
| 83 DISALLOW_COPY_AND_ASSIGN(ConstantArraySlice); | 86 DISALLOW_COPY_AND_ASSIGN(ConstantArraySlice); |
| 84 }; | 87 }; |
| 85 | 88 |
| 89 IdentityMap<index_t>* constants_map() { return &constants_map_; } |
| 90 |
| 86 Isolate* isolate_; | 91 Isolate* isolate_; |
| 87 ConstantArraySlice idx8_slice_; | 92 ConstantArraySlice idx8_slice_; |
| 88 ConstantArraySlice idx16_slice_; | 93 ConstantArraySlice idx16_slice_; |
| 89 IdentityMap<index_t> constants_map_; | 94 IdentityMap<index_t> constants_map_; |
| 90 }; | 95 }; |
| 91 | 96 |
| 92 } // namespace interpreter | 97 } // namespace interpreter |
| 93 } // namespace internal | 98 } // namespace internal |
| 94 } // namespace v8 | 99 } // namespace v8 |
| 95 | 100 |
| 96 #endif // V8_INTERPRETER_CONSTANT_ARRAY_BUILDER_H_ | 101 #endif // V8_INTERPRETER_CONSTANT_ARRAY_BUILDER_H_ |
| OLD | NEW |