prototype-info.h 2.82 KB
Newer Older
1 2 3 4 5 6 7
// 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_OBJECTS_PROTOTYPE_INFO_H_
#define V8_OBJECTS_PROTOTYPE_INFO_H_

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 14 15 16 17 18

// Has to be the last include (doesn't have include guards):
#include "src/objects/object-macros.h"

namespace v8 {
namespace internal {

19 20
#include "torque-generated/src/objects/prototype-info-tq.inc"

21
// Container for metadata stored on each prototype map.
22 23
class PrototypeInfo
    : public TorqueGeneratedPrototypeInfo<PrototypeInfo, Struct> {
24 25 26 27 28 29
 public:
  static const int UNREGISTERED = -1;

  // [object_create_map]: A field caching the map for Object.create(prototype).
  static inline void SetObjectCreateMap(Handle<PrototypeInfo> info,
                                        Handle<Map> map);
30
  inline Map ObjectCreateMap();
31 32 33 34 35 36 37 38 39
  inline bool HasObjectCreateMap();

  DECL_BOOLEAN_ACCESSORS(should_be_fast_map)

  // Dispatched behavior.
  DECL_PRINTER(PrototypeInfo)
  DECL_VERIFIER(PrototypeInfo)

  // Bit field usage.
40
  DEFINE_TORQUE_GENERATED_PROTOTYPE_INFO_FLAGS()
41 42 43

  class BodyDescriptor;

44
  TQ_OBJECT_CONSTRUCTORS(PrototypeInfo)
45 46
};

47 48
// A growing array with an additional API for marking slots "empty". When adding
// new elements, we reuse the empty slots instead of growing the array.
49
class V8_EXPORT_PRIVATE PrototypeUsers : public WeakArrayList {
50 51 52 53 54
 public:
  static Handle<WeakArrayList> Add(Isolate* isolate,
                                   Handle<WeakArrayList> array,
                                   Handle<Map> value, int* assigned_index);

55
  static inline void MarkSlotEmpty(WeakArrayList array, int index);
56 57 58 59

  // The callback is called when a weak pointer to HeapObject "object" is moved
  // from index "from_index" to index "to_index" during compaction. The callback
  // must not cause GC.
60 61
  using CompactionCallback = void (*)(HeapObject object, int from_index,
                                      int to_index);
62 63 64
  static WeakArrayList Compact(
      Handle<WeakArrayList> array, Heap* heap, CompactionCallback callback,
      AllocationType allocation = AllocationType::kYoung);
65 66

#ifdef VERIFY_HEAP
67
  static void Verify(WeakArrayList array);
68 69 70 71 72 73 74 75
#endif  // VERIFY_HEAP

  static const int kEmptySlotIndex = 0;
  static const int kFirstIndex = 1;

  static const int kNoEmptySlotsMarker = 0;

 private:
76 77
  static inline Smi empty_slot_index(WeakArrayList array);
  static inline void set_empty_slot_index(WeakArrayList array, int index);
78

79
  static void ScanForEmptySlots(WeakArrayList array);
80 81 82 83

  DISALLOW_IMPLICIT_CONSTRUCTORS(PrototypeUsers);
};

84 85 86 87 88 89
}  // namespace internal
}  // namespace v8

#include "src/objects/object-macros-undef.h"

#endif  // V8_OBJECTS_PROTOTYPE_INFO_H_