constants-table-builder.h 2.23 KB
Newer Older
1 2 3 4 5 6 7 8
// Copyright 2018 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_BUILTINS_CONSTANTS_TABLE_BUILDER_H_
#define V8_BUILTINS_CONSTANTS_TABLE_BUILDER_H_

#include "src/base/macros.h"
9 10
#include "src/utils/allocation.h"
#include "src/utils/identity-map.h"
11
#include "src/handles/handles.h"
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26

namespace v8 {
namespace internal {

class Isolate;
class Object;

// Utility class to build the builtins constants table and store it on the root
// list. The constants table contains constants used by builtins, and is there
// to avoid directly embedding them into code objects, which would not be
// possible for off-heap (and thus immutable) code objects.
class BuiltinsConstantsTableBuilder final {
 public:
  explicit BuiltinsConstantsTableBuilder(Isolate* isolate);

27 28 29 30
  BuiltinsConstantsTableBuilder(const BuiltinsConstantsTableBuilder&) = delete;
  BuiltinsConstantsTableBuilder& operator=(
      const BuiltinsConstantsTableBuilder&) = delete;

31 32
  // Returns the index within the builtins constants table for the given
  // object, possibly adding the object to the table. Objects are deduplicated.
33 34
  uint32_t AddObject(Handle<Object> object);

35 36 37 38 39 40
  // Self-references during code generation start out by referencing a handle
  // with a temporary dummy object. Once the final Code object exists, such
  // entries in the constants map must be patched up.
  void PatchSelfReference(Handle<Object> self_reference,
                          Handle<Code> code_object);

41 42 43 44 45
  // References to the array that stores basic block usage counters start out as
  // references to a unique oddball. Once the actual array has been allocated,
  // such entries in the constants map must be patched up.
  void PatchBasicBlockCountersReference(Handle<ByteArray> counters);

46 47 48 49 50 51 52 53
  // Should be called after all affected code (e.g. builtins and bytecode
  // handlers) has been generated.
  void Finalize();

 private:
  Isolate* isolate_;

  // Maps objects to corresponding indices within the constants list.
54
  using ConstantsMap = IdentityMap<uint32_t, FreeStoreAllocationPolicy>;
55 56 57 58 59 60 61
  ConstantsMap map_;
};

}  // namespace internal
}  // namespace v8

#endif  // V8_BUILTINS_CONSTANTS_TABLE_BUILDER_H_