• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2018 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef V8_BUILTINS_CONSTANTS_TABLE_BUILDER_H_
6 #define V8_BUILTINS_CONSTANTS_TABLE_BUILDER_H_
7 
8 #include "src/base/macros.h"
9 #include "src/utils/allocation.h"
10 #include "src/utils/identity-map.h"
11 #include "src/handles/handles.h"
12 
13 namespace v8 {
14 namespace internal {
15 
16 class Isolate;
17 class Object;
18 
19 // Utility class to build the builtins constants table and store it on the root
20 // list. The constants table contains constants used by builtins, and is there
21 // to avoid directly embedding them into code objects, which would not be
22 // possible for off-heap (and thus immutable) code objects.
23 class BuiltinsConstantsTableBuilder final {
24  public:
25   explicit BuiltinsConstantsTableBuilder(Isolate* isolate);
26 
27   // Returns the index within the builtins constants table for the given
28   // object, possibly adding the object to the table. Objects are deduplicated.
29   uint32_t AddObject(Handle<Object> object);
30 
31   // Self-references during code generation start out by referencing a handle
32   // with a temporary dummy object. Once the final Code object exists, such
33   // entries in the constants map must be patched up.
34   void PatchSelfReference(Handle<Object> self_reference,
35                           Handle<Code> code_object);
36 
37   // References to the array that stores basic block usage counters start out as
38   // references to a unique oddball. Once the actual array has been allocated,
39   // such entries in the constants map must be patched up.
40   void PatchBasicBlockCountersReference(Handle<ByteArray> counters);
41 
42   // Should be called after all affected code (e.g. builtins and bytecode
43   // handlers) has been generated.
44   void Finalize();
45 
46  private:
47   Isolate* isolate_;
48 
49   // Maps objects to corresponding indices within the constants list.
50   using ConstantsMap = IdentityMap<uint32_t, FreeStoreAllocationPolicy>;
51   ConstantsMap map_;
52 
53   DISALLOW_COPY_AND_ASSIGN(BuiltinsConstantsTableBuilder);
54 };
55 
56 }  // namespace internal
57 }  // namespace v8
58 
59 #endif  // V8_BUILTINS_CONSTANTS_TABLE_BUILDER_H_
60