// Copyright 2012 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_TRANSITIONS_H_ #define V8_OBJECTS_TRANSITIONS_H_ #include <optional> #include "src/common/checks.h" #include "src/execution/isolate.h" #include "src/objects/descriptor-array.h" #include "src/objects/elements-kind.h" #include "src/objects/map.h" #include "src/objects/maybe-object.h" #include "src/objects/name.h" #include "src/objects/objects.h" // Has to be the last include (doesn't have include guards): #include "src/objects/object-macros.h" namespace v8::internal { // Find all transitions with given name and calls the callback. ForEachTransitionCallback; // Descriptor for the contents of special side-step transition arrays. // Side-step transitions are accessed through the TransitionsAccessor which // enforces adherence to this format. The entries are either weak, Empty, or // Unreachable. struct SideStepTransition { … }; std::ostream& operator<<(std::ostream& os, SideStepTransition::Kind sidestep); // TransitionsAccessor is a helper class to encapsulate access to the various // ways a Map can store transitions to other maps in its respective field at // Map::kTransitionsOrPrototypeInfo. // It caches state information internally, which becomes stale when a Map's // transitions storage changes or when a GC cycle clears dead transitions; // so while a TransitionsAccessor instance can be used for several read-only // operations in a row (provided no GC happens between them), it must be // discarded and recreated after "Insert" and "UpdateHandler" operations. // // Internal details: a Map's field either holds an in-place weak reference to a // transition target, or a StoreIC handler for a transitioning store (which in // turn points to its target map), or a TransitionArray for several target maps // and/or handlers as well as prototype and ElementsKind transitions. Property // details (and in case of inline target storage, the key) are retrieved from // the target map's descriptor array. Stored transitions are weak in the GC // sense: both single transitions stored inline and TransitionArray fields are // cleared when the map they refer to is not otherwise reachable. class V8_EXPORT_PRIVATE TransitionsAccessor { … }; // TransitionArrays are fixed arrays used to hold map transitions for property, // constant, and element changes. // The TransitionArray class exposes a very low-level interface. Most clients // should use TransitionsAccessors. // TransitionArrays have the following format: // [0] Tagged<Smi>(0) or WeakFixedArray of prototype transitions (strong ref) // [1] Tagged<Smi>(0) or WeakFixedArray of side-step transitions (strong ref) // [2] Number of transitions (can be zero after trimming) // [3] First transition key (strong ref) // [4] First transition target (weak ref) // ... // [4 + number of transitions * kTransitionSize]: start of slack // TODO(olivf): The slots for prototype transitions and side-steps could be // shared. class TransitionArray : public WeakFixedArray { … }; } // namespace v8::internal #include "src/objects/object-macros-undef.h" #endif // V8_OBJECTS_TRANSITIONS_H_