Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Friends | List of all members
dart::TypeArguments::Cache Class Reference

#include <object.h>

Inheritance diagram for dart::TypeArguments::Cache:
dart::ValueObject

Classes

struct  KeyLocation
 

Public Types

enum  Header { kMetadataIndex = 0 , kHeaderSize }
 
enum  Entry {
  kSentinelIndex = 0 , kInstantiatorTypeArgsIndex = kSentinelIndex , kFunctionTypeArgsIndex , kInstantiatedTypeArgsIndex ,
  kEntrySize
}
 
using NumOccupiedBits = BitField< intptr_t, intptr_t, 0, compiler::target::kSmiBits - compiler::target::kBitsPerWordLog2 >
 
using EntryCountLog2Bits = BitField< intptr_t, intptr_t, NumOccupiedBits::kNextBit, compiler::target::kBitsPerWordLog2 >
 

Public Member Functions

 Cache (Zone *zone, const TypeArguments &source)
 
 Cache (Zone *zone, const Array &array)
 
intptr_t NumOccupied () const
 
KeyLocation FindKeyOrUnused (const TypeArguments &instantiator_tav, const TypeArguments &function_tav) const
 
bool IsOccupied (intptr_t entry) const
 
TypeArgumentsPtr Retrieve (intptr_t entry) const
 
KeyLocation AddEntry (intptr_t entry, const TypeArguments &instantiator_tav, const TypeArguments &function_tav, const TypeArguments &instantiated_tav) const
 
bool IsLinear () const
 
bool IsHash () const
 
intptr_t NumEntries () const
 
- Public Member Functions inherited from dart::ValueObject
 ValueObject ()
 
 ~ValueObject ()
 

Static Public Member Functions

static SmiPtr Sentinel ()
 
static const ArrayEmptyStorage ()
 

Static Public Attributes

static constexpr intptr_t kMaxLinearCacheEntries = 10
 
static constexpr intptr_t kMaxLinearCacheSize
 

Friends

class TypeArguments
 

Detailed Description

Definition at line 8763 of file object.h.

Member Typedef Documentation

◆ EntryCountLog2Bits

using dart::TypeArguments::Cache::EntryCountLog2Bits = BitField<intptr_t, intptr_t, NumOccupiedBits::kNextBit, compiler::target::kBitsPerWordLog2>

Definition at line 8798 of file object.h.

◆ NumOccupiedBits

using dart::TypeArguments::Cache::NumOccupiedBits = BitField<intptr_t, intptr_t, 0, compiler::target::kSmiBits - compiler::target::kBitsPerWordLog2>

Definition at line 8793 of file object.h.

Member Enumeration Documentation

◆ Entry

Enumerator
kSentinelIndex 
kInstantiatorTypeArgsIndex 
kFunctionTypeArgsIndex 
kInstantiatedTypeArgsIndex 
kEntrySize 

Definition at line 8807 of file object.h.

◆ Header

Enumerator
kMetadataIndex 
kHeaderSize 

Definition at line 8779 of file object.h.

8779 {
8780 // A single Smi that is a bitfield containing two values:
8781 // - The number of occupied entries in the cache for all caches.
8782 // - For hash-based caches, the upper bits contain log2(N) where N
8783 // is the number of total entries in the cache, so this information can
8784 // be quickly retrieved by stubs.
8785 //
8786 // Note: accesses outside of the type arguments canonicalization mutex
8787 // must have acquire semantics. In C++ code, use NumOccupied to retrieve
8788 // the number of occupied entries.
8789 kMetadataIndex = 0,
8791 };

Constructor & Destructor Documentation

◆ Cache() [1/2]

dart::TypeArguments::Cache::Cache ( Zone zone,
const TypeArguments source 
)

Definition at line 7035 of file object.cc.

