Flutter Engine
The Flutter Engine
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 8789 of file object.h.

Member Typedef Documentation

◆ EntryCountLog2Bits

Definition at line 8824 of file object.h.

◆ NumOccupiedBits

Definition at line 8819 of file object.h.

Member Enumeration Documentation

◆ Entry

Enumerator
kSentinelIndex 
kInstantiatorTypeArgsIndex 
kFunctionTypeArgsIndex 
kInstantiatedTypeArgsIndex 
kEntrySize 

Definition at line 8833 of file object.h.

8833 {
8834 kSentinelIndex = 0, // Used when only checking for sentinel values.
8838 kEntrySize,
8839 };

◆ Header

Enumerator
kMetadataIndex 
kHeaderSize 

Definition at line 8805 of file object.h.

8805 {
8806 // A single Smi that is a bitfield containing two values:
8807 // - The number of occupied entries in the cache for all caches.
8808 // - For hash-based caches, the upper bits contain log2(N) where N
8809 // is the number of total entries in the cache, so this information can
8810 // be quickly retrieved by stubs.
8811 //
8812 // Note: accesses outside of the type arguments canonicalization mutex
8813 // must have acquire semantics. In C++ code, use NumOccupied to retrieve
8814 // the number of occupied entries.
8815 kMetadataIndex = 0,
8817 };

Constructor & Destructor Documentation

◆ Cache() [1/2]

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

Definition at line 6977 of file object.cc.

6978 : zone_(ASSERT_NOTNULL(zone)),
6979 cache_container_(&source),
6980 data_(Array::Handle(source.instantiations())),
6981 smi_handle_(Smi::Handle(zone)) {
6983 ->type_arguments_canonicalization_mutex()
6984 ->IsOwnedByCurrentThread());
6985}
#define ASSERT_NOTNULL(ptr)
Definition: assert.h:323
static IsolateGroup * Current()
Definition: isolate.h:539
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 6987 of file object.cc.

6988 : zone_(ASSERT_NOTNULL(zone)),
6989 cache_container_(nullptr),
6990 data_(Array::Handle(array.ptr())),
6991 smi_handle_(Smi::Handle(zone)) {
6993 ->type_arguments_canonicalization_mutex()
6994 ->IsOwnedByCurrentThread());
6995}

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 7114 of file object.cc.

