Skip to content

Commit 6992479

Browse files
committed
[MERGE #5121 @MSLaguana] Adding notion of weak reference regions, and concurrently marking those regions.
Merge pull request #5121 from MSLaguana:recyclerWeakReferenceRegion Also adding new weak ref region dictionary to make use of this type.
2 parents 0d1e26c + 89fc0ac commit 6992479

13 files changed

+950
-18
lines changed

lib/Common/CommonDefines.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,9 @@
263263
#define RECYCLER_VISITED_HOST
264264
#endif
265265

266+
267+
#define ENABLE_WEAK_REFERENCE_REGIONS 1
268+
266269
// JIT features
267270

268271
#if DISABLE_JIT

lib/Common/DataStructures/BaseDictionary.h

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ namespace JsUtil
102102
Field(int) freeCount;
103103
Field(int) modFunctionIndex;
104104

105+
static const int FreeListSentinel = -2;
106+
105107
#if PROFILE_DICTIONARY
106108
FieldNoBarrier(DictionaryStats*) stats;
107109
#endif
@@ -780,9 +782,9 @@ namespace JsUtil
780782

781783
static bool IsFreeEntry(const EntryType &entry)
782784
{
783-
// A free entry's next index will be (-2 - nextIndex), such that it is always <= -2, for fast entry iteration
785+
// A free entry's next index will be (FreeListSentinel - nextIndex), such that it is always <= FreeListSentinel, for fast entry iteration
784786
// allowing for skipping over free entries. -1 is reserved for the end-of-chain marker for a used entry.
785-
return entry.next <= -2;
787+
return entry.next <= FreeListSentinel;
786788
}
787789

788790
void SetNextFreeEntryIndex(EntryType &freeEntry, const int nextFreeEntryIndex)
@@ -791,15 +793,15 @@ namespace JsUtil
791793
Assert(nextFreeEntryIndex >= -1);
792794
Assert(nextFreeEntryIndex < count);
793795

794-
// The last entry in the free list chain will have a next of -2 to indicate that it is a free entry. The end of the
796+
// The last entry in the free list chain will have a next of FreeListSentinel to indicate that it is a free entry. The end of the
795797
// free list chain is identified using freeCount.
796-
freeEntry.next = nextFreeEntryIndex >= 0 ? -2 - nextFreeEntryIndex : -2;
798+
freeEntry.next = nextFreeEntryIndex >= 0 ? FreeListSentinel - nextFreeEntryIndex : FreeListSentinel;
797799
}
798800

799801
static int GetNextFreeEntryIndex(const EntryType &freeEntry)
800802
{
801803
Assert(IsFreeEntry(freeEntry));
802-
return -2 - freeEntry.next;
804+
return FreeListSentinel - freeEntry.next;
803805
}
804806

805807
template <typename LookupType>
@@ -1327,8 +1329,8 @@ namespace JsUtil
13271329
bucketIndex(0u - 1)
13281330
#if DBG
13291331
,
1330-
previousEntryIndexInBucket(-2),
1331-
indexOfEntryAfterRemovedEntry(-2)
1332+
previousEntryIndexInBucket(FreeListSentinel),
1333+
indexOfEntryAfterRemovedEntry(FreeListSentinel)
13321334
#endif
13331335
{
13341336
if(dictionary.Count() != 0)
@@ -1345,9 +1347,9 @@ namespace JsUtil
13451347
Assert(this->entryIndex >= -1);
13461348
Assert(this->entryIndex < dictionary.count);
13471349
Assert(bucketIndex == 0u - 1 || bucketIndex <= bucketCount);
1348-
Assert(previousEntryIndexInBucket >= -2);
1350+
Assert(previousEntryIndexInBucket >= FreeListSentinel);
13491351
Assert(previousEntryIndexInBucket < dictionary.count);
1350-
Assert(indexOfEntryAfterRemovedEntry >= -2);
1352+
Assert(indexOfEntryAfterRemovedEntry >= FreeListSentinel);
13511353
Assert(indexOfEntryAfterRemovedEntry < dictionary.count);
13521354

13531355
return Base::IsValid() && this->entryIndex >= 0;

lib/Common/DataStructures/DictionaryEntry.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,23 @@ namespace JsUtil
118118
TKey const& Key() const { return key; }
119119
};
120120

121+
template <class TKey>
122+
class BaseKeyEntry : public ValueEntry<TKey>
123+
{
124+
public:
125+
TKey const& Key() const { return this->value; }
126+
};
127+
121128
template <class TKey, class TValue>
122129
class KeyValueEntry : public BaseKeyValueEntry<TKey, TValue>
123130
{
124131
};
125132

133+
template <class TKey>
134+
class KeyEntry : public BaseKeyEntry<TKey>
135+
{
136+
};
137+
126138
template <class TKey, class TValue>
127139
class KeyValueEntry<TKey*, TValue> : public BaseKeyValueEntry<TKey*, TValue>
128140
{
@@ -167,6 +179,28 @@ namespace JsUtil
167179
}
168180
};
169181

182+
template <class TKey, template <class K> class THashKeyEntry>
183+
class DefaultHashedKeyEntry : public THashKeyEntry<TKey>
184+
{
185+
public:
186+
template<typename Comparer, typename TLookup>
187+
inline bool KeyEquals(TLookup const& otherKey, hash_t otherHashCode)
188+
{
189+
return Comparer::Equals(this->Key(), otherKey);
190+
}
191+
192+
template<typename Comparer>
193+
inline hash_t GetHashCode()
194+
{
195+
return ((Comparer::GetHashCode(this->Key()) & 0x7fffffff) << 1) | 1;
196+
}
197+
198+
void Set(TKey const& key, int hashCode)
199+
{
200+
__super::Set(key);
201+
}
202+
};
203+
170204
template <class TKey, class TValue, template <class K, class V> class THashEntry>
171205
class CacheHashedEntry : public THashEntry<TKey, TValue>
172206
{
@@ -234,4 +268,7 @@ namespace JsUtil
234268
return (weakReference == nullptr || weakReference->Get() == nullptr);
235269
}
236270
};
271+
272+
template <class TKey>
273+
class SimpleDictionaryKeyEntry : public DefaultHashedKeyEntry<TKey, KeyEntry> {};
237274
}

0 commit comments

Comments
 (0)