7036 : zone_(ASSERT_NOTNULL(zone)),
7037 cache_container_(&source),
7038 data_(Array::Handle(source.instantiations())),
7039 smi_handle_(Smi::Handle(zone)) {
7041 ->type_arguments_canonicalization_mutex()
7042 ->IsOwnedByCurrentThread());
7043}
#define ASSERT_NOTNULL(ptr)
Definition assert.h:323
static IsolateGroup * Current()
Definition isolate.h:534
static Object & Handle()
Definition object.h:407
#define ASSERT(E)
SkBitmap source
Definition examples.cpp:28

◆ Cache() [2/2]

dart::TypeArguments::Cache::Cache ( Zone zone,
const Array array 
)

Definition at line 7045 of file object.cc.

7046 : zone_(ASSERT_NOTNULL(zone)),
7047 cache_container_(nullptr),
7048 data_(Array::Handle(array.ptr())),
7049 smi_handle_(Smi::Handle(zone)) {
7051 ->type_arguments_canonicalization_mutex()
7052 ->IsOwnedByCurrentThread());
7053}

Member Function Documentation

◆ AddEntry()

TypeArguments::Cache::KeyLocation dart::TypeArguments::Cache::AddEntry ( intptr_t  entry,
const TypeArguments instantiator_tav,
const TypeArguments function_tav,
const TypeArguments instantiated_tav 
) const

Definition at line 7172 of file object.cc.

7176 {
7177 // We don't do mutating operations in tests without a TypeArguments object.
7178 ASSERT(cache_container_ != nullptr);
7179#if defined(DEBUG)
7180 auto loc = FindKeyOrUnused(instantiator_tav, function_tav);
7181 ASSERT_EQUAL(loc.entry, entry);
7182 ASSERT(!loc.present);
7183#endif
7184 // Double-check we got the expected entry index when adding to a linear array.
7185 ASSERT(!IsLinear() || entry == NumOccupied());
7186 const intptr_t new_occupied = NumOccupied() + 1;
7187 const bool storage_changed = EnsureCapacity(new_occupied);
7188 // Note that this call to IsLinear() may return a different result than the
7189 // earlier, since EnsureCapacity() may have swapped to hash-based storage.
7190 if (storage_changed && !IsLinear()) {
7191 // The capacity of the array has changed, and the capacity is used when
7192 // probing further into the array due to collisions. Thus, we need to redo
7193 // the entry index calculation.
7194 auto loc = FindKeyOrUnused(instantiator_tav, function_tav);
7195 ASSERT(!loc.present);
7196 entry = loc.entry;
7197 }
7198
7199 // Go ahead and increment the number of occupied entries prior to adding the
7200 // entry. Use a store-release barrier in case of concurrent readers.
7201 const intptr_t metadata = RawSmiValue(Smi::RawCast(data_.At(kMetadataIndex)));
7202 smi_handle_ = Smi::New(NumOccupiedBits::update(new_occupied, metadata));
7203 data_.SetAtRelease(kMetadataIndex, smi_handle_);
7204
7206 const auto& tuple = table.At(entry);
7207 // The parts of the tuple that aren't used for sentinel checking are only
7208 // retrieved if the entry is occupied. Entries in the cache are never deleted,
7209 // so once the entry is marked as occupied, the contents of that entry never
7210 // change. Thus, we don't need store-release barriers here.
7211 tuple.Set<kFunctionTypeArgsIndex>(function_tav);
7212 tuple.Set<kInstantiatedTypeArgsIndex>(instantiated_tav);
7213 // For the sentinel position, though, we do.
7214 static_assert(
7216 "the sentinel position is not protected with a store-release barrier");
7217 tuple.Set<kInstantiatorTypeArgsIndex, std::memory_order_release>(
7218 instantiator_tav);
7219
7220 if (storage_changed) {
7221 // Only check for validity on growth, just to keep the overhead on DEBUG
7222 // builds down.
7223 DEBUG_ASSERT(IsValidStorageLocked(data_));
7224 // Update the container of the original cache to point to the new one.
7225 cache_container_->set_instantiations(data_);
7226 }
7227
7228 return {entry, true};
7229}
SI F table(const skcms_Curve *curve, F v)
#define DEBUG_ASSERT(cond)
Definition assert.h:321
#define ASSERT_EQUAL(expected, actual)
Definition assert.h:309
void SetAtRelease(intptr_t index, const Object &value) const
Definition object.h:10870
ObjectPtr At(intptr_t index) const
Definition object.h:10854
static constexpr S update(T value, S original)
Definition bitfield.h:190
static ObjectPtr RawCast(ObjectPtr obj)
Definition object.h:325
static SmiPtr New(intptr_t value)
Definition object.h:9985
KeyLocation FindKeyOrUnused(const TypeArguments &instantiator_tav, const TypeArguments &function_tav) const
Definition object.h:8839
intptr_t NumOccupied() const
Definition object.h:8827
ArrayOfTuplesView< TypeArguments::Cache::Entry, std::tuple< Object, TypeArguments, TypeArguments >, TypeArguments::Cache::kHeaderSize > InstantiationsCacheTable
Definition object.h:13540
intptr_t RawSmiValue(const SmiPtr raw_value)

