• 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_OBJECTS_PROTOTYPE_INFO_H_
6 #define V8_OBJECTS_PROTOTYPE_INFO_H_
7 
8 #include "src/objects/fixed-array.h"
9 #include "src/objects/objects.h"
10 #include "src/objects/struct.h"
11 #include "torque-generated/bit-fields.h"
12 
13 // Has to be the last include (doesn't have include guards):
14 #include "src/objects/object-macros.h"
15 
16 namespace v8 {
17 namespace internal {
18 
19 #include "torque-generated/src/objects/prototype-info-tq.inc"
20 
21 // Container for metadata stored on each prototype map.
22 class PrototypeInfo
23     : public TorqueGeneratedPrototypeInfo<PrototypeInfo, Struct> {
24  public:
25   static const int UNREGISTERED = -1;
26 
27   // [object_create_map]: A field caching the map for Object.create(prototype).
28   DECL_GETTER(object_create_map, MaybeObject)
29   DECL_RELEASE_ACQUIRE_WEAK_ACCESSORS(object_create_map)
30 
31   static inline void SetObjectCreateMap(Handle<PrototypeInfo> info,
32                                         Handle<Map> map);
33   inline Map ObjectCreateMap();
34   inline bool HasObjectCreateMap();
35 
36   DECL_BOOLEAN_ACCESSORS(should_be_fast_map)
37 
38   // Dispatched behavior.
39   DECL_PRINTER(PrototypeInfo)
40   DECL_VERIFIER(PrototypeInfo)
41 
42   // Bit field usage.
43   DEFINE_TORQUE_GENERATED_PROTOTYPE_INFO_FLAGS()
44 
45   class BodyDescriptor;
46 
47   TQ_OBJECT_CONSTRUCTORS(PrototypeInfo)
48 };
49 
50 // A growing array with an additional API for marking slots "empty". When adding
51 // new elements, we reuse the empty slots instead of growing the array.
52 class V8_EXPORT_PRIVATE PrototypeUsers : public WeakArrayList {
53  public:
54   static Handle<WeakArrayList> Add(Isolate* isolate,
55                                    Handle<WeakArrayList> array,
56                                    Handle<Map> value, int* assigned_index);
57 
58   static inline void MarkSlotEmpty(WeakArrayList array, int index);
59 
60   // The callback is called when a weak pointer to HeapObject "object" is moved
61   // from index "from_index" to index "to_index" during compaction. The callback
62   // must not cause GC.
63   using CompactionCallback = void (*)(HeapObject object, int from_index,
64                                       int to_index);
65   static WeakArrayList Compact(
66       Handle<WeakArrayList> array, Heap* heap, CompactionCallback callback,
67       AllocationType allocation = AllocationType::kYoung);
68 
69 #ifdef VERIFY_HEAP
70   static void Verify(WeakArrayList array);
71 #endif  // VERIFY_HEAP
72 
73   static const int kEmptySlotIndex = 0;
74   static const int kFirstIndex = 1;
75 
76   static const int kNoEmptySlotsMarker = 0;
77 
78  private:
79   static inline Smi empty_slot_index(WeakArrayList array);
80   static inline void set_empty_slot_index(WeakArrayList array, int index);
81 
82   static void ScanForEmptySlots(WeakArrayList array);
83 
84   DISALLOW_IMPLICIT_CONSTRUCTORS(PrototypeUsers);
85 };
86 
87 }  // namespace internal
88 }  // namespace v8
89 
90 #include "src/objects/object-macros-undef.h"
91 
92 #endif  // V8_OBJECTS_PROTOTYPE_INFO_H_
93