chromium/v8/src/objects/feedback-vector.h

// Copyright 2014 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_FEEDBACK_VECTOR_H_
#define V8_OBJECTS_FEEDBACK_VECTOR_H_

#include <optional>
#include <vector>

#include "src/base/bit-field.h"
#include "src/base/logging.h"
#include "src/base/macros.h"
#include "src/common/globals.h"
#include "src/objects/elements-kind.h"
#include "src/objects/feedback-cell.h"
#include "src/objects/map.h"
#include "src/objects/maybe-object.h"
#include "src/objects/name.h"
#include "src/objects/type-hints.h"
#include "src/zone/zone-containers.h"

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

namespace v8::internal {

class IsCompiledScope;
class FeedbackVectorSpec;

enum class UpdateFeedbackMode {};

// Which feedback slots to clear in Clear().
enum class ClearBehavior {};

enum class FeedbackSlotKind : uint8_t {};

static constexpr int kFeedbackSlotKindCount =;

MapAndHandler;
MapAndFeedback;

inline bool IsCallICKind(FeedbackSlotKind kind) {}

inline bool IsLoadICKind(FeedbackSlotKind kind) {}

inline bool IsLoadGlobalICKind(FeedbackSlotKind kind) {}

inline bool IsKeyedLoadICKind(FeedbackSlotKind kind) {}

inline bool IsKeyedHasICKind(FeedbackSlotKind kind) {}

inline bool IsStoreGlobalICKind(FeedbackSlotKind kind) {}

inline bool IsSetNamedICKind(FeedbackSlotKind kind) {}

inline bool IsDefineNamedOwnICKind(FeedbackSlotKind kind) {}

inline bool IsDefineKeyedOwnICKind(FeedbackSlotKind kind) {}

inline bool IsDefineKeyedOwnPropertyInLiteralKind(FeedbackSlotKind kind) {}

inline bool IsKeyedStoreICKind(FeedbackSlotKind kind) {}

inline bool IsStoreInArrayLiteralICKind(FeedbackSlotKind kind) {}

inline bool IsGlobalICKind(FeedbackSlotKind kind) {}

inline bool IsCloneObjectKind(FeedbackSlotKind kind) {}

inline TypeofMode GetTypeofModeFromSlotKind(FeedbackSlotKind kind) {}

inline LanguageMode GetLanguageModeFromSlotKind(FeedbackSlotKind kind) {}

V8_EXPORT_PRIVATE std::ostream& operator<<(std::ostream& os,
                                           FeedbackSlotKind kind);

using MaybeObjectHandles = std::vector<MaybeObjectHandle>;

class FeedbackMetadata;

#include "torque-generated/src/objects/feedback-vector-tq.inc"

class ClosureFeedbackCellArrayShape final : public AllStatic {};

// ClosureFeedbackCellArray contains feedback cells used when creating closures
// from a function. This is created once the function is compiled and is either
// held by the feedback vector (if allocated) or by the FeedbackCell of the
// closure.
class ClosureFeedbackCellArray
    : public TaggedArrayBase<ClosureFeedbackCellArray,
                             ClosureFeedbackCellArrayShape> {};

class NexusConfig;

// A FeedbackVector has a fixed header followed by an array of feedback slots,
// of length determined by the feedback metadata.
class FeedbackVector
    : public TorqueGeneratedFeedbackVector<FeedbackVector, HeapObject> {};

class V8_EXPORT_PRIVATE FeedbackVectorSpec {};

// Helper class that creates a feedback slot on-demand.
class SharedFeedbackSlot {};

// FeedbackMetadata is an array-like object with a slot count (indicating how
// many slots are stored). We save space by packing several slots into an array
// of int32 data. The length is never stored - it is always calculated from
// slot_count. All instances are created through the static New function, and
// the number of slots is static once an instance is created.
//
// Besides the feedback slots, the FeedbackMetadata also stores the parameter
// count for every CreateClosure slot as that is required for allocating the
// FeedbackCells for the closres. This data doesn't necessarily need to live in
// this object (it could, for example, also be stored on the Bytecode), but
// keeping it here is somewhat efficient as the uint16s can just be stored
// after the int32s of the slots.
class FeedbackMetadata : public HeapObject {};

// Verify that an empty hash field looks like a tagged object, but can't
// possibly be confused with a pointer.
static_assert;
static_assert;
// Verify that a set hash field will not look like a tagged object.
static_assert;

class FeedbackMetadataIterator {};

// NexusConfig adapts the FeedbackNexus to be used on the main thread
// or a background thread. It controls the actual read and writes of
// the underlying feedback vector, manages the creation of handles, and
// expresses capabilities available in the very different contexts of
// main and background thread. Here are the differences:
//
// Capability:      MainThread           BackgroundThread
// Write to vector  Allowed              Not allowed
// Handle creation  Via Isolate          Via LocalHeap
// Reads of vector  "Live"               Cached after initial read
// Thread safety    Exclusive write,     Shared read only
//                  shared read
class V8_EXPORT_PRIVATE NexusConfig {};

// A FeedbackNexus is the combination of a FeedbackVector and a slot.
class V8_EXPORT_PRIVATE FeedbackNexus final {};

class V8_EXPORT_PRIVATE FeedbackIterator final {};

inline BinaryOperationHint BinaryOperationHintFromFeedback(int type_feedback);
inline CompareOperationHint CompareOperationHintFromFeedback(int type_feedback);
inline ForInHint ForInHintFromFeedback(ForInFeedback type_feedback);

}  // namespace v8::internal

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

#endif  // V8_OBJECTS_FEEDBACK_VECTOR_H_