◆ EmptyStorage()

static const Array & dart::TypeArguments::Cache::EmptyStorage ( )
inlinestatic

Definition at line 8865 of file object.h.

8865 {
8866 return Object::empty_instantiations_cache_array();
8867 }

◆ FindKeyOrUnused()

KeyLocation dart::TypeArguments::Cache::FindKeyOrUnused ( const TypeArguments instantiator_tav,
const TypeArguments function_tav 
) const
inline

Definition at line 8839 of file object.h.

8840 {
8841 return FindKeyOrUnused(data_, instantiator_tav, function_tav);
8842 }

◆ IsHash()

bool dart::TypeArguments::Cache::IsHash ( ) const
inline

Definition at line 8873 of file object.h.

8873{ return IsHash(data_); }

◆ IsLinear()

bool dart::TypeArguments::Cache::IsLinear ( ) const
inline

Definition at line 8870 of file object.h.

8870{ return IsLinear(data_); }

◆ IsOccupied()

bool dart::TypeArguments::Cache::IsOccupied ( intptr_t  entry) const

Definition at line 7114 of file object.cc.

7114 {
7116 ASSERT(entry >= 0 && entry < table.Length());
7117 return table.At(entry).Get<kSentinelIndex>() != Sentinel();
7118}
static SmiPtr Sentinel()
Definition object.cc:7231

◆ NumEntries()

intptr_t dart::TypeArguments::Cache::NumEntries ( ) const
inline

Definition at line 8899 of file object.h.

8899{ return NumEntries(data_); }
intptr_t NumEntries() const
Definition object.h:8899

◆ NumOccupied()

intptr_t dart::TypeArguments::Cache::NumOccupied ( ) const
inline

Definition at line 8827 of file object.h.

8827{ return NumOccupied(data_); }

◆ Retrieve()

TypeArgumentsPtr dart::TypeArguments::Cache::Retrieve ( intptr_t  entry) const

Definition at line 7120 of file object.cc.

7120 {
7121 ASSERT(IsOccupied(entry));
7123 return table.At(entry).Get<kInstantiatedTypeArgsIndex>();
7124}
bool IsOccupied(intptr_t entry) const
Definition object.cc:7114

◆ Sentinel()

SmiPtr dart::TypeArguments::Cache::Sentinel ( )
static

Definition at line 7231 of file object.cc.

7231 {
7232 return Smi::New(kSentinelValue);
7233}

Friends And Related Symbol Documentation

◆ TypeArguments

friend class TypeArguments
friend

Definition at line 8949 of file object.h.

Member Data Documentation

◆ kMaxLinearCacheEntries

constexpr intptr_t dart::TypeArguments::Cache::kMaxLinearCacheEntries = 10
staticconstexpr

Definition at line 8907 of file object.h.

◆ kMaxLinearCacheSize

constexpr intptr_t dart::TypeArguments::Cache::kMaxLinearCacheSize
staticconstexpr
Initial value:
=
static constexpr intptr_t kMaxLinearCacheEntries
Definition object.h:8907

Definition at line 8930 of file object.h.


The documentation for this class was generated from the following files: