Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(168)

Unified Diff: src/interpreter/constant-array-builder.h

Issue 1546683002: [Interpreter] Add support for jumps using constants with wide operands. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rationalize jumps in bytecode-graph-builder.cc. Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..e106736fa9f2f0b3e39ccb15549f26b9f6e2b412
--- /dev/null
+++ b/src/interpreter/constant-array-builder.h
@@ -0,0 +1,84 @@
+// 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/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:
+ enum class ReservationToken : uint8_t { kIdx8, kIdx16 };
+ static const size_t kMaxCapacity = kMaxUInt16 + 1;
+ static const size_t kLowCapacity = kMaxUInt8 + 1;
+
+ ConstantArrayBuilder(Isolate* isolate, Zone* zone);
+
+ // Generate a fixed array of constants based on inserted objects.
+ Handle<FixedArray> ToFixedArray(Factory* factory,
+ PretenureFlag pretenure) const;
+
+ // Returns the object in the constant pool array that at index
+ // |index|.
+ Handle<Object> at(size_t index) const { return constants_[index]; }
+
+ // Returns the number of elements in the array.
+ size_t size() const { return constants_.size(); }
+
+ // 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 a
+ // token that can be subsequently committed or discarded.
+ ReservationToken CreateReservedEntry();
+
+ // Commit reserved entry and returns the constant pool index for the
+ // object.
+ size_t CommitReservedEntry(ReservationToken token, Handle<Object> object);
+
+ // Discards constant pool reservation.
+ void DiscardReservedEntry(ReservationToken token);
+
+ // Get the number of bytes required to hold the index for a
+ // reservation.
+ static size_t SizeOfReservedArrayIndex(ReservationToken token);
mythria 2015/12/24 15:53:44 I am not sure we use this function.
oth 2015/12/27 08:42:34 Thanks, removed.
+
+ private:
+ typedef uint16_t index_t;
+
+ Isolate* isolate() const { return isolate_; }
+ size_t allocated_and_reserved_low() const {
+ return static_cast<size_t>(allocated_low_ + reserved_low_);
+ }
+
+ index_t AllocateEntry(Handle<Object> object);
+ void EnsureCapacity(size_t minimum_pool_size);
+
+ Isolate* isolate_;
+ IdentityMap<index_t> constants_map_;
+ ZoneVector<Handle<Object>> constants_;
+ // Number of allocated entries with byte index operands
+ uint16_t allocated_low_;
+ // Number of reserved entries with byte index operands
+ uint16_t reserved_low_;
+ // Number of reserved entries with 2-byte index operands
+ uint16_t reserved_high_;
+};
+
+} // namespace interpreter
+} // namespace internal
+} // namespace v8
+
+#endif // V8_INTERPRETER_CONSTANT_ARRAY_BUILDER_H_

Powered by Google App Engine
This is Rietveld 408576698