Chromium Code Reviews| Index: src/interpreter/constant-array-builder.h | 
| diff --git a/src/interpreter/constant-array-builder.h b/src/interpreter/constant-array-builder.h | 
| new file mode 100644 | 
| index 0000000000000000000000000000000000000000..3213b235966cfa60df420cb7f2437ca7a44b27e2 | 
| --- /dev/null | 
| +++ b/src/interpreter/constant-array-builder.h | 
| @@ -0,0 +1,97 @@ | 
| +// Copyright 2015 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. | 
| + | 
| +#ifndef V8_INTERPRETER_CONSTANT_ARRAY_BUILDER_H_ | 
| +#define V8_INTERPRETER_CONSTANT_ARRAY_BUILDER_H_ | 
| + | 
| +#include "src/identity-map.h" | 
| +#include "src/interpreter/bytecodes.h" | 
| +#include "src/zone-containers.h" | 
| + | 
| +namespace v8 { | 
| +namespace internal { | 
| + | 
| +class Factory; | 
| +class Isolate; | 
| + | 
| +namespace interpreter { | 
| + | 
| +// A helper class for constructing constant arrays for the interpreter. | 
| +class ConstantArrayBuilder final : public ZoneObject { | 
| + public: | 
| + // Capacity of the 8-bit operand slice. | 
| + static const size_t kLowCapacity = 1u << kBitsPerByte; | 
| + | 
| + // Capacity of the combined 8-bit and 16-bit operand slices. | 
| + static const size_t kMaxCapacity = 1u << (2 * kBitsPerByte); | 
| + | 
| + // Capacity of the 16-bit operand slice. | 
| + static const size_t kHighCapacity = kMaxCapacity - kLowCapacity; | 
| + | 
| + ConstantArrayBuilder(Isolate* isolate, Zone* zone); | 
| + | 
| + // Generate a fixed array of constants based on inserted objects. | 
| + Handle<FixedArray> ToFixedArray(Factory* factory) const; | 
| + | 
| + // Returns the object in the constant pool array that at index | 
| + // |index|. | 
| + Handle<Object> At(size_t index) const; | 
| + | 
| + // Returns the number of elements in the array. | 
| + size_t size() const; | 
| + | 
| + // Insert an object into the constants array if it is not already | 
| + // present. Returns the array index associated with the object. | 
| + size_t Insert(Handle<Object> object); | 
| + | 
| + // Creates a reserved entry in the constant pool and returns | 
| + // the size of the operand that'll be required to hold the entry | 
| + // when committed. | 
| + OperandSize CreateReservedEntry(); | 
| + | 
| + // Commit reserved entry and returns the constant pool index for the | 
| + // object. | 
| + size_t CommitReservedEntry(OperandSize operand_size, Handle<Object> object); | 
| + | 
| + // Discards constant pool reservation. | 
| + void DiscardReservedEntry(OperandSize operand_size); | 
| + | 
| + private: | 
| + typedef uint16_t index_t; | 
| + | 
| + index_t AllocateEntry(Handle<Object> object); | 
| + | 
| + struct ConstantArraySlice final { | 
| + ConstantArraySlice(Zone* zone, size_t start_index, size_t capacity); | 
| + | 
| + size_t available() const; | 
| + size_t reserved() const; | 
| + size_t capacity() const; | 
| + size_t size() const; | 
| + size_t start_index() const; | 
| 
 
rmcilroy
2016/01/05 13:46:10
nit - accessors are usually below the other functi
 
oth
2016/01/05 18:31:59
Done.
 
 | 
| + void Reserve(); | 
| + void Unreserve(); | 
| + size_t Allocate(Handle<Object> object); | 
| + Handle<Object> At(size_t index) const; | 
| + | 
| + private: | 
| + const size_t start_index_; | 
| + const size_t capacity_; | 
| + size_t reserved_; | 
| + ZoneVector<Handle<Object>> constants_; | 
| + | 
| + DISALLOW_COPY_AND_ASSIGN(ConstantArraySlice); | 
| + }; | 
| + | 
| + Isolate* isolate_; | 
| + ConstantArraySlice idx8_slice_; | 
| + ConstantArraySlice idx16_slice_; | 
| + IdentityMap<index_t> constants_map_; | 
| +}; | 
| + | 
| +} // namespace interpreter | 
| +} // namespace internal | 
| +} // namespace v8 | 
| + | 
| +#endif // V8_INTERPRETER_CONSTANT_ARRAY_BUILDER_H_ |