7118 {
7119 // We don't do mutating operations in tests without a TypeArguments object.
7120 ASSERT(cache_container_ != nullptr);
7121#if defined(DEBUG)
7122 auto loc = FindKeyOrUnused(instantiator_tav, function_tav);
7123 ASSERT_EQUAL(loc.entry, entry);
7124 ASSERT(!loc.present);
7125#endif
7126 // Double-check we got the expected entry index when adding to a linear array.
7127 ASSERT(!IsLinear() || entry == NumOccupied());
7128 const intptr_t new_occupied = NumOccupied() + 1;
7129 const bool storage_changed = EnsureCapacity(new_occupied);
7130 // Note that this call to IsLinear() may return a different result than the
7131 // earlier, since EnsureCapacity() may have swapped to hash-based storage.
7132 if (storage_changed && !IsLinear()) {
7133 // The capacity of the array has changed, and the capacity is used when
7134 // probing further into the array due to collisions. Thus, we need to redo
7135 // the entry index calculation.
7136 auto loc = FindKeyOrUnused(instantiator_tav, function_tav);
7137 ASSERT(!loc.present);
7138 entry = loc.entry;
7139 }
7140
7141 // Go ahead and increment the number of occupied entries prior to adding the
7142 // entry. Use a store-release barrier in case of concurrent readers.
7143 const intptr_t metadata = RawSmiValue(Smi::RawCast(data_.At(kMetadataIndex)));
7144 smi_handle_ = Smi::New(NumOccupiedBits::update(new_occupied, metadata));
7145 data_.SetAtRelease(kMetadataIndex, smi_handle_);
7146
7148 const auto& tuple = table.At(entry);
7149 // The parts of the tuple that aren't used for sentinel checking are only
7150 // retrieved if the entry is occupied. Entries in the cache are never deleted,
7151 // so once the entry is marked as occupied, the contents of that entry never
7152 // change. Thus, we don't need store-release barriers here.
7153 tuple.Set<kFunctionTypeArgsIndex>(function_tav);
7154 tuple.Set<kInstantiatedTypeArgsIndex>(instantiated_tav);
7155 // For the sentinel position, though, we do.
7156 static_assert(
7158 "the sentinel position is not protected with a store-release barrier");
7159 tuple.Set<kInstantiatorTypeArgsIndex, std::memory_order_release>(
7160 instantiator_tav);
7161
7162 if (storage_changed) {
7163 // Only check for validity on growth, just to keep the overhead on DEBUG
7164 // builds down.
7165 DEBUG_ASSERT(IsValidStorageLocked(data_));
7166 // Update the container of the original cache to point to the new one.
7167 cache_container_->set_instantiations(data_);
7168 }
7169
7170 return {entry, true};
7171}
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:10895
ObjectPtr At(intptr_t index) const
Definition: object.h:10875
static constexpr S update(T value, S original)
Definition: bitfield.h:188
static ObjectPtr RawCast(ObjectPtr obj)
Definition: object.h:325
static SmiPtr New(intptr_t value)
Definition: object.h:10006
KeyLocation FindKeyOrUnused(const TypeArguments &instantiator_tav, const TypeArguments &function_tav) const
Definition: object.h:8865
intptr_t NumOccupied() const
Definition: object.h:8853
bool IsLinear() const
Definition: object.h:8896
ArrayOfTuplesView< TypeArguments::Cache::Entry, std::tuple< Object, TypeArguments, TypeArguments >, TypeArguments::Cache::kHeaderSize > InstantiationsCacheTable
Definition: object.h:13566
intptr_t RawSmiValue(const SmiPtr raw_value)

◆ EmptyStorage()

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

Definition at line 8891 of file object.h.

8891 {
8892 return Object::empty_instantiations_cache_array();
8893 }

◆ FindKeyOrUnused()

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

Definition at line 8865 of file object.h.

8866 {
8867 return FindKeyOrUnused(data_, instantiator_tav, function_tav);
8868 }

◆ IsHash()

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

Definition at line 8899 of file object.h.

8899{ return IsHash(data_); }

◆ IsLinear()

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

Definition at line 8896 of file object.h.

8896{ return IsLinear(data_); }

◆ IsOccupied()

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

Definition at line 7056 of file object.cc.

7056 {
7058 ASSERT(entry >= 0 && entry < table.Length());
7059 return table.At(entry).Get<kSentinelIndex>() != Sentinel();
7060}
static SmiPtr Sentinel()
Definition: object.cc:7173

◆ NumEntries()

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

Definition at line 8925 of file object.h.

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

◆ NumOccupied()

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

Definition at line 8853 of file object.h.

8853{ return NumOccupied(data_); }

◆ Retrieve()

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

Definition at line 7062 of file object.cc.

7062 {
7063 ASSERT(IsOccupied(entry));
7065 return table.At(entry).Get<kInstantiatedTypeArgsIndex>();
7066}
bool IsOccupied(intptr_t entry) const
Definition: object.cc:7056

◆ Sentinel()

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

Definition at line 7173 of file object.cc.

7173 {
7174 return Smi::New(kSentinelValue);
7175}

Friends And Related Function Documentation

◆ TypeArguments

friend class TypeArguments
friend

Definition at line 8975 of file object.h.

Member Data Documentation

◆ kMaxLinearCacheEntries

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

Definition at line 8933 of file object.h.

◆ kMaxLinearCacheSize

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

Definition at line 8956 of file object.h.


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